ProjectMapper.xml 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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_normal" property="feeNormal" />
  28. <result column="fee_travel" property="feeTravel" />
  29. <result column="fee_outsourcing" property="feeOutsourcing" />
  30. <result column="fee_man" property="feeMan" />
  31. <result column="customer_id" property="customerId" />
  32. <result column="customer_name" property="customerName" />
  33. <result column="is_public" property="isPublic" />
  34. <result column="associate_degrees" property="associateDegrees" />
  35. <result column="associate_degree_names" property="associateDegreeNames" />
  36. <result column="task_gp_incharge" property="taskGpIncharge" />
  37. <result column="category" property="category" />
  38. <result column="category_name" property="categoryName" />
  39. <result column="project_desc" property="projectDesc" />
  40. <result column="project_main_id" property="projectMainId" />
  41. <result column="project_main_name" property="projectMainName" />
  42. <result column="provider_ids" property="providerIds" />
  43. <result column="provider_names" property="providerNames" />
  44. <result column="current_stage_id" property="currentStageId" />
  45. <result column="current_stage_name" property="currentStageName" />
  46. <result column="output_value" property="outputValue" />
  47. <result column="dept_id" property="deptId" />
  48. <result column="dept_cascade" property="deptCascade" />
  49. <result column="bu_id" property="buId" />
  50. <result column="man_day" property="manDay" />
  51. <result column="plate1" property="plate1" />
  52. <result column="plate2" property="plate2" />
  53. <result column="plate3" property="plate3" />
  54. <result column="plate4" property="plate4" />
  55. <result column="plate5" property="plate5" />
  56. <result column="plate6" property="plate6" />
  57. <result column="plate7" property="plate7" />
  58. <result column="plate8" property="plate8" />
  59. <result column="plate9" property="plate9" />
  60. <result column="plate10" property="plate10" />
  61. </resultMap>
  62. <!-- 通用查询结果列 -->
  63. <sql id="Base_Column_List">
  64. 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_normal, fee_travel, fee_outsourcing, 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, plate1, plate2, plate3, plate4, plate5, plate6, plate7, plate8, plate9, plate10
  65. </sql>
  66. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  67. <result column="id" property="id" />
  68. <result column="project_name" property="projectName" />
  69. <result column="project_code" property="projectCode" />
  70. <result column="startDate" property="startDate" />
  71. <result column="endDate" property="endDate" />
  72. <collection property="stageCostList" javaType="java.util.ArrayList"
  73. ofType="com.management.platform.entity.vo.StageCost"
  74. select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
  75. </resultMap>
  76. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  77. <result column="customer_id" property="customerId" />
  78. <result column="customer_name" property="customerName" />
  79. <result column="contract_amount" property="contractAmount" />
  80. <result column="fee_normal" property="feeNormal" />
  81. <result column="fee_travel" property="feeTravel" />
  82. <result column="fee_outsourcing" property="feeOutsourcing" />
  83. <result column="fee_man" property="feeMan" />
  84. <result column="project_num" property="projectNum" />
  85. <result column="project_ids" property="projectIds" />
  86. <result column="project_names" property="projectNames" />
  87. </resultMap>
  88. <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
  89. select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
  90. from project
  91. where company_id = #{companyId}
  92. <if test="projectId != null">
  93. and id = #{projectId}
  94. </if>
  95. <if test="inchargerId!=null">
  96. and incharger_id = #{inchargerId}
  97. </if>
  98. order by is_public desc, id asc
  99. <if test="startIndex != null">
  100. limit ${startIndex}, ${endIndex}
  101. </if>
  102. </select>
  103. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  104. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  105. IFNULL(SUM(report.`working_time`), 0) AS working_time,
  106. 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
  107. FROM report
  108. left join project p on p.id=report.`project_id`
  109. where report.state = 1
  110. <if test="inchargerId!=null">
  111. and p.incharger_id = #{inchargerId}
  112. </if>
  113. <if test="projectIds!=null and projectIds.size()>0">
  114. and p.id in
  115. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  116. #{item}
  117. </foreach>
  118. </if>
  119. and report.create_date &gt;= #{startDate}
  120. and report.create_date &lt;= #{endDate}
  121. GROUP BY report.`project_id`,report.stage
  122. </select>
  123. <!--获取查询者所在公司每个项目的工时成本-->
  124. <select id="getParticipatedProject" resultType="java.util.Map">
  125. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  126. FROM project
  127. WHERE id IN (
  128. SELECT project_id
  129. FROM participation
  130. WHERE user_id = #{userId}
  131. ) or incharger_id = #{userId}
  132. or creator_id = #{userId}
  133. or (is_public = 1 and company_id = #{companyId})
  134. ORDER BY is_public DESC, id DESC
  135. </select>
  136. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  137. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  138. FROM project
  139. WHERE status = 1 and (id IN (
  140. SELECT project_id
  141. FROM participation
  142. WHERE user_id = #{userId}
  143. )
  144. or (is_public = 1 and company_id = #{companyId}))
  145. ORDER BY is_public DESC, id ASC
  146. </select>
  147. <!--获取查询者所在公司每个项目的工时成本-->
  148. <select id="getTimeCost" resultType="java.util.Map">
  149. 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
  150. FROM project AS a
  151. LEFT JOIN report AS b ON b.project_id = a.id
  152. JOIN user AS c ON b.creator_id = c.id
  153. WHERE a.company_id = #{companyId}
  154. <if test="projectId != null">
  155. AND a.id = #{projectId}
  156. </if>
  157. <if test="projectIds != null">
  158. and a.id in
  159. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  160. #{item}
  161. </foreach>
  162. </if>
  163. <if test="userIdList != null and userIdList.size()>0">
  164. AND b.creator_id in
  165. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  166. #{item}
  167. </foreach>
  168. </if>
  169. <if test="startDate != null and endDate != null">
  170. AND b.create_date between #{startDate} and #{endDate}
  171. </if>
  172. <choose>
  173. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  174. and b.dept_id in
  175. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  176. #{item}
  177. </foreach>
  178. </when>
  179. <otherwise>
  180. <if test="deptIds!=null and deptIds.size()>0">
  181. and (b.dept_id in
  182. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  183. #{item}
  184. </foreach>
  185. <if test="deptRelatedProjectIds.size() > 0">
  186. or a.id in
  187. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  188. #{pid}
  189. </foreach>
  190. </if>
  191. )
  192. </if>
  193. </otherwise>
  194. </choose>
  195. AND b.state = 1
  196. GROUP BY a.id
  197. ORDER BY a.id ASC
  198. </select>
  199. <!--获取查询者所在公司每个子项目的工时成本-->
  200. <select id="getSubProjectTimeCost" resultType="java.util.Map">
  201. 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
  202. from sub_project a
  203. left join project b on b.id=a.project_id
  204. left join report c on c.sub_project_id=a.id
  205. where a.company_id=#{companyId}
  206. <if test="startDate != null and endDate != null">
  207. and c.create_date between #{startDate} and #{endDate}
  208. </if>
  209. <if test="projectId!=null">
  210. and a.project_id=#{projectId}
  211. </if>
  212. <if test="inchagerIds!=null and inchagerIds.size()>0">
  213. and b.id in
  214. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  215. #{item}
  216. </foreach>
  217. </if>
  218. group by b.id,a.id
  219. <if test="start!=null and size!=null">
  220. limit #{start},#{size}
  221. </if>
  222. </select>
  223. <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
  224. 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
  225. from sub_project a
  226. left join project b on b.id=a.project_id
  227. left join report c on c.sub_project_id=a.id
  228. where a.company_id=#{companyId}
  229. <if test="startDate != null and endDate != null">
  230. and c.create_date between #{startDate} and #{endDate}
  231. </if>
  232. <if test="projectId!=null">
  233. and a.project_id=#{projectId}
  234. </if>
  235. <if test="inchagerIds!=null and inchagerIds.size()>0">
  236. and b.id in
  237. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  238. #{item}
  239. </foreach>
  240. </if>
  241. group by b.id,a.id
  242. <if test="start!=null and size!=null">
  243. limit #{start},#{size}
  244. </if>) as total
  245. </select>
  246. <!--获取查询者所在公司每个项目的工时成本-->
  247. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  248. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'未分类') as mainProjectName
  249. FROM project AS a
  250. LEFT JOIN report AS b ON b.project_id = a.id
  251. JOIN user AS c ON b.creator_id = c.id
  252. LEFT JOIN project_main pm on pm.id=a.project_main_id
  253. WHERE a.company_id = #{companyId}
  254. <if test="projectId != null">
  255. AND a.id = #{projectId}
  256. </if>
  257. <if test="startDate != null and endDate != null">
  258. AND b.create_date between #{startDate} and #{endDate}
  259. </if>
  260. <if test="deptIds!=null and deptIds.size()>0">
  261. and b.dept_id in
  262. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  263. #{item}
  264. </foreach>
  265. </if>
  266. AND b.state = 1
  267. GROUP BY a.project_main_id
  268. ORDER BY a.id ASC
  269. </select>
  270. <!--获取查询者所在公司每个项目分类的工时成本-->
  271. <select id="getTimeCostByCategory" resultType="java.util.Map">
  272. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  273. FROM project AS a
  274. LEFT JOIN report AS b ON b.project_id = a.id
  275. JOIN user AS c ON b.creator_id = c.id
  276. WHERE a.company_id = #{companyId}
  277. <if test="projectCategoryId != null">
  278. AND a.category = #{projectCategoryId}
  279. </if>
  280. <if test="projectIds != null">
  281. and a.id in
  282. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  283. #{item}
  284. </foreach>
  285. </if>
  286. <if test="userIdList != null and userIdList.size()>0">
  287. AND b.creator_id in
  288. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  289. #{item}
  290. </foreach>
  291. </if>
  292. <if test="startDate != null and endDate != null">
  293. AND b.create_date between #{startDate} and #{endDate}
  294. </if>
  295. <if test="deptIds!=null and deptIds.size()>0">
  296. and b.dept_id in
  297. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  298. #{item}
  299. </foreach>
  300. </if>
  301. AND b.state = 1
  302. GROUP BY a.category
  303. ORDER BY a.category ASC
  304. </select>
  305. <!--获取自定义数值的项目统计 -->
  306. <select id="getCustomDataSum" resultType="java.util.Map">
  307. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  308. FROM project AS a
  309. LEFT JOIN report AS b ON b.project_id = a.id
  310. JOIN user AS c ON b.creator_id = c.id
  311. WHERE a.company_id = #{companyId}
  312. <if test="projectId != null">
  313. AND a.id = #{projectId}
  314. </if>
  315. <if test="userId != null">
  316. AND b.creator_id = #{userId}
  317. </if>
  318. <if test="startDate != null and endDate != null">
  319. AND b.create_date between #{startDate} and #{endDate}
  320. </if>
  321. AND b.state = 1
  322. GROUP BY a.id
  323. having IFNULL(SUM(b.custom_data), 0) > 0
  324. ORDER BY SUM(b.custom_data) DESC
  325. </select>
  326. <!--获取日报的人员月度工时 -->
  327. <select id="getTimeCostReport" resultType="java.util.Map">
  328. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  329. FROM report AS a
  330. LEFT JOIN project AS b ON a.project_id = b.id
  331. LEFT JOIN user AS c ON a.creator_id = c.id
  332. WHERE b.company_id = #{companyId}
  333. <if test="projectId != null">
  334. AND b.id = #{projectId}
  335. </if>
  336. <if test="startDate != null and endDate != null">
  337. AND a.create_date between #{startDate} and #{endDate}
  338. </if>
  339. <if test="deptIds!=null and deptIds.size()>0">
  340. and a.dept_id in
  341. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  342. #{item}
  343. </foreach>
  344. </if>
  345. AND a.state = 1
  346. </select>
  347. <!--获取人员的月度总工时 -->
  348. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  349. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  350. FROM report AS a, user as b
  351. WHERE a.creator_id = b.id
  352. and b.company_id = #{companyId}
  353. <if test="startDate != null and endDate != null">
  354. AND a.create_date between #{startDate} and #{endDate}
  355. </if>
  356. AND a.state = 1
  357. group by a.creator_id
  358. </select>
  359. <!--获取某个项目每个人分别需要的工时-->
  360. <select id="getProjectCost" resultType="java.util.Map">
  361. 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
  362. FROM report AS a
  363. JOIN user AS b ON a.creator_id = b.id
  364. left join department on department.department_id = a.dept_id
  365. WHERE a.company_id=#{companyId}
  366. <choose>
  367. <when test="stateKey!=null and stateKey==1">
  368. and a.state = 1
  369. </when>
  370. <otherwise>
  371. and (a.state = 1 or a.state =0)
  372. </otherwise>
  373. </choose>
  374. <if test="projectId != null">
  375. and a.project_id = #{projectId}
  376. </if>
  377. <if test="startDate != null and endDate != null">
  378. AND a.create_date between #{startDate} and #{endDate}
  379. </if>
  380. <if test="userIdList != null and userIdList.size()>0">
  381. AND a.creator_id in
  382. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  383. #{item}
  384. </foreach>
  385. </if>
  386. <choose>
  387. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  388. and a.dept_id in
  389. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  390. #{item}
  391. </foreach>
  392. </when>
  393. <otherwise>
  394. <if test="deptIds!=null and deptIds.size()>0">
  395. and a.dept_id in
  396. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  397. #{item}
  398. </foreach>
  399. </if>
  400. </otherwise>
  401. </choose>
  402. GROUP BY b.id
  403. <if test="withDept">
  404. , a.dept_id
  405. </if>
  406. ORDER BY b.id ASC
  407. <if test="withDept">
  408. , a.dept_id ASC
  409. </if>
  410. </select>
  411. <!--获取某个项目分类每个人分别需要的工时-->
  412. <select id="getProjectCostByCategory" resultType="java.util.Map">
  413. 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
  414. FROM report AS a
  415. JOIN user AS b ON a.creator_id = b.id
  416. left join department on department.department_id = a.dept_id
  417. left join project c on c.id=a.project_id
  418. WHERE a.company_id=#{companyId} and a.state = 1
  419. <if test="curProjectCategoryId != null">
  420. and c.category = #{curProjectCategoryId}
  421. </if>
  422. <if test="startDate != null and endDate != null">
  423. AND a.create_date between #{startDate} and #{endDate}
  424. </if>
  425. <if test="userId != null">
  426. AND a.creator_id = #{userId}
  427. </if>
  428. GROUP BY c.category, a.dept_id
  429. ORDER BY c.category ASC, a.dept_id ASC
  430. </select>
  431. <!--获取个人每个项目分别需要的工时-->
  432. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  433. 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
  434. FROM report AS a
  435. JOIN user AS b ON a.creator_id = b.id
  436. left join department on department.department_id = a.dept_id
  437. WHERE a.company_id=#{companyId} and a.state = 1
  438. <if test="projectId != null">
  439. and a.project_id = #{projectId}
  440. </if>
  441. <if test="startDate != null and endDate != null">
  442. AND a.create_date between #{startDate} and #{endDate}
  443. </if>
  444. <if test="userIdList != null and userIdList.size()>0">
  445. AND a.creator_id in
  446. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  447. #{item}
  448. </foreach>
  449. </if>
  450. <if test="deptIds!=null and deptIds.size()>0">
  451. and a.dept_id in
  452. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  453. #{item}
  454. </foreach>
  455. </if>
  456. GROUP BY b.id,a.project_id
  457. ORDER BY b.id ASC, a.dept_id ASC
  458. </select>
  459. <!--获取个人每个项目分类分别需要的工时-->
  460. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  461. 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
  462. FROM report AS a
  463. JOIN user AS b ON a.creator_id = b.id
  464. left join department on department.department_id = a.dept_id
  465. left join project c on c.id=a.project_id
  466. WHERE a.company_id=#{companyId} and a.state = 1
  467. <if test="projectCategoryId != null">
  468. and c.category = #{projectCategoryId}
  469. </if>
  470. <if test="startDate != null and endDate != null">
  471. AND a.create_date between #{startDate} and #{endDate}
  472. </if>
  473. <if test="userIdList != null and userIdList.size()>0">
  474. AND a.creator_id in
  475. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  476. #{item}
  477. </foreach>
  478. </if>
  479. <if test="deptIds!=null and deptIds.size()>0">
  480. and a.dept_id in
  481. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  482. #{item}
  483. </foreach>
  484. </if>
  485. GROUP BY b.id,c.category
  486. ORDER BY b.id ASC, a.dept_id ASC
  487. </select>
  488. <!-- 获取人员在日报填写的自定义数值 -->
  489. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  490. SELECT b.id as creatorId,
  491. b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
  492. FROM report AS a
  493. JOIN user AS b ON a.creator_id = b.id
  494. left join department on department.department_id = b.department_id
  495. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  496. <if test="startDate != null and endDate != null">
  497. AND a.create_date between #{startDate} and #{endDate}
  498. </if>
  499. <if test="projectId != null">
  500. AND a.project_id = #{projectId}
  501. </if>
  502. <if test="userId != null">
  503. AND a.creator_id = #{userId}
  504. </if>
  505. <if test="deptIds != null">
  506. AND department.department_id in
  507. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  508. #{item}
  509. </foreach>
  510. </if>
  511. group by b.id
  512. ORDER BY b.id ASC
  513. </select>
  514. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  515. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  516. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  517. FROM report AS a
  518. JOIN user AS b ON a.creator_id = b.id
  519. left join department on department.department_id = b.department_id
  520. left join project on project.id = a.project_id
  521. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  522. <if test="startDate != null and endDate != null">
  523. AND a.create_date between #{startDate} and #{endDate}
  524. </if>
  525. <if test="projectId != null">
  526. AND a.project_id = #{projectId}
  527. </if>
  528. <if test="userId != null">
  529. AND a.creator_id = #{userId}
  530. </if>
  531. ORDER BY a.create_date desc
  532. </select>
  533. <!--按照项目内的阶段名称分组统计工时-->
  534. <select id="getCostInStage" resultType="java.util.Map">
  535. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  536. FROM report AS a
  537. WHERE a.project_id = #{projectId}
  538. AND a.state = 1
  539. <if test="startDate != null and endDate != null">
  540. AND a.create_date between #{startDate} and #{endDate}
  541. </if>
  542. GROUP BY a.stage
  543. ORDER BY a.stage ASC
  544. </select>
  545. <!--按照项目内的阶段名称分组统计工时-->
  546. <select id="getCostByGroup" resultType="java.util.Map">
  547. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  548. FROM report AS a
  549. left join task_group tg on tg.id=a.group_id
  550. WHERE a.project_id = #{projectId}
  551. AND a.state = 1
  552. <if test="startDate != null and endDate != null">
  553. AND a.create_date between #{startDate} and #{endDate}
  554. </if>
  555. GROUP BY a.group_id
  556. ORDER BY a.group_id ASC
  557. </select>
  558. <!--获取全部人员工时 -->
  559. <select id="getAllMembCost" resultType="java.util.Map">
  560. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  561. FROM user AS b
  562. left JOIN report AS a ON a.creator_id = b.id
  563. WHERE a.state = 1
  564. and b.company_id = #{companyId}
  565. <if test="startDate != null and endDate != null">
  566. AND a.create_date between #{startDate} and #{endDate}
  567. </if>
  568. <if test="projectId != null">
  569. AND a.project_id = #{projectId}
  570. </if>
  571. GROUP BY b.id
  572. ORDER BY b.id ASC
  573. </select>
  574. <!--分页获取项目成本 -->
  575. <select id="getAllProjectCost" resultType="java.util.Map">
  576. SELECT id, project_code as projectCode, project_name as projectName,
  577. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  578. FROM project WHERE project.`company_id` = #{companyId}
  579. and (project.status &lt;&gt; 3 or project.status is null)
  580. <if test="projectId != null">
  581. and project.id = #{projectId}
  582. </if>
  583. <if test="inchagerIds!=null and inchagerIds.size()>0">
  584. and project.id in
  585. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  586. #{item}
  587. </foreach>
  588. </if>
  589. order by project.is_public desc, project.id asc
  590. <if test="pageStart != null and pageSize != null">
  591. LIMIT #{pageStart},#{pageSize}
  592. </if>
  593. </select>
  594. <!--分页获取项目收支平衡 -->
  595. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  596. SELECT project_code, project_name,contract_amount,
  597. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  598. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 0 and expense_sheet.status = 0) AS fee_normal,
  599. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 1 and expense_sheet.status = 0) AS fee_travel,
  600. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0) AS fee_outsourcing
  601. FROM project WHERE project.`company_id` = #{companyId}
  602. and (project.status &lt;&gt; 3 or project.status is null)
  603. <if test="projectId != null">
  604. and project.id = #{projectId}
  605. </if>
  606. <if test="inchagerIds!=null and inchagerIds.size()>0">
  607. and project.id in
  608. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  609. #{item}
  610. </foreach>
  611. </if>
  612. order by is_public desc, id asc
  613. <if test="pageStart != null and pageSize != null">
  614. LIMIT #{pageStart},#{pageSize}
  615. </if>
  616. </select>
  617. <!--分页获取客户项目的成本利润报表 -->
  618. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  619. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  620. SUM(contract_amount) AS contract_amount ,
  621. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man,
  622. SUM((SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 0 and expense_sheet.status = 0)) AS fee_normal,
  623. SUM((SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 1 and expense_sheet.status = 0)) AS fee_travel,
  624. SUM((SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0)) AS fee_outsourcing
  625. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  626. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  627. <if test="customerId!=null">
  628. and project.customer_id=#{customerId}
  629. </if>
  630. <if test="projectId!=null">
  631. and project.id=#{projectId}
  632. </if>
  633. GROUP BY customer_id
  634. <if test="pageStart != null and pageSize != null">
  635. LIMIT #{pageStart},#{pageSize}
  636. </if>
  637. </select>
  638. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  639. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  640. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  641. <if test="customerId!=null">
  642. and project.customer_id=#{customerId}
  643. </if>
  644. <if test="projectId!=null">
  645. and project.id=#{projectId}
  646. </if>
  647. </select>
  648. <!--分页获取项目收支平衡 -->
  649. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  650. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  651. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  652. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 0 and expense_sheet.status = 0) AS fee_normal,
  653. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 1 and expense_sheet.status = 0) AS fee_travel,
  654. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0) AS fee_outsourcing
  655. FROM project WHERE project.`company_id` = #{companyId}
  656. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  657. #{item}
  658. </foreach>
  659. </select>
  660. <select id="getGanttData" resultType="java.util.Map">
  661. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  662. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  663. LEFT JOIN user ON user.id = participation.`user_id`
  664. LEFT JOIN project ON project.`id` = participation.`project_id`
  665. WHERE participation.`user_id` IN
  666. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  667. #{item}
  668. </foreach>
  669. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  670. ORDER BY participation.user_id, project.`plan_start_date`
  671. </select>
  672. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  673. 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,
  674. 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
  675. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  676. left join task on task.id = task_executor.task_id
  677. LEFT JOIN project ON project.`id` = task.`project_id`
  678. WHERE user.`id` IN
  679. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  680. #{item}
  681. </foreach>
  682. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  683. and task.end_date is not null
  684. AND project.`status` = 1
  685. ORDER BY user.id, task.start_date
  686. </select>
  687. <select id="getTaskPlanByProject" resultType="java.util.Map">
  688. 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,
  689. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  690. LEFT JOIN task ON task.project_id = project.id
  691. WHERE project.company_id = #{companyId}
  692. <if test="projectIds != null">
  693. and project.`id` IN
  694. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  695. #{item}
  696. </foreach>
  697. </if>
  698. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  699. and task.end_date is not null
  700. AND project.`status` = 1
  701. ORDER BY project.id, task.start_date
  702. </select>
  703. <!--获取加班统计报表 -->
  704. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  705. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  706. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  707. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  708. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  709. <!-- left join project on project.id = report.project_id-->
  710. <!-- WHERE report.is_overtime = 1-->
  711. <!-- and report.`state` = 1-->
  712. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  713. <!-- AND user.`company_id` = #{companyId}-->
  714. <!-- <if test="projectId != null">-->
  715. <!-- AND report.`project_id` = #{projectId}-->
  716. <!-- </if>-->
  717. <!-- <if test="userId != null">-->
  718. <!-- AND report.`creator_id` = #{userId}-->
  719. <!-- </if>-->
  720. <!-- GROUP BY report.creator_id-->
  721. <!-- </select>-->
  722. <!-- 获取某个员工的某时间段内的加班详情 -->
  723. <select id="getOvertimeDetail" resultType="java.util.Map">
  724. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  725. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  726. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  727. project.project_name as projectName,project.project_code as projectCode,
  728. IFNULL(report.overtime_cost, 0) AS cost,
  729. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  730. left join project on project.id = report.project_id
  731. left join report_extra_degree on report_extra_degree.id = report.degree_id
  732. left join department on department.department_id = report.dept_id
  733. WHERE report.is_overtime = 1
  734. and report.`state` = 1
  735. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  736. AND user.`company_id` = #{companyId}
  737. <if test="projectId != null">
  738. AND report.`project_id` = #{projectId}
  739. </if>
  740. <if test="userId != null">
  741. AND report.`creator_id` = #{userId}
  742. </if>
  743. <if test="branchDepartment!=null and branchDepartment.size()>0">
  744. and report.dept_id in
  745. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  746. #{item}
  747. </foreach>
  748. </if>
  749. <if test="deptIds!=null and deptIds.size()>0">
  750. and report.dept_id in
  751. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  752. #{item}
  753. </foreach>
  754. </if>
  755. order by user.create_time asc, report.create_date desc
  756. </select>
  757. <!--获取人员工时-->
  758. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  759. SELECT report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber,
  760. user.department_id As deptId,
  761. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  762. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  763. ifnull(SUM(report.`working_time`),0) AS workingTime
  764. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  765. left join project on project.id = report.project_id
  766. WHERE
  767. report.`state` = 1
  768. AND user.`is_active` = 1
  769. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  770. AND user.`company_id` =#{companyId}
  771. <if test="userId!=null">
  772. and user.id=#{userId}
  773. </if>
  774. <if test="projectId!=null">
  775. and project.id=#{projectId}
  776. </if>
  777. <if test="branchDepartment!=null and branchDepartment.size()>0">
  778. and report.dept_id in
  779. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  780. #{item}
  781. </foreach>
  782. </if>
  783. <if test="deptIds!=null and deptIds.size()>0">
  784. and report.dept_id in
  785. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  786. #{item}
  787. </foreach>
  788. </if>
  789. group by user.id
  790. order by user.create_time asc, report.create_date desc
  791. <if test="start!=null and size!=null">
  792. limit #{start},#{size}
  793. </if>
  794. </select>
  795. <select id="findCountWithUser" resultType="java.lang.Long">
  796. select count(*)
  797. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  798. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  799. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  800. ifnull(SUM(report.`working_time`),0) AS workingTime
  801. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  802. left join project on project.id = report.project_id
  803. WHERE
  804. report.`state` = 1
  805. AND user.`is_active` = 1
  806. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  807. AND user.`company_id` =#{companyId}
  808. <if test="userId!=null">
  809. and user.id=#{userId}
  810. </if>
  811. <if test="projectId!=null">
  812. and project.id=#{projectId}
  813. </if>
  814. <if test="departmentId!=null">
  815. and report.dept_id=#{departmentId}
  816. </if>
  817. <if test="deptIds!=null and deptIds.size()>0">
  818. and report.dept_id in
  819. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  820. #{item}
  821. </foreach>
  822. </if>
  823. group by user.id
  824. order by user.create_time asc, report.create_date desc
  825. <if test="start!=null and size!=null">
  826. limit #{start},#{size}
  827. </if>) as total
  828. </select>
  829. <!--按照项目内的阶段名称分组统计工时-->
  830. <select id="getDegreeCost" resultType="java.util.Map">
  831. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
  832. FROM report AS a
  833. left join report_extra_degree b on b.id = a.degree_id
  834. WHERE
  835. a.state = 1
  836. and a.company_id = #{companyId}
  837. <if test="departmentIds!=null and departmentIds.size()>0">
  838. and a.dept_id in
  839. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  840. #{item}
  841. </foreach>
  842. </if>
  843. <if test="projectId != null">
  844. and a.project_id = #{projectId}
  845. </if>
  846. <if test="startDate != null and endDate != null">
  847. AND a.create_date between #{startDate} and #{endDate}
  848. </if>
  849. GROUP BY a.degree_id
  850. ORDER BY a.degree_id ASC
  851. </select>
  852. <!--项目导出数据-->
  853. <select id="getExportData" resultType="java.util.HashMap" >
  854. 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,
  855. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  856. customer_name, associate_degree_names, provider_names,provider_ids
  857. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  858. LEFT JOIN participation c ON c.project_id = project.`id`
  859. LEFT JOIN user u ON u.id = c.user_id
  860. LEFT JOIN user d ON d.id = project.`incharger_id`
  861. WHERE project.`company_id` = #{companyId}
  862. <if test="userId != null" >
  863. and (project.creator_id = #{userId} or c.user_id = #{userId})
  864. </if>
  865. GROUP BY project.id
  866. </select>
  867. <!--按项目分组导出数据-->
  868. <select id="getExportGroupData" resultType="java.util.Map" >
  869. SELECT project_code as projectCode,project_name as projectName,task_group.`name` AS groupName,`user`.`name` AS inchargerName,`user`.corpwx_userid as corpwxUserId,`user`.corpwx_userid as corpwxUserId,
  870. (SELECT GROUP_CONCAT(name) FROM group_participator g LEFT JOIN `user` ON `user`.id = g.user_id WHERE g.group_id = group_participator.group_id GROUP BY g.group_id) AS participators,
  871. (SELECT GROUP_CONCAT(corpwx_userid) FROM group_participator g LEFT JOIN `user` ON `user`.id = g.user_id WHERE g.group_id = group_participator.group_id GROUP BY g.group_id) AS participatorsCorp
  872. FROM task_group
  873. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  874. LEFT JOIN project on task_group.project_id = project.id
  875. LEFT JOIN `user` ON task_group.incharger_id = `user`.id
  876. where project.company_id = #{companyId}
  877. GROUP BY task_group.id
  878. ORDER BY project_id
  879. </select>
  880. <!--分页获取项目工时成本预警表 -->
  881. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  882. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  883. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  884. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  885. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  886. AND project_id=project.id) AS costLimit,
  887. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  888. FROM project WHERE company_id=#{companyId}
  889. and (project.status &lt;&gt; 3 or project.status is null)
  890. <if test="projectId != null">
  891. and project.id = #{projectId}
  892. </if>
  893. <if test="pageStart != null and pageSize != null">
  894. LIMIT #{pageStart},#{pageSize}
  895. </if>
  896. </select>
  897. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  898. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  899. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  900. 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,
  901. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  902. 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,
  903. (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
  904. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  905. <if test="projectId != null">
  906. and project.id = #{projectId}
  907. </if>
  908. <if test="pageStart != null and pageSize != null">
  909. LIMIT #{pageStart},#{pageSize}
  910. </if>
  911. </select>
  912. <select id="getWaitingReviewList" resultType="java.util.Map">
  913. <choose>
  914. <when test="stateKey==0">
  915. 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
  916. FROM report AS a
  917. left join user on user.id = a.creator_id
  918. JOIN project AS b ON a.project_id=b.id
  919. left join sub_project as d on d.id = a.sub_project_id
  920. left join task on task.id = a.task_id
  921. left join report_extra_degree on report_extra_degree.id = a.degree_id
  922. left join department on department.department_id = a.audit_deptid
  923. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  924. left join department dept on dept.department_id = a.dept_id
  925. left join task_group on task_group.id = a.group_id
  926. left join user u on u.id = a.project_auditor_id
  927. WHERE a.company_id =#{companyId}
  928. and a.state = 0
  929. <if test="startDate!=null and endDate!=null">
  930. AND a.create_date between #{startDate} and #{endDate}
  931. </if>
  932. AND a.is_dept_audit=1
  933. <if test="userId!=null">
  934. and dept_manager.id=#{userId}
  935. </if>
  936. <if test="departmentId!=null">
  937. and dept_manager.department_id=#{departmentId}
  938. </if>
  939. <if test="deptIds!=null and deptIds.size()>0">
  940. and dept_manager.department_id in
  941. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  942. #{item}
  943. </foreach>
  944. </if>
  945. group by a.audit_dept_managerid
  946. ORDER BY a.create_date desc, a.creator_id asc
  947. </when>
  948. <otherwise>
  949. 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
  950. FROM report AS a
  951. left join user on user.id = a.creator_id
  952. JOIN project AS b ON a.project_id=b.id
  953. left join sub_project as d on d.id = a.sub_project_id
  954. left join task on task.id = a.task_id
  955. left join report_extra_degree on report_extra_degree.id = a.degree_id
  956. left join department on department.department_id = a.audit_deptid
  957. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  958. left join department dept on dept.department_id = a.dept_id
  959. left join task_group on task_group.id = a.group_id
  960. left join user u on u.id = a.project_auditor_id
  961. left join department dp on u.department_id=dp.department_id
  962. WHERE a.company_id =#{companyId}
  963. and a.state = 0
  964. <if test="startDate!=null and endDate!=null">
  965. AND a.create_date between #{startDate} and #{endDate}
  966. </if>
  967. AND a.is_dept_audit=0 and a.project_audit_state = 0
  968. <if test="userId!=null">
  969. and u.id=#{userId}
  970. </if>
  971. <if test="departmentId!=null">
  972. and u.department_id=#{departmentId}
  973. </if>
  974. <if test="deptIds!=null and deptIds.size()>0">
  975. and u.department_id in
  976. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  977. #{item}
  978. </foreach>
  979. </if>
  980. group by a.project_auditor_id
  981. ORDER BY a.create_date desc, a.creator_id asc
  982. </otherwise>
  983. </choose>
  984. <if test="start!=null and size!=null">
  985. limit #{start},#{size}
  986. </if>
  987. </select>
  988. <select id="findCount" resultType="java.lang.Long">
  989. select count(1)
  990. from (<choose>
  991. <when test="stateKey==0">
  992. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  993. FROM report AS a
  994. left join user on user.id = a.creator_id
  995. JOIN project AS b ON a.project_id=b.id
  996. left join sub_project as d on d.id = a.sub_project_id
  997. left join task on task.id = a.task_id
  998. left join report_extra_degree on report_extra_degree.id = a.degree_id
  999. left join department on department.department_id = a.audit_deptid
  1000. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1001. left join department dept on dept.department_id = a.dept_id
  1002. left join task_group on task_group.id = a.group_id
  1003. left join user u on u.id = a.project_auditor_id
  1004. WHERE a.company_id =#{companyId}
  1005. and a.state = 0
  1006. and u.is_active = 1
  1007. <if test="startDate!=null and endDate!=null">
  1008. AND a.create_date between #{startDate} and #{endDate}
  1009. </if>
  1010. AND a.is_dept_audit=1
  1011. <if test="userId!=null">
  1012. and dept_manager.id=#{userId}
  1013. </if>
  1014. <if test="departmentId!=null">
  1015. and dept_manager.department_id=#{departmentId}
  1016. </if>
  1017. <if test="deptIds!=null and deptIds.size()>0">
  1018. and dept_manager.department_id in
  1019. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1020. #{item}
  1021. </foreach>
  1022. </if>
  1023. group by a.audit_dept_managerid
  1024. ORDER BY a.create_date desc, a.creator_id asc
  1025. </when>
  1026. <otherwise>
  1027. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1028. FROM report AS a
  1029. left join user on user.id = a.creator_id
  1030. JOIN project AS b ON a.project_id=b.id
  1031. left join sub_project as d on d.id = a.sub_project_id
  1032. left join task on task.id = a.task_id
  1033. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1034. left join department on department.department_id = a.audit_deptid
  1035. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1036. left join department dept on dept.department_id = a.dept_id
  1037. left join task_group on task_group.id = a.group_id
  1038. left join user u on u.id = a.project_auditor_id
  1039. left join department dp on u.department_id=dp.department_id
  1040. WHERE a.company_id =#{companyId}
  1041. and a.state = 0
  1042. and u.is_active = 1
  1043. <if test="startDate!=null and endDate!=null">
  1044. AND a.create_date between #{startDate} and #{endDate}
  1045. </if>
  1046. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1047. <if test="userId!=null">
  1048. and u.id=#{userId}
  1049. </if>
  1050. <if test="departmentId!=null">
  1051. and u.department_id=#{departmentId}
  1052. </if>
  1053. <if test="deptIds!=null and deptIds.size()>0">
  1054. and u.department_id in
  1055. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1056. #{item}
  1057. </foreach>
  1058. </if>
  1059. group by a.project_auditor_id
  1060. ORDER BY a.create_date desc, a.creator_id asc
  1061. </otherwise>
  1062. </choose>
  1063. <if test="start!=null and size!=null">
  1064. limit #{start},#{size}
  1065. </if>) total
  1066. </select>
  1067. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1068. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1069. (select SUM(te.plan_hours) from task_executor te
  1070. left join task on task.id=te.task_id
  1071. where te.executor_id=us.id
  1072. <if test="startDate!=null and endDate!=null">
  1073. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1074. </if>) as planHours,
  1075. (select SUM(report.working_time) from report
  1076. left join task on task.id=report.task_id
  1077. where report.creator_id=us.id and task_id is not null and report.state=1
  1078. <if test="startDate!=null and endDate!=null">
  1079. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1080. </if>) as workingTime
  1081. from user us
  1082. left join department dp on dp.department_id=us.department_id
  1083. where us.company_id=#{companyId}
  1084. 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)
  1085. <if test="userId!=null and userId!=''">
  1086. and us.id=#{userId}
  1087. </if>
  1088. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1089. and us.department_id in
  1090. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1091. #{item}
  1092. </foreach>
  1093. </if>
  1094. <if test="deptIds!=null and deptIds.size()>0">
  1095. and us.department_id in
  1096. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1097. #{item}
  1098. </foreach>
  1099. </if>
  1100. group by us.id
  1101. order by us.department_id
  1102. <if test="start!=null and size!=null">
  1103. limit #{start},#{size}
  1104. </if>
  1105. </select>
  1106. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1107. select count(1)
  1108. from(select us.name,dp.department_name as departmentName,
  1109. (select SUM(te.plan_hours) from task_executor te
  1110. left join task on task.id=te.task_id
  1111. where te.executor_id=us.id
  1112. <if test="startDate!=null and endDate!=null">
  1113. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1114. </if>) as planHours,
  1115. (select SUM(report.working_time) from report
  1116. left join task on task.id=report.task_id
  1117. where report.creator_id=us.id and task_id is not null
  1118. <if test="startDate!=null and endDate!=null">
  1119. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1120. </if>) as workingTime
  1121. from user us
  1122. left join department dp on dp.department_id=us.department_id
  1123. where us.company_id=#{companyId}
  1124. 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)
  1125. <if test="userId!=null and userId!=''">
  1126. and us.id=#{userId}
  1127. </if>
  1128. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1129. and us.department_id in
  1130. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1131. #{item}
  1132. </foreach>
  1133. </if>
  1134. <if test="deptIds!=null and deptIds.size()>0">
  1135. and us.department_id in
  1136. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1137. #{item}
  1138. </foreach>
  1139. </if>
  1140. group by us.id
  1141. order by us.department_id)as total
  1142. </select>
  1143. <select id="selectWithGroup" resultType="java.util.Map">
  1144. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1145. from report a
  1146. left join task_group b on a.group_id=b.id
  1147. left join project c on a.project_id=c.id
  1148. where c.company_id=#{companyId} and a.state=1
  1149. <if test="startDate!=null and endDate!=null">
  1150. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1151. </if>
  1152. <if test="projectId!=null">
  1153. and c.id=#{projectId}
  1154. </if>
  1155. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1156. and c.id in
  1157. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1158. #{item}
  1159. </foreach>
  1160. </if>
  1161. <if test="groupId!=null">
  1162. and a.group_id=#{groupId}
  1163. </if>
  1164. group by b.name
  1165. order by c.id
  1166. <if test="startIndex!=null and endIndex!=null">
  1167. limit #{startIndex},#{endIndex}
  1168. </if>
  1169. </select>
  1170. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1171. select count(1) from(
  1172. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1173. from report a
  1174. left join task_group b on a.group_id=b.id
  1175. left join project c on a.project_id=c.id
  1176. where c.company_id=#{companyId} and a.state=1
  1177. <if test="startDate!=null and endDate!=null">
  1178. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1179. </if>
  1180. <if test="projectId!=null">
  1181. and c.id=#{projectId}
  1182. </if>
  1183. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1184. and c.id in
  1185. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1186. #{item}
  1187. </foreach>
  1188. </if>
  1189. <if test="groupId!=null">
  1190. and a.group_id=#{groupId}
  1191. </if>
  1192. group by b.name
  1193. order by c.id
  1194. <if test="startIndex!=null and endIndex!=null">
  1195. limit #{startIndex},#{endIndex}
  1196. </if>) as total
  1197. </select>
  1198. <select id="selectWithGroupProject" resultType="java.util.Map">
  1199. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1200. from report a
  1201. left join task_group b on a.group_id=b.id
  1202. left join project c on a.project_id=c.id
  1203. where c.company_id=#{companyId} and a.state=1
  1204. <if test="startDate!=null and endDate!=null">
  1205. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1206. </if>
  1207. <if test="projectId!=null">
  1208. and c.id=#{projectId}
  1209. </if>
  1210. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1211. and c.id in
  1212. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1213. #{item}
  1214. </foreach>
  1215. </if>
  1216. <if test="groupId!=null">
  1217. and a.group_id=#{groupId}
  1218. </if>
  1219. group by c.id,b.id
  1220. order by c.id
  1221. <if test="startIndex!=null and endIndex!=null">
  1222. limit #{startIndex},#{endIndex}
  1223. </if>
  1224. </select>
  1225. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1226. select count(1) from(
  1227. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1228. from report a
  1229. left join task_group b on a.group_id=b.id
  1230. left join project c on a.project_id=c.id
  1231. where c.company_id=#{companyId} and a.state=1
  1232. <if test="startDate!=null and endDate!=null">
  1233. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1234. </if>
  1235. <if test="projectId!=null">
  1236. and c.id=#{projectId}
  1237. </if>
  1238. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1239. and c.id in
  1240. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1241. #{item}
  1242. </foreach>
  1243. </if>
  1244. <if test="groupId!=null">
  1245. and a.group_id=#{groupId}
  1246. </if>
  1247. group by c.id,b.id
  1248. order by c.id
  1249. <if test="startIndex!=null and endIndex!=null">
  1250. limit #{startIndex},#{endIndex}
  1251. </if>) as total
  1252. </select>
  1253. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1254. 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
  1255. from report a
  1256. left join task_group b on a.group_id=b.id
  1257. left join project c on a.project_id=c.id
  1258. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1259. where c.company_id=#{companyId} and a.state=1
  1260. <if test="startDate!=null and endDate!=null">
  1261. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1262. </if>
  1263. <if test="projectId!=null">
  1264. and c.id=#{projectId}
  1265. </if>
  1266. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1267. and c.id in
  1268. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1269. #{item}
  1270. </foreach>
  1271. </if>
  1272. group by c.id,b.id
  1273. <if test="start!=null and size!=null">
  1274. limit #{start},#{size}
  1275. </if>
  1276. </select>
  1277. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1278. select count(1) from
  1279. (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
  1280. from report a
  1281. left join task_group b on a.group_id=b.id
  1282. left join project c on a.project_id=c.id
  1283. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1284. where c.company_id=#{companyId} and a.state=1
  1285. <if test="startDate!=null and endDate!=null">
  1286. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1287. </if>
  1288. <if test="projectId!=null">
  1289. and c.id=#{projectId}
  1290. </if>
  1291. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1292. and c.id in
  1293. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1294. #{item}
  1295. </foreach>
  1296. </if>
  1297. group by c.id,b.id
  1298. <if test="start!=null and size!=null">
  1299. limit #{start},#{size}
  1300. </if>) as total
  1301. </select>
  1302. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1303. 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
  1304. from report a
  1305. left join task_group b on a.group_id=b.id
  1306. left join project c on a.project_id=c.id
  1307. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1308. where c.company_id=#{companyId} and a.state=1
  1309. <if test="startDate!=null and endDate!=null">
  1310. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1311. </if>
  1312. <if test="projectId!=null">
  1313. and c.id=#{projectId}
  1314. </if>
  1315. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1316. and c.id in
  1317. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1318. #{item}
  1319. </foreach>
  1320. </if>
  1321. group by c.id,f.id
  1322. <if test="start!=null and size!=null">
  1323. limit #{start},#{size}
  1324. </if>
  1325. </select>
  1326. <select id="getCostByUserCustom" resultType="java.util.Map">
  1327. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1328. FROM user AS a
  1329. LEFT JOIN report AS b ON a.id = b.creator_id
  1330. LEFT JOIN project AS c ON b.project_id = c.id
  1331. left join user_custom uc on uc.company_id=a.company_id
  1332. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1333. WHERE b.state = 1
  1334. AND a.company_id = #{companyId}
  1335. <if test="startDate!=null and endDate!=null">
  1336. AND b.create_date between #{startDate} and #{endDate}
  1337. </if>
  1338. and uc.id=#{customId}
  1339. <if test="deptIds!=null and deptIds.size()>0">
  1340. and a.department_id in
  1341. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1342. #{item}
  1343. </foreach>
  1344. </if>
  1345. <if test="subCustomName!=null">
  1346. and suc.name=#{subCustomName}
  1347. </if>
  1348. GROUP BY suc.name
  1349. </select>
  1350. <select id="getEmpMonthHours" resultType="java.util.Map">
  1351. 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,
  1352. (select allday from time_type te
  1353. where te.company_id=#{companyId}) as allday,
  1354. (select SUM(report.working_time) from report
  1355. where report.creator_id=us.id and report.state=1
  1356. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1357. as workingTime
  1358. from user us
  1359. left join department dp on dp.department_id=us.department_id
  1360. where us.company_id=#{companyId}
  1361. 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)
  1362. <if test="userId!=null and userId!=''">
  1363. and us.id=#{userId}
  1364. </if>
  1365. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1366. and us.department_id in
  1367. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1368. #{item}
  1369. </foreach>
  1370. </if>
  1371. <if test="deptIds!=null and deptIds.size()>0">
  1372. and us.department_id in
  1373. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1374. #{item}
  1375. </foreach>
  1376. </if>
  1377. group by us.id
  1378. order by us.department_id
  1379. <if test="start!=null and size!=null">
  1380. limit #{start},#{size}
  1381. </if>
  1382. </select>
  1383. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1384. select count(1)
  1385. from(select us.name,dp.department_name as departmentName,
  1386. (select SUM(report.working_time) from report
  1387. where report.creator_id=us.id
  1388. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1389. as workingTime
  1390. from user us
  1391. left join department dp on dp.department_id=us.department_id
  1392. where us.company_id=#{companyId}
  1393. 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)
  1394. <if test="userId!=null and userId!=''">
  1395. and us.id=#{userId}
  1396. </if>
  1397. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1398. and us.department_id in
  1399. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1400. #{item}
  1401. </foreach>
  1402. </if>
  1403. <if test="deptIds!=null and deptIds.size()>0">
  1404. and us.department_id in
  1405. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1406. #{item}
  1407. </foreach>
  1408. </if>
  1409. group by us.id
  1410. order by us.department_id)as total
  1411. </select>
  1412. <!-- 分页查询部门参与项目情况-->
  1413. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1414. SELECT department.department_id deptId,
  1415. department_name deptName,
  1416. (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,
  1417. pro.projectCount projectCount,
  1418. pro.centerCount centerCount,
  1419. pcon.peopleCount peopleCount
  1420. FROM department
  1421. LEFT JOIN (
  1422. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1423. COUNT(DISTINCT(r.degree_id)) centerCount
  1424. FROM report
  1425. LEFT JOIN report r
  1426. ON report.id = r.id AND r.degree_id != -1
  1427. LEFT JOIN `user`
  1428. ON report.creator_id = user.id
  1429. WHERE report.state = 1
  1430. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1431. GROUP BY dept_id
  1432. ) pro
  1433. on pro.dept_id = department.department_id
  1434. LEFT JOIN (
  1435. SELECT dept_id,sum(p.con) peopleCount
  1436. FROM (
  1437. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1438. LEFT JOIN `user`
  1439. ON report.creator_id = user.id
  1440. WHERE report.state = 1
  1441. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1442. GROUP BY report.creator_id,dept_id
  1443. ) p GROUP BY p.dept_id
  1444. ) pcon
  1445. ON pcon.dept_id = department.department_id
  1446. WHERE department.company_id = #{companyId}
  1447. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1448. and department.department_id in
  1449. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1450. #{item}
  1451. </foreach>
  1452. </if>
  1453. <if test="deptIds!=null and deptIds.size()>0">
  1454. and department.department_id in
  1455. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1456. #{item}
  1457. </foreach>
  1458. </if>
  1459. <if test="size!=null and start!=null">
  1460. limit #{start},#{size}
  1461. </if>
  1462. </select>
  1463. <!--获取按项目分组的工时成本-->
  1464. <select id="getExportDegreeCost" resultType="java.util.Map">
  1465. 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
  1466. FROM project AS a
  1467. LEFT JOIN report AS b ON b.project_id = a.id
  1468. JOIN user AS c ON b.creator_id = c.id
  1469. WHERE a.company_id = #{companyId}
  1470. <if test="projectId != null">
  1471. AND a.id = #{projectId}
  1472. </if>
  1473. <if test="startDate != null and endDate != null">
  1474. AND b.create_date between #{startDate} and #{endDate}
  1475. </if>
  1476. <choose>
  1477. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1478. and b.dept_id in
  1479. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1480. #{item}
  1481. </foreach>
  1482. </when>
  1483. <otherwise>
  1484. <if test="deptIds!=null and deptIds.size()>0">
  1485. and (b.dept_id in
  1486. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1487. #{item}
  1488. </foreach>
  1489. <if test="deptRelatedProjectIds.size() > 0">
  1490. or a.id in
  1491. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  1492. #{pid}
  1493. </foreach>
  1494. </if>
  1495. )
  1496. </if>
  1497. </otherwise>
  1498. </choose>
  1499. AND b.state = 1
  1500. GROUP BY a.id
  1501. ORDER BY a.id ASC
  1502. </select>
  1503. <!--获取某个项目每个维度分别需要的工时-->
  1504. <select id="getDegreeDetailCost" resultType="java.util.Map">
  1505. 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
  1506. FROM report AS a
  1507. JOIN user AS b ON a.creator_id = b.id
  1508. left join department on department.department_id = a.dept_id
  1509. left join report_extra_degree as r on a.degree_id = r.id
  1510. WHERE a.company_id=#{companyId}
  1511. <if test="curProjectId != null">
  1512. and a.project_id = #{curProjectId}
  1513. </if>
  1514. <if test="projectId != null">
  1515. and a.project_id = #{projectId}
  1516. </if>
  1517. <if test="startDate != null and endDate != null">
  1518. AND a.create_date between #{startDate} and #{endDate}
  1519. </if>
  1520. <choose>
  1521. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1522. and a.dept_id in
  1523. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1524. #{item}
  1525. </foreach>
  1526. </when>
  1527. <otherwise>
  1528. <if test="deptIds!=null and deptIds.size()>0">
  1529. and a.dept_id in
  1530. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1531. #{item}
  1532. </foreach>
  1533. </if>
  1534. </otherwise>
  1535. </choose>
  1536. GROUP BY a.project_id,b.id,a.degree_id
  1537. ORDER BY b.id,a.degree_id ASC
  1538. </select>
  1539. <select id="selectNearProject" resultType="com.management.platform.entity.Project">
  1540. select * from project
  1541. where status = 1 and id in (
  1542. SELECT project_id
  1543. from (
  1544. SELECT project_id
  1545. FROM (
  1546. SELECT DISTINCT *
  1547. FROM report
  1548. WHERE creator_id = #{userId}
  1549. order by create_time
  1550. DESC
  1551. ) p1
  1552. GROUP BY project_id
  1553. order by create_time
  1554. DESC
  1555. LIMIT 3
  1556. ) p2
  1557. )
  1558. </select>
  1559. <select id="getFTEData" resultType="java.util.Map">
  1560. SELECT u.id,u.name userName,u.corpwx_userid wxUserId,u.plate1 area,SUM(r.working_time) workTime,p.project_name projectName,p.project_code projectCode
  1561. FROM `user` u
  1562. LEFT JOIN report r
  1563. ON u.id = r.creator_id
  1564. LEFT JOIN project p
  1565. ON r.project_id = p.id
  1566. WHERE r.state = 1
  1567. AND p.is_public = 0
  1568. AND u.company_id=#{companyId}
  1569. AND r.create_date BETWEEN #{startDate} AND #{endDate}
  1570. <if test="area!=null and area != '' ">
  1571. and u.plate1 = #{area}
  1572. </if>
  1573. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1574. and us.department_id in
  1575. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1576. #{item}
  1577. </foreach>
  1578. </if>
  1579. <if test="deptIds!=null and deptIds.size()>0">
  1580. and us.department_id in
  1581. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1582. #{item}
  1583. </foreach>
  1584. </if>
  1585. GROUP BY u.id,p.id,u.plate1,p.project_name,u.name,u.corpwx_userid,p.project_code
  1586. order by area,id
  1587. <if test="start!=null and size!=null">
  1588. limit #{start},#{size}
  1589. </if>
  1590. </select>
  1591. </mapper>