ProjectMapper.xml 77 KB

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