ProjectMapper.xml 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  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="project_main_name" property="projectMainName" />
  42. <result column="provider_ids" property="providerIds" />
  43. <result column="provider_names" property="providerNames" />
  44. <result column="current_stage_id" property="currentStageId" />
  45. <result column="current_stage_name" property="currentStageName" />
  46. <result column="output_value" property="outputValue" />
  47. <result column="dept_id" property="deptId" />
  48. <result column="dept_cascade" property="deptCascade" />
  49. <result column="bu_id" property="buId" />
  50. <result column="man_day" property="manDay" />
  51. <result column="man_day_start_date" property="manDayStartDate" />
  52. <result column="plate1" property="plate1" />
  53. <result column="plate2" property="plate2" />
  54. <result column="plate3" property="plate3" />
  55. <result column="plate4" property="plate4" />
  56. <result column="plate5" property="plate5" />
  57. <result column="plate6" property="plate6" />
  58. <result column="plate7" property="plate7" />
  59. <result column="plate8" property="plate8" />
  60. <result column="plate9" property="plate9" />
  61. <result column="plate10" property="plate10" />
  62. </resultMap>
  63. <!-- 通用查询结果列 -->
  64. <sql id="Base_Column_List">
  65. 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, project_main_name, provider_ids, provider_names, current_stage_id, current_stage_name, output_value, dept_id, dept_cascade, bu_id, man_day, man_day_start_date, plate1, plate2, plate3, plate4, plate5, plate6, plate7, plate8, plate9, plate10
  66. </sql>
  67. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  68. <result column="id" property="id" />
  69. <result column="project_name" property="projectName" />
  70. <result column="project_code" property="projectCode" />
  71. <result column="startDate" property="startDate" />
  72. <result column="endDate" property="endDate" />
  73. <collection property="stageCostList" javaType="java.util.ArrayList"
  74. ofType="com.management.platform.entity.vo.StageCost"
  75. select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
  76. </resultMap>
  77. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  78. <result column="customer_id" property="customerId" />
  79. <result column="customer_name" property="customerName" />
  80. <result column="contract_amount" property="contractAmount" />
  81. <result column="fee_normal" property="feeNormal" />
  82. <result column="fee_travel" property="feeTravel" />
  83. <result column="fee_outsourcing" property="feeOutsourcing" />
  84. <result column="fee_man" property="feeMan" />
  85. <result column="project_num" property="projectNum" />
  86. <result column="project_ids" property="projectIds" />
  87. <result column="project_names" property="projectNames" />
  88. </resultMap>
  89. <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
  90. select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
  91. from project
  92. where company_id = #{companyId}
  93. <if test="projectId != null">
  94. and id = #{projectId}
  95. </if>
  96. <if test="inchargerId!=null">
  97. and incharger_id = #{inchargerId}
  98. </if>
  99. order by is_public desc, id asc
  100. <if test="startIndex != null">
  101. limit ${startIndex}, ${endIndex}
  102. </if>
  103. </select>
  104. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  105. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  106. IFNULL(SUM(report.`working_time`), 0) AS working_time,
  107. IFNULL((SELECT SUM(stages.`stages_time`) from stages WHERE stages.stages_name = report.stage GROUP BY stages_name), 0) AS stages_time,report.`project_id` as projectId
  108. FROM report
  109. left join project p on p.id=report.`project_id`
  110. where report.state = 1
  111. <if test="inchargerId!=null">
  112. and p.incharger_id = #{inchargerId}
  113. </if>
  114. <if test="projectIds!=null and projectIds.size()>0">
  115. and p.id in
  116. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  117. #{item}
  118. </foreach>
  119. </if>
  120. and report.create_date &gt;= #{startDate}
  121. and report.create_date &lt;= #{endDate}
  122. GROUP BY report.`project_id`,report.stage
  123. </select>
  124. <!--获取查询者所在公司每个项目的工时成本-->
  125. <select id="getParticipatedProject" resultType="java.util.Map">
  126. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  127. FROM project
  128. WHERE id IN (
  129. SELECT project_id
  130. FROM participation
  131. WHERE user_id = #{userId}
  132. ) or incharger_id = #{userId}
  133. or creator_id = #{userId}
  134. or (is_public = 1 and company_id = #{companyId})
  135. ORDER BY is_public DESC, id DESC
  136. </select>
  137. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  138. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  139. FROM project
  140. WHERE status = 1 and (id IN (
  141. SELECT project_id
  142. FROM participation
  143. WHERE user_id = #{userId}
  144. )
  145. or (is_public = 1 and company_id = #{companyId}))
  146. ORDER BY is_public DESC, id ASC
  147. </select>
  148. <!--获取查询者所在公司每个项目的工时成本-->
  149. <select id="getTimeCost" resultType="java.util.Map">
  150. 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
  151. FROM project AS a
  152. LEFT JOIN report AS b ON b.project_id = a.id
  153. JOIN user AS c ON b.creator_id = c.id
  154. WHERE a.company_id = #{companyId}
  155. <if test="projectId != null">
  156. AND a.id = #{projectId}
  157. </if>
  158. <if test="projectIds != null">
  159. and a.id in
  160. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  161. #{item}
  162. </foreach>
  163. </if>
  164. <if test="userIdList != null and userIdList.size()>0">
  165. AND b.creator_id in
  166. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  167. #{item}
  168. </foreach>
  169. </if>
  170. <if test="startDate != null and endDate != null">
  171. AND b.create_date between #{startDate} and #{endDate}
  172. </if>
  173. <choose>
  174. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  175. and b.dept_id in
  176. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  177. #{item}
  178. </foreach>
  179. </when>
  180. <otherwise>
  181. <if test="deptIds!=null and deptIds.size()>0">
  182. and (b.dept_id in
  183. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  184. #{item}
  185. </foreach>
  186. <if test="deptRelatedProjectIds.size() > 0">
  187. or a.id in
  188. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  189. #{pid}
  190. </foreach>
  191. </if>
  192. )
  193. </if>
  194. </otherwise>
  195. </choose>
  196. AND b.state = 1
  197. GROUP BY a.id
  198. ORDER BY a.id ASC
  199. </select>
  200. <!--获取查询者所在公司每个子项目的工时成本-->
  201. <select id="getSubProjectTimeCost" resultType="java.util.Map">
  202. select b.project_code as projectCode,b.project_name as projectName,a.code as subProjectCode,a.name as subProjectName,SUM(c.cost) as cost,SUM(c.working_time) as workingTime
  203. from sub_project a
  204. left join project b on b.id=a.project_id
  205. left join report c on c.sub_project_id=a.id
  206. where a.company_id=#{companyId}
  207. <if test="startDate != null and endDate != null">
  208. and c.create_date between #{startDate} and #{endDate}
  209. </if>
  210. <if test="projectId!=null">
  211. and a.project_id=#{projectId}
  212. </if>
  213. <if test="inchagerIds!=null and inchagerIds.size()>0">
  214. and b.id in
  215. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  216. #{item}
  217. </foreach>
  218. </if>
  219. group by b.id,a.id
  220. <if test="start!=null and size!=null">
  221. limit #{start},#{size}
  222. </if>
  223. </select>
  224. <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
  225. select count(1) from(select b.project_code as projectCode,b.project_name as projectName,a.code as subProjectCode,a.name as subProjectName,SUM(c.cost) as cost,SUM(c.working_time) as workingTime
  226. from sub_project a
  227. left join project b on b.id=a.project_id
  228. left join report c on c.sub_project_id=a.id
  229. where a.company_id=#{companyId}
  230. <if test="startDate != null and endDate != null">
  231. and c.create_date between #{startDate} and #{endDate}
  232. </if>
  233. <if test="projectId!=null">
  234. and a.project_id=#{projectId}
  235. </if>
  236. <if test="inchagerIds!=null and inchagerIds.size()>0">
  237. and b.id in
  238. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  239. #{item}
  240. </foreach>
  241. </if>
  242. group by b.id,a.id
  243. <if test="start!=null and size!=null">
  244. limit #{start},#{size}
  245. </if>) as total
  246. </select>
  247. <!--获取查询者所在公司每个项目的工时成本-->
  248. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  249. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'未分类') as mainProjectName
  250. FROM project AS a
  251. LEFT JOIN report AS b ON b.project_id = a.id
  252. JOIN user AS c ON b.creator_id = c.id
  253. LEFT JOIN project_main pm on pm.id=a.project_main_id
  254. WHERE a.company_id = #{companyId}
  255. <if test="projectId != null">
  256. AND a.id = #{projectId}
  257. </if>
  258. <if test="startDate != null and endDate != null">
  259. AND b.create_date between #{startDate} and #{endDate}
  260. </if>
  261. <if test="deptIds!=null and deptIds.size()>0">
  262. and b.dept_id in
  263. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  264. #{item}
  265. </foreach>
  266. </if>
  267. AND b.state = 1
  268. GROUP BY a.project_main_id
  269. ORDER BY a.id ASC
  270. </select>
  271. <!--获取查询者所在公司每个项目分类的工时成本-->
  272. <select id="getTimeCostByCategory" resultType="java.util.Map">
  273. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  274. FROM project AS a
  275. LEFT JOIN report AS b ON b.project_id = a.id
  276. JOIN user AS c ON b.creator_id = c.id
  277. WHERE a.company_id = #{companyId}
  278. <if test="projectCategoryId != null">
  279. AND a.category = #{projectCategoryId}
  280. </if>
  281. <if test="projectIds != null">
  282. and a.id in
  283. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  284. #{item}
  285. </foreach>
  286. </if>
  287. <if test="userIdList != null and userIdList.size()>0">
  288. AND b.creator_id in
  289. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  290. #{item}
  291. </foreach>
  292. </if>
  293. <if test="startDate != null and endDate != null">
  294. AND b.create_date between #{startDate} and #{endDate}
  295. </if>
  296. <if test="deptIds!=null and deptIds.size()>0">
  297. and b.dept_id in
  298. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  299. #{item}
  300. </foreach>
  301. </if>
  302. AND b.state = 1
  303. GROUP BY a.category
  304. ORDER BY a.category ASC
  305. </select>
  306. <!--获取自定义数值的项目统计 -->
  307. <select id="getCustomDataSum" resultType="java.util.Map">
  308. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  309. FROM project AS a
  310. LEFT JOIN report AS b ON b.project_id = a.id
  311. JOIN user AS c ON b.creator_id = c.id
  312. WHERE a.company_id = #{companyId}
  313. <if test="projectId != null">
  314. AND a.id = #{projectId}
  315. </if>
  316. <if test="userId != null">
  317. AND b.creator_id = #{userId}
  318. </if>
  319. <if test="startDate != null and endDate != null">
  320. AND b.create_date between #{startDate} and #{endDate}
  321. </if>
  322. AND b.state = 1
  323. GROUP BY a.id
  324. having IFNULL(SUM(b.custom_data), 0) > 0
  325. ORDER BY SUM(b.custom_data) DESC
  326. </select>
  327. <!--获取日报的人员月度工时 -->
  328. <select id="getTimeCostReport" resultType="java.util.Map">
  329. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  330. FROM report AS a
  331. LEFT JOIN project AS b ON a.project_id = b.id
  332. LEFT JOIN user AS c ON a.creator_id = c.id
  333. WHERE b.company_id = #{companyId}
  334. <if test="projectId != null">
  335. AND b.id = #{projectId}
  336. </if>
  337. <if test="startDate != null and endDate != null">
  338. AND a.create_date between #{startDate} and #{endDate}
  339. </if>
  340. <if test="deptIds!=null and deptIds.size()>0">
  341. and a.dept_id in
  342. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  343. #{item}
  344. </foreach>
  345. </if>
  346. AND a.state = 1
  347. </select>
  348. <!--获取人员的月度总工时 -->
  349. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  350. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  351. FROM report AS a, user as b
  352. WHERE a.creator_id = b.id
  353. and b.company_id = #{companyId}
  354. <if test="startDate != null and endDate != null">
  355. AND a.create_date between #{startDate} and #{endDate}
  356. </if>
  357. AND a.state = 1
  358. group by a.creator_id
  359. </select>
  360. <!--获取某个项目每个人分别需要的工时-->
  361. <select id="getProjectCost" resultType="java.util.Map">
  362. SELECT b.id as creatorId,a.project_id as projectId, b.name,b.corpwx_userid as corpwxUserId,a.dept_id as deptId,department.corpwx_deptid as corpwxDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  363. FROM report AS a
  364. JOIN user AS b ON a.creator_id = b.id
  365. left join department on department.department_id = a.dept_id
  366. WHERE a.company_id=#{companyId}
  367. <choose>
  368. <when test="stateKey!=null and stateKey==1">
  369. and a.state = 1
  370. </when>
  371. <otherwise>
  372. and (a.state = 1 or a.state =0)
  373. </otherwise>
  374. </choose>
  375. <if test="projectId != null">
  376. and a.project_id = #{projectId}
  377. </if>
  378. <if test="startDate != null and endDate != null">
  379. AND a.create_date between #{startDate} and #{endDate}
  380. </if>
  381. <if test="userIdList != null and userIdList.size()>0">
  382. AND a.creator_id in
  383. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  384. #{item}
  385. </foreach>
  386. </if>
  387. <choose>
  388. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  389. and a.dept_id in
  390. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  391. #{item}
  392. </foreach>
  393. </when>
  394. <otherwise>
  395. <if test="deptIds!=null and deptIds.size()>0">
  396. and a.dept_id in
  397. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  398. #{item}
  399. </foreach>
  400. </if>
  401. </otherwise>
  402. </choose>
  403. GROUP BY b.id
  404. <if test="withDept">
  405. , a.dept_id
  406. </if>
  407. ORDER BY b.id ASC
  408. <if test="withDept">
  409. , a.dept_id ASC
  410. </if>
  411. </select>
  412. <!--获取某个项目分类每个人分别需要的工时-->
  413. <select id="getProjectCostByCategory" resultType="java.util.Map">
  414. 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
  415. FROM report AS a
  416. JOIN user AS b ON a.creator_id = b.id
  417. left join department on department.department_id = a.dept_id
  418. left join project c on c.id=a.project_id
  419. WHERE a.company_id=#{companyId} and a.state = 1
  420. <if test="curProjectCategoryId != null">
  421. and c.category = #{curProjectCategoryId}
  422. </if>
  423. <if test="startDate != null and endDate != null">
  424. AND a.create_date between #{startDate} and #{endDate}
  425. </if>
  426. <if test="userId != null">
  427. AND a.creator_id = #{userId}
  428. </if>
  429. GROUP BY c.category, a.dept_id
  430. ORDER BY c.category ASC, a.dept_id ASC
  431. </select>
  432. <!--获取个人每个项目分别需要的工时-->
  433. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  434. 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
  435. FROM report AS a
  436. JOIN user AS b ON a.creator_id = b.id
  437. left join department on department.department_id = a.dept_id
  438. WHERE a.company_id=#{companyId} and a.state = 1
  439. <if test="projectId != null">
  440. and a.project_id = #{projectId}
  441. </if>
  442. <if test="startDate != null and endDate != null">
  443. AND a.create_date between #{startDate} and #{endDate}
  444. </if>
  445. <if test="userIdList != null and userIdList.size()>0">
  446. AND a.creator_id in
  447. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  448. #{item}
  449. </foreach>
  450. </if>
  451. <if test="deptIds!=null and deptIds.size()>0">
  452. and a.dept_id in
  453. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  454. #{item}
  455. </foreach>
  456. </if>
  457. GROUP BY b.id,a.project_id
  458. ORDER BY b.id ASC, a.dept_id ASC
  459. </select>
  460. <!--获取个人每个项目分类分别需要的工时-->
  461. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  462. 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
  463. FROM report AS a
  464. JOIN user AS b ON a.creator_id = b.id
  465. left join department on department.department_id = a.dept_id
  466. left join project c on c.id=a.project_id
  467. WHERE a.company_id=#{companyId} and a.state = 1
  468. <if test="projectCategoryId != null">
  469. and c.category = #{projectCategoryId}
  470. </if>
  471. <if test="startDate != null and endDate != null">
  472. AND a.create_date between #{startDate} and #{endDate}
  473. </if>
  474. <if test="userIdList != null and userIdList.size()>0">
  475. AND a.creator_id in
  476. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  477. #{item}
  478. </foreach>
  479. </if>
  480. <if test="deptIds!=null and deptIds.size()>0">
  481. and a.dept_id in
  482. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  483. #{item}
  484. </foreach>
  485. </if>
  486. GROUP BY b.id,c.category
  487. ORDER BY b.id ASC, a.dept_id ASC
  488. </select>
  489. <!-- 获取人员在日报填写的自定义数值 -->
  490. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  491. SELECT b.id as creatorId,
  492. b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
  493. FROM report AS a
  494. JOIN user AS b ON a.creator_id = b.id
  495. left join department on department.department_id = b.department_id
  496. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  497. <if test="startDate != null and endDate != null">
  498. AND a.create_date between #{startDate} and #{endDate}
  499. </if>
  500. <if test="projectId != null">
  501. AND a.project_id = #{projectId}
  502. </if>
  503. <if test="userId != null">
  504. AND a.creator_id = #{userId}
  505. </if>
  506. <if test="deptIds != null">
  507. AND department.department_id in
  508. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  509. #{item}
  510. </foreach>
  511. </if>
  512. group by b.id
  513. ORDER BY b.id ASC
  514. </select>
  515. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  516. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  517. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  518. FROM report AS a
  519. JOIN user AS b ON a.creator_id = b.id
  520. left join department on department.department_id = b.department_id
  521. left join project on project.id = a.project_id
  522. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  523. <if test="startDate != null and endDate != null">
  524. AND a.create_date between #{startDate} and #{endDate}
  525. </if>
  526. <if test="projectId != null">
  527. AND a.project_id = #{projectId}
  528. </if>
  529. <if test="userId != null">
  530. AND a.creator_id = #{userId}
  531. </if>
  532. ORDER BY a.create_date desc
  533. </select>
  534. <!--按照项目内的阶段名称分组统计工时-->
  535. <select id="getCostInStage" resultType="java.util.Map">
  536. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  537. FROM report AS a
  538. WHERE a.project_id = #{projectId}
  539. AND a.state = 1
  540. <if test="startDate != null and endDate != null">
  541. AND a.create_date between #{startDate} and #{endDate}
  542. </if>
  543. GROUP BY a.stage
  544. ORDER BY a.stage ASC
  545. </select>
  546. <!--按照项目内的阶段名称分组统计工时-->
  547. <select id="getCostByGroup" resultType="java.util.Map">
  548. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  549. FROM report AS a
  550. left join task_group tg on tg.id=a.group_id
  551. WHERE a.project_id = #{projectId}
  552. AND a.state = 1
  553. <if test="startDate != null and endDate != null">
  554. AND a.create_date between #{startDate} and #{endDate}
  555. </if>
  556. GROUP BY a.group_id
  557. ORDER BY a.group_id ASC
  558. </select>
  559. <!--获取全部人员工时 -->
  560. <select id="getAllMembCost" resultType="java.util.Map">
  561. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  562. FROM user AS b
  563. left JOIN report AS a ON a.creator_id = b.id
  564. WHERE a.state = 1
  565. and b.company_id = #{companyId}
  566. <if test="startDate != null and endDate != null">
  567. AND a.create_date between #{startDate} and #{endDate}
  568. </if>
  569. <if test="projectId != null">
  570. AND a.project_id = #{projectId}
  571. </if>
  572. GROUP BY b.id
  573. ORDER BY b.id ASC
  574. </select>
  575. <!--分页获取项目成本 -->
  576. <select id="getAllProjectCost" resultType="java.util.Map">
  577. SELECT id, project_code as projectCode, project_name as projectName,
  578. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  579. FROM project WHERE project.`company_id` = #{companyId}
  580. and (project.status &lt;&gt; 3 or project.status is null)
  581. <if test="projectId != null">
  582. and project.id = #{projectId}
  583. </if>
  584. <if test="inchagerIds!=null and inchagerIds.size()>0">
  585. and project.id in
  586. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  587. #{item}
  588. </foreach>
  589. </if>
  590. order by project.is_public desc, project.id asc
  591. <if test="pageStart != null and pageSize != null">
  592. LIMIT #{pageStart},#{pageSize}
  593. </if>
  594. </select>
  595. <!--分页获取项目收支平衡 -->
  596. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  597. SELECT project_code, project_name,contract_amount,
  598. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  599. (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,
  600. (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,
  601. (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
  602. FROM project WHERE project.`company_id` = #{companyId}
  603. and (project.status &lt;&gt; 3 or project.status is null)
  604. <if test="projectId != null">
  605. and project.id = #{projectId}
  606. </if>
  607. <if test="inchagerIds!=null and inchagerIds.size()>0">
  608. and project.id in
  609. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  610. #{item}
  611. </foreach>
  612. </if>
  613. order by is_public desc, id asc
  614. <if test="pageStart != null and pageSize != null">
  615. LIMIT #{pageStart},#{pageSize}
  616. </if>
  617. </select>
  618. <!--分页获取客户项目的成本利润报表 -->
  619. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  620. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  621. SUM(contract_amount) AS contract_amount ,
  622. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man,
  623. 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,
  624. 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,
  625. 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
  626. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  627. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  628. <if test="customerId!=null">
  629. and project.customer_id=#{customerId}
  630. </if>
  631. <if test="projectId!=null">
  632. and project.id=#{projectId}
  633. </if>
  634. GROUP BY customer_id
  635. <if test="pageStart != null and pageSize != null">
  636. LIMIT #{pageStart},#{pageSize}
  637. </if>
  638. </select>
  639. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  640. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  641. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  642. <if test="customerId!=null">
  643. and project.customer_id=#{customerId}
  644. </if>
  645. <if test="projectId!=null">
  646. and project.id=#{projectId}
  647. </if>
  648. </select>
  649. <!--分页获取项目收支平衡 -->
  650. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  651. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  652. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  653. (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,
  654. (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,
  655. (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
  656. FROM project WHERE project.`company_id` = #{companyId}
  657. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  658. #{item}
  659. </foreach>
  660. </select>
  661. <select id="getGanttData" resultType="java.util.Map">
  662. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  663. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  664. LEFT JOIN user ON user.id = participation.`user_id`
  665. LEFT JOIN project ON project.`id` = participation.`project_id`
  666. WHERE participation.`user_id` IN
  667. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  668. #{item}
  669. </foreach>
  670. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  671. ORDER BY participation.user_id, project.`plan_start_date`
  672. </select>
  673. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  674. 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,
  675. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level FROM user
  676. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  677. left join task on task.id = task_executor.task_id
  678. LEFT JOIN project ON project.`id` = task.`project_id`
  679. WHERE user.`id` IN
  680. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  681. #{item}
  682. </foreach>
  683. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  684. and task.end_date is not null
  685. AND project.`status` = 1
  686. ORDER BY user.id, task.start_date
  687. </select>
  688. <select id="getTaskPlanByProject" resultType="java.util.Map">
  689. 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,
  690. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  691. LEFT JOIN task ON task.project_id = project.id
  692. WHERE project.company_id = #{companyId}
  693. <if test="projectIds != null">
  694. and project.`id` IN
  695. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  696. #{item}
  697. </foreach>
  698. </if>
  699. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  700. and task.end_date is not null
  701. AND project.`status` = 1
  702. ORDER BY project.id, task.start_date
  703. </select>
  704. <!--获取加班统计报表 -->
  705. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  706. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  707. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  708. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  709. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  710. <!-- left join project on project.id = report.project_id-->
  711. <!-- WHERE report.is_overtime = 1-->
  712. <!-- and report.`state` = 1-->
  713. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  714. <!-- AND user.`company_id` = #{companyId}-->
  715. <!-- <if test="projectId != null">-->
  716. <!-- AND report.`project_id` = #{projectId}-->
  717. <!-- </if>-->
  718. <!-- <if test="userId != null">-->
  719. <!-- AND report.`creator_id` = #{userId}-->
  720. <!-- </if>-->
  721. <!-- GROUP BY report.creator_id-->
  722. <!-- </select>-->
  723. <!-- 获取某个员工的某时间段内的加班详情 -->
  724. <select id="getOvertimeDetail" resultType="java.util.Map">
  725. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  726. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  727. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  728. project.project_name as projectName,project.project_code as projectCode,
  729. IFNULL(report.overtime_cost, 0) AS cost,
  730. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  731. left join project on project.id = report.project_id
  732. left join report_extra_degree on report_extra_degree.id = report.degree_id
  733. left join department on department.department_id = report.dept_id
  734. WHERE report.is_overtime = 1
  735. and report.`state` = 1
  736. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  737. AND user.`company_id` = #{companyId}
  738. <if test="projectId != null">
  739. AND report.`project_id` = #{projectId}
  740. </if>
  741. <if test="userId != null">
  742. AND report.`creator_id` = #{userId}
  743. </if>
  744. <if test="branchDepartment!=null and branchDepartment.size()>0">
  745. and report.dept_id in
  746. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  747. #{item}
  748. </foreach>
  749. </if>
  750. <if test="deptIds!=null and deptIds.size()>0">
  751. and report.dept_id in
  752. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  753. #{item}
  754. </foreach>
  755. </if>
  756. order by user.create_time asc, report.create_date desc
  757. </select>
  758. <!--获取人员工时-->
  759. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  760. SELECT report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber,
  761. user.department_id As deptId,
  762. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  763. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  764. ifnull(SUM(report.`working_time`),0) AS workingTime
  765. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  766. left join project on project.id = report.project_id
  767. WHERE
  768. report.`state` = 1
  769. AND user.`is_active` = 1
  770. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  771. AND user.`company_id` =#{companyId}
  772. <if test="userId!=null">
  773. and user.id=#{userId}
  774. </if>
  775. <if test="projectId!=null">
  776. and project.id=#{projectId}
  777. </if>
  778. <if test="branchDepartment!=null and branchDepartment.size()>0">
  779. and report.dept_id in
  780. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  781. #{item}
  782. </foreach>
  783. </if>
  784. <if test="deptIds!=null and deptIds.size()>0">
  785. and report.dept_id in
  786. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  787. #{item}
  788. </foreach>
  789. </if>
  790. group by user.id
  791. order by user.create_time asc, report.create_date desc
  792. <if test="start!=null and size!=null">
  793. limit #{start},#{size}
  794. </if>
  795. </select>
  796. <select id="findCountWithUser" resultType="java.lang.Long">
  797. select count(*)
  798. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  799. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  800. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  801. ifnull(SUM(report.`working_time`),0) AS workingTime
  802. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  803. left join project on project.id = report.project_id
  804. WHERE
  805. report.`state` = 1
  806. AND user.`is_active` = 1
  807. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  808. AND user.`company_id` =#{companyId}
  809. <if test="userId!=null">
  810. and user.id=#{userId}
  811. </if>
  812. <if test="projectId!=null">
  813. and project.id=#{projectId}
  814. </if>
  815. <if test="departmentId!=null">
  816. and report.dept_id=#{departmentId}
  817. </if>
  818. <if test="deptIds!=null and deptIds.size()>0">
  819. and report.dept_id in
  820. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  821. #{item}
  822. </foreach>
  823. </if>
  824. group by user.id
  825. order by user.create_time asc, report.create_date desc
  826. <if test="start!=null and size!=null">
  827. limit #{start},#{size}
  828. </if>) as total
  829. </select>
  830. <!--按照项目内的阶段名称分组统计工时-->
  831. <select id="getDegreeCost" resultType="java.util.Map">
  832. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
  833. FROM report AS a
  834. left join report_extra_degree b on b.id = a.degree_id
  835. WHERE
  836. a.state = 1
  837. and a.company_id = #{companyId}
  838. <if test="departmentIds!=null and departmentIds.size()>0">
  839. and a.dept_id in
  840. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  841. #{item}
  842. </foreach>
  843. </if>
  844. <if test="projectId != null">
  845. and a.project_id = #{projectId}
  846. </if>
  847. <if test="startDate != null and endDate != null">
  848. AND a.create_date between #{startDate} and #{endDate}
  849. </if>
  850. GROUP BY a.degree_id
  851. ORDER BY a.degree_id ASC
  852. </select>
  853. <!--项目导出数据-->
  854. <select id="getExportData" resultType="java.util.HashMap" >
  855. 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,
  856. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  857. customer_name, associate_degree_names, provider_names,provider_ids
  858. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  859. LEFT JOIN participation c ON c.project_id = project.`id`
  860. LEFT JOIN user u ON u.id = c.user_id
  861. LEFT JOIN user d ON d.id = project.`incharger_id`
  862. WHERE project.`company_id` = #{companyId}
  863. <if test="userId != null" >
  864. and (project.creator_id = #{userId} or c.user_id = #{userId})
  865. </if>
  866. GROUP BY project.id
  867. </select>
  868. <!--按项目分组导出数据-->
  869. <select id="getExportGroupData" resultType="java.util.Map" >
  870. SELECT project_code as projectCode,project_name as projectName,task_group.`name` AS groupName,`user`.`name` AS inchargerName,`user`.corpwx_userid as corpwxUserId,`user`.corpwx_userid as corpwxUserId,
  871. (SELECT GROUP_CONCAT(name) FROM group_participator g LEFT JOIN `user` ON `user`.id = g.user_id WHERE g.group_id = group_participator.group_id GROUP BY g.group_id) AS participators,
  872. (SELECT GROUP_CONCAT(corpwx_userid) FROM group_participator g LEFT JOIN `user` ON `user`.id = g.user_id WHERE g.group_id = group_participator.group_id GROUP BY g.group_id) AS participatorsCorp
  873. FROM task_group
  874. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  875. LEFT JOIN project on task_group.project_id = project.id
  876. LEFT JOIN `user` ON task_group.incharger_id = `user`.id
  877. where project.company_id = #{companyId}
  878. GROUP BY task_group.id
  879. ORDER BY project_id
  880. </select>
  881. <!--分页获取项目工时成本预警表 -->
  882. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  883. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  884. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  885. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  886. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  887. AND project_id=project.id) AS costLimit,
  888. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  889. FROM project WHERE company_id=#{companyId}
  890. and (project.status &lt;&gt; 3 or project.status is null)
  891. <if test="projectId != null">
  892. and project.id = #{projectId}
  893. </if>
  894. <if test="pageStart != null and pageSize != null">
  895. LIMIT #{pageStart},#{pageSize}
  896. </if>
  897. </select>
  898. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  899. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  900. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  901. 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,
  902. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  903. 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,
  904. (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
  905. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  906. <if test="projectId != null">
  907. and project.id = #{projectId}
  908. </if>
  909. <if test="pageStart != null and pageSize != null">
  910. LIMIT #{pageStart},#{pageSize}
  911. </if>
  912. </select>
  913. <select id="getWaitingReviewList" resultType="java.util.Map">
  914. <choose>
  915. <when test="stateKey==0">
  916. SELECT dept_manager.name as userName,`user`.corpwx_userid as corpwxUserId,IFNULL(department.department_id,0) as deptId,department.corpwx_deptid as wxDeptId,COUNT(1) as num
  917. FROM report AS a
  918. left join user on user.id = a.creator_id
  919. JOIN project AS b ON a.project_id=b.id
  920. left join sub_project as d on d.id = a.sub_project_id
  921. left join task on task.id = a.task_id
  922. left join report_extra_degree on report_extra_degree.id = a.degree_id
  923. left join department on department.department_id = a.audit_deptid
  924. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  925. left join department dept on dept.department_id = a.dept_id
  926. left join task_group on task_group.id = a.group_id
  927. left join user u on u.id = a.project_auditor_id
  928. WHERE a.company_id =#{companyId}
  929. and a.state = 0
  930. <if test="startDate!=null and endDate!=null">
  931. AND a.create_date between #{startDate} and #{endDate}
  932. </if>
  933. AND a.is_dept_audit=1
  934. <if test="userId!=null">
  935. and dept_manager.id=#{userId}
  936. </if>
  937. <if test="departmentId!=null">
  938. and dept_manager.department_id=#{departmentId}
  939. </if>
  940. <if test="deptIds!=null and deptIds.size()>0">
  941. and dept_manager.department_id in
  942. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  943. #{item}
  944. </foreach>
  945. </if>
  946. group by a.audit_dept_managerid
  947. ORDER BY a.create_date desc, a.creator_id asc
  948. </when>
  949. <otherwise>
  950. SELECT u.name as userName,u.corpwx_userid as corpwxUserId,IFNULL(dp.department_id,0) as deptId,dp.corpwx_deptid as wxDeptId,COUNT(1) as num
  951. FROM report AS a
  952. left join user on user.id = a.creator_id
  953. JOIN project AS b ON a.project_id=b.id
  954. left join sub_project as d on d.id = a.sub_project_id
  955. left join task on task.id = a.task_id
  956. left join report_extra_degree on report_extra_degree.id = a.degree_id
  957. left join department on department.department_id = a.audit_deptid
  958. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  959. left join department dept on dept.department_id = a.dept_id
  960. left join task_group on task_group.id = a.group_id
  961. left join user u on u.id = a.project_auditor_id
  962. left join department dp on u.department_id=dp.department_id
  963. WHERE a.company_id =#{companyId}
  964. and a.state = 0
  965. <if test="startDate!=null and endDate!=null">
  966. AND a.create_date between #{startDate} and #{endDate}
  967. </if>
  968. AND a.is_dept_audit=0 and a.project_audit_state = 0
  969. <if test="userId!=null">
  970. and u.id=#{userId}
  971. </if>
  972. <if test="departmentId!=null">
  973. and u.department_id=#{departmentId}
  974. </if>
  975. <if test="deptIds!=null and deptIds.size()>0">
  976. and u.department_id in
  977. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  978. #{item}
  979. </foreach>
  980. </if>
  981. group by a.project_auditor_id
  982. ORDER BY a.create_date desc, a.creator_id asc
  983. </otherwise>
  984. </choose>
  985. <if test="start!=null and size!=null">
  986. limit #{start},#{size}
  987. </if>
  988. </select>
  989. <select id="findCount" resultType="java.lang.Long">
  990. select count(1)
  991. from (<choose>
  992. <when test="stateKey==0">
  993. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  994. FROM report AS a
  995. left join user on user.id = a.creator_id
  996. JOIN project AS b ON a.project_id=b.id
  997. left join sub_project as d on d.id = a.sub_project_id
  998. left join task on task.id = a.task_id
  999. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1000. left join department on department.department_id = a.audit_deptid
  1001. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1002. left join department dept on dept.department_id = a.dept_id
  1003. left join task_group on task_group.id = a.group_id
  1004. left join user u on u.id = a.project_auditor_id
  1005. WHERE a.company_id =#{companyId}
  1006. and a.state = 0
  1007. and u.is_active = 1
  1008. <if test="startDate!=null and endDate!=null">
  1009. AND a.create_date between #{startDate} and #{endDate}
  1010. </if>
  1011. AND a.is_dept_audit=1
  1012. <if test="userId!=null">
  1013. and dept_manager.id=#{userId}
  1014. </if>
  1015. <if test="departmentId!=null">
  1016. and dept_manager.department_id=#{departmentId}
  1017. </if>
  1018. <if test="deptIds!=null and deptIds.size()>0">
  1019. and dept_manager.department_id in
  1020. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1021. #{item}
  1022. </foreach>
  1023. </if>
  1024. group by a.audit_dept_managerid
  1025. ORDER BY a.create_date desc, a.creator_id asc
  1026. </when>
  1027. <otherwise>
  1028. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1029. FROM report AS a
  1030. left join user on user.id = a.creator_id
  1031. JOIN project AS b ON a.project_id=b.id
  1032. left join sub_project as d on d.id = a.sub_project_id
  1033. left join task on task.id = a.task_id
  1034. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1035. left join department on department.department_id = a.audit_deptid
  1036. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1037. left join department dept on dept.department_id = a.dept_id
  1038. left join task_group on task_group.id = a.group_id
  1039. left join user u on u.id = a.project_auditor_id
  1040. left join department dp on u.department_id=dp.department_id
  1041. WHERE a.company_id =#{companyId}
  1042. and a.state = 0
  1043. and u.is_active = 1
  1044. <if test="startDate!=null and endDate!=null">
  1045. AND a.create_date between #{startDate} and #{endDate}
  1046. </if>
  1047. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1048. <if test="userId!=null">
  1049. and u.id=#{userId}
  1050. </if>
  1051. <if test="departmentId!=null">
  1052. and u.department_id=#{departmentId}
  1053. </if>
  1054. <if test="deptIds!=null and deptIds.size()>0">
  1055. and u.department_id in
  1056. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1057. #{item}
  1058. </foreach>
  1059. </if>
  1060. group by a.project_auditor_id
  1061. ORDER BY a.create_date desc, a.creator_id asc
  1062. </otherwise>
  1063. </choose>
  1064. <if test="start!=null and size!=null">
  1065. limit #{start},#{size}
  1066. </if>) total
  1067. </select>
  1068. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1069. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1070. (select SUM(te.plan_hours) from task_executor te
  1071. left join task on task.id=te.task_id
  1072. where te.executor_id=us.id
  1073. <if test="startDate!=null and endDate!=null">
  1074. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1075. </if>) as planHours,
  1076. (select SUM(report.working_time) from report
  1077. left join task on task.id=report.task_id
  1078. where report.creator_id=us.id and task_id is not null and report.state=1
  1079. <if test="startDate!=null and endDate!=null">
  1080. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1081. </if>) as workingTime
  1082. from user us
  1083. left join department dp on dp.department_id=us.department_id
  1084. where us.company_id=#{companyId}
  1085. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1086. <if test="userId!=null and userId!=''">
  1087. and us.id=#{userId}
  1088. </if>
  1089. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1090. and us.department_id in
  1091. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1092. #{item}
  1093. </foreach>
  1094. </if>
  1095. <if test="deptIds!=null and deptIds.size()>0">
  1096. and us.department_id in
  1097. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1098. #{item}
  1099. </foreach>
  1100. </if>
  1101. group by us.id
  1102. order by us.department_id
  1103. <if test="start!=null and size!=null">
  1104. limit #{start},#{size}
  1105. </if>
  1106. </select>
  1107. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1108. select count(1)
  1109. from(select us.name,dp.department_name as departmentName,
  1110. (select SUM(te.plan_hours) from task_executor te
  1111. left join task on task.id=te.task_id
  1112. where te.executor_id=us.id
  1113. <if test="startDate!=null and endDate!=null">
  1114. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1115. </if>) as planHours,
  1116. (select SUM(report.working_time) from report
  1117. left join task on task.id=report.task_id
  1118. where report.creator_id=us.id and task_id is not null
  1119. <if test="startDate!=null and endDate!=null">
  1120. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1121. </if>) as workingTime
  1122. from user us
  1123. left join department dp on dp.department_id=us.department_id
  1124. where us.company_id=#{companyId}
  1125. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1126. <if test="userId!=null and userId!=''">
  1127. and us.id=#{userId}
  1128. </if>
  1129. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1130. and us.department_id in
  1131. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1132. #{item}
  1133. </foreach>
  1134. </if>
  1135. <if test="deptIds!=null and deptIds.size()>0">
  1136. and us.department_id in
  1137. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1138. #{item}
  1139. </foreach>
  1140. </if>
  1141. group by us.id
  1142. order by us.department_id)as total
  1143. </select>
  1144. <select id="selectWithGroup" resultType="java.util.Map">
  1145. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1146. from report a
  1147. left join task_group b on a.group_id=b.id
  1148. left join project c on a.project_id=c.id
  1149. where c.company_id=#{companyId} and a.state=1
  1150. <if test="startDate!=null and endDate!=null">
  1151. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1152. </if>
  1153. <if test="projectId!=null">
  1154. and c.id=#{projectId}
  1155. </if>
  1156. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1157. and c.id in
  1158. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1159. #{item}
  1160. </foreach>
  1161. </if>
  1162. <if test="groupId!=null">
  1163. and a.group_id=#{groupId}
  1164. </if>
  1165. group by b.name
  1166. order by c.id
  1167. <if test="startIndex!=null and endIndex!=null">
  1168. limit #{startIndex},#{endIndex}
  1169. </if>
  1170. </select>
  1171. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1172. select count(1) from(
  1173. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1174. from report a
  1175. left join task_group b on a.group_id=b.id
  1176. left join project c on a.project_id=c.id
  1177. where c.company_id=#{companyId} and a.state=1
  1178. <if test="startDate!=null and endDate!=null">
  1179. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1180. </if>
  1181. <if test="projectId!=null">
  1182. and c.id=#{projectId}
  1183. </if>
  1184. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1185. and c.id in
  1186. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1187. #{item}
  1188. </foreach>
  1189. </if>
  1190. <if test="groupId!=null">
  1191. and a.group_id=#{groupId}
  1192. </if>
  1193. group by b.name
  1194. order by c.id
  1195. <if test="startIndex!=null and endIndex!=null">
  1196. limit #{startIndex},#{endIndex}
  1197. </if>) as total
  1198. </select>
  1199. <select id="selectWithGroupProject" resultType="java.util.Map">
  1200. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1201. from report a
  1202. left join task_group b on a.group_id=b.id
  1203. left join project c on a.project_id=c.id
  1204. where c.company_id=#{companyId} and a.state=1
  1205. <if test="startDate!=null and endDate!=null">
  1206. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1207. </if>
  1208. <if test="projectId!=null">
  1209. and c.id=#{projectId}
  1210. </if>
  1211. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1212. and c.id in
  1213. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1214. #{item}
  1215. </foreach>
  1216. </if>
  1217. <if test="groupId!=null">
  1218. and a.group_id=#{groupId}
  1219. </if>
  1220. group by c.id,b.id
  1221. order by c.id
  1222. <if test="startIndex!=null and endIndex!=null">
  1223. limit #{startIndex},#{endIndex}
  1224. </if>
  1225. </select>
  1226. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1227. select count(1) from(
  1228. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1229. from report a
  1230. left join task_group b on a.group_id=b.id
  1231. left join project c on a.project_id=c.id
  1232. where c.company_id=#{companyId} and a.state=1
  1233. <if test="startDate!=null and endDate!=null">
  1234. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1235. </if>
  1236. <if test="projectId!=null">
  1237. and c.id=#{projectId}
  1238. </if>
  1239. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1240. and c.id in
  1241. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1242. #{item}
  1243. </foreach>
  1244. </if>
  1245. <if test="groupId!=null">
  1246. and a.group_id=#{groupId}
  1247. </if>
  1248. group by c.id,b.id
  1249. order by c.id
  1250. <if test="startIndex!=null and endIndex!=null">
  1251. limit #{startIndex},#{endIndex}
  1252. </if>) as total
  1253. </select>
  1254. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1255. select c.id as projectId,c.project_name as projectName,c.project_code as projectCode,IFNULL(b.name,'未分组') as groupName,SUM(a.working_time) as workingTime,ifnull(b.id,0) as groupId
  1256. from report a
  1257. left join task_group b on a.group_id=b.id
  1258. left join project c on a.project_id=c.id
  1259. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1260. where c.company_id=#{companyId} and a.state=1
  1261. <if test="startDate!=null and endDate!=null">
  1262. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1263. </if>
  1264. <if test="projectId!=null">
  1265. and c.id=#{projectId}
  1266. </if>
  1267. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1268. and c.id in
  1269. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1270. #{item}
  1271. </foreach>
  1272. </if>
  1273. group by c.id,b.id
  1274. <if test="start!=null and size!=null">
  1275. limit #{start},#{size}
  1276. </if>
  1277. </select>
  1278. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1279. select count(1) from
  1280. (select c.id as projectId,c.project_name as projectName,c.project_code as projectCode,IFNULL(b.name,'未分组') as groupName,SUM(a.working_time) as workingTime,ifnull(b.id,0) as groupId
  1281. from report a
  1282. left join task_group b on a.group_id=b.id
  1283. left join project c on a.project_id=c.id
  1284. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1285. where c.company_id=#{companyId} and a.state=1
  1286. <if test="startDate!=null and endDate!=null">
  1287. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1288. </if>
  1289. <if test="projectId!=null">
  1290. and c.id=#{projectId}
  1291. </if>
  1292. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1293. and c.id in
  1294. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1295. #{item}
  1296. </foreach>
  1297. </if>
  1298. group by c.id,b.id
  1299. <if test="start!=null and size!=null">
  1300. limit #{start},#{size}
  1301. </if>) as total
  1302. </select>
  1303. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1304. select c.id as projectId,ifnull(b.id,0) as groupId,c.project_name as projectName,c.project_code as projectCode,SUM(a.working_time) as workingTime,IFNULL(f.stages_name,'非阶段') as stagesName
  1305. from report a
  1306. left join task_group b on a.group_id=b.id
  1307. left join project c on a.project_id=c.id
  1308. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1309. where c.company_id=#{companyId} and a.state=1
  1310. <if test="startDate!=null and endDate!=null">
  1311. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1312. </if>
  1313. <if test="projectId!=null">
  1314. and c.id=#{projectId}
  1315. </if>
  1316. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1317. and c.id in
  1318. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1319. #{item}
  1320. </foreach>
  1321. </if>
  1322. group by c.id,f.id
  1323. <if test="start!=null and size!=null">
  1324. limit #{start},#{size}
  1325. </if>
  1326. </select>
  1327. <select id="getCostByUserCustom" resultType="java.util.Map">
  1328. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1329. FROM user AS a
  1330. LEFT JOIN report AS b ON a.id = b.creator_id
  1331. LEFT JOIN project AS c ON b.project_id = c.id
  1332. left join user_custom uc on uc.company_id=a.company_id
  1333. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1334. WHERE b.state = 1
  1335. AND a.company_id = #{companyId}
  1336. <if test="startDate!=null and endDate!=null">
  1337. AND b.create_date between #{startDate} and #{endDate}
  1338. </if>
  1339. and uc.id=#{customId}
  1340. <if test="deptIds!=null and deptIds.size()>0">
  1341. and a.department_id in
  1342. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1343. #{item}
  1344. </foreach>
  1345. </if>
  1346. <if test="subCustomName!=null">
  1347. and suc.name=#{subCustomName}
  1348. </if>
  1349. GROUP BY suc.name
  1350. </select>
  1351. <select id="getEmpMonthHours" resultType="java.util.Map">
  1352. select us.id as userId,us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1353. (select allday from time_type te
  1354. where te.company_id=#{companyId}) as allday,
  1355. (select SUM(report.working_time) from report
  1356. where report.creator_id=us.id and report.state=1
  1357. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1358. as workingTime
  1359. from user us
  1360. left join department dp on dp.department_id=us.department_id
  1361. where us.company_id=#{companyId}
  1362. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1363. <if test="userId!=null and userId!=''">
  1364. and us.id=#{userId}
  1365. </if>
  1366. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1367. and us.department_id in
  1368. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1369. #{item}
  1370. </foreach>
  1371. </if>
  1372. <if test="deptIds!=null and deptIds.size()>0">
  1373. and us.department_id in
  1374. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1375. #{item}
  1376. </foreach>
  1377. </if>
  1378. group by us.id
  1379. order by us.department_id
  1380. <if test="start!=null and size!=null">
  1381. limit #{start},#{size}
  1382. </if>
  1383. </select>
  1384. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1385. select count(1)
  1386. from(select us.name,dp.department_name as departmentName,
  1387. (select SUM(report.working_time) from report
  1388. where report.creator_id=us.id
  1389. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1390. as workingTime
  1391. from user us
  1392. left join department dp on dp.department_id=us.department_id
  1393. where us.company_id=#{companyId}
  1394. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1395. <if test="userId!=null and userId!=''">
  1396. and us.id=#{userId}
  1397. </if>
  1398. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1399. and us.department_id in
  1400. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1401. #{item}
  1402. </foreach>
  1403. </if>
  1404. <if test="deptIds!=null and deptIds.size()>0">
  1405. and us.department_id in
  1406. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1407. #{item}
  1408. </foreach>
  1409. </if>
  1410. group by us.id
  1411. order by us.department_id)as total
  1412. </select>
  1413. <!-- 分页查询部门参与项目情况-->
  1414. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1415. SELECT department.department_id deptId,
  1416. department_name deptName,
  1417. (select count(user.id) from user where user.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0) AND user.department_id = department.department_id group by user.department_id) deptHeadCount,
  1418. pro.projectCount projectCount,
  1419. pro.centerCount centerCount,
  1420. pcon.peopleCount peopleCount
  1421. FROM department
  1422. LEFT JOIN (
  1423. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1424. COUNT(DISTINCT(r.degree_id)) centerCount
  1425. FROM report
  1426. LEFT JOIN report r
  1427. ON report.id = r.id AND r.degree_id != -1
  1428. LEFT JOIN `user`
  1429. ON report.creator_id = user.id
  1430. WHERE report.state = 1
  1431. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1432. GROUP BY dept_id
  1433. ) pro
  1434. on pro.dept_id = department.department_id
  1435. LEFT JOIN (
  1436. SELECT dept_id,sum(p.con) peopleCount
  1437. FROM (
  1438. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1439. LEFT JOIN `user`
  1440. ON report.creator_id = user.id
  1441. WHERE report.state = 1
  1442. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1443. GROUP BY report.creator_id,dept_id
  1444. ) p GROUP BY p.dept_id
  1445. ) pcon
  1446. ON pcon.dept_id = department.department_id
  1447. WHERE department.company_id = #{companyId}
  1448. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1449. and department.department_id in
  1450. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1451. #{item}
  1452. </foreach>
  1453. </if>
  1454. <if test="deptIds!=null and deptIds.size()>0">
  1455. and department.department_id in
  1456. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1457. #{item}
  1458. </foreach>
  1459. </if>
  1460. <if test="size!=null and start!=null">
  1461. limit #{start},#{size}
  1462. </if>
  1463. </select>
  1464. <!--获取按项目分组的工时成本-->
  1465. <select id="getExportDegreeCost" resultType="java.util.Map">
  1466. SELECT a.id, a.project_code as projectCode, a.project_name AS projectName, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName
  1467. FROM project AS a
  1468. LEFT JOIN report AS b ON b.project_id = a.id
  1469. JOIN user AS c ON b.creator_id = c.id
  1470. WHERE a.company_id = #{companyId}
  1471. <if test="projectId != null">
  1472. AND a.id = #{projectId}
  1473. </if>
  1474. <if test="startDate != null and endDate != null">
  1475. AND b.create_date between #{startDate} and #{endDate}
  1476. </if>
  1477. <choose>
  1478. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1479. and b.dept_id in
  1480. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1481. #{item}
  1482. </foreach>
  1483. </when>
  1484. <otherwise>
  1485. <if test="deptIds!=null and deptIds.size()>0">
  1486. and (b.dept_id in
  1487. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1488. #{item}
  1489. </foreach>
  1490. <if test="deptRelatedProjectIds.size() > 0">
  1491. or a.id in
  1492. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  1493. #{pid}
  1494. </foreach>
  1495. </if>
  1496. )
  1497. </if>
  1498. </otherwise>
  1499. </choose>
  1500. AND b.state = 1
  1501. GROUP BY a.id
  1502. ORDER BY a.id ASC
  1503. </select>
  1504. <!--获取某个项目每个维度分别需要的工时-->
  1505. <select id="getDegreeDetailCost" resultType="java.util.Map">
  1506. SELECT b.id as creatorId,a.project_id as projectId, b.name,b.corpwx_userid as corpwxUserId,a.dept_id as deptId,department.corpwx_deptid as corpwxDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney,r.name as degreeName
  1507. FROM report AS a
  1508. JOIN user AS b ON a.creator_id = b.id
  1509. left join department on department.department_id = a.dept_id
  1510. left join report_extra_degree as r on a.degree_id = r.id
  1511. WHERE a.company_id=#{companyId}
  1512. <if test="curProjectId != null">
  1513. and a.project_id = #{curProjectId}
  1514. </if>
  1515. <if test="projectId != null">
  1516. and a.project_id = #{projectId}
  1517. </if>
  1518. <if test="startDate != null and endDate != null">
  1519. AND a.create_date between #{startDate} and #{endDate}
  1520. </if>
  1521. <choose>
  1522. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1523. and a.dept_id in
  1524. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1525. #{item}
  1526. </foreach>
  1527. </when>
  1528. <otherwise>
  1529. <if test="deptIds!=null and deptIds.size()>0">
  1530. and a.dept_id in
  1531. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1532. #{item}
  1533. </foreach>
  1534. </if>
  1535. </otherwise>
  1536. </choose>
  1537. GROUP BY a.project_id,b.id,a.degree_id
  1538. ORDER BY b.id,a.degree_id ASC
  1539. </select>
  1540. <select id="selectNearProject" resultType="com.management.platform.entity.Project">
  1541. select * from project
  1542. where status = 1 and id in (
  1543. SELECT project_id
  1544. from (
  1545. SELECT project_id
  1546. FROM (
  1547. SELECT DISTINCT *
  1548. FROM report
  1549. WHERE creator_id = #{userId}
  1550. order by create_time
  1551. DESC
  1552. ) p1
  1553. GROUP BY project_id
  1554. order by create_time
  1555. DESC
  1556. LIMIT 3
  1557. ) p2
  1558. )
  1559. </select>
  1560. <select id="getFTEData" resultType="java.util.Map">
  1561. SELECT u.id,u.name userName,u.corpwx_userid wxUserId,u.plate1 area,r.projectName,r.projectCode,r.workTime
  1562. FROM `user` u
  1563. LEFT JOIN (
  1564. SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
  1565. FROM report
  1566. LEFT JOIN project p
  1567. ON report.project_id = p.id
  1568. LEFT JOIN `user`
  1569. ON user.id = report.creator_id
  1570. WHERE report.state = 1
  1571. AND p.is_public = 0
  1572. AND report.company_id=#{companyId}
  1573. AND report.create_date BETWEEN #{startDate} AND #{endDate}
  1574. GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
  1575. ) r
  1576. ON u.id = r.creator_id
  1577. WHERE u.company_id=#{companyId}
  1578. <if test="area!=null and area != '' ">
  1579. and u.plate1 = #{area}
  1580. </if>
  1581. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1582. and us.department_id in
  1583. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1584. #{item}
  1585. </foreach>
  1586. </if>
  1587. <if test="deptIds!=null and deptIds.size()>0">
  1588. and us.department_id in
  1589. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1590. #{item}
  1591. </foreach>
  1592. </if>
  1593. order by area,workTime,id
  1594. <if test="start!=null and size!=null">
  1595. limit #{start},#{size}
  1596. </if>
  1597. </select>
  1598. </mapper>