ProjectMapper.xml 41 KB

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