ProjectMapper.xml 65 KB

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