ProjectMapper.xml 146 KB

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