ProjectMapper.xml 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.management.platform.mapper.ProjectMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.Project">
  6. <id column="id" property="id" />
  7. <result column="project_name" property="projectName" />
  8. <result column="company_id" property="companyId" />
  9. <result column="project_code" property="projectCode" />
  10. <result column="incharger_id" property="inchargerId" />
  11. <result column="plan_start_date" property="planStartDate" />
  12. <result column="plan_end_date" property="planEndDate" />
  13. <result column="progress" property="progress" />
  14. <result column="level" property="level" />
  15. <result column="status" property="status" />
  16. <result column="finish_date" property="finishDate" />
  17. <result column="creator_id" property="creatorId" />
  18. <result column="creator_name" property="creatorName" />
  19. <result column="create_date" property="createDate" />
  20. <result column="contract_amount" property="contractAmount" />
  21. <result column="budget" property="budget" />
  22. <result column="base_man" property="baseMan" />
  23. <result column="base_outsourcing" property="baseOutsourcing" />
  24. <result column="base_risk1" property="baseRisk1" />
  25. <result column="base_risk2" property="baseRisk2" />
  26. <result column="base_fee" property="baseFee" />
  27. <result column="fee_man" property="feeMan" />
  28. <result column="customer_id" property="customerId" />
  29. <result column="customer_name" property="customerName" />
  30. <result column="is_public" property="isPublic" />
  31. <result column="associate_degrees" property="associateDegrees" />
  32. <result column="associate_degree_names" property="associateDegreeNames" />
  33. <result column="task_gp_incharge" property="taskGpIncharge" />
  34. <result column="category" property="category" />
  35. <result column="category_name" property="categoryName" />
  36. <result column="project_desc" property="projectDesc" />
  37. <result column="project_main_id" property="projectMainId" />
  38. <result column="project_main_name" property="projectMainName" />
  39. <result column="provider_ids" property="providerIds" />
  40. <result column="provider_names" property="providerNames" />
  41. <result column="current_stage_id" property="currentStageId" />
  42. <result column="current_stage_name" property="currentStageName" />
  43. <result column="output_value" property="outputValue" />
  44. <result column="dept_id" property="deptId" />
  45. <result column="dept_cascade" property="deptCascade" />
  46. <result column="bu_id" property="buId" />
  47. <result column="man_day" property="manDay" />
  48. <result column="man_day_start_date" property="manDayStartDate" />
  49. <result column="plate1" property="plate1" />
  50. <result column="plate2" property="plate2" />
  51. <result column="plate3" property="plate3" />
  52. <result column="plate4" property="plate4" />
  53. <result column="plate5" property="plate5" />
  54. <result column="plate6" property="plate6" />
  55. <result column="plate7" property="plate7" />
  56. <result column="plate8" property="plate8" />
  57. <result column="plate9" property="plate9" />
  58. <result column="plate10" property="plate10" />
  59. <result column="from_outside" property="fromOutside" />
  60. <result column="approve_id" property="approveId" />
  61. <result column="reviwer_id" property="reviwerId" />
  62. </resultMap>
  63. <!-- 通用查询结果列 -->
  64. <sql id="Base_Column_List">
  65. id, project_name, company_id, project_code, incharger_id, plan_start_date, plan_end_date, progress, level, status, finish_date, creator_id, creator_name, create_date, contract_amount, budget, base_man, base_outsourcing, base_risk1, base_risk2, base_fee, fee_man, customer_id, customer_name, is_public, associate_degrees, associate_degree_names, task_gp_incharge, category, category_name, project_desc, project_main_id, project_main_name, provider_ids, provider_names, current_stage_id, current_stage_name, output_value, dept_id, dept_cascade, bu_id, man_day, man_day_start_date, plate1, plate2, plate3, plate4, plate5, plate6, plate7, plate8, plate9, plate10, from_outside, approve_id, reviwer_id
  66. </sql>
  67. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  68. <result column="id" property="id" />
  69. <result column="project_name" property="projectName" />
  70. <result column="project_code" property="projectCode" />
  71. <result column="startDate" property="startDate" />
  72. <result column="endDate" property="endDate" />
  73. <collection property="stageCostList" javaType="java.util.ArrayList"
  74. ofType="com.management.platform.entity.vo.StageCost"
  75. select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
  76. </resultMap>
  77. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  78. <result column="customer_id" property="customerId" />
  79. <result column="customer_name" property="customerName" />
  80. <result column="contract_amount" property="contractAmount" />
  81. <result column="fee_man" property="feeMan" />
  82. <result column="project_num" property="projectNum" />
  83. <result column="project_ids" property="projectIds" />
  84. <result column="project_names" property="projectNames" />
  85. </resultMap>
  86. <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
  87. select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
  88. from project
  89. where company_id = #{companyId}
  90. <if test="projectId != null">
  91. and id = #{projectId}
  92. </if>
  93. <if test="inchargerId!=null">
  94. and incharger_id = #{inchargerId}
  95. </if>
  96. order by is_public desc, id asc
  97. <if test="startIndex != null">
  98. limit ${startIndex}, ${endIndex}
  99. </if>
  100. </select>
  101. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  102. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  103. IFNULL(SUM(report.`working_time`), 0) AS working_time,
  104. 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
  105. FROM report
  106. left join project p on p.id=report.`project_id`
  107. where report.state = 1
  108. <if test="inchargerId!=null">
  109. and p.incharger_id = #{inchargerId}
  110. </if>
  111. <if test="projectIds!=null and projectIds.size()>0">
  112. and p.id in
  113. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  114. #{item}
  115. </foreach>
  116. </if>
  117. and report.create_date &gt;= #{startDate}
  118. and report.create_date &lt;= #{endDate}
  119. GROUP BY report.`project_id`,report.stage
  120. </select>
  121. <!--获取查询者所在公司每个项目的工时成本-->
  122. <select id="getParticipatedProject" resultType="java.util.Map">
  123. 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
  124. FROM project
  125. WHERE id IN (
  126. SELECT project_id
  127. FROM participation
  128. WHERE user_id = #{userId}
  129. ) or incharger_id = #{userId}
  130. or creator_id = #{userId}
  131. or (is_public = 1 and company_id = #{companyId})
  132. ORDER BY is_public DESC, id DESC
  133. </select>
  134. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  135. 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
  136. FROM project
  137. WHERE status = 1 and (id IN (
  138. SELECT project_id
  139. FROM participation
  140. WHERE user_id = #{userId}
  141. )
  142. or (is_public = 1 and company_id = #{companyId}))
  143. ORDER BY is_public DESC, id ASC
  144. </select>
  145. <!--获取查询者所在公司每个项目的工时成本-->
  146. <select id="getTimeCost" resultType="java.util.Map">
  147. 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
  148. FROM project AS a
  149. LEFT JOIN report AS b ON b.project_id = a.id
  150. JOIN user AS c ON b.creator_id = c.id
  151. WHERE a.company_id = #{companyId}
  152. <if test="projectId != null">
  153. AND a.id = #{projectId}
  154. </if>
  155. <if test="categoryId != null">
  156. AND a.category = #{categoryId}
  157. </if>
  158. <if test="projectIds != null">
  159. and a.id in
  160. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  161. #{item}
  162. </foreach>
  163. </if>
  164. <if test="userIdList != null and userIdList.size()>0">
  165. AND b.creator_id in
  166. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  167. #{item}
  168. </foreach>
  169. </if>
  170. <if test="startDate != null and endDate != null">
  171. AND b.create_date between #{startDate} and #{endDate}
  172. </if>
  173. <choose>
  174. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  175. and b.dept_id in
  176. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  177. #{item}
  178. </foreach>
  179. </when>
  180. <otherwise>
  181. <if test="deptIds!=null and deptIds.size()>0">
  182. and (b.dept_id in
  183. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  184. #{item}
  185. </foreach>
  186. <if test="deptRelatedProjectIds.size() > 0">
  187. or a.id in
  188. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  189. #{pid}
  190. </foreach>
  191. </if>
  192. <if test="inchargeUserIds != null and inchargeUserIds.size()>0">
  193. OR a.`incharger_id` IN
  194. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  195. #{pid}
  196. </foreach>
  197. OR b.`group_id` IN(SELECT id FROM task_group WHERE incharger_id IN
  198. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  199. #{pid}
  200. </foreach>
  201. )
  202. </if>
  203. )
  204. </if>
  205. </otherwise>
  206. </choose>
  207. AND b.state = 1
  208. GROUP BY a.id
  209. ORDER BY a.id ASC
  210. </select>
  211. <!--获取查询者所在公司每个子项目的工时成本-->
  212. <select id="getSubProjectTimeCost" resultType="java.util.Map">
  213. 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
  214. from sub_project a
  215. left join project b on b.id=a.project_id
  216. left join report c on c.sub_project_id=a.id
  217. where a.company_id=#{companyId}
  218. and c.state = 1
  219. <if test="startDate != null and endDate != null">
  220. and c.create_date between #{startDate} and #{endDate}
  221. </if>
  222. <if test="projectId!=null">
  223. and a.project_id=#{projectId}
  224. </if>
  225. <if test="inchagerIds!=null and inchagerIds.size()>0">
  226. and b.id in
  227. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  228. #{item}
  229. </foreach>
  230. </if>
  231. group by b.id,a.id
  232. <if test="start!=null and size!=null">
  233. limit #{start},#{size}
  234. </if>
  235. </select>
  236. <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
  237. 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
  238. from sub_project a
  239. left join project b on b.id=a.project_id
  240. left join report c on c.sub_project_id=a.id
  241. where a.company_id=#{companyId}
  242. and c.state = 1
  243. <if test="startDate != null and endDate != null">
  244. and c.create_date between #{startDate} and #{endDate}
  245. </if>
  246. <if test="projectId!=null">
  247. and a.project_id=#{projectId}
  248. </if>
  249. <if test="inchagerIds!=null and inchagerIds.size()>0">
  250. and b.id in
  251. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  252. #{item}
  253. </foreach>
  254. </if>
  255. group by b.id,a.id
  256. <if test="start!=null and size!=null">
  257. limit #{start},#{size}
  258. </if>) as total
  259. </select>
  260. <!--获取查询者所在公司每个项目的工时成本-->
  261. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  262. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'无主项目') as mainProjectName
  263. FROM project AS a
  264. LEFT JOIN report AS b ON b.project_id = a.id
  265. JOIN user AS c ON b.creator_id = c.id
  266. LEFT JOIN project_main pm on pm.id=a.project_main_id
  267. WHERE a.company_id = #{companyId}
  268. <if test="projectId != null">
  269. AND a.id = #{projectId}
  270. </if>
  271. <if test="startDate != null and endDate != null">
  272. AND b.create_date between #{startDate} and #{endDate}
  273. </if>
  274. <if test="deptIds!=null and deptIds.size()>0">
  275. and b.dept_id in
  276. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  277. #{item}
  278. </foreach>
  279. </if>
  280. AND b.state = 1
  281. GROUP BY a.project_main_id
  282. ORDER BY a.id ASC
  283. </select>
  284. <!--获取查询者所在公司每个项目分类的工时成本-->
  285. <select id="getTimeCostByCategory" resultType="java.util.Map">
  286. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  287. FROM project AS a
  288. LEFT JOIN report AS b ON b.project_id = a.id
  289. JOIN user AS c ON b.creator_id = c.id
  290. WHERE a.company_id = #{companyId}
  291. <if test="projectCategoryId != null">
  292. AND a.category = #{projectCategoryId}
  293. </if>
  294. <if test="projectIds != null">
  295. and a.id in
  296. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  297. #{item}
  298. </foreach>
  299. </if>
  300. <if test="userIdList != null and userIdList.size()>0">
  301. AND b.creator_id in
  302. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  303. #{item}
  304. </foreach>
  305. </if>
  306. <if test="startDate != null and endDate != null">
  307. AND b.create_date between #{startDate} and #{endDate}
  308. </if>
  309. <if test="deptIds!=null and deptIds.size()>0">
  310. and b.dept_id in
  311. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  312. #{item}
  313. </foreach>
  314. </if>
  315. AND b.state = 1
  316. GROUP BY a.category
  317. ORDER BY a.category ASC
  318. </select>
  319. <!--获取自定义数值的项目统计 -->
  320. <select id="getCustomDataSum" resultType="java.util.Map">
  321. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  322. FROM project AS a
  323. LEFT JOIN report AS b ON b.project_id = a.id
  324. JOIN user AS c ON b.creator_id = c.id
  325. WHERE a.company_id = #{companyId}
  326. <if test="projectId != null">
  327. AND a.id = #{projectId}
  328. </if>
  329. <if test="userId != null">
  330. AND b.creator_id = #{userId}
  331. </if>
  332. <if test="startDate != null and endDate != null">
  333. AND b.create_date between #{startDate} and #{endDate}
  334. </if>
  335. AND b.state = 1
  336. GROUP BY a.id
  337. having IFNULL(SUM(b.custom_data), 0) > 0
  338. ORDER BY SUM(b.custom_data) DESC
  339. </select>
  340. <!--获取日报的人员月度工时 -->
  341. <select id="getTimeCostReport" resultType="java.util.Map">
  342. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  343. FROM report AS a
  344. LEFT JOIN project AS b ON a.project_id = b.id
  345. LEFT JOIN user AS c ON a.creator_id = c.id
  346. WHERE b.company_id = #{companyId}
  347. <if test="projectId != null">
  348. AND b.id = #{projectId}
  349. </if>
  350. <if test="startDate != null and endDate != null">
  351. AND a.create_date between #{startDate} and #{endDate}
  352. </if>
  353. <if test="deptIds!=null and deptIds.size()>0">
  354. and a.dept_id in
  355. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  356. #{item}
  357. </foreach>
  358. </if>
  359. AND a.state = 1
  360. </select>
  361. <!--获取人员的月度总工时 -->
  362. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  363. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  364. FROM report AS a, user as b
  365. WHERE a.creator_id = b.id
  366. and b.company_id = #{companyId}
  367. <if test="startDate != null and endDate != null">
  368. AND a.create_date between #{startDate} and #{endDate}
  369. </if>
  370. AND a.state = 1
  371. group by a.creator_id
  372. </select>
  373. <!--获取某个项目每个人分别需要的工时-->
  374. <select id="getProjectCost" resultType="java.util.Map">
  375. 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,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  376. FROM report AS a
  377. JOIN user AS b ON a.creator_id = b.id
  378. left join department on department.department_id = a.dept_id
  379. WHERE a.company_id=#{companyId}
  380. <choose>
  381. <when test="stateKey!=null and stateKey==1">
  382. and a.state = 1
  383. </when>
  384. <otherwise>
  385. and (a.state = 1 or a.state =0)
  386. </otherwise>
  387. </choose>
  388. <if test="projectId != null">
  389. and a.project_id = #{projectId}
  390. </if>
  391. <if test="startDate != null and endDate != null">
  392. AND a.create_date between #{startDate} and #{endDate}
  393. </if>
  394. <if test="userIdList != null and userIdList.size()>0">
  395. AND a.creator_id in
  396. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  397. #{item}
  398. </foreach>
  399. </if>
  400. <choose>
  401. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  402. and a.dept_id in
  403. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  404. #{item}
  405. </foreach>
  406. </when>
  407. <otherwise>
  408. <if test="deptIds!=null and deptIds.size()>0">
  409. and a.dept_id in
  410. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  411. #{item}
  412. </foreach>
  413. </if>
  414. </otherwise>
  415. </choose>
  416. GROUP BY b.id
  417. <if test="withDept">
  418. , a.dept_id
  419. </if>
  420. ORDER BY b.id ASC
  421. <if test="withDept">
  422. , a.dept_id ASC
  423. </if>
  424. </select>
  425. <!--获取某个项目分类每个人分别需要的工时-->
  426. <select id="getProjectCostByCategory" resultType="java.util.Map">
  427. 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
  428. FROM report AS a
  429. JOIN user AS b ON a.creator_id = b.id
  430. left join department on department.department_id = a.dept_id
  431. left join project c on c.id=a.project_id
  432. WHERE a.company_id=#{companyId} and a.state = 1
  433. <if test="curProjectCategoryId != null">
  434. and c.category = #{curProjectCategoryId}
  435. </if>
  436. <if test="startDate != null and endDate != null">
  437. AND a.create_date between #{startDate} and #{endDate}
  438. </if>
  439. <if test="userId != null">
  440. AND a.creator_id = #{userId}
  441. </if>
  442. GROUP BY c.category, a.dept_id
  443. ORDER BY c.category ASC, a.dept_id ASC
  444. </select>
  445. <!--获取个人每个项目分别需要的工时-->
  446. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  447. 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
  448. FROM report AS a
  449. JOIN user AS b ON a.creator_id = b.id
  450. left join department on department.department_id = a.dept_id
  451. WHERE a.company_id=#{companyId} and a.state = 1
  452. <if test="projectId != null">
  453. and a.project_id = #{projectId}
  454. </if>
  455. <if test="startDate != null and endDate != null">
  456. AND a.create_date between #{startDate} and #{endDate}
  457. </if>
  458. <if test="userIdList != null and userIdList.size()>0">
  459. AND a.creator_id in
  460. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  461. #{item}
  462. </foreach>
  463. </if>
  464. <if test="deptIds!=null and deptIds.size()>0">
  465. and a.dept_id in
  466. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  467. #{item}
  468. </foreach>
  469. </if>
  470. GROUP BY b.id,a.project_id
  471. ORDER BY b.id ASC, a.dept_id ASC
  472. </select>
  473. <!--获取个人每个项目分类分别需要的工时-->
  474. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  475. 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
  476. FROM report AS a
  477. JOIN user AS b ON a.creator_id = b.id
  478. left join department on department.department_id = a.dept_id
  479. left join project c on c.id=a.project_id
  480. WHERE a.company_id=#{companyId} and a.state = 1
  481. <if test="projectCategoryId != null">
  482. and c.category = #{projectCategoryId}
  483. </if>
  484. <if test="startDate != null and endDate != null">
  485. AND a.create_date between #{startDate} and #{endDate}
  486. </if>
  487. <if test="userIdList != null and userIdList.size()>0">
  488. AND a.creator_id in
  489. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  490. #{item}
  491. </foreach>
  492. </if>
  493. <if test="deptIds!=null and deptIds.size()>0">
  494. and a.dept_id in
  495. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  496. #{item}
  497. </foreach>
  498. </if>
  499. GROUP BY b.id,c.category
  500. ORDER BY b.id ASC, a.dept_id ASC
  501. </select>
  502. <!-- 获取人员在日报填写的自定义数值 -->
  503. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  504. SELECT b.id as creatorId,
  505. b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
  506. FROM report AS a
  507. JOIN user AS b ON a.creator_id = b.id
  508. left join department on department.department_id = b.department_id
  509. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  510. <if test="startDate != null and endDate != null">
  511. AND a.create_date between #{startDate} and #{endDate}
  512. </if>
  513. <if test="projectId != null">
  514. AND a.project_id = #{projectId}
  515. </if>
  516. <if test="userId != null">
  517. AND a.creator_id = #{userId}
  518. </if>
  519. <if test="deptIds != null">
  520. AND department.department_id in
  521. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  522. #{item}
  523. </foreach>
  524. </if>
  525. group by b.id
  526. ORDER BY b.id ASC
  527. </select>
  528. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  529. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  530. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  531. FROM report AS a
  532. JOIN user AS b ON a.creator_id = b.id
  533. left join department on department.department_id = b.department_id
  534. left join project on project.id = a.project_id
  535. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  536. <if test="startDate != null and endDate != null">
  537. AND a.create_date between #{startDate} and #{endDate}
  538. </if>
  539. <if test="projectId != null">
  540. AND a.project_id = #{projectId}
  541. </if>
  542. <if test="userId != null">
  543. AND a.creator_id = #{userId}
  544. </if>
  545. ORDER BY a.create_date desc
  546. </select>
  547. <!--按照项目内的阶段名称分组统计工时-->
  548. <select id="getCostInStage" resultType="java.util.Map">
  549. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  550. FROM report AS a
  551. WHERE a.project_id = #{projectId}
  552. AND a.state = 1
  553. <if test="startDate != null and endDate != null">
  554. AND a.create_date between #{startDate} and #{endDate}
  555. </if>
  556. GROUP BY a.stage
  557. ORDER BY a.stage ASC
  558. </select>
  559. <!--按照项目内的阶段名称分组统计工时-->
  560. <select id="getCostByGroup" resultType="java.util.Map">
  561. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  562. FROM report AS a
  563. left join task_group tg on tg.id=a.group_id
  564. WHERE a.project_id = #{projectId}
  565. AND a.state = 1
  566. <if test="startDate != null and endDate != null">
  567. AND a.create_date between #{startDate} and #{endDate}
  568. </if>
  569. <if test="gpIds != null">
  570. AND a.group_id in
  571. <foreach collection="gpIds" open="(" separator="," close=")" item="item">
  572. #{item}
  573. </foreach>
  574. </if>
  575. GROUP BY a.group_id
  576. ORDER BY a.group_id ASC
  577. </select>
  578. <!--获取全部人员工时 -->
  579. <select id="getAllMembCost" resultType="java.util.Map">
  580. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  581. FROM user AS b
  582. left JOIN report AS a ON a.creator_id = b.id
  583. WHERE a.state = 1
  584. and b.company_id = #{companyId}
  585. <if test="startDate != null and endDate != null">
  586. AND a.create_date between #{startDate} and #{endDate}
  587. </if>
  588. <if test="projectId != null">
  589. AND a.project_id = #{projectId}
  590. </if>
  591. GROUP BY b.id
  592. ORDER BY b.id ASC
  593. </select>
  594. <!--分页获取项目成本 -->
  595. <select id="getAllProjectCost" resultType="java.util.Map">
  596. SELECT id, project_code as projectCode, project_name as projectName,budget,
  597. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  598. FROM project WHERE project.`company_id` = #{companyId}
  599. and (project.status &lt;&gt; 3 or project.status is null)
  600. <if test="projectId != null">
  601. and project.id = #{projectId}
  602. </if>
  603. <if test="inchagerIds!=null and inchagerIds.size()>0">
  604. and project.id in
  605. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  606. #{item}
  607. </foreach>
  608. </if>
  609. order by project.is_public desc, project.id asc
  610. <if test="pageStart != null and pageSize != null">
  611. LIMIT #{pageStart},#{pageSize}
  612. </if>
  613. </select>
  614. <!--分页获取项目收支平衡 -->
  615. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  616. SELECT project.id, project_code, project_name,contract_amount, IFNULL(contract.payment, 0) as payment,project_main.name as project_main_name,
  617. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  618. FROM project
  619. left join contract on contract.project_id = project.id
  620. left join project_main on project_main.id = project.project_main_id
  621. WHERE project.`company_id` = #{companyId}
  622. and (project.status &lt;&gt; 3 or project.status is null)
  623. <if test="projectId != null">
  624. and project.id = #{projectId}
  625. </if>
  626. <if test="projectMainId != null">
  627. and project.project_main_id = #{projectMainId}
  628. </if>
  629. <if test="inchagerIds!=null and inchagerIds.size()>0">
  630. and project.id in
  631. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  632. #{item}
  633. </foreach>
  634. </if>
  635. order by is_public desc, project.id asc
  636. <if test="pageStart != null and pageSize != null">
  637. LIMIT #{pageStart},#{pageSize}
  638. </if>
  639. </select>
  640. <select id="getProjectExpenseFee" resultType="java.util.Map">
  641. 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
  642. left join expense_sheet on expense_sheet.id = expense_item.`expense_id`
  643. left join expense_main_type on expense_main_type.id = expense_sheet.`type`
  644. WHERE expense_sheet.`company_id` = #{companyId} AND expense_sheet.id = expense_item.`expense_id`
  645. AND expense_sheet.status = 0
  646. and project_id in
  647. <foreach collection="projectIds" open="(" separator="," close=")" item="item">
  648. #{item}
  649. </foreach>
  650. GROUP BY project_id, expense_sheet.type
  651. </select>
  652. <!--分页获取客户项目的成本利润报表 -->
  653. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  654. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  655. SUM(contract_amount) AS contract_amount ,
  656. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man
  657. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  658. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  659. <if test="customerId!=null">
  660. and project.customer_id=#{customerId}
  661. </if>
  662. <if test="projectId!=null">
  663. and project.id=#{projectId}
  664. </if>
  665. GROUP BY customer_id
  666. <if test="pageStart != null and pageSize != null">
  667. LIMIT #{pageStart},#{pageSize}
  668. </if>
  669. </select>
  670. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  671. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  672. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  673. <if test="customerId!=null">
  674. and project.customer_id=#{customerId}
  675. </if>
  676. <if test="projectId!=null">
  677. and project.id=#{projectId}
  678. </if>
  679. </select>
  680. <!--分页获取项目收支平衡 -->
  681. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  682. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  683. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  684. FROM project WHERE project.`company_id` = #{companyId}
  685. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  686. #{item}
  687. </foreach>
  688. </select>
  689. <select id="getGanttData" resultType="java.util.Map">
  690. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  691. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  692. LEFT JOIN user ON user.id = participation.`user_id`
  693. LEFT JOIN project ON project.`id` = participation.`project_id`
  694. WHERE participation.`user_id` IN
  695. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  696. #{item}
  697. </foreach>
  698. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  699. ORDER BY participation.user_id, project.`plan_start_date`
  700. </select>
  701. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  702. 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,
  703. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  704. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId,
  705. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  706. FROM user
  707. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  708. left join task on task.id = task_executor.task_id
  709. LEFT JOIN project ON project.`id` = task.`project_id`
  710. WHERE user.`id` IN
  711. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  712. #{item}
  713. </foreach>
  714. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  715. and task.end_date is not null and task.task_plan =0
  716. AND project.`status` = 1
  717. ORDER BY user.id, task.start_date
  718. </select>
  719. <select id="getTaskPlanByProject" resultType="java.util.Map">
  720. 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,
  721. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId
  722. ,task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
  723. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  724. LEFT JOIN task ON task.project_id = project.id
  725. <if test="groupName !=null and groupName !='' ">
  726. LEFT JOIN task_group tg ON tg.project_id = project.id
  727. </if>
  728. WHERE project.company_id = #{companyId}
  729. <if test="projectIds != null">
  730. and project.`id` IN
  731. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  732. #{item}
  733. </foreach>
  734. </if>
  735. <if test="groupName !=null and groupName !='' ">
  736. and tg.name = #{groupName} and task.group_id=tg.id
  737. </if>
  738. <if test="taskType !=null ">
  739. and task.task_type = #{taskType}
  740. </if>
  741. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  742. and task.end_date is not null and task.task_plan =0
  743. AND project.`status` = 1
  744. ORDER BY project.id, task.start_date
  745. </select>
  746. <!--获取加班统计报表 -->
  747. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  748. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  749. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  750. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  751. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  752. <!-- left join project on project.id = report.project_id-->
  753. <!-- WHERE report.is_overtime = 1-->
  754. <!-- and report.`state` = 1-->
  755. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  756. <!-- AND user.`company_id` = #{companyId}-->
  757. <!-- <if test="projectId != null">-->
  758. <!-- AND report.`project_id` = #{projectId}-->
  759. <!-- </if>-->
  760. <!-- <if test="userId != null">-->
  761. <!-- AND report.`creator_id` = #{userId}-->
  762. <!-- </if>-->
  763. <!-- GROUP BY report.creator_id-->
  764. <!-- </select>-->
  765. <!-- 获取某个员工的某时间段内的加班详情 -->
  766. <select id="getOvertimeDetail" resultType="java.util.Map">
  767. SELECT report.id AS reportId,date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  768. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  769. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  770. project.project_name as projectName,project.project_code as projectCode,
  771. IFNULL(report.overtime_cost, 0) AS cost,
  772. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName,
  773. (CASE WHEN rwo.`write_off`=1 THEN 1 ELSE 0 END) AS writeOffValue,rwo.creator_name as writeOffUser,date_format(rwo.`create_time`, '%Y-%m-%d %H:%i:%s') as writeOffTime,rwo.reason as writeOffReason
  774. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  775. left join project on project.id = report.project_id
  776. left join report_extra_degree on report_extra_degree.id = report.degree_id
  777. left join department on department.department_id = report.dept_id
  778. LEFT JOIN report_write_off rwo ON rwo.`report_id`=report.`id`
  779. WHERE report.is_overtime = 1
  780. and report.`state` = 1
  781. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  782. AND user.`company_id` = #{companyId}
  783. <if test="projectId != null">
  784. AND report.`project_id` = #{projectId}
  785. </if>
  786. <if test="userId != null">
  787. AND report.`creator_id` = #{userId}
  788. </if>
  789. <if test="branchDepartment!=null and branchDepartment.size()>0">
  790. and report.dept_id in
  791. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  792. #{item}
  793. </foreach>
  794. </if>
  795. <if test="deptIds!=null and deptIds.size()>0">
  796. and report.dept_id in
  797. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  798. #{item}
  799. </foreach>
  800. </if>
  801. <if test="writeOffValue!=null">
  802. <choose>
  803. <when test="writeOffValue==1">
  804. and rwo.write_off=1
  805. </when>
  806. <otherwise>
  807. and (rwo.write_off is null or rwo.write_off=0)
  808. </otherwise>
  809. </choose>
  810. </if>
  811. order by user.create_time asc, report.create_date desc
  812. </select>
  813. <!--获取人员工时-->
  814. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  815. SELECT report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.dingding_userid as corpDdUserId,user.job_number as jobNumber,
  816. user.department_id As deptId,
  817. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  818. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  819. ifnull(SUM(report.`working_time`),0) AS workingTime,
  820. ifnull(SUM(report.`overtime_hours`),0) AS overtimeHours
  821. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  822. left join project on project.id = report.project_id
  823. WHERE
  824. report.`state` = 1
  825. AND user.`is_active` = 1
  826. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  827. AND user.`company_id` =#{companyId}
  828. <if test="userId!=null">
  829. and user.id=#{userId}
  830. </if>
  831. <if test="projectId!=null">
  832. and project.id=#{projectId}
  833. </if>
  834. <if test="branchDepartment!=null and branchDepartment.size()>0">
  835. and report.dept_id in
  836. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  837. #{item}
  838. </foreach>
  839. </if>
  840. <if test="deptIds!=null and deptIds.size()>0">
  841. and report.dept_id in
  842. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  843. #{item}
  844. </foreach>
  845. </if>
  846. group by user.id
  847. order by user.create_time asc, report.create_date desc
  848. <if test="start!=null and size!=null">
  849. limit #{start},#{size}
  850. </if>
  851. </select>
  852. <select id="findCountWithUser" resultType="java.lang.Long">
  853. select count(*)
  854. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  855. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  856. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  857. ifnull(SUM(report.`working_time`),0) AS workingTime
  858. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  859. left join project on project.id = report.project_id
  860. WHERE
  861. report.`state` = 1
  862. AND user.`is_active` = 1
  863. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  864. AND user.`company_id` =#{companyId}
  865. <if test="userId!=null">
  866. and user.id=#{userId}
  867. </if>
  868. <if test="projectId!=null">
  869. and project.id=#{projectId}
  870. </if>
  871. <if test="departmentId!=null">
  872. and report.dept_id=#{departmentId}
  873. </if>
  874. <if test="deptIds!=null and deptIds.size()>0">
  875. and report.dept_id in
  876. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  877. #{item}
  878. </foreach>
  879. </if>
  880. group by user.id
  881. order by user.create_time asc, report.create_date desc
  882. <if test="start!=null and size!=null">
  883. limit #{start},#{size}
  884. </if>) as total
  885. </select>
  886. <!--按照项目内的阶段名称分组统计工时-->
  887. <select id="getDegreeCost" resultType="java.util.Map">
  888. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
  889. FROM report AS a
  890. left join report_extra_degree b on b.id = a.degree_id
  891. WHERE
  892. a.state = 1
  893. and a.company_id = #{companyId}
  894. <if test="departmentIds!=null and departmentIds.size()>0">
  895. and a.dept_id in
  896. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  897. #{item}
  898. </foreach>
  899. </if>
  900. <if test="projectId != null">
  901. and a.project_id = #{projectId}
  902. </if>
  903. <if test="userId != null and userId!=''">
  904. and a.creator_id = #{userId}
  905. </if>
  906. <if test="startDate != null and endDate != null">
  907. AND a.create_date between #{startDate} and #{endDate}
  908. </if>
  909. GROUP BY a.degree_id
  910. ORDER BY a.degree_id ASC
  911. </select>
  912. <!--项目导出数据-->
  913. <select id="getExportData" resultType="java.util.HashMap" >
  914. 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,
  915. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  916. customer_name, associate_degree_names, provider_names,provider_ids
  917. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  918. LEFT JOIN participation c ON c.project_id = project.`id`
  919. LEFT JOIN user u ON u.id = c.user_id
  920. LEFT JOIN user d ON d.id = project.`incharger_id`
  921. WHERE project.`company_id` = #{companyId}
  922. <if test="userId != null" >
  923. and (project.creator_id = #{userId} or c.user_id = #{userId})
  924. </if>
  925. GROUP BY project.id
  926. </select>
  927. <!--按项目分组导出数据-->
  928. <select id="getExportGroupData" resultType="java.util.Map" >
  929. SELECT project_code AS projectCode,project_name AS projectName,task_group.`name` AS groupName,task_group.`incharger_id` AS inchargerId,
  930. GROUP_CONCAT(group_participator.`user_id`) AS participatorIds
  931. FROM task_group
  932. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  933. LEFT JOIN project ON task_group.project_id = project.id
  934. <if test="projectCategorySub!=null and projectCategorySub!=''">
  935. left join project_separate ps on ps.id=project.id
  936. </if>
  937. where project.company_id = #{companyId}
  938. <if test="projectCategorySub!=null and projectCategorySub!=''">
  939. and ps.project_category_sub=#{projectCategorySub}
  940. </if>
  941. GROUP BY task_group.id
  942. ORDER BY project_id
  943. </select>
  944. <!--分页获取项目工时成本预警表 -->
  945. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  946. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  947. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  948. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  949. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  950. AND project_id=project.id) AS costLimit,
  951. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  952. FROM project WHERE company_id=#{companyId}
  953. and (project.status &lt;&gt; 3 or project.status is null)
  954. <if test="projectId != null">
  955. and project.id = #{projectId}
  956. </if>
  957. <if test="pageStart != null and pageSize != null">
  958. LIMIT #{pageStart},#{pageSize}
  959. </if>
  960. </select>
  961. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  962. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  963. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  964. 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,
  965. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  966. 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,
  967. (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
  968. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  969. <if test="projectId != null">
  970. and project.id = #{projectId}
  971. </if>
  972. <if test="list!=null and list.size()>0">
  973. and project.id in
  974. <foreach collection="list" open="(" close=")" item="item" separator=",">
  975. #{item}
  976. </foreach>
  977. </if>
  978. <if test="pageStart != null and pageSize != null">
  979. LIMIT #{pageStart},#{pageSize}
  980. </if>
  981. </select>
  982. <select id="getWaitingReviewList" resultType="java.util.Map">
  983. <choose>
  984. <when test="stateKey==0">
  985. 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
  986. FROM report AS a
  987. left join user on user.id = a.creator_id
  988. JOIN project AS b ON a.project_id=b.id
  989. left join sub_project as d on d.id = a.sub_project_id
  990. left join task on task.id = a.task_id
  991. left join report_extra_degree on report_extra_degree.id = a.degree_id
  992. left join department on department.department_id = a.audit_deptid
  993. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  994. left join department dept on dept.department_id = a.dept_id
  995. left join task_group on task_group.id = a.group_id
  996. left join user u on u.id = a.project_auditor_id
  997. WHERE a.company_id =#{companyId}
  998. and a.state = 0
  999. <if test="startDate!=null and endDate!=null">
  1000. AND a.create_date between #{startDate} and #{endDate}
  1001. </if>
  1002. AND a.is_dept_audit=1
  1003. <if test="userId!=null">
  1004. and dept_manager.id=#{userId}
  1005. </if>
  1006. <if test="departmentId!=null">
  1007. and dept_manager.department_id=#{departmentId}
  1008. </if>
  1009. <if test="deptIds!=null and deptIds.size()>0">
  1010. and dept_manager.department_id in
  1011. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1012. #{item}
  1013. </foreach>
  1014. </if>
  1015. group by a.audit_dept_managerid
  1016. ORDER BY a.create_date desc, a.creator_id asc
  1017. </when>
  1018. <otherwise>
  1019. 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
  1020. FROM report AS a
  1021. left join user on user.id = a.creator_id
  1022. JOIN project AS b ON a.project_id=b.id
  1023. left join sub_project as d on d.id = a.sub_project_id
  1024. left join task on task.id = a.task_id
  1025. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1026. left join department on department.department_id = a.audit_deptid
  1027. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1028. left join department dept on dept.department_id = a.dept_id
  1029. left join task_group on task_group.id = a.group_id
  1030. left join user u on u.id = a.project_auditor_id
  1031. left join department dp on u.department_id=dp.department_id
  1032. WHERE a.company_id =#{companyId}
  1033. and a.state = 0
  1034. <if test="startDate!=null and endDate!=null">
  1035. AND a.create_date between #{startDate} and #{endDate}
  1036. </if>
  1037. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1038. <if test="userId!=null">
  1039. and u.id=#{userId}
  1040. </if>
  1041. <if test="departmentId!=null">
  1042. and u.department_id=#{departmentId}
  1043. </if>
  1044. <if test="deptIds!=null and deptIds.size()>0">
  1045. and u.department_id in
  1046. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1047. #{item}
  1048. </foreach>
  1049. </if>
  1050. group by a.project_auditor_id
  1051. ORDER BY a.create_date desc, a.creator_id asc
  1052. </otherwise>
  1053. </choose>
  1054. <if test="start!=null and size!=null">
  1055. limit #{start},#{size}
  1056. </if>
  1057. </select>
  1058. <select id="findCount" resultType="java.lang.Long">
  1059. select count(1)
  1060. from (<choose>
  1061. <when test="stateKey==0">
  1062. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  1063. FROM report AS a
  1064. left join user on user.id = a.creator_id
  1065. JOIN project AS b ON a.project_id=b.id
  1066. left join sub_project as d on d.id = a.sub_project_id
  1067. left join task on task.id = a.task_id
  1068. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1069. left join department on department.department_id = a.audit_deptid
  1070. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1071. left join department dept on dept.department_id = a.dept_id
  1072. left join task_group on task_group.id = a.group_id
  1073. left join user u on u.id = a.project_auditor_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=1
  1081. <if test="userId!=null">
  1082. and dept_manager.id=#{userId}
  1083. </if>
  1084. <if test="departmentId!=null">
  1085. and dept_manager.department_id=#{departmentId}
  1086. </if>
  1087. <if test="deptIds!=null and deptIds.size()>0">
  1088. and dept_manager.department_id in
  1089. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1090. #{item}
  1091. </foreach>
  1092. </if>
  1093. group by a.audit_dept_managerid
  1094. ORDER BY a.create_date desc, a.creator_id asc
  1095. </when>
  1096. <otherwise>
  1097. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1098. FROM report AS a
  1099. left join user on user.id = a.creator_id
  1100. JOIN project AS b ON a.project_id=b.id
  1101. left join sub_project as d on d.id = a.sub_project_id
  1102. left join task on task.id = a.task_id
  1103. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1104. left join department on department.department_id = a.audit_deptid
  1105. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1106. left join department dept on dept.department_id = a.dept_id
  1107. left join task_group on task_group.id = a.group_id
  1108. left join user u on u.id = a.project_auditor_id
  1109. left join department dp on u.department_id=dp.department_id
  1110. WHERE a.company_id =#{companyId}
  1111. and a.state = 0
  1112. and u.is_active = 1
  1113. <if test="startDate!=null and endDate!=null">
  1114. AND a.create_date between #{startDate} and #{endDate}
  1115. </if>
  1116. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1117. <if test="userId!=null">
  1118. and u.id=#{userId}
  1119. </if>
  1120. <if test="departmentId!=null">
  1121. and u.department_id=#{departmentId}
  1122. </if>
  1123. <if test="deptIds!=null and deptIds.size()>0">
  1124. and u.department_id in
  1125. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1126. #{item}
  1127. </foreach>
  1128. </if>
  1129. group by a.project_auditor_id
  1130. ORDER BY a.create_date desc, a.creator_id asc
  1131. </otherwise>
  1132. </choose>
  1133. <if test="start!=null and size!=null">
  1134. limit #{start},#{size}
  1135. </if>) total
  1136. </select>
  1137. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1138. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1139. (select SUM(te.plan_hours) from task_executor te
  1140. left join task on task.id=te.task_id
  1141. where te.executor_id=us.id
  1142. <if test="startDate!=null and endDate!=null">
  1143. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1144. </if>) as planHours,
  1145. (select SUM(report.working_time) from report
  1146. left join task on task.id=report.task_id
  1147. where report.creator_id=us.id and task_id is not null and report.state=1
  1148. <if test="startDate!=null and endDate!=null">
  1149. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1150. </if>) as workingTime
  1151. from user us
  1152. left join department dp on dp.department_id=us.department_id
  1153. where us.company_id=#{companyId}
  1154. 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)
  1155. <if test="userId!=null and userId!=''">
  1156. and us.id=#{userId}
  1157. </if>
  1158. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1159. and us.department_id in
  1160. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1161. #{item}
  1162. </foreach>
  1163. </if>
  1164. <if test="deptIds!=null and deptIds.size()>0">
  1165. and us.department_id in
  1166. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1167. #{item}
  1168. </foreach>
  1169. </if>
  1170. group by us.id
  1171. order by us.department_id
  1172. <if test="start!=null and size!=null">
  1173. limit #{start},#{size}
  1174. </if>
  1175. </select>
  1176. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1177. select count(1)
  1178. from(select us.name,dp.department_name as departmentName,
  1179. (select SUM(te.plan_hours) from task_executor te
  1180. left join task on task.id=te.task_id
  1181. where te.executor_id=us.id
  1182. <if test="startDate!=null and endDate!=null">
  1183. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1184. </if>) as planHours,
  1185. (select SUM(report.working_time) from report
  1186. left join task on task.id=report.task_id
  1187. where report.creator_id=us.id and task_id is not null
  1188. <if test="startDate!=null and endDate!=null">
  1189. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1190. </if>) as workingTime
  1191. from user us
  1192. left join department dp on dp.department_id=us.department_id
  1193. where us.company_id=#{companyId}
  1194. 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)
  1195. <if test="userId!=null and userId!=''">
  1196. and us.id=#{userId}
  1197. </if>
  1198. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1199. and us.department_id in
  1200. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1201. #{item}
  1202. </foreach>
  1203. </if>
  1204. <if test="deptIds!=null and deptIds.size()>0">
  1205. and us.department_id in
  1206. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1207. #{item}
  1208. </foreach>
  1209. </if>
  1210. group by us.id
  1211. order by us.department_id)as total
  1212. </select>
  1213. <select id="selectWithGroup" resultType="java.util.Map">
  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}
  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>
  1247. </select>
  1248. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1249. select count(1) from(
  1250. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1251. from report a
  1252. left join task_group b on a.group_id=b.id
  1253. left join project c on a.project_id=c.id
  1254. where c.company_id=#{companyId}
  1255. <if test="startDate!=null and endDate!=null">
  1256. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1257. </if>
  1258. <if test="projectId!=null">
  1259. and c.id=#{projectId}
  1260. </if>
  1261. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1262. and (c.id in
  1263. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1264. #{item}
  1265. </foreach>
  1266. <!--或者按分组负责人的匹配-->
  1267. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1268. or a.group_id in
  1269. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1270. #{item}
  1271. </foreach>
  1272. </if>
  1273. )
  1274. </if>
  1275. <if test="groupId!=null">
  1276. and a.group_id=#{groupId}
  1277. </if>
  1278. group by b.name
  1279. order by c.id
  1280. <if test="startIndex!=null and endIndex!=null">
  1281. limit #{startIndex},#{endIndex}
  1282. </if>) as total
  1283. </select>
  1284. <select id="selectWithGroupProject" resultType="java.util.Map">
  1285. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1286. from report a
  1287. left join task_group b on a.group_id=b.id
  1288. left join project c on a.project_id=c.id
  1289. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1290. left join project_separate ps on ps.id=c.id
  1291. </if>
  1292. where c.company_id=#{companyId}
  1293. <if test="startDate!=null and endDate!=null">
  1294. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1295. </if>
  1296. <if test="projectId!=null">
  1297. and c.id=#{projectId}
  1298. </if>
  1299. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1300. and ps.project_category_sub=#{projectCategorySub}
  1301. </if>
  1302. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1303. and (c.id in
  1304. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1305. #{item}
  1306. </foreach>
  1307. <!--或者按分组负责人的匹配-->
  1308. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1309. or a.group_id in
  1310. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1311. #{item}
  1312. </foreach>
  1313. </if>
  1314. )
  1315. </if>
  1316. <if test="groupId!=null">
  1317. and a.group_id=#{groupId}
  1318. </if>
  1319. group by c.id,b.id
  1320. order by c.id
  1321. <if test="startIndex!=null and endIndex!=null">
  1322. limit #{startIndex},#{endIndex}
  1323. </if>
  1324. </select>
  1325. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1326. select count(1) from(
  1327. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1328. from report a
  1329. left join task_group b on a.group_id=b.id
  1330. left join project c on a.project_id=c.id
  1331. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1332. left join project_separate ps on ps.id=c.id
  1333. </if>
  1334. where c.company_id=#{companyId}
  1335. <if test="startDate!=null and endDate!=null">
  1336. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1337. </if>
  1338. <if test="projectId!=null">
  1339. and c.id=#{projectId}
  1340. </if>
  1341. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1342. and ps.project_category_sub=#{projectCategorySub}
  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. <!--或者按分组负责人的匹配-->
  1350. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1351. or a.group_id in
  1352. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1353. #{item}
  1354. </foreach>
  1355. </if>
  1356. )
  1357. </if>
  1358. <if test="groupId!=null">
  1359. and a.group_id=#{groupId}
  1360. </if>
  1361. group by c.id,b.id
  1362. order by c.id
  1363. <if test="startIndex!=null and endIndex!=null">
  1364. limit #{startIndex},#{endIndex}
  1365. </if>) as total
  1366. </select>
  1367. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1368. 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
  1369. from report a
  1370. left join task_group b on a.group_id=b.id
  1371. left join project c on a.project_id=c.id
  1372. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1373. where c.company_id=#{companyId} and a.state=1
  1374. <if test="startDate!=null and endDate!=null">
  1375. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1376. </if>
  1377. <if test="projectId!=null">
  1378. and c.id=#{projectId}
  1379. </if>
  1380. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1381. and c.id in
  1382. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1383. #{item}
  1384. </foreach>
  1385. </if>
  1386. <if test="gpNamesList !=null">
  1387. and b.name in
  1388. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1389. #{item}
  1390. </foreach>
  1391. </if>
  1392. group by c.id,b.id
  1393. <if test="start!=null and size!=null">
  1394. limit #{start},#{size}
  1395. </if>
  1396. </select>
  1397. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1398. select count(1) from
  1399. (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
  1400. from report a
  1401. left join task_group b on a.group_id=b.id
  1402. left join project c on a.project_id=c.id
  1403. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1404. where c.company_id=#{companyId} and a.state=1
  1405. <if test="startDate!=null and endDate!=null">
  1406. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1407. </if>
  1408. <if test="projectId!=null">
  1409. and c.id=#{projectId}
  1410. </if>
  1411. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1412. and c.id in
  1413. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1414. #{item}
  1415. </foreach>
  1416. </if>
  1417. <if test="gpNamesList !=null">
  1418. and b.name in
  1419. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1420. #{item}
  1421. </foreach>
  1422. </if>
  1423. group by c.id,b.id
  1424. <if test="start!=null and size!=null">
  1425. limit #{start},#{size}
  1426. </if>) as total
  1427. </select>
  1428. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1429. 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
  1430. from report a
  1431. left join task_group b on a.group_id=b.id
  1432. left join project c on a.project_id=c.id
  1433. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1434. where c.company_id=#{companyId} and a.state=1
  1435. <if test="startDate!=null and endDate!=null">
  1436. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1437. </if>
  1438. <if test="projectId!=null">
  1439. and c.id=#{projectId}
  1440. </if>
  1441. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1442. and c.id in
  1443. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1444. #{item}
  1445. </foreach>
  1446. </if>
  1447. <if test="gpNamesList !=null">
  1448. and b.name in
  1449. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1450. #{item}
  1451. </foreach>
  1452. </if>
  1453. group by c.id,f.id
  1454. <if test="start!=null and size!=null">
  1455. limit #{start},#{size}
  1456. </if>
  1457. </select>
  1458. <select id="getCostByUserCustom" resultType="java.util.Map">
  1459. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1460. FROM user AS a
  1461. LEFT JOIN report AS b ON a.id = b.creator_id
  1462. LEFT JOIN project AS c ON b.project_id = c.id
  1463. left join user_custom uc on uc.company_id=a.company_id
  1464. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1465. WHERE b.state = 1
  1466. AND a.company_id = #{companyId}
  1467. <if test="startDate!=null and endDate!=null">
  1468. AND b.create_date between #{startDate} and #{endDate}
  1469. </if>
  1470. and uc.id=#{customId}
  1471. <if test="deptIds!=null and deptIds.size()>0">
  1472. and a.department_id in
  1473. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1474. #{item}
  1475. </foreach>
  1476. </if>
  1477. <if test="subCustomName!=null">
  1478. and suc.name=#{subCustomName}
  1479. </if>
  1480. GROUP BY suc.name
  1481. </select>
  1482. <select id="getEmpMonthHours" resultType="java.util.Map">
  1483. 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,
  1484. (select allday from time_type te
  1485. where te.company_id=#{companyId}) as allday,
  1486. (select SUM(report.working_time) from report
  1487. where report.creator_id=us.id and report.state=1
  1488. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1489. as workingTime
  1490. from user us
  1491. left join department dp on dp.department_id=us.department_id
  1492. where us.company_id=#{companyId}
  1493. 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)
  1494. <if test="userId!=null and userId!=''">
  1495. and us.id=#{userId}
  1496. </if>
  1497. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1498. and us.department_id in
  1499. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1500. #{item}
  1501. </foreach>
  1502. </if>
  1503. <if test="deptIds!=null and deptIds.size()>0">
  1504. and us.department_id in
  1505. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1506. #{item}
  1507. </foreach>
  1508. </if>
  1509. group by us.id
  1510. order by us.department_id
  1511. <if test="start!=null and size!=null">
  1512. limit #{start},#{size}
  1513. </if>
  1514. </select>
  1515. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1516. select count(1)
  1517. from(select us.name,dp.department_name as departmentName,
  1518. (select SUM(report.working_time) from report
  1519. where report.creator_id=us.id
  1520. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1521. as workingTime
  1522. from user us
  1523. left join department dp on dp.department_id=us.department_id
  1524. where us.company_id=#{companyId}
  1525. 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)
  1526. <if test="userId!=null and userId!=''">
  1527. and us.id=#{userId}
  1528. </if>
  1529. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1530. and us.department_id in
  1531. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1532. #{item}
  1533. </foreach>
  1534. </if>
  1535. <if test="deptIds!=null and deptIds.size()>0">
  1536. and us.department_id in
  1537. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1538. #{item}
  1539. </foreach>
  1540. </if>
  1541. group by us.id
  1542. order by us.department_id)as total
  1543. </select>
  1544. <!-- 分页查询部门参与项目情况-->
  1545. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1546. SELECT department.department_id deptId,
  1547. department_name deptName,
  1548. (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,
  1549. pro.projectCount projectCount,
  1550. pro.centerCount centerCount,
  1551. pcon.peopleCount peopleCount
  1552. FROM department
  1553. LEFT JOIN (
  1554. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1555. COUNT(DISTINCT(r.degree_id)) centerCount
  1556. FROM report
  1557. LEFT JOIN report r
  1558. ON report.id = r.id AND r.degree_id != -1
  1559. LEFT JOIN `user`
  1560. ON report.creator_id = user.id
  1561. WHERE report.state = 1
  1562. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1563. GROUP BY dept_id
  1564. ) pro
  1565. on pro.dept_id = department.department_id
  1566. LEFT JOIN (
  1567. SELECT dept_id,sum(p.con) peopleCount
  1568. FROM (
  1569. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1570. LEFT JOIN `user`
  1571. ON report.creator_id = user.id
  1572. WHERE report.state = 1
  1573. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1574. GROUP BY report.creator_id,dept_id
  1575. ) p GROUP BY p.dept_id
  1576. ) pcon
  1577. ON pcon.dept_id = department.department_id
  1578. WHERE department.company_id = #{companyId}
  1579. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1580. and department.department_id in
  1581. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1582. #{item}
  1583. </foreach>
  1584. </if>
  1585. <if test="deptIds!=null and deptIds.size()>0">
  1586. and department.department_id in
  1587. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1588. #{item}
  1589. </foreach>
  1590. </if>
  1591. <if test="size!=null and start!=null">
  1592. limit #{start},#{size}
  1593. </if>
  1594. </select>
  1595. <!--获取按项目分组的工时成本-->
  1596. <select id="getExportDegreeCost" resultType="java.util.Map">
  1597. 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
  1598. FROM project AS a
  1599. LEFT JOIN report AS b ON b.project_id = a.id
  1600. JOIN user AS c ON b.creator_id = c.id
  1601. WHERE a.company_id = #{companyId}
  1602. <if test="projectId != null">
  1603. AND a.id = #{projectId}
  1604. </if>
  1605. <if test="startDate != null and endDate != null">
  1606. AND b.create_date between #{startDate} and #{endDate}
  1607. </if>
  1608. <choose>
  1609. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1610. and b.dept_id in
  1611. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1612. #{item}
  1613. </foreach>
  1614. </when>
  1615. <otherwise>
  1616. <if test="deptIds!=null and deptIds.size()>0">
  1617. and (b.dept_id in
  1618. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1619. #{item}
  1620. </foreach>
  1621. <if test="deptRelatedProjectIds.size() > 0">
  1622. or a.id in
  1623. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  1624. #{pid}
  1625. </foreach>
  1626. </if>
  1627. )
  1628. </if>
  1629. </otherwise>
  1630. </choose>
  1631. AND b.state = 1
  1632. GROUP BY a.id
  1633. ORDER BY a.id ASC
  1634. </select>
  1635. <!--获取某个项目每个维度分别需要的工时-->
  1636. <select id="getDegreeDetailCost" resultType="java.util.Map">
  1637. 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
  1638. FROM report AS a
  1639. JOIN user AS b ON a.creator_id = b.id
  1640. left join department on department.department_id = a.dept_id
  1641. left join report_extra_degree as r on a.degree_id = r.id
  1642. WHERE a.company_id=#{companyId}
  1643. <if test="curProjectId != null">
  1644. and a.project_id = #{curProjectId}
  1645. </if>
  1646. <if test="projectId != null">
  1647. and a.project_id = #{projectId}
  1648. </if>
  1649. <if test="startDate != null and endDate != null">
  1650. AND a.create_date between #{startDate} and #{endDate}
  1651. </if>
  1652. <choose>
  1653. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1654. and a.dept_id in
  1655. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1656. #{item}
  1657. </foreach>
  1658. </when>
  1659. <otherwise>
  1660. <if test="deptIds!=null and deptIds.size()>0">
  1661. and a.dept_id in
  1662. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1663. #{item}
  1664. </foreach>
  1665. </if>
  1666. </otherwise>
  1667. </choose>
  1668. GROUP BY a.project_id,b.id,a.degree_id
  1669. ORDER BY b.id,a.degree_id ASC
  1670. </select>
  1671. <select id="selectNearProject" resultType="com.management.platform.entity.Project">
  1672. SELECT * FROM project
  1673. WHERE STATUS = 1 AND id IN (
  1674. SELECT project_id
  1675. FROM (
  1676. SELECT DISTINCT report.project_id
  1677. FROM report
  1678. WHERE creator_id = #{userId}
  1679. GROUP BY project_id
  1680. ORDER BY MAX(create_time)
  1681. DESC LIMIT 3
  1682. ) p2
  1683. ) AND id IN(SELECT project_id FROM participation WHERE user_id=#{userId})
  1684. </select>
  1685. <select id="getFTEData" resultType="java.util.Map">
  1686. 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,
  1687. IFNULL(r.projectCode,'') as projectCode,IFNULL(r.workTime,0) as workTime,IFNULL(t.nonProjectWorkingTime,0) as nonProjectWorkingTime
  1688. FROM `user` u
  1689. LEFT JOIN department d on u.department_id=d.department_id
  1690. LEFT JOIN (
  1691. SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
  1692. FROM report
  1693. LEFT JOIN project p
  1694. ON report.project_id = p.id
  1695. LEFT JOIN `user`
  1696. ON user.id = report.creator_id
  1697. WHERE report.state = 1
  1698. AND p.is_public = 0
  1699. AND report.company_id=#{companyId}
  1700. AND
  1701. (
  1702. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate} and user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1703. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1704. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1705. and
  1706. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1707. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1708. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1709. and
  1710. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1711. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1712. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1713. )
  1714. GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
  1715. ) r
  1716. ON u.id = r.creator_id
  1717. LEFT JOIN (
  1718. SELECT report.creator_id,SUM(working_time) nonProjectWorkingTime
  1719. FROM report
  1720. LEFT JOIN project p
  1721. ON report.project_id = p.id
  1722. LEFT JOIN `user`
  1723. ON user.id = report.creator_id
  1724. WHERE report.state = 1
  1725. AND p.is_public = 1
  1726. AND report.company_id=#{companyId}
  1727. AND
  1728. (
  1729. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate} and user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1730. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1731. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1732. and
  1733. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1734. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1735. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1736. and
  1737. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1738. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1739. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1740. )
  1741. GROUP BY user.id
  1742. ) t
  1743. ON u.id = t.creator_id
  1744. WHERE u.company_id=#{companyId}
  1745. AND (workTime>0 OR u.`is_active`=1)
  1746. <if test="area!=null and area != '' ">
  1747. and u.plate1 = #{area}
  1748. </if>
  1749. <if test="userId!=null and userId != '' ">
  1750. and u.id = #{userId}
  1751. </if>
  1752. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1753. and u.department_id in
  1754. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1755. #{item}
  1756. </foreach>
  1757. </if>
  1758. <if test="deptIds!=null and deptIds.size()>0">
  1759. and u.department_id in
  1760. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1761. #{item}
  1762. </foreach>
  1763. </if>
  1764. <!-- <if test="departmentId!=null">-->
  1765. <!-- and u.department_id=#{departmentId}-->
  1766. <!-- </if>-->
  1767. <if test="sortProp!=null and sortProp!=''">
  1768. <choose>
  1769. <when test="sortOrder==0">
  1770. order by id desc
  1771. </when>
  1772. <otherwise>
  1773. order by id
  1774. </otherwise>
  1775. </choose>
  1776. </if>
  1777. <if test="start!=null and size!=null">
  1778. limit #{start},#{size}
  1779. </if>
  1780. </select>
  1781. <!--获取查询者所在公司每个项目的工时成本-->
  1782. <select id="getTimeCostByToken" resultType="java.util.Map">
  1783. 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
  1784. FROM project AS a
  1785. LEFT JOIN report AS b ON b.project_id = a.id
  1786. JOIN user AS c ON b.creator_id = c.id
  1787. JOIN department d on d.department_id=c.department_id
  1788. WHERE a.company_id = #{companyId}
  1789. <if test="startDate != null and endDate != null">
  1790. AND b.create_date between #{startDate} and #{endDate}
  1791. </if>
  1792. AND b.state = 1
  1793. GROUP BY a.id,b.creator_id
  1794. ORDER BY a.id ASC
  1795. </select>
  1796. <!--获取员工的项目分类工时统计数据 -->
  1797. <select id="getMembProjectCateTime" resultType="com.management.platform.entity.vo.UserCateTimeVo">
  1798. SELECT user.id AS userId,user.plate1 as plate1,user.plate2 as plate2,user.plate3 as plate3,user.plate4 as plate4,user.plate5 as plate5, user.`name`, project.`category`, project.`category_name` AS categoryName, SUM(report.`working_time`) AS workingTime
  1799. FROM report
  1800. LEFT JOIN `user` ON user.id = report.`creator_id`
  1801. LEFT JOIN project ON project.id = report.`project_id`
  1802. WHERE report.`company_id` = #{companyId}
  1803. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  1804. AND report.state = 1
  1805. <if test="departmentId!=null">
  1806. AND user.department_id=#{departmentId}
  1807. </if>
  1808. <if test="subUserCustomName!=null and subUserCustomName!='' and plateString!=null">
  1809. <choose>
  1810. <when test="plateString==1">
  1811. AND user.plate1=#{subUserCustomName}
  1812. </when>
  1813. <when test="plateString==2">
  1814. AND user.plate2=#{subUserCustomName}
  1815. </when>
  1816. <when test="plateString==3">
  1817. AND user.plate3=#{subUserCustomName}
  1818. </when>
  1819. <when test="plateString==4">
  1820. AND user.plate4=#{subUserCustomName}
  1821. </when>
  1822. <otherwise>
  1823. AND user.plate5=#{subUserCustomName}
  1824. </otherwise>
  1825. </choose>
  1826. </if>
  1827. GROUP BY user.id, project.`category`
  1828. </select>
  1829. <select id="userProjectProcessList" resultType="java.util.Map">
  1830. 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,
  1831. 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
  1832. from task_executor te
  1833. left join user u on u.id=te.executor_id
  1834. left join department d on d.department_id=u.department_id
  1835. left join project p on p.id=te.project_id
  1836. where u.company_id=#{companyId} and te.project_id is not null
  1837. <if test="deptId!=null">
  1838. and d.department_id=#{deptId}
  1839. </if>
  1840. <if test="userId!=null and userId!=''">
  1841. and u.id=#{userId}
  1842. </if>
  1843. <if test="projectId!=null">
  1844. and p.id=#{projectId}
  1845. </if>
  1846. <if test="list!=null and list.size()>0">
  1847. and d.department_id in
  1848. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1849. #{item}
  1850. </foreach>
  1851. </if>
  1852. <if test="listSecond!=null and listSecond.size()>0">
  1853. and d.department_id in
  1854. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1855. #{item}
  1856. </foreach>
  1857. </if>
  1858. group by te.executor_id,te.project_id
  1859. order by d.department_id,u.id
  1860. <if test="start!=null and size!=null">
  1861. limit #{start},#{size}
  1862. </if>
  1863. </select>
  1864. <select id="userProjectProcessCount" resultType="java.lang.Long">
  1865. select count(1) from (
  1866. select d.department_name as departmentName
  1867. from task_executor te
  1868. left join user u on u.id=te.executor_id
  1869. left join department d on d.department_id=u.department_id
  1870. left join project p on p.id=te.project_id
  1871. where u.company_id=#{companyId} and te.project_id is not null
  1872. <if test="deptId!=null">
  1873. and d.department_id=#{deptId}
  1874. </if>
  1875. <if test="userId!=null and userId!=''">
  1876. and u.id=#{userId}
  1877. </if>
  1878. <if test="projectId!=null">
  1879. and p.id=#{projectId}
  1880. </if>
  1881. <if test="list!=null and list.size()>0">
  1882. and d.department_id in
  1883. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1884. #{item}
  1885. </foreach>
  1886. </if>
  1887. <if test="listSecond!=null and listSecond.size()>0">
  1888. and d.department_id in
  1889. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1890. #{item}
  1891. </foreach>
  1892. </if>
  1893. group by te.executor_id,te.project_id
  1894. ) as total
  1895. </select>
  1896. <select id="groupExpendProcessList" resultType="java.util.Map">
  1897. 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,
  1898. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) as normalHour,IFNULL(r.overHour,0) as overHour,
  1899. IFNULL(tg.man_day*8,0) AS planHour,IFNULL((SELECT SUM(change_man_day*8) FROM `group_budget_review` WHERE group_id=tg.`id` AND `status`=1),0) AS afterSetPlanHour
  1900. FROM task_group tg
  1901. LEFT JOIN task t ON tg.id = t.group_id
  1902. LEFT JOIN task_executor te ON t.id = te.task_id
  1903. LEFT JOIN user u
  1904. ON te.executor_id = u.id AND u.`company_id`=#{companyId}
  1905. LEFT JOIN project p ON p.id=tg.project_id
  1906. LEFT JOIN department d ON d.department_id=u.department_id
  1907. LEFT JOIN (
  1908. SELECT SUM(working_time) AS realHour,SUM(cost) AS realCost,(SUM(working_time)-SUM(overtime_hours)) AS normalHour,SUM(overtime_hours) AS overHour,group_id,dept_id
  1909. FROM report WHERE state=1
  1910. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1911. AND create_date BETWEEN #{startDate} AND #{endDate}
  1912. </if>
  1913. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id,dept_id) r ON r.group_id=tg.`id` and r.dept_id=u.department_id
  1914. WHERE p.company_id=#{companyId}
  1915. <if test="listFour!=null and listFour.size()>0">
  1916. AND tg.project_id in
  1917. <foreach collection="listFour" separator="," open="(" close=")" item="item">
  1918. #{item}
  1919. </foreach>
  1920. </if>
  1921. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1922. <if test="userId!=null and userId!=''">
  1923. and t.executor_id=#{userId}
  1924. </if>
  1925. GROUP BY p.id,tg.id,d.department_id ORDER BY p.id,d.department_id
  1926. </select>
  1927. <select id="groupExpendProcessListForChart" resultType="java.util.Map">
  1928. SELECT groupName,SUM(realHour) AS realHour,SUM(realCost) AS realCost,SUM(normalHour) AS normalHour,SUM(overHour) AS overHour,SUM(planHour) AS planHour,SUM(afterSetPlanHour) AS afterSetPlanHour
  1929. FROM (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,
  1930. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) AS normalHour,IFNULL(r.overHour,0) AS overHour,
  1931. IFNULL(tg.man_day*8,0) AS planHour,IFNULL((SELECT SUM(change_man_day*8) FROM `group_budget_review` WHERE group_id=tg.`id` AND `status`=1),0) AS afterSetPlanHour
  1932. FROM task_group tg
  1933. LEFT JOIN task t ON tg.id = t.group_id
  1934. LEFT JOIN task_executor te ON t.id = te.task_id
  1935. LEFT JOIN `user` u
  1936. ON te.executor_id = u.id AND u.`company_id`=#{companyId}
  1937. LEFT JOIN project p ON p.id=tg.project_id
  1938. LEFT JOIN department d ON d.department_id=u.department_id
  1939. LEFT JOIN (
  1940. SELECT SUM(working_time) AS realHour,SUM(cost) AS realCost,(SUM(working_time)-SUM(overtime_hours)) AS normalHour,SUM(overtime_hours) AS overHour,group_id,dept_id
  1941. FROM report WHERE state=1
  1942. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1943. AND create_date BETWEEN #{startDate} AND #{endDate}
  1944. </if>
  1945. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  1946. WHERE p.company_id=#{companyId}
  1947. <if test="listThird!=null and listThird.size()>0">
  1948. AND tg.project_id in
  1949. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  1950. #{item}
  1951. </foreach>
  1952. </if>
  1953. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1954. <if test="userId!=null and userId!=''">
  1955. and t.executor_id=#{userId}
  1956. </if>
  1957. GROUP BY tg.id ORDER BY p.id,d.department_id) AS t
  1958. <where>
  1959. <if test="listFour!=null and listFour.size()>0">
  1960. t.groupName in
  1961. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  1962. #{item}
  1963. </foreach>
  1964. </if>
  1965. </where>
  1966. GROUP BY t.groupName
  1967. </select>
  1968. <select id="groupExpendProcessListForUser" resultType="java.util.Map">
  1969. SELECT departmentId, departmentName,jobNumber,userName,
  1970. SUM(CASE WHEN groupName='方案设计' THEN workTime ELSE 0 END) AS '方案设计' ,
  1971. SUM(CASE WHEN groupName='研发部' THEN workTime ELSE 0 END) AS '研发部' ,
  1972. SUM(CASE WHEN groupName='研发部工艺调试' THEN workTime ELSE 0 END) AS '研发部工艺调试',
  1973. SUM(CASE WHEN groupName='研发部工艺调试验收' THEN workTime ELSE 0 END) AS '研发部工艺调试验收' ,
  1974. SUM(CASE WHEN groupName='研发部工艺设计' THEN workTime ELSE 0 END) AS '研发部工艺设计' ,
  1975. SUM(CASE WHEN groupName='研发部结构设计' THEN workTime ELSE 0 END) AS '研发部结构设计' ,
  1976. SUM(CASE WHEN groupName='研发部BIM设计' THEN workTime ELSE 0 END) AS '研发部BIM设计' ,
  1977. SUM(CASE WHEN groupName='研发部电气调试验收' THEN workTime ELSE 0 END) AS '研发部电气调试验收' ,
  1978. SUM(CASE WHEN groupName='研发部电气设计' THEN workTime ELSE 0 END) AS '研发部电气设计' ,
  1979. SUM(CASE WHEN groupName='研发部售后' THEN workTime ELSE 0 END) AS '研发部售后' ,
  1980. SUM(CASE WHEN groupName='工程部配合运维' THEN workTime ELSE 0 END) AS '工程部配合运维' ,
  1981. SUM(CASE WHEN groupName='研发部运维' THEN workTime ELSE 0 END) AS '研发部运维' ,
  1982. SUM(CASE WHEN groupName='生产部' THEN workTime ELSE 0 END) AS '生产部' ,
  1983. SUM(CASE WHEN groupName='生产部车间' THEN workTime ELSE 0 END) AS '生产部车间' ,
  1984. SUM(CASE WHEN groupName='生产部电气' THEN workTime ELSE 0 END) AS '生产部电气' ,
  1985. SUM(CASE WHEN groupName='工程部配合调试' THEN workTime ELSE 0 END) AS '工程部配合调试' ,
  1986. SUM(CASE WHEN groupName='工程部' THEN workTime ELSE 0 END) AS '工程部' ,
  1987. SUM(CASE WHEN groupName='工程部售后' THEN workTime ELSE 0 END) AS '工程部售后' ,
  1988. SUM(CASE WHEN groupName='工程部现场安装施工' THEN workTime ELSE 0 END) AS '工程部现场安装施工',
  1989. IFNULL(SUM(workTime),0) AS totalWorkTime
  1990. FROM (
  1991. SELECT d.`department_id` AS departmentId,d.`department_name` AS departmentName,u.`job_number` AS jobNumber,u.`name` AS userName ,tg.name AS groupName,rr.realHour AS workTime,u.id
  1992. FROM task_executor te
  1993. LEFT JOIN task t ON t.id=te.task_id
  1994. LEFT JOIN `user` u ON te.executor_id=u.id
  1995. LEFT JOIN task_group tg ON tg.id=t.group_id
  1996. LEFT JOIN project p ON p.id=tg.project_id
  1997. LEFT JOIN department d ON d.department_id=u.department_id
  1998. LEFT JOIN (
  1999. SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
  2000. FROM report r
  2001. LEFT JOIN task_group tg ON r.group_id=tg.`id`
  2002. WHERE r.state=1 AND r.project_id IS NOT NULL
  2003. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2004. AND r.create_date BETWEEN #{startDate} AND #{endDate}
  2005. </if> AND r.company_id=#{companyId}
  2006. GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
  2007. WHERE u.company_id=#{companyId}
  2008. <if test="listThird!=null and listThird.size()>0">
  2009. AND tg.project_id in
  2010. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2011. #{item}
  2012. </foreach>
  2013. </if>
  2014. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2015. <if test="listFour!=null and listFour.size()>0">
  2016. and tg.name in
  2017. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2018. #{item}
  2019. </foreach>
  2020. </if>
  2021. GROUP BY u.`id`,tg.id
  2022. ) AS t
  2023. <where>
  2024. <if test="listFive!=null and listFive.size()>0">
  2025. t.departmentId in
  2026. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2027. #{item}
  2028. </foreach>
  2029. </if>
  2030. </where>
  2031. GROUP BY t.id
  2032. <if test="start!=null and size!=null">
  2033. limit #{start},#{size}
  2034. </if>
  2035. </select>
  2036. <select id="groupExpendProcessListForUserCount" resultType="java.lang.Integer">
  2037. select count(1) from (
  2038. SELECT departmentId,departmentName,jobNumber,userName,IFNULL(SUM(workTime),0) AS totalWorkTime
  2039. FROM (
  2040. SELECT d.`department_id` AS departmentId,d.`department_name` AS departmentName,u.`job_number` AS jobNumber,u.`name` AS userName ,tg.name AS groupName,rr.realHour AS workTime,u.id
  2041. FROM task_executor te
  2042. LEFT JOIN task t ON t.id=te.task_id
  2043. LEFT JOIN `user` u ON te.executor_id=u.id
  2044. LEFT JOIN task_group tg ON tg.id=t.group_id
  2045. LEFT JOIN project p ON p.id=tg.project_id
  2046. LEFT JOIN department d ON d.department_id=u.department_id
  2047. LEFT JOIN (
  2048. SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
  2049. FROM report r
  2050. LEFT JOIN task_group tg ON r.group_id=tg.`id`
  2051. WHERE r.state=1 AND r.project_id IS NOT NULL
  2052. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2053. AND r.create_date BETWEEN #{startDate} AND #{endDate}
  2054. </if> AND r.company_id=#{companyId}
  2055. GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
  2056. WHERE u.company_id=#{companyId}
  2057. <if test="listThird!=null and listThird.size()>0">
  2058. AND tg.project_id in
  2059. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2060. #{item}
  2061. </foreach>
  2062. </if>
  2063. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2064. <if test="listFour!=null and listFour.size()>0">
  2065. and tg.name in
  2066. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2067. #{item}
  2068. </foreach>
  2069. </if>
  2070. GROUP BY u.`id`,tg.id
  2071. ) AS t
  2072. <where>
  2073. <if test="listFive!=null and listFive.size()>0">
  2074. t.departmentId in
  2075. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2076. #{item}
  2077. </foreach>
  2078. </if>
  2079. </where>
  2080. GROUP BY t.id
  2081. ) as total
  2082. </select>
  2083. <select id="groupExpendProcessListForProject" resultType="java.util.Map">
  2084. SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
  2085. SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
  2086. IFNULL(r.realHour,0) AS realHour
  2087. FROM task_executor te
  2088. LEFT JOIN task t ON t.id=te.task_id
  2089. LEFT JOIN `user` u ON te.executor_id=u.id
  2090. LEFT JOIN task_group tg ON tg.id=t.group_id
  2091. LEFT JOIN project p ON p.id=tg.project_id
  2092. LEFT JOIN department d ON d.department_id=u.department_id
  2093. LEFT JOIN (
  2094. SELECT SUM(working_time) AS realHour,group_id,dept_id
  2095. FROM report WHERE state=1
  2096. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2097. AND create_date BETWEEN #{startDate} AND #{endDate}
  2098. </if>
  2099. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  2100. WHERE u.company_id=#{companyId}
  2101. <if test="listThird!=null and listThird.size()>0">
  2102. AND tg.project_id in
  2103. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2104. #{item}
  2105. </foreach>
  2106. </if>
  2107. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2108. <if test="listFour!=null and listFour.size()>0">
  2109. and tg.name in
  2110. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2111. #{item}
  2112. </foreach>
  2113. </if>
  2114. <if test="listFive!=null and listFive.size()>0">
  2115. and d.department_id in
  2116. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2117. #{item}
  2118. </foreach>
  2119. </if>
  2120. GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
  2121. <where>
  2122. realHour>0
  2123. <if test="listThird!=null and listThird.size()>0">
  2124. and
  2125. projectId in
  2126. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2127. #{item}
  2128. </foreach>
  2129. </if>
  2130. </where>
  2131. GROUP BY projectId
  2132. <if test="start!=null and size!=null">
  2133. limit #{start},#{size}
  2134. </if>
  2135. </select>
  2136. <select id="groupExpendProcessListForProjectCount" resultType="java.lang.Integer">
  2137. select count(1) from (
  2138. SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
  2139. SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
  2140. IFNULL(r.realHour,0) AS realHour
  2141. FROM task_executor te
  2142. LEFT JOIN task t ON t.id=te.task_id
  2143. LEFT JOIN `user` u ON te.executor_id=u.id
  2144. LEFT JOIN task_group tg ON tg.id=t.group_id
  2145. LEFT JOIN project p ON p.id=tg.project_id
  2146. LEFT JOIN department d ON d.department_id=u.department_id
  2147. LEFT JOIN (
  2148. SELECT SUM(working_time) AS realHour,group_id,dept_id
  2149. FROM report WHERE state=1
  2150. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2151. AND create_date BETWEEN #{startDate} AND #{endDate}
  2152. </if>
  2153. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  2154. WHERE u.company_id=#{companyId}
  2155. <if test="listThird!=null and listThird.size()>0">
  2156. AND tg.project_id in
  2157. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2158. #{item}
  2159. </foreach>
  2160. </if>
  2161. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2162. <if test="listFour!=null and listFour.size()>0">
  2163. and tg.name in
  2164. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2165. #{item}
  2166. </foreach>
  2167. </if>
  2168. <if test="listFive!=null and listFive.size()>0">
  2169. and d.department_id in
  2170. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2171. #{item}
  2172. </foreach>
  2173. </if>
  2174. GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
  2175. <where>
  2176. realHour>0
  2177. <if test="listThird!=null and listThird.size()>0">
  2178. and
  2179. projectId in
  2180. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2181. #{item}
  2182. </foreach>
  2183. </if>
  2184. </where>
  2185. GROUP BY projectId
  2186. ) as total
  2187. </select>
  2188. <select id="projectExpendProcessList" resultType="java.util.Map">
  2189. 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,
  2190. IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realHour, IFNULL((select SUM(cost) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realCost,
  2191. IFNULL(IFNULL(SUM(te.plan_hours),0)-IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0),0) as residueHour
  2192. from task_executor te
  2193. left join user u on u.id=te.executor_id
  2194. left join department d on u.department_id=d.department_id
  2195. left join task t on t.id=te.task_id
  2196. left join project p on p.id=t.project_id
  2197. left join project_category pc on pc.id=p.category
  2198. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
  2199. <if test="projectId!=null">
  2200. and p.id=#{projectId}
  2201. </if>
  2202. <if test="userId!=null and userId!=''">
  2203. and FIND_IN_SET(#{userId},t.executor_id)
  2204. </if>
  2205. <if test="categoryId!=null">
  2206. and pc.id=#{categoryId}
  2207. </if>
  2208. <if test="list!=null and list.size()>0">
  2209. and d.department_id in
  2210. <foreach collection="list" open="(" close=")" separator="," item="item">
  2211. #{item}
  2212. </foreach>
  2213. </if>
  2214. group by t.project_id
  2215. <if test="start!=null and size!=null">
  2216. limit #{start},#{size}
  2217. </if>
  2218. </select>
  2219. <select id="projectExpendProcessListCount" resultType="java.lang.Long">
  2220. select count(1) from (
  2221. select p.project_name as projectName
  2222. from task_executor te
  2223. left join user u on u.id=te.executor_id
  2224. left join department d on u.department_id=d.department_id
  2225. left join task t on t.id=te.task_id
  2226. left join project p on p.id=t.project_id
  2227. left join project_category pc on pc.id=p.category
  2228. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
  2229. <if test="projectId!=null">
  2230. and p.id=#{projectId}
  2231. </if>
  2232. <if test="userId!=null and userId!=''">
  2233. and te.executor_id=#{userId}
  2234. </if>
  2235. <if test="categoryId!=null">
  2236. and pc.id=#{categoryId}
  2237. </if>
  2238. <if test="list!=null and list.size()>0">
  2239. and d.department_id in
  2240. <foreach collection="list" open="(" close=")" separator="," item="item">
  2241. #{item}
  2242. </foreach>
  2243. </if>
  2244. group by t.project_id
  2245. ) as total
  2246. </select>
  2247. <select id="userTaskProcessList" resultType="java.util.Map">
  2248. 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,
  2249. 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
  2250. ,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate
  2251. from task_executor te
  2252. left join user u on u.id=te.executor_id
  2253. left join department d on d.department_id=u.department_id
  2254. left join project p on p.id=te.project_id
  2255. left join task t on te.task_id=t.id
  2256. where u.company_id=#{companyId} and te.project_id is not null
  2257. <if test="deptId!=null">
  2258. and d.department_id=#{deptId}
  2259. </if>
  2260. <if test="userId!=null and userId!=''">
  2261. and u.id=#{userId}
  2262. </if>
  2263. <if test="projectId!=null">
  2264. and p.id=#{projectId}
  2265. </if>
  2266. <if test="list!=null and list.size()>0">
  2267. and d.department_id in
  2268. <foreach collection="list" open="(" close=")" item="item" separator=",">
  2269. #{item}
  2270. </foreach>
  2271. </if>
  2272. <if test="listSecond!=null and listSecond.size()>0">
  2273. and d.department_id in
  2274. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  2275. #{item}
  2276. </foreach>
  2277. </if>
  2278. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2279. and ((t.start_date between #{startDate} and #{endDate})
  2280. or
  2281. (t.end_date between #{startDate} and #{endDate}))
  2282. </if>
  2283. group by te.executor_id,t.id
  2284. order by d.department_id,u.id
  2285. <if test="start!=null and size!=null">
  2286. limit #{start},#{size}
  2287. </if>
  2288. </select>
  2289. <select id="userTaskProcessListCount" resultType="java.lang.Long">
  2290. select count(1) from (
  2291. select d.department_name as departmentName
  2292. from task_executor te
  2293. left join user u on u.id=te.executor_id
  2294. left join department d on d.department_id=u.department_id
  2295. left join project p on p.id=te.project_id
  2296. left join task t on te.task_id=t.id
  2297. where u.company_id=#{companyId} and te.project_id is not null
  2298. <if test="deptId!=null">
  2299. and d.department_id=#{deptId}
  2300. </if>
  2301. <if test="userId!=null and userId!=''">
  2302. and u.id=#{userId}
  2303. </if>
  2304. <if test="projectId!=null">
  2305. and p.id=#{projectId}
  2306. </if>
  2307. <if test="list!=null and list.size()>0">
  2308. and d.department_id in
  2309. <foreach collection="list" open="(" close=")" item="item" separator=",">
  2310. #{item}
  2311. </foreach>
  2312. </if>
  2313. <if test="listSecond!=null and listSecond.size()>0">
  2314. and d.department_id in
  2315. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  2316. #{item}
  2317. </foreach>
  2318. </if>
  2319. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2320. and ((t.start_date between #{startDate} and #{endDate})
  2321. or
  2322. (t.end_date between #{startDate} and #{endDate}))
  2323. </if>
  2324. group by te.executor_id,t.id
  2325. order by d.department_id,u.id
  2326. ) as total
  2327. </select>
  2328. <select id="getOnlyJoinProjectsPage" resultType="java.util.Map">
  2329. SELECT id, project_code AS projectCode, project_name AS projectName
  2330. FROM project
  2331. WHERE status = 1 and (id IN (
  2332. SELECT project_id
  2333. FROM participation
  2334. WHERE user_id = #{userId}
  2335. )
  2336. or (is_public = 1 and company_id = #{companyId}))
  2337. <if test="infoString !=null and infoString!='' ">
  2338. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2339. </if>
  2340. ORDER BY is_public DESC, id ASC
  2341. limit #{pageIndex},#{pageSize}
  2342. </select>
  2343. <select id="getOnlyJoinProjectsTotal" resultType="java.lang.Integer">
  2344. SELECT count(*) total
  2345. FROM project
  2346. WHERE status = 1 and (id IN (
  2347. SELECT project_id
  2348. FROM participation
  2349. WHERE user_id = #{userId}
  2350. )
  2351. or (is_public = 1 and company_id = #{companyId}))
  2352. <if test="infoString !=null and infoString!='' ">
  2353. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2354. </if>
  2355. </select>
  2356. <select id="getOnlyJoinProjectsById" resultType="java.util.Map">
  2357. SELECT id, project_code AS projectCode, project_name AS projectName
  2358. FROM project
  2359. WHERE status = 1 and (id IN (
  2360. SELECT project_id
  2361. FROM participation
  2362. WHERE user_id = #{userId}
  2363. )
  2364. or (is_public = 1 and company_id = #{companyId}))
  2365. and id =#{projectId}
  2366. </select>
  2367. <select id="getParticipatedProjectPage" resultType="java.util.Map">
  2368. SELECT id, project_code AS projectCode, project_name AS projectName
  2369. FROM project
  2370. WHERE id IN (
  2371. SELECT project_id
  2372. FROM participation
  2373. WHERE user_id = #{userId}
  2374. ) or incharger_id = #{userId}
  2375. or creator_id = #{userId}
  2376. or (is_public = 1 and company_id = #{companyId})
  2377. <if test="infoString !=null and infoString!='' ">
  2378. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2379. </if>
  2380. ORDER BY is_public DESC, id DESC
  2381. limit #{pageIndex},#{pageSize}
  2382. </select>
  2383. <select id="getParticipatedProjectTotal" resultType="java.lang.Integer">
  2384. SELECT count(*) total
  2385. FROM project
  2386. WHERE id IN (
  2387. SELECT project_id
  2388. FROM participation
  2389. WHERE user_id = #{userId}
  2390. ) or incharger_id = #{userId}
  2391. or creator_id = #{userId}
  2392. or (is_public = 1 and company_id = #{companyId})
  2393. <if test="infoString !=null and infoString!='' ">
  2394. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2395. </if>
  2396. </select>
  2397. <select id="getParticipatedProjectById" resultType="java.util.Map">
  2398. SELECT count(*) total
  2399. FROM project
  2400. WHERE id IN (
  2401. SELECT project_id
  2402. FROM participation
  2403. WHERE user_id = #{userId}
  2404. ) or incharger_id = #{userId}
  2405. or creator_id = #{userId}
  2406. or (is_public = 1 and company_id = #{companyId})
  2407. and id =#{projectId}
  2408. </select>
  2409. <select id="getTimeCostGroupByProjectUserSumTime" resultType="java.util.Map">
  2410. SELECT a.id, a.project_code as projectCode, a.project_name AS projectName,a.category_name as categoryName,
  2411. c.name name,sum(b.working_time) AS cost,
  2412. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
  2413. c.id userId
  2414. FROM project AS a
  2415. LEFT JOIN report AS b ON b.project_id = a.id
  2416. JOIN user AS c ON b.creator_id = c.id
  2417. left join department on department.department_id = b.dept_id
  2418. WHERE a.company_id = #{companyId}
  2419. <if test="startDate != null and endDate != null">
  2420. AND b.create_date between #{startDate} and #{endDate}
  2421. </if>
  2422. AND b.state = 1
  2423. group by id,projectCode,projectName,categoryName,name
  2424. ORDER BY a.id ASC
  2425. </select>
  2426. <select id="getTimeCostProjectUserWorkTime" resultType="java.util.Map">
  2427. SELECT a.id, a.project_code as projectCode,a.project_name AS projectName,a.category_name as categoryName,
  2428. c.name name,b.working_time cost,
  2429. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
  2430. b.create_date createDate,DAY(b.create_date) dayOnly,c.id userId
  2431. FROM project AS a
  2432. LEFT JOIN report AS b ON b.project_id = a.id
  2433. JOIN user AS c ON b.creator_id = c.id
  2434. left join department on department.department_id = b.dept_id
  2435. WHERE a.company_id = #{companyId}
  2436. <if test="startDate != null and endDate != null">
  2437. AND b.create_date between #{startDate} and #{endDate}
  2438. </if>
  2439. AND b.state = 1
  2440. ORDER BY a.id ASC ,c.name asc
  2441. </select>
  2442. <select id="getCostTimeByUserSum" resultType="java.util.Map">
  2443. SELECT c.id userId, c.job_number jobNumber,c.name name,sum(b.working_time) AS cost,
  2444. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName
  2445. FROM project AS a
  2446. LEFT JOIN report AS b ON b.project_id = a.id
  2447. JOIN user AS c ON b.creator_id = c.id
  2448. left join department on department.department_id = b.dept_id
  2449. WHERE c.company_id = #{companyId}
  2450. <if test="startDate != null and endDate != null">
  2451. AND b.create_date between #{startDate} and #{endDate}
  2452. </if>
  2453. AND b.state = 1
  2454. group by userId
  2455. </select>
  2456. <select id="getCostTimeByUserForDay" resultType="java.util.Map">
  2457. SELECT c.id userId, c.job_number jobNumber,c.name name,b.working_time AS cost, a.id projectId,a.project_name ,
  2458. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
  2459. DAY(b.create_date) dayOnly
  2460. FROM project AS a
  2461. LEFT JOIN report AS b ON b.project_id = a.id
  2462. JOIN user AS c ON b.creator_id = c.id
  2463. left join department on department.department_id = b.dept_id
  2464. WHERE c.company_id = #{companyId}
  2465. <if test="startDate != null and endDate != null">
  2466. AND b.create_date between #{startDate} and #{endDate}
  2467. </if>
  2468. AND b.state = 1
  2469. </select>
  2470. <select id="getTotalProjectByTime" resultType="java.util.Map">
  2471. SELECT
  2472. a.id projectId,a.project_name projectName
  2473. FROM project AS a
  2474. LEFT JOIN report AS b ON b.project_id = a.id
  2475. JOIN user AS c ON b.creator_id = c.id
  2476. left join department on department.department_id = b.dept_id
  2477. WHERE c.company_id = #{companyId}
  2478. <if test="startDate != null and endDate != null">
  2479. AND b.create_date between #{startDate} and #{endDate}
  2480. </if>
  2481. AND b.state = 1
  2482. GROUP BY projectId
  2483. </select>
  2484. <select id="selectProjectEestimatedWorkTimeList" resultType="java.util.Map">
  2485. SELECT
  2486. p.id AS projectId,
  2487. p.project_code AS projectCode,
  2488. p.project_name AS projectName,
  2489. CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END AS estimatedWorkTime,
  2490. SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END) AS workTime,
  2491. (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) AS remainWorkTime,
  2492. CASE
  2493. WHEN (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END) = 0 THEN NULL
  2494. ELSE ROUND((CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) / (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END), 4)
  2495. END AS remainWorkTimeProportion
  2496. FROM
  2497. project p
  2498. LEFT JOIN
  2499. report r ON p.id = r.project_id
  2500. WHERE
  2501. p.company_id = #{map.companyId}
  2502. AND p.`status` IN (1, 2)
  2503. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2504. <if test="map.projectId!=null">
  2505. AND p.id = #{map.projectId}
  2506. </if>
  2507. GROUP BY
  2508. p.id, p.project_code, p.project_name
  2509. <if test="map.isWarn!=null and map.isWarn==1 ">
  2510. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2511. </if>
  2512. <if test="map.pageIndex!=null and map.pageSize!=null ">
  2513. LIMIT #{map.pageIndex}, #{map.pageSize}
  2514. </if>
  2515. </select>
  2516. <select id="selectProjectEestimatedWorkTimeCount" resultType="java.lang.Integer">
  2517. SELECT
  2518. count(1) total
  2519. FROM
  2520. (
  2521. SELECT
  2522. p.id AS projectId,
  2523. (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) AS remainWorkTime,
  2524. CASE
  2525. WHEN (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END) = 0 THEN NULL
  2526. ELSE ROUND((CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) / (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END), 4)
  2527. END AS remainWorkTimeProportion
  2528. FROM
  2529. project p
  2530. LEFT JOIN
  2531. report r ON p.id = r.project_id
  2532. WHERE
  2533. p.company_id = #{map.companyId}
  2534. AND p.`status` IN (1, 2)
  2535. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2536. <if test="map.projectId!=null">
  2537. AND p.id = #{map.projectId}
  2538. </if>
  2539. GROUP BY
  2540. p.id, p.project_code, p.project_name
  2541. <if test="map.isWarn!=null and map.isWarn==1 ">
  2542. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2543. </if>
  2544. ) a
  2545. </select>
  2546. <select id="selectGroupEestimatedWorkTimeList" resultType="java.util.Map">
  2547. SELECT
  2548. p.id AS projectId,
  2549. p.project_code AS projectCode,
  2550. p.project_name AS projectName,
  2551. g.`name` groupName,
  2552. g.id id,
  2553. CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END AS estimatedWorkTime,
  2554. SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
  2555. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2556. END) AS workTime,
  2557. (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
  2558. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2559. END)) AS remainWorkTime,
  2560. CASE
  2561. WHEN (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END) = 0 THEN NULL
  2562. ELSE ROUND((CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
  2563. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2564. END)) / (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END),4)
  2565. END AS remainWorkTimeProportion
  2566. FROM
  2567. project p
  2568. LEFT JOIN
  2569. report r ON p.id = r.project_id
  2570. LEFT JOIN
  2571. task_group g ON g.project_id =p.id
  2572. WHERE
  2573. p.company_id = #{map.companyId}
  2574. AND p.`status` IN (1, 2)
  2575. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2576. <if test="map.projectId!=null">
  2577. AND p.id = #{map.projectId}
  2578. </if>
  2579. GROUP BY
  2580. p.id,g.`name`,g.id
  2581. <if test="map.isWarn!=null and map.isWarn==1 ">
  2582. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2583. </if>
  2584. <if test="map.pageIndex!=null and map.pageSize!=null ">
  2585. LIMIT #{map.pageIndex}, #{map.pageSize}
  2586. </if>
  2587. </select>
  2588. <select id="selectGroupEestimatedWorkTimeCount" resultType="java.lang.Integer">
  2589. SELECT
  2590. count(*)
  2591. FROM
  2592. (
  2593. SELECT
  2594. p.id AS projectId,
  2595. g.`name` groupName,
  2596. g.id id,
  2597. CASE
  2598. WHEN (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END) = 0 THEN NULL
  2599. ELSE ROUND((CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
  2600. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2601. END)) / (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END),4)
  2602. END AS remainWorkTimeProportion
  2603. FROM
  2604. project p
  2605. LEFT JOIN
  2606. report r ON p.id = r.project_id
  2607. LEFT JOIN
  2608. task_group g ON g.project_id =p.id
  2609. WHERE
  2610. p.company_id = #{map.companyId}
  2611. AND p.`status` IN (1, 2)
  2612. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2613. <if test="map.projectId!=null">
  2614. AND p.id = #{map.projectId}
  2615. </if>
  2616. GROUP BY
  2617. p.id,g.`name`,g.id
  2618. <if test="map.isWarn!=null and map.isWarn==1 ">
  2619. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2620. </if>
  2621. ) a
  2622. </select>
  2623. <select id="getParticipatedProjectWithMainProjectId" resultType="java.util.Map">
  2624. 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
  2625. FROM project
  2626. WHERE id IN (
  2627. SELECT project_id
  2628. FROM participation
  2629. WHERE user_id = #{userId}
  2630. ) or incharger_id = #{userId}
  2631. or creator_id = #{userId}
  2632. or (is_public = 1 and company_id = #{companyId})
  2633. and project_main_id = #{projectMainId}
  2634. ORDER BY is_public DESC, id DESC
  2635. </select>
  2636. <select id="getProjectInAndOutTotal" resultType="java.lang.Integer">
  2637. SELECT count(*) total
  2638. FROM project
  2639. left join contract on contract.project_id = project.id
  2640. WHERE project.`company_id` = #{companyId}
  2641. and (project.status &lt;&gt; 3 or project.status is null)
  2642. <if test="projectId != null">
  2643. and project.id = #{projectId}
  2644. </if>
  2645. <if test="projectMainId != null">
  2646. and project.project_main_id = #{projectMainId}
  2647. </if>
  2648. <if test="inchagerIds!=null and inchagerIds.size()>0">
  2649. and project.id in
  2650. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  2651. #{item}
  2652. </foreach>
  2653. </if>
  2654. </select>
  2655. <select id="getTaskPlanByGeneralMemb" resultType="java.util.Map">
  2656. 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,
  2657. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2658. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId,
  2659. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2660. FROM user
  2661. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2662. left join task on task.id = task_executor.task_id
  2663. LEFT JOIN project ON project.`id` = task.`project_id`
  2664. WHERE user.`id` IN
  2665. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  2666. #{item}
  2667. </foreach>
  2668. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2669. and task.end_date is not null
  2670. <if test="targetUserId !=null and targetUserId !='' ">
  2671. and user.`id`=#{targetUserId}
  2672. </if>
  2673. AND project.`status` = 1
  2674. ORDER BY user.id, task.start_date
  2675. </select>
  2676. <select id="getTaskPlanWithLeave" resultType="java.util.Map">
  2677. SELECT user.`id` as user_id, user.`name`,task.id as task_id, task.name as task_name,task_executor.id as exe_id,
  2678. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2679. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId,
  2680. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2681. FROM user
  2682. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2683. left join task on task.id = task_executor.task_id
  2684. WHERE
  2685. ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2686. and task.end_date is not null and task.task_plan_type=3 and task.task_plan=1
  2687. <if test="targetUserId !=null and targetUserId !='' ">
  2688. and user.`id`=#{targetUserId}
  2689. </if>
  2690. ORDER BY user.id, task.start_date
  2691. </select>
  2692. <select id="getTaskPlanByProManager" resultType="java.util.Map">
  2693. 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,
  2694. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2695. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId,
  2696. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2697. FROM user
  2698. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2699. left join task on task.id = task_executor.task_id
  2700. LEFT JOIN project ON project.`id` = task.`project_id`
  2701. WHERE user.`id` IN
  2702. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  2703. #{item}
  2704. </foreach>
  2705. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2706. and task.end_date is not null and task.is_task_plan=1 and task.task_status=3 and task.check_first_id=#{managerId}
  2707. AND project.`status` = 1
  2708. <if test="targetUserId !=null and targetUserId !='' ">
  2709. and user.`id`=#{targetUserId}
  2710. </if>
  2711. ORDER BY user.id, task.start_date
  2712. </select>
  2713. <select id="getTaskPlanByAreaManager" resultType="java.util.Map">
  2714. 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,
  2715. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2716. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId,
  2717. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2718. FROM user
  2719. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2720. left join task on task.id = task_executor.task_id
  2721. LEFT JOIN project ON project.`id` = task.`project_id`
  2722. WHERE user.`id` IN
  2723. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  2724. #{item}
  2725. </foreach>
  2726. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2727. and task.end_date is not null and task.is_task_plan=1 and task.task_status=4 and task.check_second_id=#{managerId}
  2728. AND project.`status` = 1
  2729. <if test="targetUserId !=null and targetUserId !='' ">
  2730. and user.`id`=#{targetUserId}
  2731. </if>
  2732. ORDER BY user.id, task.start_date
  2733. </select>
  2734. <select id="getTaskPlanByProjectGeneralMemb" resultType="java.util.Map">
  2735. 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,
  2736. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId
  2737. ,task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
  2738. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  2739. LEFT JOIN task ON task.project_id = project.id
  2740. <if test="groupName !=null and groupName !='' ">
  2741. LEFT JOIN task_group tg ON tg.project_id = project.id
  2742. </if>
  2743. WHERE project.company_id = #{companyId}
  2744. <if test="projectIds != null">
  2745. and project.`id` IN
  2746. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  2747. #{item}
  2748. </foreach>
  2749. </if>
  2750. <if test="groupName !=null and groupName !='' ">
  2751. and tg.name = #{groupName} and task.group_id=tg.id
  2752. </if>
  2753. <if test="taskType !=null ">
  2754. and task.task_type = #{taskType}
  2755. </if>
  2756. <if test="targetProjectId !=null ">
  2757. and project.`id` = #{targetProjectId}
  2758. </if>
  2759. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2760. and task.end_date is not null
  2761. AND project.`status` = 1
  2762. ORDER BY project.id, task.start_date
  2763. </select>
  2764. <select id="getTaskPlanByProjectManager" resultType="java.util.Map">
  2765. 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,
  2766. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId
  2767. ,task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
  2768. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  2769. LEFT JOIN task ON task.project_id = project.id
  2770. <if test="groupName !=null and groupName !='' ">
  2771. LEFT JOIN task_group tg ON tg.project_id = project.id
  2772. </if>
  2773. WHERE project.company_id = #{companyId}
  2774. <if test="projectIds != null">
  2775. and project.`id` IN
  2776. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  2777. #{item}
  2778. </foreach>
  2779. </if>
  2780. <if test="groupName !=null and groupName !='' ">
  2781. and tg.name = #{groupName} and task.group_id=tg.id
  2782. </if>
  2783. <if test="taskType !=null ">
  2784. and task.task_type = #{taskType}
  2785. </if>
  2786. <if test="targetProjectId !=null ">
  2787. and project.`id` = #{targetProjectId}
  2788. </if>
  2789. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2790. and task.end_date is not null and task.is_task_plan=1 and task.task_status=3 and task.check_first_id=#{managerId}
  2791. AND project.`status` = 1
  2792. ORDER BY project.id, task.start_date
  2793. </select>
  2794. <select id="getTaskPlanByProjectAreaManager" resultType="java.util.Map">
  2795. 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,
  2796. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,task.check_first_id as checkFirstId,task.check_second_id as checkSecondId
  2797. ,task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
  2798. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  2799. LEFT JOIN task ON task.project_id = project.id
  2800. <if test="groupName !=null and groupName !='' ">
  2801. LEFT JOIN task_group tg ON tg.project_id = project.id
  2802. </if>
  2803. WHERE project.company_id = #{companyId}
  2804. <if test="projectIds != null">
  2805. and project.`id` IN
  2806. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  2807. #{item}
  2808. </foreach>
  2809. </if>
  2810. <if test="groupName !=null and groupName !='' ">
  2811. and tg.name = #{groupName} and task.group_id=tg.id
  2812. </if>
  2813. <if test="taskType !=null ">
  2814. and task.task_type = #{taskType}
  2815. </if>
  2816. <if test="targetProjectId !=null ">
  2817. and project.`id` = #{targetProjectId}
  2818. </if>
  2819. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2820. and task.end_date is not null and task.is_task_plan=1 and task.task_status=4 and task.check_second_id=#{managerId}
  2821. AND project.`status` = 1
  2822. ORDER BY project.id, task.start_date
  2823. </select>
  2824. <select id="getFTETaskPlanData" resultType="java.util.Map">
  2825. select t.id, u.plate1 area, p.project_code projectCode,p.project_name projectName,u.name userName, t.plan_hours planHours from task t
  2826. left join project p on t.project_id=p.id
  2827. LEFT JOIN task_executor te on t.id=te.task_id
  2828. INNER JOIN user u on u.id=te.executor_id
  2829. WHERE u.company_id=#{companyId} and t.task_plan=1 and t.task_status &lt;3 and t.task_plan_type !=3
  2830. <if test="area!=null and area != '' ">
  2831. and u.plate1 = #{area}
  2832. </if>
  2833. <if test="userId!=null and userId != '' ">
  2834. and u.id = #{userId}
  2835. </if>
  2836. <if test="deptIds!=null and deptIds.size()>0">
  2837. and u.department_id in
  2838. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  2839. #{item}
  2840. </foreach>
  2841. </if>
  2842. <if test=" startDate!= null and endDate!= null">
  2843. AND
  2844. (
  2845. (
  2846. (t.start_date IS NULL OR t.start_date &lt;= #{startDate}) AND (t.end_date &gt;= #{startDate} AND t.end_date &lt;= #{endDate})
  2847. )
  2848. OR
  2849. (
  2850. (t.end_date IS NULL OR t.end_date &gt;= #{endDate}) AND (t.start_date &gt;= #{startDate} AND t.start_date &lt;= #{endDate})
  2851. )
  2852. OR
  2853. (
  2854. t.start_date IS NOT NULL AND t.end_date IS NOT NULL AND t.start_date &gt;= #{startDate}
  2855. AND t.start_date &lt;= #{endDate} AND t.end_date &gt;= #{startDate} AND t.end_date &lt;= #{endDate}
  2856. )
  2857. OR
  2858. (
  2859. t.start_date IS NOT NULL AND t.end_date IS NOT NULL AND t.start_date &lt;= #{startDate} AND t.end_date &gt; #{endDate}
  2860. )
  2861. )
  2862. </if>
  2863. <if test=" startDate != null and endDate == null">
  2864. AND (t.end_date IS NOT NULL and t.end_date &gt;= #{startDate})
  2865. </if>
  2866. <if test=" startDate == null and endDate != null">
  2867. AND (t.start_date IS NOT NULL and t.start_date &lt;= #{endDate})
  2868. </if>
  2869. </select>
  2870. <select id="getRelatedProjectIds" resultType="java.lang.Integer">
  2871. SELECT DISTINCT pl.project_id
  2872. FROM project_leader pl
  2873. WHERE pl.leader_id = #{userId}
  2874. UNION
  2875. SELECT DISTINCT p.id
  2876. FROM project p
  2877. INNER JOIN task t ON t.project_id = p.id
  2878. WHERE p.company_id = #{companyId}
  2879. AND (t.check_first_id = #{userId} OR t.check_second_id = #{userId})
  2880. </select>
  2881. </mapper>