ProjectMapper.xml 37 KB

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