ProjectMapper.xml 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  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. </resultMap>
  62. <!-- 通用查询结果列 -->
  63. <sql id="Base_Column_List">
  64. 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
  65. </sql>
  66. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  67. <result column="id" property="id" />
  68. <result column="project_name" property="projectName" />
  69. <result column="project_code" property="projectCode" />
  70. <result column="startDate" property="startDate" />
  71. <result column="endDate" property="endDate" />
  72. <collection property="stageCostList" javaType="java.util.ArrayList"
  73. ofType="com.management.platform.entity.vo.StageCost"
  74. select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
  75. </resultMap>
  76. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  77. <result column="customer_id" property="customerId" />
  78. <result column="customer_name" property="customerName" />
  79. <result column="contract_amount" property="contractAmount" />
  80. <result column="fee_man" property="feeMan" />
  81. <result column="project_num" property="projectNum" />
  82. <result column="project_ids" property="projectIds" />
  83. <result column="project_names" property="projectNames" />
  84. </resultMap>
  85. <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
  86. select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
  87. from project
  88. where company_id = #{companyId}
  89. <if test="projectId != null">
  90. and id = #{projectId}
  91. </if>
  92. <if test="inchargerId!=null">
  93. and incharger_id = #{inchargerId}
  94. </if>
  95. order by is_public desc, id asc
  96. <if test="startIndex != null">
  97. limit ${startIndex}, ${endIndex}
  98. </if>
  99. </select>
  100. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  101. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  102. IFNULL(SUM(report.`working_time`), 0) AS working_time,
  103. 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
  104. FROM report
  105. left join project p on p.id=report.`project_id`
  106. where report.state = 1
  107. <if test="inchargerId!=null">
  108. and p.incharger_id = #{inchargerId}
  109. </if>
  110. <if test="projectIds!=null and projectIds.size()>0">
  111. and p.id in
  112. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  113. #{item}
  114. </foreach>
  115. </if>
  116. and report.create_date &gt;= #{startDate}
  117. and report.create_date &lt;= #{endDate}
  118. GROUP BY report.`project_id`,report.stage
  119. </select>
  120. <!--获取查询者所在公司每个项目的工时成本-->
  121. <select id="getParticipatedProject" resultType="java.util.Map">
  122. 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
  123. FROM project
  124. WHERE id IN (
  125. SELECT project_id
  126. FROM participation
  127. WHERE user_id = #{userId}
  128. ) or incharger_id = #{userId}
  129. or creator_id = #{userId}
  130. or (is_public = 1 and company_id = #{companyId})
  131. ORDER BY is_public DESC, id DESC
  132. </select>
  133. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  134. 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
  135. FROM project
  136. WHERE status = 1 and (id IN (
  137. SELECT project_id
  138. FROM participation
  139. WHERE user_id = #{userId}
  140. )
  141. or (is_public = 1 and company_id = #{companyId}))
  142. ORDER BY is_public DESC, id ASC
  143. </select>
  144. <!--获取查询者所在公司每个项目的工时成本-->
  145. <select id="getTimeCost" resultType="java.util.Map">
  146. 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
  147. FROM project AS a
  148. LEFT JOIN report AS b ON b.project_id = a.id
  149. JOIN user AS c ON b.creator_id = c.id
  150. WHERE a.company_id = #{companyId}
  151. <if test="projectId != null">
  152. AND a.id = #{projectId}
  153. </if>
  154. <if test="categoryId != null">
  155. AND a.category = #{categoryId}
  156. </if>
  157. <if test="projectIds != null">
  158. and a.id in
  159. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  160. #{item}
  161. </foreach>
  162. </if>
  163. <if test="userIdList != null and userIdList.size()>0">
  164. AND b.creator_id in
  165. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  166. #{item}
  167. </foreach>
  168. </if>
  169. <if test="startDate != null and endDate != null">
  170. AND b.create_date between #{startDate} and #{endDate}
  171. </if>
  172. <choose>
  173. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  174. and b.dept_id in
  175. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  176. #{item}
  177. </foreach>
  178. </when>
  179. <otherwise>
  180. <if test="deptIds!=null and deptIds.size()>0">
  181. and (b.dept_id in
  182. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  183. #{item}
  184. </foreach>
  185. <if test="deptRelatedProjectIds.size() > 0">
  186. or a.id in
  187. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  188. #{pid}
  189. </foreach>
  190. </if>
  191. <if test="inchargeUserIds != null and inchargeUserIds.size()>0">
  192. OR a.`incharger_id` IN
  193. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  194. #{pid}
  195. </foreach>
  196. OR b.`group_id` IN(SELECT id FROM task_group WHERE incharger_id IN
  197. <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
  198. #{pid}
  199. </foreach>
  200. )
  201. </if>
  202. )
  203. </if>
  204. </otherwise>
  205. </choose>
  206. AND b.state = 1
  207. GROUP BY a.id
  208. ORDER BY a.id ASC
  209. </select>
  210. <!--获取查询者所在公司每个子项目的工时成本-->
  211. <select id="getSubProjectTimeCost" resultType="java.util.Map">
  212. 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
  213. from sub_project a
  214. left join project b on b.id=a.project_id
  215. left join report c on c.sub_project_id=a.id
  216. where a.company_id=#{companyId}
  217. and c.state = 1
  218. <if test="startDate != null and endDate != null">
  219. and c.create_date between #{startDate} and #{endDate}
  220. </if>
  221. <if test="projectId!=null">
  222. and a.project_id=#{projectId}
  223. </if>
  224. <if test="inchagerIds!=null and inchagerIds.size()>0">
  225. and b.id in
  226. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  227. #{item}
  228. </foreach>
  229. </if>
  230. group by b.id,a.id
  231. <if test="start!=null and size!=null">
  232. limit #{start},#{size}
  233. </if>
  234. </select>
  235. <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
  236. 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
  237. from sub_project a
  238. left join project b on b.id=a.project_id
  239. left join report c on c.sub_project_id=a.id
  240. where a.company_id=#{companyId}
  241. and c.state = 1
  242. <if test="startDate != null and endDate != null">
  243. and c.create_date between #{startDate} and #{endDate}
  244. </if>
  245. <if test="projectId!=null">
  246. and a.project_id=#{projectId}
  247. </if>
  248. <if test="inchagerIds!=null and inchagerIds.size()>0">
  249. and b.id in
  250. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  251. #{item}
  252. </foreach>
  253. </if>
  254. group by b.id,a.id
  255. <if test="start!=null and size!=null">
  256. limit #{start},#{size}
  257. </if>) as total
  258. </select>
  259. <!--获取查询者所在公司每个项目的工时成本-->
  260. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  261. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'无主项目') as mainProjectName
  262. FROM project AS a
  263. LEFT JOIN report AS b ON b.project_id = a.id
  264. JOIN user AS c ON b.creator_id = c.id
  265. LEFT JOIN project_main pm on pm.id=a.project_main_id
  266. WHERE a.company_id = #{companyId}
  267. <if test="projectId != null">
  268. AND a.id = #{projectId}
  269. </if>
  270. <if test="startDate != null and endDate != null">
  271. AND b.create_date between #{startDate} and #{endDate}
  272. </if>
  273. <if test="deptIds!=null and deptIds.size()>0">
  274. and b.dept_id in
  275. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  276. #{item}
  277. </foreach>
  278. </if>
  279. AND b.state = 1
  280. GROUP BY a.project_main_id
  281. ORDER BY a.id ASC
  282. </select>
  283. <!--获取查询者所在公司每个项目分类的工时成本-->
  284. <select id="getTimeCostByCategory" resultType="java.util.Map">
  285. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  286. FROM project AS a
  287. LEFT JOIN report AS b ON b.project_id = a.id
  288. JOIN user AS c ON b.creator_id = c.id
  289. WHERE a.company_id = #{companyId}
  290. <if test="projectCategoryId != null">
  291. AND a.category = #{projectCategoryId}
  292. </if>
  293. <if test="projectIds != null">
  294. and a.id in
  295. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  296. #{item}
  297. </foreach>
  298. </if>
  299. <if test="userIdList != null and userIdList.size()>0">
  300. AND b.creator_id in
  301. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  302. #{item}
  303. </foreach>
  304. </if>
  305. <if test="startDate != null and endDate != null">
  306. AND b.create_date between #{startDate} and #{endDate}
  307. </if>
  308. <if test="deptIds!=null and deptIds.size()>0">
  309. and b.dept_id in
  310. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  311. #{item}
  312. </foreach>
  313. </if>
  314. AND b.state = 1
  315. GROUP BY a.category
  316. ORDER BY a.category ASC
  317. </select>
  318. <!--获取自定义数值的项目统计 -->
  319. <select id="getCustomDataSum" resultType="java.util.Map">
  320. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  321. FROM project AS a
  322. LEFT JOIN report AS b ON b.project_id = a.id
  323. JOIN user AS c ON b.creator_id = c.id
  324. WHERE a.company_id = #{companyId}
  325. <if test="projectId != null">
  326. AND a.id = #{projectId}
  327. </if>
  328. <if test="userId != null">
  329. AND b.creator_id = #{userId}
  330. </if>
  331. <if test="startDate != null and endDate != null">
  332. AND b.create_date between #{startDate} and #{endDate}
  333. </if>
  334. AND b.state = 1
  335. GROUP BY a.id
  336. having IFNULL(SUM(b.custom_data), 0) > 0
  337. ORDER BY SUM(b.custom_data) DESC
  338. </select>
  339. <!--获取日报的人员月度工时 -->
  340. <select id="getTimeCostReport" resultType="java.util.Map">
  341. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  342. FROM report AS a
  343. LEFT JOIN project AS b ON a.project_id = b.id
  344. LEFT JOIN user AS c ON a.creator_id = c.id
  345. WHERE b.company_id = #{companyId}
  346. <if test="projectId != null">
  347. AND b.id = #{projectId}
  348. </if>
  349. <if test="startDate != null and endDate != null">
  350. AND a.create_date between #{startDate} and #{endDate}
  351. </if>
  352. <if test="deptIds!=null and deptIds.size()>0">
  353. and a.dept_id in
  354. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  355. #{item}
  356. </foreach>
  357. </if>
  358. AND a.state = 1
  359. </select>
  360. <!--获取人员的月度总工时 -->
  361. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  362. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  363. FROM report AS a, user as b
  364. WHERE a.creator_id = b.id
  365. and b.company_id = #{companyId}
  366. <if test="startDate != null and endDate != null">
  367. AND a.create_date between #{startDate} and #{endDate}
  368. </if>
  369. AND a.state = 1
  370. group by a.creator_id
  371. </select>
  372. <!--获取某个项目每个人分别需要的工时-->
  373. <select id="getProjectCost" resultType="java.util.Map">
  374. 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
  375. FROM report AS a
  376. JOIN user AS b ON a.creator_id = b.id
  377. left join department on department.department_id = a.dept_id
  378. WHERE a.company_id=#{companyId}
  379. <choose>
  380. <when test="stateKey!=null and stateKey==1">
  381. and a.state = 1
  382. </when>
  383. <otherwise>
  384. and (a.state = 1 or a.state =0)
  385. </otherwise>
  386. </choose>
  387. <if test="projectId != null">
  388. and a.project_id = #{projectId}
  389. </if>
  390. <if test="startDate != null and endDate != null">
  391. AND a.create_date between #{startDate} and #{endDate}
  392. </if>
  393. <if test="userIdList != null and userIdList.size()>0">
  394. AND a.creator_id in
  395. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  396. #{item}
  397. </foreach>
  398. </if>
  399. <choose>
  400. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  401. and a.dept_id in
  402. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  403. #{item}
  404. </foreach>
  405. </when>
  406. <otherwise>
  407. <if test="deptIds!=null and deptIds.size()>0">
  408. and a.dept_id in
  409. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  410. #{item}
  411. </foreach>
  412. </if>
  413. </otherwise>
  414. </choose>
  415. GROUP BY b.id
  416. <if test="withDept">
  417. , a.dept_id
  418. </if>
  419. ORDER BY b.id ASC
  420. <if test="withDept">
  421. , a.dept_id ASC
  422. </if>
  423. </select>
  424. <!--获取某个项目分类每个人分别需要的工时-->
  425. <select id="getProjectCostByCategory" resultType="java.util.Map">
  426. 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
  427. FROM report AS a
  428. JOIN user AS b ON a.creator_id = b.id
  429. left join department on department.department_id = a.dept_id
  430. left join project c on c.id=a.project_id
  431. WHERE a.company_id=#{companyId} and a.state = 1
  432. <if test="curProjectCategoryId != null">
  433. and c.category = #{curProjectCategoryId}
  434. </if>
  435. <if test="startDate != null and endDate != null">
  436. AND a.create_date between #{startDate} and #{endDate}
  437. </if>
  438. <if test="userId != null">
  439. AND a.creator_id = #{userId}
  440. </if>
  441. GROUP BY c.category, a.dept_id
  442. ORDER BY c.category ASC, a.dept_id ASC
  443. </select>
  444. <!--获取个人每个项目分别需要的工时-->
  445. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  446. 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
  447. FROM report AS a
  448. JOIN user AS b ON a.creator_id = b.id
  449. left join department on department.department_id = a.dept_id
  450. WHERE a.company_id=#{companyId} and a.state = 1
  451. <if test="projectId != null">
  452. and a.project_id = #{projectId}
  453. </if>
  454. <if test="startDate != null and endDate != null">
  455. AND a.create_date between #{startDate} and #{endDate}
  456. </if>
  457. <if test="userIdList != null and userIdList.size()>0">
  458. AND a.creator_id in
  459. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  460. #{item}
  461. </foreach>
  462. </if>
  463. <if test="deptIds!=null and deptIds.size()>0">
  464. and a.dept_id in
  465. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  466. #{item}
  467. </foreach>
  468. </if>
  469. GROUP BY b.id,a.project_id
  470. ORDER BY b.id ASC, a.dept_id ASC
  471. </select>
  472. <!--获取个人每个项目分类分别需要的工时-->
  473. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  474. 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
  475. FROM report AS a
  476. JOIN user AS b ON a.creator_id = b.id
  477. left join department on department.department_id = a.dept_id
  478. left join project c on c.id=a.project_id
  479. WHERE a.company_id=#{companyId} and a.state = 1
  480. <if test="projectCategoryId != null">
  481. and c.category = #{projectCategoryId}
  482. </if>
  483. <if test="startDate != null and endDate != null">
  484. AND a.create_date between #{startDate} and #{endDate}
  485. </if>
  486. <if test="userIdList != null and userIdList.size()>0">
  487. AND a.creator_id in
  488. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  489. #{item}
  490. </foreach>
  491. </if>
  492. <if test="deptIds!=null and deptIds.size()>0">
  493. and a.dept_id in
  494. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  495. #{item}
  496. </foreach>
  497. </if>
  498. GROUP BY b.id,c.category
  499. ORDER BY b.id ASC, a.dept_id ASC
  500. </select>
  501. <!-- 获取人员在日报填写的自定义数值 -->
  502. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  503. SELECT b.id as creatorId,
  504. b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
  505. FROM report AS a
  506. JOIN user AS b ON a.creator_id = b.id
  507. left join department on department.department_id = b.department_id
  508. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  509. <if test="startDate != null and endDate != null">
  510. AND a.create_date between #{startDate} and #{endDate}
  511. </if>
  512. <if test="projectId != null">
  513. AND a.project_id = #{projectId}
  514. </if>
  515. <if test="userId != null">
  516. AND a.creator_id = #{userId}
  517. </if>
  518. <if test="deptIds != null">
  519. AND department.department_id in
  520. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  521. #{item}
  522. </foreach>
  523. </if>
  524. group by b.id
  525. ORDER BY b.id ASC
  526. </select>
  527. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  528. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  529. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  530. FROM report AS a
  531. JOIN user AS b ON a.creator_id = b.id
  532. left join department on department.department_id = b.department_id
  533. left join project on project.id = a.project_id
  534. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  535. <if test="startDate != null and endDate != null">
  536. AND a.create_date between #{startDate} and #{endDate}
  537. </if>
  538. <if test="projectId != null">
  539. AND a.project_id = #{projectId}
  540. </if>
  541. <if test="userId != null">
  542. AND a.creator_id = #{userId}
  543. </if>
  544. ORDER BY a.create_date desc
  545. </select>
  546. <!--按照项目内的阶段名称分组统计工时-->
  547. <select id="getCostInStage" resultType="java.util.Map">
  548. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  549. FROM report AS a
  550. WHERE a.project_id = #{projectId}
  551. AND a.state = 1
  552. <if test="startDate != null and endDate != null">
  553. AND a.create_date between #{startDate} and #{endDate}
  554. </if>
  555. GROUP BY a.stage
  556. ORDER BY a.stage ASC
  557. </select>
  558. <!--按照项目内的阶段名称分组统计工时-->
  559. <select id="getCostByGroup" resultType="java.util.Map">
  560. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  561. FROM report AS a
  562. left join task_group tg on tg.id=a.group_id
  563. WHERE a.project_id = #{projectId}
  564. AND a.state = 1
  565. <if test="startDate != null and endDate != null">
  566. AND a.create_date between #{startDate} and #{endDate}
  567. </if>
  568. <if test="gpIds != null">
  569. AND a.group_id in
  570. <foreach collection="gpIds" open="(" separator="," close=")" item="item">
  571. #{item}
  572. </foreach>
  573. </if>
  574. GROUP BY a.group_id
  575. ORDER BY a.group_id ASC
  576. </select>
  577. <!--获取全部人员工时 -->
  578. <select id="getAllMembCost" resultType="java.util.Map">
  579. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  580. FROM user AS b
  581. left JOIN report AS a ON a.creator_id = b.id
  582. WHERE a.state = 1
  583. and b.company_id = #{companyId}
  584. <if test="startDate != null and endDate != null">
  585. AND a.create_date between #{startDate} and #{endDate}
  586. </if>
  587. <if test="projectId != null">
  588. AND a.project_id = #{projectId}
  589. </if>
  590. GROUP BY b.id
  591. ORDER BY b.id ASC
  592. </select>
  593. <!--分页获取项目成本 -->
  594. <select id="getAllProjectCost" resultType="java.util.Map">
  595. SELECT id, project_code as projectCode, project_name as projectName,budget,
  596. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  597. FROM project WHERE project.`company_id` = #{companyId}
  598. and (project.status &lt;&gt; 3 or project.status is null)
  599. <if test="projectId != null">
  600. and project.id = #{projectId}
  601. </if>
  602. <if test="inchagerIds!=null and inchagerIds.size()>0">
  603. and project.id in
  604. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  605. #{item}
  606. </foreach>
  607. </if>
  608. order by project.is_public desc, project.id asc
  609. <if test="pageStart != null and pageSize != null">
  610. LIMIT #{pageStart},#{pageSize}
  611. </if>
  612. </select>
  613. <!--分页获取项目收支平衡 -->
  614. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  615. SELECT project.id, project_code, project_name,contract_amount, IFNULL(contract.payment, 0) as payment,
  616. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  617. FROM project
  618. left join contract on contract.project_id = project.id
  619. WHERE project.`company_id` = #{companyId}
  620. and (project.status &lt;&gt; 3 or project.status is null)
  621. <if test="projectId != null">
  622. and project.id = #{projectId}
  623. </if>
  624. <if test="inchagerIds!=null and inchagerIds.size()>0">
  625. and project.id in
  626. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  627. #{item}
  628. </foreach>
  629. </if>
  630. order by is_public desc, project.id asc
  631. <if test="pageStart != null and pageSize != null">
  632. LIMIT #{pageStart},#{pageSize}
  633. </if>
  634. </select>
  635. <select id="getProjectExpenseFee" resultType="java.util.Map">
  636. 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
  637. left join expense_sheet on expense_sheet.id = expense_item.`expense_id`
  638. left join expense_main_type on expense_main_type.id = expense_sheet.`type`
  639. WHERE expense_sheet.`company_id` = #{companyId} AND expense_sheet.id = expense_item.`expense_id`
  640. AND expense_sheet.status = 0
  641. and project_id in
  642. <foreach collection="projectIds" open="(" separator="," close=")" item="item">
  643. #{item}
  644. </foreach>
  645. GROUP BY project_id, expense_sheet.type
  646. </select>
  647. <!--分页获取客户项目的成本利润报表 -->
  648. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  649. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  650. SUM(contract_amount) AS contract_amount ,
  651. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man
  652. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  653. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  654. <if test="customerId!=null">
  655. and project.customer_id=#{customerId}
  656. </if>
  657. <if test="projectId!=null">
  658. and project.id=#{projectId}
  659. </if>
  660. GROUP BY customer_id
  661. <if test="pageStart != null and pageSize != null">
  662. LIMIT #{pageStart},#{pageSize}
  663. </if>
  664. </select>
  665. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  666. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  667. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  668. <if test="customerId!=null">
  669. and project.customer_id=#{customerId}
  670. </if>
  671. <if test="projectId!=null">
  672. and project.id=#{projectId}
  673. </if>
  674. </select>
  675. <!--分页获取项目收支平衡 -->
  676. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  677. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  678. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
  679. FROM project WHERE project.`company_id` = #{companyId}
  680. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  681. #{item}
  682. </foreach>
  683. </select>
  684. <select id="getGanttData" resultType="java.util.Map">
  685. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  686. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  687. LEFT JOIN user ON user.id = participation.`user_id`
  688. LEFT JOIN project ON project.`id` = participation.`project_id`
  689. WHERE participation.`user_id` IN
  690. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  691. #{item}
  692. </foreach>
  693. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  694. ORDER BY participation.user_id, project.`plan_start_date`
  695. </select>
  696. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  697. 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,
  698. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level FROM user
  699. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  700. left join task on task.id = task_executor.task_id
  701. LEFT JOIN project ON project.`id` = task.`project_id`
  702. WHERE user.`id` IN
  703. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  704. #{item}
  705. </foreach>
  706. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  707. and task.end_date is not null
  708. AND project.`status` = 1
  709. ORDER BY user.id, task.start_date
  710. </select>
  711. <select id="getTaskPlanByProject" resultType="java.util.Map">
  712. 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,
  713. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  714. LEFT JOIN task ON task.project_id = project.id
  715. WHERE project.company_id = #{companyId}
  716. <if test="projectIds != null">
  717. and project.`id` IN
  718. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  719. #{item}
  720. </foreach>
  721. </if>
  722. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  723. and task.end_date is not null
  724. AND project.`status` = 1
  725. ORDER BY project.id, task.start_date
  726. </select>
  727. <!--获取加班统计报表 -->
  728. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  729. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  730. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  731. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  732. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  733. <!-- left join project on project.id = report.project_id-->
  734. <!-- WHERE report.is_overtime = 1-->
  735. <!-- and report.`state` = 1-->
  736. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  737. <!-- AND user.`company_id` = #{companyId}-->
  738. <!-- <if test="projectId != null">-->
  739. <!-- AND report.`project_id` = #{projectId}-->
  740. <!-- </if>-->
  741. <!-- <if test="userId != null">-->
  742. <!-- AND report.`creator_id` = #{userId}-->
  743. <!-- </if>-->
  744. <!-- GROUP BY report.creator_id-->
  745. <!-- </select>-->
  746. <!-- 获取某个员工的某时间段内的加班详情 -->
  747. <select id="getOvertimeDetail" resultType="java.util.Map">
  748. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  749. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  750. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  751. project.project_name as projectName,project.project_code as projectCode,
  752. IFNULL(report.overtime_cost, 0) AS cost,
  753. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  754. left join project on project.id = report.project_id
  755. left join report_extra_degree on report_extra_degree.id = report.degree_id
  756. left join department on department.department_id = report.dept_id
  757. WHERE report.is_overtime = 1
  758. and report.`state` = 1
  759. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  760. AND user.`company_id` = #{companyId}
  761. <if test="projectId != null">
  762. AND report.`project_id` = #{projectId}
  763. </if>
  764. <if test="userId != null">
  765. AND report.`creator_id` = #{userId}
  766. </if>
  767. <if test="branchDepartment!=null and branchDepartment.size()>0">
  768. and report.dept_id in
  769. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  770. #{item}
  771. </foreach>
  772. </if>
  773. <if test="deptIds!=null and deptIds.size()>0">
  774. and report.dept_id in
  775. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  776. #{item}
  777. </foreach>
  778. </if>
  779. order by user.create_time asc, report.create_date desc
  780. </select>
  781. <!--获取人员工时-->
  782. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  783. 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,
  784. user.department_id As deptId,
  785. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  786. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  787. ifnull(SUM(report.`working_time`),0) AS workingTime,
  788. ifnull(SUM(report.`overtime_hours`),0) AS overtimeHours
  789. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  790. left join project on project.id = report.project_id
  791. WHERE
  792. report.`state` = 1
  793. AND user.`is_active` = 1
  794. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  795. AND user.`company_id` =#{companyId}
  796. <if test="userId!=null">
  797. and user.id=#{userId}
  798. </if>
  799. <if test="projectId!=null">
  800. and project.id=#{projectId}
  801. </if>
  802. <if test="branchDepartment!=null and branchDepartment.size()>0">
  803. and report.dept_id in
  804. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  805. #{item}
  806. </foreach>
  807. </if>
  808. <if test="deptIds!=null and deptIds.size()>0">
  809. and report.dept_id in
  810. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  811. #{item}
  812. </foreach>
  813. </if>
  814. group by user.id
  815. order by user.create_time asc, report.create_date desc
  816. <if test="start!=null and size!=null">
  817. limit #{start},#{size}
  818. </if>
  819. </select>
  820. <select id="findCountWithUser" resultType="java.lang.Long">
  821. select count(*)
  822. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  823. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  824. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  825. ifnull(SUM(report.`working_time`),0) AS workingTime
  826. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  827. left join project on project.id = report.project_id
  828. WHERE
  829. report.`state` = 1
  830. AND user.`is_active` = 1
  831. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  832. AND user.`company_id` =#{companyId}
  833. <if test="userId!=null">
  834. and user.id=#{userId}
  835. </if>
  836. <if test="projectId!=null">
  837. and project.id=#{projectId}
  838. </if>
  839. <if test="departmentId!=null">
  840. and report.dept_id=#{departmentId}
  841. </if>
  842. <if test="deptIds!=null and deptIds.size()>0">
  843. and report.dept_id in
  844. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  845. #{item}
  846. </foreach>
  847. </if>
  848. group by user.id
  849. order by user.create_time asc, report.create_date desc
  850. <if test="start!=null and size!=null">
  851. limit #{start},#{size}
  852. </if>) as total
  853. </select>
  854. <!--按照项目内的阶段名称分组统计工时-->
  855. <select id="getDegreeCost" resultType="java.util.Map">
  856. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
  857. FROM report AS a
  858. left join report_extra_degree b on b.id = a.degree_id
  859. WHERE
  860. a.state = 1
  861. and a.company_id = #{companyId}
  862. <if test="departmentIds!=null and departmentIds.size()>0">
  863. and a.dept_id in
  864. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  865. #{item}
  866. </foreach>
  867. </if>
  868. <if test="projectId != null">
  869. and a.project_id = #{projectId}
  870. </if>
  871. <if test="userId != null and userId!=''">
  872. and a.creator_id = #{userId}
  873. </if>
  874. <if test="startDate != null and endDate != null">
  875. AND a.create_date between #{startDate} and #{endDate}
  876. </if>
  877. GROUP BY a.degree_id
  878. ORDER BY a.degree_id ASC
  879. </select>
  880. <!--项目导出数据-->
  881. <select id="getExportData" resultType="java.util.HashMap" >
  882. 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,
  883. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  884. customer_name, associate_degree_names, provider_names,provider_ids
  885. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  886. LEFT JOIN participation c ON c.project_id = project.`id`
  887. LEFT JOIN user u ON u.id = c.user_id
  888. LEFT JOIN user d ON d.id = project.`incharger_id`
  889. WHERE project.`company_id` = #{companyId}
  890. <if test="userId != null" >
  891. and (project.creator_id = #{userId} or c.user_id = #{userId})
  892. </if>
  893. GROUP BY project.id
  894. </select>
  895. <!--按项目分组导出数据-->
  896. <select id="getExportGroupData" resultType="java.util.Map" >
  897. SELECT project_code AS projectCode,project_name AS projectName,task_group.`name` AS groupName,task_group.`incharger_id` AS inchargerId,
  898. GROUP_CONCAT(group_participator.`user_id`) AS participatorIds
  899. FROM task_group
  900. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  901. LEFT JOIN project ON task_group.project_id = project.id
  902. <if test="projectCategorySub!=null and projectCategorySub!=''">
  903. left join project_separate ps on ps.id=project.id
  904. </if>
  905. where project.company_id = #{companyId}
  906. <if test="projectCategorySub!=null and projectCategorySub!=''">
  907. and ps.project_category_sub=#{projectCategorySub}
  908. </if>
  909. GROUP BY task_group.id
  910. ORDER BY project_id
  911. </select>
  912. <!--分页获取项目工时成本预警表 -->
  913. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  914. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  915. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  916. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  917. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  918. AND project_id=project.id) AS costLimit,
  919. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  920. FROM project WHERE company_id=#{companyId}
  921. and (project.status &lt;&gt; 3 or project.status is null)
  922. <if test="projectId != null">
  923. and project.id = #{projectId}
  924. </if>
  925. <if test="pageStart != null and pageSize != null">
  926. LIMIT #{pageStart},#{pageSize}
  927. </if>
  928. </select>
  929. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  930. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  931. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  932. 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,
  933. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  934. 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,
  935. (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
  936. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  937. <if test="projectId != null">
  938. and project.id = #{projectId}
  939. </if>
  940. <if test="list!=null and list.size()>0">
  941. and project.id in
  942. <foreach collection="list" open="(" close=")" item="item" separator=",">
  943. #{item}
  944. </foreach>
  945. </if>
  946. <if test="pageStart != null and pageSize != null">
  947. LIMIT #{pageStart},#{pageSize}
  948. </if>
  949. </select>
  950. <select id="getWaitingReviewList" resultType="java.util.Map">
  951. <choose>
  952. <when test="stateKey==0">
  953. 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
  954. FROM report AS a
  955. left join user on user.id = a.creator_id
  956. JOIN project AS b ON a.project_id=b.id
  957. left join sub_project as d on d.id = a.sub_project_id
  958. left join task on task.id = a.task_id
  959. left join report_extra_degree on report_extra_degree.id = a.degree_id
  960. left join department on department.department_id = a.audit_deptid
  961. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  962. left join department dept on dept.department_id = a.dept_id
  963. left join task_group on task_group.id = a.group_id
  964. left join user u on u.id = a.project_auditor_id
  965. WHERE a.company_id =#{companyId}
  966. and a.state = 0
  967. <if test="startDate!=null and endDate!=null">
  968. AND a.create_date between #{startDate} and #{endDate}
  969. </if>
  970. AND a.is_dept_audit=1
  971. <if test="userId!=null">
  972. and dept_manager.id=#{userId}
  973. </if>
  974. <if test="departmentId!=null">
  975. and dept_manager.department_id=#{departmentId}
  976. </if>
  977. <if test="deptIds!=null and deptIds.size()>0">
  978. and dept_manager.department_id in
  979. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  980. #{item}
  981. </foreach>
  982. </if>
  983. group by a.audit_dept_managerid
  984. ORDER BY a.create_date desc, a.creator_id asc
  985. </when>
  986. <otherwise>
  987. 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
  988. FROM report AS a
  989. left join user on user.id = a.creator_id
  990. JOIN project AS b ON a.project_id=b.id
  991. left join sub_project as d on d.id = a.sub_project_id
  992. left join task on task.id = a.task_id
  993. left join report_extra_degree on report_extra_degree.id = a.degree_id
  994. left join department on department.department_id = a.audit_deptid
  995. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  996. left join department dept on dept.department_id = a.dept_id
  997. left join task_group on task_group.id = a.group_id
  998. left join user u on u.id = a.project_auditor_id
  999. left join department dp on u.department_id=dp.department_id
  1000. WHERE a.company_id =#{companyId}
  1001. and a.state = 0
  1002. <if test="startDate!=null and endDate!=null">
  1003. AND a.create_date between #{startDate} and #{endDate}
  1004. </if>
  1005. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1006. <if test="userId!=null">
  1007. and u.id=#{userId}
  1008. </if>
  1009. <if test="departmentId!=null">
  1010. and u.department_id=#{departmentId}
  1011. </if>
  1012. <if test="deptIds!=null and deptIds.size()>0">
  1013. and u.department_id in
  1014. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1015. #{item}
  1016. </foreach>
  1017. </if>
  1018. group by a.project_auditor_id
  1019. ORDER BY a.create_date desc, a.creator_id asc
  1020. </otherwise>
  1021. </choose>
  1022. <if test="start!=null and size!=null">
  1023. limit #{start},#{size}
  1024. </if>
  1025. </select>
  1026. <select id="findCount" resultType="java.lang.Long">
  1027. select count(1)
  1028. from (<choose>
  1029. <when test="stateKey==0">
  1030. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  1031. FROM report AS a
  1032. left join user on user.id = a.creator_id
  1033. JOIN project AS b ON a.project_id=b.id
  1034. left join sub_project as d on d.id = a.sub_project_id
  1035. left join task on task.id = a.task_id
  1036. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1037. left join department on department.department_id = a.audit_deptid
  1038. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1039. left join department dept on dept.department_id = a.dept_id
  1040. left join task_group on task_group.id = a.group_id
  1041. left join user u on u.id = a.project_auditor_id
  1042. WHERE a.company_id =#{companyId}
  1043. and a.state = 0
  1044. and u.is_active = 1
  1045. <if test="startDate!=null and endDate!=null">
  1046. AND a.create_date between #{startDate} and #{endDate}
  1047. </if>
  1048. AND a.is_dept_audit=1
  1049. <if test="userId!=null">
  1050. and dept_manager.id=#{userId}
  1051. </if>
  1052. <if test="departmentId!=null">
  1053. and dept_manager.department_id=#{departmentId}
  1054. </if>
  1055. <if test="deptIds!=null and deptIds.size()>0">
  1056. and dept_manager.department_id in
  1057. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1058. #{item}
  1059. </foreach>
  1060. </if>
  1061. group by a.audit_dept_managerid
  1062. ORDER BY a.create_date desc, a.creator_id asc
  1063. </when>
  1064. <otherwise>
  1065. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1066. FROM report AS a
  1067. left join user on user.id = a.creator_id
  1068. JOIN project AS b ON a.project_id=b.id
  1069. left join sub_project as d on d.id = a.sub_project_id
  1070. left join task on task.id = a.task_id
  1071. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1072. left join department on department.department_id = a.audit_deptid
  1073. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1074. left join department dept on dept.department_id = a.dept_id
  1075. left join task_group on task_group.id = a.group_id
  1076. left join user u on u.id = a.project_auditor_id
  1077. left join department dp on u.department_id=dp.department_id
  1078. WHERE a.company_id =#{companyId}
  1079. and a.state = 0
  1080. and u.is_active = 1
  1081. <if test="startDate!=null and endDate!=null">
  1082. AND a.create_date between #{startDate} and #{endDate}
  1083. </if>
  1084. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1085. <if test="userId!=null">
  1086. and u.id=#{userId}
  1087. </if>
  1088. <if test="departmentId!=null">
  1089. and u.department_id=#{departmentId}
  1090. </if>
  1091. <if test="deptIds!=null and deptIds.size()>0">
  1092. and u.department_id in
  1093. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1094. #{item}
  1095. </foreach>
  1096. </if>
  1097. group by a.project_auditor_id
  1098. ORDER BY a.create_date desc, a.creator_id asc
  1099. </otherwise>
  1100. </choose>
  1101. <if test="start!=null and size!=null">
  1102. limit #{start},#{size}
  1103. </if>) total
  1104. </select>
  1105. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1106. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1107. (select SUM(te.plan_hours) from task_executor te
  1108. left join task on task.id=te.task_id
  1109. where te.executor_id=us.id
  1110. <if test="startDate!=null and endDate!=null">
  1111. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1112. </if>) as planHours,
  1113. (select SUM(report.working_time) from report
  1114. left join task on task.id=report.task_id
  1115. where report.creator_id=us.id and task_id is not null and report.state=1
  1116. <if test="startDate!=null and endDate!=null">
  1117. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1118. </if>) as workingTime
  1119. from user us
  1120. left join department dp on dp.department_id=us.department_id
  1121. where us.company_id=#{companyId}
  1122. 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)
  1123. <if test="userId!=null and userId!=''">
  1124. and us.id=#{userId}
  1125. </if>
  1126. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1127. and us.department_id in
  1128. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1129. #{item}
  1130. </foreach>
  1131. </if>
  1132. <if test="deptIds!=null and deptIds.size()>0">
  1133. and us.department_id in
  1134. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1135. #{item}
  1136. </foreach>
  1137. </if>
  1138. group by us.id
  1139. order by us.department_id
  1140. <if test="start!=null and size!=null">
  1141. limit #{start},#{size}
  1142. </if>
  1143. </select>
  1144. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1145. select count(1)
  1146. from(select us.name,dp.department_name as departmentName,
  1147. (select SUM(te.plan_hours) from task_executor te
  1148. left join task on task.id=te.task_id
  1149. where te.executor_id=us.id
  1150. <if test="startDate!=null and endDate!=null">
  1151. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1152. </if>) as planHours,
  1153. (select SUM(report.working_time) from report
  1154. left join task on task.id=report.task_id
  1155. where report.creator_id=us.id and task_id is not null
  1156. <if test="startDate!=null and endDate!=null">
  1157. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1158. </if>) as workingTime
  1159. from user us
  1160. left join department dp on dp.department_id=us.department_id
  1161. where us.company_id=#{companyId}
  1162. 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)
  1163. <if test="userId!=null and userId!=''">
  1164. and us.id=#{userId}
  1165. </if>
  1166. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1167. and us.department_id in
  1168. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1169. #{item}
  1170. </foreach>
  1171. </if>
  1172. <if test="deptIds!=null and deptIds.size()>0">
  1173. and us.department_id in
  1174. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1175. #{item}
  1176. </foreach>
  1177. </if>
  1178. group by us.id
  1179. order by us.department_id)as total
  1180. </select>
  1181. <select id="selectWithGroup" resultType="java.util.Map">
  1182. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1183. from report a
  1184. left join task_group b on a.group_id=b.id
  1185. left join project c on a.project_id=c.id
  1186. where c.company_id=#{companyId} and a.state=1
  1187. <if test="startDate!=null and endDate!=null">
  1188. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1189. </if>
  1190. <if test="projectId!=null">
  1191. and c.id=#{projectId}
  1192. </if>
  1193. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1194. and (c.id in
  1195. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1196. #{item}
  1197. </foreach>
  1198. <!--或者按分组负责人的匹配-->
  1199. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1200. or a.group_id in
  1201. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1202. #{item}
  1203. </foreach>
  1204. </if>
  1205. )
  1206. </if>
  1207. <if test="groupId!=null">
  1208. and a.group_id=#{groupId}
  1209. </if>
  1210. group by b.name
  1211. order by c.id
  1212. <if test="startIndex!=null and endIndex!=null">
  1213. limit #{startIndex},#{endIndex}
  1214. </if>
  1215. </select>
  1216. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1217. select count(1) from(
  1218. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1219. from report a
  1220. left join task_group b on a.group_id=b.id
  1221. left join project c on a.project_id=c.id
  1222. where c.company_id=#{companyId} and a.state=1
  1223. <if test="startDate!=null and endDate!=null">
  1224. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1225. </if>
  1226. <if test="projectId!=null">
  1227. and c.id=#{projectId}
  1228. </if>
  1229. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1230. and (c.id in
  1231. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1232. #{item}
  1233. </foreach>
  1234. <!--或者按分组负责人的匹配-->
  1235. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1236. or a.group_id in
  1237. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1238. #{item}
  1239. </foreach>
  1240. </if>
  1241. )
  1242. </if>
  1243. <if test="groupId!=null">
  1244. and a.group_id=#{groupId}
  1245. </if>
  1246. group by b.name
  1247. order by c.id
  1248. <if test="startIndex!=null and endIndex!=null">
  1249. limit #{startIndex},#{endIndex}
  1250. </if>) as total
  1251. </select>
  1252. <select id="selectWithGroupProject" resultType="java.util.Map">
  1253. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1254. from report a
  1255. left join task_group b on a.group_id=b.id
  1256. left join project c on a.project_id=c.id
  1257. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1258. left join project_separate ps on ps.id=c.id
  1259. </if>
  1260. where c.company_id=#{companyId} and a.state=1
  1261. <if test="startDate!=null and endDate!=null">
  1262. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1263. </if>
  1264. <if test="projectId!=null">
  1265. and c.id=#{projectId}
  1266. </if>
  1267. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1268. and ps.project_category_sub=#{projectCategorySub}
  1269. </if>
  1270. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1271. and (c.id in
  1272. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1273. #{item}
  1274. </foreach>
  1275. <!--或者按分组负责人的匹配-->
  1276. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1277. or a.group_id in
  1278. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1279. #{item}
  1280. </foreach>
  1281. </if>
  1282. )
  1283. </if>
  1284. <if test="groupId!=null">
  1285. and a.group_id=#{groupId}
  1286. </if>
  1287. group by c.id,b.id
  1288. order by c.id
  1289. <if test="startIndex!=null and endIndex!=null">
  1290. limit #{startIndex},#{endIndex}
  1291. </if>
  1292. </select>
  1293. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1294. select count(1) from(
  1295. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1296. from report a
  1297. left join task_group b on a.group_id=b.id
  1298. left join project c on a.project_id=c.id
  1299. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1300. left join project_separate ps on ps.id=c.id
  1301. </if>
  1302. where c.company_id=#{companyId} and a.state=1
  1303. <if test="startDate!=null and endDate!=null">
  1304. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1305. </if>
  1306. <if test="projectId!=null">
  1307. and c.id=#{projectId}
  1308. </if>
  1309. <if test="projectCategorySub!=null and projectCategorySub!=''">
  1310. and ps.project_category_sub=#{projectCategorySub}
  1311. </if>
  1312. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1313. and (c.id in
  1314. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1315. #{item}
  1316. </foreach>
  1317. <!--或者按分组负责人的匹配-->
  1318. <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
  1319. or a.group_id in
  1320. <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
  1321. #{item}
  1322. </foreach>
  1323. </if>
  1324. )
  1325. </if>
  1326. <if test="groupId!=null">
  1327. and a.group_id=#{groupId}
  1328. </if>
  1329. group by c.id,b.id
  1330. order by c.id
  1331. <if test="startIndex!=null and endIndex!=null">
  1332. limit #{startIndex},#{endIndex}
  1333. </if>) as total
  1334. </select>
  1335. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1336. 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
  1337. from report a
  1338. left join task_group b on a.group_id=b.id
  1339. left join project c on a.project_id=c.id
  1340. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1341. where c.company_id=#{companyId} and a.state=1
  1342. <if test="startDate!=null and endDate!=null">
  1343. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1344. </if>
  1345. <if test="projectId!=null">
  1346. and c.id=#{projectId}
  1347. </if>
  1348. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1349. and c.id in
  1350. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1351. #{item}
  1352. </foreach>
  1353. </if>
  1354. <if test="gpNamesList !=null">
  1355. and b.name in
  1356. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1357. #{item}
  1358. </foreach>
  1359. </if>
  1360. group by c.id,b.id
  1361. <if test="start!=null and size!=null">
  1362. limit #{start},#{size}
  1363. </if>
  1364. </select>
  1365. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1366. select count(1) from
  1367. (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
  1368. from report a
  1369. left join task_group b on a.group_id=b.id
  1370. left join project c on a.project_id=c.id
  1371. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1372. where c.company_id=#{companyId} and a.state=1
  1373. <if test="startDate!=null and endDate!=null">
  1374. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1375. </if>
  1376. <if test="projectId!=null">
  1377. and c.id=#{projectId}
  1378. </if>
  1379. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1380. and c.id in
  1381. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1382. #{item}
  1383. </foreach>
  1384. </if>
  1385. <if test="gpNamesList !=null">
  1386. and b.name in
  1387. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1388. #{item}
  1389. </foreach>
  1390. </if>
  1391. group by c.id,b.id
  1392. <if test="start!=null and size!=null">
  1393. limit #{start},#{size}
  1394. </if>) as total
  1395. </select>
  1396. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1397. 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
  1398. from report a
  1399. left join task_group b on a.group_id=b.id
  1400. left join project c on a.project_id=c.id
  1401. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1402. where c.company_id=#{companyId} and a.state=1
  1403. <if test="startDate!=null and endDate!=null">
  1404. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1405. </if>
  1406. <if test="projectId!=null">
  1407. and c.id=#{projectId}
  1408. </if>
  1409. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1410. and c.id in
  1411. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1412. #{item}
  1413. </foreach>
  1414. </if>
  1415. <if test="gpNamesList !=null">
  1416. and b.name in
  1417. <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
  1418. #{item}
  1419. </foreach>
  1420. </if>
  1421. group by c.id,f.id
  1422. <if test="start!=null and size!=null">
  1423. limit #{start},#{size}
  1424. </if>
  1425. </select>
  1426. <select id="getCostByUserCustom" resultType="java.util.Map">
  1427. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1428. FROM user AS a
  1429. LEFT JOIN report AS b ON a.id = b.creator_id
  1430. LEFT JOIN project AS c ON b.project_id = c.id
  1431. left join user_custom uc on uc.company_id=a.company_id
  1432. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1433. WHERE b.state = 1
  1434. AND a.company_id = #{companyId}
  1435. <if test="startDate!=null and endDate!=null">
  1436. AND b.create_date between #{startDate} and #{endDate}
  1437. </if>
  1438. and uc.id=#{customId}
  1439. <if test="deptIds!=null and deptIds.size()>0">
  1440. and a.department_id in
  1441. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1442. #{item}
  1443. </foreach>
  1444. </if>
  1445. <if test="subCustomName!=null">
  1446. and suc.name=#{subCustomName}
  1447. </if>
  1448. GROUP BY suc.name
  1449. </select>
  1450. <select id="getEmpMonthHours" resultType="java.util.Map">
  1451. 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,
  1452. (select allday from time_type te
  1453. where te.company_id=#{companyId}) as allday,
  1454. (select SUM(report.working_time) from report
  1455. where report.creator_id=us.id and report.state=1
  1456. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1457. as workingTime
  1458. from user us
  1459. left join department dp on dp.department_id=us.department_id
  1460. where us.company_id=#{companyId}
  1461. 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)
  1462. <if test="userId!=null and userId!=''">
  1463. and us.id=#{userId}
  1464. </if>
  1465. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1466. and us.department_id in
  1467. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1468. #{item}
  1469. </foreach>
  1470. </if>
  1471. <if test="deptIds!=null and deptIds.size()>0">
  1472. and us.department_id in
  1473. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1474. #{item}
  1475. </foreach>
  1476. </if>
  1477. group by us.id
  1478. order by us.department_id
  1479. <if test="start!=null and size!=null">
  1480. limit #{start},#{size}
  1481. </if>
  1482. </select>
  1483. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1484. select count(1)
  1485. from(select us.name,dp.department_name as departmentName,
  1486. (select SUM(report.working_time) from report
  1487. where report.creator_id=us.id
  1488. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1489. as workingTime
  1490. from user us
  1491. left join department dp on dp.department_id=us.department_id
  1492. where us.company_id=#{companyId}
  1493. and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date &lt; #{startDate} AND is_active = 0)
  1494. <if test="userId!=null and userId!=''">
  1495. and us.id=#{userId}
  1496. </if>
  1497. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1498. and us.department_id in
  1499. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1500. #{item}
  1501. </foreach>
  1502. </if>
  1503. <if test="deptIds!=null and deptIds.size()>0">
  1504. and us.department_id in
  1505. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1506. #{item}
  1507. </foreach>
  1508. </if>
  1509. group by us.id
  1510. order by us.department_id)as total
  1511. </select>
  1512. <!-- 分页查询部门参与项目情况-->
  1513. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1514. SELECT department.department_id deptId,
  1515. department_name deptName,
  1516. (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,
  1517. pro.projectCount projectCount,
  1518. pro.centerCount centerCount,
  1519. pcon.peopleCount peopleCount
  1520. FROM department
  1521. LEFT JOIN (
  1522. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1523. COUNT(DISTINCT(r.degree_id)) centerCount
  1524. FROM report
  1525. LEFT JOIN report r
  1526. ON report.id = r.id AND r.degree_id != -1
  1527. LEFT JOIN `user`
  1528. ON report.creator_id = user.id
  1529. WHERE report.state = 1
  1530. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1531. GROUP BY dept_id
  1532. ) pro
  1533. on pro.dept_id = department.department_id
  1534. LEFT JOIN (
  1535. SELECT dept_id,sum(p.con) peopleCount
  1536. FROM (
  1537. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1538. LEFT JOIN `user`
  1539. ON report.creator_id = user.id
  1540. WHERE report.state = 1
  1541. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1542. GROUP BY report.creator_id,dept_id
  1543. ) p GROUP BY p.dept_id
  1544. ) pcon
  1545. ON pcon.dept_id = department.department_id
  1546. WHERE department.company_id = #{companyId}
  1547. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1548. and department.department_id in
  1549. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1550. #{item}
  1551. </foreach>
  1552. </if>
  1553. <if test="deptIds!=null and deptIds.size()>0">
  1554. and department.department_id in
  1555. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1556. #{item}
  1557. </foreach>
  1558. </if>
  1559. <if test="size!=null and start!=null">
  1560. limit #{start},#{size}
  1561. </if>
  1562. </select>
  1563. <!--获取按项目分组的工时成本-->
  1564. <select id="getExportDegreeCost" resultType="java.util.Map">
  1565. 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
  1566. FROM project AS a
  1567. LEFT JOIN report AS b ON b.project_id = a.id
  1568. JOIN user AS c ON b.creator_id = c.id
  1569. WHERE a.company_id = #{companyId}
  1570. <if test="projectId != null">
  1571. AND a.id = #{projectId}
  1572. </if>
  1573. <if test="startDate != null and endDate != null">
  1574. AND b.create_date between #{startDate} and #{endDate}
  1575. </if>
  1576. <choose>
  1577. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1578. and b.dept_id in
  1579. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1580. #{item}
  1581. </foreach>
  1582. </when>
  1583. <otherwise>
  1584. <if test="deptIds!=null and deptIds.size()>0">
  1585. and (b.dept_id in
  1586. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1587. #{item}
  1588. </foreach>
  1589. <if test="deptRelatedProjectIds.size() > 0">
  1590. or a.id in
  1591. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  1592. #{pid}
  1593. </foreach>
  1594. </if>
  1595. )
  1596. </if>
  1597. </otherwise>
  1598. </choose>
  1599. AND b.state = 1
  1600. GROUP BY a.id
  1601. ORDER BY a.id ASC
  1602. </select>
  1603. <!--获取某个项目每个维度分别需要的工时-->
  1604. <select id="getDegreeDetailCost" resultType="java.util.Map">
  1605. 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
  1606. FROM report AS a
  1607. JOIN user AS b ON a.creator_id = b.id
  1608. left join department on department.department_id = a.dept_id
  1609. left join report_extra_degree as r on a.degree_id = r.id
  1610. WHERE a.company_id=#{companyId}
  1611. <if test="curProjectId != null">
  1612. and a.project_id = #{curProjectId}
  1613. </if>
  1614. <if test="projectId != null">
  1615. and a.project_id = #{projectId}
  1616. </if>
  1617. <if test="startDate != null and endDate != null">
  1618. AND a.create_date between #{startDate} and #{endDate}
  1619. </if>
  1620. <choose>
  1621. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  1622. and a.dept_id in
  1623. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  1624. #{item}
  1625. </foreach>
  1626. </when>
  1627. <otherwise>
  1628. <if test="deptIds!=null and deptIds.size()>0">
  1629. and a.dept_id in
  1630. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1631. #{item}
  1632. </foreach>
  1633. </if>
  1634. </otherwise>
  1635. </choose>
  1636. GROUP BY a.project_id,b.id,a.degree_id
  1637. ORDER BY b.id,a.degree_id ASC
  1638. </select>
  1639. <select id="selectNearProject" resultType="com.management.platform.entity.Project">
  1640. SELECT * FROM project
  1641. WHERE STATUS = 1 AND id IN (
  1642. SELECT project_id
  1643. FROM (
  1644. SELECT DISTINCT report.project_id
  1645. FROM report
  1646. WHERE creator_id = #{userId}
  1647. GROUP BY project_id
  1648. ORDER BY MAX(create_time)
  1649. DESC LIMIT 3
  1650. ) p2
  1651. ) AND id IN(SELECT project_id FROM participation WHERE user_id=#{userId})
  1652. </select>
  1653. <select id="getFTEData" resultType="java.util.Map">
  1654. 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,IFNULL(r.projectCode,'') as projectCode,IFNULL(r.workTime,0) as workTime
  1655. FROM `user` u
  1656. LEFT JOIN department d on u.department_id=d.department_id
  1657. LEFT JOIN (
  1658. SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
  1659. FROM report
  1660. LEFT JOIN project p
  1661. ON report.project_id = p.id
  1662. LEFT JOIN `user`
  1663. ON user.id = report.creator_id
  1664. WHERE report.state = 1
  1665. AND p.is_public = 0
  1666. AND report.company_id=#{companyId}
  1667. AND
  1668. (
  1669. 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}
  1670. ,report.create_date BETWEEN user.induction_date AND user.inactive_date
  1671. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1672. and
  1673. IF(user.induction_date is not null AND user.induction_date &gt; #{startDate}
  1674. ,report.create_date BETWEEN user.induction_date AND #{endDate}
  1675. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1676. and
  1677. IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date &lt; #{endDate}
  1678. ,report.create_date BETWEEN #{startDate} AND user.inactive_date
  1679. ,report.create_date BETWEEN #{startDate} AND #{endDate} )
  1680. )
  1681. GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
  1682. ) r
  1683. ON u.id = r.creator_id
  1684. WHERE u.company_id=#{companyId}
  1685. AND (workTime>0 OR u.`is_active`=1)
  1686. <if test="area!=null and area != '' ">
  1687. and u.plate1 = #{area}
  1688. </if>
  1689. <if test="userId!=null and userId != '' ">
  1690. and u.id = #{userId}
  1691. </if>
  1692. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1693. and u.department_id in
  1694. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1695. #{item}
  1696. </foreach>
  1697. </if>
  1698. <if test="deptIds!=null and deptIds.size()>0">
  1699. and u.department_id in
  1700. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1701. #{item}
  1702. </foreach>
  1703. </if>
  1704. <if test="sortProp!=null and sortProp!=''">
  1705. <choose>
  1706. <when test="sortOrder==0">
  1707. order by id desc
  1708. </when>
  1709. <otherwise>
  1710. order by id
  1711. </otherwise>
  1712. </choose>
  1713. </if>
  1714. <if test="start!=null and size!=null">
  1715. limit #{start},#{size}
  1716. </if>
  1717. </select>
  1718. <!--获取查询者所在公司每个项目的工时成本-->
  1719. <select id="getTimeCostByToken" resultType="java.util.Map">
  1720. 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
  1721. FROM project AS a
  1722. LEFT JOIN report AS b ON b.project_id = a.id
  1723. JOIN user AS c ON b.creator_id = c.id
  1724. JOIN department d on d.department_id=c.department_id
  1725. WHERE a.company_id = #{companyId}
  1726. <if test="startDate != null and endDate != null">
  1727. AND b.create_date between #{startDate} and #{endDate}
  1728. </if>
  1729. AND b.state = 1
  1730. GROUP BY a.id,b.creator_id
  1731. ORDER BY a.id ASC
  1732. </select>
  1733. <!--获取员工的项目分类工时统计数据 -->
  1734. <select id="getMembProjectCateTime" resultType="com.management.platform.entity.vo.UserCateTimeVo">
  1735. 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
  1736. FROM report
  1737. LEFT JOIN `user` ON user.id = report.`creator_id`
  1738. LEFT JOIN project ON project.id = report.`project_id`
  1739. WHERE report.`company_id` = #{companyId}
  1740. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  1741. AND report.state = 1
  1742. <if test="departmentId!=null">
  1743. AND user.department_id=#{departmentId}
  1744. </if>
  1745. <if test="subUserCustomName!=null and subUserCustomName!='' and plateString!=null">
  1746. <choose>
  1747. <when test="plateString==1">
  1748. AND user.plate1=#{subUserCustomName}
  1749. </when>
  1750. <when test="plateString==2">
  1751. AND user.plate2=#{subUserCustomName}
  1752. </when>
  1753. <when test="plateString==3">
  1754. AND user.plate3=#{subUserCustomName}
  1755. </when>
  1756. <when test="plateString==4">
  1757. AND user.plate4=#{subUserCustomName}
  1758. </when>
  1759. <otherwise>
  1760. AND user.plate5=#{subUserCustomName}
  1761. </otherwise>
  1762. </choose>
  1763. </if>
  1764. GROUP BY user.id, project.`category`
  1765. </select>
  1766. <select id="userProjectProcessList" resultType="java.util.Map">
  1767. 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,
  1768. 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
  1769. from task_executor te
  1770. left join user u on u.id=te.executor_id
  1771. left join department d on d.department_id=u.department_id
  1772. left join project p on p.id=te.project_id
  1773. where u.company_id=#{companyId} and te.project_id is not null
  1774. <if test="deptId!=null">
  1775. and d.department_id=#{deptId}
  1776. </if>
  1777. <if test="userId!=null and userId!=''">
  1778. and u.id=#{userId}
  1779. </if>
  1780. <if test="projectId!=null">
  1781. and p.id=#{projectId}
  1782. </if>
  1783. <if test="list!=null and list.size()>0">
  1784. and d.department_id in
  1785. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1786. #{item}
  1787. </foreach>
  1788. </if>
  1789. <if test="listSecond!=null and listSecond.size()>0">
  1790. and d.department_id in
  1791. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1792. #{item}
  1793. </foreach>
  1794. </if>
  1795. group by te.executor_id,te.project_id
  1796. order by d.department_id,u.id
  1797. <if test="start!=null and size!=null">
  1798. limit #{start},#{size}
  1799. </if>
  1800. </select>
  1801. <select id="userProjectProcessCount" resultType="java.lang.Long">
  1802. select count(1) from (
  1803. select d.department_name as departmentName
  1804. from task_executor te
  1805. left join user u on u.id=te.executor_id
  1806. left join department d on d.department_id=u.department_id
  1807. left join project p on p.id=te.project_id
  1808. where u.company_id=#{companyId} and te.project_id is not null
  1809. <if test="deptId!=null">
  1810. and d.department_id=#{deptId}
  1811. </if>
  1812. <if test="userId!=null and userId!=''">
  1813. and u.id=#{userId}
  1814. </if>
  1815. <if test="projectId!=null">
  1816. and p.id=#{projectId}
  1817. </if>
  1818. <if test="list!=null and list.size()>0">
  1819. and d.department_id in
  1820. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1821. #{item}
  1822. </foreach>
  1823. </if>
  1824. <if test="listSecond!=null and listSecond.size()>0">
  1825. and d.department_id in
  1826. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1827. #{item}
  1828. </foreach>
  1829. </if>
  1830. group by te.executor_id,te.project_id
  1831. ) as total
  1832. </select>
  1833. <select id="groupExpendProcessList" resultType="java.util.Map">
  1834. 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,
  1835. IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) as normalHour,IFNULL(r.overHour,0) as overHour,
  1836. 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
  1837. FROM task_executor te
  1838. LEFT JOIN task t ON t.id=te.task_id
  1839. LEFT JOIN user u ON te.executor_id=u.id
  1840. LEFT JOIN task_group tg ON tg.id=t.group_id
  1841. LEFT JOIN project p ON p.id=tg.project_id
  1842. LEFT JOIN department d ON d.department_id=u.department_id
  1843. LEFT JOIN (
  1844. 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
  1845. FROM report WHERE state=1 <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''"> AND create_date BETWEEN #{startDate} AND #{endDate} </if>AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id,dept_id) r ON r.group_id=tg.`id` and r.dept_id=u.department_id
  1846. WHERE u.company_id=#{companyId}
  1847. AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
  1848. <if test="userId!=null and userId!=''">
  1849. and t.executor_id=#{userId}
  1850. </if>
  1851. GROUP BY p.id,tg.id,d.department_id ORDER BY p.id,d.department_id
  1852. </select>
  1853. <select id="projectExpendProcessList" resultType="java.util.Map">
  1854. 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,
  1855. 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,
  1856. 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
  1857. from task_executor te
  1858. left join user u on u.id=te.executor_id
  1859. left join department d on u.department_id=d.department_id
  1860. left join task t on t.id=te.task_id
  1861. left join project p on p.id=t.project_id
  1862. left join project_category pc on pc.id=p.category
  1863. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目')
  1864. <if test="projectId!=null">
  1865. and p.id=#{projectId}
  1866. </if>
  1867. <if test="userId!=null and userId!=''">
  1868. and FIND_IN_SET(#{userId},t.executor_id)
  1869. </if>
  1870. <if test="categoryId!=null">
  1871. and pc.id=#{categoryId}
  1872. </if>
  1873. <if test="list!=null and list.size()>0">
  1874. and d.department_id in
  1875. <foreach collection="list" open="(" close=")" separator="," item="item">
  1876. #{item}
  1877. </foreach>
  1878. </if>
  1879. group by t.project_id
  1880. <if test="start!=null and size!=null">
  1881. limit #{start},#{size}
  1882. </if>
  1883. </select>
  1884. <select id="projectExpendProcessListCount" resultType="java.lang.Long">
  1885. select count(1) from (
  1886. select p.project_name as projectName
  1887. from task_executor te
  1888. left join user u on u.id=te.executor_id
  1889. left join department d on u.department_id=d.department_id
  1890. left join task t on t.id=te.task_id
  1891. left join project p on p.id=t.project_id
  1892. left join project_category pc on pc.id=p.category
  1893. where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目')
  1894. <if test="projectId!=null">
  1895. and p.id=#{projectId}
  1896. </if>
  1897. <if test="userId!=null and userId!=''">
  1898. and te.executor_id=#{userId}
  1899. </if>
  1900. <if test="categoryId!=null">
  1901. and pc.id=#{categoryId}
  1902. </if>
  1903. <if test="list!=null and list.size()>0">
  1904. and d.department_id in
  1905. <foreach collection="list" open="(" close=")" separator="," item="item">
  1906. #{item}
  1907. </foreach>
  1908. </if>
  1909. group by t.project_id
  1910. ) as total
  1911. </select>
  1912. <select id="userTaskProcessList" resultType="java.util.Map">
  1913. 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,
  1914. 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
  1915. ,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate
  1916. from task_executor te
  1917. left join user u on u.id=te.executor_id
  1918. left join department d on d.department_id=u.department_id
  1919. left join project p on p.id=te.project_id
  1920. left join task t on te.task_id=t.id
  1921. where u.company_id=#{companyId} and te.project_id is not null
  1922. <if test="deptId!=null">
  1923. and d.department_id=#{deptId}
  1924. </if>
  1925. <if test="userId!=null and userId!=''">
  1926. and u.id=#{userId}
  1927. </if>
  1928. <if test="projectId!=null">
  1929. and p.id=#{projectId}
  1930. </if>
  1931. <if test="list!=null and list.size()>0">
  1932. and d.department_id in
  1933. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1934. #{item}
  1935. </foreach>
  1936. </if>
  1937. <if test="listSecond!=null and listSecond.size()>0">
  1938. and d.department_id in
  1939. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1940. #{item}
  1941. </foreach>
  1942. </if>
  1943. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  1944. and ((t.start_date between #{startDate} and #{endDate})
  1945. or
  1946. (t.end_date between #{startDate} and #{endDate}))
  1947. </if>
  1948. group by te.executor_id,t.id
  1949. order by d.department_id,u.id
  1950. <if test="start!=null and size!=null">
  1951. limit #{start},#{size}
  1952. </if>
  1953. </select>
  1954. <select id="userTaskProcessListCount" resultType="java.lang.Long">
  1955. select count(1) from (
  1956. select d.department_name as departmentName
  1957. from task_executor te
  1958. left join user u on u.id=te.executor_id
  1959. left join department d on d.department_id=u.department_id
  1960. left join project p on p.id=te.project_id
  1961. left join task t on te.task_id=t.id
  1962. where u.company_id=#{companyId} and te.project_id is not null
  1963. <if test="deptId!=null">
  1964. and d.department_id=#{deptId}
  1965. </if>
  1966. <if test="userId!=null and userId!=''">
  1967. and u.id=#{userId}
  1968. </if>
  1969. <if test="projectId!=null">
  1970. and p.id=#{projectId}
  1971. </if>
  1972. <if test="list!=null and list.size()>0">
  1973. and d.department_id in
  1974. <foreach collection="list" open="(" close=")" item="item" separator=",">
  1975. #{item}
  1976. </foreach>
  1977. </if>
  1978. <if test="listSecond!=null and listSecond.size()>0">
  1979. and d.department_id in
  1980. <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
  1981. #{item}
  1982. </foreach>
  1983. </if>
  1984. <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
  1985. and ((t.start_date between #{startDate} and #{endDate})
  1986. or
  1987. (t.end_date between #{startDate} and #{endDate}))
  1988. </if>
  1989. group by te.executor_id,t.id
  1990. order by d.department_id,u.id
  1991. ) as total
  1992. </select>
  1993. </mapper>