ProjectMapper.xml 58 KB

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