ProjectMapper.xml 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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, report.`working_time` AS workingTime,
  615. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,
  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,
  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="getProjectCostAlarm" resultType="java.util.HashMap">
  755. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  756. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  757. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  758. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  759. AND project_id=project.id) AS costLimit,
  760. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  761. FROM project WHERE company_id=#{companyId}
  762. and (project.status &lt;&gt; 3 or project.status is null)
  763. <if test="projectId != null">
  764. and project.id = #{projectId}
  765. </if>
  766. <if test="pageStart != null and pageSize != null">
  767. LIMIT #{pageStart},#{pageSize}
  768. </if>
  769. </select>
  770. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  771. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  772. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  773. 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,
  774. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  775. 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,
  776. (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
  777. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  778. <if test="projectId != null">
  779. and project.id = #{projectId}
  780. </if>
  781. <if test="pageStart != null and pageSize != null">
  782. LIMIT #{pageStart},#{pageSize}
  783. </if>
  784. </select>
  785. <select id="getWaitingReviewList" resultType="java.util.Map">
  786. <choose>
  787. <when test="stateKey==0">
  788. select us.name as userName,dp2.department_name as departmentName,COUNT(rp.state=0 or null) as num
  789. from department dp
  790. left join user us on dp.manager_id=us.id
  791. left join report rp on rp.audit_deptid=us.manage_dept_id and rp.create_date between #{startDate} and #{endDate} and rp.audit_deptid !=0 and rp.is_dept_audit=1
  792. left join department dp2 on dp2.department_id=dp.department_id
  793. </when>
  794. <otherwise>
  795. select us.name as userName,dp.department_name as departmentName,COUNT(rp.state=0 or null) as num
  796. from project_auditor pa
  797. left join user us on pa.auditor_id=us.id
  798. left join report rp on rp.project_auditor_id=us.id and pa.project_id=rp.project_id and rp.create_date between #{startDate} and #{endDate} and rp.is_dept_audit=0
  799. left join department dp on dp.department_id=us.department_id
  800. </otherwise>
  801. </choose>
  802. where us.company_id=#{companyId} and us.is_active=1
  803. <if test="userId!=null">
  804. and us.id=#{userId}
  805. </if>
  806. <if test="departmentId!=null">
  807. and us.department_id=#{departmentId}
  808. </if>
  809. group by us.id
  810. order by us.department_id
  811. <if test="start!=null and size!=null">
  812. limit #{start},#{size}
  813. </if>
  814. </select>
  815. <select id="findCount" resultType="java.lang.Long">
  816. select count(1)
  817. from (<choose>
  818. <when test="stateKey==0">
  819. select us.name as userName,dp2.department_name as departmentName,COUNT(rp.state=0 or null) as num
  820. from department dp
  821. left join user us on dp.manager_id=us.id
  822. left join report rp on rp.audit_deptid=us.manage_dept_id and rp.create_date between #{startDate} and #{endDate} and rp.audit_deptid !=0
  823. left join department dp2 on dp2.department_id=dp.department_id
  824. </when>
  825. <otherwise>
  826. select us.name as userName,dp.department_name as departmentName,COUNT(rp.state=0 or null) as num
  827. from project_auditor pa
  828. left join user us on pa.auditor_id=us.id
  829. left join report rp on rp.project_auditor_id=us.id and pa.project_id=rp.project_id and rp.create_date between #{startDate} and #{endDate}
  830. left join department dp on dp.department_id=us.department_id
  831. </otherwise>
  832. </choose>
  833. where us.company_id=#{companyId} and us.is_active=1
  834. <if test="userId!=null">
  835. and us.id=#{userId}
  836. </if>
  837. <if test="departmentId!=null">
  838. and us.department_id=#{departmentId}
  839. </if>
  840. group by us.id
  841. order by us.department_id
  842. <if test="start!=null and size!=null">
  843. limit #{start},#{size}
  844. </if>) total
  845. </select>
  846. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  847. select us.name,dp.department_name as departmentName,
  848. (select SUM(te.plan_hours) from task_executor te
  849. left join task on task.id=te.task_id
  850. where te.executor_id=us.id
  851. <if test="startDate!=null and endDate!=null">
  852. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  853. </if>) as planHours,
  854. (select SUM(report.working_time) from report
  855. left join task on task.id=report.task_id
  856. where report.creator_id=us.id and task_id is not null and report.state=1
  857. <if test="startDate!=null and endDate!=null">
  858. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  859. </if>) as workingTime
  860. from user us
  861. left join department dp on dp.department_id=us.department_id
  862. where us.company_id=#{companyId}
  863. <if test="userId!=null and userId!=''">
  864. and us.id=#{userId}
  865. </if>
  866. <if test="branchDepartment!=null and branchDepartment.size()>0">
  867. and us.department_id in
  868. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  869. #{item}
  870. </foreach>
  871. </if>
  872. <if test="deptIds!=null and deptIds.size()>0">
  873. and us.department_id in
  874. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  875. #{item}
  876. </foreach>
  877. </if>
  878. group by us.id
  879. order by us.department_id
  880. <if test="start!=null and size!=null">
  881. limit #{start},#{size}
  882. </if>
  883. </select>
  884. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  885. select count(1)
  886. from(select us.name,dp.department_name as departmentName,
  887. (select SUM(te.plan_hours) from task_executor te
  888. left join task on task.id=te.task_id
  889. where te.executor_id=us.id
  890. <if test="startDate!=null and endDate!=null">
  891. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  892. </if>) as planHours,
  893. (select SUM(report.working_time) from report
  894. left join task on task.id=report.task_id
  895. where report.creator_id=us.id and task_id is not null
  896. <if test="startDate!=null and endDate!=null">
  897. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  898. </if>) as workingTime
  899. from user us
  900. left join department dp on dp.department_id=us.department_id
  901. where us.company_id=#{companyId}
  902. <if test="userId!=null and userId!=''">
  903. and us.id=#{userId}
  904. </if>
  905. <if test="branchDepartment!=null and branchDepartment.size()>0">
  906. and us.department_id in
  907. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  908. #{item}
  909. </foreach>
  910. </if>
  911. <if test="deptIds!=null and deptIds.size()>0">
  912. and us.department_id in
  913. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  914. #{item}
  915. </foreach>
  916. </if>
  917. group by us.id
  918. order by us.department_id)as total
  919. </select>
  920. <select id="selectWithGroup" resultType="java.util.Map">
  921. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  922. from report a
  923. left join task_group b on a.group_id=b.id
  924. left join project c on a.project_id=c.id
  925. where c.company_id=#{companyId} and a.state=1
  926. <if test="startDate!=null and endDate!=null">
  927. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  928. </if>
  929. <if test="projectId!=null">
  930. and c.id=#{projectId}
  931. </if>
  932. <if test="inchagerIds!=null and inchagerIds.size()>0">
  933. and c.id in
  934. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  935. #{item}
  936. </foreach>
  937. </if>
  938. <if test="groupId!=null">
  939. and a.group_id=#{groupId}
  940. </if>
  941. group by b.name
  942. order by c.id
  943. <if test="startIndex!=null and endIndex!=null">
  944. limit #{startIndex},#{endIndex}
  945. </if>
  946. </select>
  947. <select id="selectCountWithGroup" resultType="java.lang.Long">
  948. select count(1) from(
  949. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  950. from report a
  951. left join task_group b on a.group_id=b.id
  952. left join project c on a.project_id=c.id
  953. where c.company_id=#{companyId} and a.state=1
  954. <if test="startDate!=null and endDate!=null">
  955. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  956. </if>
  957. <if test="projectId!=null">
  958. and c.id=#{projectId}
  959. </if>
  960. <if test="inchagerIds!=null and inchagerIds.size()>0">
  961. and c.id in
  962. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  963. #{item}
  964. </foreach>
  965. </if>
  966. <if test="groupId!=null">
  967. and a.group_id=#{groupId}
  968. </if>
  969. group by b.name
  970. order by c.id
  971. <if test="startIndex!=null and endIndex!=null">
  972. limit #{startIndex},#{endIndex}
  973. </if>) as total
  974. </select>
  975. <select id="selectWithGroupProject" resultType="java.util.Map">
  976. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  977. from report a
  978. left join task_group b on a.group_id=b.id
  979. left join project c on a.project_id=c.id
  980. where c.company_id=#{companyId} and a.state=1
  981. <if test="startDate!=null and endDate!=null">
  982. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  983. </if>
  984. <if test="projectId!=null">
  985. and c.id=#{projectId}
  986. </if>
  987. <if test="inchagerIds!=null and inchagerIds.size()>0">
  988. and c.id in
  989. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  990. #{item}
  991. </foreach>
  992. </if>
  993. <if test="groupId!=null">
  994. and a.group_id=#{groupId}
  995. </if>
  996. group by c.id,b.id
  997. order by c.id
  998. <if test="startIndex!=null and endIndex!=null">
  999. limit #{startIndex},#{endIndex}
  1000. </if>
  1001. </select>
  1002. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1003. select count(1) from(
  1004. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1005. from report a
  1006. left join task_group b on a.group_id=b.id
  1007. left join project c on a.project_id=c.id
  1008. where c.company_id=#{companyId} and a.state=1
  1009. <if test="startDate!=null and endDate!=null">
  1010. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1011. </if>
  1012. <if test="projectId!=null">
  1013. and c.id=#{projectId}
  1014. </if>
  1015. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1016. and c.id in
  1017. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1018. #{item}
  1019. </foreach>
  1020. </if>
  1021. <if test="groupId!=null">
  1022. and a.group_id=#{groupId}
  1023. </if>
  1024. group by c.id,b.id
  1025. order by c.id
  1026. <if test="startIndex!=null and endIndex!=null">
  1027. limit #{startIndex},#{endIndex}
  1028. </if>) as total
  1029. </select>
  1030. <select id="getCostByUserCustom" resultType="java.util.Map">
  1031. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1032. FROM user AS a
  1033. LEFT JOIN report AS b ON a.id = b.creator_id
  1034. LEFT JOIN project AS c ON b.project_id = c.id
  1035. left join user_custom uc on uc.company_id=a.company_id
  1036. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1037. WHERE b.state = 1
  1038. AND a.company_id = #{companyId}
  1039. <if test="startDate!=null and endDate!=null">
  1040. AND b.create_date between #{startDate} and #{endDate}
  1041. </if>
  1042. and uc.id=#{customId}
  1043. <if test="deptIds!=null and deptIds.size()>0">
  1044. and a.department_id in
  1045. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1046. #{item}
  1047. </foreach>
  1048. </if>
  1049. <if test="subCustomName!=null">
  1050. and suc.name=#{subCustomName}
  1051. </if>
  1052. GROUP BY suc.name
  1053. </select>
  1054. </mapper>