ProjectMapper.xml 144 KB

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