ProjectMapper.xml 141 KB

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