ProjectMapper.xml 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116
  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,IFNULL(r.projectCode,'') as projectCode,IFNULL(r.workTime,0) as workTime
  1669. FROM `user` u
  1670. LEFT JOIN department d on u.department_id=d.department_id
  1671. LEFT JOIN (
  1672. SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
  1673. FROM report
  1674. LEFT JOIN project p
  1675. ON report.project_id = p.id
  1676. LEFT JOIN `user`
  1677. ON user.id = report.creator_id
  1678. WHERE report.state = 1
  1679. AND p.is_public = 0
  1680. AND report.company_id=#{companyId}
  1681. AND
  1682. (
  1683. 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}
  1684. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1685. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1686. and
  1687. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1688. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1689. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1690. and
  1691. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1692. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1693. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1694. )
  1695. GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
  1696. ) r
  1697. ON u.id = r.creator_id
  1698. WHERE u.company_id=#{companyId}
  1699. AND (workTime>0 OR u.`is_active`=1)
  1700. <if test="area!=null and area != '' ">
  1701. and u.plate1 = #{area}
  1702. </if>
  1703. <if test="userId!=null and userId != '' ">
  1704. and u.id = #{userId}
  1705. </if>
  1706. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1707. and u.department_id in
  1708. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1709. #{item}
  1710. </foreach>
  1711. </if>
  1712. <if test="deptIds!=null and deptIds.size()>0">
  1713. and u.department_id in
  1714. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1715. #{item}
  1716. </foreach>
  1717. </if>
  1718. <if test="sortProp!=null and sortProp!=''">
  1719. <choose>
  1720. <when test="sortOrder==0">
  1721. order by id desc
  1722. </when>
  1723. <otherwise>
  1724. order by id
  1725. </otherwise>
  1726. </choose>
  1727. </if>
  1728. <if test="start!=null and size!=null">
  1729. limit #{start},#{size}
  1730. </if>
  1731. </select>
  1732. <!--获取查询者所在公司每个项目的工时成本-->
  1733. <select id="getTimeCostByToken" resultType="java.util.Map">
  1734. 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
  1735. FROM project AS a
  1736. LEFT JOIN report AS b ON b.project_id = a.id
  1737. JOIN user AS c ON b.creator_id = c.id
  1738. JOIN department d on d.department_id=c.department_id
  1739. WHERE a.company_id = #{companyId}
  1740. <if test="startDate != null and endDate != null">
  1741. AND b.create_date between #{startDate} and #{endDate}
  1742. </if>
  1743. AND b.state = 1
  1744. GROUP BY a.id,b.creator_id
  1745. ORDER BY a.id ASC
  1746. </select>
  1747. <!--获取员工的项目分类工时统计数据 -->
  1748. <select id="getMembProjectCateTime" resultType="com.management.platform.entity.vo.UserCateTimeVo">
  1749. 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
  1750. FROM report
  1751. LEFT JOIN `user` ON user.id = report.`creator_id`
  1752. LEFT JOIN project ON project.id = report.`project_id`
  1753. WHERE report.`company_id` = #{companyId}
  1754. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  1755. AND report.state = 1
  1756. <if test="departmentId!=null">
  1757. AND user.department_id=#{departmentId}
  1758. </if>
  1759. <if test="subUserCustomName!=null and subUserCustomName!='' and plateString!=null">
  1760. <choose>
  1761. <when test="plateString==1">
  1762. AND user.plate1=#{subUserCustomName}
  1763. </when>
  1764. <when test="plateString==2">
  1765. AND user.plate2=#{subUserCustomName}
  1766. </when>
  1767. <when test="plateString==3">
  1768. AND user.plate3=#{subUserCustomName}
  1769. </when>
  1770. <when test="plateString==4">
  1771. AND user.plate4=#{subUserCustomName}
  1772. </when>
  1773. <otherwise>
  1774. AND user.plate5=#{subUserCustomName}
  1775. </otherwise>
  1776. </choose>
  1777. </if>
  1778. GROUP BY user.id, project.`category`
  1779. </select>
  1780. <select id="userProjectProcessList" resultType="java.util.Map">
  1781. 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,
  1782. 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
  1783. from task_executor te
  1784. left join user u on u.id=te.executor_id
  1785. left join department d on d.department_id=u.department_id
  1786. left join project p on p.id=te.project_id
  1787. where u.company_id=#{companyId} and te.project_id is not null
  1788. <if test="deptId!=null">
  1789. and d.department_id=#{deptId}
  1790. </if>
  1791. <if test="userId!=null and userId!=''">
  1792. and u.id=#{userId}
  1793. </if>
  1794. <if test="projectId!=null">
  1795. and p.id=#{projectId}
  1796. </if>
  1797. <if test="list!=null and list.size()>0">
  1798. and d.department_id in
  1799. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1800. #{item}
  1801. </foreach>
  1802. </if>
  1803. <if test="listSecond!=null and listSecond.size()>0">
  1804. and d.department_id in
  1805. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1806. #{item}
  1807. </foreach>
  1808. </if>
  1809. group by te.executor_id,te.project_id
  1810. order by d.department_id,u.id
  1811. <if test="start!=null and size!=null">
  1812. limit #{start},#{size}
  1813. </if>
  1814. </select>
  1815. <select id="userProjectProcessCount" resultType="java.lang.Long">
  1816. select count(1) from (
  1817. select d.department_name as departmentName
  1818. from task_executor te
  1819. left join user u on u.id=te.executor_id
  1820. left join department d on d.department_id=u.department_id
  1821. left join project p on p.id=te.project_id
  1822. where u.company_id=#{companyId} and te.project_id is not null
  1823. <if test="deptId!=null">
  1824. and d.department_id=#{deptId}
  1825. </if>
  1826. <if test="userId!=null and userId!=''">
  1827. and u.id=#{userId}
  1828. </if>
  1829. <if test="projectId!=null">
  1830. and p.id=#{projectId}
  1831. </if>
  1832. <if test="list!=null and list.size()>0">
  1833. and d.department_id in
  1834. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1835. #{item}
  1836. </foreach>
  1837. </if>
  1838. <if test="listSecond!=null and listSecond.size()>0">
  1839. and d.department_id in
  1840. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1841. #{item}
  1842. </foreach>
  1843. </if>
  1844. group by te.executor_id,te.project_id
  1845. ) as total
  1846. </select>
  1847. <select id="groupExpendProcessList" resultType="java.util.Map">
  1848. 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,
  1849. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) as normalHour,IFNULL(r.overHour,0) as overHour,
  1850. 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
  1851. FROM task_executor te
  1852. LEFT JOIN task t ON t.id=te.task_id
  1853. LEFT JOIN user u ON te.executor_id=u.id
  1854. LEFT JOIN task_group tg ON tg.id=t.group_id
  1855. LEFT JOIN project p ON p.id=tg.project_id
  1856. LEFT JOIN department d ON d.department_id=u.department_id
  1857. LEFT JOIN (
  1858. 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
  1859. FROM report WHERE state=1
  1860. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1861. AND create_date BETWEEN #{startDate} AND #{endDate}
  1862. </if>
  1863. 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
  1864. WHERE u.company_id=#{companyId}
  1865. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1866. <if test="userId!=null and userId!=''">
  1867. and t.executor_id=#{userId}
  1868. </if>
  1869. GROUP BY p.id,tg.id,d.department_id ORDER BY p.id,d.department_id
  1870. </select>
  1871. <select id="groupExpendProcessListForChart" resultType="java.util.Map">
  1872. 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
  1873. 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,
  1874. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) AS normalHour,IFNULL(r.overHour,0) AS overHour,
  1875. 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
  1876. FROM task_executor te
  1877. LEFT JOIN task t ON t.id=te.task_id
  1878. LEFT JOIN `user` u ON te.executor_id=u.id
  1879. LEFT JOIN task_group tg ON tg.id=t.group_id
  1880. LEFT JOIN project p ON p.id=tg.project_id
  1881. LEFT JOIN department d ON d.department_id=u.department_id
  1882. LEFT JOIN (
  1883. 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
  1884. FROM report WHERE state=1
  1885. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1886. AND create_date BETWEEN #{startDate} AND #{endDate}
  1887. </if>
  1888. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id,dept_id) r ON r.group_id=tg.`id`
  1889. WHERE u.company_id=#{companyId}
  1890. <if test="listThird!=null and listThird.size()>0">
  1891. AND tg.project_id in
  1892. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  1893. #{item}
  1894. </foreach>
  1895. </if>
  1896. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1897. <if test="userId!=null and userId!=''">
  1898. and t.executor_id=#{userId}
  1899. </if>
  1900. GROUP BY tg.id ORDER BY p.id,d.department_id) AS t
  1901. <where>
  1902. <if test="listFour!=null and listFour.size()>0">
  1903. t.groupName in
  1904. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  1905. #{item}
  1906. </foreach>
  1907. </if>
  1908. </where>
  1909. GROUP BY t.groupName
  1910. </select>
  1911. <select id="projectExpendProcessList" resultType="java.util.Map">
  1912. 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,
  1913. 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,
  1914. 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
  1915. from task_executor te
  1916. left join user u on u.id=te.executor_id
  1917. left join department d on u.department_id=d.department_id
  1918. left join task t on t.id=te.task_id
  1919. left join project p on p.id=t.project_id
  1920. left join project_category pc on pc.id=p.category
  1921. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目')
  1922. <if test="projectId!=null">
  1923. and p.id=#{projectId}
  1924. </if>
  1925. <if test="userId!=null and userId!=''">
  1926. and FIND_IN_SET(#{userId},t.executor_id)
  1927. </if>
  1928. <if test="categoryId!=null">
  1929. and pc.id=#{categoryId}
  1930. </if>
  1931. <if test="list!=null and list.size()>0">
  1932. and d.department_id in
  1933. <foreach collection="list" open="(" close=")" separator="," item="item">
  1934. #{item}
  1935. </foreach>
  1936. </if>
  1937. group by t.project_id
  1938. <if test="start!=null and size!=null">
  1939. limit #{start},#{size}
  1940. </if>
  1941. </select>
  1942. <select id="projectExpendProcessListCount" resultType="java.lang.Long">
  1943. select count(1) from (
  1944. select p.project_name as projectName
  1945. from task_executor te
  1946. left join user u on u.id=te.executor_id
  1947. left join department d on u.department_id=d.department_id
  1948. left join task t on t.id=te.task_id
  1949. left join project p on p.id=t.project_id
  1950. left join project_category pc on pc.id=p.category
  1951. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目')
  1952. <if test="projectId!=null">
  1953. and p.id=#{projectId}
  1954. </if>
  1955. <if test="userId!=null and userId!=''">
  1956. and te.executor_id=#{userId}
  1957. </if>
  1958. <if test="categoryId!=null">
  1959. and pc.id=#{categoryId}
  1960. </if>
  1961. <if test="list!=null and list.size()>0">
  1962. and d.department_id in
  1963. <foreach collection="list" open="(" close=")" separator="," item="item">
  1964. #{item}
  1965. </foreach>
  1966. </if>
  1967. group by t.project_id
  1968. ) as total
  1969. </select>
  1970. <select id="userTaskProcessList" resultType="java.util.Map">
  1971. 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,
  1972. 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
  1973. ,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate
  1974. from task_executor te
  1975. left join user u on u.id=te.executor_id
  1976. left join department d on d.department_id=u.department_id
  1977. left join project p on p.id=te.project_id
  1978. left join task t on te.task_id=t.id
  1979. where u.company_id=#{companyId} and te.project_id is not null
  1980. <if test="deptId!=null">
  1981. and d.department_id=#{deptId}
  1982. </if>
  1983. <if test="userId!=null and userId!=''">
  1984. and u.id=#{userId}
  1985. </if>
  1986. <if test="projectId!=null">
  1987. and p.id=#{projectId}
  1988. </if>
  1989. <if test="list!=null and list.size()>0">
  1990. and d.department_id in
  1991. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1992. #{item}
  1993. </foreach>
  1994. </if>
  1995. <if test="listSecond!=null and listSecond.size()>0">
  1996. and d.department_id in
  1997. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1998. #{item}
  1999. </foreach>
  2000. </if>
  2001. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2002. and ((t.start_date between #{startDate} and #{endDate})
  2003. or
  2004. (t.end_date between #{startDate} and #{endDate}))
  2005. </if>
  2006. group by te.executor_id,t.id
  2007. order by d.department_id,u.id
  2008. <if test="start!=null and size!=null">
  2009. limit #{start},#{size}
  2010. </if>
  2011. </select>
  2012. <select id="userTaskProcessListCount" resultType="java.lang.Long">
  2013. select count(1) from (
  2014. select d.department_name as departmentName
  2015. from task_executor te
  2016. left join user u on u.id=te.executor_id
  2017. left join department d on d.department_id=u.department_id
  2018. left join project p on p.id=te.project_id
  2019. left join task t on te.task_id=t.id
  2020. where u.company_id=#{companyId} and te.project_id is not null
  2021. <if test="deptId!=null">
  2022. and d.department_id=#{deptId}
  2023. </if>
  2024. <if test="userId!=null and userId!=''">
  2025. and u.id=#{userId}
  2026. </if>
  2027. <if test="projectId!=null">
  2028. and p.id=#{projectId}
  2029. </if>
  2030. <if test="list!=null and list.size()>0">
  2031. and d.department_id in
  2032. <foreach collection="list" open="(" close=")" item="item" separator=",">
  2033. #{item}
  2034. </foreach>
  2035. </if>
  2036. <if test="listSecond!=null and listSecond.size()>0">
  2037. and d.department_id in
  2038. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  2039. #{item}
  2040. </foreach>
  2041. </if>
  2042. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2043. and ((t.start_date between #{startDate} and #{endDate})
  2044. or
  2045. (t.end_date between #{startDate} and #{endDate}))
  2046. </if>
  2047. group by te.executor_id,t.id
  2048. order by d.department_id,u.id
  2049. ) as total
  2050. </select>
  2051. </mapper>