ProjectMapper.xml 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  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_normal" property="feeNormal" />
  28. <result column="fee_travel" property="feeTravel" />
  29. <result column="fee_outsourcing" property="feeOutsourcing" />
  30. <result column="fee_man" property="feeMan" />
  31. <result column="customer_id" property="customerId" />
  32. <result column="customer_name" property="customerName" />
  33. <result column="is_public" property="isPublic" />
  34. <result column="associate_degrees" property="associateDegrees" />
  35. <result column="associate_degree_names" property="associateDegreeNames" />
  36. <result column="task_gp_incharge" property="taskGpIncharge" />
  37. <result column="category" property="category" />
  38. <result column="category_name" property="categoryName" />
  39. <result column="project_desc" property="projectDesc" />
  40. <result column="project_main_id" property="projectMainId" />
  41. <result column="project_main_name" property="projectMainName" />
  42. <result column="provider_ids" property="providerIds" />
  43. <result column="provider_names" property="providerNames" />
  44. <result column="current_stage_id" property="currentStageId" />
  45. <result column="current_stage_name" property="currentStageName" />
  46. <result column="output_value" property="outputValue" />
  47. <result column="dept_id" property="deptId" />
  48. <result column="dept_cascade" property="deptCascade" />
  49. </resultMap>
  50. <!-- 通用查询结果列 -->
  51. <sql id="Base_Column_List">
  52. 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_normal, fee_travel, fee_outsourcing, 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
  53. </sql>
  54. <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
  55. <result column="id" property="id" />
  56. <result column="project_name" property="projectName" />
  57. <result column="project_code" property="projectCode" />
  58. <result column="startDate" property="startDate" />
  59. <result column="endDate" property="endDate" />
  60. <collection property="stageCostList" javaType="java.util.ArrayList"
  61. ofType="com.management.platform.entity.vo.StageCost"
  62. select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
  63. </resultMap>
  64. <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
  65. <result column="customer_id" property="customerId" />
  66. <result column="customer_name" property="customerName" />
  67. <result column="contract_amount" property="contractAmount" />
  68. <result column="fee_normal" property="feeNormal" />
  69. <result column="fee_travel" property="feeTravel" />
  70. <result column="fee_outsourcing" property="feeOutsourcing" />
  71. <result column="fee_man" property="feeMan" />
  72. <result column="project_num" property="projectNum" />
  73. <result column="project_ids" property="projectIds" />
  74. <result column="project_names" property="projectNames" />
  75. </resultMap>
  76. <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
  77. select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
  78. from project
  79. where company_id = #{companyId}
  80. <if test="projectId != null">
  81. and id = #{projectId}
  82. </if>
  83. <if test="inchargerId!=null">
  84. and incharger_id = #{inchargerId}
  85. </if>
  86. order by is_public desc, id asc
  87. <if test="startIndex != null">
  88. limit ${startIndex}, ${endIndex}
  89. </if>
  90. </select>
  91. <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
  92. select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
  93. IFNULL(SUM(report.`working_time`), 0) AS working_time,
  94. 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
  95. FROM report
  96. left join project p on p.id=report.`project_id`
  97. where report.state = 1
  98. <if test="inchargerId!=null">
  99. and p.incharger_id = #{inchargerId}
  100. </if>
  101. <if test="projectIds!=null and projectIds.size()>0">
  102. and p.id in
  103. <foreach collection="projectIds" open="(" close=")" separator="," item="item">
  104. #{item}
  105. </foreach>
  106. </if>
  107. and report.create_date &gt;= #{startDate}
  108. and report.create_date &lt;= #{endDate}
  109. GROUP BY report.`project_id`,report.stage
  110. </select>
  111. <!--获取查询者所在公司每个项目的工时成本-->
  112. <select id="getParticipatedProject" resultType="java.util.Map">
  113. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  114. FROM project
  115. WHERE id IN (
  116. SELECT project_id
  117. FROM participation
  118. WHERE user_id = #{userId}
  119. ) or incharger_id = #{userId}
  120. or creator_id = #{userId}
  121. or (is_public = 1 and company_id = #{companyId})
  122. ORDER BY is_public DESC, id DESC
  123. </select>
  124. <select id="getOnlyJoinProjects" resultType="java.util.Map">
  125. SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc
  126. FROM project
  127. WHERE (status = 1 or status = 4) and (id IN (
  128. SELECT project_id
  129. FROM participation
  130. WHERE user_id = #{userId}
  131. )
  132. or (is_public = 1 and company_id = #{companyId}))
  133. ORDER BY is_public DESC, id ASC
  134. </select>
  135. <!--获取查询者所在公司每个项目的工时成本-->
  136. <select id="getTimeCost" resultType="java.util.Map">
  137. 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
  138. FROM project AS a
  139. LEFT JOIN report AS b ON b.project_id = a.id
  140. JOIN user AS c ON b.creator_id = c.id
  141. WHERE a.company_id = #{companyId}
  142. <if test="projectId != null">
  143. AND a.id = #{projectId}
  144. </if>
  145. <if test="userIdList != null and userIdList.size()>0">
  146. AND b.creator_id in
  147. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  148. #{item}
  149. </foreach>
  150. </if>
  151. <if test="startDate != null and endDate != null">
  152. AND b.create_date between #{startDate} and #{endDate}
  153. </if>
  154. <choose>
  155. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  156. and b.dept_id in
  157. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  158. #{item}
  159. </foreach>
  160. </when>
  161. <otherwise>
  162. <if test="deptIds!=null and deptIds.size()>0">
  163. and (b.dept_id in
  164. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  165. #{item}
  166. </foreach>
  167. <if test="deptRelatedProjectIds.size() > 0">
  168. or a.id in
  169. <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
  170. #{pid}
  171. </foreach>
  172. </if>
  173. )
  174. </if>
  175. </otherwise>
  176. </choose>
  177. AND b.state = 1
  178. GROUP BY a.id
  179. ORDER BY a.id ASC
  180. </select>
  181. <!--获取查询者所在公司每个子项目的工时成本-->
  182. <select id="getSubProjectTimeCost" resultType="java.util.Map">
  183. 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
  184. from sub_project a
  185. left join project b on b.id=a.project_id
  186. left join report c on c.sub_project_id=a.id
  187. where a.company_id=#{companyId}
  188. <if test="startDate != null and endDate != null">
  189. and c.create_date between #{startDate} and #{endDate}
  190. </if>
  191. <if test="projectId!=null">
  192. and a.project_id=#{projectId}
  193. </if>
  194. <if test="inchagerIds!=null and inchagerIds.size()>0">
  195. and b.id in
  196. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  197. #{item}
  198. </foreach>
  199. </if>
  200. group by b.id,a.id
  201. <if test="start!=null and size!=null">
  202. limit #{start},#{size}
  203. </if>
  204. </select>
  205. <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
  206. 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
  207. from sub_project a
  208. left join project b on b.id=a.project_id
  209. left join report c on c.sub_project_id=a.id
  210. where a.company_id=#{companyId}
  211. <if test="startDate != null and endDate != null">
  212. and c.create_date between #{startDate} and #{endDate}
  213. </if>
  214. <if test="projectId!=null">
  215. and a.project_id=#{projectId}
  216. </if>
  217. <if test="inchagerIds!=null and inchagerIds.size()>0">
  218. and b.id in
  219. <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
  220. #{item}
  221. </foreach>
  222. </if>
  223. group by b.id,a.id
  224. <if test="start!=null and size!=null">
  225. limit #{start},#{size}
  226. </if>) as total
  227. </select>
  228. <!--获取查询者所在公司每个项目的工时成本-->
  229. <select id="getTimeCostByMainProject" resultType="java.util.Map">
  230. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'未分类') as mainProjectName
  231. FROM project AS a
  232. LEFT JOIN report AS b ON b.project_id = a.id
  233. JOIN user AS c ON b.creator_id = c.id
  234. LEFT JOIN project_main pm on pm.id=a.project_main_id
  235. WHERE a.company_id = #{companyId}
  236. <if test="projectId != null">
  237. AND a.id = #{projectId}
  238. </if>
  239. <if test="startDate != null and endDate != null">
  240. AND b.create_date between #{startDate} and #{endDate}
  241. </if>
  242. <if test="deptIds!=null and deptIds.size()>0">
  243. and b.dept_id in
  244. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  245. #{item}
  246. </foreach>
  247. </if>
  248. AND b.state = 1
  249. GROUP BY a.project_main_id
  250. ORDER BY a.id ASC
  251. </select>
  252. <!--获取查询者所在公司每个项目分类的工时成本-->
  253. <select id="getTimeCostByCategory" resultType="java.util.Map">
  254. SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
  255. FROM project AS a
  256. LEFT JOIN report AS b ON b.project_id = a.id
  257. JOIN user AS c ON b.creator_id = c.id
  258. WHERE a.company_id = #{companyId}
  259. <if test="projectCategoryId != null">
  260. AND a.category = #{projectCategoryId}
  261. </if>
  262. <if test="userIdList != null and userIdList.size()>0">
  263. AND b.creator_id in
  264. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  265. #{item}
  266. </foreach>
  267. </if>
  268. <if test="startDate != null and endDate != null">
  269. AND b.create_date between #{startDate} and #{endDate}
  270. </if>
  271. <if test="deptIds!=null and deptIds.size()>0">
  272. and b.dept_id in
  273. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  274. #{item}
  275. </foreach>
  276. </if>
  277. AND b.state = 1
  278. GROUP BY a.category
  279. ORDER BY a.category ASC
  280. </select>
  281. <!--获取自定义数值的项目统计 -->
  282. <select id="getCustomDataSum" resultType="java.util.Map">
  283. SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
  284. FROM project AS a
  285. LEFT JOIN report AS b ON b.project_id = a.id
  286. JOIN user AS c ON b.creator_id = c.id
  287. WHERE a.company_id = #{companyId}
  288. <if test="projectId != null">
  289. AND a.id = #{projectId}
  290. </if>
  291. <if test="userId != null">
  292. AND b.creator_id = #{userId}
  293. </if>
  294. <if test="startDate != null and endDate != null">
  295. AND b.create_date between #{startDate} and #{endDate}
  296. </if>
  297. AND b.state = 1
  298. GROUP BY a.id
  299. having IFNULL(SUM(b.custom_data), 0) > 0
  300. ORDER BY SUM(b.custom_data) DESC
  301. </select>
  302. <!--获取日报的人员月度工时 -->
  303. <select id="getTimeCostReport" resultType="java.util.Map">
  304. SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
  305. FROM report AS a
  306. LEFT JOIN project AS b ON a.project_id = b.id
  307. LEFT JOIN user AS c ON a.creator_id = c.id
  308. WHERE b.company_id = #{companyId}
  309. <if test="projectId != null">
  310. AND b.id = #{projectId}
  311. </if>
  312. <if test="startDate != null and endDate != null">
  313. AND a.create_date between #{startDate} and #{endDate}
  314. </if>
  315. <if test="deptIds!=null and deptIds.size()>0">
  316. and a.dept_id in
  317. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  318. #{item}
  319. </foreach>
  320. </if>
  321. AND a.state = 1
  322. </select>
  323. <!--获取人员的月度总工时 -->
  324. <select id="getUserMonthTimeCost" resultType="java.util.Map">
  325. SELECT a.creator_id as creatorId, sum(a.working_time) as cost
  326. FROM report AS a, user as b
  327. WHERE a.creator_id = b.id
  328. and b.company_id = #{companyId}
  329. <if test="startDate != null and endDate != null">
  330. AND a.create_date between #{startDate} and #{endDate}
  331. </if>
  332. AND a.state = 1
  333. group by a.creator_id
  334. </select>
  335. <!--获取某个项目每个人分别需要的工时-->
  336. <select id="getProjectCost" resultType="java.util.Map">
  337. 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
  338. FROM report AS a
  339. JOIN user AS b ON a.creator_id = b.id
  340. left join department on department.department_id = a.dept_id
  341. WHERE a.company_id=#{companyId}
  342. <choose>
  343. <when test="stateKey!=null and stateKey==1">
  344. and a.state = 1
  345. </when>
  346. <otherwise>
  347. and (a.state = 1 or a.state =0)
  348. </otherwise>
  349. </choose>
  350. <if test="projectId != null">
  351. and a.project_id = #{projectId}
  352. </if>
  353. <if test="startDate != null and endDate != null">
  354. AND a.create_date between #{startDate} and #{endDate}
  355. </if>
  356. <if test="userIdList != null and userIdList.size()>0">
  357. AND a.creator_id in
  358. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  359. #{item}
  360. </foreach>
  361. </if>
  362. <choose>
  363. <when test="filterDeptIds!=null and filterDeptIds.size()>0">
  364. and a.dept_id in
  365. <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
  366. #{item}
  367. </foreach>
  368. </when>
  369. <otherwise>
  370. <if test="deptIds!=null and deptIds.size()>0">
  371. and a.dept_id in
  372. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  373. #{item}
  374. </foreach>
  375. </if>
  376. </otherwise>
  377. </choose>
  378. GROUP BY b.id, a.dept_id
  379. ORDER BY b.id ASC, a.dept_id ASC
  380. </select>
  381. <!--获取某个项目分类每个人分别需要的工时-->
  382. <select id="getProjectCostByCategory" resultType="java.util.Map">
  383. 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
  384. FROM report AS a
  385. JOIN user AS b ON a.creator_id = b.id
  386. left join department on department.department_id = a.dept_id
  387. left join project c on c.id=a.project_id
  388. WHERE a.company_id=#{companyId} and a.state = 1
  389. <if test="curProjectCategoryId != null">
  390. and c.category = #{curProjectCategoryId}
  391. </if>
  392. <if test="startDate != null and endDate != null">
  393. AND a.create_date between #{startDate} and #{endDate}
  394. </if>
  395. <if test="userId != null">
  396. AND a.creator_id = #{userId}
  397. </if>
  398. GROUP BY c.category, a.dept_id
  399. ORDER BY c.category ASC, a.dept_id ASC
  400. </select>
  401. <!--获取个人每个项目分别需要的工时-->
  402. <select id="getProjectCostGroupByProject" resultType="java.util.Map">
  403. 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
  404. FROM report AS a
  405. JOIN user AS b ON a.creator_id = b.id
  406. left join department on department.department_id = a.dept_id
  407. WHERE a.company_id=#{companyId} and a.state = 1
  408. <if test="projectId != null">
  409. and a.project_id = #{projectId}
  410. </if>
  411. <if test="startDate != null and endDate != null">
  412. AND a.create_date between #{startDate} and #{endDate}
  413. </if>
  414. <if test="userIdList != null and userIdList.size()>0">
  415. AND a.creator_id in
  416. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  417. #{item}
  418. </foreach>
  419. </if>
  420. <if test="deptIds!=null and deptIds.size()>0">
  421. and a.dept_id in
  422. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  423. #{item}
  424. </foreach>
  425. </if>
  426. GROUP BY b.id,a.project_id
  427. ORDER BY b.id ASC, a.dept_id ASC
  428. </select>
  429. <!--获取个人每个项目分类分别需要的工时-->
  430. <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
  431. 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
  432. FROM report AS a
  433. JOIN user AS b ON a.creator_id = b.id
  434. left join department on department.department_id = a.dept_id
  435. left join project c on c.id=a.project_id
  436. WHERE a.company_id=#{companyId} and a.state = 1
  437. <if test="projectCategoryId != null">
  438. and c.category = #{projectCategoryId}
  439. </if>
  440. <if test="startDate != null and endDate != null">
  441. AND a.create_date between #{startDate} and #{endDate}
  442. </if>
  443. <if test="userIdList != null and userIdList.size()>0">
  444. AND a.creator_id in
  445. <foreach collection="userIdList" item="item" open="(" separator="," close=")">
  446. #{item}
  447. </foreach>
  448. </if>
  449. <if test="deptIds!=null and deptIds.size()>0">
  450. and a.dept_id in
  451. <foreach collection="deptIds" separator="," close=")" open="(" item="item">
  452. #{item}
  453. </foreach>
  454. </if>
  455. GROUP BY b.id,c.category
  456. ORDER BY b.id ASC, a.dept_id ASC
  457. </select>
  458. <!-- 获取人员在日报填写的自定义数值 -->
  459. <select id="getProjectCusDataSumItem" resultType="java.util.Map">
  460. SELECT b.id as creatorId,
  461. b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
  462. FROM report AS a
  463. JOIN user AS b ON a.creator_id = b.id
  464. left join department on department.department_id = b.department_id
  465. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  466. <if test="startDate != null and endDate != null">
  467. AND a.create_date between #{startDate} and #{endDate}
  468. </if>
  469. <if test="projectId != null">
  470. AND a.project_id = #{projectId}
  471. </if>
  472. <if test="userId != null">
  473. AND a.creator_id = #{userId}
  474. </if>
  475. <if test="deptIds != null">
  476. AND department.department_id in
  477. <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
  478. #{item}
  479. </foreach>
  480. </if>
  481. group by b.id
  482. ORDER BY b.id ASC
  483. </select>
  484. <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
  485. SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
  486. b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
  487. FROM report AS a
  488. JOIN user AS b ON a.creator_id = b.id
  489. left join department on department.department_id = b.department_id
  490. left join project on project.id = a.project_id
  491. WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data &lt;&gt; 0
  492. <if test="startDate != null and endDate != null">
  493. AND a.create_date between #{startDate} and #{endDate}
  494. </if>
  495. <if test="projectId != null">
  496. AND a.project_id = #{projectId}
  497. </if>
  498. <if test="userId != null">
  499. AND a.creator_id = #{userId}
  500. </if>
  501. ORDER BY a.create_date desc
  502. </select>
  503. <!--按照项目内的阶段名称分组统计工时-->
  504. <select id="getCostInStage" resultType="java.util.Map">
  505. SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  506. FROM report AS a
  507. WHERE a.project_id = #{projectId}
  508. AND a.state = 1
  509. <if test="startDate != null and endDate != null">
  510. AND a.create_date between #{startDate} and #{endDate}
  511. </if>
  512. GROUP BY a.stage
  513. ORDER BY a.stage ASC
  514. </select>
  515. <!--按照项目内的阶段名称分组统计工时-->
  516. <select id="getCostByGroup" resultType="java.util.Map">
  517. SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  518. FROM report AS a
  519. left join task_group tg on tg.id=a.group_id
  520. WHERE a.project_id = #{projectId}
  521. AND a.state = 1
  522. <if test="startDate != null and endDate != null">
  523. AND a.create_date between #{startDate} and #{endDate}
  524. </if>
  525. GROUP BY a.group_id
  526. ORDER BY a.group_id ASC
  527. </select>
  528. <!--获取全部人员工时 -->
  529. <select id="getAllMembCost" resultType="java.util.Map">
  530. SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  531. FROM user AS b
  532. left JOIN report AS a ON a.creator_id = b.id
  533. WHERE a.state = 1
  534. and b.company_id = #{companyId}
  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. GROUP BY b.id
  542. ORDER BY b.id ASC
  543. </select>
  544. <!--分页获取项目成本 -->
  545. <select id="getAllProjectCost" resultMap="BaseResultMap">
  546. SELECT id, project_code, project_name,
  547. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  548. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 0 and expense_sheet.status = 0) AS fee_normal,
  549. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 1 and expense_sheet.status = 0) AS fee_travel,
  550. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0) AS fee_outsourcing
  551. FROM project WHERE project.`company_id` = #{companyId}
  552. and (project.status &lt;&gt; 3 or project.status is null)
  553. <if test="projectId != null">
  554. and project.id = #{projectId}
  555. </if>
  556. <if test="inchagerIds!=null and inchagerIds.size()>0">
  557. and project.id in
  558. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  559. #{item}
  560. </foreach>
  561. </if>
  562. order by project.is_public desc, project.id asc
  563. <if test="pageStart != null and pageSize != null">
  564. LIMIT #{pageStart},#{pageSize}
  565. </if>
  566. </select>
  567. <!--分页获取项目收支平衡 -->
  568. <select id="getProjectInAndOut" resultMap="BaseResultMap">
  569. SELECT project_code, project_name,contract_amount,
  570. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  571. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 0 and expense_sheet.status = 0) AS fee_normal,
  572. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 1 and expense_sheet.status = 0) AS fee_travel,
  573. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0) AS fee_outsourcing
  574. FROM project WHERE project.`company_id` = #{companyId}
  575. and (project.status &lt;&gt; 3 or project.status is null)
  576. <if test="projectId != null">
  577. and project.id = #{projectId}
  578. </if>
  579. <if test="inchagerIds!=null and inchagerIds.size()>0">
  580. and project.id in
  581. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  582. #{item}
  583. </foreach>
  584. </if>
  585. order by is_public desc, id asc
  586. <if test="pageStart != null and pageSize != null">
  587. LIMIT #{pageStart},#{pageSize}
  588. </if>
  589. </select>
  590. <!--分页获取客户项目的成本利润报表 -->
  591. <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
  592. SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
  593. SUM(contract_amount) AS contract_amount ,
  594. SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man,
  595. SUM((SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 0 and expense_sheet.status = 0)) AS fee_normal,
  596. SUM((SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 1 and expense_sheet.status = 0)) AS fee_travel,
  597. SUM((SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0)) AS fee_outsourcing
  598. FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  599. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  600. <if test="customerId!=null">
  601. and project.customer_id=#{customerId}
  602. </if>
  603. <if test="projectId!=null">
  604. and project.id=#{projectId}
  605. </if>
  606. GROUP BY customer_id
  607. <if test="pageStart != null and pageSize != null">
  608. LIMIT #{pageStart},#{pageSize}
  609. </if>
  610. </select>
  611. <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
  612. SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
  613. AND (project.status &lt;&gt; 3 OR project.status IS NULL)
  614. <if test="customerId!=null">
  615. and project.customer_id=#{customerId}
  616. </if>
  617. <if test="projectId!=null">
  618. and project.id=#{projectId}
  619. </if>
  620. </select>
  621. <!--分页获取项目收支平衡 -->
  622. <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
  623. SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
  624. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man,
  625. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 0 and expense_sheet.status = 0) AS fee_normal,
  626. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 1 and expense_sheet.status = 0) AS fee_travel,
  627. (SELECT IFNULL(SUM(amount),0) FROM expense_item , expense_sheet WHERE project_id = project.id AND expense_sheet.id = expense_item.`expense_id` AND expense_sheet.type = 2 and expense_sheet.status = 0) AS fee_outsourcing
  628. FROM project WHERE project.`company_id` = #{companyId}
  629. and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
  630. #{item}
  631. </foreach>
  632. </select>
  633. <select id="getGanttData" resultType="java.util.Map">
  634. SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
  635. TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
  636. LEFT JOIN user ON user.id = participation.`user_id`
  637. LEFT JOIN project ON project.`id` = participation.`project_id`
  638. WHERE participation.`user_id` IN
  639. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  640. #{item}
  641. </foreach>
  642. AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
  643. ORDER BY participation.user_id, project.`plan_start_date`
  644. </select>
  645. <select id="getTaskPlanByMemb" resultType="java.util.Map">
  646. 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,
  647. 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
  648. LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
  649. left join task on task.id = task_executor.task_id
  650. LEFT JOIN project ON project.`id` = task.`project_id`
  651. WHERE user.`id` IN
  652. <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
  653. #{item}
  654. </foreach>
  655. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  656. and task.end_date is not null
  657. AND project.`status` = 1
  658. ORDER BY user.id, task.start_date
  659. </select>
  660. <select id="getTaskPlanByProject" resultType="java.util.Map">
  661. 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,
  662. IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
  663. LEFT JOIN task ON task.project_id = project.id
  664. WHERE project.company_id = #{companyId}
  665. <if test="projectIds != null">
  666. and project.`id` IN
  667. <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
  668. #{item}
  669. </foreach>
  670. </if>
  671. and ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
  672. and task.end_date is not null
  673. AND project.`status` = 1
  674. ORDER BY project.id, task.start_date
  675. </select>
  676. <!--获取加班统计报表 -->
  677. <!-- <select id="getOvertimeList" resultType="java.util.Map">-->
  678. <!-- SELECT report.`creator_id` AS userId, user.`name` AS username, SUM(report.`working_time`) AS workingTime,-->
  679. <!-- IFNULL(SUM(report.`overtime_hours`),0) AS overtimeHours,-->
  680. <!-- group_concat(distinct(project.project_code)) as projectCode,-->
  681. <!-- IFNULL(SUM(report.overtime_cost), 0) AS cost FROM report LEFT JOIN user ON user.id = report.`creator_id`-->
  682. <!-- left join project on project.id = report.project_id-->
  683. <!-- WHERE report.is_overtime = 1-->
  684. <!-- and report.`state` = 1-->
  685. <!-- AND report.`create_date` BETWEEN #{startDate} and #{endDate}-->
  686. <!-- AND user.`company_id` = #{companyId}-->
  687. <!-- <if test="projectId != null">-->
  688. <!-- AND report.`project_id` = #{projectId}-->
  689. <!-- </if>-->
  690. <!-- <if test="userId != null">-->
  691. <!-- AND report.`creator_id` = #{userId}-->
  692. <!-- </if>-->
  693. <!-- GROUP BY report.creator_id-->
  694. <!-- </select>-->
  695. <!-- 获取某个员工的某时间段内的加班详情 -->
  696. <select id="getOvertimeDetail" resultType="java.util.Map">
  697. SELECT date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
  698. report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
  699. IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
  700. project.project_name as projectName,project.project_code as projectCode,
  701. IFNULL(report.overtime_cost, 0) AS cost,
  702. IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName FROM report LEFT JOIN user ON user.id = report.`creator_id`
  703. left join project on project.id = report.project_id
  704. left join report_extra_degree on report_extra_degree.id = report.degree_id
  705. left join department on department.department_id = report.dept_id
  706. WHERE report.is_overtime = 1
  707. and report.`state` = 1
  708. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  709. AND user.`company_id` = #{companyId}
  710. <if test="projectId != null">
  711. AND report.`project_id` = #{projectId}
  712. </if>
  713. <if test="userId != null">
  714. AND report.`creator_id` = #{userId}
  715. </if>
  716. <if test="branchDepartment!=null and branchDepartment.size()>0">
  717. and report.dept_id in
  718. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  719. #{item}
  720. </foreach>
  721. </if>
  722. <if test="deptIds!=null and deptIds.size()>0">
  723. and report.dept_id in
  724. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  725. #{item}
  726. </foreach>
  727. </if>
  728. order by user.create_time asc, report.create_date desc
  729. </select>
  730. <!--获取人员工时-->
  731. <select id="getUserWorkingTimeList" resultType="java.util.Map">
  732. SELECT report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber,
  733. user.department_id As deptId,
  734. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  735. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  736. ifnull(SUM(report.`working_time`),0) AS workingTime
  737. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  738. left join project on project.id = report.project_id
  739. WHERE
  740. report.`state` = 1
  741. AND user.`is_active` = 1
  742. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  743. AND user.`company_id` =#{companyId}
  744. <if test="userId!=null">
  745. and user.id=#{userId}
  746. </if>
  747. <if test="projectId!=null">
  748. and project.id=#{projectId}
  749. </if>
  750. <if test="branchDepartment!=null and branchDepartment.size()>0">
  751. and report.dept_id in
  752. <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
  753. #{item}
  754. </foreach>
  755. </if>
  756. <if test="deptIds!=null and deptIds.size()>0">
  757. and report.dept_id in
  758. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  759. #{item}
  760. </foreach>
  761. </if>
  762. group by user.id
  763. order by user.create_time asc, report.create_date desc
  764. <if test="start!=null and size!=null">
  765. limit #{start},#{size}
  766. </if>
  767. </select>
  768. <select id="findCountWithUser" resultType="java.lang.Long">
  769. select count(*)
  770. from (SELECT report.`creator_id` AS userId, user.`name` AS username,
  771. ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
  772. ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
  773. ifnull(SUM(report.`working_time`),0) AS workingTime
  774. FROM report LEFT JOIN user ON user.id = report.`creator_id`
  775. left join project on project.id = report.project_id
  776. WHERE
  777. report.`state` = 1
  778. AND user.`is_active` = 1
  779. AND report.`create_date` BETWEEN #{startDate} and #{endDate}
  780. AND user.`company_id` =#{companyId}
  781. <if test="userId!=null">
  782. and user.id=#{userId}
  783. </if>
  784. <if test="projectId!=null">
  785. and project.id=#{projectId}
  786. </if>
  787. <if test="departmentId!=null">
  788. and report.dept_id=#{departmentId}
  789. </if>
  790. <if test="deptIds!=null and deptIds.size()>0">
  791. and report.dept_id in
  792. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  793. #{item}
  794. </foreach>
  795. </if>
  796. group by user.id
  797. order by user.create_time asc, report.create_date desc
  798. <if test="start!=null and size!=null">
  799. limit #{start},#{size}
  800. </if>) as total
  801. </select>
  802. <!--按照项目内的阶段名称分组统计工时-->
  803. <select id="getDegreeCost" resultType="java.util.Map">
  804. SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
  805. FROM report AS a
  806. left join report_extra_degree b on b.id = a.degree_id
  807. WHERE
  808. a.state = 1
  809. and a.company_id = #{companyId}
  810. <if test="departmentIds!=null and departmentIds.size()>0">
  811. and a.dept_id in
  812. <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
  813. #{item}
  814. </foreach>
  815. </if>
  816. <if test="projectId != null">
  817. and a.project_id = #{projectId}
  818. </if>
  819. <if test="startDate != null and endDate != null">
  820. AND a.create_date between #{startDate} and #{endDate}
  821. </if>
  822. GROUP BY a.degree_id
  823. ORDER BY a.degree_id ASC
  824. </select>
  825. <!--项目导出数据-->
  826. <select id="getExportData" resultType="java.util.HashMap" >
  827. 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,
  828. plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
  829. customer_name, associate_degree_names, provider_names,provider_ids
  830. FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
  831. LEFT JOIN participation c ON c.project_id = project.`id`
  832. LEFT JOIN user u ON u.id = c.user_id
  833. LEFT JOIN user d ON d.id = project.`incharger_id`
  834. WHERE project.`company_id` = #{companyId}
  835. <if test="userId != null" >
  836. and (project.creator_id = #{userId} or c.user_id = #{userId})
  837. </if>
  838. GROUP BY project.id
  839. </select>
  840. <!--按项目分组导出数据-->
  841. <select id="getExportGroupData" resultType="java.util.Map" >
  842. SELECT project_code as projectCode,project_name as projectName,task_group.`name` AS groupName,`user`.`name` AS inchargerName,`user`.corpwx_userid as corpwxUserId,`user`.corpwx_userid as corpwxUserId,
  843. (SELECT GROUP_CONCAT(name) FROM group_participator g LEFT JOIN `user` ON `user`.id = g.user_id WHERE g.group_id = group_participator.group_id GROUP BY g.group_id) AS participators,
  844. (SELECT GROUP_CONCAT(corpwx_userid) FROM group_participator g LEFT JOIN `user` ON `user`.id = g.user_id WHERE g.group_id = group_participator.group_id GROUP BY g.group_id) AS participatorsCorp
  845. FROM task_group
  846. LEFT JOIN group_participator ON task_group.id = group_participator.group_id
  847. LEFT JOIN project on task_group.project_id = project.id
  848. LEFT JOIN `user` ON task_group.incharger_id = `user`.id
  849. where project.company_id = #{companyId}
  850. GROUP BY task_group.id
  851. ORDER BY project_id
  852. </select>
  853. <!--分页获取项目工时成本预警表 -->
  854. <select id="getProjectCostAlarm" resultType="java.util.HashMap">
  855. SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  856. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
  857. AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
  858. WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
  859. AND project_id=project.id) AS costLimit,
  860. (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
  861. FROM project WHERE company_id=#{companyId}
  862. and (project.status &lt;&gt; 3 or project.status is null)
  863. <if test="projectId != null">
  864. and project.id = #{projectId}
  865. </if>
  866. <if test="pageStart != null and pageSize != null">
  867. LIMIT #{pageStart},#{pageSize}
  868. </if>
  869. </select>
  870. <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
  871. SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
  872. (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
  873. 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,
  874. (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
  875. 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,
  876. (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
  877. FROM project WHERE (STATUS &lt;&gt; 3 OR project.status IS NULL) AND company_id=#{companyId}
  878. <if test="projectId != null">
  879. and project.id = #{projectId}
  880. </if>
  881. <if test="pageStart != null and pageSize != null">
  882. LIMIT #{pageStart},#{pageSize}
  883. </if>
  884. </select>
  885. <select id="getWaitingReviewList" resultType="java.util.Map">
  886. <choose>
  887. <when test="stateKey==0">
  888. SELECT dept_manager.name as userName,`user`.corpwx_userid as corpwxUserId,department.department_name as departmentName,department.corpwx_deptid as wxDeptId,COUNT(1) as num
  889. FROM report AS a
  890. left join user on user.id = a.creator_id
  891. JOIN project AS b ON a.project_id=b.id
  892. left join sub_project as d on d.id = a.sub_project_id
  893. left join task on task.id = a.task_id
  894. left join report_extra_degree on report_extra_degree.id = a.degree_id
  895. left join department on department.department_id = a.audit_deptid
  896. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  897. left join department dept on dept.department_id = a.dept_id
  898. left join task_group on task_group.id = a.group_id
  899. left join user u on u.id = a.project_auditor_id
  900. WHERE a.company_id =#{companyId}
  901. and a.state = 0
  902. and u.is_active = 1
  903. <if test="startDate!=null and endDate!=null">
  904. AND a.create_date between #{startDate} and #{endDate}
  905. </if>
  906. AND a.is_dept_audit=1
  907. <if test="userId!=null">
  908. and dept_manager.id=#{userId}
  909. </if>
  910. <if test="departmentId!=null">
  911. and dept_manager.department_id=#{departmentId}
  912. </if>
  913. <if test="deptIds!=null and deptIds.size()>0">
  914. and dept_manager.department_id in
  915. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  916. #{item}
  917. </foreach>
  918. </if>
  919. group by a.audit_dept_managerid
  920. ORDER BY a.create_date desc, a.creator_id asc
  921. </when>
  922. <otherwise>
  923. SELECT u.name as userName,u.corpwx_userid as corpwxUserId,dp.department_name as departmentName,dp.corpwx_deptid as wxDeptId,COUNT(1) as num
  924. FROM report AS a
  925. left join user on user.id = a.creator_id
  926. JOIN project AS b ON a.project_id=b.id
  927. left join sub_project as d on d.id = a.sub_project_id
  928. left join task on task.id = a.task_id
  929. left join report_extra_degree on report_extra_degree.id = a.degree_id
  930. left join department on department.department_id = a.audit_deptid
  931. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  932. left join department dept on dept.department_id = a.dept_id
  933. left join task_group on task_group.id = a.group_id
  934. left join user u on u.id = a.project_auditor_id
  935. left join department dp on u.department_id=dp.department_id
  936. WHERE a.company_id =#{companyId}
  937. and a.state = 0
  938. and u.is_active = 1
  939. <if test="startDate!=null and endDate!=null">
  940. AND a.create_date between #{startDate} and #{endDate}
  941. </if>
  942. AND a.is_dept_audit=0 and a.project_audit_state = 0
  943. <if test="userId!=null">
  944. and u.id=#{userId}
  945. </if>
  946. <if test="departmentId!=null">
  947. and u.department_id=#{departmentId}
  948. </if>
  949. <if test="deptIds!=null and deptIds.size()>0">
  950. and u.department_id in
  951. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  952. #{item}
  953. </foreach>
  954. </if>
  955. group by a.project_auditor_id
  956. ORDER BY a.create_date desc, a.creator_id asc
  957. </otherwise>
  958. </choose>
  959. <if test="start!=null and size!=null">
  960. limit #{start},#{size}
  961. </if>
  962. </select>
  963. <select id="findCount" resultType="java.lang.Long">
  964. select count(1)
  965. from (<choose>
  966. <when test="stateKey==0">
  967. SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
  968. FROM report AS a
  969. left join user on user.id = a.creator_id
  970. JOIN project AS b ON a.project_id=b.id
  971. left join sub_project as d on d.id = a.sub_project_id
  972. left join task on task.id = a.task_id
  973. left join report_extra_degree on report_extra_degree.id = a.degree_id
  974. left join department on department.department_id = a.audit_deptid
  975. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  976. left join department dept on dept.department_id = a.dept_id
  977. left join task_group on task_group.id = a.group_id
  978. left join user u on u.id = a.project_auditor_id
  979. WHERE a.company_id =#{companyId}
  980. and a.state = 0
  981. and u.is_active = 1
  982. <if test="startDate!=null and endDate!=null">
  983. AND a.create_date between #{startDate} and #{endDate}
  984. </if>
  985. AND a.is_dept_audit=1
  986. <if test="userId!=null">
  987. and dept_manager.id=#{userId}
  988. </if>
  989. <if test="departmentId!=null">
  990. and dept_manager.department_id=#{departmentId}
  991. </if>
  992. <if test="deptIds!=null and deptIds.size()>0">
  993. and dept_manager.department_id in
  994. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  995. #{item}
  996. </foreach>
  997. </if>
  998. group by a.audit_dept_managerid
  999. ORDER BY a.create_date desc, a.creator_id asc
  1000. </when>
  1001. <otherwise>
  1002. SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
  1003. FROM report AS a
  1004. left join user on user.id = a.creator_id
  1005. JOIN project AS b ON a.project_id=b.id
  1006. left join sub_project as d on d.id = a.sub_project_id
  1007. left join task on task.id = a.task_id
  1008. left join report_extra_degree on report_extra_degree.id = a.degree_id
  1009. left join department on department.department_id = a.audit_deptid
  1010. left join user dept_manager on dept_manager.id = a.audit_dept_managerid
  1011. left join department dept on dept.department_id = a.dept_id
  1012. left join task_group on task_group.id = a.group_id
  1013. left join user u on u.id = a.project_auditor_id
  1014. left join department dp on u.department_id=dp.department_id
  1015. WHERE a.company_id =#{companyId}
  1016. and a.state = 0
  1017. and u.is_active = 1
  1018. <if test="startDate!=null and endDate!=null">
  1019. AND a.create_date between #{startDate} and #{endDate}
  1020. </if>
  1021. AND a.is_dept_audit=0 and a.project_audit_state = 0
  1022. <if test="userId!=null">
  1023. and u.id=#{userId}
  1024. </if>
  1025. <if test="departmentId!=null">
  1026. and u.department_id=#{departmentId}
  1027. </if>
  1028. <if test="deptIds!=null and deptIds.size()>0">
  1029. and u.department_id in
  1030. <foreach collection="deptIds" open="(" separator="," close=")" item="item">
  1031. #{item}
  1032. </foreach>
  1033. </if>
  1034. group by a.project_auditor_id
  1035. ORDER BY a.create_date desc, a.creator_id asc
  1036. </otherwise>
  1037. </choose>
  1038. <if test="start!=null and size!=null">
  1039. limit #{start},#{size}
  1040. </if>) total
  1041. </select>
  1042. <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
  1043. select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
  1044. (select SUM(te.plan_hours) from task_executor te
  1045. left join task on task.id=te.task_id
  1046. where te.executor_id=us.id
  1047. <if test="startDate!=null and endDate!=null">
  1048. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1049. </if>) as planHours,
  1050. (select SUM(report.working_time) from report
  1051. left join task on task.id=report.task_id
  1052. where report.creator_id=us.id and task_id is not null and report.state=1
  1053. <if test="startDate!=null and endDate!=null">
  1054. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate}
  1055. </if>) as workingTime
  1056. from user us
  1057. left join department dp on dp.department_id=us.department_id
  1058. where us.company_id=#{companyId}
  1059. 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)
  1060. <if test="userId!=null and userId!=''">
  1061. and us.id=#{userId}
  1062. </if>
  1063. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1064. and us.department_id in
  1065. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1066. #{item}
  1067. </foreach>
  1068. </if>
  1069. <if test="deptIds!=null and deptIds.size()>0">
  1070. and us.department_id in
  1071. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1072. #{item}
  1073. </foreach>
  1074. </if>
  1075. group by us.id
  1076. order by us.department_id
  1077. <if test="start!=null and size!=null">
  1078. limit #{start},#{size}
  1079. </if>
  1080. </select>
  1081. <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
  1082. select count(1)
  1083. from(select us.name,dp.department_name as departmentName,
  1084. (select SUM(te.plan_hours) from task_executor te
  1085. left join task on task.id=te.task_id
  1086. where te.executor_id=us.id
  1087. <if test="startDate!=null and endDate!=null">
  1088. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1089. </if>) as planHours,
  1090. (select SUM(report.working_time) from report
  1091. left join task on task.id=report.task_id
  1092. where report.creator_id=us.id and task_id is not null
  1093. <if test="startDate!=null and endDate!=null">
  1094. and task.create_date &gt;=#{startDate} and task.create_date &lt;=#{endDate}
  1095. </if>) as workingTime
  1096. from user us
  1097. left join department dp on dp.department_id=us.department_id
  1098. where us.company_id=#{companyId}
  1099. 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)
  1100. <if test="userId!=null and userId!=''">
  1101. and us.id=#{userId}
  1102. </if>
  1103. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1104. and us.department_id in
  1105. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1106. #{item}
  1107. </foreach>
  1108. </if>
  1109. <if test="deptIds!=null and deptIds.size()>0">
  1110. and us.department_id in
  1111. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1112. #{item}
  1113. </foreach>
  1114. </if>
  1115. group by us.id
  1116. order by us.department_id)as total
  1117. </select>
  1118. <select id="selectWithGroup" resultType="java.util.Map">
  1119. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1120. from report a
  1121. left join task_group b on a.group_id=b.id
  1122. left join project c on a.project_id=c.id
  1123. where c.company_id=#{companyId} and a.state=1
  1124. <if test="startDate!=null and endDate!=null">
  1125. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1126. </if>
  1127. <if test="projectId!=null">
  1128. and c.id=#{projectId}
  1129. </if>
  1130. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1131. and c.id in
  1132. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1133. #{item}
  1134. </foreach>
  1135. </if>
  1136. <if test="groupId!=null">
  1137. and a.group_id=#{groupId}
  1138. </if>
  1139. group by b.name
  1140. order by c.id
  1141. <if test="startIndex!=null and endIndex!=null">
  1142. limit #{startIndex},#{endIndex}
  1143. </if>
  1144. </select>
  1145. <select id="selectCountWithGroup" resultType="java.lang.Long">
  1146. select count(1) from(
  1147. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
  1148. from report a
  1149. left join task_group b on a.group_id=b.id
  1150. left join project c on a.project_id=c.id
  1151. where c.company_id=#{companyId} and a.state=1
  1152. <if test="startDate!=null and endDate!=null">
  1153. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1154. </if>
  1155. <if test="projectId!=null">
  1156. and c.id=#{projectId}
  1157. </if>
  1158. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1159. and c.id in
  1160. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1161. #{item}
  1162. </foreach>
  1163. </if>
  1164. <if test="groupId!=null">
  1165. and a.group_id=#{groupId}
  1166. </if>
  1167. group by b.name
  1168. order by c.id
  1169. <if test="startIndex!=null and endIndex!=null">
  1170. limit #{startIndex},#{endIndex}
  1171. </if>) as total
  1172. </select>
  1173. <select id="selectWithGroupProject" resultType="java.util.Map">
  1174. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1175. from report a
  1176. left join task_group b on a.group_id=b.id
  1177. left join project c on a.project_id=c.id
  1178. where c.company_id=#{companyId} and a.state=1
  1179. <if test="startDate!=null and endDate!=null">
  1180. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1181. </if>
  1182. <if test="projectId!=null">
  1183. and c.id=#{projectId}
  1184. </if>
  1185. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1186. and c.id in
  1187. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1188. #{item}
  1189. </foreach>
  1190. </if>
  1191. <if test="groupId!=null">
  1192. and a.group_id=#{groupId}
  1193. </if>
  1194. group by c.id,b.id
  1195. order by c.id
  1196. <if test="startIndex!=null and endIndex!=null">
  1197. limit #{startIndex},#{endIndex}
  1198. </if>
  1199. </select>
  1200. <select id="selectCountWithGroupProject" resultType="java.lang.Long">
  1201. select count(1) from(
  1202. select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
  1203. from report a
  1204. left join task_group b on a.group_id=b.id
  1205. left join project c on a.project_id=c.id
  1206. where c.company_id=#{companyId} and a.state=1
  1207. <if test="startDate!=null and endDate!=null">
  1208. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1209. </if>
  1210. <if test="projectId!=null">
  1211. and c.id=#{projectId}
  1212. </if>
  1213. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1214. and c.id in
  1215. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1216. #{item}
  1217. </foreach>
  1218. </if>
  1219. <if test="groupId!=null">
  1220. and a.group_id=#{groupId}
  1221. </if>
  1222. group by c.id,b.id
  1223. order by c.id
  1224. <if test="startIndex!=null and endIndex!=null">
  1225. limit #{startIndex},#{endIndex}
  1226. </if>) as total
  1227. </select>
  1228. <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
  1229. 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
  1230. from report a
  1231. left join task_group b on a.group_id=b.id
  1232. left join project c on a.project_id=c.id
  1233. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1234. where c.company_id=#{companyId} and a.state=1
  1235. <if test="startDate!=null and endDate!=null">
  1236. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1237. </if>
  1238. <if test="projectId!=null">
  1239. and c.id=#{projectId}
  1240. </if>
  1241. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1242. and c.id in
  1243. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1244. #{item}
  1245. </foreach>
  1246. </if>
  1247. group by c.id,b.id
  1248. <if test="start!=null and size!=null">
  1249. limit #{start},#{size}
  1250. </if>
  1251. </select>
  1252. <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
  1253. select count(1) from
  1254. (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
  1255. from report a
  1256. left join task_group b on a.group_id=b.id
  1257. left join project c on a.project_id=c.id
  1258. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1259. where c.company_id=#{companyId} and a.state=1
  1260. <if test="startDate!=null and endDate!=null">
  1261. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1262. </if>
  1263. <if test="projectId!=null">
  1264. and c.id=#{projectId}
  1265. </if>
  1266. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1267. and c.id in
  1268. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1269. #{item}
  1270. </foreach>
  1271. </if>
  1272. group by c.id,b.id
  1273. <if test="start!=null and size!=null">
  1274. limit #{start},#{size}
  1275. </if>) as total
  1276. </select>
  1277. <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
  1278. 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
  1279. from report a
  1280. left join task_group b on a.group_id=b.id
  1281. left join project c on a.project_id=c.id
  1282. left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
  1283. where c.company_id=#{companyId} and a.state=1
  1284. <if test="startDate!=null and endDate!=null">
  1285. and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
  1286. </if>
  1287. <if test="projectId!=null">
  1288. and c.id=#{projectId}
  1289. </if>
  1290. <if test="inchagerIds!=null and inchagerIds.size()>0">
  1291. and c.id in
  1292. <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
  1293. #{item}
  1294. </foreach>
  1295. </if>
  1296. group by c.id,f.id
  1297. <if test="start!=null and size!=null">
  1298. limit #{start},#{size}
  1299. </if>
  1300. </select>
  1301. <select id="getCostByUserCustom" resultType="java.util.Map">
  1302. SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
  1303. FROM user AS a
  1304. LEFT JOIN report AS b ON a.id = b.creator_id
  1305. LEFT JOIN project AS c ON b.project_id = c.id
  1306. left join user_custom uc on uc.company_id=a.company_id
  1307. left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
  1308. WHERE b.state = 1
  1309. AND a.company_id = #{companyId}
  1310. <if test="startDate!=null and endDate!=null">
  1311. AND b.create_date between #{startDate} and #{endDate}
  1312. </if>
  1313. and uc.id=#{customId}
  1314. <if test="deptIds!=null and deptIds.size()>0">
  1315. and a.department_id in
  1316. <foreach collection="deptIds" open="(" item="item" separator="," close=")">
  1317. #{item}
  1318. </foreach>
  1319. </if>
  1320. <if test="subCustomName!=null">
  1321. and suc.name=#{subCustomName}
  1322. </if>
  1323. GROUP BY suc.name
  1324. </select>
  1325. <select id="getEmpMonthHours" resultType="java.util.Map">
  1326. 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,
  1327. (select allday from time_type te
  1328. where te.company_id=#{companyId}) as allday,
  1329. (select SUM(report.working_time) from report
  1330. where report.creator_id=us.id and report.state=1
  1331. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1332. as workingTime
  1333. from user us
  1334. left join department dp on dp.department_id=us.department_id
  1335. where us.company_id=#{companyId}
  1336. 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)
  1337. <if test="userId!=null and userId!=''">
  1338. and us.id=#{userId}
  1339. </if>
  1340. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1341. and us.department_id in
  1342. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1343. #{item}
  1344. </foreach>
  1345. </if>
  1346. <if test="deptIds!=null and deptIds.size()>0">
  1347. and us.department_id in
  1348. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1349. #{item}
  1350. </foreach>
  1351. </if>
  1352. group by us.id
  1353. order by us.department_id
  1354. <if test="start!=null and size!=null">
  1355. limit #{start},#{size}
  1356. </if>
  1357. </select>
  1358. <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
  1359. select count(1)
  1360. from(select us.name,dp.department_name as departmentName,
  1361. (select SUM(report.working_time) from report
  1362. where report.creator_id=us.id
  1363. and report.create_date &gt;=#{startDate} and report.create_date &lt;=#{endDate})
  1364. as workingTime
  1365. from user us
  1366. left join department dp on dp.department_id=us.department_id
  1367. where us.company_id=#{companyId}
  1368. 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)
  1369. <if test="userId!=null and userId!=''">
  1370. and us.id=#{userId}
  1371. </if>
  1372. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1373. and us.department_id in
  1374. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1375. #{item}
  1376. </foreach>
  1377. </if>
  1378. <if test="deptIds!=null and deptIds.size()>0">
  1379. and us.department_id in
  1380. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1381. #{item}
  1382. </foreach>
  1383. </if>
  1384. group by us.id
  1385. order by us.department_id)as total
  1386. </select>
  1387. <!-- 分页查询部门参与项目情况-->
  1388. <select id="selectDeptPartInProjects" resultType="java.util.Map">
  1389. SELECT department.department_id deptId,
  1390. department_name deptName,
  1391. (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,
  1392. pro.projectCount projectCount,
  1393. pro.centerCount centerCount,
  1394. pcon.peopleCount peopleCount
  1395. FROM department
  1396. LEFT JOIN (
  1397. SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
  1398. COUNT(DISTINCT(r.degree_id)) centerCount
  1399. FROM report
  1400. LEFT JOIN report r
  1401. ON report.id = r.id AND r.degree_id != -1
  1402. LEFT JOIN `user`
  1403. ON report.creator_id = user.id
  1404. WHERE report.state = 1
  1405. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1406. GROUP BY dept_id
  1407. ) pro
  1408. on pro.dept_id = department.department_id
  1409. LEFT JOIN (
  1410. SELECT dept_id,sum(p.con) peopleCount
  1411. FROM (
  1412. SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
  1413. LEFT JOIN `user`
  1414. ON report.creator_id = user.id
  1415. WHERE report.state = 1
  1416. And report.create_date BETWEEN #{startDate} AND #{endDate}
  1417. GROUP BY report.creator_id,dept_id
  1418. ) p GROUP BY p.dept_id
  1419. ) pcon
  1420. ON pcon.dept_id = department.department_id
  1421. WHERE department.company_id = #{companyId}
  1422. <if test="branchDepartment!=null and branchDepartment.size()>0">
  1423. and department.department_id in
  1424. <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
  1425. #{item}
  1426. </foreach>
  1427. </if>
  1428. <if test="deptIds!=null and deptIds.size()>0">
  1429. and department.department_id in
  1430. <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
  1431. #{item}
  1432. </foreach>
  1433. </if>
  1434. <if test="size!=null and start!=null">
  1435. limit #{start},#{size}
  1436. </if>
  1437. </select>
  1438. </mapper>