ProjectMapper.xml 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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. having IFNULL(SUM(b.custom_data), 0) > 0
  225. ORDER BY SUM(b.custom_data) DESC
  226. </select>
  227. <!--获取日报的人员月度工时 -->
  228. <select id="getTimeCostReport" resultType="java.util.Map">
  229. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  230. FROM report AS a
  231. LEFT JOIN project AS b ON a.project_id = b.id
  232. LEFT JOIN user AS c ON a.creator_id = c.id
  233. WHERE b.company_id = #{companyId}
  234. <if test="projectId != null">
  235. AND b.id = #{projectId}
  236. </if>
  237. <if test="startDate != null and endDate != null">
  238. AND a.create_date between #{startDate} and #{endDate}
  239. </if>
  240. <if test="deptIds!=null and deptIds.size()>0">
  241. and a.dept_id in
  242. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  243. #{item}
  244. </foreach>
  245. </if>
  246. AND a.state = 1
  247. </select>
  248. <!--获取人员的月度总工时 -->
  249. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  250. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  251. FROM report AS a, user as b
  252. WHERE a.creator_id = b.id
  253. and b.company_id = #{companyId}
  254. <if test="startDate != null and endDate != null">
  255. AND a.create_date between #{startDate} and #{endDate}
  256. </if>
  257. AND a.state = 1
  258. group by a.creator_id
  259. </select>
  260. <!--获取某个项目每个人分别需要的工时-->
  261. <select id="getProjectCost" resultType="java.util.Map">
  262. 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
  263. FROM report AS a
  264. JOIN user AS b ON a.creator_id = b.id
  265. left join department on department.department_id = a.dept_id
  266. WHERE a.company_id=#{companyId}
  267. <choose>
  268. <when test="stateKey!=null and stateKey==1">
  269. and a.state = 1
  270. </when>
  271. <otherwise>
  272. and (a.state = 1 or a.state =0)
  273. </otherwise>
  274. </choose>
  275. <if test="projectId != null">
  276. and a.project_id = #{projectId}
  277. </if>
  278. <if test="startDate != null and endDate != null">
  279. AND a.create_date between #{startDate} and #{endDate}
  280. </if>
  281. <if test="userId != null">
  282. AND a.creator_id = #{userId}
  283. </if>
  284. <choose>
  285. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  286. and a.dept_id in
  287. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  288. #{item}
  289. </foreach>
  290. </when>
  291. <otherwise>
  292. <if test="deptIds!=null and deptIds.size()>0">
  293. and a.dept_id in
  294. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  295. #{item}
  296. </foreach>
  297. </if>
  298. </otherwise>
  299. </choose>
  300. GROUP BY b.id, a.dept_id
  301. ORDER BY b.id ASC, a.dept_id ASC
  302. </select>
  303. <!--获取某个项目分类每个人分别需要的工时-->
  304. <select id="getProjectCostByCategory" resultType="java.util.Map">
  305. 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
  306. FROM report AS a
  307. JOIN user AS b ON a.creator_id = b.id
  308. left join department on department.department_id = a.dept_id
  309. left join project c on c.id=a.project_id
  310. WHERE a.company_id=#{companyId} and a.state = 1
  311. <if test="curProjectCategoryId != null">
  312. and c.category = #{curProjectCategoryId}
  313. </if>
  314. <if test="startDate != null and endDate != null">
  315. AND a.create_date between #{startDate} and #{endDate}
  316. </if>
  317. <if test="userId != null">
  318. AND a.creator_id = #{userId}
  319. </if>
  320. GROUP BY c.category, a.dept_id
  321. ORDER BY c.category ASC, a.dept_id ASC
  322. </select>
  323. <!--获取个人每个项目分别需要的工时-->
  324. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  325. 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
  326. FROM report AS a
  327. JOIN user AS b ON a.creator_id = b.id
  328. left join department on department.department_id = a.dept_id
  329. WHERE a.company_id=#{companyId} and a.state = 1
  330. <if test="projectId != null">
  331. and a.project_id = #{projectId}
  332. </if>
  333. <if test="startDate != null and endDate != null">
  334. AND a.create_date between #{startDate} and #{endDate}
  335. </if>
  336. <if test="userId != null">
  337. AND a.creator_id = #{userId}
  338. </if>
  339. <if test="deptIds!=null and deptIds.size()>0">
  340. and a.dept_id in
  341. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  342. #{item}
  343. </foreach>
  344. </if>
  345. GROUP BY b.id,a.project_id
  346. ORDER BY b.id ASC, a.dept_id ASC
  347. </select>
  348. <!--获取个人每个项目分类分别需要的工时-->
  349. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  350. 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
  351. FROM report AS a
  352. JOIN user AS b ON a.creator_id = b.id
  353. left join department on department.department_id = a.dept_id
  354. left join project c on c.id=a.project_id
  355. WHERE a.company_id=#{companyId} and a.state = 1
  356. <if test="projectCategoryId != null">
  357. and c.category = #{projectCategoryId}
  358. </if>
  359. <if test="startDate != null and endDate != null">
  360. AND a.create_date between #{startDate} and #{endDate}
  361. </if>
  362. <if test="userId != null">
  363. AND a.creator_id = #{userId}
  364. </if>
  365. <if test="deptIds!=null and deptIds.size()>0">
  366. and a.dept_id in
  367. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  368. #{item}
  369. </foreach>
  370. </if>
  371. GROUP BY b.id,c.category
  372. ORDER BY b.id ASC, a.dept_id ASC
  373. </select>
  374. <!-- 获取人员在日报填写的自定义数值 -->
  375. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  376. SELECT b.id as creatorId,
  377. b.name,department.department_name as departmentName, IFNULL(SUM(a.custom_data),0) AS cost
  378. FROM report AS a
  379. JOIN user AS b ON a.creator_id = b.id
  380. left join department on department.department_id = b.department_id
  381. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  382. <if test="startDate != null and endDate != null">
  383. AND a.create_date between #{startDate} and #{endDate}
  384. </if>
  385. <if test="projectId != null">
  386. AND a.project_id = #{projectId}
  387. </if>
  388. <if test="userId != null">
  389. AND a.creator_id = #{userId}
  390. </if>
  391. <if test="deptIds != null">
  392. AND department.department_id in
  393. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  394. #{item}
  395. </foreach>
  396. </if>
  397. group by b.id
  398. ORDER BY b.id ASC
  399. </select>
  400. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  401. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  402. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  403. FROM report AS a
  404. JOIN user AS b ON a.creator_id = b.id
  405. left join department on department.department_id = b.department_id
  406. left join project on project.id = a.project_id
  407. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  408. <if test="startDate != null and endDate != null">
  409. AND a.create_date between #{startDate} and #{endDate}
  410. </if>
  411. <if test="projectId != null">
  412. AND a.project_id = #{projectId}
  413. </if>
  414. <if test="userId != null">
  415. AND a.creator_id = #{userId}
  416. </if>
  417. ORDER BY a.create_date desc
  418. </select>
  419. <!--按照项目内的阶段名称分组统计工时-->
  420. <select id="getCostInStage" resultType="java.util.Map">
  421. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  422. FROM report AS a
  423. WHERE a.project_id = #{projectId}
  424. AND a.state = 1
  425. <if test="startDate != null and endDate != null">
  426. AND a.create_date between #{startDate} and #{endDate}
  427. </if>
  428. GROUP BY a.stage
  429. ORDER BY a.stage ASC
  430. </select>
  431. <!--按照项目内的阶段名称分组统计工时-->
  432. <select id="getCostByGroup" resultType="java.util.Map">
  433. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  434. FROM report AS a
  435. left join task_group tg on tg.id=a.group_id
  436. WHERE a.project_id = #{projectId}
  437. AND a.state = 1
  438. <if test="startDate != null and endDate != null">
  439. AND a.create_date between #{startDate} and #{endDate}
  440. </if>
  441. GROUP BY a.group_id
  442. ORDER BY a.group_id ASC
  443. </select>
  444. <!--获取全部人员工时 -->
  445. <select id="getAllMembCost" resultType="java.util.Map">
  446. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  447. FROM user AS b
  448. left JOIN report AS a ON a.creator_id = b.id
  449. WHERE a.state = 1
  450. and b.company_id = #{companyId}
  451. <if test="startDate != null and endDate != null">
  452. AND a.create_date between #{startDate} and #{endDate}
  453. </if>
  454. <if test="projectId != null">
  455. AND a.project_id = #{projectId}
  456. </if>
  457. GROUP BY b.id
  458. ORDER BY b.id ASC
  459. </select>
  460. <!--分页获取项目成本 -->
  461. <select id="getAllProjectCost" resultMap="BaseResultMap">
  462. SELECT id, project_code, project_name,
  463. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  464. (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,
  465. (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,
  466. (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
  467. FROM project WHERE project.`company_id` = #{companyId}
  468. and (project.status &lt;&gt; 3 or project.status is null)
  469. <if test="projectId != null">
  470. and project.id = #{projectId}
  471. </if>
  472. <if test="inchagerIds!=null and inchagerIds.size()>0">
  473. and project.id in
  474. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  475. #{item}
  476. </foreach>
  477. </if>
  478. order by project.is_public desc, project.id asc
  479. <if test="pageStart != null and pageSize != null">
  480. LIMIT #{pageStart},#{pageSize}
  481. </if>
  482. </select>
  483. <!--分页获取项目收支平衡 -->
  484. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  485. SELECT project_code, project_name,contract_amount,
  486. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  487. (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,
  488. (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,
  489. (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
  490. FROM project WHERE project.`company_id` = #{companyId}
  491. and (project.status &lt;&gt; 3 or project.status is null)
  492. <if test="projectId != null">
  493. and project.id = #{projectId}
  494. </if>
  495. <if test="inchagerIds!=null and inchagerIds.size()>0">
  496. and project.id in
  497. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  498. #{item}
  499. </foreach>
  500. </if>
  501. order by is_public desc, id asc
  502. <if test="pageStart != null and pageSize != null">
  503. LIMIT #{pageStart},#{pageSize}
  504. </if>
  505. </select>
  506. <!--分页获取客户项目的成本利润报表 -->
  507. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  508. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  509. SUM(contract_amount) AS contract_amount ,
  510. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man,
  511. 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,
  512. 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,
  513. 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
  514. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  515. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  516. <if test="customerId!=null">
  517. and project.customer_id=#{customerId}
  518. </if>
  519. <if test="projectId!=null">
  520. and project.id=#{projectId}
  521. </if>
  522. GROUP BY customer_id
  523. <if test="pageStart != null and pageSize != null">
  524. LIMIT #{pageStart},#{pageSize}
  525. </if>
  526. </select>
  527. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  528. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  529. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  530. <if test="customerId!=null">
  531. and project.customer_id=#{customerId}
  532. </if>
  533. <if test="projectId!=null">
  534. and project.id=#{projectId}
  535. </if>
  536. </select>
  537. <!--分页获取项目收支平衡 -->
  538. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  539. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  540. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  541. (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,
  542. (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,
  543. (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
  544. FROM project WHERE project.`company_id` = #{companyId}
  545. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  546. #{item}
  547. </foreach>
  548. </select>
  549. <select id="getGanttData" resultType="java.util.Map">
  550. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  551. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  552. LEFT JOIN user ON user.id = participation.`user_id`
  553. LEFT JOIN project ON project.`id` = participation.`project_id`
  554. WHERE participation.`user_id` IN
  555. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  556. #{item}
  557. </foreach>
  558. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  559. ORDER BY participation.user_id, project.`plan_start_date`
  560. </select>
  561. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  562. 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,
  563. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration FROM user
  564. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  565. left join task on task.id = task_executor.task_id
  566. LEFT JOIN project ON project.`id` = task.`project_id`
  567. WHERE user.`id` IN
  568. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  569. #{item}
  570. </foreach>
  571. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  572. and task.end_date is not null
  573. AND project.`status` = 1
  574. ORDER BY user.id, task.start_date
  575. </select>
  576. <select id="getTaskPlanByProject" resultType="java.util.Map">
  577. 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,
  578. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  579. LEFT JOIN task ON task.project_id = project.id
  580. WHERE project.company_id = #{companyId}
  581. <if test="projectIds != null">
  582. and project.`id` IN
  583. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  584. #{item}
  585. </foreach>
  586. </if>
  587. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  588. and task.end_date is not null
  589. AND project.`status` = 1
  590. ORDER BY project.id, task.start_date
  591. </select>
  592. <!--获取加班统计报表 -->
  593. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  594. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  595. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  596. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  597. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  598. <!-- left join project on project.id = report.project_id-->
  599. <!-- WHERE report.is_overtime = 1-->
  600. <!-- and report.`state` = 1-->
  601. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  602. <!-- AND user.`company_id` = #{companyId}-->
  603. <!-- <if test="projectId != null">-->
  604. <!-- AND report.`project_id` = #{projectId}-->
  605. <!-- </if>-->
  606. <!-- <if test="userId != null">-->
  607. <!-- AND report.`creator_id` = #{userId}-->
  608. <!-- </if>-->
  609. <!-- GROUP BY report.creator_id-->
  610. <!-- </select>-->
  611. <!-- 获取某个员工的某时间段内的加班详情 -->
  612. <select id="getOvertimeDetail" resultType="java.util.Map">
  613. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  614. report.`creator_id` AS userId, user.`name` AS username, report.`working_time` AS workingTime,
  615. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,
  616. project.project_name as projectName,project.project_code as projectCode,
  617. IFNULL(report.overtime_cost, 0) AS cost,
  618. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  619. left join project on project.id = report.project_id
  620. left join report_extra_degree on report_extra_degree.id = report.degree_id
  621. left join department on department.department_id = report.dept_id
  622. WHERE report.is_overtime = 1
  623. and report.`state` = 1
  624. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  625. AND user.`company_id` = #{companyId}
  626. <if test="projectId != null">
  627. AND report.`project_id` = #{projectId}
  628. </if>
  629. <if test="userId != null">
  630. AND report.`creator_id` = #{userId}
  631. </if>
  632. <if test="branchDepartment!=null and branchDepartment.size()>0">
  633. and report.dept_id in
  634. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  635. #{item}
  636. </foreach>
  637. </if>
  638. <if test="deptIds!=null and deptIds.size()>0">
  639. and report.dept_id in
  640. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  641. #{item}
  642. </foreach>
  643. </if>
  644. order by user.create_time asc, report.create_date desc
  645. </select>
  646. <!--获取人员工时-->
  647. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  648. SELECT report.`creator_id` AS userId, user.`name` AS username,
  649. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  650. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  651. ifnull(SUM(report.`working_time`),0) AS workingTime
  652. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  653. left join project on project.id = report.project_id
  654. WHERE
  655. report.`state` = 1
  656. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  657. AND user.`company_id` =#{companyId}
  658. <if test="userId!=null">
  659. and user.id=#{userId}
  660. </if>
  661. <if test="projectId!=null">
  662. and project.id=#{projectId}
  663. </if>
  664. <if test="branchDepartment!=null and branchDepartment.size()>0">
  665. and report.dept_id in
  666. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  667. #{item}
  668. </foreach>
  669. </if>
  670. <if test="deptIds!=null and deptIds.size()>0">
  671. and report.dept_id in
  672. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  673. #{item}
  674. </foreach>
  675. </if>
  676. group by user.id
  677. order by user.create_time asc, report.create_date desc
  678. <if test="start!=null and size!=null">
  679. limit #{start},#{size}
  680. </if>
  681. </select>
  682. <select id="findCountWithUser" resultType="java.lang.Long">
  683. select count(*)
  684. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  685. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  686. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  687. ifnull(SUM(report.`working_time`),0) AS workingTime
  688. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  689. left join project on project.id = report.project_id
  690. WHERE
  691. report.`state` = 1
  692. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  693. AND user.`company_id` =#{companyId}
  694. <if test="userId!=null">
  695. and user.id=#{userId}
  696. </if>
  697. <if test="projectId!=null">
  698. and project.id=#{projectId}
  699. </if>
  700. <if test="departmentId!=null">
  701. and report.dept_id=#{departmentId}
  702. </if>
  703. <if test="deptIds!=null and deptIds.size()>0">
  704. and report.dept_id in
  705. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  706. #{item}
  707. </foreach>
  708. </if>
  709. group by user.id
  710. order by user.create_time asc, report.create_date desc
  711. <if test="start!=null and size!=null">
  712. limit #{start},#{size}
  713. </if>) as total
  714. </select>
  715. <!--按照项目内的阶段名称分组统计工时-->
  716. <select id="getDegreeCost" resultType="java.util.Map">
  717. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  718. FROM report AS a
  719. left join report_extra_degree b on b.id = a.degree_id
  720. WHERE
  721. a.state = 1
  722. and a.company_id = #{companyId}
  723. <if test="departmentIds!=null and departmentIds.size()>0">
  724. and a.dept_id in
  725. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  726. #{item}
  727. </foreach>
  728. </if>
  729. <if test="projectId != null">
  730. and a.project_id = #{projectId}
  731. </if>
  732. <if test="startDate != null and endDate != null">
  733. AND a.create_date between #{startDate} and #{endDate}
  734. </if>
  735. GROUP BY a.degree_id
  736. ORDER BY a.degree_id ASC
  737. </select>
  738. <!--项目导出数据-->
  739. <select id="getExportData" resultType="java.util.HashMap" >
  740. 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,
  741. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  742. customer_name, associate_degree_names, provider_names,provider_ids
  743. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  744. LEFT JOIN participation c ON c.project_id = project.`id`
  745. LEFT JOIN user u ON u.id = c.user_id
  746. LEFT JOIN user d ON d.id = project.`incharger_id`
  747. WHERE project.`company_id` = #{companyId}
  748. <if test="userId != null" >
  749. and (project.creator_id = #{userId} or c.user_id = #{userId})
  750. </if>
  751. GROUP BY project.id
  752. </select>
  753. <!--分页获取项目工时成本预警表 -->
  754. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  755. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  756. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  757. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  758. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  759. AND project_id=project.id) AS costLimit,
  760. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  761. FROM project WHERE company_id=#{companyId}
  762. and (project.status &lt;&gt; 3 or project.status is null)
  763. <if test="projectId != null">
  764. and project.id = #{projectId}
  765. </if>
  766. <if test="pageStart != null and pageSize != null">
  767. LIMIT #{pageStart},#{pageSize}
  768. </if>
  769. </select>
  770. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  771. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  772. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  773. 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,
  774. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  775. 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,
  776. (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
  777. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  778. <if test="projectId != null">
  779. and project.id = #{projectId}
  780. </if>
  781. <if test="pageStart != null and pageSize != null">
  782. LIMIT #{pageStart},#{pageSize}
  783. </if>
  784. </select>
  785. <select id="getWaitingReviewList" resultType="java.util.Map">
  786. <choose>
  787. <when test="stateKey==0">
  788. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  789. FROM report AS a
  790. left join user on user.id = a.creator_id
  791. JOIN project AS b ON a.project_id=b.id
  792. left join sub_project as d on d.id = a.sub_project_id
  793. left join task on task.id = a.task_id
  794. left join report_extra_degree on report_extra_degree.id = a.degree_id
  795. left join department on department.department_id = a.audit_deptid
  796. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  797. left join department dept on dept.department_id = a.dept_id
  798. left join task_group on task_group.id = a.group_id
  799. left join user u on u.id = a.project_auditor_id
  800. WHERE a.company_id =#{companyId}
  801. and a.state = 0
  802. <if test="startDate!=null and endDate!=null">
  803. AND a.create_date between #{startDate} and #{endDate}
  804. </if>
  805. AND a.is_dept_audit=1
  806. <if test="userId!=null">
  807. and dept_manager.id=#{userId}
  808. </if>
  809. <if test="departmentId!=null">
  810. and dept_manager.department_id=#{departmentId}
  811. </if>
  812. <if test="deptIds!=null and deptIds.size()>0">
  813. and dept_manager.department_id in
  814. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  815. #{item}
  816. </foreach>
  817. </if>
  818. group by a.audit_dept_managerid
  819. ORDER BY a.create_date desc, a.creator_id asc
  820. </when>
  821. <otherwise>
  822. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  823. FROM report AS a
  824. left join user on user.id = a.creator_id
  825. JOIN project AS b ON a.project_id=b.id
  826. left join sub_project as d on d.id = a.sub_project_id
  827. left join task on task.id = a.task_id
  828. left join report_extra_degree on report_extra_degree.id = a.degree_id
  829. left join department on department.department_id = a.audit_deptid
  830. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  831. left join department dept on dept.department_id = a.dept_id
  832. left join task_group on task_group.id = a.group_id
  833. left join user u on u.id = a.project_auditor_id
  834. left join department dp on u.department_id=dp.department_id
  835. WHERE a.company_id =#{companyId}
  836. and a.state = 0
  837. <if test="startDate!=null and endDate!=null">
  838. AND a.create_date between #{startDate} and #{endDate}
  839. </if>
  840. AND a.is_dept_audit=0 and a.project_audit_state = 0
  841. <if test="userId!=null">
  842. and u.id=#{userId}
  843. </if>
  844. <if test="departmentId!=null">
  845. and u.department_id=#{departmentId}
  846. </if>
  847. <if test="deptIds!=null and deptIds.size()>0">
  848. and u.department_id in
  849. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  850. #{item}
  851. </foreach>
  852. </if>
  853. group by a.project_auditor_id
  854. ORDER BY a.create_date desc, a.creator_id asc
  855. </otherwise>
  856. </choose>
  857. <if test="start!=null and size!=null">
  858. limit #{start},#{size}
  859. </if>
  860. </select>
  861. <select id="findCount" resultType="java.lang.Long">
  862. select count(1)
  863. from (<choose>
  864. <when test="stateKey==0">
  865. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  866. FROM report AS a
  867. left join user on user.id = a.creator_id
  868. JOIN project AS b ON a.project_id=b.id
  869. left join sub_project as d on d.id = a.sub_project_id
  870. left join task on task.id = a.task_id
  871. left join report_extra_degree on report_extra_degree.id = a.degree_id
  872. left join department on department.department_id = a.audit_deptid
  873. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  874. left join department dept on dept.department_id = a.dept_id
  875. left join task_group on task_group.id = a.group_id
  876. left join user u on u.id = a.project_auditor_id
  877. WHERE a.company_id =#{companyId}
  878. and a.state = 0
  879. <if test="startDate!=null and endDate!=null">
  880. AND a.create_date between #{startDate} and #{endDate}
  881. </if>
  882. AND a.is_dept_audit=1
  883. <if test="userId!=null">
  884. and dept_manager.id=#{userId}
  885. </if>
  886. <if test="departmentId!=null">
  887. and dept_manager.department_id=#{departmentId}
  888. </if>
  889. <if test="deptIds!=null and deptIds.size()>0">
  890. and dept_manager.department_id in
  891. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  892. #{item}
  893. </foreach>
  894. </if>
  895. group by a.audit_dept_managerid
  896. ORDER BY a.create_date desc, a.creator_id asc
  897. </when>
  898. <otherwise>
  899. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  900. FROM report AS a
  901. left join user on user.id = a.creator_id
  902. JOIN project AS b ON a.project_id=b.id
  903. left join sub_project as d on d.id = a.sub_project_id
  904. left join task on task.id = a.task_id
  905. left join report_extra_degree on report_extra_degree.id = a.degree_id
  906. left join department on department.department_id = a.audit_deptid
  907. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  908. left join department dept on dept.department_id = a.dept_id
  909. left join task_group on task_group.id = a.group_id
  910. left join user u on u.id = a.project_auditor_id
  911. left join department dp on u.department_id=dp.department_id
  912. WHERE a.company_id =#{companyId}
  913. and a.state = 0
  914. <if test="startDate!=null and endDate!=null">
  915. AND a.create_date between #{startDate} and #{endDate}
  916. </if>
  917. AND a.is_dept_audit=0 and a.project_audit_state = 0
  918. <if test="userId!=null">
  919. and u.id=#{userId}
  920. </if>
  921. <if test="departmentId!=null">
  922. and u.department_id=#{departmentId}
  923. </if>
  924. <if test="deptIds!=null and deptIds.size()>0">
  925. and u.department_id in
  926. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  927. #{item}
  928. </foreach>
  929. </if>
  930. group by a.project_auditor_id
  931. ORDER BY a.create_date desc, a.creator_id asc
  932. </otherwise>
  933. </choose>
  934. <if test="start!=null and size!=null">
  935. limit #{start},#{size}
  936. </if>) total
  937. </select>
  938. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  939. select us.name,dp.department_name as departmentName,
  940. (select SUM(te.plan_hours) from task_executor te
  941. left join task on task.id=te.task_id
  942. where te.executor_id=us.id
  943. <if test="startDate!=null and endDate!=null">
  944. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  945. </if>) as planHours,
  946. (select SUM(report.working_time) from report
  947. left join task on task.id=report.task_id
  948. where report.creator_id=us.id and task_id is not null and report.state=1
  949. <if test="startDate!=null and endDate!=null">
  950. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  951. </if>) as workingTime
  952. from user us
  953. left join department dp on dp.department_id=us.department_id
  954. where us.company_id=#{companyId}
  955. <if test="userId!=null and userId!=''">
  956. and us.id=#{userId}
  957. </if>
  958. <if test="branchDepartment!=null and branchDepartment.size()>0">
  959. and us.department_id in
  960. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  961. #{item}
  962. </foreach>
  963. </if>
  964. <if test="deptIds!=null and deptIds.size()>0">
  965. and us.department_id in
  966. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  967. #{item}
  968. </foreach>
  969. </if>
  970. group by us.id
  971. order by us.department_id
  972. <if test="start!=null and size!=null">
  973. limit #{start},#{size}
  974. </if>
  975. </select>
  976. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  977. select count(1)
  978. from(select us.name,dp.department_name as departmentName,
  979. (select SUM(te.plan_hours) from task_executor te
  980. left join task on task.id=te.task_id
  981. where te.executor_id=us.id
  982. <if test="startDate!=null and endDate!=null">
  983. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  984. </if>) as planHours,
  985. (select SUM(report.working_time) from report
  986. left join task on task.id=report.task_id
  987. where report.creator_id=us.id and task_id is not null
  988. <if test="startDate!=null and endDate!=null">
  989. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  990. </if>) as workingTime
  991. from user us
  992. left join department dp on dp.department_id=us.department_id
  993. where us.company_id=#{companyId}
  994. <if test="userId!=null and userId!=''">
  995. and us.id=#{userId}
  996. </if>
  997. <if test="branchDepartment!=null and branchDepartment.size()>0">
  998. and us.department_id in
  999. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1000. #{item}
  1001. </foreach>
  1002. </if>
  1003. <if test="deptIds!=null and deptIds.size()>0">
  1004. and us.department_id in
  1005. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1006. #{item}
  1007. </foreach>
  1008. </if>
  1009. group by us.id
  1010. order by us.department_id)as total
  1011. </select>
  1012. <select id="selectWithGroup" resultType="java.util.Map">
  1013. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1014. from report a
  1015. left join task_group b on a.group_id=b.id
  1016. left join project c on a.project_id=c.id
  1017. where c.company_id=#{companyId} and a.state=1
  1018. <if test="startDate!=null and endDate!=null">
  1019. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1020. </if>
  1021. <if test="projectId!=null">
  1022. and c.id=#{projectId}
  1023. </if>
  1024. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1025. and c.id in
  1026. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1027. #{item}
  1028. </foreach>
  1029. </if>
  1030. <if test="groupId!=null">
  1031. and a.group_id=#{groupId}
  1032. </if>
  1033. group by b.name
  1034. order by c.id
  1035. <if test="startIndex!=null and endIndex!=null">
  1036. limit #{startIndex},#{endIndex}
  1037. </if>
  1038. </select>
  1039. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1040. select count(1) from(
  1041. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1042. from report a
  1043. left join task_group b on a.group_id=b.id
  1044. left join project c on a.project_id=c.id
  1045. where c.company_id=#{companyId} and a.state=1
  1046. <if test="startDate!=null and endDate!=null">
  1047. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1048. </if>
  1049. <if test="projectId!=null">
  1050. and c.id=#{projectId}
  1051. </if>
  1052. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1053. and c.id in
  1054. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1055. #{item}
  1056. </foreach>
  1057. </if>
  1058. <if test="groupId!=null">
  1059. and a.group_id=#{groupId}
  1060. </if>
  1061. group by b.name
  1062. order by c.id
  1063. <if test="startIndex!=null and endIndex!=null">
  1064. limit #{startIndex},#{endIndex}
  1065. </if>) as total
  1066. </select>
  1067. <select id="selectWithGroupProject" resultType="java.util.Map">
  1068. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1069. from report a
  1070. left join task_group b on a.group_id=b.id
  1071. left join project c on a.project_id=c.id
  1072. where c.company_id=#{companyId} and a.state=1
  1073. <if test="startDate!=null and endDate!=null">
  1074. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1075. </if>
  1076. <if test="projectId!=null">
  1077. and c.id=#{projectId}
  1078. </if>
  1079. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1080. and c.id in
  1081. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1082. #{item}
  1083. </foreach>
  1084. </if>
  1085. <if test="groupId!=null">
  1086. and a.group_id=#{groupId}
  1087. </if>
  1088. group by c.id,b.id
  1089. order by c.id
  1090. <if test="startIndex!=null and endIndex!=null">
  1091. limit #{startIndex},#{endIndex}
  1092. </if>
  1093. </select>
  1094. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1095. select count(1) from(
  1096. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1097. from report a
  1098. left join task_group b on a.group_id=b.id
  1099. left join project c on a.project_id=c.id
  1100. where c.company_id=#{companyId} and a.state=1
  1101. <if test="startDate!=null and endDate!=null">
  1102. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1103. </if>
  1104. <if test="projectId!=null">
  1105. and c.id=#{projectId}
  1106. </if>
  1107. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1108. and c.id in
  1109. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1110. #{item}
  1111. </foreach>
  1112. </if>
  1113. <if test="groupId!=null">
  1114. and a.group_id=#{groupId}
  1115. </if>
  1116. group by c.id,b.id
  1117. order by c.id
  1118. <if test="startIndex!=null and endIndex!=null">
  1119. limit #{startIndex},#{endIndex}
  1120. </if>) as total
  1121. </select>
  1122. <select id="getCostByUserCustom" resultType="java.util.Map">
  1123. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1124. FROM user AS a
  1125. LEFT JOIN report AS b ON a.id = b.creator_id
  1126. LEFT JOIN project AS c ON b.project_id = c.id
  1127. left join user_custom uc on uc.company_id=a.company_id
  1128. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1129. WHERE b.state = 1
  1130. AND a.company_id = #{companyId}
  1131. <if test="startDate!=null and endDate!=null">
  1132. AND b.create_date between #{startDate} and #{endDate}
  1133. </if>
  1134. and uc.id=#{customId}
  1135. <if test="deptIds!=null and deptIds.size()>0">
  1136. and a.department_id in
  1137. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1138. #{item}
  1139. </foreach>
  1140. </if>
  1141. <if test="subCustomName!=null">
  1142. and suc.name=#{subCustomName}
  1143. </if>
  1144. GROUP BY suc.name
  1145. </select>
  1146. </mapper>