ProjectMapper.xml 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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. </resultMap>
  46. <!-- 通用查询结果列 -->
  47. <sql id="Base_Column_List">
  48. 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
  49. </sql>
  50. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  51. <result column="id" property="id" />
  52. <result column="project_name" property="projectName" />
  53. <result column="project_code" property="projectCode" />
  54. <collection property="stageCostList" javaType="java.util.ArrayList"
  55. ofType="com.management.platform.entity.vo.StageCost"
  56. select="selectStageSum" column="projectId=id"></collection>
  57. </resultMap>
  58. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  59. <result column="customer_id" property="customerId" />
  60. <result column="customer_name" property="customerName" />
  61. <result column="contract_amount" property="contractAmount" />
  62. <result column="fee_normal" property="feeNormal" />
  63. <result column="fee_travel" property="feeTravel" />
  64. <result column="fee_outsourcing" property="feeOutsourcing" />
  65. <result column="fee_man" property="feeMan" />
  66. <result column="project_num" property="projectNum" />
  67. <result column="project_ids" property="projectIds" />
  68. <result column="project_names" property="projectNames" />
  69. </resultMap>
  70. <select id="selectWithStage" resultMap="BaseResultMap2" >
  71. select id, project_code, project_name from project
  72. where company_id = #{companyId}
  73. <if test="projectId != null">
  74. and id = #{projectId}
  75. </if>
  76. <if test="inchagerIds!=null and inchagerIds.size()>0">
  77. and id in
  78. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  79. #{item}
  80. </foreach>
  81. </if>
  82. order by is_public desc, id asc
  83. <if test="startIndex != null">
  84. limit ${startIndex}, ${endIndex}
  85. </if>
  86. </select>
  87. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  88. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  89. IFNULL(SUM(report.`working_time`), 0) AS working_time
  90. FROM report where report.state = 1 and report.`project_id` = #{projectId}
  91. GROUP BY report.stage
  92. </select>
  93. <!--获取查询者所在公司每个项目的工时成本-->
  94. <select id="getParticipatedProject" resultType="java.util.Map">
  95. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  96. FROM project
  97. WHERE id IN (
  98. SELECT project_id
  99. FROM participation
  100. WHERE user_id = #{userId}
  101. ) or incharger_id = #{userId}
  102. or creator_id = #{userId}
  103. or (is_public = 1 and company_id = #{companyId})
  104. ORDER BY is_public DESC, id DESC
  105. </select>
  106. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  107. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  108. FROM project
  109. WHERE id IN (
  110. SELECT project_id
  111. FROM participation
  112. WHERE user_id = #{userId}
  113. )
  114. or (is_public = 1 and company_id = #{companyId})
  115. ORDER BY is_public DESC, id ASC
  116. </select>
  117. <!--获取查询者所在公司每个项目的工时成本-->
  118. <select id="getTimeCost" resultType="java.util.Map">
  119. 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
  120. FROM project AS a
  121. LEFT JOIN report AS b ON b.project_id = a.id
  122. JOIN user AS c ON b.creator_id = c.id
  123. WHERE a.company_id = #{companyId}
  124. <if test="projectId != null">
  125. AND a.id = #{projectId}
  126. </if>
  127. <if test="userId != null">
  128. AND b.creator_id = #{userId}
  129. </if>
  130. <if test="startDate != null and endDate != null">
  131. AND b.create_date between #{startDate} and #{endDate}
  132. </if>
  133. <if test="deptIds!=null and deptIds.size()>0">
  134. and b.dept_id in
  135. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  136. #{item}
  137. </foreach>
  138. </if>
  139. AND b.state = 1
  140. GROUP BY a.id
  141. ORDER BY a.id ASC
  142. </select>
  143. <!--获取查询者所在公司每个项目的工时成本-->
  144. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  145. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'未分类') as mainProjectName
  146. FROM project AS a
  147. LEFT JOIN report AS b ON b.project_id = a.id
  148. JOIN user AS c ON b.creator_id = c.id
  149. LEFT JOIN project_main pm on pm.id=a.project_main_id
  150. WHERE a.company_id = #{companyId}
  151. <if test="projectId != null">
  152. AND a.id = #{projectId}
  153. </if>
  154. <if test="userId != null">
  155. AND b.creator_id = #{userId}
  156. </if>
  157. <if test="startDate != null and endDate != null">
  158. AND b.create_date between #{startDate} and #{endDate}
  159. </if>
  160. <if test="deptIds!=null and deptIds.size()>0">
  161. and b.dept_id in
  162. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  163. #{item}
  164. </foreach>
  165. </if>
  166. AND b.state = 1
  167. GROUP BY a.project_main_id
  168. ORDER BY a.id ASC
  169. </select>
  170. <!--获取查询者所在公司每个项目分类的工时成本-->
  171. <select id="getTimeCostByCategory" resultType="java.util.Map">
  172. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  173. FROM project AS a
  174. LEFT JOIN report AS b ON b.project_id = a.id
  175. JOIN user AS c ON b.creator_id = c.id
  176. WHERE a.company_id = #{companyId}
  177. <if test="projectCategoryId != null">
  178. AND a.category = #{projectCategoryId}
  179. </if>
  180. <if test="userId != null">
  181. AND b.creator_id = #{userId}
  182. </if>
  183. <if test="startDate != null and endDate != null">
  184. AND b.create_date between #{startDate} and #{endDate}
  185. </if>
  186. <if test="deptIds!=null and deptIds.size()>0">
  187. and b.dept_id in
  188. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  189. #{item}
  190. </foreach>
  191. </if>
  192. AND b.state = 1
  193. GROUP BY a.category
  194. ORDER BY a.category ASC
  195. </select>
  196. <!--获取自定义数值的项目统计 -->
  197. <select id="getCustomDataSum" resultType="java.util.Map">
  198. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  199. FROM project AS a
  200. LEFT JOIN report AS b ON b.project_id = a.id
  201. JOIN user AS c ON b.creator_id = c.id
  202. WHERE a.company_id = #{companyId}
  203. <if test="projectId != null">
  204. AND a.id = #{projectId}
  205. </if>
  206. <if test="userId != null">
  207. AND b.creator_id = #{userId}
  208. </if>
  209. <if test="startDate != null and endDate != null">
  210. AND b.create_date between #{startDate} and #{endDate}
  211. </if>
  212. AND b.state = 1
  213. GROUP BY a.id
  214. ORDER BY SUM(b.custom_data) DESC
  215. </select>
  216. <!--获取日报的人员月度工时 -->
  217. <select id="getTimeCostReport" resultType="java.util.Map">
  218. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  219. FROM report AS a
  220. LEFT JOIN project AS b ON a.project_id = b.id
  221. LEFT JOIN user AS c ON a.creator_id = c.id
  222. WHERE b.company_id = #{companyId}
  223. <if test="projectId != null">
  224. AND b.id = #{projectId}
  225. </if>
  226. <if test="startDate != null and endDate != null">
  227. AND a.create_date between #{startDate} and #{endDate}
  228. </if>
  229. <if test="deptIds!=null and deptIds.size()>0">
  230. and a.dept_id in
  231. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  232. #{item}
  233. </foreach>
  234. </if>
  235. AND a.state = 1
  236. </select>
  237. <!--获取人员的月度总工时 -->
  238. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  239. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  240. FROM report AS a, user as b
  241. WHERE a.creator_id = b.id
  242. and b.company_id = #{companyId}
  243. <if test="startDate != null and endDate != null">
  244. AND a.create_date between #{startDate} and #{endDate}
  245. </if>
  246. AND a.state = 1
  247. group by a.creator_id
  248. </select>
  249. <!--获取某个项目每个人分别需要的工时-->
  250. <select id="getProjectCost" resultType="java.util.Map">
  251. 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
  252. FROM report AS a
  253. JOIN user AS b ON a.creator_id = b.id
  254. left join department on department.department_id = a.dept_id
  255. WHERE a.company_id=#{companyId} and (a.state = 1 or a.state =0)
  256. <if test="projectId != null">
  257. and a.project_id = #{projectId}
  258. </if>
  259. <if test="startDate != null and endDate != null">
  260. AND a.create_date between #{startDate} and #{endDate}
  261. </if>
  262. <if test="userId != null">
  263. AND a.creator_id = #{userId}
  264. </if>
  265. GROUP BY b.id, a.dept_id
  266. ORDER BY b.id ASC, a.dept_id ASC
  267. </select>
  268. <!--获取某个项目分类每个人分别需要的工时-->
  269. <select id="getProjectCostByCategory" resultType="java.util.Map">
  270. 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
  271. FROM report AS a
  272. JOIN user AS b ON a.creator_id = b.id
  273. left join department on department.department_id = a.dept_id
  274. left join project c on c.id=a.project_id
  275. WHERE a.company_id=#{companyId} and a.state = 1
  276. <if test="curProjectCategoryId != null">
  277. and c.category = #{curProjectCategoryId}
  278. </if>
  279. <if test="startDate != null and endDate != null">
  280. AND a.create_date between #{startDate} and #{endDate}
  281. </if>
  282. <if test="userId != null">
  283. AND a.creator_id = #{userId}
  284. </if>
  285. GROUP BY c.category, a.dept_id
  286. ORDER BY c.category ASC, a.dept_id ASC
  287. </select>
  288. <!--获取个人每个项目分别需要的工时-->
  289. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  290. 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
  291. FROM report AS a
  292. JOIN user AS b ON a.creator_id = b.id
  293. left join department on department.department_id = a.dept_id
  294. WHERE a.company_id=#{companyId} and a.state = 1
  295. <if test="projectId != null">
  296. and a.project_id = #{projectId}
  297. </if>
  298. <if test="startDate != null and endDate != null">
  299. AND a.create_date between #{startDate} and #{endDate}
  300. </if>
  301. <if test="userId != null">
  302. AND a.creator_id = #{userId}
  303. </if>
  304. <if test="deptIds!=null and deptIds.size()>0">
  305. and a.dept_id in
  306. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  307. #{item}
  308. </foreach>
  309. </if>
  310. GROUP BY b.id,a.project_id
  311. ORDER BY b.id ASC, a.dept_id ASC
  312. </select>
  313. <!--获取个人每个项目分类分别需要的工时-->
  314. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  315. 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
  316. FROM report AS a
  317. JOIN user AS b ON a.creator_id = b.id
  318. left join department on department.department_id = a.dept_id
  319. left join project c on c.id=a.project_id
  320. WHERE a.company_id=#{companyId} and a.state = 1
  321. <if test="projectCategoryId != null">
  322. and c.category = #{projectCategoryId}
  323. </if>
  324. <if test="startDate != null and endDate != null">
  325. AND a.create_date between #{startDate} and #{endDate}
  326. </if>
  327. <if test="userId != null">
  328. AND a.creator_id = #{userId}
  329. </if>
  330. <if test="deptIds!=null and deptIds.size()>0">
  331. and a.dept_id in
  332. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  333. #{item}
  334. </foreach>
  335. </if>
  336. GROUP BY b.id,c.category
  337. ORDER BY b.id ASC, a.dept_id ASC
  338. </select>
  339. <!-- 获取人员在日报填写的自定义数值 -->
  340. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  341. SELECT b.id as creatorId,
  342. b.name,department.department_name as departmentName, IFNULL(SUM(a.custom_data),0) AS cost
  343. FROM report AS a
  344. JOIN user AS b ON a.creator_id = b.id
  345. left join department on department.department_id = b.department_id
  346. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  347. <if test="startDate != null and endDate != null">
  348. AND a.create_date between #{startDate} and #{endDate}
  349. </if>
  350. <if test="projectId != null">
  351. AND a.project_id = #{projectId}
  352. </if>
  353. <if test="userId != null">
  354. AND a.creator_id = #{userId}
  355. </if>
  356. group by b.id
  357. ORDER BY b.id ASC
  358. </select>
  359. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  360. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  361. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  362. FROM report AS a
  363. JOIN user AS b ON a.creator_id = b.id
  364. left join department on department.department_id = b.department_id
  365. left join project on project.id = a.project_id
  366. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  367. <if test="startDate != null and endDate != null">
  368. AND a.create_date between #{startDate} and #{endDate}
  369. </if>
  370. <if test="projectId != null">
  371. AND a.project_id = #{projectId}
  372. </if>
  373. <if test="userId != null">
  374. AND a.creator_id = #{userId}
  375. </if>
  376. ORDER BY a.create_date desc
  377. </select>
  378. <!--按照项目内的阶段名称分组统计工时-->
  379. <select id="getCostInStage" resultType="java.util.Map">
  380. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  381. FROM report AS a
  382. WHERE a.project_id = #{projectId}
  383. AND a.state = 1
  384. <if test="startDate != null and endDate != null">
  385. AND a.create_date between #{startDate} and #{endDate}
  386. </if>
  387. GROUP BY a.stage
  388. ORDER BY a.stage ASC
  389. </select>
  390. <!--按照项目内的阶段名称分组统计工时-->
  391. <select id="getCostByGroup" resultType="java.util.Map">
  392. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  393. FROM report AS a
  394. left join task_group tg on tg.id=a.group_id
  395. WHERE a.project_id = #{projectId}
  396. AND a.state = 1
  397. <if test="startDate != null and endDate != null">
  398. AND a.create_date between #{startDate} and #{endDate}
  399. </if>
  400. GROUP BY a.group_id
  401. ORDER BY a.group_id ASC
  402. </select>
  403. <!--获取全部人员工时 -->
  404. <select id="getAllMembCost" resultType="java.util.Map">
  405. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  406. FROM user AS b
  407. left JOIN report AS a ON a.creator_id = b.id
  408. WHERE a.state = 1
  409. and b.company_id = #{companyId}
  410. <if test="startDate != null and endDate != null">
  411. AND a.create_date between #{startDate} and #{endDate}
  412. </if>
  413. <if test="projectId != null">
  414. AND a.project_id = #{projectId}
  415. </if>
  416. GROUP BY b.id
  417. ORDER BY b.id ASC
  418. </select>
  419. <!--分页获取项目成本 -->
  420. <select id="getAllProjectCost" resultMap="BaseResultMap">
  421. SELECT id, project_code, project_name,
  422. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  423. (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,
  424. (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,
  425. (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
  426. FROM project WHERE project.`company_id` = #{companyId}
  427. and (project.status &lt;&gt; 3 or project.status is null)
  428. <if test="projectId != null">
  429. and project.id = #{projectId}
  430. </if>
  431. <if test="inchagerIds!=null and inchagerIds.size()>0">
  432. and project.id in
  433. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  434. #{item}
  435. </foreach>
  436. </if>
  437. order by project.is_public desc, project.id asc
  438. <if test="pageStart != null and pageSize != null">
  439. LIMIT #{pageStart},#{pageSize}
  440. </if>
  441. </select>
  442. <!--分页获取项目收支平衡 -->
  443. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  444. SELECT project_code, project_name,contract_amount,
  445. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  446. (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,
  447. (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,
  448. (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
  449. FROM project WHERE project.`company_id` = #{companyId}
  450. and (project.status &lt;&gt; 3 or project.status is null)
  451. <if test="projectId != null">
  452. and project.id = #{projectId}
  453. </if>
  454. <if test="inchagerIds!=null and inchagerIds.size()>0">
  455. and project.id in
  456. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  457. #{item}
  458. </foreach>
  459. </if>
  460. order by is_public desc, id asc
  461. <if test="pageStart != null and pageSize != null">
  462. LIMIT #{pageStart},#{pageSize}
  463. </if>
  464. </select>
  465. <!--分页获取客户项目的成本利润报表 -->
  466. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  467. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  468. SUM(contract_amount) AS contract_amount ,
  469. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man,
  470. 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,
  471. 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,
  472. 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
  473. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  474. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  475. <if test="customerId!=null">
  476. and project.customer_id=#{customerId}
  477. </if>
  478. <if test="projectId!=null">
  479. and project.id=#{projectId}
  480. </if>
  481. GROUP BY customer_id
  482. <if test="pageStart != null and pageSize != null">
  483. LIMIT #{pageStart},#{pageSize}
  484. </if>
  485. </select>
  486. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  487. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  488. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  489. <if test="customerId!=null">
  490. and project.customer_id=#{customerId}
  491. </if>
  492. <if test="projectId!=null">
  493. and project.id=#{projectId}
  494. </if>
  495. </select>
  496. <!--分页获取项目收支平衡 -->
  497. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  498. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  499. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  500. (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,
  501. (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,
  502. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0) AS fee_outsourcing
  503. FROM project WHERE project.`company_id` = #{companyId}
  504. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  505. #{item}
  506. </foreach>
  507. </select>
  508. <select id="getGanttData" resultType="java.util.Map">
  509. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  510. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  511. LEFT JOIN user ON user.id = participation.`user_id`
  512. LEFT JOIN project ON project.`id` = participation.`project_id`
  513. WHERE participation.`user_id` IN
  514. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  515. #{item}
  516. </foreach>
  517. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  518. ORDER BY participation.user_id, project.`plan_start_date`
  519. </select>
  520. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  521. 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,
  522. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration FROM user
  523. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  524. left join task on task.id = task_executor.task_id
  525. LEFT JOIN project ON project.`id` = task.`project_id`
  526. WHERE user.`id` IN
  527. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  528. #{item}
  529. </foreach>
  530. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  531. and task.end_date is not null
  532. AND project.`status` = 1
  533. ORDER BY user.id, task.start_date
  534. </select>
  535. <select id="getTaskPlanByProject" resultType="java.util.Map">
  536. 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,
  537. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  538. LEFT JOIN task ON task.project_id = project.id
  539. WHERE project.company_id = #{companyId}
  540. <if test="projectIds != null">
  541. and project.`id` IN
  542. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  543. #{item}
  544. </foreach>
  545. </if>
  546. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  547. and task.end_date is not null
  548. AND project.`status` = 1
  549. ORDER BY project.id, task.start_date
  550. </select>
  551. <!--获取加班统计报表 -->
  552. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  553. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  554. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  555. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  556. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  557. <!-- left join project on project.id = report.project_id-->
  558. <!-- WHERE report.is_overtime = 1-->
  559. <!-- and report.`state` = 1-->
  560. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  561. <!-- AND user.`company_id` = #{companyId}-->
  562. <!-- <if test="projectId != null">-->
  563. <!-- AND report.`project_id` = #{projectId}-->
  564. <!-- </if>-->
  565. <!-- <if test="userId != null">-->
  566. <!-- AND report.`creator_id` = #{userId}-->
  567. <!-- </if>-->
  568. <!-- GROUP BY report.creator_id-->
  569. <!-- </select>-->
  570. <!-- 获取某个员工的某时间段内的加班详情 -->
  571. <select id="getOvertimeDetail" resultType="java.util.Map">
  572. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  573. report.`creator_id` AS userId, user.`name` AS username, report.`working_time` AS workingTime,
  574. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,
  575. project.project_name as projectName,project.project_code as projectCode,
  576. IFNULL(report.overtime_cost, 0) AS cost,
  577. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  578. left join project on project.id = report.project_id
  579. left join report_extra_degree on report_extra_degree.id = report.degree_id
  580. left join department on department.department_id = report.dept_id
  581. WHERE report.is_overtime = 1
  582. and report.`state` = 1
  583. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  584. AND user.`company_id` = #{companyId}
  585. <if test="projectId != null">
  586. AND report.`project_id` = #{projectId}
  587. </if>
  588. <if test="userId != null">
  589. AND report.`creator_id` = #{userId}
  590. </if>
  591. <if test="departmentId!=null">
  592. and report.dept_id=#{departmentId}
  593. </if>
  594. <if test="deptIds!=null and deptIds.size()>0">
  595. and report.dept_id in
  596. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  597. #{item}
  598. </foreach>
  599. </if>
  600. order by user.create_time asc, report.create_date desc
  601. </select>
  602. <!--获取人员工时-->
  603. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  604. SELECT report.`creator_id` AS userId, user.`name` AS username,
  605. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  606. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  607. ifnull(SUM(report.`working_time`),0) AS workingTime
  608. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  609. left join project on project.id = report.project_id
  610. WHERE
  611. report.`state` = 1
  612. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  613. AND user.`company_id` =#{companyId}
  614. <if test="userId!=null">
  615. and user.id=#{userId}
  616. </if>
  617. <if test="projectId!=null">
  618. and project.id=#{projectId}
  619. </if>
  620. <if test="departmentId!=null">
  621. and report.dept_id=#{departmentId}
  622. </if>
  623. <if test="deptIds!=null and deptIds.size()>0">
  624. and report.dept_id in
  625. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  626. #{item}
  627. </foreach>
  628. </if>
  629. group by user.id
  630. order by user.create_time asc, report.create_date desc
  631. <if test="start!=null and size!=null">
  632. limit #{start},#{size}
  633. </if>
  634. </select>
  635. <select id="findCountWithUser" resultType="java.lang.Long">
  636. select count(*)
  637. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  638. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  639. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  640. ifnull(SUM(report.`working_time`),0) AS workingTime
  641. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  642. left join project on project.id = report.project_id
  643. WHERE
  644. report.`state` = 1
  645. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  646. AND user.`company_id` =#{companyId}
  647. <if test="userId!=null">
  648. and user.id=#{userId}
  649. </if>
  650. <if test="projectId!=null">
  651. and project.id=#{projectId}
  652. </if>
  653. <if test="departmentId!=null">
  654. and report.dept_id=#{departmentId}
  655. </if>
  656. <if test="deptIds!=null and deptIds.size()>0">
  657. and report.dept_id in
  658. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  659. #{item}
  660. </foreach>
  661. </if>
  662. group by user.id
  663. order by user.create_time asc, report.create_date desc
  664. <if test="start!=null and size!=null">
  665. limit #{start},#{size}
  666. </if>) as total
  667. </select>
  668. <!--按照项目内的阶段名称分组统计工时-->
  669. <select id="getDegreeCost" resultType="java.util.Map">
  670. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  671. FROM report AS a
  672. left join report_extra_degree b on b.id = a.degree_id
  673. WHERE
  674. a.state = 1
  675. and a.company_id = #{companyId}
  676. <if test="departmentIds!=null and departmentIds.size()>0">
  677. and a.dept_id in
  678. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  679. #{item}
  680. </foreach>
  681. </if>
  682. <if test="projectId != null">
  683. and a.project_id = #{projectId}
  684. </if>
  685. <if test="startDate != null and endDate != null">
  686. AND a.create_date between #{startDate} and #{endDate}
  687. </if>
  688. GROUP BY a.degree_id
  689. ORDER BY a.degree_id ASC
  690. </select>
  691. <!--项目导出数据-->
  692. <select id="getExportData" resultType="java.util.HashMap" >
  693. 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,
  694. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  695. customer_name, associate_degree_names, provider_names,provider_ids
  696. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  697. LEFT JOIN participation c ON c.project_id = project.`id`
  698. LEFT JOIN user u ON u.id = c.user_id
  699. LEFT JOIN user d ON d.id = project.`incharger_id`
  700. WHERE project.`company_id` = #{companyId}
  701. <if test="userId != null" >
  702. and (project.creator_id = #{userId} or c.user_id = #{userId})
  703. </if>
  704. GROUP BY project.id
  705. </select>
  706. <!--分页获取项目工时成本预警表 -->
  707. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  708. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  709. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  710. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  711. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  712. AND project_id=project.id) AS costLimit,
  713. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  714. FROM project WHERE company_id=#{companyId}
  715. and (project.status &lt;&gt; 3 or project.status is null)
  716. <if test="projectId != null">
  717. and project.id = #{projectId}
  718. </if>
  719. <if test="pageStart != null and pageSize != null">
  720. LIMIT #{pageStart},#{pageSize}
  721. </if>
  722. </select>
  723. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  724. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  725. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  726. 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,
  727. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  728. 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,
  729. (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
  730. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  731. <if test="projectId != null">
  732. and project.id = #{projectId}
  733. </if>
  734. <if test="pageStart != null and pageSize != null">
  735. LIMIT #{pageStart},#{pageSize}
  736. </if>
  737. </select>
  738. <select id="getWaitingReviewList" resultType="java.util.Map">
  739. select us.name as userName,dp.department_name as departmentName,COUNT(rp.state=0 or null) as num
  740. from user us
  741. left join report rp on rp.audit_deptid=us.manage_dept_id or rp.project_auditor_id=us.id
  742. left join department dp on dp.department_id=rp.dept_id
  743. where us.company_id=#{companyId} and (rp.audit_deptid !=0 or rp.project_id is not null) and rp.create_date between #{startDate} and #{endDate} and us.is_active=1
  744. <if test="userId!=null">
  745. and us.id=#{userId}
  746. </if>
  747. <if test="departmentId!=null">
  748. and rp.dept_id=#{departmentId}
  749. </if>
  750. group by us.id
  751. order by rp.dept_id
  752. <if test="start!=null and size!=null">
  753. limit #{start},#{size}
  754. </if>
  755. </select>
  756. <select id="findCount" resultType="java.lang.Long">
  757. select count(1)
  758. from (select us.name as userName,dp.department_name as departmentName,COUNT(rp.state=0 or null) as num
  759. from user us
  760. left join report rp on rp.audit_deptid=us.manage_dept_id or rp.project_auditor_id=us.id
  761. left join department dp on dp.department_id=rp.dept_id
  762. where us.company_id=#{companyId} and (rp.audit_deptid !=0 or rp.project_id is not null) and rp.create_date between #{startDate} and #{endDate} and us.is_active=1
  763. <if test="userId!=null">
  764. and us.id=#{userId}
  765. </if>
  766. <if test="departmentId!=null">
  767. and rp.dept_id=#{departmentId}
  768. </if>
  769. group by us.id
  770. order by rp.dept_id
  771. <if test="start!=null and size!=null">
  772. limit #{start},#{size}
  773. </if>) total
  774. </select>
  775. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  776. select us.name,dp.department_name as departmentName,
  777. (select SUM(te.plan_hours) from task_executor te
  778. left join task on task.id=te.task_id
  779. where te.executor_id=us.id
  780. <if test="startDate!=null and endDate!=null">
  781. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  782. </if>) as planHours,
  783. (select SUM(report.working_time) from report
  784. left join task on task.id=report.task_id
  785. where report.creator_id=us.id and task_id is not null and report.state=1
  786. <if test="startDate!=null and endDate!=null">
  787. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  788. </if>) as workingTime
  789. from user us
  790. left join department dp on dp.department_id=us.department_id
  791. where us.company_id=#{companyId}
  792. <if test="userId!=null and userId!=''">
  793. and us.id=#{userId}
  794. </if>
  795. <if test="departmentId!=null">
  796. and us.department_id=#{departmentId}
  797. </if>
  798. <if test="deptIds!=null and deptIds.size()>0">
  799. and us.department_id in
  800. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  801. #{item}
  802. </foreach>
  803. </if>
  804. group by us.id
  805. order by us.department_id
  806. <if test="start!=null and size!=null">
  807. limit #{start},#{size}
  808. </if>
  809. </select>
  810. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  811. select count(1)
  812. from(select us.name,dp.department_name as departmentName,
  813. (select SUM(te.plan_hours) from task_executor te
  814. left join task on task.id=te.task_id
  815. where te.executor_id=us.id
  816. <if test="startDate!=null and endDate!=null">
  817. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  818. </if>) as planHours,
  819. (select SUM(report.working_time) from report
  820. left join task on task.id=report.task_id
  821. where report.creator_id=us.id and task_id is not null
  822. <if test="startDate!=null and endDate!=null">
  823. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  824. </if>) as workingTime
  825. from user us
  826. left join department dp on dp.department_id=us.department_id
  827. where us.company_id=#{companyId}
  828. <if test="userId!=null and userId!=''">
  829. and us.id=#{userId}
  830. </if>
  831. <if test="departmentId!=null">
  832. and us.department_id=#{departmentId}
  833. </if>
  834. <if test="deptIds!=null and deptIds.size()>0">
  835. and us.department_id in
  836. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  837. #{item}
  838. </foreach>
  839. </if>
  840. group by us.id
  841. order by us.department_id)as total
  842. </select>
  843. </mapper>