ProjectMapper.xml 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036
  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) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  726. and task.end_date is not null
  727. AND (project.`status` = 1 or project.`status` is null)
  728. <if test="deptId !=null">
  729. and user.department_id= #{deptId}
  730. </if>
  731. <if test="taskStatus != null">
  732. <choose>
  733. <when test="taskStatus == 0">
  734. and task.task_status in (3, 4)
  735. </when>
  736. <when test="taskStatus == 1">
  737. and task.task_status = 1
  738. </when>
  739. <when test="taskStatus == 2">
  740. and task.task_status in (5, 6)
  741. </when>
  742. <when test="taskStatus == 3">
  743. and task.task_status = 2
  744. </when>
  745. </choose>
  746. </if>
  747. ORDER BY user.id, task.start_date
  748. </select>
  749. <select id="getTaskPlanByProject" resultType="java.util.Map">
  750. 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,
  751. 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,
  752. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  753. LEFT JOIN task ON task.project_id = project.id
  754. left join task_type on task_type.id = task.task_plan_type
  755. <if test="groupName !=null and groupName !='' ">
  756. LEFT JOIN task_group tg ON tg.project_id = project.id
  757. </if>
  758. WHERE project.company_id = #{companyId}
  759. <if test="projectIds != null">
  760. and project.`id` IN
  761. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  762. #{item}
  763. </foreach>
  764. </if>
  765. <if test="groupName !=null and groupName !='' ">
  766. and tg.name = #{groupName} and task.group_id=tg.id
  767. </if>
  768. <if test="taskType !=null ">
  769. and task.task_plan_type = #{taskType}
  770. </if>
  771. <if test="userIds != null">
  772. and exists(select 1 from task_executor where task.id=task_executor.task_id
  773. and task_executor.executor_id in <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">#{item}</foreach>)
  774. </if>
  775. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  776. and task.end_date is not null
  777. AND project.`status` = 1
  778. ORDER BY project.id, task.start_date
  779. </select>
  780. <!-- 获取某个员工的某时间段内的加班详情 -->
  781. <select id="getOvertimeDetail" resultType="java.util.Map">
  782. SELECT report.id AS reportId,date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  783. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  784. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  785. project.project_name as projectName,project.project_code as projectCode,
  786. IFNULL(report.overtime_cost, 0) AS cost,
  787. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName,
  788. (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
  789. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  790. left join project on project.id = report.project_id
  791. left join report_extra_degree on report_extra_degree.id = report.degree_id
  792. left join department on department.department_id = report.dept_id
  793. LEFT JOIN report_write_off rwo ON rwo.`report_id`=report.`id`
  794. WHERE report.is_overtime = 1
  795. and report.`state` = 1
  796. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  797. AND user.`company_id` = #{companyId}
  798. <if test="projectId != null">
  799. AND report.`project_id` = #{projectId}
  800. </if>
  801. <if test="userId != null">
  802. AND report.`creator_id` = #{userId}
  803. </if>
  804. <if test="branchDepartment!=null and branchDepartment.size()>0">
  805. and report.dept_id in
  806. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  807. #{item}
  808. </foreach>
  809. </if>
  810. <if test="deptIds!=null and deptIds.size()>0">
  811. and report.dept_id in
  812. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  813. #{item}
  814. </foreach>
  815. </if>
  816. <if test="writeOffValue!=null">
  817. <choose>
  818. <when test="writeOffValue==1">
  819. and rwo.write_off=1
  820. </when>
  821. <otherwise>
  822. and (rwo.write_off is null or rwo.write_off=0)
  823. </otherwise>
  824. </choose>
  825. </if>
  826. order by user.create_time asc, report.create_date desc
  827. </select>
  828. <!--获取人员工时-->
  829. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  830. 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,
  831. user.department_id As deptId,
  832. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  833. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  834. ifnull(SUM(report.`working_time`),0) AS workingTime,
  835. ifnull(SUM(report.`overtime_hours`),0) AS overtimeHours
  836. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  837. left join project on project.id = report.project_id
  838. WHERE
  839. report.`state` = 1
  840. AND user.`is_active` = 1
  841. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  842. AND user.`company_id` =#{companyId}
  843. <if test="userId!=null">
  844. and user.id=#{userId}
  845. </if>
  846. <if test="projectId!=null">
  847. and project.id=#{projectId}
  848. </if>
  849. <if test="branchDepartment!=null and branchDepartment.size()>0">
  850. and report.dept_id in
  851. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  852. #{item}
  853. </foreach>
  854. </if>
  855. <if test="deptIds!=null and deptIds.size()>0">
  856. and report.dept_id in
  857. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  858. #{item}
  859. </foreach>
  860. </if>
  861. group by user.id
  862. order by user.create_time asc, report.create_date desc
  863. <if test="start!=null and size!=null">
  864. limit #{start},#{size}
  865. </if>
  866. </select>
  867. <select id="findCountWithUser" resultType="java.lang.Long">
  868. select count(*)
  869. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  870. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  871. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  872. ifnull(SUM(report.`working_time`),0) AS workingTime
  873. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  874. left join project on project.id = report.project_id
  875. WHERE
  876. report.`state` = 1
  877. AND user.`is_active` = 1
  878. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  879. AND user.`company_id` =#{companyId}
  880. <if test="userId!=null">
  881. and user.id=#{userId}
  882. </if>
  883. <if test="projectId!=null">
  884. and project.id=#{projectId}
  885. </if>
  886. <if test="departmentId!=null">
  887. and report.dept_id=#{departmentId}
  888. </if>
  889. <if test="deptIds!=null and deptIds.size()>0">
  890. and report.dept_id in
  891. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  892. #{item}
  893. </foreach>
  894. </if>
  895. group by user.id
  896. order by user.create_time asc, report.create_date desc
  897. <if test="start!=null and size!=null">
  898. limit #{start},#{size}
  899. </if>) as total
  900. </select>
  901. <!--按照项目内的阶段名称分组统计工时-->
  902. <select id="getDegreeCost" resultType="java.util.Map">
  903. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
  904. FROM report AS a
  905. left join report_extra_degree b on b.id = a.degree_id
  906. WHERE
  907. a.state = 1
  908. and a.company_id = #{companyId}
  909. <if test="departmentIds!=null and departmentIds.size()>0">
  910. and a.dept_id in
  911. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  912. #{item}
  913. </foreach>
  914. </if>
  915. <if test="projectId != null">
  916. and a.project_id = #{projectId}
  917. </if>
  918. <if test="userId != null and userId!=''">
  919. and a.creator_id = #{userId}
  920. </if>
  921. <if test="startDate != null and endDate != null">
  922. AND a.create_date between #{startDate} and #{endDate}
  923. </if>
  924. GROUP BY a.degree_id
  925. ORDER BY a.degree_id ASC
  926. </select>
  927. <!--项目导出数据-->
  928. <select id="getExportData" resultType="java.util.HashMap" >
  929. 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,
  930. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  931. customer_name, associate_degree_names, provider_names,provider_ids
  932. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  933. LEFT JOIN participation c ON c.project_id = project.`id`
  934. LEFT JOIN user u ON u.id = c.user_id
  935. LEFT JOIN user d ON d.id = project.`incharger_id`
  936. WHERE project.`company_id` = #{companyId}
  937. <if test="userId != null" >
  938. and (project.creator_id = #{userId} or c.user_id = #{userId})
  939. </if>
  940. GROUP BY project.id
  941. </select>
  942. <!--按项目分组导出数据-->
  943. <select id="getExportGroupData" resultType="java.util.Map" >
  944. SELECT project_code AS projectCode,project_name AS projectName,task_group.`name` AS groupName,task_group.`incharger_id` AS inchargerId,
  945. GROUP_CONCAT(group_participator.`user_id`) AS participatorIds
  946. FROM task_group
  947. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  948. LEFT JOIN project ON task_group.project_id = project.id
  949. <if test="projectCategorySub!=null and projectCategorySub!=''">
  950. left join project_separate ps on ps.id=project.id
  951. </if>
  952. where project.company_id = #{companyId}
  953. <if test="projectCategorySub!=null and projectCategorySub!=''">
  954. and ps.project_category_sub=#{projectCategorySub}
  955. </if>
  956. GROUP BY task_group.id
  957. ORDER BY project_id
  958. </select>
  959. <!--分页获取项目工时成本预警表 -->
  960. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  961. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  962. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  963. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  964. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  965. AND project_id=project.id) AS costLimit,
  966. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  967. FROM project WHERE company_id=#{companyId}
  968. and (project.status &lt;&gt; 3 or project.status is null)
  969. <if test="projectId != null">
  970. and project.id = #{projectId}
  971. </if>
  972. <if test="pageStart != null and pageSize != null">
  973. LIMIT #{pageStart},#{pageSize}
  974. </if>
  975. </select>
  976. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  977. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  978. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  979. 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,
  980. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  981. 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,
  982. (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
  983. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  984. <if test="projectId != null">
  985. and project.id = #{projectId}
  986. </if>
  987. <if test="list!=null and list.size()>0">
  988. and project.id in
  989. <foreach collection="list" open="(" close=")" item="item" separator=",">
  990. #{item}
  991. </foreach>
  992. </if>
  993. <if test="pageStart != null and pageSize != null">
  994. LIMIT #{pageStart},#{pageSize}
  995. </if>
  996. </select>
  997. <select id="getWaitingReviewList" resultType="java.util.Map">
  998. <choose>
  999. <when test="stateKey==0">
  1000. 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
  1001. FROM report AS a
  1002. left join user on user.id = a.creator_id
  1003. JOIN project AS b ON a.project_id=b.id
  1004. left join sub_project as d on d.id = a.sub_project_id
  1005. left join task on task.id = a.task_id
  1006. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1007. left join department on department.department_id = a.audit_deptid
  1008. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1009. left join department dept on dept.department_id = a.dept_id
  1010. left join task_group on task_group.id = a.group_id
  1011. left join user u on u.id = a.project_auditor_id
  1012. WHERE a.company_id =#{companyId}
  1013. and a.state = 0
  1014. <if test="startDate!=null and endDate!=null">
  1015. AND a.create_date between #{startDate} and #{endDate}
  1016. </if>
  1017. AND a.is_dept_audit=1
  1018. <if test="userId!=null">
  1019. and dept_manager.id=#{userId}
  1020. </if>
  1021. <if test="departmentId!=null">
  1022. and dept_manager.department_id=#{departmentId}
  1023. </if>
  1024. <if test="deptIds!=null and deptIds.size()>0">
  1025. and dept_manager.department_id in
  1026. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1027. #{item}
  1028. </foreach>
  1029. </if>
  1030. group by a.audit_dept_managerid
  1031. ORDER BY a.create_date desc, a.creator_id asc
  1032. </when>
  1033. <otherwise>
  1034. 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
  1035. FROM report AS a
  1036. left join user on user.id = a.creator_id
  1037. JOIN project AS b ON a.project_id=b.id
  1038. left join sub_project as d on d.id = a.sub_project_id
  1039. left join task on task.id = a.task_id
  1040. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1041. left join department on department.department_id = a.audit_deptid
  1042. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1043. left join department dept on dept.department_id = a.dept_id
  1044. left join task_group on task_group.id = a.group_id
  1045. left join user u on u.id = a.project_auditor_id
  1046. left join department dp on u.department_id=dp.department_id
  1047. WHERE a.company_id =#{companyId}
  1048. and a.state = 0
  1049. <if test="startDate!=null and endDate!=null">
  1050. AND a.create_date between #{startDate} and #{endDate}
  1051. </if>
  1052. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1053. <if test="userId!=null">
  1054. and u.id=#{userId}
  1055. </if>
  1056. <if test="departmentId!=null">
  1057. and u.department_id=#{departmentId}
  1058. </if>
  1059. <if test="deptIds!=null and deptIds.size()>0">
  1060. and u.department_id in
  1061. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1062. #{item}
  1063. </foreach>
  1064. </if>
  1065. group by a.project_auditor_id
  1066. ORDER BY a.create_date desc, a.creator_id asc
  1067. </otherwise>
  1068. </choose>
  1069. <if test="start!=null and size!=null">
  1070. limit #{start},#{size}
  1071. </if>
  1072. </select>
  1073. <select id="findCount" resultType="java.lang.Long">
  1074. select count(1)
  1075. from (<choose>
  1076. <when test="stateKey==0">
  1077. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  1078. FROM report AS a
  1079. left join user on user.id = a.creator_id
  1080. JOIN project AS b ON a.project_id=b.id
  1081. left join sub_project as d on d.id = a.sub_project_id
  1082. left join task on task.id = a.task_id
  1083. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1084. left join department on department.department_id = a.audit_deptid
  1085. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1086. left join department dept on dept.department_id = a.dept_id
  1087. left join task_group on task_group.id = a.group_id
  1088. left join user u on u.id = a.project_auditor_id
  1089. WHERE a.company_id =#{companyId}
  1090. and a.state = 0
  1091. and u.is_active = 1
  1092. <if test="startDate!=null and endDate!=null">
  1093. AND a.create_date between #{startDate} and #{endDate}
  1094. </if>
  1095. AND a.is_dept_audit=1
  1096. <if test="userId!=null">
  1097. and dept_manager.id=#{userId}
  1098. </if>
  1099. <if test="departmentId!=null">
  1100. and dept_manager.department_id=#{departmentId}
  1101. </if>
  1102. <if test="deptIds!=null and deptIds.size()>0">
  1103. and dept_manager.department_id in
  1104. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1105. #{item}
  1106. </foreach>
  1107. </if>
  1108. group by a.audit_dept_managerid
  1109. ORDER BY a.create_date desc, a.creator_id asc
  1110. </when>
  1111. <otherwise>
  1112. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1113. FROM report AS a
  1114. left join user on user.id = a.creator_id
  1115. JOIN project AS b ON a.project_id=b.id
  1116. left join sub_project as d on d.id = a.sub_project_id
  1117. left join task on task.id = a.task_id
  1118. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1119. left join department on department.department_id = a.audit_deptid
  1120. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1121. left join department dept on dept.department_id = a.dept_id
  1122. left join task_group on task_group.id = a.group_id
  1123. left join user u on u.id = a.project_auditor_id
  1124. left join department dp on u.department_id=dp.department_id
  1125. WHERE a.company_id =#{companyId}
  1126. and a.state = 0
  1127. and u.is_active = 1
  1128. <if test="startDate!=null and endDate!=null">
  1129. AND a.create_date between #{startDate} and #{endDate}
  1130. </if>
  1131. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1132. <if test="userId!=null">
  1133. and u.id=#{userId}
  1134. </if>
  1135. <if test="departmentId!=null">
  1136. and u.department_id=#{departmentId}
  1137. </if>
  1138. <if test="deptIds!=null and deptIds.size()>0">
  1139. and u.department_id in
  1140. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1141. #{item}
  1142. </foreach>
  1143. </if>
  1144. group by a.project_auditor_id
  1145. ORDER BY a.create_date desc, a.creator_id asc
  1146. </otherwise>
  1147. </choose>
  1148. <if test="start!=null and size!=null">
  1149. limit #{start},#{size}
  1150. </if>) total
  1151. </select>
  1152. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1153. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1154. (select SUM(te.plan_hours) from task_executor te
  1155. left join task on task.id=te.task_id
  1156. where te.executor_id=us.id
  1157. <if test="startDate!=null and endDate!=null">
  1158. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1159. </if>) as planHours,
  1160. (select SUM(report.working_time) from report
  1161. left join task on task.id=report.task_id
  1162. where report.creator_id=us.id and task_id is not null and report.state=1
  1163. <if test="startDate!=null and endDate!=null">
  1164. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1165. </if>) as workingTime
  1166. from user us
  1167. left join department dp on dp.department_id=us.department_id
  1168. where us.company_id=#{companyId}
  1169. 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)
  1170. <if test="userId!=null and userId!=''">
  1171. and us.id=#{userId}
  1172. </if>
  1173. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1174. and us.department_id in
  1175. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1176. #{item}
  1177. </foreach>
  1178. </if>
  1179. <if test="deptIds!=null and deptIds.size()>0">
  1180. and us.department_id in
  1181. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1182. #{item}
  1183. </foreach>
  1184. </if>
  1185. group by us.id
  1186. order by us.department_id
  1187. <if test="start!=null and size!=null">
  1188. limit #{start},#{size}
  1189. </if>
  1190. </select>
  1191. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1192. select count(1)
  1193. from(select us.name,dp.department_name as departmentName,
  1194. (select SUM(te.plan_hours) from task_executor te
  1195. left join task on task.id=te.task_id
  1196. where te.executor_id=us.id
  1197. <if test="startDate!=null and endDate!=null">
  1198. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1199. </if>) as planHours,
  1200. (select SUM(report.working_time) from report
  1201. left join task on task.id=report.task_id
  1202. where report.creator_id=us.id and task_id is not null
  1203. <if test="startDate!=null and endDate!=null">
  1204. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1205. </if>) as workingTime
  1206. from user us
  1207. left join department dp on dp.department_id=us.department_id
  1208. where us.company_id=#{companyId}
  1209. 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)
  1210. <if test="userId!=null and userId!=''">
  1211. and us.id=#{userId}
  1212. </if>
  1213. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1214. and us.department_id in
  1215. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1216. #{item}
  1217. </foreach>
  1218. </if>
  1219. <if test="deptIds!=null and deptIds.size()>0">
  1220. and us.department_id in
  1221. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1222. #{item}
  1223. </foreach>
  1224. </if>
  1225. group by us.id
  1226. order by us.department_id)as total
  1227. </select>
  1228. <select id="selectWithGroup" resultType="java.util.Map">
  1229. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1230. from report a
  1231. left join task_group b on a.group_id=b.id
  1232. left join project c on a.project_id=c.id
  1233. where c.company_id=#{companyId}
  1234. <if test="startDate!=null and endDate!=null">
  1235. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1236. </if>
  1237. <if test="projectId!=null">
  1238. and c.id=#{projectId}
  1239. </if>
  1240. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1241. and (c.id in
  1242. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1243. #{item}
  1244. </foreach>
  1245. <!--或者按分组负责人的匹配-->
  1246. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1247. or a.group_id in
  1248. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1249. #{item}
  1250. </foreach>
  1251. </if>
  1252. )
  1253. </if>
  1254. <if test="groupId!=null">
  1255. and a.group_id=#{groupId}
  1256. </if>
  1257. group by b.name
  1258. order by c.id
  1259. <if test="startIndex!=null and endIndex!=null">
  1260. limit #{startIndex},#{endIndex}
  1261. </if>
  1262. </select>
  1263. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1264. select count(1) from(
  1265. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1266. from report a
  1267. left join task_group b on a.group_id=b.id
  1268. left join project c on a.project_id=c.id
  1269. where c.company_id=#{companyId}
  1270. <if test="startDate!=null and endDate!=null">
  1271. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1272. </if>
  1273. <if test="projectId!=null">
  1274. and c.id=#{projectId}
  1275. </if>
  1276. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1277. and (c.id in
  1278. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1279. #{item}
  1280. </foreach>
  1281. <!--或者按分组负责人的匹配-->
  1282. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1283. or a.group_id in
  1284. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1285. #{item}
  1286. </foreach>
  1287. </if>
  1288. )
  1289. </if>
  1290. <if test="groupId!=null">
  1291. and a.group_id=#{groupId}
  1292. </if>
  1293. group by b.name
  1294. order by c.id
  1295. <if test="startIndex!=null and endIndex!=null">
  1296. limit #{startIndex},#{endIndex}
  1297. </if>) as total
  1298. </select>
  1299. <select id="selectWithGroupProject" resultType="java.util.Map">
  1300. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1301. from report a
  1302. left join task_group b on a.group_id=b.id
  1303. left join project c on a.project_id=c.id
  1304. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1305. left join project_separate ps on ps.id=c.id
  1306. </if>
  1307. where c.company_id=#{companyId}
  1308. <if test="startDate!=null and endDate!=null">
  1309. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1310. </if>
  1311. <if test="projectId!=null">
  1312. and c.id=#{projectId}
  1313. </if>
  1314. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1315. and ps.project_category_sub=#{projectCategorySub}
  1316. </if>
  1317. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1318. and (c.id in
  1319. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1320. #{item}
  1321. </foreach>
  1322. <!--或者按分组负责人的匹配-->
  1323. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1324. or a.group_id in
  1325. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1326. #{item}
  1327. </foreach>
  1328. </if>
  1329. )
  1330. </if>
  1331. <if test="groupId!=null">
  1332. and a.group_id=#{groupId}
  1333. </if>
  1334. group by c.id,b.id
  1335. order by c.id
  1336. <if test="startIndex!=null and endIndex!=null">
  1337. limit #{startIndex},#{endIndex}
  1338. </if>
  1339. </select>
  1340. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1341. select count(1) from(
  1342. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1343. from report a
  1344. left join task_group b on a.group_id=b.id
  1345. left join project c on a.project_id=c.id
  1346. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1347. left join project_separate ps on ps.id=c.id
  1348. </if>
  1349. where c.company_id=#{companyId}
  1350. <if test="startDate!=null and endDate!=null">
  1351. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1352. </if>
  1353. <if test="projectId!=null">
  1354. and c.id=#{projectId}
  1355. </if>
  1356. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1357. and ps.project_category_sub=#{projectCategorySub}
  1358. </if>
  1359. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1360. and (c.id in
  1361. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1362. #{item}
  1363. </foreach>
  1364. <!--或者按分组负责人的匹配-->
  1365. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1366. or a.group_id in
  1367. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1368. #{item}
  1369. </foreach>
  1370. </if>
  1371. )
  1372. </if>
  1373. <if test="groupId!=null">
  1374. and a.group_id=#{groupId}
  1375. </if>
  1376. group by c.id,b.id
  1377. order by c.id
  1378. <if test="startIndex!=null and endIndex!=null">
  1379. limit #{startIndex},#{endIndex}
  1380. </if>) as total
  1381. </select>
  1382. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1383. 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
  1384. from report a
  1385. left join task_group b on a.group_id=b.id
  1386. left join project c on a.project_id=c.id
  1387. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1388. where c.company_id=#{companyId} and a.state=1
  1389. <if test="startDate!=null and endDate!=null">
  1390. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1391. </if>
  1392. <if test="projectId!=null">
  1393. and c.id=#{projectId}
  1394. </if>
  1395. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1396. and c.id in
  1397. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1398. #{item}
  1399. </foreach>
  1400. </if>
  1401. <if test="gpNamesList !=null">
  1402. and b.name in
  1403. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1404. #{item}
  1405. </foreach>
  1406. </if>
  1407. group by c.id,b.id
  1408. <if test="start!=null and size!=null">
  1409. limit #{start},#{size}
  1410. </if>
  1411. </select>
  1412. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1413. select count(1) from
  1414. (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
  1415. from report a
  1416. left join task_group b on a.group_id=b.id
  1417. left join project c on a.project_id=c.id
  1418. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1419. where c.company_id=#{companyId} and a.state=1
  1420. <if test="startDate!=null and endDate!=null">
  1421. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1422. </if>
  1423. <if test="projectId!=null">
  1424. and c.id=#{projectId}
  1425. </if>
  1426. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1427. and c.id in
  1428. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1429. #{item}
  1430. </foreach>
  1431. </if>
  1432. <if test="gpNamesList !=null">
  1433. and b.name in
  1434. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1435. #{item}
  1436. </foreach>
  1437. </if>
  1438. group by c.id,b.id
  1439. <if test="start!=null and size!=null">
  1440. limit #{start},#{size}
  1441. </if>) as total
  1442. </select>
  1443. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1444. 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
  1445. from report a
  1446. left join task_group b on a.group_id=b.id
  1447. left join project c on a.project_id=c.id
  1448. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1449. where c.company_id=#{companyId} and a.state=1
  1450. <if test="startDate!=null and endDate!=null">
  1451. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1452. </if>
  1453. <if test="projectId!=null">
  1454. and c.id=#{projectId}
  1455. </if>
  1456. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1457. and c.id in
  1458. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1459. #{item}
  1460. </foreach>
  1461. </if>
  1462. <if test="gpNamesList !=null">
  1463. and b.name in
  1464. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1465. #{item}
  1466. </foreach>
  1467. </if>
  1468. group by c.id,f.id
  1469. <if test="start!=null and size!=null">
  1470. limit #{start},#{size}
  1471. </if>
  1472. </select>
  1473. <select id="getCostByUserCustom" resultType="java.util.Map">
  1474. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1475. FROM user AS a
  1476. LEFT JOIN report AS b ON a.id = b.creator_id
  1477. LEFT JOIN project AS c ON b.project_id = c.id
  1478. left join user_custom uc on uc.company_id=a.company_id
  1479. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1480. WHERE b.state = 1
  1481. AND a.company_id = #{companyId}
  1482. <if test="startDate!=null and endDate!=null">
  1483. AND b.create_date between #{startDate} and #{endDate}
  1484. </if>
  1485. and uc.id=#{customId}
  1486. <if test="deptIds!=null and deptIds.size()>0">
  1487. and a.department_id in
  1488. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1489. #{item}
  1490. </foreach>
  1491. </if>
  1492. <if test="subCustomName!=null">
  1493. and suc.name=#{subCustomName}
  1494. </if>
  1495. GROUP BY suc.name
  1496. </select>
  1497. <select id="getEmpMonthHours" resultType="java.util.Map">
  1498. 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,
  1499. (select allday from time_type te
  1500. where te.company_id=#{companyId}) as allday,
  1501. (select SUM(report.working_time) from report
  1502. where report.creator_id=us.id and report.state=1
  1503. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1504. as workingTime
  1505. from user us
  1506. left join department dp on dp.department_id=us.department_id
  1507. where us.company_id=#{companyId}
  1508. 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)
  1509. <if test="userId!=null and userId!=''">
  1510. and us.id=#{userId}
  1511. </if>
  1512. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1513. and us.department_id in
  1514. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1515. #{item}
  1516. </foreach>
  1517. </if>
  1518. <if test="deptIds!=null and deptIds.size()>0">
  1519. and us.department_id in
  1520. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1521. #{item}
  1522. </foreach>
  1523. </if>
  1524. group by us.id
  1525. order by us.department_id
  1526. <if test="start!=null and size!=null">
  1527. limit #{start},#{size}
  1528. </if>
  1529. </select>
  1530. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1531. select count(1)
  1532. from(select us.name,dp.department_name as departmentName,
  1533. (select SUM(report.working_time) from report
  1534. where report.creator_id=us.id
  1535. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1536. as workingTime
  1537. from user us
  1538. left join department dp on dp.department_id=us.department_id
  1539. where us.company_id=#{companyId}
  1540. 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)
  1541. <if test="userId!=null and userId!=''">
  1542. and us.id=#{userId}
  1543. </if>
  1544. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1545. and us.department_id in
  1546. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1547. #{item}
  1548. </foreach>
  1549. </if>
  1550. <if test="deptIds!=null and deptIds.size()>0">
  1551. and us.department_id in
  1552. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1553. #{item}
  1554. </foreach>
  1555. </if>
  1556. group by us.id
  1557. order by us.department_id)as total
  1558. </select>
  1559. <!-- 分页查询部门参与项目情况-->
  1560. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1561. SELECT department.department_id deptId,
  1562. department_name deptName,
  1563. (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,
  1564. pro.projectCount projectCount,
  1565. pro.centerCount centerCount,
  1566. pcon.peopleCount peopleCount
  1567. FROM department
  1568. LEFT JOIN (
  1569. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1570. COUNT(DISTINCT(r.degree_id)) centerCount
  1571. FROM report
  1572. LEFT JOIN report r
  1573. ON report.id = r.id AND r.degree_id != -1
  1574. LEFT JOIN `user`
  1575. ON report.creator_id = user.id
  1576. WHERE report.state = 1
  1577. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1578. GROUP BY dept_id
  1579. ) pro
  1580. on pro.dept_id = department.department_id
  1581. LEFT JOIN (
  1582. SELECT dept_id,sum(p.con) peopleCount
  1583. FROM (
  1584. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1585. LEFT JOIN `user`
  1586. ON report.creator_id = user.id
  1587. WHERE report.state = 1
  1588. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1589. GROUP BY report.creator_id,dept_id
  1590. ) p GROUP BY p.dept_id
  1591. ) pcon
  1592. ON pcon.dept_id = department.department_id
  1593. WHERE department.company_id = #{companyId}
  1594. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1595. and department.department_id in
  1596. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1597. #{item}
  1598. </foreach>
  1599. </if>
  1600. <if test="deptIds!=null and deptIds.size()>0">
  1601. and department.department_id in
  1602. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1603. #{item}
  1604. </foreach>
  1605. </if>
  1606. <if test="size!=null and start!=null">
  1607. limit #{start},#{size}
  1608. </if>
  1609. </select>
  1610. <!--获取按项目分组的工时成本-->
  1611. <select id="getExportDegreeCost" resultType="java.util.Map">
  1612. 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
  1613. FROM project AS a
  1614. LEFT JOIN report AS b ON b.project_id = a.id
  1615. JOIN user AS c ON b.creator_id = c.id
  1616. WHERE a.company_id = #{companyId}
  1617. <if test="projectId != null">
  1618. AND a.id = #{projectId}
  1619. </if>
  1620. <if test="startDate != null and endDate != null">
  1621. AND b.create_date between #{startDate} and #{endDate}
  1622. </if>
  1623. <choose>
  1624. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1625. and b.dept_id in
  1626. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1627. #{item}
  1628. </foreach>
  1629. </when>
  1630. <otherwise>
  1631. <if test="deptIds!=null and deptIds.size()>0">
  1632. and (b.dept_id in
  1633. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1634. #{item}
  1635. </foreach>
  1636. <if test="deptRelatedProjectIds.size() > 0">
  1637. or a.id in
  1638. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  1639. #{pid}
  1640. </foreach>
  1641. </if>
  1642. )
  1643. </if>
  1644. </otherwise>
  1645. </choose>
  1646. AND b.state = 1
  1647. GROUP BY a.id
  1648. ORDER BY a.id ASC
  1649. </select>
  1650. <!--获取某个项目每个维度分别需要的工时-->
  1651. <select id="getDegreeDetailCost" resultType="java.util.Map">
  1652. 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
  1653. FROM report AS a
  1654. JOIN user AS b ON a.creator_id = b.id
  1655. left join department on department.department_id = a.dept_id
  1656. left join report_extra_degree as r on a.degree_id = r.id
  1657. WHERE a.company_id=#{companyId}
  1658. <if test="curProjectId != null">
  1659. and a.project_id = #{curProjectId}
  1660. </if>
  1661. <if test="projectId != null">
  1662. and a.project_id = #{projectId}
  1663. </if>
  1664. <if test="startDate != null and endDate != null">
  1665. AND a.create_date between #{startDate} and #{endDate}
  1666. </if>
  1667. <choose>
  1668. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1669. and a.dept_id in
  1670. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1671. #{item}
  1672. </foreach>
  1673. </when>
  1674. <otherwise>
  1675. <if test="deptIds!=null and deptIds.size()>0">
  1676. and a.dept_id in
  1677. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1678. #{item}
  1679. </foreach>
  1680. </if>
  1681. </otherwise>
  1682. </choose>
  1683. GROUP BY a.project_id,b.id,a.degree_id
  1684. ORDER BY b.id,a.degree_id ASC
  1685. </select>
  1686. <select id="selectNearProject" resultType="com.management.platform.entity.Project">
  1687. SELECT * FROM project
  1688. WHERE STATUS = 1 AND id IN (
  1689. SELECT project_id
  1690. FROM (
  1691. SELECT DISTINCT report.project_id
  1692. FROM report
  1693. WHERE creator_id = #{userId}
  1694. GROUP BY project_id
  1695. ORDER BY MAX(create_time)
  1696. DESC LIMIT 3
  1697. ) p2
  1698. ) AND id IN(SELECT project_id FROM participation WHERE user_id=#{userId})
  1699. </select>
  1700. <select id="getFTEData" resultType="java.util.Map">
  1701. 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,
  1702. IFNULL(r.projectCode,'') as projectCode,IFNULL(r.workTime,0) as workTime,IFNULL(t.nonProjectWorkingTime,0) as nonProjectWorkingTime
  1703. FROM `user` u
  1704. LEFT JOIN department d on u.department_id=d.department_id
  1705. LEFT JOIN (
  1706. SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
  1707. FROM report
  1708. LEFT JOIN project p
  1709. ON report.project_id = p.id
  1710. LEFT JOIN `user`
  1711. ON user.id = report.creator_id
  1712. WHERE report.state = 1
  1713. AND p.is_public = 0
  1714. AND report.company_id=#{companyId}
  1715. AND
  1716. (
  1717. 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}
  1718. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1719. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1720. and
  1721. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1722. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1723. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1724. and
  1725. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1726. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1727. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1728. )
  1729. GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
  1730. ) r
  1731. ON u.id = r.creator_id
  1732. LEFT JOIN (
  1733. SELECT report.creator_id,SUM(working_time) nonProjectWorkingTime
  1734. FROM report
  1735. LEFT JOIN project p
  1736. ON report.project_id = p.id
  1737. LEFT JOIN `user`
  1738. ON user.id = report.creator_id
  1739. WHERE report.state = 1
  1740. AND p.is_public = 1
  1741. AND report.company_id=#{companyId}
  1742. AND
  1743. (
  1744. 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}
  1745. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1746. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1747. and
  1748. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1749. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1750. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1751. and
  1752. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1753. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1754. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1755. )
  1756. GROUP BY user.id
  1757. ) t
  1758. ON u.id = t.creator_id
  1759. WHERE u.company_id=#{companyId}
  1760. AND (workTime>0 OR u.`is_active`=1)
  1761. <if test="area!=null and area != '' ">
  1762. and u.plate1 = #{area}
  1763. </if>
  1764. <if test="userId!=null and userId != '' ">
  1765. and u.id = #{userId}
  1766. </if>
  1767. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1768. and u.department_id in
  1769. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1770. #{item}
  1771. </foreach>
  1772. </if>
  1773. <if test="deptIds!=null and deptIds.size()>0">
  1774. and u.department_id in
  1775. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1776. #{item}
  1777. </foreach>
  1778. </if>
  1779. <!-- <if test="departmentId!=null">-->
  1780. <!-- and u.department_id=#{departmentId}-->
  1781. <!-- </if>-->
  1782. <if test="sortProp!=null and sortProp!=''">
  1783. <choose>
  1784. <when test="sortOrder==0">
  1785. order by id desc
  1786. </when>
  1787. <otherwise>
  1788. order by id
  1789. </otherwise>
  1790. </choose>
  1791. </if>
  1792. <if test="start!=null and size!=null">
  1793. limit #{start},#{size}
  1794. </if>
  1795. </select>
  1796. <!--获取查询者所在公司每个项目的工时成本-->
  1797. <select id="getTimeCostByToken" resultType="java.util.Map">
  1798. 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
  1799. FROM project AS a
  1800. LEFT JOIN report AS b ON b.project_id = a.id
  1801. JOIN user AS c ON b.creator_id = c.id
  1802. JOIN department d on d.department_id=c.department_id
  1803. WHERE a.company_id = #{companyId}
  1804. <if test="startDate != null and endDate != null">
  1805. AND b.create_date between #{startDate} and #{endDate}
  1806. </if>
  1807. AND b.state = 1
  1808. GROUP BY a.id,b.creator_id
  1809. ORDER BY a.id ASC
  1810. </select>
  1811. <!--获取员工的项目分类工时统计数据 -->
  1812. <select id="getMembProjectCateTime" resultType="com.management.platform.entity.vo.UserCateTimeVo">
  1813. 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
  1814. FROM report
  1815. LEFT JOIN `user` ON user.id = report.`creator_id`
  1816. LEFT JOIN project ON project.id = report.`project_id`
  1817. WHERE report.`company_id` = #{companyId}
  1818. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  1819. AND report.state = 1
  1820. <if test="departmentId!=null">
  1821. AND user.department_id=#{departmentId}
  1822. </if>
  1823. <if test="subUserCustomName!=null and subUserCustomName!='' and plateString!=null">
  1824. <choose>
  1825. <when test="plateString==1">
  1826. AND user.plate1=#{subUserCustomName}
  1827. </when>
  1828. <when test="plateString==2">
  1829. AND user.plate2=#{subUserCustomName}
  1830. </when>
  1831. <when test="plateString==3">
  1832. AND user.plate3=#{subUserCustomName}
  1833. </when>
  1834. <when test="plateString==4">
  1835. AND user.plate4=#{subUserCustomName}
  1836. </when>
  1837. <otherwise>
  1838. AND user.plate5=#{subUserCustomName}
  1839. </otherwise>
  1840. </choose>
  1841. </if>
  1842. GROUP BY user.id, project.`category`
  1843. </select>
  1844. <select id="userProjectProcessList" resultType="java.util.Map">
  1845. 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,
  1846. 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
  1847. from task_executor te
  1848. left join user u on u.id=te.executor_id
  1849. left join department d on d.department_id=u.department_id
  1850. left join project p on p.id=te.project_id
  1851. where u.company_id=#{companyId} and te.project_id is not null
  1852. <if test="deptId!=null">
  1853. and d.department_id=#{deptId}
  1854. </if>
  1855. <if test="userId!=null and userId!=''">
  1856. and u.id=#{userId}
  1857. </if>
  1858. <if test="projectId!=null">
  1859. and p.id=#{projectId}
  1860. </if>
  1861. <if test="list!=null and list.size()>0">
  1862. and d.department_id in
  1863. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1864. #{item}
  1865. </foreach>
  1866. </if>
  1867. <if test="listSecond!=null and listSecond.size()>0">
  1868. and d.department_id in
  1869. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1870. #{item}
  1871. </foreach>
  1872. </if>
  1873. group by te.executor_id,te.project_id
  1874. order by d.department_id,u.id
  1875. <if test="start!=null and size!=null">
  1876. limit #{start},#{size}
  1877. </if>
  1878. </select>
  1879. <select id="userProjectProcessCount" resultType="java.lang.Long">
  1880. select count(1) from (
  1881. select d.department_name as departmentName
  1882. from task_executor te
  1883. left join user u on u.id=te.executor_id
  1884. left join department d on d.department_id=u.department_id
  1885. left join project p on p.id=te.project_id
  1886. where u.company_id=#{companyId} and te.project_id is not null
  1887. <if test="deptId!=null">
  1888. and d.department_id=#{deptId}
  1889. </if>
  1890. <if test="userId!=null and userId!=''">
  1891. and u.id=#{userId}
  1892. </if>
  1893. <if test="projectId!=null">
  1894. and p.id=#{projectId}
  1895. </if>
  1896. <if test="list!=null and list.size()>0">
  1897. and d.department_id in
  1898. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1899. #{item}
  1900. </foreach>
  1901. </if>
  1902. <if test="listSecond!=null and listSecond.size()>0">
  1903. and d.department_id in
  1904. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1905. #{item}
  1906. </foreach>
  1907. </if>
  1908. group by te.executor_id,te.project_id
  1909. ) as total
  1910. </select>
  1911. <select id="groupExpendProcessList" resultType="java.util.Map">
  1912. SELECT p.project_name AS projectName,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
  1913. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) as normalHour,IFNULL(r.overHour,0) as overHour,
  1914. 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
  1915. FROM task_group tg
  1916. LEFT JOIN project p ON p.id=tg.project_id AND p.`company_id`=#{companyId}
  1917. LEFT JOIN (
  1918. 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
  1919. FROM report WHERE state=1
  1920. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1921. AND create_date BETWEEN #{startDate} AND #{endDate}
  1922. </if>
  1923. <if test="userId!=null and userId!=''">
  1924. and report.creator_id=#{userId}
  1925. </if>
  1926. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  1927. WHERE p.company_id=#{companyId}
  1928. <if test="projectIds!=null and projectIds.size()>0">
  1929. AND tg.project_id in
  1930. <foreach collection="projectIds" separator="," open="(" close=")" item="item">
  1931. #{item}
  1932. </foreach>
  1933. </if>
  1934. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1935. GROUP BY p.id,tg.id ORDER BY p.id
  1936. </select>
  1937. <select id="groupExpendProcessListForChart" resultType="java.util.Map">
  1938. 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
  1939. 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,
  1940. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) AS normalHour,IFNULL(r.overHour,0) AS overHour,
  1941. 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
  1942. FROM task_group tg
  1943. LEFT JOIN task t ON tg.id = t.group_id
  1944. LEFT JOIN task_executor te ON t.id = te.task_id
  1945. LEFT JOIN `user` u
  1946. ON te.executor_id = u.id AND u.`company_id`=#{companyId}
  1947. LEFT JOIN project p ON p.id=tg.project_id
  1948. LEFT JOIN department d ON d.department_id=u.department_id
  1949. LEFT JOIN (
  1950. 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
  1951. FROM report WHERE state=1
  1952. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  1953. AND create_date BETWEEN #{startDate} AND #{endDate}
  1954. </if>
  1955. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  1956. WHERE p.company_id=#{companyId}
  1957. <if test="listThird!=null and listThird.size()>0">
  1958. AND tg.project_id in
  1959. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  1960. #{item}
  1961. </foreach>
  1962. </if>
  1963. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1964. <if test="userId!=null and userId!=''">
  1965. and t.executor_id=#{userId}
  1966. </if>
  1967. GROUP BY tg.id ORDER BY p.id,d.department_id) AS t
  1968. <where>
  1969. <if test="listFour!=null and listFour.size()>0">
  1970. t.groupName in
  1971. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  1972. #{item}
  1973. </foreach>
  1974. </if>
  1975. </where>
  1976. GROUP BY t.groupName
  1977. </select>
  1978. <select id="groupExpendProcessListForUser" resultType="java.util.Map">
  1979. SELECT departmentId, departmentName,jobNumber,userName,
  1980. SUM(CASE WHEN groupName='方案设计' THEN workTime ELSE 0 END) AS '方案设计' ,
  1981. SUM(CASE WHEN groupName='研发部' THEN workTime ELSE 0 END) AS '研发部' ,
  1982. SUM(CASE WHEN groupName='研发部工艺调试' THEN workTime ELSE 0 END) AS '研发部工艺调试',
  1983. SUM(CASE WHEN groupName='研发部工艺调试验收' THEN workTime ELSE 0 END) AS '研发部工艺调试验收' ,
  1984. SUM(CASE WHEN groupName='研发部工艺设计' THEN workTime ELSE 0 END) AS '研发部工艺设计' ,
  1985. SUM(CASE WHEN groupName='研发部结构设计' THEN workTime ELSE 0 END) AS '研发部结构设计' ,
  1986. SUM(CASE WHEN groupName='研发部BIM设计' THEN workTime ELSE 0 END) AS '研发部BIM设计' ,
  1987. SUM(CASE WHEN groupName='研发部电气调试验收' THEN workTime ELSE 0 END) AS '研发部电气调试验收' ,
  1988. SUM(CASE WHEN groupName='研发部电气设计' THEN workTime ELSE 0 END) AS '研发部电气设计' ,
  1989. SUM(CASE WHEN groupName='研发部售后' THEN workTime ELSE 0 END) AS '研发部售后' ,
  1990. SUM(CASE WHEN groupName='工程部配合运维' THEN workTime ELSE 0 END) AS '工程部配合运维' ,
  1991. SUM(CASE WHEN groupName='研发部运维' THEN workTime ELSE 0 END) AS '研发部运维' ,
  1992. SUM(CASE WHEN groupName='生产部' THEN workTime ELSE 0 END) AS '生产部' ,
  1993. SUM(CASE WHEN groupName='生产部车间' THEN workTime ELSE 0 END) AS '生产部车间' ,
  1994. SUM(CASE WHEN groupName='生产部电气' THEN workTime ELSE 0 END) AS '生产部电气' ,
  1995. SUM(CASE WHEN groupName='工程部配合调试' THEN workTime ELSE 0 END) AS '工程部配合调试' ,
  1996. SUM(CASE WHEN groupName='工程部' THEN workTime ELSE 0 END) AS '工程部' ,
  1997. SUM(CASE WHEN groupName='工程部售后' THEN workTime ELSE 0 END) AS '工程部售后' ,
  1998. SUM(CASE WHEN groupName='工程部现场安装施工' THEN workTime ELSE 0 END) AS '工程部现场安装施工',
  1999. IFNULL(SUM(workTime),0) AS totalWorkTime
  2000. FROM (
  2001. 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
  2002. FROM task_executor te
  2003. LEFT JOIN task t ON t.id=te.task_id
  2004. LEFT JOIN `user` u ON te.executor_id=u.id
  2005. LEFT JOIN task_group tg ON tg.id=t.group_id
  2006. LEFT JOIN project p ON p.id=tg.project_id
  2007. LEFT JOIN department d ON d.department_id=u.department_id
  2008. LEFT JOIN (
  2009. SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
  2010. FROM report r
  2011. LEFT JOIN task_group tg ON r.group_id=tg.`id`
  2012. WHERE r.state=1 AND r.project_id IS NOT NULL
  2013. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2014. AND r.create_date BETWEEN #{startDate} AND #{endDate}
  2015. </if> AND r.company_id=#{companyId}
  2016. GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
  2017. WHERE u.company_id=#{companyId}
  2018. <if test="listThird!=null and listThird.size()>0">
  2019. AND tg.project_id in
  2020. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2021. #{item}
  2022. </foreach>
  2023. </if>
  2024. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2025. <if test="listFour!=null and listFour.size()>0">
  2026. and tg.name in
  2027. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2028. #{item}
  2029. </foreach>
  2030. </if>
  2031. GROUP BY u.`id`,tg.id
  2032. ) AS t
  2033. <where>
  2034. <if test="listFive!=null and listFive.size()>0">
  2035. t.departmentId in
  2036. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2037. #{item}
  2038. </foreach>
  2039. </if>
  2040. </where>
  2041. GROUP BY t.id
  2042. <if test="start!=null and size!=null">
  2043. limit #{start},#{size}
  2044. </if>
  2045. </select>
  2046. <select id="groupExpendProcessListForUserCount" resultType="java.lang.Integer">
  2047. select count(1) from (
  2048. SELECT departmentId,departmentName,jobNumber,userName,IFNULL(SUM(workTime),0) AS totalWorkTime
  2049. FROM (
  2050. 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
  2051. FROM task_executor te
  2052. LEFT JOIN task t ON t.id=te.task_id
  2053. LEFT JOIN `user` u ON te.executor_id=u.id
  2054. LEFT JOIN task_group tg ON tg.id=t.group_id
  2055. LEFT JOIN project p ON p.id=tg.project_id
  2056. LEFT JOIN department d ON d.department_id=u.department_id
  2057. LEFT JOIN (
  2058. SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
  2059. FROM report r
  2060. LEFT JOIN task_group tg ON r.group_id=tg.`id`
  2061. WHERE r.state=1 AND r.project_id IS NOT NULL
  2062. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2063. AND r.create_date BETWEEN #{startDate} AND #{endDate}
  2064. </if> AND r.company_id=#{companyId}
  2065. GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
  2066. WHERE u.company_id=#{companyId}
  2067. <if test="listThird!=null and listThird.size()>0">
  2068. AND tg.project_id in
  2069. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2070. #{item}
  2071. </foreach>
  2072. </if>
  2073. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2074. <if test="listFour!=null and listFour.size()>0">
  2075. and tg.name in
  2076. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2077. #{item}
  2078. </foreach>
  2079. </if>
  2080. GROUP BY u.`id`,tg.id
  2081. ) AS t
  2082. <where>
  2083. <if test="listFive!=null and listFive.size()>0">
  2084. t.departmentId in
  2085. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2086. #{item}
  2087. </foreach>
  2088. </if>
  2089. </where>
  2090. GROUP BY t.id
  2091. ) as total
  2092. </select>
  2093. <select id="groupExpendProcessListForProject" resultType="java.util.Map">
  2094. SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
  2095. SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
  2096. IFNULL(r.realHour,0) AS realHour
  2097. FROM task_executor te
  2098. LEFT JOIN task t ON t.id=te.task_id
  2099. LEFT JOIN `user` u ON te.executor_id=u.id
  2100. LEFT JOIN task_group tg ON tg.id=t.group_id
  2101. LEFT JOIN project p ON p.id=tg.project_id
  2102. LEFT JOIN department d ON d.department_id=u.department_id
  2103. LEFT JOIN (
  2104. SELECT SUM(working_time) AS realHour,group_id,dept_id
  2105. FROM report WHERE state=1
  2106. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2107. AND create_date BETWEEN #{startDate} AND #{endDate}
  2108. </if>
  2109. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  2110. WHERE u.company_id=#{companyId}
  2111. <if test="listThird!=null and listThird.size()>0">
  2112. AND tg.project_id in
  2113. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2114. #{item}
  2115. </foreach>
  2116. </if>
  2117. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2118. <if test="listFour!=null and listFour.size()>0">
  2119. and tg.name in
  2120. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2121. #{item}
  2122. </foreach>
  2123. </if>
  2124. <if test="listFive!=null and listFive.size()>0">
  2125. and d.department_id in
  2126. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2127. #{item}
  2128. </foreach>
  2129. </if>
  2130. GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
  2131. <where>
  2132. realHour>0
  2133. <if test="listThird!=null and listThird.size()>0">
  2134. and
  2135. projectId in
  2136. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2137. #{item}
  2138. </foreach>
  2139. </if>
  2140. </where>
  2141. GROUP BY projectId
  2142. <if test="start!=null and size!=null">
  2143. limit #{start},#{size}
  2144. </if>
  2145. </select>
  2146. <select id="groupExpendProcessListForProjectCount" resultType="java.lang.Integer">
  2147. select count(1) from (
  2148. SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
  2149. SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
  2150. IFNULL(r.realHour,0) AS realHour
  2151. FROM task_executor te
  2152. LEFT JOIN task t ON t.id=te.task_id
  2153. LEFT JOIN `user` u ON te.executor_id=u.id
  2154. LEFT JOIN task_group tg ON tg.id=t.group_id
  2155. LEFT JOIN project p ON p.id=tg.project_id
  2156. LEFT JOIN department d ON d.department_id=u.department_id
  2157. LEFT JOIN (
  2158. SELECT SUM(working_time) AS realHour,group_id,dept_id
  2159. FROM report WHERE state=1
  2160. <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
  2161. AND create_date BETWEEN #{startDate} AND #{endDate}
  2162. </if>
  2163. AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
  2164. WHERE u.company_id=#{companyId}
  2165. <if test="listThird!=null and listThird.size()>0">
  2166. AND tg.project_id in
  2167. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2168. #{item}
  2169. </foreach>
  2170. </if>
  2171. AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  2172. <if test="listFour!=null and listFour.size()>0">
  2173. and tg.name in
  2174. <foreach collection="listFour" close=")" open="(" separator="," item="item">
  2175. #{item}
  2176. </foreach>
  2177. </if>
  2178. <if test="listFive!=null and listFive.size()>0">
  2179. and d.department_id in
  2180. <foreach collection="listFive" close=")" open="(" separator="," item="item">
  2181. #{item}
  2182. </foreach>
  2183. </if>
  2184. GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
  2185. <where>
  2186. realHour>0
  2187. <if test="listThird!=null and listThird.size()>0">
  2188. and
  2189. projectId in
  2190. <foreach collection="listThird" separator="," open="(" close=")" item="item">
  2191. #{item}
  2192. </foreach>
  2193. </if>
  2194. </where>
  2195. GROUP BY projectId
  2196. ) as total
  2197. </select>
  2198. <select id="projectExpendProcessList" resultType="java.util.Map">
  2199. 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,
  2200. 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,
  2201. 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
  2202. from task_executor te
  2203. left join user u on u.id=te.executor_id
  2204. left join department d on u.department_id=d.department_id
  2205. left join task t on t.id=te.task_id
  2206. left join project p on p.id=t.project_id
  2207. left join project_category pc on pc.id=p.category
  2208. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
  2209. <if test="projectId!=null">
  2210. and p.id=#{projectId}
  2211. </if>
  2212. <if test="userId!=null and userId!=''">
  2213. and FIND_IN_SET(#{userId},t.executor_id)
  2214. </if>
  2215. <if test="categoryId!=null">
  2216. and pc.id=#{categoryId}
  2217. </if>
  2218. <if test="list!=null and list.size()>0">
  2219. and d.department_id in
  2220. <foreach collection="list" open="(" close=")" separator="," item="item">
  2221. #{item}
  2222. </foreach>
  2223. </if>
  2224. group by t.project_id
  2225. <if test="start!=null and size!=null">
  2226. limit #{start},#{size}
  2227. </if>
  2228. </select>
  2229. <select id="projectExpendProcessListCount" resultType="java.lang.Long">
  2230. select count(1) from (
  2231. select p.project_name as projectName
  2232. from task_executor te
  2233. left join user u on u.id=te.executor_id
  2234. left join department d on u.department_id=d.department_id
  2235. left join task t on t.id=te.task_id
  2236. left join project p on p.id=t.project_id
  2237. left join project_category pc on pc.id=p.category
  2238. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
  2239. <if test="projectId!=null">
  2240. and p.id=#{projectId}
  2241. </if>
  2242. <if test="userId!=null and userId!=''">
  2243. and te.executor_id=#{userId}
  2244. </if>
  2245. <if test="categoryId!=null">
  2246. and pc.id=#{categoryId}
  2247. </if>
  2248. <if test="list!=null and list.size()>0">
  2249. and d.department_id in
  2250. <foreach collection="list" open="(" close=")" separator="," item="item">
  2251. #{item}
  2252. </foreach>
  2253. </if>
  2254. group by t.project_id
  2255. ) as total
  2256. </select>
  2257. <select id="userTaskProcessList" resultType="java.util.Map">
  2258. 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,
  2259. 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
  2260. ,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate
  2261. from task_executor te
  2262. left join user u on u.id=te.executor_id
  2263. left join department d on d.department_id=u.department_id
  2264. left join project p on p.id=te.project_id
  2265. left join task t on te.task_id=t.id
  2266. where u.company_id=#{companyId} and te.project_id is not null
  2267. <if test="deptId!=null">
  2268. and d.department_id=#{deptId}
  2269. </if>
  2270. <if test="userId!=null and userId!=''">
  2271. and u.id=#{userId}
  2272. </if>
  2273. <if test="projectId!=null">
  2274. and p.id=#{projectId}
  2275. </if>
  2276. <if test="list!=null and list.size()>0">
  2277. and d.department_id in
  2278. <foreach collection="list" open="(" close=")" item="item" separator=",">
  2279. #{item}
  2280. </foreach>
  2281. </if>
  2282. <if test="listSecond!=null and listSecond.size()>0">
  2283. and d.department_id in
  2284. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  2285. #{item}
  2286. </foreach>
  2287. </if>
  2288. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2289. and ((t.start_date between #{startDate} and #{endDate})
  2290. or
  2291. (t.end_date between #{startDate} and #{endDate}))
  2292. </if>
  2293. group by te.executor_id,t.id
  2294. order by d.department_id,u.id
  2295. <if test="start!=null and size!=null">
  2296. limit #{start},#{size}
  2297. </if>
  2298. </select>
  2299. <select id="userTaskProcessListCount" resultType="java.lang.Long">
  2300. select count(1) from (
  2301. select d.department_name as departmentName
  2302. from task_executor te
  2303. left join user u on u.id=te.executor_id
  2304. left join department d on d.department_id=u.department_id
  2305. left join project p on p.id=te.project_id
  2306. left join task t on te.task_id=t.id
  2307. where u.company_id=#{companyId} and te.project_id is not null
  2308. <if test="deptId!=null">
  2309. and d.department_id=#{deptId}
  2310. </if>
  2311. <if test="userId!=null and userId!=''">
  2312. and u.id=#{userId}
  2313. </if>
  2314. <if test="projectId!=null">
  2315. and p.id=#{projectId}
  2316. </if>
  2317. <if test="list!=null and list.size()>0">
  2318. and d.department_id in
  2319. <foreach collection="list" open="(" close=")" item="item" separator=",">
  2320. #{item}
  2321. </foreach>
  2322. </if>
  2323. <if test="listSecond!=null and listSecond.size()>0">
  2324. and d.department_id in
  2325. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  2326. #{item}
  2327. </foreach>
  2328. </if>
  2329. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  2330. and ((t.start_date between #{startDate} and #{endDate})
  2331. or
  2332. (t.end_date between #{startDate} and #{endDate}))
  2333. </if>
  2334. group by te.executor_id,t.id
  2335. order by d.department_id,u.id
  2336. ) as total
  2337. </select>
  2338. <select id="getOnlyJoinProjectsPage" resultType="java.util.Map">
  2339. SELECT id, project_code AS projectCode, project_name AS projectName
  2340. FROM project
  2341. WHERE status = 1 and (id IN (
  2342. SELECT project_id
  2343. FROM participation
  2344. WHERE user_id = #{userId}
  2345. )
  2346. or (is_public = 1 and company_id = #{companyId}))
  2347. <if test="infoString !=null and infoString!='' ">
  2348. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2349. </if>
  2350. ORDER BY is_public DESC, id ASC
  2351. limit #{pageIndex},#{pageSize}
  2352. </select>
  2353. <select id="getOnlyJoinProjectsTotal" resultType="java.lang.Integer">
  2354. SELECT count(*) total
  2355. FROM project
  2356. WHERE status = 1 and (id IN (
  2357. SELECT project_id
  2358. FROM participation
  2359. WHERE user_id = #{userId}
  2360. )
  2361. or (is_public = 1 and company_id = #{companyId}))
  2362. <if test="infoString !=null and infoString!='' ">
  2363. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2364. </if>
  2365. </select>
  2366. <select id="getOnlyJoinProjectsById" resultType="java.util.Map">
  2367. SELECT id, project_code AS projectCode, project_name AS projectName
  2368. FROM project
  2369. WHERE status = 1 and (id IN (
  2370. SELECT project_id
  2371. FROM participation
  2372. WHERE user_id = #{userId}
  2373. )
  2374. or (is_public = 1 and company_id = #{companyId}))
  2375. and id =#{projectId}
  2376. </select>
  2377. <select id="getParticipatedProjectPage" resultType="java.util.Map">
  2378. SELECT id, project_code AS projectCode, project_name AS projectName
  2379. FROM project
  2380. WHERE id IN (
  2381. SELECT project_id
  2382. FROM participation
  2383. WHERE user_id = #{userId}
  2384. ) or incharger_id = #{userId}
  2385. or creator_id = #{userId}
  2386. or (is_public = 1 and company_id = #{companyId})
  2387. <if test="infoString !=null and infoString!='' ">
  2388. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2389. </if>
  2390. ORDER BY is_public DESC, id DESC
  2391. limit #{pageIndex},#{pageSize}
  2392. </select>
  2393. <select id="getParticipatedProjectTotal" resultType="java.lang.Integer">
  2394. SELECT count(*) total
  2395. FROM project
  2396. WHERE id IN (
  2397. SELECT project_id
  2398. FROM participation
  2399. WHERE user_id = #{userId}
  2400. ) or incharger_id = #{userId}
  2401. or creator_id = #{userId}
  2402. or (is_public = 1 and company_id = #{companyId})
  2403. <if test="infoString !=null and infoString!='' ">
  2404. and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
  2405. </if>
  2406. </select>
  2407. <select id="getParticipatedProjectById" resultType="java.util.Map">
  2408. SELECT count(*) total
  2409. FROM project
  2410. WHERE id IN (
  2411. SELECT project_id
  2412. FROM participation
  2413. WHERE user_id = #{userId}
  2414. ) or incharger_id = #{userId}
  2415. or creator_id = #{userId}
  2416. or (is_public = 1 and company_id = #{companyId})
  2417. and id =#{projectId}
  2418. </select>
  2419. <select id="getTimeCostGroupByProjectUserSumTime" resultType="java.util.Map">
  2420. SELECT a.id, a.project_code as projectCode, a.project_name AS projectName,a.category_name as categoryName,
  2421. c.name name,sum(b.working_time) AS cost,
  2422. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
  2423. c.id userId
  2424. FROM project AS a
  2425. LEFT JOIN report AS b ON b.project_id = a.id
  2426. JOIN user AS c ON b.creator_id = c.id
  2427. left join department on department.department_id = b.dept_id
  2428. WHERE a.company_id = #{companyId}
  2429. <if test="startDate != null and endDate != null">
  2430. AND b.create_date between #{startDate} and #{endDate}
  2431. </if>
  2432. AND b.state = 1
  2433. group by id,projectCode,projectName,categoryName,name
  2434. ORDER BY a.id ASC
  2435. </select>
  2436. <select id="getTimeCostProjectUserWorkTime" resultType="java.util.Map">
  2437. SELECT a.id, a.project_code as projectCode,a.project_name AS projectName,a.category_name as categoryName,
  2438. c.name name,b.working_time cost,
  2439. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
  2440. b.create_date createDate,DAY(b.create_date) dayOnly,c.id userId
  2441. FROM project AS a
  2442. LEFT JOIN report AS b ON b.project_id = a.id
  2443. JOIN user AS c ON b.creator_id = c.id
  2444. left join department on department.department_id = b.dept_id
  2445. WHERE a.company_id = #{companyId}
  2446. <if test="startDate != null and endDate != null">
  2447. AND b.create_date between #{startDate} and #{endDate}
  2448. </if>
  2449. AND b.state = 1
  2450. ORDER BY a.id ASC ,c.name asc
  2451. </select>
  2452. <select id="getCostTimeByUserSum" resultType="java.util.Map">
  2453. SELECT c.id userId, c.job_number jobNumber,c.name name,sum(b.working_time) AS cost,
  2454. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName
  2455. FROM project AS a
  2456. LEFT JOIN report AS b ON b.project_id = a.id
  2457. JOIN user AS c ON b.creator_id = c.id
  2458. left join department on department.department_id = b.dept_id
  2459. WHERE c.company_id = #{companyId}
  2460. <if test="startDate != null and endDate != null">
  2461. AND b.create_date between #{startDate} and #{endDate}
  2462. </if>
  2463. AND b.state = 1
  2464. group by userId
  2465. </select>
  2466. <select id="getCostTimeByUserForDay" resultType="java.util.Map">
  2467. SELECT c.id userId, c.job_number jobNumber,c.name name,b.working_time AS cost, a.id projectId,a.project_name ,
  2468. b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
  2469. DAY(b.create_date) dayOnly
  2470. FROM project AS a
  2471. LEFT JOIN report AS b ON b.project_id = a.id
  2472. JOIN user AS c ON b.creator_id = c.id
  2473. left join department on department.department_id = b.dept_id
  2474. WHERE c.company_id = #{companyId}
  2475. <if test="startDate != null and endDate != null">
  2476. AND b.create_date between #{startDate} and #{endDate}
  2477. </if>
  2478. AND b.state = 1
  2479. </select>
  2480. <select id="getTotalProjectByTime" resultType="java.util.Map">
  2481. SELECT
  2482. a.id projectId,a.project_name projectName
  2483. FROM project AS a
  2484. LEFT JOIN report AS b ON b.project_id = a.id
  2485. JOIN user AS c ON b.creator_id = c.id
  2486. left join department on department.department_id = b.dept_id
  2487. WHERE c.company_id = #{companyId}
  2488. <if test="startDate != null and endDate != null">
  2489. AND b.create_date between #{startDate} and #{endDate}
  2490. </if>
  2491. AND b.state = 1
  2492. GROUP BY projectId
  2493. </select>
  2494. <select id="selectProjectEestimatedWorkTimeList" resultType="java.util.Map">
  2495. SELECT
  2496. p.id AS projectId,
  2497. p.project_code AS projectCode,
  2498. p.project_name AS projectName,
  2499. CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END AS estimatedWorkTime,
  2500. SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END) AS workTime,
  2501. (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,
  2502. CASE
  2503. WHEN (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END) = 0 THEN NULL
  2504. 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)
  2505. END AS remainWorkTimeProportion
  2506. FROM
  2507. project p
  2508. LEFT JOIN
  2509. report r ON p.id = r.project_id
  2510. WHERE
  2511. p.company_id = #{map.companyId}
  2512. AND p.`status` IN (1, 2)
  2513. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2514. <if test="map.projectId!=null">
  2515. AND p.id = #{map.projectId}
  2516. </if>
  2517. GROUP BY
  2518. p.id, p.project_code, p.project_name
  2519. <if test="map.isWarn!=null and map.isWarn==1 ">
  2520. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2521. </if>
  2522. <if test="map.pageIndex!=null and map.pageSize!=null ">
  2523. LIMIT #{map.pageIndex}, #{map.pageSize}
  2524. </if>
  2525. </select>
  2526. <select id="selectProjectEestimatedWorkTimeCount" resultType="java.lang.Integer">
  2527. SELECT
  2528. count(1) total
  2529. FROM
  2530. (
  2531. SELECT
  2532. p.id AS projectId,
  2533. (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,
  2534. CASE
  2535. WHEN (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END) = 0 THEN NULL
  2536. 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)
  2537. END AS remainWorkTimeProportion
  2538. FROM
  2539. project p
  2540. LEFT JOIN
  2541. report r ON p.id = r.project_id
  2542. WHERE
  2543. p.company_id = #{map.companyId}
  2544. AND p.`status` IN (1, 2)
  2545. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2546. <if test="map.projectId!=null">
  2547. AND p.id = #{map.projectId}
  2548. </if>
  2549. GROUP BY
  2550. p.id, p.project_code, p.project_name
  2551. <if test="map.isWarn!=null and map.isWarn==1 ">
  2552. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2553. </if>
  2554. ) a
  2555. </select>
  2556. <select id="selectGroupEestimatedWorkTimeList" resultType="java.util.Map">
  2557. SELECT
  2558. p.id AS projectId,
  2559. p.project_code AS projectCode,
  2560. p.project_name AS projectName,
  2561. g.`name` groupName,
  2562. g.id id,
  2563. CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END AS estimatedWorkTime,
  2564. SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
  2565. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2566. END) AS workTime,
  2567. (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
  2568. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2569. END)) AS remainWorkTime,
  2570. CASE
  2571. WHEN (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END) = 0 THEN NULL
  2572. 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
  2573. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2574. END)) / (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END),4)
  2575. END AS remainWorkTimeProportion
  2576. FROM
  2577. project p
  2578. LEFT JOIN
  2579. report r ON p.id = r.project_id
  2580. LEFT JOIN
  2581. task_group g ON g.project_id =p.id
  2582. WHERE
  2583. p.company_id = #{map.companyId}
  2584. AND p.`status` IN (1, 2)
  2585. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2586. <if test="map.projectId!=null">
  2587. AND p.id = #{map.projectId}
  2588. </if>
  2589. GROUP BY
  2590. p.id,g.`name`,g.id
  2591. <if test="map.isWarn!=null and map.isWarn==1 ">
  2592. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2593. </if>
  2594. <if test="map.pageIndex!=null and map.pageSize!=null ">
  2595. LIMIT #{map.pageIndex}, #{map.pageSize}
  2596. </if>
  2597. </select>
  2598. <select id="selectGroupEestimatedWorkTimeCount" resultType="java.lang.Integer">
  2599. SELECT
  2600. count(*)
  2601. FROM
  2602. (
  2603. SELECT
  2604. p.id AS projectId,
  2605. g.`name` groupName,
  2606. g.id id,
  2607. CASE
  2608. WHEN (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END) = 0 THEN NULL
  2609. 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
  2610. CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
  2611. END)) / (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END),4)
  2612. END AS remainWorkTimeProportion
  2613. FROM
  2614. project p
  2615. LEFT JOIN
  2616. report r ON p.id = r.project_id
  2617. LEFT JOIN
  2618. task_group g ON g.project_id =p.id
  2619. WHERE
  2620. p.company_id = #{map.companyId}
  2621. AND p.`status` IN (1, 2)
  2622. AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
  2623. <if test="map.projectId!=null">
  2624. AND p.id = #{map.projectId}
  2625. </if>
  2626. GROUP BY
  2627. p.id,g.`name`,g.id
  2628. <if test="map.isWarn!=null and map.isWarn==1 ">
  2629. HAVING remainWorkTimeProportion *100 &lt; #{map.warningPercent}
  2630. </if>
  2631. ) a
  2632. </select>
  2633. <select id="getParticipatedProjectWithMainProjectId" resultType="java.util.Map">
  2634. 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
  2635. FROM project
  2636. WHERE id IN (
  2637. SELECT project_id
  2638. FROM participation
  2639. WHERE user_id = #{userId}
  2640. ) or incharger_id = #{userId}
  2641. or creator_id = #{userId}
  2642. or (is_public = 1 and company_id = #{companyId})
  2643. and project_main_id = #{projectMainId}
  2644. ORDER BY is_public DESC, id DESC
  2645. </select>
  2646. <select id="getProjectInAndOutTotal" resultType="java.lang.Integer">
  2647. SELECT count(*) total
  2648. FROM project
  2649. left join contract on contract.project_id = project.id
  2650. WHERE project.`company_id` = #{companyId}
  2651. and (project.status &lt;&gt; 3 or project.status is null)
  2652. <if test="projectId != null">
  2653. and project.id = #{projectId}
  2654. </if>
  2655. <if test="projectMainId != null">
  2656. and project.project_main_id = #{projectMainId}
  2657. </if>
  2658. <if test="inchagerIds!=null and inchagerIds.size()>0">
  2659. and project.id in
  2660. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  2661. #{item}
  2662. </foreach>
  2663. </if>
  2664. </select>
  2665. <select id="getTaskPlanByGeneralMemb" resultType="java.util.Map">
  2666. 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,
  2667. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2668. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
  2669. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2670. FROM user
  2671. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2672. left join task on task.id = task_executor.task_id
  2673. LEFT JOIN project ON project.`id` = task.`project_id`
  2674. WHERE user.`id` IN
  2675. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  2676. #{item}
  2677. </foreach>
  2678. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  2679. and task.end_date is not null
  2680. <if test="targetUserId !=null and targetUserId !='' ">
  2681. and user.`id`=#{targetUserId}
  2682. </if>
  2683. AND project.`status` = 1 and task.task_plan=1
  2684. ORDER BY user.id, task.start_date
  2685. </select>
  2686. <select id="getTaskPlanWithLeave" resultType="java.util.Map">
  2687. SELECT user.`id` as user_id, user.`name`,task.id as task_id, task.name as task_name,task_executor.id as exe_id,
  2688. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2689. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
  2690. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2691. FROM user
  2692. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2693. left join task on task.id = task_executor.task_id
  2694. WHERE
  2695. ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  2696. and task.end_date is not null and task.task_plan_type=3 and task.task_plan=1
  2697. <if test="targetUserId !=null and targetUserId !='' ">
  2698. and user.`id`=#{targetUserId}
  2699. </if>
  2700. ORDER BY user.id, task.start_date
  2701. </select>
  2702. <select id="getTaskPlanByProManager" resultType="java.util.Map">
  2703. 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,
  2704. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2705. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
  2706. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2707. FROM user
  2708. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2709. left join task on task.id = task_executor.task_id
  2710. LEFT JOIN project ON project.`id` = task.`project_id`
  2711. WHERE user.`id` IN
  2712. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  2713. #{item}
  2714. </foreach>
  2715. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  2716. and task.end_date is not null and task.is_task_plan=1 and project.incharger_id=#{managerId}
  2717. AND project.`status` = 1 and task.task_plan=1 and task.task_status !=2
  2718. <if test="targetUserId !=null and targetUserId !='' ">
  2719. and user.`id`=#{targetUserId}
  2720. </if>
  2721. ORDER BY user.id, task.start_date
  2722. </select>
  2723. <select id="getTaskPlanByAreaManager" resultType="java.util.Map">
  2724. 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,
  2725. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
  2726. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
  2727. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
  2728. FROM user
  2729. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2730. left join task on task.id = task_executor.task_id
  2731. LEFT JOIN project ON project.`id` = task.`project_id`
  2732. WHERE user.`id` IN
  2733. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  2734. #{item}
  2735. </foreach>
  2736. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  2737. and task.end_date is not null and task.check_second_id=#{managerId}
  2738. AND project.`status` = 1 and task.task_plan=1 and task.task_status !=2
  2739. <if test="targetUserId !=null and targetUserId !='' ">
  2740. and user.`id`=#{targetUserId}
  2741. </if>
  2742. ORDER BY user.id, task.start_date
  2743. </select>
  2744. <select id="getTaskPlanByProjectGeneralMemb" resultType="java.util.Map">
  2745. 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,
  2746. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
  2747. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
  2748. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  2749. LEFT JOIN task ON task.project_id = project.id
  2750. <if test="groupName !=null and groupName !='' ">
  2751. LEFT JOIN task_group tg ON tg.project_id = project.id
  2752. </if>
  2753. WHERE project.company_id = #{companyId}
  2754. <if test="projectIds != null">
  2755. and project.`id` IN
  2756. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  2757. #{item}
  2758. </foreach>
  2759. </if>
  2760. <if test="groupName !=null and groupName !='' ">
  2761. and tg.name = #{groupName} and task.group_id=tg.id
  2762. </if>
  2763. <if test="taskType !=null ">
  2764. and task.task_type = #{taskType}
  2765. </if>
  2766. <if test="targetProjectId !=null ">
  2767. and project.`id` = #{targetProjectId}
  2768. </if>
  2769. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  2770. and task.end_date is not null
  2771. AND project.`status` = 1
  2772. ORDER BY project.id, task.start_date
  2773. </select>
  2774. <select id="getTaskPlanByProjectManager" resultType="java.util.Map">
  2775. 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,
  2776. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
  2777. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
  2778. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  2779. LEFT JOIN task ON task.project_id = project.id
  2780. <if test="groupName !=null and groupName !='' ">
  2781. LEFT JOIN task_group tg ON tg.project_id = project.id
  2782. </if>
  2783. WHERE project.company_id = #{companyId}
  2784. <if test="projectIds != null">
  2785. and project.`id` IN
  2786. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  2787. #{item}
  2788. </foreach>
  2789. </if>
  2790. <if test="groupName !=null and groupName !='' ">
  2791. and tg.name = #{groupName} and task.group_id=tg.id
  2792. </if>
  2793. <if test="taskType !=null ">
  2794. and task.task_type = #{taskType}
  2795. </if>
  2796. <if test="targetProjectId !=null ">
  2797. and project.`id` = #{targetProjectId}
  2798. </if>
  2799. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  2800. and task.end_date is not null and task.is_task_plan=1 and project.incharger_id=#{managerId} and task.task_status !=2
  2801. AND project.`status` = 1
  2802. ORDER BY project.id, task.start_date
  2803. </select>
  2804. <select id="getTaskPlanByProjectAreaManager" resultType="java.util.Map">
  2805. 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,
  2806. task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
  2807. task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
  2808. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  2809. LEFT JOIN task ON task.project_id = project.id
  2810. <if test="groupName !=null and groupName !='' ">
  2811. LEFT JOIN task_group tg ON tg.project_id = project.id
  2812. </if>
  2813. WHERE project.company_id = #{companyId}
  2814. <if test="projectIds != null">
  2815. and project.`id` IN
  2816. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  2817. #{item}
  2818. </foreach>
  2819. </if>
  2820. <if test="groupName !=null and groupName !='' ">
  2821. and tg.name = #{groupName} and task.group_id=tg.id
  2822. </if>
  2823. <if test="taskType !=null ">
  2824. and task.task_type = #{taskType}
  2825. </if>
  2826. <if test="targetProjectId !=null ">
  2827. and project.`id` = #{targetProjectId}
  2828. </if>
  2829. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  2830. and task.end_date is not null and task.task_plan=1 and task.check_second_id=#{managerId}
  2831. AND project.`status` = 1 and task.task_status !=2
  2832. ORDER BY project.id, task.start_date
  2833. </select>
  2834. <select id="getFTETaskPlanData" resultType="java.util.Map">
  2835. select t.id, u.plate1 area, p.project_code projectCode,p.project_name projectName,u.name userName, sum(daily.work_hour) planHours, date_format(MIN(daily.`allocate_date`) , '%Y-%m-%d') startDate, date_format(MAX(daily.allocate_date),'%Y-%m-%d') endDate
  2836. ,p.category_name categoryName,p.incharger_id inchargerId,p.associate_degree_names associateDegreeNames,tg.name groupName,
  2837. stages.stages_name stagesName,t.name taskName,te.first_auditor_id firstAuditorId, te.second_auditor_id secondAuditorId,t.task_status auditStatus
  2838. ,u.department_id departmentId,u.role_name roleName,t.task_plan_type taskPlanType,u.id userId,u.corpwx_userid as corpwxUserId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId
  2839. from task t
  2840. LEFT JOIN stages ON stages.id = t.stages_id
  2841. LEFT JOIN task_group tg ON tg.id=t.group_id
  2842. LEFT JOIN project p ON t.project_id=p.id
  2843. LEFT JOIN task_daily_allocate daily ON daily.`task_id` = t.id
  2844. LEFT JOIN user u ON u.id= daily.`user_id`
  2845. LEFT JOIN department ON department.department_id = u.department_id
  2846. LEFT JOIN task_executor te ON te.task_id = daily.`task_id` AND te.`executor_id` = daily.`user_id`
  2847. WHERE u.company_id=#{companyId}
  2848. <if test="area!=null and area != '' ">
  2849. and u.plate1 = #{area}
  2850. </if>
  2851. <if test="userId!=null and userId != '' ">
  2852. and u.id = #{userId}
  2853. </if>
  2854. <if test="deptIds!=null and deptIds.size()>0">
  2855. and u.department_id in
  2856. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  2857. #{item}
  2858. </foreach>
  2859. </if>
  2860. and daily.`allocate_date` BETWEEN #{startDate} AND #{endDate}
  2861. GROUP BY t.id, daily.`user_id`
  2862. <if test="start!=null and size !=null">
  2863. limit #{start},#{size}
  2864. </if>
  2865. </select>
  2866. <select id="getFTETaskPlanDataCount" resultType="java.lang.Integer">
  2867. select count(distinct t.id, daily.`user_id`) from task t
  2868. LEFT JOIN stages ON stages.id = t.stages_id
  2869. LEFT JOIN task_group tg ON tg.id=t.group_id
  2870. LEFT JOIN project p ON t.project_id=p.id
  2871. LEFT JOIN task_daily_allocate daily ON daily.`task_id` = t.id
  2872. LEFT JOIN user u ON u.id= daily.`user_id`
  2873. LEFT JOIN department ON department.department_id = u.department_id
  2874. LEFT JOIN task_executor te ON te.task_id = daily.`task_id` AND te.`executor_id` = daily.`user_id`
  2875. WHERE u.company_id=#{companyId}
  2876. <if test="area!=null and area != '' ">
  2877. and u.plate1 = #{area}
  2878. </if>
  2879. <if test="userId!=null and userId != '' ">
  2880. and u.id = #{userId}
  2881. </if>
  2882. <if test="deptIds!=null and deptIds.size()>0">
  2883. and u.department_id in
  2884. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  2885. #{item}
  2886. </foreach>
  2887. </if>
  2888. and daily.`allocate_date` BETWEEN #{startDate} AND #{endDate}
  2889. </select>
  2890. <select id="getRelatedProjectIds" resultType="java.lang.Integer">
  2891. SELECT DISTINCT pl.project_id
  2892. FROM project_leader pl
  2893. WHERE pl.leader_id = #{userId}
  2894. UNION
  2895. SELECT DISTINCT p.id
  2896. FROM project p
  2897. INNER JOIN task t ON t.project_id = p.id
  2898. LEFT JOIN task_executor te ON te.task_id = t.id
  2899. WHERE p.company_id = #{companyId}
  2900. AND (te.first_auditor_id = #{userId} OR te.second_auditor_id = #{userId})
  2901. </select>
  2902. <select id="getExistIds" resultType="java.lang.String">
  2903. select project_code
  2904. from project
  2905. where company_id = #{companyId}
  2906. and project_code in <foreach collection="projectCodes" item="projectCode" separator="," open="(" close=")">#{projectCode}</foreach>
  2907. </select>
  2908. <select id="getexportTaskPlanByMemb" resultType="com.management.platform.entity.vo.GantExportVo">
  2909. SELECT user.`id` as userId,
  2910. user.`name` userName,
  2911. project.`project_name` projectName,
  2912. project.id projectId,
  2913. tda.task_id as allocateTaskId,
  2914. task.id as taskId,
  2915. task.name as taskName,
  2916. task_executor.plan_hours as duration,
  2917. task.task_plan_type as taskPlanType,
  2918. task.task_status as taskStatus,
  2919. d.department_name deptName,
  2920. tda.allocate_date allocateDate,
  2921. SUM(tda.work_hour) as totalWorkHour,
  2922. SUM(tda.over_work_hour) as totalOverWorkHour
  2923. FROM user
  2924. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  2925. left join task on task.id = task_executor.task_id
  2926. left join task_type on task_type.id = task.task_plan_type
  2927. LEFT JOIN project ON project.`id` = task.`project_id`
  2928. LEFT join task_daily_allocate tda on tda.user_id=user.id AND tda.task_id = task.id
  2929. LEFT JOIN department d on user.department_id=d.department_id
  2930. <where>
  2931. and task.end_date is not null
  2932. AND (project.`status` = 1 or project.`status` is null)
  2933. <if test="userIds!=null and userIds.size()>0">
  2934. and user.`id` IN
  2935. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  2936. #{item}
  2937. </foreach>
  2938. </if>
  2939. <if test="startDate !=null and startDate!='' and endDate !=null and endDate!=''">
  2940. and ((IFNULL(task.start_date , task.end_date) &lt;= #{endDate}) and (task.end_date &gt;= #{startDate}))
  2941. </if>
  2942. <if test="deptId !=null">
  2943. and user.department_id= #{deptId}
  2944. </if>
  2945. <if test="taskStatus != null">
  2946. <choose>
  2947. <when test="taskStatus == 0">
  2948. and task.task_status in (3, 4)
  2949. </when>
  2950. <when test="taskStatus == 1">
  2951. and task.task_status = 1
  2952. </when>
  2953. <when test="taskStatus == 2">
  2954. and task.task_status in (5, 6)
  2955. </when>
  2956. <when test="taskStatus == 3">
  2957. and task.task_status = 2
  2958. </when>
  2959. </choose>
  2960. </if>
  2961. </where>
  2962. GROUP BY user.`id`,user.`name`,tda.task_id,project.`project_name`,project.id,tda.allocate_date
  2963. ORDER BY user.id, task.start_date
  2964. </select>
  2965. </mapper>