ProjectMapper.xml 76 KB

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