ProjectMapper.xml 77 KB

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