ProjectMapper.xml 80 KB

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