ProjectMapper.xml 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.management.platform.mapper.ProjectMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Project">
  6. <id column="id" property="id" />
  7. <result column="project_name" property="projectName" />
  8. <result column="company_id" property="companyId" />
  9. <result column="project_code" property="projectCode" />
  10. <result column="incharger_id" property="inchargerId" />
  11. <result column="plan_start_date" property="planStartDate" />
  12. <result column="plan_end_date" property="planEndDate" />
  13. <result column="progress" property="progress" />
  14. <result column="level" property="level" />
  15. <result column="status" property="status" />
  16. <result column="finish_date" property="finishDate" />
  17. <result column="creator_id" property="creatorId" />
  18. <result column="creator_name" property="creatorName" />
  19. <result column="create_date" property="createDate" />
  20. <result column="contract_amount" property="contractAmount" />
  21. <result column="budget" property="budget" />
  22. <result column="base_man" property="baseMan" />
  23. <result column="base_outsourcing" property="baseOutsourcing" />
  24. <result column="base_risk1" property="baseRisk1" />
  25. <result column="base_risk2" property="baseRisk2" />
  26. <result column="base_fee" property="baseFee" />
  27. <result column="fee_man" property="feeMan" />
  28. <result column="customer_id" property="customerId" />
  29. <result column="customer_name" property="customerName" />
  30. <result column="is_public" property="isPublic" />
  31. <result column="associate_degrees" property="associateDegrees" />
  32. <result column="associate_degree_names" property="associateDegreeNames" />
  33. <result column="task_gp_incharge" property="taskGpIncharge" />
  34. <result column="category" property="category" />
  35. <result column="category_name" property="categoryName" />
  36. <result column="project_desc" property="projectDesc" />
  37. <result column="project_main_id" property="projectMainId" />
  38. <result column="project_main_name" property="projectMainName" />
  39. <result column="provider_ids" property="providerIds" />
  40. <result column="provider_names" property="providerNames" />
  41. <result column="current_stage_id" property="currentStageId" />
  42. <result column="current_stage_name" property="currentStageName" />
  43. <result column="output_value" property="outputValue" />
  44. <result column="dept_id" property="deptId" />
  45. <result column="dept_cascade" property="deptCascade" />
  46. <result column="bu_id" property="buId" />
  47. <result column="man_day" property="manDay" />
  48. <result column="man_day_start_date" property="manDayStartDate" />
  49. <result column="plate1" property="plate1" />
  50. <result column="plate2" property="plate2" />
  51. <result column="plate3" property="plate3" />
  52. <result column="plate4" property="plate4" />
  53. <result column="plate5" property="plate5" />
  54. <result column="plate6" property="plate6" />
  55. <result column="plate7" property="plate7" />
  56. <result column="plate8" property="plate8" />
  57. <result column="plate9" property="plate9" />
  58. <result column="plate10" property="plate10" />
  59. <result column="from_outside" property="fromOutside" />
  60. <result column="approve_id" property="approveId" />
  61. <result column="reviwer_id" property="reviwerId" />
  62. </resultMap>
  63. <!-- 通用查询结果列 -->
  64. <sql id="Base_Column_List">
  65. id, project_name, company_id, project_code, incharger_id, plan_start_date, plan_end_date, progress, level, status, finish_date, creator_id, creator_name, create_date, contract_amount, budget, base_man, base_outsourcing, base_risk1, base_risk2, base_fee, fee_man, customer_id, customer_name, is_public, associate_degrees, associate_degree_names, task_gp_incharge, category, category_name, project_desc, project_main_id, project_main_name, provider_ids, provider_names, current_stage_id, current_stage_name, output_value, dept_id, dept_cascade, bu_id, man_day, man_day_start_date, plate1, plate2, plate3, plate4, plate5, plate6, plate7, plate8, plate9, plate10, from_outside, approve_id, reviwer_id
  66. </sql>
  67. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  68. <result column="id" property="id" />
  69. <result column="project_name" property="projectName" />
  70. <result column="project_code" property="projectCode" />
  71. <result column="startDate" property="startDate" />
  72. <result column="endDate" property="endDate" />
  73. <collection property="stageCostList" javaType="java.util.ArrayList"
  74. ofType="com.management.platform.entity.vo.StageCost"
  75. select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
  76. </resultMap>
  77. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  78. <result column="customer_id" property="customerId" />
  79. <result column="customer_name" property="customerName" />
  80. <result column="contract_amount" property="contractAmount" />
  81. <result column="fee_man" property="feeMan" />
  82. <result column="project_num" property="projectNum" />
  83. <result column="project_ids" property="projectIds" />
  84. <result column="project_names" property="projectNames" />
  85. </resultMap>
  86. <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
  87. select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
  88. from project
  89. where company_id = #{companyId}
  90. <if test="projectId != null">
  91. and id = #{projectId}
  92. </if>
  93. <if test="inchargerId!=null">
  94. and incharger_id = #{inchargerId}
  95. </if>
  96. order by is_public desc, id asc
  97. <if test="startIndex != null">
  98. limit ${startIndex}, ${endIndex}
  99. </if>
  100. </select>
  101. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  102. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  103. IFNULL(SUM(report.`working_time`), 0) AS working_time,
  104. IFNULL((SELECT SUM(stages.`stages_time`) from stages WHERE stages.stages_name = report.stage GROUP BY stages_name), 0) AS stages_time,report.`project_id` as projectId
  105. FROM report
  106. left join project p on p.id=report.`project_id`
  107. where report.state = 1
  108. <if test="inchargerId!=null">
  109. and p.incharger_id = #{inchargerId}
  110. </if>
  111. <if test="projectIds!=null and projectIds.size()>0">
  112. and p.id in
  113. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  114. #{item}
  115. </foreach>
  116. </if>
  117. and report.create_date &gt;= #{startDate}
  118. and report.create_date &lt;= #{endDate}
  119. GROUP BY report.`project_id`,report.stage
  120. </select>
  121. <!--获取查询者所在公司每个项目的工时成本-->
  122. <select id="getParticipatedProject" resultType="java.util.Map">
  123. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc,is_public as isPublic, plan_end_date as planEndDate
  124. FROM project
  125. WHERE id IN (
  126. SELECT project_id
  127. FROM participation
  128. WHERE user_id = #{userId}
  129. ) or incharger_id = #{userId}
  130. or creator_id = #{userId}
  131. or (is_public = 1 and company_id = #{companyId})
  132. ORDER BY is_public DESC, id DESC
  133. </select>
  134. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  135. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc, is_public as isPublic, plan_end_date as planEndDate
  136. FROM project
  137. WHERE status = 1 and (id IN (
  138. SELECT project_id
  139. FROM participation
  140. WHERE user_id = #{userId}
  141. )
  142. or (is_public = 1 and company_id = #{companyId}))
  143. ORDER BY is_public DESC, id ASC
  144. </select>
  145. <!--获取查询者所在公司每个项目的工时成本-->
  146. <select id="getTimeCost" resultType="java.util.Map">
  147. SELECT a.id, a.project_main_id as projectMainId, a.project_code as projectCode, a.project_name AS project, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName
  148. FROM project AS a
  149. LEFT JOIN report AS b ON b.project_id = a.id
  150. JOIN user AS c ON b.creator_id = c.id
  151. WHERE a.company_id = #{companyId}
  152. <if test="projectId != null">
  153. AND a.id = #{projectId}
  154. </if>
  155. <if test="categoryId != null">
  156. AND a.category = #{categoryId}
  157. </if>
  158. <if test="projectIds != null">
  159. and a.id in
  160. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  161. #{item}
  162. </foreach>
  163. </if>
  164. <if test="userIdList != null and userIdList.size()>0">
  165. AND b.creator_id in
  166. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  167. #{item}
  168. </foreach>
  169. </if>
  170. <if test="startDate != null and endDate != null">
  171. AND b.create_date between #{startDate} and #{endDate}
  172. </if>
  173. <choose>
  174. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  175. and b.dept_id in
  176. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  177. #{item}
  178. </foreach>
  179. </when>
  180. <otherwise>
  181. <if test="deptIds!=null and deptIds.size()>0">
  182. and (b.dept_id in
  183. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  184. #{item}
  185. </foreach>
  186. <if test="deptRelatedProjectIds.size() > 0">
  187. or a.id in
  188. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  189. #{pid}
  190. </foreach>
  191. </if>
  192. <if test="inchargeUserIds != null and inchargeUserIds.size()>0">
  193. OR a.`incharger_id` IN
  194. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  195. #{pid}
  196. </foreach>
  197. OR b.`group_id` IN(SELECT id FROM task_group WHERE incharger_id IN
  198. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  199. #{pid}
  200. </foreach>
  201. )
  202. </if>
  203. )
  204. </if>
  205. </otherwise>
  206. </choose>
  207. AND b.state = 1
  208. GROUP BY a.id
  209. ORDER BY a.id ASC
  210. </select>
  211. <!--获取查询者所在公司每个子项目的工时成本-->
  212. <select id="getSubProjectTimeCost" resultType="java.util.Map">
  213. select b.project_code as projectCode,b.project_name as projectName,a.code as subProjectCode,a.name as subProjectName,SUM(c.cost) as cost,SUM(c.working_time) as workingTime
  214. from sub_project a
  215. left join project b on b.id=a.project_id
  216. left join report c on c.sub_project_id=a.id
  217. where a.company_id=#{companyId}
  218. and c.state = 1
  219. <if test="startDate != null and endDate != null">
  220. and c.create_date between #{startDate} and #{endDate}
  221. </if>
  222. <if test="projectId!=null">
  223. and a.project_id=#{projectId}
  224. </if>
  225. <if test="inchagerIds!=null and inchagerIds.size()>0">
  226. and b.id in
  227. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  228. #{item}
  229. </foreach>
  230. </if>
  231. group by b.id,a.id
  232. <if test="start!=null and size!=null">
  233. limit #{start},#{size}
  234. </if>
  235. </select>
  236. <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
  237. select count(1) from(select b.project_code as projectCode,b.project_name as projectName,a.code as subProjectCode,a.name as subProjectName,SUM(c.cost) as cost,SUM(c.working_time) as workingTime
  238. from sub_project a
  239. left join project b on b.id=a.project_id
  240. left join report c on c.sub_project_id=a.id
  241. where a.company_id=#{companyId}
  242. and c.state = 1
  243. <if test="startDate != null and endDate != null">
  244. and c.create_date between #{startDate} and #{endDate}
  245. </if>
  246. <if test="projectId!=null">
  247. and a.project_id=#{projectId}
  248. </if>
  249. <if test="inchagerIds!=null and inchagerIds.size()>0">
  250. and b.id in
  251. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  252. #{item}
  253. </foreach>
  254. </if>
  255. group by b.id,a.id
  256. <if test="start!=null and size!=null">
  257. limit #{start},#{size}
  258. </if>) as total
  259. </select>
  260. <!--获取查询者所在公司每个项目的工时成本-->
  261. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  262. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'无主项目') as mainProjectName
  263. FROM project AS a
  264. LEFT JOIN report AS b ON b.project_id = a.id
  265. JOIN user AS c ON b.creator_id = c.id
  266. LEFT JOIN project_main pm on pm.id=a.project_main_id
  267. WHERE a.company_id = #{companyId}
  268. <if test="projectId != null">
  269. AND a.id = #{projectId}
  270. </if>
  271. <if test="startDate != null and endDate != null">
  272. AND b.create_date between #{startDate} and #{endDate}
  273. </if>
  274. <if test="deptIds!=null and deptIds.size()>0">
  275. and b.dept_id in
  276. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  277. #{item}
  278. </foreach>
  279. </if>
  280. AND b.state = 1
  281. GROUP BY a.project_main_id
  282. ORDER BY a.id ASC
  283. </select>
  284. <!--获取查询者所在公司每个项目分类的工时成本-->
  285. <select id="getTimeCostByCategory" resultType="java.util.Map">
  286. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  287. FROM project AS a
  288. LEFT JOIN report AS b ON b.project_id = a.id
  289. JOIN user AS c ON b.creator_id = c.id
  290. WHERE a.company_id = #{companyId}
  291. <if test="projectCategoryId != null">
  292. AND a.category = #{projectCategoryId}
  293. </if>
  294. <if test="projectIds != null">
  295. and a.id in
  296. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  297. #{item}
  298. </foreach>
  299. </if>
  300. <if test="userIdList != null and userIdList.size()>0">
  301. AND b.creator_id in
  302. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  303. #{item}
  304. </foreach>
  305. </if>
  306. <if test="startDate != null and endDate != null">
  307. AND b.create_date between #{startDate} and #{endDate}
  308. </if>
  309. <if test="deptIds!=null and deptIds.size()>0">
  310. and b.dept_id in
  311. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  312. #{item}
  313. </foreach>
  314. </if>
  315. AND b.state = 1
  316. GROUP BY a.category
  317. ORDER BY a.category ASC
  318. </select>
  319. <!--获取自定义数值的项目统计 -->
  320. <select id="getCustomDataSum" resultType="java.util.Map">
  321. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  322. FROM project AS a
  323. LEFT JOIN report AS b ON b.project_id = a.id
  324. JOIN user AS c ON b.creator_id = c.id
  325. WHERE a.company_id = #{companyId}
  326. <if test="projectId != null">
  327. AND a.id = #{projectId}
  328. </if>
  329. <if test="userId != null">
  330. AND b.creator_id = #{userId}
  331. </if>
  332. <if test="startDate != null and endDate != null">
  333. AND b.create_date between #{startDate} and #{endDate}
  334. </if>
  335. AND b.state = 1
  336. GROUP BY a.id
  337. having IFNULL(SUM(b.custom_data), 0) > 0
  338. ORDER BY SUM(b.custom_data) DESC
  339. </select>
  340. <!--获取日报的人员月度工时 -->
  341. <select id="getTimeCostReport" resultType="java.util.Map">
  342. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  343. FROM report AS a
  344. LEFT JOIN project AS b ON a.project_id = b.id
  345. LEFT JOIN user AS c ON a.creator_id = c.id
  346. WHERE b.company_id = #{companyId}
  347. <if test="projectId != null">
  348. AND b.id = #{projectId}
  349. </if>
  350. <if test="startDate != null and endDate != null">
  351. AND a.create_date between #{startDate} and #{endDate}
  352. </if>
  353. <if test="deptIds!=null and deptIds.size()>0">
  354. and a.dept_id in
  355. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  356. #{item}
  357. </foreach>
  358. </if>
  359. AND a.state = 1
  360. </select>
  361. <!--获取人员的月度总工时 -->
  362. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  363. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  364. FROM report AS a, user as b
  365. WHERE a.creator_id = b.id
  366. and b.company_id = #{companyId}
  367. <if test="startDate != null and endDate != null">
  368. AND a.create_date between #{startDate} and #{endDate}
  369. </if>
  370. AND a.state = 1
  371. group by a.creator_id
  372. </select>
  373. <!--获取某个项目每个人分别需要的工时-->
  374. <select id="getProjectCost" resultType="java.util.Map">
  375. SELECT b.id as creatorId,a.project_id as projectId, b.name,b.corpwx_userid as corpwxUserId,a.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  376. FROM report AS a
  377. JOIN user AS b ON a.creator_id = b.id
  378. left join department on department.department_id = a.dept_id
  379. WHERE a.company_id=#{companyId}
  380. <choose>
  381. <when test="stateKey!=null and stateKey==1">
  382. and a.state = 1
  383. </when>
  384. <otherwise>
  385. and (a.state = 1 or a.state =0)
  386. </otherwise>
  387. </choose>
  388. <if test="projectId != null">
  389. and a.project_id = #{projectId}
  390. </if>
  391. <if test="startDate != null and endDate != null">
  392. AND a.create_date between #{startDate} and #{endDate}
  393. </if>
  394. <if test="userIdList != null and userIdList.size()>0">
  395. AND a.creator_id in
  396. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  397. #{item}
  398. </foreach>
  399. </if>
  400. <choose>
  401. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  402. and a.dept_id in
  403. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  404. #{item}
  405. </foreach>
  406. </when>
  407. <otherwise>
  408. <if test="deptIds!=null and deptIds.size()>0">
  409. and a.dept_id in
  410. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  411. #{item}
  412. </foreach>
  413. </if>
  414. </otherwise>
  415. </choose>
  416. GROUP BY b.id
  417. <if test="withDept">
  418. , a.dept_id
  419. </if>
  420. ORDER BY b.id ASC
  421. <if test="withDept">
  422. , a.dept_id ASC
  423. </if>
  424. </select>
  425. <!--获取某个项目分类每个人分别需要的工时-->
  426. <select id="getProjectCostByCategory" resultType="java.util.Map">
  427. SELECT b.id as creatorId,ifnull(c.category_name,'未分类') as categoryName,ifnull(c.category,0) as category, b.name,a.dept_id as deptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  428. FROM report AS a
  429. JOIN user AS b ON a.creator_id = b.id
  430. left join department on department.department_id = a.dept_id
  431. left join project c on c.id=a.project_id
  432. WHERE a.company_id=#{companyId} and a.state = 1
  433. <if test="curProjectCategoryId != null">
  434. and c.category = #{curProjectCategoryId}
  435. </if>
  436. <if test="startDate != null and endDate != null">
  437. AND a.create_date between #{startDate} and #{endDate}
  438. </if>
  439. <if test="userId != null">
  440. AND a.creator_id = #{userId}
  441. </if>
  442. GROUP BY c.category, a.dept_id
  443. ORDER BY c.category ASC, a.dept_id ASC
  444. </select>
  445. <!--获取个人每个项目分别需要的工时-->
  446. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  447. SELECT b.id as creatorId,a.project_id as projectId, b.name,a.dept_id as deptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  448. FROM report AS a
  449. JOIN user AS b ON a.creator_id = b.id
  450. left join department on department.department_id = a.dept_id
  451. WHERE a.company_id=#{companyId} and a.state = 1
  452. <if test="projectId != null">
  453. and a.project_id = #{projectId}
  454. </if>
  455. <if test="startDate != null and endDate != null">
  456. AND a.create_date between #{startDate} and #{endDate}
  457. </if>
  458. <if test="userIdList != null and userIdList.size()>0">
  459. AND a.creator_id in
  460. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  461. #{item}
  462. </foreach>
  463. </if>
  464. <if test="deptIds!=null and deptIds.size()>0">
  465. and a.dept_id in
  466. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  467. #{item}
  468. </foreach>
  469. </if>
  470. GROUP BY b.id,a.project_id
  471. ORDER BY b.id ASC, a.dept_id ASC
  472. </select>
  473. <!--获取个人每个项目分类分别需要的工时-->
  474. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  475. SELECT a.creator_id as creatorId,ifnull(c.category_name,'未分类') as categoryName,ifnull(c.category,0) as category, b.name,a.dept_id as deptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  476. FROM report AS a
  477. JOIN user AS b ON a.creator_id = b.id
  478. left join department on department.department_id = a.dept_id
  479. left join project c on c.id=a.project_id
  480. WHERE a.company_id=#{companyId} and a.state = 1
  481. <if test="projectCategoryId != null">
  482. and c.category = #{projectCategoryId}
  483. </if>
  484. <if test="startDate != null and endDate != null">
  485. AND a.create_date between #{startDate} and #{endDate}
  486. </if>
  487. <if test="userIdList != null and userIdList.size()>0">
  488. AND a.creator_id in
  489. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  490. #{item}
  491. </foreach>
  492. </if>
  493. <if test="deptIds!=null and deptIds.size()>0">
  494. and a.dept_id in
  495. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  496. #{item}
  497. </foreach>
  498. </if>
  499. GROUP BY b.id,c.category
  500. ORDER BY b.id ASC, a.dept_id ASC
  501. </select>
  502. <!-- 获取人员在日报填写的自定义数值 -->
  503. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  504. SELECT b.id as creatorId,
  505. b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
  506. FROM report AS a
  507. JOIN user AS b ON a.creator_id = b.id
  508. left join department on department.department_id = b.department_id
  509. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  510. <if test="startDate != null and endDate != null">
  511. AND a.create_date between #{startDate} and #{endDate}
  512. </if>
  513. <if test="projectId != null">
  514. AND a.project_id = #{projectId}
  515. </if>
  516. <if test="userId != null">
  517. AND a.creator_id = #{userId}
  518. </if>
  519. <if test="deptIds != null">
  520. AND department.department_id in
  521. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  522. #{item}
  523. </foreach>
  524. </if>
  525. group by b.id
  526. ORDER BY b.id ASC
  527. </select>
  528. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  529. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  530. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  531. FROM report AS a
  532. JOIN user AS b ON a.creator_id = b.id
  533. left join department on department.department_id = b.department_id
  534. left join project on project.id = a.project_id
  535. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  536. <if test="startDate != null and endDate != null">
  537. AND a.create_date between #{startDate} and #{endDate}
  538. </if>
  539. <if test="projectId != null">
  540. AND a.project_id = #{projectId}
  541. </if>
  542. <if test="userId != null">
  543. AND a.creator_id = #{userId}
  544. </if>
  545. ORDER BY a.create_date desc
  546. </select>
  547. <!--按照项目内的阶段名称分组统计工时-->
  548. <select id="getCostInStage" resultType="java.util.Map">
  549. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  550. FROM report AS a
  551. WHERE a.project_id = #{projectId}
  552. AND a.state = 1
  553. <if test="startDate != null and endDate != null">
  554. AND a.create_date between #{startDate} and #{endDate}
  555. </if>
  556. GROUP BY a.stage
  557. ORDER BY a.stage ASC
  558. </select>
  559. <!--按照项目内的阶段名称分组统计工时-->
  560. <select id="getCostByGroup" resultType="java.util.Map">
  561. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  562. FROM report AS a
  563. left join task_group tg on tg.id=a.group_id
  564. WHERE a.project_id = #{projectId}
  565. AND a.state = 1
  566. <if test="startDate != null and endDate != null">
  567. AND a.create_date between #{startDate} and #{endDate}
  568. </if>
  569. <if test="gpIds != null">
  570. AND a.group_id in
  571. <foreach collection="gpIds" open="(" separator="," close=")" item="item">
  572. #{item}
  573. </foreach>
  574. </if>
  575. GROUP BY a.group_id
  576. ORDER BY a.group_id ASC
  577. </select>
  578. <!--获取全部人员工时 -->
  579. <select id="getAllMembCost" resultType="java.util.Map">
  580. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  581. FROM user AS b
  582. left JOIN report AS a ON a.creator_id = b.id
  583. WHERE a.state = 1
  584. and b.company_id = #{companyId}
  585. <if test="startDate != null and endDate != null">
  586. AND a.create_date between #{startDate} and #{endDate}
  587. </if>
  588. <if test="projectId != null">
  589. AND a.project_id = #{projectId}
  590. </if>
  591. GROUP BY b.id
  592. ORDER BY b.id ASC
  593. </select>
  594. <!--分页获取项目成本 -->
  595. <select id="getAllProjectCost" resultType="java.util.Map">
  596. SELECT id, project_code as projectCode, project_name as projectName,budget,
  597. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  598. FROM project WHERE project.`company_id` = #{companyId}
  599. and (project.status &lt;&gt; 3 or project.status is null)
  600. <if test="projectId != null">
  601. and project.id = #{projectId}
  602. </if>
  603. <if test="inchagerIds!=null and inchagerIds.size()>0">
  604. and project.id in
  605. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  606. #{item}
  607. </foreach>
  608. </if>
  609. order by project.is_public desc, project.id asc
  610. <if test="pageStart != null and pageSize != null">
  611. LIMIT #{pageStart},#{pageSize}
  612. </if>
  613. </select>
  614. <!--分页获取项目收支平衡 -->
  615. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  616. SELECT project.id, project_code, project_name,contract_amount, IFNULL(contract.payment, 0) as payment,
  617. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  618. FROM project
  619. left join contract on contract.project_id = project.id
  620. WHERE project.`company_id` = #{companyId}
  621. and (project.status &lt;&gt; 3 or project.status is null)
  622. <if test="projectId != null">
  623. and project.id = #{projectId}
  624. </if>
  625. <if test="inchagerIds!=null and inchagerIds.size()>0">
  626. and project.id in
  627. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  628. #{item}
  629. </foreach>
  630. </if>
  631. order by is_public desc, project.id asc
  632. <if test="pageStart != null and pageSize != null">
  633. LIMIT #{pageStart},#{pageSize}
  634. </if>
  635. </select>
  636. <select id="getProjectExpenseFee" resultType="java.util.Map">
  637. SELECT project_id as projectId,expense_sheet.type as typeId, expense_main_type.name as typeName, IFNULL(SUM(amount),0) AS amount FROM expense_item
  638. left join expense_sheet on expense_sheet.id = expense_item.`expense_id`
  639. left join expense_main_type on expense_main_type.id = expense_sheet.`type`
  640. WHERE expense_sheet.`company_id` = #{companyId} AND expense_sheet.id = expense_item.`expense_id`
  641. AND expense_sheet.status = 0
  642. and project_id in
  643. <foreach collection="projectIds" open="(" separator="," close=")" item="item">
  644. #{item}
  645. </foreach>
  646. GROUP BY project_id, expense_sheet.type
  647. </select>
  648. <!--分页获取客户项目的成本利润报表 -->
  649. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  650. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  651. SUM(contract_amount) AS contract_amount ,
  652. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man
  653. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  654. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  655. <if test="customerId!=null">
  656. and project.customer_id=#{customerId}
  657. </if>
  658. <if test="projectId!=null">
  659. and project.id=#{projectId}
  660. </if>
  661. GROUP BY customer_id
  662. <if test="pageStart != null and pageSize != null">
  663. LIMIT #{pageStart},#{pageSize}
  664. </if>
  665. </select>
  666. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  667. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  668. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  669. <if test="customerId!=null">
  670. and project.customer_id=#{customerId}
  671. </if>
  672. <if test="projectId!=null">
  673. and project.id=#{projectId}
  674. </if>
  675. </select>
  676. <!--分页获取项目收支平衡 -->
  677. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  678. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  679. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  680. FROM project WHERE project.`company_id` = #{companyId}
  681. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  682. #{item}
  683. </foreach>
  684. </select>
  685. <select id="getGanttData" resultType="java.util.Map">
  686. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  687. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  688. LEFT JOIN user ON user.id = participation.`user_id`
  689. LEFT JOIN project ON project.`id` = participation.`project_id`
  690. WHERE participation.`user_id` IN
  691. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  692. #{item}
  693. </foreach>
  694. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  695. ORDER BY participation.user_id, project.`plan_start_date`
  696. </select>
  697. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  698. SELECT user.`id` as user_id, user.`name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,task_executor.id as exe_id,
  699. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level FROM user
  700. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  701. left join task on task.id = task_executor.task_id
  702. LEFT JOIN project ON project.`id` = task.`project_id`
  703. WHERE user.`id` IN
  704. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  705. #{item}
  706. </foreach>
  707. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  708. and task.end_date is not null
  709. AND project.`status` = 1
  710. ORDER BY user.id, task.start_date
  711. </select>
  712. <select id="getTaskPlanByProject" resultType="java.util.Map">
  713. SELECT task.executor_id as user_id, task.executor_name as `name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,
  714. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  715. LEFT JOIN task ON task.project_id = project.id
  716. WHERE project.company_id = #{companyId}
  717. <if test="projectIds != null">
  718. and project.`id` IN
  719. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  720. #{item}
  721. </foreach>
  722. </if>
  723. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  724. and task.end_date is not null
  725. AND project.`status` = 1
  726. ORDER BY project.id, task.start_date
  727. </select>
  728. <!--获取加班统计报表 -->
  729. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  730. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  731. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  732. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  733. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  734. <!-- left join project on project.id = report.project_id-->
  735. <!-- WHERE report.is_overtime = 1-->
  736. <!-- and report.`state` = 1-->
  737. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  738. <!-- AND user.`company_id` = #{companyId}-->
  739. <!-- <if test="projectId != null">-->
  740. <!-- AND report.`project_id` = #{projectId}-->
  741. <!-- </if>-->
  742. <!-- <if test="userId != null">-->
  743. <!-- AND report.`creator_id` = #{userId}-->
  744. <!-- </if>-->
  745. <!-- GROUP BY report.creator_id-->
  746. <!-- </select>-->
  747. <!-- 获取某个员工的某时间段内的加班详情 -->
  748. <select id="getOvertimeDetail" resultType="java.util.Map">
  749. SELECT report.id AS reportId,date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  750. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  751. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  752. project.project_name as projectName,project.project_code as projectCode,
  753. IFNULL(report.overtime_cost, 0) AS cost,
  754. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName,
  755. (CASE WHEN rwo.`write_off`=1 THEN 1 ELSE 0 END) AS writeOffValue,rwo.creator_name as writeOffUser,date_format(rwo.`create_time`, '%Y-%m-%d %H:%i:%s') as writeOffTime,rwo.reason as writeOffReason
  756. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  757. left join project on project.id = report.project_id
  758. left join report_extra_degree on report_extra_degree.id = report.degree_id
  759. left join department on department.department_id = report.dept_id
  760. LEFT JOIN report_write_off rwo ON rwo.`report_id`=report.`id`
  761. WHERE report.is_overtime = 1
  762. and report.`state` = 1
  763. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  764. AND user.`company_id` = #{companyId}
  765. <if test="projectId != null">
  766. AND report.`project_id` = #{projectId}
  767. </if>
  768. <if test="userId != null">
  769. AND report.`creator_id` = #{userId}
  770. </if>
  771. <if test="branchDepartment!=null and branchDepartment.size()>0">
  772. and report.dept_id in
  773. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  774. #{item}
  775. </foreach>
  776. </if>
  777. <if test="deptIds!=null and deptIds.size()>0">
  778. and report.dept_id in
  779. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  780. #{item}
  781. </foreach>
  782. </if>
  783. <if test="writeOffValue!=null">
  784. <choose>
  785. <when test="writeOffValue==1">
  786. and rwo.write_off=1
  787. </when>
  788. <otherwise>
  789. and (rwo.write_off is null or rwo.write_off=0)
  790. </otherwise>
  791. </choose>
  792. </if>
  793. order by user.create_time asc, report.create_date desc
  794. </select>
  795. <!--获取人员工时-->
  796. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  797. SELECT report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.dingding_userid as corpDdUserId,user.job_number as jobNumber,
  798. user.department_id As deptId,
  799. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  800. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  801. ifnull(SUM(report.`working_time`),0) AS workingTime,
  802. ifnull(SUM(report.`overtime_hours`),0) AS overtimeHours
  803. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  804. left join project on project.id = report.project_id
  805. WHERE
  806. report.`state` = 1
  807. AND user.`is_active` = 1
  808. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  809. AND user.`company_id` =#{companyId}
  810. <if test="userId!=null">
  811. and user.id=#{userId}
  812. </if>
  813. <if test="projectId!=null">
  814. and project.id=#{projectId}
  815. </if>
  816. <if test="branchDepartment!=null and branchDepartment.size()>0">
  817. and report.dept_id in
  818. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  819. #{item}
  820. </foreach>
  821. </if>
  822. <if test="deptIds!=null and deptIds.size()>0">
  823. and report.dept_id in
  824. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  825. #{item}
  826. </foreach>
  827. </if>
  828. group by user.id
  829. order by user.create_time asc, report.create_date desc
  830. <if test="start!=null and size!=null">
  831. limit #{start},#{size}
  832. </if>
  833. </select>
  834. <select id="findCountWithUser" resultType="java.lang.Long">
  835. select count(*)
  836. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  837. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  838. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  839. ifnull(SUM(report.`working_time`),0) AS workingTime
  840. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  841. left join project on project.id = report.project_id
  842. WHERE
  843. report.`state` = 1
  844. AND user.`is_active` = 1
  845. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  846. AND user.`company_id` =#{companyId}
  847. <if test="userId!=null">
  848. and user.id=#{userId}
  849. </if>
  850. <if test="projectId!=null">
  851. and project.id=#{projectId}
  852. </if>
  853. <if test="departmentId!=null">
  854. and report.dept_id=#{departmentId}
  855. </if>
  856. <if test="deptIds!=null and deptIds.size()>0">
  857. and report.dept_id in
  858. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  859. #{item}
  860. </foreach>
  861. </if>
  862. group by user.id
  863. order by user.create_time asc, report.create_date desc
  864. <if test="start!=null and size!=null">
  865. limit #{start},#{size}
  866. </if>) as total
  867. </select>
  868. <!--按照项目内的阶段名称分组统计工时-->
  869. <select id="getDegreeCost" resultType="java.util.Map">
  870. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
  871. FROM report AS a
  872. left join report_extra_degree b on b.id = a.degree_id
  873. WHERE
  874. a.state = 1
  875. and a.company_id = #{companyId}
  876. <if test="departmentIds!=null and departmentIds.size()>0">
  877. and a.dept_id in
  878. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  879. #{item}
  880. </foreach>
  881. </if>
  882. <if test="projectId != null">
  883. and a.project_id = #{projectId}
  884. </if>
  885. <if test="userId != null and userId!=''">
  886. and a.creator_id = #{userId}
  887. </if>
  888. <if test="startDate != null and endDate != null">
  889. AND a.create_date between #{startDate} and #{endDate}
  890. </if>
  891. GROUP BY a.degree_id
  892. ORDER BY a.degree_id ASC
  893. </select>
  894. <!--项目导出数据-->
  895. <select id="getExportData" resultType="java.util.HashMap" >
  896. SELECT project.id, project_name, project_code,category_name,is_public,plan_start_date, d.name AS incharger_name,GROUP_CONCAT(u.name) AS participators,
  897. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  898. customer_name, associate_degree_names, provider_names,provider_ids
  899. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  900. LEFT JOIN participation c ON c.project_id = project.`id`
  901. LEFT JOIN user u ON u.id = c.user_id
  902. LEFT JOIN user d ON d.id = project.`incharger_id`
  903. WHERE project.`company_id` = #{companyId}
  904. <if test="userId != null" >
  905. and (project.creator_id = #{userId} or c.user_id = #{userId})
  906. </if>
  907. GROUP BY project.id
  908. </select>
  909. <!--按项目分组导出数据-->
  910. <select id="getExportGroupData" resultType="java.util.Map" >
  911. SELECT project_code AS projectCode,project_name AS projectName,task_group.`name` AS groupName,task_group.`incharger_id` AS inchargerId,
  912. GROUP_CONCAT(group_participator.`user_id`) AS participatorIds
  913. FROM task_group
  914. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  915. LEFT JOIN project ON task_group.project_id = project.id
  916. <if test="projectCategorySub!=null and projectCategorySub!=''">
  917. left join project_separate ps on ps.id=project.id
  918. </if>
  919. where project.company_id = #{companyId}
  920. <if test="projectCategorySub!=null and projectCategorySub!=''">
  921. and ps.project_category_sub=#{projectCategorySub}
  922. </if>
  923. GROUP BY task_group.id
  924. ORDER BY project_id
  925. </select>
  926. <!--分页获取项目工时成本预警表 -->
  927. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  928. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  929. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  930. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  931. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  932. AND project_id=project.id) AS costLimit,
  933. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  934. FROM project WHERE company_id=#{companyId}
  935. and (project.status &lt;&gt; 3 or project.status is null)
  936. <if test="projectId != null">
  937. and project.id = #{projectId}
  938. </if>
  939. <if test="pageStart != null and pageSize != null">
  940. LIMIT #{pageStart},#{pageSize}
  941. </if>
  942. </select>
  943. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  944. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  945. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  946. ON project_basecost_setting.id = project_basecost.`base_id` WHERE alarm_type=1 AND company_id=#{companyId} AND project_basecost.`project_id`=project.id) AS baseCost,
  947. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  948. ON project_basecost_setting.id = project_currentcost.`base_id` WHERE alarm_type=1 AND company_id=#{companyId} AND project_currentcost.`project_id`=project.id) AS baseCurcost,
  949. (SELECT IFNULL(SUM(cost), 0) FROM report WHERE report.`company_id` = #{companyId} AND project_id = project.id AND state=1 AND basecost_id >0) AS feeMan
  950. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  951. <if test="projectId != null">
  952. and project.id = #{projectId}
  953. </if>
  954. <if test="list!=null and list.size()>0">
  955. and project.id in
  956. <foreach collection="list" open="(" close=")" item="item" separator=",">
  957. #{item}
  958. </foreach>
  959. </if>
  960. <if test="pageStart != null and pageSize != null">
  961. LIMIT #{pageStart},#{pageSize}
  962. </if>
  963. </select>
  964. <select id="getWaitingReviewList" resultType="java.util.Map">
  965. <choose>
  966. <when test="stateKey==0">
  967. SELECT dept_manager.name as userName,`user`.corpwx_userid as corpwxUserId,IFNULL(department.department_id,0) as deptId,department.corpwx_deptid as wxDeptId,COUNT(1) as num
  968. FROM report AS a
  969. left join user on user.id = a.creator_id
  970. JOIN project AS b ON a.project_id=b.id
  971. left join sub_project as d on d.id = a.sub_project_id
  972. left join task on task.id = a.task_id
  973. left join report_extra_degree on report_extra_degree.id = a.degree_id
  974. left join department on department.department_id = a.audit_deptid
  975. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  976. left join department dept on dept.department_id = a.dept_id
  977. left join task_group on task_group.id = a.group_id
  978. left join user u on u.id = a.project_auditor_id
  979. WHERE a.company_id =#{companyId}
  980. and a.state = 0
  981. <if test="startDate!=null and endDate!=null">
  982. AND a.create_date between #{startDate} and #{endDate}
  983. </if>
  984. AND a.is_dept_audit=1
  985. <if test="userId!=null">
  986. and dept_manager.id=#{userId}
  987. </if>
  988. <if test="departmentId!=null">
  989. and dept_manager.department_id=#{departmentId}
  990. </if>
  991. <if test="deptIds!=null and deptIds.size()>0">
  992. and dept_manager.department_id in
  993. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  994. #{item}
  995. </foreach>
  996. </if>
  997. group by a.audit_dept_managerid
  998. ORDER BY a.create_date desc, a.creator_id asc
  999. </when>
  1000. <otherwise>
  1001. SELECT u.name as userName,u.corpwx_userid as corpwxUserId,IFNULL(dp.department_id,0) as deptId,dp.corpwx_deptid as wxDeptId,COUNT(1) as num
  1002. FROM report AS a
  1003. left join user on user.id = a.creator_id
  1004. JOIN project AS b ON a.project_id=b.id
  1005. left join sub_project as d on d.id = a.sub_project_id
  1006. left join task on task.id = a.task_id
  1007. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1008. left join department on department.department_id = a.audit_deptid
  1009. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1010. left join department dept on dept.department_id = a.dept_id
  1011. left join task_group on task_group.id = a.group_id
  1012. left join user u on u.id = a.project_auditor_id
  1013. left join department dp on u.department_id=dp.department_id
  1014. WHERE a.company_id =#{companyId}
  1015. and a.state = 0
  1016. <if test="startDate!=null and endDate!=null">
  1017. AND a.create_date between #{startDate} and #{endDate}
  1018. </if>
  1019. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1020. <if test="userId!=null">
  1021. and u.id=#{userId}
  1022. </if>
  1023. <if test="departmentId!=null">
  1024. and u.department_id=#{departmentId}
  1025. </if>
  1026. <if test="deptIds!=null and deptIds.size()>0">
  1027. and u.department_id in
  1028. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1029. #{item}
  1030. </foreach>
  1031. </if>
  1032. group by a.project_auditor_id
  1033. ORDER BY a.create_date desc, a.creator_id asc
  1034. </otherwise>
  1035. </choose>
  1036. <if test="start!=null and size!=null">
  1037. limit #{start},#{size}
  1038. </if>
  1039. </select>
  1040. <select id="findCount" resultType="java.lang.Long">
  1041. select count(1)
  1042. from (<choose>
  1043. <when test="stateKey==0">
  1044. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  1045. FROM report AS a
  1046. left join user on user.id = a.creator_id
  1047. JOIN project AS b ON a.project_id=b.id
  1048. left join sub_project as d on d.id = a.sub_project_id
  1049. left join task on task.id = a.task_id
  1050. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1051. left join department on department.department_id = a.audit_deptid
  1052. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1053. left join department dept on dept.department_id = a.dept_id
  1054. left join task_group on task_group.id = a.group_id
  1055. left join user u on u.id = a.project_auditor_id
  1056. WHERE a.company_id =#{companyId}
  1057. and a.state = 0
  1058. and u.is_active = 1
  1059. <if test="startDate!=null and endDate!=null">
  1060. AND a.create_date between #{startDate} and #{endDate}
  1061. </if>
  1062. AND a.is_dept_audit=1
  1063. <if test="userId!=null">
  1064. and dept_manager.id=#{userId}
  1065. </if>
  1066. <if test="departmentId!=null">
  1067. and dept_manager.department_id=#{departmentId}
  1068. </if>
  1069. <if test="deptIds!=null and deptIds.size()>0">
  1070. and dept_manager.department_id in
  1071. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1072. #{item}
  1073. </foreach>
  1074. </if>
  1075. group by a.audit_dept_managerid
  1076. ORDER BY a.create_date desc, a.creator_id asc
  1077. </when>
  1078. <otherwise>
  1079. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1080. FROM report AS a
  1081. left join user on user.id = a.creator_id
  1082. JOIN project AS b ON a.project_id=b.id
  1083. left join sub_project as d on d.id = a.sub_project_id
  1084. left join task on task.id = a.task_id
  1085. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1086. left join department on department.department_id = a.audit_deptid
  1087. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1088. left join department dept on dept.department_id = a.dept_id
  1089. left join task_group on task_group.id = a.group_id
  1090. left join user u on u.id = a.project_auditor_id
  1091. left join department dp on u.department_id=dp.department_id
  1092. WHERE a.company_id =#{companyId}
  1093. and a.state = 0
  1094. and u.is_active = 1
  1095. <if test="startDate!=null and endDate!=null">
  1096. AND a.create_date between #{startDate} and #{endDate}
  1097. </if>
  1098. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1099. <if test="userId!=null">
  1100. and u.id=#{userId}
  1101. </if>
  1102. <if test="departmentId!=null">
  1103. and u.department_id=#{departmentId}
  1104. </if>
  1105. <if test="deptIds!=null and deptIds.size()>0">
  1106. and u.department_id in
  1107. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1108. #{item}
  1109. </foreach>
  1110. </if>
  1111. group by a.project_auditor_id
  1112. ORDER BY a.create_date desc, a.creator_id asc
  1113. </otherwise>
  1114. </choose>
  1115. <if test="start!=null and size!=null">
  1116. limit #{start},#{size}
  1117. </if>) total
  1118. </select>
  1119. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1120. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1121. (select SUM(te.plan_hours) from task_executor te
  1122. left join task on task.id=te.task_id
  1123. where te.executor_id=us.id
  1124. <if test="startDate!=null and endDate!=null">
  1125. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1126. </if>) as planHours,
  1127. (select SUM(report.working_time) from report
  1128. left join task on task.id=report.task_id
  1129. where report.creator_id=us.id and task_id is not null and report.state=1
  1130. <if test="startDate!=null and endDate!=null">
  1131. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1132. </if>) as workingTime
  1133. from user us
  1134. left join department dp on dp.department_id=us.department_id
  1135. where us.company_id=#{companyId}
  1136. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1137. <if test="userId!=null and userId!=''">
  1138. and us.id=#{userId}
  1139. </if>
  1140. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1141. and us.department_id in
  1142. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1143. #{item}
  1144. </foreach>
  1145. </if>
  1146. <if test="deptIds!=null and deptIds.size()>0">
  1147. and us.department_id in
  1148. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1149. #{item}
  1150. </foreach>
  1151. </if>
  1152. group by us.id
  1153. order by us.department_id
  1154. <if test="start!=null and size!=null">
  1155. limit #{start},#{size}
  1156. </if>
  1157. </select>
  1158. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1159. select count(1)
  1160. from(select us.name,dp.department_name as departmentName,
  1161. (select SUM(te.plan_hours) from task_executor te
  1162. left join task on task.id=te.task_id
  1163. where te.executor_id=us.id
  1164. <if test="startDate!=null and endDate!=null">
  1165. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1166. </if>) as planHours,
  1167. (select SUM(report.working_time) from report
  1168. left join task on task.id=report.task_id
  1169. where report.creator_id=us.id and task_id is not null
  1170. <if test="startDate!=null and endDate!=null">
  1171. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1172. </if>) as workingTime
  1173. from user us
  1174. left join department dp on dp.department_id=us.department_id
  1175. where us.company_id=#{companyId}
  1176. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1177. <if test="userId!=null and userId!=''">
  1178. and us.id=#{userId}
  1179. </if>
  1180. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1181. and us.department_id in
  1182. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1183. #{item}
  1184. </foreach>
  1185. </if>
  1186. <if test="deptIds!=null and deptIds.size()>0">
  1187. and us.department_id in
  1188. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1189. #{item}
  1190. </foreach>
  1191. </if>
  1192. group by us.id
  1193. order by us.department_id)as total
  1194. </select>
  1195. <select id="selectWithGroup" resultType="java.util.Map">
  1196. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1197. from report a
  1198. left join task_group b on a.group_id=b.id
  1199. left join project c on a.project_id=c.id
  1200. where c.company_id=#{companyId} and a.state=1
  1201. <if test="startDate!=null and endDate!=null">
  1202. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1203. </if>
  1204. <if test="projectId!=null">
  1205. and c.id=#{projectId}
  1206. </if>
  1207. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1208. and (c.id in
  1209. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1210. #{item}
  1211. </foreach>
  1212. <!--或者按分组负责人的匹配-->
  1213. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1214. or a.group_id in
  1215. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1216. #{item}
  1217. </foreach>
  1218. </if>
  1219. )
  1220. </if>
  1221. <if test="groupId!=null">
  1222. and a.group_id=#{groupId}
  1223. </if>
  1224. group by b.name
  1225. order by c.id
  1226. <if test="startIndex!=null and endIndex!=null">
  1227. limit #{startIndex},#{endIndex}
  1228. </if>
  1229. </select>
  1230. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1231. select count(1) from(
  1232. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1233. from report a
  1234. left join task_group b on a.group_id=b.id
  1235. left join project c on a.project_id=c.id
  1236. where c.company_id=#{companyId} and a.state=1
  1237. <if test="startDate!=null and endDate!=null">
  1238. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1239. </if>
  1240. <if test="projectId!=null">
  1241. and c.id=#{projectId}
  1242. </if>
  1243. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1244. and (c.id in
  1245. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1246. #{item}
  1247. </foreach>
  1248. <!--或者按分组负责人的匹配-->
  1249. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1250. or a.group_id in
  1251. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1252. #{item}
  1253. </foreach>
  1254. </if>
  1255. )
  1256. </if>
  1257. <if test="groupId!=null">
  1258. and a.group_id=#{groupId}
  1259. </if>
  1260. group by b.name
  1261. order by c.id
  1262. <if test="startIndex!=null and endIndex!=null">
  1263. limit #{startIndex},#{endIndex}
  1264. </if>) as total
  1265. </select>
  1266. <select id="selectWithGroupProject" resultType="java.util.Map">
  1267. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1268. from report a
  1269. left join task_group b on a.group_id=b.id
  1270. left join project c on a.project_id=c.id
  1271. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1272. left join project_separate ps on ps.id=c.id
  1273. </if>
  1274. where c.company_id=#{companyId} and a.state=1
  1275. <if test="startDate!=null and endDate!=null">
  1276. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1277. </if>
  1278. <if test="projectId!=null">
  1279. and c.id=#{projectId}
  1280. </if>
  1281. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1282. and ps.project_category_sub=#{projectCategorySub}
  1283. </if>
  1284. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1285. and (c.id in
  1286. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1287. #{item}
  1288. </foreach>
  1289. <!--或者按分组负责人的匹配-->
  1290. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1291. or a.group_id in
  1292. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1293. #{item}
  1294. </foreach>
  1295. </if>
  1296. )
  1297. </if>
  1298. <if test="groupId!=null">
  1299. and a.group_id=#{groupId}
  1300. </if>
  1301. group by c.id,b.id
  1302. order by c.id
  1303. <if test="startIndex!=null and endIndex!=null">
  1304. limit #{startIndex},#{endIndex}
  1305. </if>
  1306. </select>
  1307. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1308. select count(1) from(
  1309. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1310. from report a
  1311. left join task_group b on a.group_id=b.id
  1312. left join project c on a.project_id=c.id
  1313. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1314. left join project_separate ps on ps.id=c.id
  1315. </if>
  1316. where c.company_id=#{companyId} and a.state=1
  1317. <if test="startDate!=null and endDate!=null">
  1318. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1319. </if>
  1320. <if test="projectId!=null">
  1321. and c.id=#{projectId}
  1322. </if>
  1323. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1324. and ps.project_category_sub=#{projectCategorySub}
  1325. </if>
  1326. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1327. and (c.id in
  1328. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1329. #{item}
  1330. </foreach>
  1331. <!--或者按分组负责人的匹配-->
  1332. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1333. or a.group_id in
  1334. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1335. #{item}
  1336. </foreach>
  1337. </if>
  1338. )
  1339. </if>
  1340. <if test="groupId!=null">
  1341. and a.group_id=#{groupId}
  1342. </if>
  1343. group by c.id,b.id
  1344. order by c.id
  1345. <if test="startIndex!=null and endIndex!=null">
  1346. limit #{startIndex},#{endIndex}
  1347. </if>) as total
  1348. </select>
  1349. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1350. select c.id as projectId,c.project_name as projectName,c.project_code as projectCode,IFNULL(b.name,'未分组') as groupName,SUM(a.working_time) as workingTime,ifnull(b.id,0) as groupId
  1351. from report a
  1352. left join task_group b on a.group_id=b.id
  1353. left join project c on a.project_id=c.id
  1354. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1355. where c.company_id=#{companyId} and a.state=1
  1356. <if test="startDate!=null and endDate!=null">
  1357. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1358. </if>
  1359. <if test="projectId!=null">
  1360. and c.id=#{projectId}
  1361. </if>
  1362. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1363. and c.id in
  1364. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1365. #{item}
  1366. </foreach>
  1367. </if>
  1368. <if test="gpNamesList !=null">
  1369. and b.name in
  1370. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1371. #{item}
  1372. </foreach>
  1373. </if>
  1374. group by c.id,b.id
  1375. <if test="start!=null and size!=null">
  1376. limit #{start},#{size}
  1377. </if>
  1378. </select>
  1379. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1380. select count(1) from
  1381. (select c.id as projectId,c.project_name as projectName,c.project_code as projectCode,IFNULL(b.name,'未分组') as groupName,SUM(a.working_time) as workingTime,ifnull(b.id,0) as groupId
  1382. from report a
  1383. left join task_group b on a.group_id=b.id
  1384. left join project c on a.project_id=c.id
  1385. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1386. where c.company_id=#{companyId} and a.state=1
  1387. <if test="startDate!=null and endDate!=null">
  1388. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1389. </if>
  1390. <if test="projectId!=null">
  1391. and c.id=#{projectId}
  1392. </if>
  1393. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1394. and c.id in
  1395. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1396. #{item}
  1397. </foreach>
  1398. </if>
  1399. <if test="gpNamesList !=null">
  1400. and b.name in
  1401. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1402. #{item}
  1403. </foreach>
  1404. </if>
  1405. group by c.id,b.id
  1406. <if test="start!=null and size!=null">
  1407. limit #{start},#{size}
  1408. </if>) as total
  1409. </select>
  1410. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1411. select c.id as projectId,ifnull(b.id,0) as groupId,c.project_name as projectName,c.project_code as projectCode,SUM(a.working_time) as workingTime,IFNULL(f.stages_name,'非阶段') as stagesName
  1412. from report a
  1413. left join task_group b on a.group_id=b.id
  1414. left join project c on a.project_id=c.id
  1415. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1416. where c.company_id=#{companyId} and a.state=1
  1417. <if test="startDate!=null and endDate!=null">
  1418. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1419. </if>
  1420. <if test="projectId!=null">
  1421. and c.id=#{projectId}
  1422. </if>
  1423. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1424. and c.id in
  1425. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1426. #{item}
  1427. </foreach>
  1428. </if>
  1429. <if test="gpNamesList !=null">
  1430. and b.name in
  1431. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1432. #{item}
  1433. </foreach>
  1434. </if>
  1435. group by c.id,f.id
  1436. <if test="start!=null and size!=null">
  1437. limit #{start},#{size}
  1438. </if>
  1439. </select>
  1440. <select id="getCostByUserCustom" resultType="java.util.Map">
  1441. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1442. FROM user AS a
  1443. LEFT JOIN report AS b ON a.id = b.creator_id
  1444. LEFT JOIN project AS c ON b.project_id = c.id
  1445. left join user_custom uc on uc.company_id=a.company_id
  1446. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1447. WHERE b.state = 1
  1448. AND a.company_id = #{companyId}
  1449. <if test="startDate!=null and endDate!=null">
  1450. AND b.create_date between #{startDate} and #{endDate}
  1451. </if>
  1452. and uc.id=#{customId}
  1453. <if test="deptIds!=null and deptIds.size()>0">
  1454. and a.department_id in
  1455. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1456. #{item}
  1457. </foreach>
  1458. </if>
  1459. <if test="subCustomName!=null">
  1460. and suc.name=#{subCustomName}
  1461. </if>
  1462. GROUP BY suc.name
  1463. </select>
  1464. <select id="getEmpMonthHours" resultType="java.util.Map">
  1465. select us.id as userId,us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1466. (select allday from time_type te
  1467. where te.company_id=#{companyId}) as allday,
  1468. (select SUM(report.working_time) from report
  1469. where report.creator_id=us.id and report.state=1
  1470. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1471. as workingTime
  1472. from user us
  1473. left join department dp on dp.department_id=us.department_id
  1474. where us.company_id=#{companyId}
  1475. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1476. <if test="userId!=null and userId!=''">
  1477. and us.id=#{userId}
  1478. </if>
  1479. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1480. and us.department_id in
  1481. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1482. #{item}
  1483. </foreach>
  1484. </if>
  1485. <if test="deptIds!=null and deptIds.size()>0">
  1486. and us.department_id in
  1487. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1488. #{item}
  1489. </foreach>
  1490. </if>
  1491. group by us.id
  1492. order by us.department_id
  1493. <if test="start!=null and size!=null">
  1494. limit #{start},#{size}
  1495. </if>
  1496. </select>
  1497. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1498. select count(1)
  1499. from(select us.name,dp.department_name as departmentName,
  1500. (select SUM(report.working_time) from report
  1501. where report.creator_id=us.id
  1502. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1503. as workingTime
  1504. from user us
  1505. left join department dp on dp.department_id=us.department_id
  1506. where us.company_id=#{companyId}
  1507. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1508. <if test="userId!=null and userId!=''">
  1509. and us.id=#{userId}
  1510. </if>
  1511. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1512. and us.department_id in
  1513. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1514. #{item}
  1515. </foreach>
  1516. </if>
  1517. <if test="deptIds!=null and deptIds.size()>0">
  1518. and us.department_id in
  1519. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1520. #{item}
  1521. </foreach>
  1522. </if>
  1523. group by us.id
  1524. order by us.department_id)as total
  1525. </select>
  1526. <!-- 分页查询部门参与项目情况-->
  1527. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1528. SELECT department.department_id deptId,
  1529. department_name deptName,
  1530. (select count(user.id) from user where user.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0) AND user.department_id = department.department_id group by user.department_id) deptHeadCount,
  1531. pro.projectCount projectCount,
  1532. pro.centerCount centerCount,
  1533. pcon.peopleCount peopleCount
  1534. FROM department
  1535. LEFT JOIN (
  1536. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1537. COUNT(DISTINCT(r.degree_id)) centerCount
  1538. FROM report
  1539. LEFT JOIN report r
  1540. ON report.id = r.id AND r.degree_id != -1
  1541. LEFT JOIN `user`
  1542. ON report.creator_id = user.id
  1543. WHERE report.state = 1
  1544. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1545. GROUP BY dept_id
  1546. ) pro
  1547. on pro.dept_id = department.department_id
  1548. LEFT JOIN (
  1549. SELECT dept_id,sum(p.con) peopleCount
  1550. FROM (
  1551. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1552. LEFT JOIN `user`
  1553. ON report.creator_id = user.id
  1554. WHERE report.state = 1
  1555. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1556. GROUP BY report.creator_id,dept_id
  1557. ) p GROUP BY p.dept_id
  1558. ) pcon
  1559. ON pcon.dept_id = department.department_id
  1560. WHERE department.company_id = #{companyId}
  1561. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1562. and department.department_id in
  1563. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1564. #{item}
  1565. </foreach>
  1566. </if>
  1567. <if test="deptIds!=null and deptIds.size()>0">
  1568. and department.department_id in
  1569. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1570. #{item}
  1571. </foreach>
  1572. </if>
  1573. <if test="size!=null and start!=null">
  1574. limit #{start},#{size}
  1575. </if>
  1576. </select>
  1577. <!--获取按项目分组的工时成本-->
  1578. <select id="getExportDegreeCost" resultType="java.util.Map">
  1579. SELECT a.id, a.project_code as projectCode, a.project_name AS projectName, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName
  1580. FROM project AS a
  1581. LEFT JOIN report AS b ON b.project_id = a.id
  1582. JOIN user AS c ON b.creator_id = c.id
  1583. WHERE a.company_id = #{companyId}
  1584. <if test="projectId != null">
  1585. AND a.id = #{projectId}
  1586. </if>
  1587. <if test="startDate != null and endDate != null">
  1588. AND b.create_date between #{startDate} and #{endDate}
  1589. </if>
  1590. <choose>
  1591. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1592. and b.dept_id in
  1593. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1594. #{item}
  1595. </foreach>
  1596. </when>
  1597. <otherwise>
  1598. <if test="deptIds!=null and deptIds.size()>0">
  1599. and (b.dept_id in
  1600. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1601. #{item}
  1602. </foreach>
  1603. <if test="deptRelatedProjectIds.size() > 0">
  1604. or a.id in
  1605. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  1606. #{pid}
  1607. </foreach>
  1608. </if>
  1609. )
  1610. </if>
  1611. </otherwise>
  1612. </choose>
  1613. AND b.state = 1
  1614. GROUP BY a.id
  1615. ORDER BY a.id ASC
  1616. </select>
  1617. <!--获取某个项目每个维度分别需要的工时-->
  1618. <select id="getDegreeDetailCost" resultType="java.util.Map">
  1619. SELECT b.id as creatorId,a.project_id as projectId, b.name,b.corpwx_userid as corpwxUserId,a.dept_id as deptId,department.corpwx_deptid as corpwxDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney,r.name as degreeName
  1620. FROM report AS a
  1621. JOIN user AS b ON a.creator_id = b.id
  1622. left join department on department.department_id = a.dept_id
  1623. left join report_extra_degree as r on a.degree_id = r.id
  1624. WHERE a.company_id=#{companyId}
  1625. <if test="curProjectId != null">
  1626. and a.project_id = #{curProjectId}
  1627. </if>
  1628. <if test="projectId != null">
  1629. and a.project_id = #{projectId}
  1630. </if>
  1631. <if test="startDate != null and endDate != null">
  1632. AND a.create_date between #{startDate} and #{endDate}
  1633. </if>
  1634. <choose>
  1635. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1636. and a.dept_id in
  1637. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1638. #{item}
  1639. </foreach>
  1640. </when>
  1641. <otherwise>
  1642. <if test="deptIds!=null and deptIds.size()>0">
  1643. and a.dept_id in
  1644. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1645. #{item}
  1646. </foreach>
  1647. </if>
  1648. </otherwise>
  1649. </choose>
  1650. GROUP BY a.project_id,b.id,a.degree_id
  1651. ORDER BY b.id,a.degree_id ASC
  1652. </select>
  1653. <select id="selectNearProject" resultType="com.management.platform.entity.Project">
  1654. SELECT * FROM project
  1655. WHERE STATUS = 1 AND id IN (
  1656. SELECT project_id
  1657. FROM (
  1658. SELECT DISTINCT report.project_id
  1659. FROM report
  1660. WHERE creator_id = #{userId}
  1661. GROUP BY project_id
  1662. ORDER BY MAX(create_time)
  1663. DESC LIMIT 3
  1664. ) p2
  1665. ) AND id IN(SELECT project_id FROM participation WHERE user_id=#{userId})
  1666. </select>
  1667. <select id="getFTEData" resultType="java.util.Map">
  1668. SELECT u.id,u.name userName,d.department_name as departmentName,d.corpwx_deptid as wxdeptId,u.corpwx_userid as wxUserId,IF(u.plate1 IS NULL OR u.plate1='' ,'无',u.plate1) as area,IFNULL(r.projectName,'') as projectName,
  1669. IFNULL(r.projectCode,'') as projectCode,IFNULL(r.workTime,0) as workTime,IFNULL(t.nonProjectWorkingTime,0) as nonProjectWorkingTime
  1670. FROM `user` u
  1671. LEFT JOIN department d on u.department_id=d.department_id
  1672. LEFT JOIN (
  1673. SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
  1674. FROM report
  1675. LEFT JOIN project p
  1676. ON report.project_id = p.id
  1677. LEFT JOIN `user`
  1678. ON user.id = report.creator_id
  1679. WHERE report.state = 1
  1680. AND p.is_public = 0
  1681. AND report.company_id=#{companyId}
  1682. AND
  1683. (
  1684. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate} and user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1685. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1686. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1687. and
  1688. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1689. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1690. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1691. and
  1692. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1693. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1694. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1695. )
  1696. GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
  1697. ) r
  1698. ON u.id = r.creator_id
  1699. LEFT JOIN (
  1700. SELECT report.creator_id,SUM(working_time) nonProjectWorkingTime
  1701. FROM report
  1702. LEFT JOIN project p
  1703. ON report.project_id = p.id
  1704. LEFT JOIN `user`
  1705. ON user.id = report.creator_id
  1706. WHERE report.state = 1
  1707. AND p.is_public = 1
  1708. AND report.company_id=#{companyId}
  1709. AND
  1710. (
  1711. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate} and user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1712. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1713. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1714. and
  1715. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1716. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1717. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1718. and
  1719. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1720. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1721. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1722. )
  1723. GROUP BY user.id
  1724. ) t
  1725. ON u.id = t.creator_id
  1726. WHERE u.company_id=#{companyId}
  1727. AND (workTime>0 OR u.`is_active`=1)
  1728. <if test="area!=null and area != '' ">
  1729. and u.plate1 = #{area}
  1730. </if>
  1731. <if test="userId!=null and userId != '' ">
  1732. and u.id = #{userId}
  1733. </if>
  1734. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1735. and u.department_id in
  1736. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1737. #{item}
  1738. </foreach>
  1739. </if>
  1740. <if test="deptIds!=null and deptIds.size()>0">
  1741. and u.department_id in
  1742. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1743. #{item}
  1744. </foreach>
  1745. </if>
  1746. <!-- <if test="departmentId!=null">-->
  1747. <!-- and u.department_id=#{departmentId}-->
  1748. <!-- </if>-->
  1749. <if test="sortProp!=null and sortProp!=''">
  1750. <choose>
  1751. <when test="sortOrder==0">
  1752. order by id desc
  1753. </when>
  1754. <otherwise>
  1755. order by id
  1756. </otherwise>
  1757. </choose>
  1758. </if>
  1759. <if test="start!=null and size!=null">
  1760. limit #{start},#{size}
  1761. </if>
  1762. </select>
  1763. <!--获取查询者所在公司每个项目的工时成本-->
  1764. <select id="getTimeCostByToken" resultType="java.util.Map">
  1765. SELECT a.id, a.project_code as projectCode, a.project_name AS project, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,c.job_number as userJobNumber,d.department_name as departmentName
  1766. FROM project AS a
  1767. LEFT JOIN report AS b ON b.project_id = a.id
  1768. JOIN user AS c ON b.creator_id = c.id
  1769. JOIN department d on d.department_id=c.department_id
  1770. WHERE a.company_id = #{companyId}
  1771. <if test="startDate != null and endDate != null">
  1772. AND b.create_date between #{startDate} and #{endDate}
  1773. </if>
  1774. AND b.state = 1
  1775. GROUP BY a.id,b.creator_id
  1776. ORDER BY a.id ASC
  1777. </select>
  1778. <!--获取员工的项目分类工时统计数据 -->
  1779. <select id="getMembProjectCateTime" resultType="com.management.platform.entity.vo.UserCateTimeVo">
  1780. SELECT user.id AS userId,user.plate1 as plate1,user.plate2 as plate2,user.plate3 as plate3,user.plate4 as plate4,user.plate5 as plate5, user.`name`, project.`category`, project.`category_name` AS categoryName, SUM(report.`working_time`) AS workingTime
  1781. FROM report
  1782. LEFT JOIN `user` ON user.id = report.`creator_id`
  1783. LEFT JOIN project ON project.id = report.`project_id`
  1784. WHERE report.`company_id` = #{companyId}
  1785. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  1786. AND report.state = 1
  1787. <if test="departmentId!=null">
  1788. AND user.department_id=#{departmentId}
  1789. </if>
  1790. <if test="subUserCustomName!=null and subUserCustomName!='' and plateString!=null">
  1791. <choose>
  1792. <when test="plateString==1">
  1793. AND user.plate1=#{subUserCustomName}
  1794. </when>
  1795. <when test="plateString==2">
  1796. AND user.plate2=#{subUserCustomName}
  1797. </when>
  1798. <when test="plateString==3">
  1799. AND user.plate3=#{subUserCustomName}
  1800. </when>
  1801. <when test="plateString==4">
  1802. AND user.plate4=#{subUserCustomName}
  1803. </when>
  1804. <otherwise>
  1805. AND user.plate5=#{subUserCustomName}
  1806. </otherwise>
  1807. </choose>
  1808. </if>
  1809. GROUP BY user.id, project.`category`
  1810. </select>
  1811. <select id="userProjectProcessList" resultType="java.util.Map">
  1812. select d.department_name as departmentName,d.corpwx_deptid as corpwxDeptId,u.corpwx_userid as corpwxUserId,u.name as userName,u.job_number as jobNumber,p.project_name as projectName,p.project_code as projectCode,
  1813. IFNULL(IFNULL(SUM(te.plan_hours),0)-IFNULL((select SUM(working_time) from report where task_id=te.task_id and state=1),0),0)as residueTime
  1814. from task_executor te
  1815. left join user u on u.id=te.executor_id
  1816. left join department d on d.department_id=u.department_id
  1817. left join project p on p.id=te.project_id
  1818. where u.company_id=#{companyId} and te.project_id is not null
  1819. <if test="deptId!=null">
  1820. and d.department_id=#{deptId}
  1821. </if>
  1822. <if test="userId!=null and userId!=''">
  1823. and u.id=#{userId}
  1824. </if>
  1825. <if test="projectId!=null">
  1826. and p.id=#{projectId}
  1827. </if>
  1828. <if test="list!=null and list.size()>0">
  1829. and d.department_id in
  1830. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1831. #{item}
  1832. </foreach>
  1833. </if>
  1834. <if test="listSecond!=null and listSecond.size()>0">
  1835. and d.department_id in
  1836. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1837. #{item}
  1838. </foreach>
  1839. </if>
  1840. group by te.executor_id,te.project_id
  1841. order by d.department_id,u.id
  1842. <if test="start!=null and size!=null">
  1843. limit #{start},#{size}
  1844. </if>
  1845. </select>
  1846. <select id="userProjectProcessCount" resultType="java.lang.Long">
  1847. select count(1) from (
  1848. select d.department_name as departmentName
  1849. from task_executor te
  1850. left join user u on u.id=te.executor_id
  1851. left join department d on d.department_id=u.department_id
  1852. left join project p on p.id=te.project_id
  1853. where u.company_id=#{companyId} and te.project_id is not null
  1854. <if test="deptId!=null">
  1855. and d.department_id=#{deptId}
  1856. </if>
  1857. <if test="userId!=null and userId!=''">
  1858. and u.id=#{userId}
  1859. </if>
  1860. <if test="projectId!=null">
  1861. and p.id=#{projectId}
  1862. </if>
  1863. <if test="list!=null and list.size()>0">
  1864. and d.department_id in
  1865. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1866. #{item}
  1867. </foreach>
  1868. </if>
  1869. <if test="listSecond!=null and listSecond.size()>0">
  1870. and d.department_id in
  1871. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1872. #{item}
  1873. </foreach>
  1874. </if>
  1875. group by te.executor_id,te.project_id
  1876. ) as total
  1877. </select>
  1878. <select id="groupExpendProcessList" resultType="java.util.Map">
  1879. SELECT p.project_name AS projectName,p.id AS projectId,tg.id AS groupId,d.department_name,d.department_id AS deptId,d.corpwx_deptid AS corpwxDeptId,tg.name AS groupName,
  1880. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) as normalHour,IFNULL(r.overHour,0) as overHour,
  1881. IFNULL(tg.man_day*8,0) AS planHour,IFNULL((SELECT SUM(change_man_day*8) FROM `group_budget_review` WHERE group_id=tg.`id` AND `status`=1),0) AS afterSetPlanHour
  1882. FROM task_group tg
  1883. LEFT JOIN task t ON tg.id = t.group_id
  1884. LEFT JOIN task_executor te ON t.id = te.task_id
  1885. LEFT JOIN user u
  1886. ON te.executor_id = u.id AND u.`company_id`=#{companyId}
  1887. LEFT JOIN project p ON p.id=tg.project_id
  1888. LEFT JOIN department d ON d.department_id=u.department_id
  1889. LEFT JOIN (
  1890. SELECT SUM(working_time) AS realHour,SUM(cost) AS realCost,(SUM(working_time)-SUM(overtime_hours)) AS normalHour,SUM(overtime_hours) AS overHour,group_id,dept_id
  1891. FROM report WHERE state=1
  1892. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1893. AND create_date BETWEEN #{startDate} AND #{endDate}
  1894. </if>
  1895. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id,dept_id) r ON r.group_id=tg.`id` and r.dept_id=u.department_id
  1896. WHERE p.company_id=#{companyId}
  1897. <if test="listFour!=null and listFour.size()>0">
  1898. AND tg.project_id in
  1899. <foreach collection="listFour" separator="," open="(" close=")" item="item">
  1900. #{item}
  1901. </foreach>
  1902. </if>
  1903. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1904. <if test="userId!=null and userId!=''">
  1905. and t.executor_id=#{userId}
  1906. </if>
  1907. GROUP BY p.id,tg.id,d.department_id ORDER BY p.id,d.department_id
  1908. </select>
  1909. <select id="groupExpendProcessListForChart" resultType="java.util.Map">
  1910. SELECT groupName,SUM(realHour) AS realHour,SUM(realCost) AS realCost,SUM(normalHour) AS normalHour,SUM(overHour) AS overHour,SUM(planHour) AS planHour,SUM(afterSetPlanHour) AS afterSetPlanHour
  1911. FROM (SELECT p.project_name AS projectName,p.id AS projectId,tg.id AS groupId,d.department_name,d.department_id AS deptId,d.corpwx_deptid AS corpwxDeptId,tg.name AS groupName,
  1912. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) AS normalHour,IFNULL(r.overHour,0) AS overHour,
  1913. IFNULL(tg.man_day*8,0) AS planHour,IFNULL((SELECT SUM(change_man_day*8) FROM `group_budget_review` WHERE group_id=tg.`id` AND `status`=1),0) AS afterSetPlanHour
  1914. FROM task_group tg
  1915. LEFT JOIN task t ON tg.id = t.group_id
  1916. LEFT JOIN task_executor te ON t.id = te.task_id
  1917. LEFT JOIN `user` u
  1918. ON te.executor_id = u.id AND u.`company_id`=#{companyId}
  1919. LEFT JOIN project p ON p.id=tg.project_id
  1920. LEFT JOIN department d ON d.department_id=u.department_id
  1921. LEFT JOIN (
  1922. SELECT SUM(working_time) AS realHour,SUM(cost) AS realCost,(SUM(working_time)-SUM(overtime_hours)) AS normalHour,SUM(overtime_hours) AS overHour,group_id,dept_id
  1923. FROM report WHERE state=1
  1924. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1925. AND create_date BETWEEN #{startDate} AND #{endDate}
  1926. </if>
  1927. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  1928. WHERE p.company_id=#{companyId}
  1929. <if test="listThird!=null and listThird.size()>0">
  1930. AND tg.project_id in
  1931. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  1932. #{item}
  1933. </foreach>
  1934. </if>
  1935. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1936. <if test="userId!=null and userId!=''">
  1937. and t.executor_id=#{userId}
  1938. </if>
  1939. GROUP BY tg.id ORDER BY p.id,d.department_id) AS t
  1940. <where>
  1941. <if test="listFour!=null and listFour.size()>0">
  1942. t.groupName in
  1943. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  1944. #{item}
  1945. </foreach>
  1946. </if>
  1947. </where>
  1948. GROUP BY t.groupName
  1949. </select>
  1950. <select id="groupExpendProcessListForUser" resultType="java.util.Map">
  1951. SELECT departmentId, departmentName,jobNumber,userName,
  1952. SUM(CASE WHEN groupName='方案设计' THEN workTime ELSE 0 END) AS '方案设计' ,
  1953. SUM(CASE WHEN groupName='研发部' THEN workTime ELSE 0 END) AS '研发部' ,
  1954. SUM(CASE WHEN groupName='研发部工艺调试' THEN workTime ELSE 0 END) AS '研发部工艺调试',
  1955. SUM(CASE WHEN groupName='研发部工艺调试验收' THEN workTime ELSE 0 END) AS '研发部工艺调试验收' ,
  1956. SUM(CASE WHEN groupName='研发部工艺设计' THEN workTime ELSE 0 END) AS '研发部工艺设计' ,
  1957. SUM(CASE WHEN groupName='研发部结构设计' THEN workTime ELSE 0 END) AS '研发部结构设计' ,
  1958. SUM(CASE WHEN groupName='研发部BIM设计' THEN workTime ELSE 0 END) AS '研发部BIM设计' ,
  1959. SUM(CASE WHEN groupName='研发部电气调试验收' THEN workTime ELSE 0 END) AS '研发部电气调试验收' ,
  1960. SUM(CASE WHEN groupName='研发部电气设计' THEN workTime ELSE 0 END) AS '研发部电气设计' ,
  1961. SUM(CASE WHEN groupName='研发部售后' THEN workTime ELSE 0 END) AS '研发部售后' ,
  1962. SUM(CASE WHEN groupName='工程部配合运维' THEN workTime ELSE 0 END) AS '工程部配合运维' ,
  1963. SUM(CASE WHEN groupName='研发部运维' THEN workTime ELSE 0 END) AS '研发部运维' ,
  1964. SUM(CASE WHEN groupName='生产部' THEN workTime ELSE 0 END) AS '生产部' ,
  1965. SUM(CASE WHEN groupName='生产部车间' THEN workTime ELSE 0 END) AS '生产部车间' ,
  1966. SUM(CASE WHEN groupName='生产部电气' THEN workTime ELSE 0 END) AS '生产部电气' ,
  1967. SUM(CASE WHEN groupName='工程部配合调试' THEN workTime ELSE 0 END) AS '工程部配合调试' ,
  1968. SUM(CASE WHEN groupName='工程部' THEN workTime ELSE 0 END) AS '工程部' ,
  1969. SUM(CASE WHEN groupName='工程部售后' THEN workTime ELSE 0 END) AS '工程部售后' ,
  1970. SUM(CASE WHEN groupName='工程部现场安装施工' THEN workTime ELSE 0 END) AS '工程部现场安装施工',
  1971. IFNULL(SUM(workTime),0) AS totalWorkTime
  1972. FROM (
  1973. SELECT d.`department_id` AS departmentId,d.`department_name` AS departmentName,u.`job_number` AS jobNumber,u.`name` AS userName ,tg.name AS groupName,rr.realHour AS workTime,u.id
  1974. FROM task_executor te
  1975. LEFT JOIN task t ON t.id=te.task_id
  1976. LEFT JOIN `user` u ON te.executor_id=u.id
  1977. LEFT JOIN task_group tg ON tg.id=t.group_id
  1978. LEFT JOIN project p ON p.id=tg.project_id
  1979. LEFT JOIN department d ON d.department_id=u.department_id
  1980. LEFT JOIN (
  1981. SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
  1982. FROM report r
  1983. LEFT JOIN task_group tg ON r.group_id=tg.`id`
  1984. WHERE r.state=1 AND r.project_id IS NOT NULL
  1985. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1986. AND r.create_date BETWEEN #{startDate} AND #{endDate}
  1987. </if> AND r.company_id=#{companyId}
  1988. GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
  1989. WHERE u.company_id=#{companyId}
  1990. <if test="listThird!=null and listThird.size()>0">
  1991. AND tg.project_id in
  1992. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  1993. #{item}
  1994. </foreach>
  1995. </if>
  1996. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1997. <if test="listFour!=null and listFour.size()>0">
  1998. and tg.name in
  1999. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2000. #{item}
  2001. </foreach>
  2002. </if>
  2003. GROUP BY u.`id`,tg.id
  2004. ) AS t
  2005. <where>
  2006. <if test="listFive!=null and listFive.size()>0">
  2007. t.departmentId in
  2008. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2009. #{item}
  2010. </foreach>
  2011. </if>
  2012. </where>
  2013. GROUP BY t.id
  2014. <if test="start!=null and size!=null">
  2015. limit #{start},#{size}
  2016. </if>
  2017. </select>
  2018. <select id="groupExpendProcessListForUserCount" resultType="java.lang.Integer">
  2019. select count(1) from (
  2020. SELECT departmentId,departmentName,jobNumber,userName,IFNULL(SUM(workTime),0) AS totalWorkTime
  2021. FROM (
  2022. SELECT d.`department_id` AS departmentId,d.`department_name` AS departmentName,u.`job_number` AS jobNumber,u.`name` AS userName ,tg.name AS groupName,rr.realHour AS workTime,u.id
  2023. FROM task_executor te
  2024. LEFT JOIN task t ON t.id=te.task_id
  2025. LEFT JOIN `user` u ON te.executor_id=u.id
  2026. LEFT JOIN task_group tg ON tg.id=t.group_id
  2027. LEFT JOIN project p ON p.id=tg.project_id
  2028. LEFT JOIN department d ON d.department_id=u.department_id
  2029. LEFT JOIN (
  2030. SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
  2031. FROM report r
  2032. LEFT JOIN task_group tg ON r.group_id=tg.`id`
  2033. WHERE r.state=1 AND r.project_id IS NOT NULL
  2034. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2035. AND r.create_date BETWEEN #{startDate} AND #{endDate}
  2036. </if> AND r.company_id=#{companyId}
  2037. GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
  2038. WHERE u.company_id=#{companyId}
  2039. <if test="listThird!=null and listThird.size()>0">
  2040. AND tg.project_id in
  2041. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2042. #{item}
  2043. </foreach>
  2044. </if>
  2045. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2046. <if test="listFour!=null and listFour.size()>0">
  2047. and tg.name in
  2048. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2049. #{item}
  2050. </foreach>
  2051. </if>
  2052. GROUP BY u.`id`,tg.id
  2053. ) AS t
  2054. <where>
  2055. <if test="listFive!=null and listFive.size()>0">
  2056. t.departmentId in
  2057. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2058. #{item}
  2059. </foreach>
  2060. </if>
  2061. </where>
  2062. GROUP BY t.id
  2063. ) as total
  2064. </select>
  2065. <select id="groupExpendProcessListForProject" resultType="java.util.Map">
  2066. SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
  2067. SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
  2068. IFNULL(r.realHour,0) AS realHour
  2069. FROM task_executor te
  2070. LEFT JOIN task t ON t.id=te.task_id
  2071. LEFT JOIN `user` u ON te.executor_id=u.id
  2072. LEFT JOIN task_group tg ON tg.id=t.group_id
  2073. LEFT JOIN project p ON p.id=tg.project_id
  2074. LEFT JOIN department d ON d.department_id=u.department_id
  2075. LEFT JOIN (
  2076. SELECT SUM(working_time) AS realHour,group_id,dept_id
  2077. FROM report WHERE state=1
  2078. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2079. AND create_date BETWEEN #{startDate} AND #{endDate}
  2080. </if>
  2081. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  2082. WHERE u.company_id=#{companyId}
  2083. <if test="listThird!=null and listThird.size()>0">
  2084. AND tg.project_id in
  2085. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2086. #{item}
  2087. </foreach>
  2088. </if>
  2089. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2090. <if test="listFour!=null and listFour.size()>0">
  2091. and tg.name in
  2092. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2093. #{item}
  2094. </foreach>
  2095. </if>
  2096. <if test="listFive!=null and listFive.size()>0">
  2097. and d.department_id in
  2098. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2099. #{item}
  2100. </foreach>
  2101. </if>
  2102. GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
  2103. <where>
  2104. realHour>0
  2105. <if test="listThird!=null and listThird.size()>0">
  2106. and
  2107. projectId in
  2108. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2109. #{item}
  2110. </foreach>
  2111. </if>
  2112. </where>
  2113. GROUP BY projectId
  2114. <if test="start!=null and size!=null">
  2115. limit #{start},#{size}
  2116. </if>
  2117. </select>
  2118. <select id="groupExpendProcessListForProjectCount" resultType="java.lang.Integer">
  2119. select count(1) from (
  2120. SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
  2121. SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
  2122. IFNULL(r.realHour,0) AS realHour
  2123. FROM task_executor te
  2124. LEFT JOIN task t ON t.id=te.task_id
  2125. LEFT JOIN `user` u ON te.executor_id=u.id
  2126. LEFT JOIN task_group tg ON tg.id=t.group_id
  2127. LEFT JOIN project p ON p.id=tg.project_id
  2128. LEFT JOIN department d ON d.department_id=u.department_id
  2129. LEFT JOIN (
  2130. SELECT SUM(working_time) AS realHour,group_id,dept_id
  2131. FROM report WHERE state=1
  2132. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2133. AND create_date BETWEEN #{startDate} AND #{endDate}
  2134. </if>
  2135. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  2136. WHERE u.company_id=#{companyId}
  2137. <if test="listThird!=null and listThird.size()>0">
  2138. AND tg.project_id in
  2139. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2140. #{item}
  2141. </foreach>
  2142. </if>
  2143. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2144. <if test="listFour!=null and listFour.size()>0">
  2145. and tg.name in
  2146. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2147. #{item}
  2148. </foreach>
  2149. </if>
  2150. <if test="listFive!=null and listFive.size()>0">
  2151. and d.department_id in
  2152. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2153. #{item}
  2154. </foreach>
  2155. </if>
  2156. GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
  2157. <where>
  2158. realHour>0
  2159. <if test="listThird!=null and listThird.size()>0">
  2160. and
  2161. projectId in
  2162. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2163. #{item}
  2164. </foreach>
  2165. </if>
  2166. </where>
  2167. GROUP BY projectId
  2168. ) as total
  2169. </select>
  2170. <select id="projectExpendProcessList" resultType="java.util.Map">
  2171. select p.id AS projectId,p.project_name as projectName,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate,pc.name as categoryName,p.project_code as projectCode,IFNULL(SUM(te.plan_hours),0) as planHour,
  2172. IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realHour, IFNULL((select SUM(cost) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realCost,
  2173. IFNULL(IFNULL(SUM(te.plan_hours),0)-IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0),0) as residueHour
  2174. from task_executor te
  2175. left join user u on u.id=te.executor_id
  2176. left join department d on u.department_id=d.department_id
  2177. left join task t on t.id=te.task_id
  2178. left join project p on p.id=t.project_id
  2179. left join project_category pc on pc.id=p.category
  2180. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
  2181. <if test="projectId!=null">
  2182. and p.id=#{projectId}
  2183. </if>
  2184. <if test="userId!=null and userId!=''">
  2185. and FIND_IN_SET(#{userId},t.executor_id)
  2186. </if>
  2187. <if test="categoryId!=null">
  2188. and pc.id=#{categoryId}
  2189. </if>
  2190. <if test="list!=null and list.size()>0">
  2191. and d.department_id in
  2192. <foreach collection="list" open="(" close=")" separator="," item="item">
  2193. #{item}
  2194. </foreach>
  2195. </if>
  2196. group by t.project_id
  2197. <if test="start!=null and size!=null">
  2198. limit #{start},#{size}
  2199. </if>
  2200. </select>
  2201. <select id="projectExpendProcessListCount" resultType="java.lang.Long">
  2202. select count(1) from (
  2203. select p.project_name as projectName
  2204. from task_executor te
  2205. left join user u on u.id=te.executor_id
  2206. left join department d on u.department_id=d.department_id
  2207. left join task t on t.id=te.task_id
  2208. left join project p on p.id=t.project_id
  2209. left join project_category pc on pc.id=p.category
  2210. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
  2211. <if test="projectId!=null">
  2212. and p.id=#{projectId}
  2213. </if>
  2214. <if test="userId!=null and userId!=''">
  2215. and te.executor_id=#{userId}
  2216. </if>
  2217. <if test="categoryId!=null">
  2218. and pc.id=#{categoryId}
  2219. </if>
  2220. <if test="list!=null and list.size()>0">
  2221. and d.department_id in
  2222. <foreach collection="list" open="(" close=")" separator="," item="item">
  2223. #{item}
  2224. </foreach>
  2225. </if>
  2226. group by t.project_id
  2227. ) as total
  2228. </select>
  2229. <select id="userTaskProcessList" resultType="java.util.Map">
  2230. select d.department_name as departmentName,d.corpwx_deptid as corpwxDeptId,u.corpwx_userid as corpwxUserId,t.name as taskName,IFNULL(t.plan_hours,0) as planHour,u.name as userName,u.job_number as jobNumber,p.project_name as projectName,p.project_code as projectCode,
  2231. IFNULL((select SUM(working_time) from report where task_id=te.task_id and state=1),0)as consumeTime,IF((IFNULL(t.plan_hours,0)-IFNULL((SELECT SUM(working_time) FROM report WHERE task_id=te.task_id AND state=1),0))&lt;0,0,(IFNULL(t.plan_hours,0)-IFNULL((SELECT SUM(working_time) FROM report WHERE task_id=te.task_id AND state=1),0))) AS residue
  2232. ,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate
  2233. from task_executor te
  2234. left join user u on u.id=te.executor_id
  2235. left join department d on d.department_id=u.department_id
  2236. left join project p on p.id=te.project_id
  2237. left join task t on te.task_id=t.id
  2238. where u.company_id=#{companyId} and te.project_id is not null
  2239. <if test="deptId!=null">
  2240. and d.department_id=#{deptId}
  2241. </if>
  2242. <if test="userId!=null and userId!=''">
  2243. and u.id=#{userId}
  2244. </if>
  2245. <if test="projectId!=null">
  2246. and p.id=#{projectId}
  2247. </if>
  2248. <if test="list!=null and list.size()>0">
  2249. and d.department_id in
  2250. <foreach collection="list" open="(" close=")" item="item" separator=",">
  2251. #{item}
  2252. </foreach>
  2253. </if>
  2254. <if test="listSecond!=null and listSecond.size()>0">
  2255. and d.department_id in
  2256. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  2257. #{item}
  2258. </foreach>
  2259. </if>
  2260. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2261. and ((t.start_date between #{startDate} and #{endDate})
  2262. or
  2263. (t.end_date between #{startDate} and #{endDate}))
  2264. </if>
  2265. group by te.executor_id,t.id
  2266. order by d.department_id,u.id
  2267. <if test="start!=null and size!=null">
  2268. limit #{start},#{size}
  2269. </if>
  2270. </select>
  2271. <select id="userTaskProcessListCount" resultType="java.lang.Long">
  2272. select count(1) from (
  2273. select d.department_name as departmentName
  2274. from task_executor te
  2275. left join user u on u.id=te.executor_id
  2276. left join department d on d.department_id=u.department_id
  2277. left join project p on p.id=te.project_id
  2278. left join task t on te.task_id=t.id
  2279. where u.company_id=#{companyId} and te.project_id is not null
  2280. <if test="deptId!=null">
  2281. and d.department_id=#{deptId}
  2282. </if>
  2283. <if test="userId!=null and userId!=''">
  2284. and u.id=#{userId}
  2285. </if>
  2286. <if test="projectId!=null">
  2287. and p.id=#{projectId}
  2288. </if>
  2289. <if test="list!=null and list.size()>0">
  2290. and d.department_id in
  2291. <foreach collection="list" open="(" close=")" item="item" separator=",">
  2292. #{item}
  2293. </foreach>
  2294. </if>
  2295. <if test="listSecond!=null and listSecond.size()>0">
  2296. and d.department_id in
  2297. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  2298. #{item}
  2299. </foreach>
  2300. </if>
  2301. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2302. and ((t.start_date between #{startDate} and #{endDate})
  2303. or
  2304. (t.end_date between #{startDate} and #{endDate}))
  2305. </if>
  2306. group by te.executor_id,t.id
  2307. order by d.department_id,u.id
  2308. ) as total
  2309. </select>
  2310. </mapper>