ProjectMapper.xml 65 KB

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