ProjectMapper.xml 65 KB

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