ProjectMapper.xml 76 KB

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