ProjectMapper.xml 95 KB

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