ProjectMapper.xml 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.management.platform.mapper.ProjectMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Project">
  6. <id column="id" property="id" />
  7. <result column="project_name" property="projectName" />
  8. <result column="company_id" property="companyId" />
  9. <result column="project_code" property="projectCode" />
  10. <result column="incharger_id" property="inchargerId" />
  11. <result column="plan_start_date" property="planStartDate" />
  12. <result column="plan_end_date" property="planEndDate" />
  13. <result column="progress" property="progress" />
  14. <result column="level" property="level" />
  15. <result column="status" property="status" />
  16. <result column="finish_date" property="finishDate" />
  17. <result column="creator_id" property="creatorId" />
  18. <result column="creator_name" property="creatorName" />
  19. <result column="create_date" property="createDate" />
  20. <result column="contract_amount" property="contractAmount" />
  21. <result column="budget" property="budget" />
  22. <result column="base_man" property="baseMan" />
  23. <result column="base_outsourcing" property="baseOutsourcing" />
  24. <result column="base_risk1" property="baseRisk1" />
  25. <result column="base_risk2" property="baseRisk2" />
  26. <result column="base_fee" property="baseFee" />
  27. <result column="fee_normal" property="feeNormal" />
  28. <result column="fee_travel" property="feeTravel" />
  29. <result column="fee_outsourcing" property="feeOutsourcing" />
  30. <result column="fee_man" property="feeMan" />
  31. <result column="customer_id" property="customerId" />
  32. <result column="customer_name" property="customerName" />
  33. <result column="is_public" property="isPublic" />
  34. <result column="associate_degrees" property="associateDegrees" />
  35. <result column="associate_degree_names" property="associateDegreeNames" />
  36. <result column="task_gp_incharge" property="taskGpIncharge" />
  37. <result column="category" property="category" />
  38. <result column="category_name" property="categoryName" />
  39. <result column="project_desc" property="projectDesc" />
  40. <result column="project_main_id" property="projectMainId" />
  41. <result column="provider_ids" property="providerIds" />
  42. <result column="provider_names" property="providerNames" />
  43. <result column="current_stage_id" property="currentStageId" />
  44. <result column="current_stage_name" property="currentStageName" />
  45. <result column="output_value" property="outputValue" />
  46. <result column="dept_id" property="deptId" />
  47. <result column="dept_cascade" property="deptCascade" />
  48. </resultMap>
  49. <!-- 通用查询结果列 -->
  50. <sql id="Base_Column_List">
  51. id, project_name, company_id, project_code, incharger_id, plan_start_date, plan_end_date, progress, level, status, finish_date, creator_id, creator_name, create_date, contract_amount, budget, base_man, base_outsourcing, base_risk1, base_risk2, base_fee, fee_normal, fee_travel, fee_outsourcing, fee_man, customer_id, customer_name, is_public, associate_degrees, associate_degree_names, task_gp_incharge, category, category_name, project_desc, project_main_id, provider_ids, provider_names, current_stage_id, current_stage_name, output_value, dept_id, dept_cascade
  52. </sql>
  53. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  54. <result column="id" property="id" />
  55. <result column="project_name" property="projectName" />
  56. <result column="project_code" property="projectCode" />
  57. <collection property="stageCostList" javaType="java.util.ArrayList"
  58. ofType="com.management.platform.entity.vo.StageCost"
  59. select="selectStageSum" column="projectId=id"></collection>
  60. </resultMap>
  61. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  62. <result column="customer_id" property="customerId" />
  63. <result column="customer_name" property="customerName" />
  64. <result column="contract_amount" property="contractAmount" />
  65. <result column="fee_normal" property="feeNormal" />
  66. <result column="fee_travel" property="feeTravel" />
  67. <result column="fee_outsourcing" property="feeOutsourcing" />
  68. <result column="fee_man" property="feeMan" />
  69. <result column="project_num" property="projectNum" />
  70. <result column="project_ids" property="projectIds" />
  71. <result column="project_names" property="projectNames" />
  72. </resultMap>
  73. <select id="selectWithStage" resultMap="BaseResultMap2" >
  74. select id, project_code, project_name from project
  75. where company_id = #{companyId}
  76. <if test="projectId != null">
  77. and id = #{projectId}
  78. </if>
  79. <if test="inchagerIds!=null and inchagerIds.size()>0">
  80. and id in
  81. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  82. #{item}
  83. </foreach>
  84. </if>
  85. order by is_public desc, id asc
  86. <if test="startIndex != null">
  87. limit ${startIndex}, ${endIndex}
  88. </if>
  89. </select>
  90. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  91. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  92. IFNULL(SUM(report.`working_time`), 0) AS working_time
  93. FROM report where report.state = 1 and report.`project_id` = #{projectId}
  94. GROUP BY report.stage
  95. </select>
  96. <!--获取查询者所在公司每个项目的工时成本-->
  97. <select id="getParticipatedProject" resultType="java.util.Map">
  98. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  99. FROM project
  100. WHERE id IN (
  101. SELECT project_id
  102. FROM participation
  103. WHERE user_id = #{userId}
  104. ) or incharger_id = #{userId}
  105. or creator_id = #{userId}
  106. or (is_public = 1 and company_id = #{companyId})
  107. ORDER BY is_public DESC, id DESC
  108. </select>
  109. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  110. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  111. FROM project
  112. WHERE id IN (
  113. SELECT project_id
  114. FROM participation
  115. WHERE user_id = #{userId}
  116. )
  117. or (is_public = 1 and company_id = #{companyId})
  118. ORDER BY is_public DESC, id ASC
  119. </select>
  120. <!--获取查询者所在公司每个项目的工时成本-->
  121. <select id="getTimeCost" resultType="java.util.Map">
  122. SELECT a.id, a.project_code as projectCode, a.project_name AS project, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName
  123. FROM project AS a
  124. LEFT JOIN report AS b ON b.project_id = a.id
  125. JOIN user AS c ON b.creator_id = c.id
  126. WHERE a.company_id = #{companyId}
  127. <if test="projectId != null">
  128. AND a.id = #{projectId}
  129. </if>
  130. <if test="userId != null">
  131. AND b.creator_id = #{userId}
  132. </if>
  133. <if test="startDate != null and endDate != null">
  134. AND b.create_date between #{startDate} and #{endDate}
  135. </if>
  136. <choose>
  137. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  138. and b.dept_id in
  139. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  140. #{item}
  141. </foreach>
  142. </when>
  143. <otherwise>
  144. <if test="deptIds!=null and deptIds.size()>0">
  145. and b.dept_id in
  146. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  147. #{item}
  148. </foreach>
  149. </if>
  150. </otherwise>
  151. </choose>
  152. AND b.state = 1
  153. GROUP BY a.id
  154. ORDER BY a.id ASC
  155. </select>
  156. <!--获取查询者所在公司每个项目的工时成本-->
  157. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  158. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'未分类') as mainProjectName
  159. FROM project AS a
  160. LEFT JOIN report AS b ON b.project_id = a.id
  161. JOIN user AS c ON b.creator_id = c.id
  162. LEFT JOIN project_main pm on pm.id=a.project_main_id
  163. WHERE a.company_id = #{companyId}
  164. <if test="projectId != null">
  165. AND a.id = #{projectId}
  166. </if>
  167. <if test="startDate != null and endDate != null">
  168. AND b.create_date between #{startDate} and #{endDate}
  169. </if>
  170. <if test="deptIds!=null and deptIds.size()>0">
  171. and b.dept_id in
  172. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  173. #{item}
  174. </foreach>
  175. </if>
  176. AND b.state = 1
  177. GROUP BY a.project_main_id
  178. ORDER BY a.id ASC
  179. </select>
  180. <!--获取查询者所在公司每个项目分类的工时成本-->
  181. <select id="getTimeCostByCategory" resultType="java.util.Map">
  182. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  183. FROM project AS a
  184. LEFT JOIN report AS b ON b.project_id = a.id
  185. JOIN user AS c ON b.creator_id = c.id
  186. WHERE a.company_id = #{companyId}
  187. <if test="projectCategoryId != null">
  188. AND a.category = #{projectCategoryId}
  189. </if>
  190. <if test="userId != null">
  191. AND b.creator_id = #{userId}
  192. </if>
  193. <if test="startDate != null and endDate != null">
  194. AND b.create_date between #{startDate} and #{endDate}
  195. </if>
  196. <if test="deptIds!=null and deptIds.size()>0">
  197. and b.dept_id in
  198. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  199. #{item}
  200. </foreach>
  201. </if>
  202. AND b.state = 1
  203. GROUP BY a.category
  204. ORDER BY a.category ASC
  205. </select>
  206. <!--获取自定义数值的项目统计 -->
  207. <select id="getCustomDataSum" resultType="java.util.Map">
  208. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  209. FROM project AS a
  210. LEFT JOIN report AS b ON b.project_id = a.id
  211. JOIN user AS c ON b.creator_id = c.id
  212. WHERE a.company_id = #{companyId}
  213. <if test="projectId != null">
  214. AND a.id = #{projectId}
  215. </if>
  216. <if test="userId != null">
  217. AND b.creator_id = #{userId}
  218. </if>
  219. <if test="startDate != null and endDate != null">
  220. AND b.create_date between #{startDate} and #{endDate}
  221. </if>
  222. AND b.state = 1
  223. GROUP BY a.id
  224. ORDER BY SUM(b.custom_data) DESC
  225. </select>
  226. <!--获取日报的人员月度工时 -->
  227. <select id="getTimeCostReport" resultType="java.util.Map">
  228. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  229. FROM report AS a
  230. LEFT JOIN project AS b ON a.project_id = b.id
  231. LEFT JOIN user AS c ON a.creator_id = c.id
  232. WHERE b.company_id = #{companyId}
  233. <if test="projectId != null">
  234. AND b.id = #{projectId}
  235. </if>
  236. <if test="startDate != null and endDate != null">
  237. AND a.create_date between #{startDate} and #{endDate}
  238. </if>
  239. <if test="deptIds!=null and deptIds.size()>0">
  240. and a.dept_id in
  241. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  242. #{item}
  243. </foreach>
  244. </if>
  245. AND a.state = 1
  246. </select>
  247. <!--获取人员的月度总工时 -->
  248. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  249. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  250. FROM report AS a, user as b
  251. WHERE a.creator_id = b.id
  252. and b.company_id = #{companyId}
  253. <if test="startDate != null and endDate != null">
  254. AND a.create_date between #{startDate} and #{endDate}
  255. </if>
  256. AND a.state = 1
  257. group by a.creator_id
  258. </select>
  259. <!--获取某个项目每个人分别需要的工时-->
  260. <select id="getProjectCost" resultType="java.util.Map">
  261. 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
  262. FROM report AS a
  263. JOIN user AS b ON a.creator_id = b.id
  264. left join department on department.department_id = a.dept_id
  265. WHERE a.company_id=#{companyId}
  266. <choose>
  267. <when test="stateKey!=null and stateKey==1">
  268. and a.state = 1
  269. </when>
  270. <otherwise>
  271. and (a.state = 1 or a.state =0)
  272. </otherwise>
  273. </choose>
  274. <if test="projectId != null">
  275. and a.project_id = #{projectId}
  276. </if>
  277. <if test="startDate != null and endDate != null">
  278. AND a.create_date between #{startDate} and #{endDate}
  279. </if>
  280. <if test="userId != null">
  281. AND a.creator_id = #{userId}
  282. </if>
  283. <choose>
  284. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  285. and a.dept_id in
  286. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  287. #{item}
  288. </foreach>
  289. </when>
  290. <otherwise>
  291. <if test="deptIds!=null and deptIds.size()>0">
  292. and a.dept_id in
  293. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  294. #{item}
  295. </foreach>
  296. </if>
  297. </otherwise>
  298. </choose>
  299. GROUP BY b.id, a.dept_id
  300. ORDER BY b.id ASC, a.dept_id ASC
  301. </select>
  302. <!--获取某个项目分类每个人分别需要的工时-->
  303. <select id="getProjectCostByCategory" resultType="java.util.Map">
  304. 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
  305. FROM report AS a
  306. JOIN user AS b ON a.creator_id = b.id
  307. left join department on department.department_id = a.dept_id
  308. left join project c on c.id=a.project_id
  309. WHERE a.company_id=#{companyId} and a.state = 1
  310. <if test="curProjectCategoryId != null">
  311. and c.category = #{curProjectCategoryId}
  312. </if>
  313. <if test="startDate != null and endDate != null">
  314. AND a.create_date between #{startDate} and #{endDate}
  315. </if>
  316. <if test="userId != null">
  317. AND a.creator_id = #{userId}
  318. </if>
  319. GROUP BY c.category, a.dept_id
  320. ORDER BY c.category ASC, a.dept_id ASC
  321. </select>
  322. <!--获取个人每个项目分别需要的工时-->
  323. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  324. 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
  325. FROM report AS a
  326. JOIN user AS b ON a.creator_id = b.id
  327. left join department on department.department_id = a.dept_id
  328. WHERE a.company_id=#{companyId} and a.state = 1
  329. <if test="projectId != null">
  330. and a.project_id = #{projectId}
  331. </if>
  332. <if test="startDate != null and endDate != null">
  333. AND a.create_date between #{startDate} and #{endDate}
  334. </if>
  335. <if test="userId != null">
  336. AND a.creator_id = #{userId}
  337. </if>
  338. <if test="deptIds!=null and deptIds.size()>0">
  339. and a.dept_id in
  340. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  341. #{item}
  342. </foreach>
  343. </if>
  344. GROUP BY b.id,a.project_id
  345. ORDER BY b.id ASC, a.dept_id ASC
  346. </select>
  347. <!--获取个人每个项目分类分别需要的工时-->
  348. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  349. 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
  350. FROM report AS a
  351. JOIN user AS b ON a.creator_id = b.id
  352. left join department on department.department_id = a.dept_id
  353. left join project c on c.id=a.project_id
  354. WHERE a.company_id=#{companyId} and a.state = 1
  355. <if test="projectCategoryId != null">
  356. and c.category = #{projectCategoryId}
  357. </if>
  358. <if test="startDate != null and endDate != null">
  359. AND a.create_date between #{startDate} and #{endDate}
  360. </if>
  361. <if test="userId != null">
  362. AND a.creator_id = #{userId}
  363. </if>
  364. <if test="deptIds!=null and deptIds.size()>0">
  365. and a.dept_id in
  366. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  367. #{item}
  368. </foreach>
  369. </if>
  370. GROUP BY b.id,c.category
  371. ORDER BY b.id ASC, a.dept_id ASC
  372. </select>
  373. <!-- 获取人员在日报填写的自定义数值 -->
  374. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  375. SELECT b.id as creatorId,
  376. b.name,department.department_name as departmentName, IFNULL(SUM(a.custom_data),0) AS cost
  377. FROM report AS a
  378. JOIN user AS b ON a.creator_id = b.id
  379. left join department on department.department_id = b.department_id
  380. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  381. <if test="startDate != null and endDate != null">
  382. AND a.create_date between #{startDate} and #{endDate}
  383. </if>
  384. <if test="projectId != null">
  385. AND a.project_id = #{projectId}
  386. </if>
  387. <if test="userId != null">
  388. AND a.creator_id = #{userId}
  389. </if>
  390. group by b.id
  391. ORDER BY b.id ASC
  392. </select>
  393. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  394. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  395. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  396. FROM report AS a
  397. JOIN user AS b ON a.creator_id = b.id
  398. left join department on department.department_id = b.department_id
  399. left join project on project.id = a.project_id
  400. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  401. <if test="startDate != null and endDate != null">
  402. AND a.create_date between #{startDate} and #{endDate}
  403. </if>
  404. <if test="projectId != null">
  405. AND a.project_id = #{projectId}
  406. </if>
  407. <if test="userId != null">
  408. AND a.creator_id = #{userId}
  409. </if>
  410. ORDER BY a.create_date desc
  411. </select>
  412. <!--按照项目内的阶段名称分组统计工时-->
  413. <select id="getCostInStage" resultType="java.util.Map">
  414. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  415. FROM report AS a
  416. WHERE a.project_id = #{projectId}
  417. AND a.state = 1
  418. <if test="startDate != null and endDate != null">
  419. AND a.create_date between #{startDate} and #{endDate}
  420. </if>
  421. GROUP BY a.stage
  422. ORDER BY a.stage ASC
  423. </select>
  424. <!--按照项目内的阶段名称分组统计工时-->
  425. <select id="getCostByGroup" resultType="java.util.Map">
  426. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  427. FROM report AS a
  428. left join task_group tg on tg.id=a.group_id
  429. WHERE a.project_id = #{projectId}
  430. AND a.state = 1
  431. <if test="startDate != null and endDate != null">
  432. AND a.create_date between #{startDate} and #{endDate}
  433. </if>
  434. GROUP BY a.group_id
  435. ORDER BY a.group_id ASC
  436. </select>
  437. <!--获取全部人员工时 -->
  438. <select id="getAllMembCost" resultType="java.util.Map">
  439. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  440. FROM user AS b
  441. left JOIN report AS a ON a.creator_id = b.id
  442. WHERE a.state = 1
  443. and b.company_id = #{companyId}
  444. <if test="startDate != null and endDate != null">
  445. AND a.create_date between #{startDate} and #{endDate}
  446. </if>
  447. <if test="projectId != null">
  448. AND a.project_id = #{projectId}
  449. </if>
  450. GROUP BY b.id
  451. ORDER BY b.id ASC
  452. </select>
  453. <!--分页获取项目成本 -->
  454. <select id="getAllProjectCost" resultMap="BaseResultMap">
  455. SELECT id, project_code, project_name,
  456. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  457. (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,
  458. (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,
  459. (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
  460. FROM project WHERE project.`company_id` = #{companyId}
  461. and (project.status &lt;&gt; 3 or project.status is null)
  462. <if test="projectId != null">
  463. and project.id = #{projectId}
  464. </if>
  465. <if test="inchagerIds!=null and inchagerIds.size()>0">
  466. and project.id in
  467. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  468. #{item}
  469. </foreach>
  470. </if>
  471. order by project.is_public desc, project.id asc
  472. <if test="pageStart != null and pageSize != null">
  473. LIMIT #{pageStart},#{pageSize}
  474. </if>
  475. </select>
  476. <!--分页获取项目收支平衡 -->
  477. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  478. SELECT project_code, project_name,contract_amount,
  479. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  480. (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,
  481. (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,
  482. (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
  483. FROM project WHERE project.`company_id` = #{companyId}
  484. and (project.status &lt;&gt; 3 or project.status is null)
  485. <if test="projectId != null">
  486. and project.id = #{projectId}
  487. </if>
  488. <if test="inchagerIds!=null and inchagerIds.size()>0">
  489. and project.id in
  490. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  491. #{item}
  492. </foreach>
  493. </if>
  494. order by is_public desc, id asc
  495. <if test="pageStart != null and pageSize != null">
  496. LIMIT #{pageStart},#{pageSize}
  497. </if>
  498. </select>
  499. <!--分页获取客户项目的成本利润报表 -->
  500. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  501. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  502. SUM(contract_amount) AS contract_amount ,
  503. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man,
  504. 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,
  505. 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,
  506. 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
  507. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  508. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  509. <if test="customerId!=null">
  510. and project.customer_id=#{customerId}
  511. </if>
  512. <if test="projectId!=null">
  513. and project.id=#{projectId}
  514. </if>
  515. GROUP BY customer_id
  516. <if test="pageStart != null and pageSize != null">
  517. LIMIT #{pageStart},#{pageSize}
  518. </if>
  519. </select>
  520. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  521. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  522. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  523. <if test="customerId!=null">
  524. and project.customer_id=#{customerId}
  525. </if>
  526. <if test="projectId!=null">
  527. and project.id=#{projectId}
  528. </if>
  529. </select>
  530. <!--分页获取项目收支平衡 -->
  531. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  532. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  533. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  534. (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,
  535. (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,
  536. (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
  537. FROM project WHERE project.`company_id` = #{companyId}
  538. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  539. #{item}
  540. </foreach>
  541. </select>
  542. <select id="getGanttData" resultType="java.util.Map">
  543. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  544. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  545. LEFT JOIN user ON user.id = participation.`user_id`
  546. LEFT JOIN project ON project.`id` = participation.`project_id`
  547. WHERE participation.`user_id` IN
  548. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  549. #{item}
  550. </foreach>
  551. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  552. ORDER BY participation.user_id, project.`plan_start_date`
  553. </select>
  554. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  555. 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,
  556. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration FROM user
  557. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  558. left join task on task.id = task_executor.task_id
  559. LEFT JOIN project ON project.`id` = task.`project_id`
  560. WHERE user.`id` IN
  561. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  562. #{item}
  563. </foreach>
  564. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  565. and task.end_date is not null
  566. AND project.`status` = 1
  567. ORDER BY user.id, task.start_date
  568. </select>
  569. <select id="getTaskPlanByProject" resultType="java.util.Map">
  570. 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,
  571. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  572. LEFT JOIN task ON task.project_id = project.id
  573. WHERE project.company_id = #{companyId}
  574. <if test="projectIds != null">
  575. and project.`id` IN
  576. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  577. #{item}
  578. </foreach>
  579. </if>
  580. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  581. and task.end_date is not null
  582. AND project.`status` = 1
  583. ORDER BY project.id, task.start_date
  584. </select>
  585. <!--获取加班统计报表 -->
  586. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  587. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  588. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  589. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  590. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  591. <!-- left join project on project.id = report.project_id-->
  592. <!-- WHERE report.is_overtime = 1-->
  593. <!-- and report.`state` = 1-->
  594. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  595. <!-- AND user.`company_id` = #{companyId}-->
  596. <!-- <if test="projectId != null">-->
  597. <!-- AND report.`project_id` = #{projectId}-->
  598. <!-- </if>-->
  599. <!-- <if test="userId != null">-->
  600. <!-- AND report.`creator_id` = #{userId}-->
  601. <!-- </if>-->
  602. <!-- GROUP BY report.creator_id-->
  603. <!-- </select>-->
  604. <!-- 获取某个员工的某时间段内的加班详情 -->
  605. <select id="getOvertimeDetail" resultType="java.util.Map">
  606. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  607. report.`creator_id` AS userId, user.`name` AS username, report.`working_time` AS workingTime,
  608. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,
  609. project.project_name as projectName,project.project_code as projectCode,
  610. IFNULL(report.overtime_cost, 0) AS cost,
  611. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  612. left join project on project.id = report.project_id
  613. left join report_extra_degree on report_extra_degree.id = report.degree_id
  614. left join department on department.department_id = report.dept_id
  615. WHERE report.is_overtime = 1
  616. and report.`state` = 1
  617. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  618. AND user.`company_id` = #{companyId}
  619. <if test="projectId != null">
  620. AND report.`project_id` = #{projectId}
  621. </if>
  622. <if test="userId != null">
  623. AND report.`creator_id` = #{userId}
  624. </if>
  625. <if test="branchDepartment!=null and branchDepartment.size()>0">
  626. and report.dept_id in
  627. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  628. #{item}
  629. </foreach>
  630. </if>
  631. <if test="deptIds!=null and deptIds.size()>0">
  632. and report.dept_id in
  633. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  634. #{item}
  635. </foreach>
  636. </if>
  637. order by user.create_time asc, report.create_date desc
  638. </select>
  639. <!--获取人员工时-->
  640. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  641. SELECT report.`creator_id` AS userId, user.`name` AS username,
  642. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  643. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  644. ifnull(SUM(report.`working_time`),0) AS workingTime
  645. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  646. left join project on project.id = report.project_id
  647. WHERE
  648. report.`state` = 1
  649. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  650. AND user.`company_id` =#{companyId}
  651. <if test="userId!=null">
  652. and user.id=#{userId}
  653. </if>
  654. <if test="projectId!=null">
  655. and project.id=#{projectId}
  656. </if>
  657. <if test="branchDepartment!=null and branchDepartment.size()>0">
  658. and report.dept_id in
  659. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  660. #{item}
  661. </foreach>
  662. </if>
  663. <if test="deptIds!=null and deptIds.size()>0">
  664. and report.dept_id in
  665. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  666. #{item}
  667. </foreach>
  668. </if>
  669. group by user.id
  670. order by user.create_time asc, report.create_date desc
  671. <if test="start!=null and size!=null">
  672. limit #{start},#{size}
  673. </if>
  674. </select>
  675. <select id="findCountWithUser" resultType="java.lang.Long">
  676. select count(*)
  677. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  678. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  679. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  680. ifnull(SUM(report.`working_time`),0) AS workingTime
  681. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  682. left join project on project.id = report.project_id
  683. WHERE
  684. report.`state` = 1
  685. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  686. AND user.`company_id` =#{companyId}
  687. <if test="userId!=null">
  688. and user.id=#{userId}
  689. </if>
  690. <if test="projectId!=null">
  691. and project.id=#{projectId}
  692. </if>
  693. <if test="departmentId!=null">
  694. and report.dept_id=#{departmentId}
  695. </if>
  696. <if test="deptIds!=null and deptIds.size()>0">
  697. and report.dept_id in
  698. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  699. #{item}
  700. </foreach>
  701. </if>
  702. group by user.id
  703. order by user.create_time asc, report.create_date desc
  704. <if test="start!=null and size!=null">
  705. limit #{start},#{size}
  706. </if>) as total
  707. </select>
  708. <!--按照项目内的阶段名称分组统计工时-->
  709. <select id="getDegreeCost" resultType="java.util.Map">
  710. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  711. FROM report AS a
  712. left join report_extra_degree b on b.id = a.degree_id
  713. WHERE
  714. a.state = 1
  715. and a.company_id = #{companyId}
  716. <if test="departmentIds!=null and departmentIds.size()>0">
  717. and a.dept_id in
  718. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  719. #{item}
  720. </foreach>
  721. </if>
  722. <if test="projectId != null">
  723. and a.project_id = #{projectId}
  724. </if>
  725. <if test="startDate != null and endDate != null">
  726. AND a.create_date between #{startDate} and #{endDate}
  727. </if>
  728. GROUP BY a.degree_id
  729. ORDER BY a.degree_id ASC
  730. </select>
  731. <!--项目导出数据-->
  732. <select id="getExportData" resultType="java.util.HashMap" >
  733. 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,
  734. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  735. customer_name, associate_degree_names, provider_names,provider_ids
  736. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  737. LEFT JOIN participation c ON c.project_id = project.`id`
  738. LEFT JOIN user u ON u.id = c.user_id
  739. LEFT JOIN user d ON d.id = project.`incharger_id`
  740. WHERE project.`company_id` = #{companyId}
  741. <if test="userId != null" >
  742. and (project.creator_id = #{userId} or c.user_id = #{userId})
  743. </if>
  744. GROUP BY project.id
  745. </select>
  746. <!--分页获取项目工时成本预警表 -->
  747. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  748. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  749. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  750. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  751. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  752. AND project_id=project.id) AS costLimit,
  753. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  754. FROM project WHERE company_id=#{companyId}
  755. and (project.status &lt;&gt; 3 or project.status is null)
  756. <if test="projectId != null">
  757. and project.id = #{projectId}
  758. </if>
  759. <if test="pageStart != null and pageSize != null">
  760. LIMIT #{pageStart},#{pageSize}
  761. </if>
  762. </select>
  763. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  764. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  765. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  766. 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,
  767. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  768. 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,
  769. (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
  770. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  771. <if test="projectId != null">
  772. and project.id = #{projectId}
  773. </if>
  774. <if test="pageStart != null and pageSize != null">
  775. LIMIT #{pageStart},#{pageSize}
  776. </if>
  777. </select>
  778. <select id="getWaitingReviewList" resultType="java.util.Map">
  779. <choose>
  780. <when test="stateKey==0">
  781. select us.name as userName,dp2.department_name as departmentName,COUNT(rp.state=0 or null) as num
  782. from department dp
  783. left join user us on dp.manager_id=us.id
  784. left join report rp on rp.audit_deptid=us.manage_dept_id and rp.create_date between #{startDate} and #{endDate} and rp.audit_deptid !=0
  785. left join department dp2 on dp2.department_id=dp.department_id
  786. </when>
  787. <otherwise>
  788. select us.name as userName,dp.department_name as departmentName,COUNT(rp.state=0 or null) as num
  789. from project_auditor pa
  790. left join user us on pa.auditor_id=us.id
  791. left join report rp on rp.project_auditor_id=us.id and pa.project_id=rp.project_id and rp.create_date between #{startDate} and #{endDate}
  792. left join department dp on dp.department_id=us.department_id
  793. </otherwise>
  794. </choose>
  795. where us.company_id=#{companyId} and us.is_active=1
  796. <if test="userId!=null">
  797. and us.id=#{userId}
  798. </if>
  799. <if test="departmentId!=null">
  800. and us.department_id=#{departmentId}
  801. </if>
  802. group by us.id
  803. order by us.department_id
  804. <if test="start!=null and size!=null">
  805. limit #{start},#{size}
  806. </if>
  807. </select>
  808. <select id="findCount" resultType="java.lang.Long">
  809. select count(1)
  810. from (<choose>
  811. <when test="stateKey==0">
  812. select us.name as userName,dp2.department_name as departmentName,COUNT(rp.state=0 or null) as num
  813. from department dp
  814. left join user us on dp.manager_id=us.id
  815. left join report rp on rp.audit_deptid=us.manage_dept_id and rp.create_date between #{startDate} and #{endDate} and rp.audit_deptid !=0
  816. left join department dp2 on dp2.department_id=dp.department_id
  817. </when>
  818. <otherwise>
  819. select us.name as userName,dp.department_name as departmentName,COUNT(rp.state=0 or null) as num
  820. from project_auditor pa
  821. left join user us on pa.auditor_id=us.id
  822. left join report rp on rp.project_auditor_id=us.id and pa.project_id=rp.project_id and rp.create_date between #{startDate} and #{endDate}
  823. left join department dp on dp.department_id=us.department_id
  824. </otherwise>
  825. </choose>
  826. where us.company_id=#{companyId} and us.is_active=1
  827. <if test="userId!=null">
  828. and us.id=#{userId}
  829. </if>
  830. <if test="departmentId!=null">
  831. and us.department_id=#{departmentId}
  832. </if>
  833. group by us.id
  834. order by us.department_id
  835. <if test="start!=null and size!=null">
  836. limit #{start},#{size}
  837. </if>) total
  838. </select>
  839. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  840. select us.name,dp.department_name as departmentName,
  841. (select SUM(te.plan_hours) from task_executor te
  842. left join task on task.id=te.task_id
  843. where te.executor_id=us.id
  844. <if test="startDate!=null and endDate!=null">
  845. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  846. </if>) as planHours,
  847. (select SUM(report.working_time) from report
  848. left join task on task.id=report.task_id
  849. where report.creator_id=us.id and task_id is not null and report.state=1
  850. <if test="startDate!=null and endDate!=null">
  851. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  852. </if>) as workingTime
  853. from user us
  854. left join department dp on dp.department_id=us.department_id
  855. where us.company_id=#{companyId}
  856. <if test="userId!=null and userId!=''">
  857. and us.id=#{userId}
  858. </if>
  859. <if test="branchDepartment!=null and branchDepartment.size()>0">
  860. and us.department_id in
  861. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  862. #{item}
  863. </foreach>
  864. </if>
  865. <if test="deptIds!=null and deptIds.size()>0">
  866. and us.department_id in
  867. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  868. #{item}
  869. </foreach>
  870. </if>
  871. group by us.id
  872. order by us.department_id
  873. <if test="start!=null and size!=null">
  874. limit #{start},#{size}
  875. </if>
  876. </select>
  877. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  878. select count(1)
  879. from(select us.name,dp.department_name as departmentName,
  880. (select SUM(te.plan_hours) from task_executor te
  881. left join task on task.id=te.task_id
  882. where te.executor_id=us.id
  883. <if test="startDate!=null and endDate!=null">
  884. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  885. </if>) as planHours,
  886. (select SUM(report.working_time) from report
  887. left join task on task.id=report.task_id
  888. where report.creator_id=us.id and task_id is not null
  889. <if test="startDate!=null and endDate!=null">
  890. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  891. </if>) as workingTime
  892. from user us
  893. left join department dp on dp.department_id=us.department_id
  894. where us.company_id=#{companyId}
  895. <if test="userId!=null and userId!=''">
  896. and us.id=#{userId}
  897. </if>
  898. <if test="branchDepartment!=null and branchDepartment.size()>0">
  899. and us.department_id in
  900. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  901. #{item}
  902. </foreach>
  903. </if>
  904. <if test="deptIds!=null and deptIds.size()>0">
  905. and us.department_id in
  906. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  907. #{item}
  908. </foreach>
  909. </if>
  910. group by us.id
  911. order by us.department_id)as total
  912. </select>
  913. <select id="selectWithGroup" resultType="java.util.Map">
  914. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  915. from report a
  916. left join task_group b on a.group_id=b.id
  917. left join project c on a.project_id=c.id
  918. where c.company_id=#{companyId} and a.state=1
  919. <if test="startDate!=null and endDate!=null">
  920. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  921. </if>
  922. <if test="projectId!=null">
  923. and c.id=#{projectId}
  924. </if>
  925. <if test="inchagerIds!=null and inchagerIds.size()>0">
  926. and c.id in
  927. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  928. #{item}
  929. </foreach>
  930. </if>
  931. <if test="groupId!=null">
  932. and a.group_id=#{groupId}
  933. </if>
  934. group by b.name
  935. order by c.id
  936. <if test="startIndex!=null and endIndex!=null">
  937. limit #{startIndex},#{endIndex}
  938. </if>
  939. </select>
  940. <select id="selectCountWithGroup" resultType="java.lang.Long">
  941. select count(1) from(
  942. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  943. from report a
  944. left join task_group b on a.group_id=b.id
  945. left join project c on a.project_id=c.id
  946. where c.company_id=#{companyId} and a.state=1
  947. <if test="startDate!=null and endDate!=null">
  948. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  949. </if>
  950. <if test="projectId!=null">
  951. and c.id=#{projectId}
  952. </if>
  953. <if test="inchagerIds!=null and inchagerIds.size()>0">
  954. and c.id in
  955. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  956. #{item}
  957. </foreach>
  958. </if>
  959. <if test="groupId!=null">
  960. and a.group_id=#{groupId}
  961. </if>
  962. group by b.name
  963. order by c.id
  964. <if test="startIndex!=null and endIndex!=null">
  965. limit #{startIndex},#{endIndex}
  966. </if>) as total
  967. </select>
  968. <select id="selectWithGroupProject" resultType="java.util.Map">
  969. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  970. from report a
  971. left join task_group b on a.group_id=b.id
  972. left join project c on a.project_id=c.id
  973. where c.company_id=#{companyId} and a.state=1
  974. <if test="startDate!=null and endDate!=null">
  975. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  976. </if>
  977. <if test="projectId!=null">
  978. and c.id=#{projectId}
  979. </if>
  980. <if test="inchagerIds!=null and inchagerIds.size()>0">
  981. and c.id in
  982. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  983. #{item}
  984. </foreach>
  985. </if>
  986. <if test="groupId!=null">
  987. and a.group_id=#{groupId}
  988. </if>
  989. group by c.id,b.id
  990. order by c.id
  991. <if test="startIndex!=null and endIndex!=null">
  992. limit #{startIndex},#{endIndex}
  993. </if>
  994. </select>
  995. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  996. select count(1) from(
  997. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  998. from report a
  999. left join task_group b on a.group_id=b.id
  1000. left join project c on a.project_id=c.id
  1001. where c.company_id=#{companyId} and a.state=1
  1002. <if test="startDate!=null and endDate!=null">
  1003. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1004. </if>
  1005. <if test="projectId!=null">
  1006. and c.id=#{projectId}
  1007. </if>
  1008. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1009. and c.id in
  1010. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1011. #{item}
  1012. </foreach>
  1013. </if>
  1014. <if test="groupId!=null">
  1015. and a.group_id=#{groupId}
  1016. </if>
  1017. group by c.id,b.id
  1018. order by c.id
  1019. <if test="startIndex!=null and endIndex!=null">
  1020. limit #{startIndex},#{endIndex}
  1021. </if>) as total
  1022. </select>
  1023. <select id="getCostByUserCustom" resultType="java.util.Map">
  1024. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1025. FROM user AS a
  1026. LEFT JOIN report AS b ON a.id = b.creator_id
  1027. LEFT JOIN project AS c ON b.project_id = c.id
  1028. left join user_custom uc on uc.company_id=a.company_id
  1029. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1030. WHERE b.state = 1
  1031. AND a.company_id = #{companyId}
  1032. <if test="startDate!=null and endDate!=null">
  1033. AND b.create_date between #{startDate} and #{endDate}
  1034. </if>
  1035. and uc.id=#{customId}
  1036. <if test="deptIds!=null and deptIds.size()>0">
  1037. and a.department_id in
  1038. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1039. #{item}
  1040. </foreach>
  1041. </if>
  1042. <if test="subCustomName!=null">
  1043. and suc.name=#{subCustomName}
  1044. </if>
  1045. GROUP BY suc.name
  1046. </select>
  1047. </mapper>