ProjectMapper.xml 41 KB

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