ProjectMapper.xml 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  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. <result column="from_outside" property="fromOutside" />
  60. <result column="approve_id" property="approveId" />
  61. </resultMap>
  62. <!-- 通用查询结果列 -->
  63. <sql id="Base_Column_List">
  64. 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, from_outside, approve_id
  65. </sql>
  66. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  67. <result column="id" property="id" />
  68. <result column="project_name" property="projectName" />
  69. <result column="project_code" property="projectCode" />
  70. <result column="startDate" property="startDate" />
  71. <result column="endDate" property="endDate" />
  72. <collection property="stageCostList" javaType="java.util.ArrayList"
  73. ofType="com.management.platform.entity.vo.StageCost"
  74. select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
  75. </resultMap>
  76. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  77. <result column="customer_id" property="customerId" />
  78. <result column="customer_name" property="customerName" />
  79. <result column="contract_amount" property="contractAmount" />
  80. <result column="fee_man" property="feeMan" />
  81. <result column="project_num" property="projectNum" />
  82. <result column="project_ids" property="projectIds" />
  83. <result column="project_names" property="projectNames" />
  84. </resultMap>
  85. <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
  86. select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
  87. from project
  88. where company_id = #{companyId}
  89. <if test="projectId != null">
  90. and id = #{projectId}
  91. </if>
  92. <if test="inchargerId!=null">
  93. and incharger_id = #{inchargerId}
  94. </if>
  95. order by is_public desc, id asc
  96. <if test="startIndex != null">
  97. limit ${startIndex}, ${endIndex}
  98. </if>
  99. </select>
  100. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  101. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  102. IFNULL(SUM(report.`working_time`), 0) AS working_time,
  103. 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
  104. FROM report
  105. left join project p on p.id=report.`project_id`
  106. where report.state = 1
  107. <if test="inchargerId!=null">
  108. and p.incharger_id = #{inchargerId}
  109. </if>
  110. <if test="projectIds!=null and projectIds.size()>0">
  111. and p.id in
  112. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  113. #{item}
  114. </foreach>
  115. </if>
  116. and report.create_date &gt;= #{startDate}
  117. and report.create_date &lt;= #{endDate}
  118. GROUP BY report.`project_id`,report.stage
  119. </select>
  120. <!--获取查询者所在公司每个项目的工时成本-->
  121. <select id="getParticipatedProject" resultType="java.util.Map">
  122. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc,is_public as isPublic, plan_end_date as planEndDate
  123. FROM project
  124. WHERE id IN (
  125. SELECT project_id
  126. FROM participation
  127. WHERE user_id = #{userId}
  128. ) or incharger_id = #{userId}
  129. or creator_id = #{userId}
  130. or (is_public = 1 and company_id = #{companyId})
  131. ORDER BY is_public DESC, id DESC
  132. </select>
  133. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  134. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc, is_public as isPublic, plan_end_date as planEndDate
  135. FROM project
  136. WHERE status = 1 and (id IN (
  137. SELECT project_id
  138. FROM participation
  139. WHERE user_id = #{userId}
  140. )
  141. or (is_public = 1 and company_id = #{companyId}))
  142. ORDER BY is_public DESC, id ASC
  143. </select>
  144. <!--获取查询者所在公司每个项目的工时成本-->
  145. <select id="getTimeCost" resultType="java.util.Map">
  146. SELECT a.id, a.project_main_id as projectMainId, 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
  147. FROM project AS a
  148. LEFT JOIN report AS b ON b.project_id = a.id
  149. JOIN user AS c ON b.creator_id = c.id
  150. WHERE a.company_id = #{companyId}
  151. <if test="projectId != null">
  152. AND a.id = #{projectId}
  153. </if>
  154. <if test="categoryId != null">
  155. AND a.category = #{categoryId}
  156. </if>
  157. <if test="projectIds != null">
  158. and a.id in
  159. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  160. #{item}
  161. </foreach>
  162. </if>
  163. <if test="userIdList != null and userIdList.size()>0">
  164. AND b.creator_id in
  165. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  166. #{item}
  167. </foreach>
  168. </if>
  169. <if test="startDate != null and endDate != null">
  170. AND b.create_date between #{startDate} and #{endDate}
  171. </if>
  172. <choose>
  173. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  174. and b.dept_id in
  175. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  176. #{item}
  177. </foreach>
  178. </when>
  179. <otherwise>
  180. <if test="deptIds!=null and deptIds.size()>0">
  181. and (b.dept_id in
  182. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  183. #{item}
  184. </foreach>
  185. <if test="deptRelatedProjectIds.size() > 0">
  186. or a.id in
  187. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  188. #{pid}
  189. </foreach>
  190. </if>
  191. <if test="inchargeUserIds != null and inchargeUserIds.size()>0">
  192. OR a.`incharger_id` IN
  193. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  194. #{pid}
  195. </foreach>
  196. OR b.`group_id` IN(SELECT id FROM task_group WHERE incharger_id IN
  197. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  198. #{pid}
  199. </foreach>
  200. )
  201. </if>
  202. )
  203. </if>
  204. </otherwise>
  205. </choose>
  206. AND b.state = 1
  207. GROUP BY a.id
  208. ORDER BY a.id ASC
  209. </select>
  210. <!--获取查询者所在公司每个子项目的工时成本-->
  211. <select id="getSubProjectTimeCost" resultType="java.util.Map">
  212. 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
  213. from sub_project a
  214. left join project b on b.id=a.project_id
  215. left join report c on c.sub_project_id=a.id
  216. where a.company_id=#{companyId}
  217. <if test="startDate != null and endDate != null">
  218. and c.create_date between #{startDate} and #{endDate}
  219. </if>
  220. <if test="projectId!=null">
  221. and a.project_id=#{projectId}
  222. </if>
  223. <if test="inchagerIds!=null and inchagerIds.size()>0">
  224. and b.id in
  225. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  226. #{item}
  227. </foreach>
  228. </if>
  229. group by b.id,a.id
  230. <if test="start!=null and size!=null">
  231. limit #{start},#{size}
  232. </if>
  233. </select>
  234. <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
  235. 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
  236. from sub_project a
  237. left join project b on b.id=a.project_id
  238. left join report c on c.sub_project_id=a.id
  239. where a.company_id=#{companyId}
  240. <if test="startDate != null and endDate != null">
  241. and c.create_date between #{startDate} and #{endDate}
  242. </if>
  243. <if test="projectId!=null">
  244. and a.project_id=#{projectId}
  245. </if>
  246. <if test="inchagerIds!=null and inchagerIds.size()>0">
  247. and b.id in
  248. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  249. #{item}
  250. </foreach>
  251. </if>
  252. group by b.id,a.id
  253. <if test="start!=null and size!=null">
  254. limit #{start},#{size}
  255. </if>) as total
  256. </select>
  257. <!--获取查询者所在公司每个项目的工时成本-->
  258. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  259. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'无主项目') as mainProjectName
  260. FROM project AS a
  261. LEFT JOIN report AS b ON b.project_id = a.id
  262. JOIN user AS c ON b.creator_id = c.id
  263. LEFT JOIN project_main pm on pm.id=a.project_main_id
  264. WHERE a.company_id = #{companyId}
  265. <if test="projectId != null">
  266. AND a.id = #{projectId}
  267. </if>
  268. <if test="startDate != null and endDate != null">
  269. AND b.create_date between #{startDate} and #{endDate}
  270. </if>
  271. <if test="deptIds!=null and deptIds.size()>0">
  272. and b.dept_id in
  273. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  274. #{item}
  275. </foreach>
  276. </if>
  277. AND b.state = 1
  278. GROUP BY a.project_main_id
  279. ORDER BY a.id ASC
  280. </select>
  281. <!--获取查询者所在公司每个项目分类的工时成本-->
  282. <select id="getTimeCostByCategory" resultType="java.util.Map">
  283. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  284. FROM project AS a
  285. LEFT JOIN report AS b ON b.project_id = a.id
  286. JOIN user AS c ON b.creator_id = c.id
  287. WHERE a.company_id = #{companyId}
  288. <if test="projectCategoryId != null">
  289. AND a.category = #{projectCategoryId}
  290. </if>
  291. <if test="projectIds != null">
  292. and a.id in
  293. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  294. #{item}
  295. </foreach>
  296. </if>
  297. <if test="userIdList != null and userIdList.size()>0">
  298. AND b.creator_id in
  299. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  300. #{item}
  301. </foreach>
  302. </if>
  303. <if test="startDate != null and endDate != null">
  304. AND b.create_date between #{startDate} and #{endDate}
  305. </if>
  306. <if test="deptIds!=null and deptIds.size()>0">
  307. and b.dept_id in
  308. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  309. #{item}
  310. </foreach>
  311. </if>
  312. AND b.state = 1
  313. GROUP BY a.category
  314. ORDER BY a.category ASC
  315. </select>
  316. <!--获取自定义数值的项目统计 -->
  317. <select id="getCustomDataSum" resultType="java.util.Map">
  318. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  319. FROM project AS a
  320. LEFT JOIN report AS b ON b.project_id = a.id
  321. JOIN user AS c ON b.creator_id = c.id
  322. WHERE a.company_id = #{companyId}
  323. <if test="projectId != null">
  324. AND a.id = #{projectId}
  325. </if>
  326. <if test="userId != null">
  327. AND b.creator_id = #{userId}
  328. </if>
  329. <if test="startDate != null and endDate != null">
  330. AND b.create_date between #{startDate} and #{endDate}
  331. </if>
  332. AND b.state = 1
  333. GROUP BY a.id
  334. having IFNULL(SUM(b.custom_data), 0) > 0
  335. ORDER BY SUM(b.custom_data) DESC
  336. </select>
  337. <!--获取日报的人员月度工时 -->
  338. <select id="getTimeCostReport" resultType="java.util.Map">
  339. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  340. FROM report AS a
  341. LEFT JOIN project AS b ON a.project_id = b.id
  342. LEFT JOIN user AS c ON a.creator_id = c.id
  343. WHERE b.company_id = #{companyId}
  344. <if test="projectId != null">
  345. AND b.id = #{projectId}
  346. </if>
  347. <if test="startDate != null and endDate != null">
  348. AND a.create_date between #{startDate} and #{endDate}
  349. </if>
  350. <if test="deptIds!=null and deptIds.size()>0">
  351. and a.dept_id in
  352. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  353. #{item}
  354. </foreach>
  355. </if>
  356. AND a.state = 1
  357. </select>
  358. <!--获取人员的月度总工时 -->
  359. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  360. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  361. FROM report AS a, user as b
  362. WHERE a.creator_id = b.id
  363. and b.company_id = #{companyId}
  364. <if test="startDate != null and endDate != null">
  365. AND a.create_date between #{startDate} and #{endDate}
  366. </if>
  367. AND a.state = 1
  368. group by a.creator_id
  369. </select>
  370. <!--获取某个项目每个人分别需要的工时-->
  371. <select id="getProjectCost" resultType="java.util.Map">
  372. 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
  373. FROM report AS a
  374. JOIN user AS b ON a.creator_id = b.id
  375. left join department on department.department_id = a.dept_id
  376. WHERE a.company_id=#{companyId}
  377. <choose>
  378. <when test="stateKey!=null and stateKey==1">
  379. and a.state = 1
  380. </when>
  381. <otherwise>
  382. and (a.state = 1 or a.state =0)
  383. </otherwise>
  384. </choose>
  385. <if test="projectId != null">
  386. and a.project_id = #{projectId}
  387. </if>
  388. <if test="startDate != null and endDate != null">
  389. AND a.create_date between #{startDate} and #{endDate}
  390. </if>
  391. <if test="userIdList != null and userIdList.size()>0">
  392. AND a.creator_id in
  393. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  394. #{item}
  395. </foreach>
  396. </if>
  397. <choose>
  398. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  399. and a.dept_id in
  400. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  401. #{item}
  402. </foreach>
  403. </when>
  404. <otherwise>
  405. <if test="deptIds!=null and deptIds.size()>0">
  406. and a.dept_id in
  407. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  408. #{item}
  409. </foreach>
  410. </if>
  411. </otherwise>
  412. </choose>
  413. GROUP BY b.id
  414. <if test="withDept">
  415. , a.dept_id
  416. </if>
  417. ORDER BY b.id ASC
  418. <if test="withDept">
  419. , a.dept_id ASC
  420. </if>
  421. </select>
  422. <!--获取某个项目分类每个人分别需要的工时-->
  423. <select id="getProjectCostByCategory" resultType="java.util.Map">
  424. 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
  425. FROM report AS a
  426. JOIN user AS b ON a.creator_id = b.id
  427. left join department on department.department_id = a.dept_id
  428. left join project c on c.id=a.project_id
  429. WHERE a.company_id=#{companyId} and a.state = 1
  430. <if test="curProjectCategoryId != null">
  431. and c.category = #{curProjectCategoryId}
  432. </if>
  433. <if test="startDate != null and endDate != null">
  434. AND a.create_date between #{startDate} and #{endDate}
  435. </if>
  436. <if test="userId != null">
  437. AND a.creator_id = #{userId}
  438. </if>
  439. GROUP BY c.category, a.dept_id
  440. ORDER BY c.category ASC, a.dept_id ASC
  441. </select>
  442. <!--获取个人每个项目分别需要的工时-->
  443. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  444. 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
  445. FROM report AS a
  446. JOIN user AS b ON a.creator_id = b.id
  447. left join department on department.department_id = a.dept_id
  448. WHERE a.company_id=#{companyId} and a.state = 1
  449. <if test="projectId != null">
  450. and a.project_id = #{projectId}
  451. </if>
  452. <if test="startDate != null and endDate != null">
  453. AND a.create_date between #{startDate} and #{endDate}
  454. </if>
  455. <if test="userIdList != null and userIdList.size()>0">
  456. AND a.creator_id in
  457. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  458. #{item}
  459. </foreach>
  460. </if>
  461. <if test="deptIds!=null and deptIds.size()>0">
  462. and a.dept_id in
  463. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  464. #{item}
  465. </foreach>
  466. </if>
  467. GROUP BY b.id,a.project_id
  468. ORDER BY b.id ASC, a.dept_id ASC
  469. </select>
  470. <!--获取个人每个项目分类分别需要的工时-->
  471. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  472. 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
  473. FROM report AS a
  474. JOIN user AS b ON a.creator_id = b.id
  475. left join department on department.department_id = a.dept_id
  476. left join project c on c.id=a.project_id
  477. WHERE a.company_id=#{companyId} and a.state = 1
  478. <if test="projectCategoryId != null">
  479. and c.category = #{projectCategoryId}
  480. </if>
  481. <if test="startDate != null and endDate != null">
  482. AND a.create_date between #{startDate} and #{endDate}
  483. </if>
  484. <if test="userIdList != null and userIdList.size()>0">
  485. AND a.creator_id in
  486. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  487. #{item}
  488. </foreach>
  489. </if>
  490. <if test="deptIds!=null and deptIds.size()>0">
  491. and a.dept_id in
  492. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  493. #{item}
  494. </foreach>
  495. </if>
  496. GROUP BY b.id,c.category
  497. ORDER BY b.id ASC, a.dept_id ASC
  498. </select>
  499. <!-- 获取人员在日报填写的自定义数值 -->
  500. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  501. SELECT b.id as creatorId,
  502. b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
  503. FROM report AS a
  504. JOIN user AS b ON a.creator_id = b.id
  505. left join department on department.department_id = b.department_id
  506. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  507. <if test="startDate != null and endDate != null">
  508. AND a.create_date between #{startDate} and #{endDate}
  509. </if>
  510. <if test="projectId != null">
  511. AND a.project_id = #{projectId}
  512. </if>
  513. <if test="userId != null">
  514. AND a.creator_id = #{userId}
  515. </if>
  516. <if test="deptIds != null">
  517. AND department.department_id in
  518. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  519. #{item}
  520. </foreach>
  521. </if>
  522. group by b.id
  523. ORDER BY b.id ASC
  524. </select>
  525. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  526. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  527. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  528. FROM report AS a
  529. JOIN user AS b ON a.creator_id = b.id
  530. left join department on department.department_id = b.department_id
  531. left join project on project.id = a.project_id
  532. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  533. <if test="startDate != null and endDate != null">
  534. AND a.create_date between #{startDate} and #{endDate}
  535. </if>
  536. <if test="projectId != null">
  537. AND a.project_id = #{projectId}
  538. </if>
  539. <if test="userId != null">
  540. AND a.creator_id = #{userId}
  541. </if>
  542. ORDER BY a.create_date desc
  543. </select>
  544. <!--按照项目内的阶段名称分组统计工时-->
  545. <select id="getCostInStage" resultType="java.util.Map">
  546. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  547. FROM report AS a
  548. WHERE a.project_id = #{projectId}
  549. AND a.state = 1
  550. <if test="startDate != null and endDate != null">
  551. AND a.create_date between #{startDate} and #{endDate}
  552. </if>
  553. GROUP BY a.stage
  554. ORDER BY a.stage ASC
  555. </select>
  556. <!--按照项目内的阶段名称分组统计工时-->
  557. <select id="getCostByGroup" resultType="java.util.Map">
  558. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  559. FROM report AS a
  560. left join task_group tg on tg.id=a.group_id
  561. WHERE a.project_id = #{projectId}
  562. AND a.state = 1
  563. <if test="startDate != null and endDate != null">
  564. AND a.create_date between #{startDate} and #{endDate}
  565. </if>
  566. <if test="gpIds != null">
  567. AND a.group_id in
  568. <foreach collection="gpIds" open="(" separator="," close=")" item="item">
  569. #{item}
  570. </foreach>
  571. </if>
  572. GROUP BY a.group_id
  573. ORDER BY a.group_id ASC
  574. </select>
  575. <!--获取全部人员工时 -->
  576. <select id="getAllMembCost" resultType="java.util.Map">
  577. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  578. FROM user AS b
  579. left JOIN report AS a ON a.creator_id = b.id
  580. WHERE a.state = 1
  581. and b.company_id = #{companyId}
  582. <if test="startDate != null and endDate != null">
  583. AND a.create_date between #{startDate} and #{endDate}
  584. </if>
  585. <if test="projectId != null">
  586. AND a.project_id = #{projectId}
  587. </if>
  588. GROUP BY b.id
  589. ORDER BY b.id ASC
  590. </select>
  591. <!--分页获取项目成本 -->
  592. <select id="getAllProjectCost" resultType="java.util.Map">
  593. SELECT id, project_code as projectCode, project_name as projectName,budget,
  594. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  595. FROM project 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 project.is_public desc, project.id asc
  607. <if test="pageStart != null and pageSize != null">
  608. LIMIT #{pageStart},#{pageSize}
  609. </if>
  610. </select>
  611. <!--分页获取项目收支平衡 -->
  612. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  613. SELECT project.id, project_code, project_name,contract_amount, IFNULL(contract.payment, 0) as payment,
  614. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  615. FROM project
  616. left join contract on contract.project_id = project.id
  617. WHERE project.`company_id` = #{companyId}
  618. and (project.status &lt;&gt; 3 or project.status is null)
  619. <if test="projectId != null">
  620. and project.id = #{projectId}
  621. </if>
  622. <if test="inchagerIds!=null and inchagerIds.size()>0">
  623. and project.id in
  624. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  625. #{item}
  626. </foreach>
  627. </if>
  628. order by is_public desc, project.id asc
  629. <if test="pageStart != null and pageSize != null">
  630. LIMIT #{pageStart},#{pageSize}
  631. </if>
  632. </select>
  633. <select id="getProjectExpenseFee" resultType="java.util.Map">
  634. 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
  635. left join expense_sheet on expense_sheet.id = expense_item.`expense_id`
  636. left join expense_main_type on expense_main_type.id = expense_sheet.`type`
  637. WHERE expense_sheet.`company_id` = #{companyId} AND expense_sheet.id = expense_item.`expense_id`
  638. AND expense_sheet.status = 0
  639. and project_id in
  640. <foreach collection="projectIds" open="(" separator="," close=")" item="item">
  641. #{item}
  642. </foreach>
  643. GROUP BY project_id, expense_sheet.type
  644. </select>
  645. <!--分页获取客户项目的成本利润报表 -->
  646. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  647. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  648. SUM(contract_amount) AS contract_amount ,
  649. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man
  650. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  651. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  652. <if test="customerId!=null">
  653. and project.customer_id=#{customerId}
  654. </if>
  655. <if test="projectId!=null">
  656. and project.id=#{projectId}
  657. </if>
  658. GROUP BY customer_id
  659. <if test="pageStart != null and pageSize != null">
  660. LIMIT #{pageStart},#{pageSize}
  661. </if>
  662. </select>
  663. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  664. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  665. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  666. <if test="customerId!=null">
  667. and project.customer_id=#{customerId}
  668. </if>
  669. <if test="projectId!=null">
  670. and project.id=#{projectId}
  671. </if>
  672. </select>
  673. <!--分页获取项目收支平衡 -->
  674. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  675. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  676. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  677. FROM project WHERE project.`company_id` = #{companyId}
  678. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  679. #{item}
  680. </foreach>
  681. </select>
  682. <select id="getGanttData" resultType="java.util.Map">
  683. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  684. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  685. LEFT JOIN user ON user.id = participation.`user_id`
  686. LEFT JOIN project ON project.`id` = participation.`project_id`
  687. WHERE participation.`user_id` IN
  688. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  689. #{item}
  690. </foreach>
  691. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  692. ORDER BY participation.user_id, project.`plan_start_date`
  693. </select>
  694. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  695. 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,
  696. 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
  697. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  698. left join task on task.id = task_executor.task_id
  699. LEFT JOIN project ON project.`id` = task.`project_id`
  700. WHERE user.`id` IN
  701. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  702. #{item}
  703. </foreach>
  704. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  705. and task.end_date is not null
  706. AND project.`status` = 1
  707. ORDER BY user.id, task.start_date
  708. </select>
  709. <select id="getTaskPlanByProject" resultType="java.util.Map">
  710. 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,
  711. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  712. LEFT JOIN task ON task.project_id = project.id
  713. WHERE project.company_id = #{companyId}
  714. <if test="projectIds != null">
  715. and project.`id` IN
  716. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  717. #{item}
  718. </foreach>
  719. </if>
  720. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  721. and task.end_date is not null
  722. AND project.`status` = 1
  723. ORDER BY project.id, task.start_date
  724. </select>
  725. <!--获取加班统计报表 -->
  726. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  727. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  728. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  729. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  730. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  731. <!-- left join project on project.id = report.project_id-->
  732. <!-- WHERE report.is_overtime = 1-->
  733. <!-- and report.`state` = 1-->
  734. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  735. <!-- AND user.`company_id` = #{companyId}-->
  736. <!-- <if test="projectId != null">-->
  737. <!-- AND report.`project_id` = #{projectId}-->
  738. <!-- </if>-->
  739. <!-- <if test="userId != null">-->
  740. <!-- AND report.`creator_id` = #{userId}-->
  741. <!-- </if>-->
  742. <!-- GROUP BY report.creator_id-->
  743. <!-- </select>-->
  744. <!-- 获取某个员工的某时间段内的加班详情 -->
  745. <select id="getOvertimeDetail" resultType="java.util.Map">
  746. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  747. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  748. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  749. project.project_name as projectName,project.project_code as projectCode,
  750. IFNULL(report.overtime_cost, 0) AS cost,
  751. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  752. left join project on project.id = report.project_id
  753. left join report_extra_degree on report_extra_degree.id = report.degree_id
  754. left join department on department.department_id = report.dept_id
  755. WHERE report.is_overtime = 1
  756. and report.`state` = 1
  757. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  758. AND user.`company_id` = #{companyId}
  759. <if test="projectId != null">
  760. AND report.`project_id` = #{projectId}
  761. </if>
  762. <if test="userId != null">
  763. AND report.`creator_id` = #{userId}
  764. </if>
  765. <if test="branchDepartment!=null and branchDepartment.size()>0">
  766. and report.dept_id in
  767. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  768. #{item}
  769. </foreach>
  770. </if>
  771. <if test="deptIds!=null and deptIds.size()>0">
  772. and report.dept_id in
  773. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  774. #{item}
  775. </foreach>
  776. </if>
  777. order by user.create_time asc, report.create_date desc
  778. </select>
  779. <!--获取人员工时-->
  780. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  781. SELECT report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber,
  782. user.department_id As deptId,
  783. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  784. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  785. ifnull(SUM(report.`working_time`),0) AS workingTime,
  786. ifnull(SUM(report.`overtime_hours`),0) AS overtimeHours
  787. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  788. left join project on project.id = report.project_id
  789. WHERE
  790. report.`state` = 1
  791. AND user.`is_active` = 1
  792. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  793. AND user.`company_id` =#{companyId}
  794. <if test="userId!=null">
  795. and user.id=#{userId}
  796. </if>
  797. <if test="projectId!=null">
  798. and project.id=#{projectId}
  799. </if>
  800. <if test="branchDepartment!=null and branchDepartment.size()>0">
  801. and report.dept_id in
  802. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  803. #{item}
  804. </foreach>
  805. </if>
  806. <if test="deptIds!=null and deptIds.size()>0">
  807. and report.dept_id in
  808. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  809. #{item}
  810. </foreach>
  811. </if>
  812. group by user.id
  813. order by user.create_time asc, report.create_date desc
  814. <if test="start!=null and size!=null">
  815. limit #{start},#{size}
  816. </if>
  817. </select>
  818. <select id="findCountWithUser" resultType="java.lang.Long">
  819. select count(*)
  820. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  821. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  822. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  823. ifnull(SUM(report.`working_time`),0) AS workingTime
  824. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  825. left join project on project.id = report.project_id
  826. WHERE
  827. report.`state` = 1
  828. AND user.`is_active` = 1
  829. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  830. AND user.`company_id` =#{companyId}
  831. <if test="userId!=null">
  832. and user.id=#{userId}
  833. </if>
  834. <if test="projectId!=null">
  835. and project.id=#{projectId}
  836. </if>
  837. <if test="departmentId!=null">
  838. and report.dept_id=#{departmentId}
  839. </if>
  840. <if test="deptIds!=null and deptIds.size()>0">
  841. and report.dept_id in
  842. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  843. #{item}
  844. </foreach>
  845. </if>
  846. group by user.id
  847. order by user.create_time asc, report.create_date desc
  848. <if test="start!=null and size!=null">
  849. limit #{start},#{size}
  850. </if>) as total
  851. </select>
  852. <!--按照项目内的阶段名称分组统计工时-->
  853. <select id="getDegreeCost" resultType="java.util.Map">
  854. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
  855. FROM report AS a
  856. left join report_extra_degree b on b.id = a.degree_id
  857. WHERE
  858. a.state = 1
  859. and a.company_id = #{companyId}
  860. <if test="departmentIds!=null and departmentIds.size()>0">
  861. and a.dept_id in
  862. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  863. #{item}
  864. </foreach>
  865. </if>
  866. <if test="projectId != null">
  867. and a.project_id = #{projectId}
  868. </if>
  869. <if test="userId != null and userId!=''">
  870. and a.creator_id = #{userId}
  871. </if>
  872. <if test="startDate != null and endDate != null">
  873. AND a.create_date between #{startDate} and #{endDate}
  874. </if>
  875. GROUP BY a.degree_id
  876. ORDER BY a.degree_id ASC
  877. </select>
  878. <!--项目导出数据-->
  879. <select id="getExportData" resultType="java.util.HashMap" >
  880. 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,
  881. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  882. customer_name, associate_degree_names, provider_names,provider_ids
  883. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  884. LEFT JOIN participation c ON c.project_id = project.`id`
  885. LEFT JOIN user u ON u.id = c.user_id
  886. LEFT JOIN user d ON d.id = project.`incharger_id`
  887. WHERE project.`company_id` = #{companyId}
  888. <if test="userId != null" >
  889. and (project.creator_id = #{userId} or c.user_id = #{userId})
  890. </if>
  891. GROUP BY project.id
  892. </select>
  893. <!--按项目分组导出数据-->
  894. <select id="getExportGroupData" resultType="java.util.Map" >
  895. SELECT project_code AS projectCode,project_name AS projectName,task_group.`name` AS groupName,task_group.`incharger_id` AS inchargerId,
  896. GROUP_CONCAT(group_participator.`user_id`) AS participatorIds
  897. FROM task_group
  898. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  899. LEFT JOIN project ON task_group.project_id = project.id
  900. <if test="projectCategorySub!=null and projectCategorySub!=''">
  901. left join project_separate ps on ps.id=project.id
  902. </if>
  903. where project.company_id = #{companyId}
  904. <if test="projectCategorySub!=null and projectCategorySub!=''">
  905. and ps.project_category_sub=#{projectCategorySub}
  906. </if>
  907. GROUP BY task_group.id
  908. ORDER BY project_id
  909. </select>
  910. <!--分页获取项目工时成本预警表 -->
  911. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  912. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  913. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  914. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  915. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  916. AND project_id=project.id) AS costLimit,
  917. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  918. FROM project WHERE company_id=#{companyId}
  919. and (project.status &lt;&gt; 3 or project.status is null)
  920. <if test="projectId != null">
  921. and project.id = #{projectId}
  922. </if>
  923. <if test="pageStart != null and pageSize != null">
  924. LIMIT #{pageStart},#{pageSize}
  925. </if>
  926. </select>
  927. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  928. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  929. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  930. 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,
  931. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  932. 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,
  933. (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
  934. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  935. <if test="projectId != null">
  936. and project.id = #{projectId}
  937. </if>
  938. <if test="list!=null and list.size()>0">
  939. and project.id in
  940. <foreach collection="list" open="(" close=")" item="item" separator=",">
  941. #{item}
  942. </foreach>
  943. </if>
  944. <if test="pageStart != null and pageSize != null">
  945. LIMIT #{pageStart},#{pageSize}
  946. </if>
  947. </select>
  948. <select id="getWaitingReviewList" resultType="java.util.Map">
  949. <choose>
  950. <when test="stateKey==0">
  951. 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
  952. FROM report AS a
  953. left join user on user.id = a.creator_id
  954. JOIN project AS b ON a.project_id=b.id
  955. left join sub_project as d on d.id = a.sub_project_id
  956. left join task on task.id = a.task_id
  957. left join report_extra_degree on report_extra_degree.id = a.degree_id
  958. left join department on department.department_id = a.audit_deptid
  959. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  960. left join department dept on dept.department_id = a.dept_id
  961. left join task_group on task_group.id = a.group_id
  962. left join user u on u.id = a.project_auditor_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=1
  969. <if test="userId!=null">
  970. and dept_manager.id=#{userId}
  971. </if>
  972. <if test="departmentId!=null">
  973. and dept_manager.department_id=#{departmentId}
  974. </if>
  975. <if test="deptIds!=null and deptIds.size()>0">
  976. and dept_manager.department_id in
  977. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  978. #{item}
  979. </foreach>
  980. </if>
  981. group by a.audit_dept_managerid
  982. ORDER BY a.create_date desc, a.creator_id asc
  983. </when>
  984. <otherwise>
  985. 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
  986. FROM report AS a
  987. left join user on user.id = a.creator_id
  988. JOIN project AS b ON a.project_id=b.id
  989. left join sub_project as d on d.id = a.sub_project_id
  990. left join task on task.id = a.task_id
  991. left join report_extra_degree on report_extra_degree.id = a.degree_id
  992. left join department on department.department_id = a.audit_deptid
  993. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  994. left join department dept on dept.department_id = a.dept_id
  995. left join task_group on task_group.id = a.group_id
  996. left join user u on u.id = a.project_auditor_id
  997. left join department dp on u.department_id=dp.department_id
  998. WHERE a.company_id =#{companyId}
  999. and a.state = 0
  1000. <if test="startDate!=null and endDate!=null">
  1001. AND a.create_date between #{startDate} and #{endDate}
  1002. </if>
  1003. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1004. <if test="userId!=null">
  1005. and u.id=#{userId}
  1006. </if>
  1007. <if test="departmentId!=null">
  1008. and u.department_id=#{departmentId}
  1009. </if>
  1010. <if test="deptIds!=null and deptIds.size()>0">
  1011. and u.department_id in
  1012. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1013. #{item}
  1014. </foreach>
  1015. </if>
  1016. group by a.project_auditor_id
  1017. ORDER BY a.create_date desc, a.creator_id asc
  1018. </otherwise>
  1019. </choose>
  1020. <if test="start!=null and size!=null">
  1021. limit #{start},#{size}
  1022. </if>
  1023. </select>
  1024. <select id="findCount" resultType="java.lang.Long">
  1025. select count(1)
  1026. from (<choose>
  1027. <when test="stateKey==0">
  1028. SELECT dept_manager.name as userName,department.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. 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=1
  1047. <if test="userId!=null">
  1048. and dept_manager.id=#{userId}
  1049. </if>
  1050. <if test="departmentId!=null">
  1051. and dept_manager.department_id=#{departmentId}
  1052. </if>
  1053. <if test="deptIds!=null and deptIds.size()>0">
  1054. and dept_manager.department_id in
  1055. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1056. #{item}
  1057. </foreach>
  1058. </if>
  1059. group by a.audit_dept_managerid
  1060. ORDER BY a.create_date desc, a.creator_id asc
  1061. </when>
  1062. <otherwise>
  1063. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1064. FROM report AS a
  1065. left join user on user.id = a.creator_id
  1066. JOIN project AS b ON a.project_id=b.id
  1067. left join sub_project as d on d.id = a.sub_project_id
  1068. left join task on task.id = a.task_id
  1069. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1070. left join department on department.department_id = a.audit_deptid
  1071. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1072. left join department dept on dept.department_id = a.dept_id
  1073. left join task_group on task_group.id = a.group_id
  1074. left join user u on u.id = a.project_auditor_id
  1075. left join department dp on u.department_id=dp.department_id
  1076. WHERE a.company_id =#{companyId}
  1077. and a.state = 0
  1078. and u.is_active = 1
  1079. <if test="startDate!=null and endDate!=null">
  1080. AND a.create_date between #{startDate} and #{endDate}
  1081. </if>
  1082. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1083. <if test="userId!=null">
  1084. and u.id=#{userId}
  1085. </if>
  1086. <if test="departmentId!=null">
  1087. and u.department_id=#{departmentId}
  1088. </if>
  1089. <if test="deptIds!=null and deptIds.size()>0">
  1090. and u.department_id in
  1091. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1092. #{item}
  1093. </foreach>
  1094. </if>
  1095. group by a.project_auditor_id
  1096. ORDER BY a.create_date desc, a.creator_id asc
  1097. </otherwise>
  1098. </choose>
  1099. <if test="start!=null and size!=null">
  1100. limit #{start},#{size}
  1101. </if>) total
  1102. </select>
  1103. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1104. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1105. (select SUM(te.plan_hours) from task_executor te
  1106. left join task on task.id=te.task_id
  1107. where te.executor_id=us.id
  1108. <if test="startDate!=null and endDate!=null">
  1109. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1110. </if>) as planHours,
  1111. (select SUM(report.working_time) from report
  1112. left join task on task.id=report.task_id
  1113. where report.creator_id=us.id and task_id is not null and report.state=1
  1114. <if test="startDate!=null and endDate!=null">
  1115. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1116. </if>) as workingTime
  1117. from user us
  1118. left join department dp on dp.department_id=us.department_id
  1119. where us.company_id=#{companyId}
  1120. 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)
  1121. <if test="userId!=null and userId!=''">
  1122. and us.id=#{userId}
  1123. </if>
  1124. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1125. and us.department_id in
  1126. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1127. #{item}
  1128. </foreach>
  1129. </if>
  1130. <if test="deptIds!=null and deptIds.size()>0">
  1131. and us.department_id in
  1132. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1133. #{item}
  1134. </foreach>
  1135. </if>
  1136. group by us.id
  1137. order by us.department_id
  1138. <if test="start!=null and size!=null">
  1139. limit #{start},#{size}
  1140. </if>
  1141. </select>
  1142. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1143. select count(1)
  1144. from(select us.name,dp.department_name as departmentName,
  1145. (select SUM(te.plan_hours) from task_executor te
  1146. left join task on task.id=te.task_id
  1147. where te.executor_id=us.id
  1148. <if test="startDate!=null and endDate!=null">
  1149. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1150. </if>) as planHours,
  1151. (select SUM(report.working_time) from report
  1152. left join task on task.id=report.task_id
  1153. where report.creator_id=us.id and task_id is not null
  1154. <if test="startDate!=null and endDate!=null">
  1155. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1156. </if>) as workingTime
  1157. from user us
  1158. left join department dp on dp.department_id=us.department_id
  1159. where us.company_id=#{companyId}
  1160. 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)
  1161. <if test="userId!=null and userId!=''">
  1162. and us.id=#{userId}
  1163. </if>
  1164. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1165. and us.department_id in
  1166. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1167. #{item}
  1168. </foreach>
  1169. </if>
  1170. <if test="deptIds!=null and deptIds.size()>0">
  1171. and us.department_id in
  1172. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1173. #{item}
  1174. </foreach>
  1175. </if>
  1176. group by us.id
  1177. order by us.department_id)as total
  1178. </select>
  1179. <select id="selectWithGroup" resultType="java.util.Map">
  1180. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1181. from report a
  1182. left join task_group b on a.group_id=b.id
  1183. left join project c on a.project_id=c.id
  1184. where c.company_id=#{companyId} and a.state=1
  1185. <if test="startDate!=null and endDate!=null">
  1186. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1187. </if>
  1188. <if test="projectId!=null">
  1189. and c.id=#{projectId}
  1190. </if>
  1191. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1192. and (c.id in
  1193. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1194. #{item}
  1195. </foreach>
  1196. <!--或者按分组负责人的匹配-->
  1197. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1198. or a.group_id in
  1199. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1200. #{item}
  1201. </foreach>
  1202. </if>
  1203. )
  1204. </if>
  1205. <if test="groupId!=null">
  1206. and a.group_id=#{groupId}
  1207. </if>
  1208. group by b.name
  1209. order by c.id
  1210. <if test="startIndex!=null and endIndex!=null">
  1211. limit #{startIndex},#{endIndex}
  1212. </if>
  1213. </select>
  1214. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1215. select count(1) from(
  1216. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1217. from report a
  1218. left join task_group b on a.group_id=b.id
  1219. left join project c on a.project_id=c.id
  1220. where c.company_id=#{companyId} and a.state=1
  1221. <if test="startDate!=null and endDate!=null">
  1222. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1223. </if>
  1224. <if test="projectId!=null">
  1225. and c.id=#{projectId}
  1226. </if>
  1227. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1228. and (c.id in
  1229. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1230. #{item}
  1231. </foreach>
  1232. <!--或者按分组负责人的匹配-->
  1233. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1234. or a.group_id in
  1235. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1236. #{item}
  1237. </foreach>
  1238. </if>
  1239. )
  1240. </if>
  1241. <if test="groupId!=null">
  1242. and a.group_id=#{groupId}
  1243. </if>
  1244. group by b.name
  1245. order by c.id
  1246. <if test="startIndex!=null and endIndex!=null">
  1247. limit #{startIndex},#{endIndex}
  1248. </if>) as total
  1249. </select>
  1250. <select id="selectWithGroupProject" resultType="java.util.Map">
  1251. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1252. from report a
  1253. left join task_group b on a.group_id=b.id
  1254. left join project c on a.project_id=c.id
  1255. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1256. left join project_separate ps on ps.id=c.id
  1257. </if>
  1258. where c.company_id=#{companyId} and a.state=1
  1259. <if test="startDate!=null and endDate!=null">
  1260. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1261. </if>
  1262. <if test="projectId!=null">
  1263. and c.id=#{projectId}
  1264. </if>
  1265. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1266. and ps.project_category_sub=#{projectCategorySub}
  1267. </if>
  1268. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1269. and (c.id in
  1270. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1271. #{item}
  1272. </foreach>
  1273. <!--或者按分组负责人的匹配-->
  1274. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1275. or a.group_id in
  1276. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1277. #{item}
  1278. </foreach>
  1279. </if>
  1280. )
  1281. </if>
  1282. <if test="groupId!=null">
  1283. and a.group_id=#{groupId}
  1284. </if>
  1285. group by c.id,b.id
  1286. order by c.id
  1287. <if test="startIndex!=null and endIndex!=null">
  1288. limit #{startIndex},#{endIndex}
  1289. </if>
  1290. </select>
  1291. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1292. select count(1) from(
  1293. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1294. from report a
  1295. left join task_group b on a.group_id=b.id
  1296. left join project c on a.project_id=c.id
  1297. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1298. left join project_separate ps on ps.id=c.id
  1299. </if>
  1300. where c.company_id=#{companyId} and a.state=1
  1301. <if test="startDate!=null and endDate!=null">
  1302. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1303. </if>
  1304. <if test="projectId!=null">
  1305. and c.id=#{projectId}
  1306. </if>
  1307. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1308. and ps.project_category_sub=#{projectCategorySub}
  1309. </if>
  1310. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1311. and (c.id in
  1312. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1313. #{item}
  1314. </foreach>
  1315. <!--或者按分组负责人的匹配-->
  1316. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1317. or a.group_id in
  1318. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1319. #{item}
  1320. </foreach>
  1321. </if>
  1322. )
  1323. </if>
  1324. <if test="groupId!=null">
  1325. and a.group_id=#{groupId}
  1326. </if>
  1327. group by c.id,b.id
  1328. order by c.id
  1329. <if test="startIndex!=null and endIndex!=null">
  1330. limit #{startIndex},#{endIndex}
  1331. </if>) as total
  1332. </select>
  1333. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1334. 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
  1335. from report a
  1336. left join task_group b on a.group_id=b.id
  1337. left join project c on a.project_id=c.id
  1338. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1339. where c.company_id=#{companyId} and a.state=1
  1340. <if test="startDate!=null and endDate!=null">
  1341. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1342. </if>
  1343. <if test="projectId!=null">
  1344. and c.id=#{projectId}
  1345. </if>
  1346. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1347. and c.id in
  1348. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1349. #{item}
  1350. </foreach>
  1351. </if>
  1352. <if test="gpNamesList !=null">
  1353. and b.name in
  1354. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1355. #{item}
  1356. </foreach>
  1357. </if>
  1358. group by c.id,b.id
  1359. <if test="start!=null and size!=null">
  1360. limit #{start},#{size}
  1361. </if>
  1362. </select>
  1363. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1364. select count(1) from
  1365. (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
  1366. from report a
  1367. left join task_group b on a.group_id=b.id
  1368. left join project c on a.project_id=c.id
  1369. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1370. where c.company_id=#{companyId} and a.state=1
  1371. <if test="startDate!=null and endDate!=null">
  1372. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1373. </if>
  1374. <if test="projectId!=null">
  1375. and c.id=#{projectId}
  1376. </if>
  1377. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1378. and c.id in
  1379. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1380. #{item}
  1381. </foreach>
  1382. </if>
  1383. <if test="gpNamesList !=null">
  1384. and b.name in
  1385. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1386. #{item}
  1387. </foreach>
  1388. </if>
  1389. group by c.id,b.id
  1390. <if test="start!=null and size!=null">
  1391. limit #{start},#{size}
  1392. </if>) as total
  1393. </select>
  1394. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1395. 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
  1396. from report a
  1397. left join task_group b on a.group_id=b.id
  1398. left join project c on a.project_id=c.id
  1399. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1400. where c.company_id=#{companyId} and a.state=1
  1401. <if test="startDate!=null and endDate!=null">
  1402. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1403. </if>
  1404. <if test="projectId!=null">
  1405. and c.id=#{projectId}
  1406. </if>
  1407. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1408. and c.id in
  1409. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1410. #{item}
  1411. </foreach>
  1412. </if>
  1413. <if test="gpNamesList !=null">
  1414. and b.name in
  1415. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1416. #{item}
  1417. </foreach>
  1418. </if>
  1419. group by c.id,f.id
  1420. <if test="start!=null and size!=null">
  1421. limit #{start},#{size}
  1422. </if>
  1423. </select>
  1424. <select id="getCostByUserCustom" resultType="java.util.Map">
  1425. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1426. FROM user AS a
  1427. LEFT JOIN report AS b ON a.id = b.creator_id
  1428. LEFT JOIN project AS c ON b.project_id = c.id
  1429. left join user_custom uc on uc.company_id=a.company_id
  1430. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1431. WHERE b.state = 1
  1432. AND a.company_id = #{companyId}
  1433. <if test="startDate!=null and endDate!=null">
  1434. AND b.create_date between #{startDate} and #{endDate}
  1435. </if>
  1436. and uc.id=#{customId}
  1437. <if test="deptIds!=null and deptIds.size()>0">
  1438. and a.department_id in
  1439. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1440. #{item}
  1441. </foreach>
  1442. </if>
  1443. <if test="subCustomName!=null">
  1444. and suc.name=#{subCustomName}
  1445. </if>
  1446. GROUP BY suc.name
  1447. </select>
  1448. <select id="getEmpMonthHours" resultType="java.util.Map">
  1449. 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,
  1450. (select allday from time_type te
  1451. where te.company_id=#{companyId}) as allday,
  1452. (select SUM(report.working_time) from report
  1453. where report.creator_id=us.id and report.state=1
  1454. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1455. as workingTime
  1456. from user us
  1457. left join department dp on dp.department_id=us.department_id
  1458. where us.company_id=#{companyId}
  1459. 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)
  1460. <if test="userId!=null and userId!=''">
  1461. and us.id=#{userId}
  1462. </if>
  1463. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1464. and us.department_id in
  1465. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1466. #{item}
  1467. </foreach>
  1468. </if>
  1469. <if test="deptIds!=null and deptIds.size()>0">
  1470. and us.department_id in
  1471. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1472. #{item}
  1473. </foreach>
  1474. </if>
  1475. group by us.id
  1476. order by us.department_id
  1477. <if test="start!=null and size!=null">
  1478. limit #{start},#{size}
  1479. </if>
  1480. </select>
  1481. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1482. select count(1)
  1483. from(select us.name,dp.department_name as departmentName,
  1484. (select SUM(report.working_time) from report
  1485. where report.creator_id=us.id
  1486. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1487. as workingTime
  1488. from user us
  1489. left join department dp on dp.department_id=us.department_id
  1490. where us.company_id=#{companyId}
  1491. 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)
  1492. <if test="userId!=null and userId!=''">
  1493. and us.id=#{userId}
  1494. </if>
  1495. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1496. and us.department_id in
  1497. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1498. #{item}
  1499. </foreach>
  1500. </if>
  1501. <if test="deptIds!=null and deptIds.size()>0">
  1502. and us.department_id in
  1503. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1504. #{item}
  1505. </foreach>
  1506. </if>
  1507. group by us.id
  1508. order by us.department_id)as total
  1509. </select>
  1510. <!-- 分页查询部门参与项目情况-->
  1511. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1512. SELECT department.department_id deptId,
  1513. department_name deptName,
  1514. (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,
  1515. pro.projectCount projectCount,
  1516. pro.centerCount centerCount,
  1517. pcon.peopleCount peopleCount
  1518. FROM department
  1519. LEFT JOIN (
  1520. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1521. COUNT(DISTINCT(r.degree_id)) centerCount
  1522. FROM report
  1523. LEFT JOIN report r
  1524. ON report.id = r.id AND r.degree_id != -1
  1525. LEFT JOIN `user`
  1526. ON report.creator_id = user.id
  1527. WHERE report.state = 1
  1528. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1529. GROUP BY dept_id
  1530. ) pro
  1531. on pro.dept_id = department.department_id
  1532. LEFT JOIN (
  1533. SELECT dept_id,sum(p.con) peopleCount
  1534. FROM (
  1535. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1536. LEFT JOIN `user`
  1537. ON report.creator_id = user.id
  1538. WHERE report.state = 1
  1539. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1540. GROUP BY report.creator_id,dept_id
  1541. ) p GROUP BY p.dept_id
  1542. ) pcon
  1543. ON pcon.dept_id = department.department_id
  1544. WHERE department.company_id = #{companyId}
  1545. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1546. and department.department_id in
  1547. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1548. #{item}
  1549. </foreach>
  1550. </if>
  1551. <if test="deptIds!=null and deptIds.size()>0">
  1552. and department.department_id in
  1553. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1554. #{item}
  1555. </foreach>
  1556. </if>
  1557. <if test="size!=null and start!=null">
  1558. limit #{start},#{size}
  1559. </if>
  1560. </select>
  1561. <!--获取按项目分组的工时成本-->
  1562. <select id="getExportDegreeCost" resultType="java.util.Map">
  1563. 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
  1564. FROM project AS a
  1565. LEFT JOIN report AS b ON b.project_id = a.id
  1566. JOIN user AS c ON b.creator_id = c.id
  1567. WHERE a.company_id = #{companyId}
  1568. <if test="projectId != null">
  1569. AND a.id = #{projectId}
  1570. </if>
  1571. <if test="startDate != null and endDate != null">
  1572. AND b.create_date between #{startDate} and #{endDate}
  1573. </if>
  1574. <choose>
  1575. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1576. and b.dept_id in
  1577. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1578. #{item}
  1579. </foreach>
  1580. </when>
  1581. <otherwise>
  1582. <if test="deptIds!=null and deptIds.size()>0">
  1583. and (b.dept_id in
  1584. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1585. #{item}
  1586. </foreach>
  1587. <if test="deptRelatedProjectIds.size() > 0">
  1588. or a.id in
  1589. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  1590. #{pid}
  1591. </foreach>
  1592. </if>
  1593. )
  1594. </if>
  1595. </otherwise>
  1596. </choose>
  1597. AND b.state = 1
  1598. GROUP BY a.id
  1599. ORDER BY a.id ASC
  1600. </select>
  1601. <!--获取某个项目每个维度分别需要的工时-->
  1602. <select id="getDegreeDetailCost" resultType="java.util.Map">
  1603. 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
  1604. FROM report AS a
  1605. JOIN user AS b ON a.creator_id = b.id
  1606. left join department on department.department_id = a.dept_id
  1607. left join report_extra_degree as r on a.degree_id = r.id
  1608. WHERE a.company_id=#{companyId}
  1609. <if test="curProjectId != null">
  1610. and a.project_id = #{curProjectId}
  1611. </if>
  1612. <if test="projectId != null">
  1613. and a.project_id = #{projectId}
  1614. </if>
  1615. <if test="startDate != null and endDate != null">
  1616. AND a.create_date between #{startDate} and #{endDate}
  1617. </if>
  1618. <choose>
  1619. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1620. and a.dept_id in
  1621. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1622. #{item}
  1623. </foreach>
  1624. </when>
  1625. <otherwise>
  1626. <if test="deptIds!=null and deptIds.size()>0">
  1627. and a.dept_id in
  1628. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1629. #{item}
  1630. </foreach>
  1631. </if>
  1632. </otherwise>
  1633. </choose>
  1634. GROUP BY a.project_id,b.id,a.degree_id
  1635. ORDER BY b.id,a.degree_id ASC
  1636. </select>
  1637. <select id="selectNearProject" resultType="com.management.platform.entity.Project">
  1638. select * from project
  1639. where status = 1 and id in (
  1640. SELECT project_id
  1641. from (
  1642. SELECT project_id
  1643. FROM (
  1644. SELECT DISTINCT *
  1645. FROM report
  1646. WHERE creator_id = #{userId}
  1647. order by create_time
  1648. DESC
  1649. ) p1
  1650. GROUP BY project_id
  1651. order by create_time
  1652. DESC
  1653. LIMIT 3
  1654. ) p2
  1655. )
  1656. </select>
  1657. <select id="getFTEData" resultType="java.util.Map">
  1658. SELECT u.id,u.name userName,d.department_name as departmentName,d.corpwx_deptid as wxdeptId,u.corpwx_userid as wxUserId,IF(u.plate1 IS NULL OR u.plate1='' ,'无',u.plate1) as area,IFNULL(r.projectName,'') as projectName,IFNULL(r.projectCode,'') as projectCode,IFNULL(r.workTime,0) as workTime
  1659. FROM `user` u
  1660. LEFT JOIN department d on u.department_id=d.department_id
  1661. LEFT JOIN (
  1662. SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
  1663. FROM report
  1664. LEFT JOIN project p
  1665. ON report.project_id = p.id
  1666. LEFT JOIN `user`
  1667. ON user.id = report.creator_id
  1668. WHERE report.state = 1
  1669. AND p.is_public = 0
  1670. AND report.company_id=#{companyId}
  1671. AND
  1672. (
  1673. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate} and user.inactive_date is not null AND user.inactive_date &lt; #{endDate}
  1674. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1675. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1676. and
  1677. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1678. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1679. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1680. and
  1681. IF(user.inactive_date is not null AND user.inactive_date &lt; #{endDate}
  1682. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1683. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1684. )
  1685. GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
  1686. ) r
  1687. ON u.id = r.creator_id
  1688. WHERE u.company_id=#{companyId}
  1689. AND (workTime>0 OR u.`is_active`=1)
  1690. <if test="area!=null and area != '' ">
  1691. and u.plate1 = #{area}
  1692. </if>
  1693. <if test="userId!=null and userId != '' ">
  1694. and u.id = #{userId}
  1695. </if>
  1696. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1697. and u.department_id in
  1698. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1699. #{item}
  1700. </foreach>
  1701. </if>
  1702. <if test="deptIds!=null and deptIds.size()>0">
  1703. and u.department_id in
  1704. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1705. #{item}
  1706. </foreach>
  1707. </if>
  1708. <if test="sortProp!=null and sortProp!=''">
  1709. <choose>
  1710. <when test="sortOrder==0">
  1711. order by id desc
  1712. </when>
  1713. <otherwise>
  1714. order by id
  1715. </otherwise>
  1716. </choose>
  1717. </if>
  1718. <if test="start!=null and size!=null">
  1719. limit #{start},#{size}
  1720. </if>
  1721. </select>
  1722. <!--获取查询者所在公司每个项目的工时成本-->
  1723. <select id="getTimeCostByToken" resultType="java.util.Map">
  1724. 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,c.job_number as userJobNumber,d.department_name as departmentName
  1725. FROM project AS a
  1726. LEFT JOIN report AS b ON b.project_id = a.id
  1727. JOIN user AS c ON b.creator_id = c.id
  1728. JOIN department d on d.department_id=c.department_id
  1729. WHERE a.company_id = #{companyId}
  1730. <if test="startDate != null and endDate != null">
  1731. AND b.create_date between #{startDate} and #{endDate}
  1732. </if>
  1733. AND b.state = 1
  1734. GROUP BY a.id,b.creator_id
  1735. ORDER BY a.id ASC
  1736. </select>
  1737. <!--获取员工的项目分类工时统计数据 -->
  1738. <select id="getMembProjectCateTime" resultType="com.management.platform.entity.vo.UserCateTimeVo">
  1739. SELECT user.id AS userId,user.plate1 as plate1,user.plate2 as plate2,user.plate3 as plate3,user.plate4 as plate4,user.plate5 as plate5, user.`name`, project.`category`, project.`category_name` AS categoryName, SUM(report.`working_time`) AS workingTime
  1740. FROM report
  1741. LEFT JOIN `user` ON user.id = report.`creator_id`
  1742. LEFT JOIN project ON project.id = report.`project_id`
  1743. WHERE report.`company_id` = #{companyId}
  1744. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  1745. AND report.state = 1
  1746. <if test="departmentId!=null">
  1747. AND user.department_id=#{departmentId}
  1748. </if>
  1749. <if test="subUserCustomName!=null and subUserCustomName!='' and plateString!=null">
  1750. <choose>
  1751. <when test="plateString==1">
  1752. AND user.plate1=#{subUserCustomName}
  1753. </when>
  1754. <when test="plateString==2">
  1755. AND user.plate2=#{subUserCustomName}
  1756. </when>
  1757. <when test="plateString==3">
  1758. AND user.plate3=#{subUserCustomName}
  1759. </when>
  1760. <when test="plateString==4">
  1761. AND user.plate4=#{subUserCustomName}
  1762. </when>
  1763. <otherwise>
  1764. AND user.plate5=#{subUserCustomName}
  1765. </otherwise>
  1766. </choose>
  1767. </if>
  1768. GROUP BY user.id, project.`category`
  1769. </select>
  1770. <select id="userProjectProcessList" resultType="java.util.Map">
  1771. select d.department_name as departmentName,d.corpwx_deptid as corpwxDeptId,u.corpwx_userid as corpwxUserId,u.name as userName,u.job_number as jobNumber,p.project_name as projectName,p.project_code as projectCode,
  1772. IFNULL(IFNULL(SUM(te.plan_hours),0)-IFNULL((select SUM(working_time) from report where task_id=te.task_id and state=1),0),0)as residueTime
  1773. from task_executor te
  1774. left join user u on u.id=te.executor_id
  1775. left join department d on d.department_id=u.department_id
  1776. left join project p on p.id=te.project_id
  1777. where u.company_id=#{companyId} and te.project_id is not null
  1778. <if test="deptId!=null">
  1779. and d.department_id=#{deptId}
  1780. </if>
  1781. <if test="userId!=null and userId!=''">
  1782. and u.id=#{userId}
  1783. </if>
  1784. <if test="projectId!=null">
  1785. and p.id=#{projectId}
  1786. </if>
  1787. <if test="list!=null and list.size()>0">
  1788. and d.department_id in
  1789. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1790. #{item}
  1791. </foreach>
  1792. </if>
  1793. <if test="listSecond!=null and listSecond.size()>0">
  1794. and d.department_id in
  1795. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1796. #{item}
  1797. </foreach>
  1798. </if>
  1799. group by te.executor_id,te.project_id
  1800. order by d.department_id,u.id
  1801. <if test="start!=null and size!=null">
  1802. limit #{start},#{size}
  1803. </if>
  1804. </select>
  1805. <select id="userProjectProcessCount" resultType="java.lang.Long">
  1806. select count(1) from (
  1807. select d.department_name as departmentName
  1808. from task_executor te
  1809. left join user u on u.id=te.executor_id
  1810. left join department d on d.department_id=u.department_id
  1811. left join project p on p.id=te.project_id
  1812. where u.company_id=#{companyId} and te.project_id is not null
  1813. <if test="deptId!=null">
  1814. and d.department_id=#{deptId}
  1815. </if>
  1816. <if test="userId!=null and userId!=''">
  1817. and u.id=#{userId}
  1818. </if>
  1819. <if test="projectId!=null">
  1820. and p.id=#{projectId}
  1821. </if>
  1822. <if test="list!=null and list.size()>0">
  1823. and d.department_id in
  1824. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1825. #{item}
  1826. </foreach>
  1827. </if>
  1828. <if test="listSecond!=null and listSecond.size()>0">
  1829. and d.department_id in
  1830. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1831. #{item}
  1832. </foreach>
  1833. </if>
  1834. group by te.executor_id,te.project_id
  1835. ) as total
  1836. </select>
  1837. <select id="groupExpendProcessList" resultType="java.util.Map">
  1838. SELECT p.project_name AS projectName,p.id AS projectId,tg.id AS groupId,d.department_name,d.department_id AS deptId,d.corpwx_deptid AS corpwxDeptId,tg.name AS groupName,
  1839. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) as normalHour,IFNULL(r.overHour,0) as overHour,
  1840. IFNULL(tg.first_man_day*8,0) AS planHour,IFNULL((SELECT SUM(change_man_day) FROM `group_budget_review` WHERE group_id=tg.`id` AND `status`=1),0) AS afterSetPlanHour
  1841. FROM task_executor te
  1842. LEFT JOIN task t ON t.id=te.task_id
  1843. LEFT JOIN user u ON te.executor_id=u.id
  1844. LEFT JOIN task_group tg ON tg.id=t.group_id
  1845. LEFT JOIN project p ON p.id=tg.project_id
  1846. LEFT JOIN department d ON d.department_id=u.department_id
  1847. LEFT JOIN (
  1848. SELECT SUM(working_time) AS realHour,SUM(cost) AS realCost,(SUM(working_time)-SUM(overtime_hours)) AS normalHour,SUM(overtime_hours) AS overHour,group_id,dept_id
  1849. FROM report WHERE create_date BETWEEN #{startDate} AND #{endDate} AND state=1 AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id,dept_id) r ON r.group_id=tg.`id` and r.dept_id=u.department_id
  1850. WHERE u.company_id=#{companyId}
  1851. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1852. <if test="userId!=null and userId!=''">
  1853. and t.executor_id=#{userId}
  1854. </if>
  1855. GROUP BY p.id,tg.id,d.department_id ORDER BY p.id,d.department_id
  1856. </select>
  1857. <select id="projectExpendProcessList" resultType="java.util.Map">
  1858. select p.id AS projectId,p.project_name as projectName,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate,pc.name as categoryName,p.project_code as projectCode,IFNULL(SUM(te.plan_hours),0) as planHour,
  1859. IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realHour, IFNULL((select SUM(cost) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realCost,
  1860. IFNULL(IFNULL(SUM(te.plan_hours),0)-IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0),0) as residueHour,
  1861. GROUP_CONCAT(CONCAT_WS('|',te.executor_name,IFNULL((select SUM(working_time) from report where creator_id=te.executor_id and project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0))) as executorString
  1862. from task_executor te
  1863. left join user u on u.id=te.executor_id
  1864. left join department d on u.department_id=d.department_id
  1865. left join task t on t.id=te.task_id
  1866. left join project p on p.id=t.project_id
  1867. left join project_category pc on pc.id=p.category
  1868. where u.company_id=#{companyId} and te.project_id is not null and pc.name in ('报价项目','售后报价项目','售后工程项目','工程项目')
  1869. <if test="projectId!=null">
  1870. and p.id=#{projectId}
  1871. </if>
  1872. <if test="userId!=null and userId!=''">
  1873. and FIND_IN_SET(#{userId},t.executor_id)
  1874. </if>
  1875. <if test="categoryId!=null">
  1876. and pc.id=#{categoryId}
  1877. </if>
  1878. <if test="list!=null and list.size()>0">
  1879. and d.department_id in
  1880. <foreach collection="list" open="(" close=")" separator="," item="item">
  1881. #{item}
  1882. </foreach>
  1883. </if>
  1884. group by t.project_id
  1885. <if test="start!=null and size!=null">
  1886. limit #{start},#{size}
  1887. </if>
  1888. </select>
  1889. <select id="projectExpendProcessListCount" resultType="java.lang.Long">
  1890. select count(1) from (
  1891. select p.project_name as projectName
  1892. from task_executor te
  1893. left join user u on u.id=te.executor_id
  1894. left join department d on u.department_id=d.department_id
  1895. left join task t on t.id=te.task_id
  1896. left join project p on p.id=t.project_id
  1897. left join project_category pc on pc.id=p.category
  1898. where u.company_id=#{companyId} and te.project_id is not null and pc.name in ('报价项目','售后报价项目','售后工程项目','工程项目')
  1899. <if test="projectId!=null">
  1900. and p.id=#{projectId}
  1901. </if>
  1902. <if test="userId!=null and userId!=''">
  1903. and te.executor_id=#{userId}
  1904. </if>
  1905. <if test="categoryId!=null">
  1906. and pc.id=#{categoryId}
  1907. </if>
  1908. <if test="list!=null and list.size()>0">
  1909. and d.department_id in
  1910. <foreach collection="list" open="(" close=")" separator="," item="item">
  1911. #{item}
  1912. </foreach>
  1913. </if>
  1914. group by t.project_id
  1915. ) as total
  1916. </select>
  1917. <select id="userTaskProcessList" resultType="java.util.Map">
  1918. select d.department_name as departmentName,d.corpwx_deptid as corpwxDeptId,u.corpwx_userid as corpwxUserId,t.name as taskName,IFNULL(t.plan_hours,0) as planHour,u.name as userName,u.job_number as jobNumber,p.project_name as projectName,p.project_code as projectCode,
  1919. IFNULL((select SUM(working_time) from report where task_id=te.task_id and state=1),0)as consumeTime,IF((IFNULL(t.plan_hours,0)-IFNULL((SELECT SUM(working_time) FROM report WHERE task_id=te.task_id AND state=1),0))&lt;0,0,(IFNULL(t.plan_hours,0)-IFNULL((SELECT SUM(working_time) FROM report WHERE task_id=te.task_id AND state=1),0))) AS residue
  1920. ,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate
  1921. from task_executor te
  1922. left join user u on u.id=te.executor_id
  1923. left join department d on d.department_id=u.department_id
  1924. left join project p on p.id=te.project_id
  1925. left join task t on te.task_id=t.id
  1926. where u.company_id=#{companyId} and te.project_id is not null
  1927. <if test="deptId!=null">
  1928. and d.department_id=#{deptId}
  1929. </if>
  1930. <if test="userId!=null and userId!=''">
  1931. and u.id=#{userId}
  1932. </if>
  1933. <if test="projectId!=null">
  1934. and p.id=#{projectId}
  1935. </if>
  1936. <if test="list!=null and list.size()>0">
  1937. and d.department_id in
  1938. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1939. #{item}
  1940. </foreach>
  1941. </if>
  1942. <if test="listSecond!=null and listSecond.size()>0">
  1943. and d.department_id in
  1944. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1945. #{item}
  1946. </foreach>
  1947. </if>
  1948. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  1949. and ((t.start_date between #{startDate} and #{endDate})
  1950. or
  1951. (t.end_date between #{startDate} and #{endDate}))
  1952. </if>
  1953. group by te.executor_id,t.id
  1954. order by d.department_id,u.id
  1955. <if test="start!=null and size!=null">
  1956. limit #{start},#{size}
  1957. </if>
  1958. </select>
  1959. <select id="userTaskProcessListCount" resultType="java.lang.Long">
  1960. select count(1) from (
  1961. select d.department_name as departmentName
  1962. from task_executor te
  1963. left join user u on u.id=te.executor_id
  1964. left join department d on d.department_id=u.department_id
  1965. left join project p on p.id=te.project_id
  1966. left join task t on te.task_id=t.id
  1967. where u.company_id=#{companyId} and te.project_id is not null
  1968. <if test="deptId!=null">
  1969. and d.department_id=#{deptId}
  1970. </if>
  1971. <if test="userId!=null and userId!=''">
  1972. and u.id=#{userId}
  1973. </if>
  1974. <if test="projectId!=null">
  1975. and p.id=#{projectId}
  1976. </if>
  1977. <if test="list!=null and list.size()>0">
  1978. and d.department_id in
  1979. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1980. #{item}
  1981. </foreach>
  1982. </if>
  1983. <if test="listSecond!=null and listSecond.size()>0">
  1984. and d.department_id in
  1985. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1986. #{item}
  1987. </foreach>
  1988. </if>
  1989. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  1990. and ((t.start_date between #{startDate} and #{endDate})
  1991. or
  1992. (t.end_date between #{startDate} and #{endDate}))
  1993. </if>
  1994. group by te.executor_id,t.id
  1995. order by d.department_id,u.id
  1996. ) as total
  1997. </select>
  1998. </mapper>