ProjectTaskController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. package com.ruoyi.web.controller.project;
  2. import com.ruoyi.common.annotation.Log;
  3. import com.ruoyi.common.config.RuoYiConfig;
  4. import com.ruoyi.common.core.controller.BaseController;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.common.core.domain.R;
  7. import com.ruoyi.project.domain.CompanyClockBo;
  8. import com.ruoyi.common.core.page.TableDataInfo;
  9. import com.ruoyi.common.enums.BusinessType;
  10. import com.ruoyi.common.exception.ServiceException;
  11. import com.ruoyi.common.utils.SecurityUtils;
  12. import com.ruoyi.common.utils.StringUtils;
  13. import com.ruoyi.common.utils.file.FileUploadUtils;
  14. import com.ruoyi.common.utils.file.FileUtils;
  15. import com.ruoyi.common.utils.file.MimeTypeUtils;
  16. import com.ruoyi.common.utils.poi.ExcelUtil;
  17. import com.ruoyi.project.bo.*;
  18. import com.ruoyi.project.domain.ProjectStaff;
  19. import com.ruoyi.project.domain.ProjectStaffRecord;
  20. import com.ruoyi.project.domain.ProjectStaffRecordLog;
  21. import com.ruoyi.project.domain.ProjectTask;
  22. import com.ruoyi.project.service.ProjectStaffRecordService;
  23. import com.ruoyi.project.service.ProjectStaffService;
  24. import com.ruoyi.project.service.ProjectTaskService;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import org.apache.http.HttpStatus;
  28. import org.springframework.http.MediaType;
  29. import org.springframework.validation.annotation.Validated;
  30. import org.springframework.web.bind.annotation.*;
  31. import org.springframework.web.multipart.MultipartFile;
  32. import javax.annotation.Resource;
  33. import javax.servlet.http.HttpServletResponse;
  34. import java.util.Date;
  35. import java.util.HashMap;
  36. import java.util.List;
  37. import java.util.Map;
  38. /**
  39. * 项目管理
  40. */
  41. @Api("项目管理")
  42. @RestController
  43. @RequestMapping("/api/project")
  44. public class ProjectTaskController extends BaseController {
  45. @Resource
  46. private ProjectTaskService projectTaskService;
  47. @Resource
  48. private ProjectStaffService projectStaffService;
  49. @Resource
  50. private ProjectStaffRecordService projectStaffRecordService;
  51. /**
  52. * 新增项目任务
  53. */
  54. @PostMapping("/add")
  55. @ApiOperation("新增项目")
  56. @Log(title = "项目管理", businessType = BusinessType.INSERT)
  57. public AjaxResult add( @RequestBody ProjectTask projectTask){
  58. if (projectTask.getAid()== null){
  59. return error("负责人不能为空");
  60. }
  61. if (projectTaskService.checkProjectNumber(projectTask)){
  62. return error("项目编号已存在");
  63. }
  64. return projectTaskService.addProjectTask(projectTask);
  65. }
  66. /**
  67. * 查询项目编号
  68. */
  69. @GetMapping("/checkProjectNumber")
  70. @ApiOperation("查询项目编号")
  71. public AjaxResult checkProjectNumber( @RequestBody ProjectTask projectTask){
  72. if (projectTaskService.checkProjectNumber(projectTask)){
  73. return error("项目编号已存在");
  74. }
  75. return success(1);
  76. }
  77. /**
  78. * 修改项目
  79. */
  80. @PutMapping("/update")
  81. @ApiOperation("修改项目")
  82. @Log(title = "项目管理", businessType = BusinessType.UPDATE)
  83. public AjaxResult update( @RequestBody ProjectTask projectTask){
  84. if (projectTask.getAid()== null){
  85. return error("负责人不能为空");
  86. }
  87. if (projectTaskService.checkProjectNumber(projectTask)){
  88. return error("项目编号已存在");
  89. }
  90. return projectTaskService.updateProjectTask(projectTask);
  91. }
  92. /**
  93. * 新增项目成员
  94. */
  95. @PostMapping("/addStaff")
  96. @ApiOperation("新增项目成员")
  97. public AjaxResult addStaff(@Validated @RequestBody ProjectStaff in){
  98. return projectStaffService.addStaff(in);
  99. }
  100. /**
  101. * 新增成员打卡
  102. */
  103. @PostMapping("/addRecord")
  104. @ApiOperation("新增项目打卡")
  105. @Log(title = "项目管理", businessType = BusinessType.INSERT)
  106. public AjaxResult addRecord( @RequestBody ProjectStaffRecord in){
  107. if (in.getRecordTime()==null){
  108. in.setRecordTime(new Date());
  109. }
  110. Long userId = SecurityUtils.getUserId();
  111. in.setAid(userId);
  112. AjaxResult ajaxResult = projectStaffRecordService.addCheckMaxDuration(in);
  113. ajaxResult=projectStaffRecordService.checkRecordTime(ajaxResult,in);
  114. if (ajaxResult.isError()){
  115. return ajaxResult;
  116. }
  117. return projectStaffRecordService.add(in);
  118. }
  119. /**
  120. * 修改成员打卡
  121. */
  122. @PostMapping("/updateRecord")
  123. @ApiOperation("修改成员打卡")
  124. @Log(title = "项目日志管理", businessType = BusinessType.UPDATE)
  125. public AjaxResult updateRecord( @RequestBody ProjectStaffRecord in){
  126. Long userId = SecurityUtils.getUserId();
  127. in.setAid(userId);
  128. AjaxResult ajaxResult = projectStaffRecordService.updateCheckMaxDuration(in);
  129. projectStaffRecordService.checkRecordTime(ajaxResult,in);
  130. if (ajaxResult.isError()){
  131. return ajaxResult;
  132. }
  133. return projectStaffRecordService.update(in);
  134. }
  135. /**
  136. * 研发打卡日志详情
  137. */
  138. @GetMapping("/recordDetails")
  139. @ApiOperation("打卡日志详情")
  140. public AjaxResult recordDetails( Long id){
  141. return projectStaffRecordService.recordDetails(id);
  142. }
  143. /**
  144. * 审核成员打卡
  145. */
  146. @PostMapping("/examineRecord")
  147. @ApiOperation("审核成员打卡")
  148. public AjaxResult examineRecord( @RequestBody ProjectStaffRecord in){
  149. if (in.getProcessStatus()!=2 && in.getProcessStatus()!=3){
  150. return AjaxResult.error("审核状态错误");
  151. }
  152. return projectStaffRecordService.examineRecord(in);
  153. }
  154. /**
  155. * 批量审核成员打卡
  156. */
  157. @PostMapping("/batchExamineRecord")
  158. @ApiOperation("批量审核成员打卡")
  159. public AjaxResult batchExamineRecord( @RequestBody batchExamineRecordInput in){
  160. if (in.getProcessStatus()!=2 && in.getProcessStatus()!=3){
  161. return AjaxResult.error("审核状态错误");
  162. }
  163. return projectStaffRecordService.batchExamineRecord(in);
  164. }
  165. /**
  166. * 成员打卡列表
  167. */
  168. @GetMapping("/listRecord")
  169. @ApiOperation("成员打卡列表")
  170. public TableDataInfo listRecord( ProjectStaffRecordInput in){
  171. startPage();
  172. List<ProjectStaffRecordOut> list = projectStaffRecordService.listRecord(in);
  173. return getDataTable(list);
  174. }
  175. /**
  176. * 成员打卡审核日志
  177. */
  178. @GetMapping("/listRecordLog")
  179. @ApiOperation("成员打卡审核日志")
  180. public AjaxResult listRecordLog(ProjectStaffRecordLog in){
  181. return projectStaffRecordService.listRecordLog(in);
  182. }
  183. /**
  184. * 导出项目打卡列表
  185. */
  186. @PostMapping("/listRecord/export")
  187. @ApiOperation("导出项目打卡列表")
  188. @Log(title = "项目日志管理", businessType = BusinessType.EXPORT)
  189. public void listRecordExport(HttpServletResponse response, ProjectStaffRecordInput in){
  190. in.setPageSize(999999);
  191. List<ProjectStaffRecordOut> list=projectStaffRecordService.listRecord(in);
  192. ExcelUtil<ProjectStaffRecordOut> util = new ExcelUtil<>(ProjectStaffRecordOut.class);
  193. util.exportExcel(response, list, "项目研发日志列表");
  194. }
  195. /**
  196. * 导入数据
  197. */
  198. @PostMapping("/listRecord/importData")
  199. @ApiOperation("导入项目打卡数据")
  200. @Log(title = "项目日志管理", businessType = BusinessType.IMPORT)
  201. public AjaxResult listRecordImportData(@RequestParam(value ="file")MultipartFile file, @RequestParam(value = "updateSupport") boolean updateSupport) throws Exception
  202. {
  203. ExcelUtil<ProjectStaffRecordOut> util = new ExcelUtil<>(ProjectStaffRecordOut.class);
  204. List<ProjectStaffRecordOut> list = util.importExcel(file.getInputStream());
  205. String message = projectStaffRecordService.importProject(list, updateSupport);
  206. return success(message);
  207. }
  208. /**
  209. * 项目打卡日志导出模版
  210. */
  211. @PostMapping("/listRecord/importTemplate")
  212. @ApiOperation("项目打卡日志导出模版")
  213. public void listRecordImportTemplate(HttpServletResponse response)
  214. {
  215. ExcelUtil<ProjectStaffRecordOut> util = new ExcelUtil<>(ProjectStaffRecordOut.class);
  216. util.importTemplateExcel(response, "项目打卡日志列表");
  217. }
  218. /**
  219. * 删除项目成员
  220. */
  221. @PostMapping("/deleteStaff")
  222. @ApiOperation("删除项目成员")
  223. @Log(title = "项目管理", businessType = BusinessType.DELETE)
  224. public AjaxResult deleteStaff( @RequestBody ProjectStaff in){
  225. if (in.getId()== null){
  226. return error("项目成员编号不能为空");
  227. }
  228. return projectStaffService.deleteStaff(in);
  229. }
  230. /**
  231. * 项目成员列表
  232. */
  233. @GetMapping("/listStaff")
  234. @ApiOperation("项目成员列表")
  235. public AjaxResult listStaff( ProjectStaff in){
  236. if (in.getPid()== null){
  237. return error("项目编号不能为空");
  238. }
  239. return projectStaffService.listStaff(in);
  240. }
  241. /**
  242. * 删除项目
  243. */
  244. @PostMapping("/deleteProject")
  245. @ApiOperation("删除项目")
  246. @Log(title = "项目管理", businessType = BusinessType.DELETE)
  247. public AjaxResult deleteProject( @RequestBody ProjectTask in){
  248. if (in.getId()== null){
  249. return error("项目编号不能为空");
  250. }
  251. return projectTaskService.deleteProject(in);
  252. }
  253. /**
  254. * 项目详情
  255. */
  256. @GetMapping ("/details")
  257. @ApiOperation("项目详情")
  258. public AjaxResult details( Long id){
  259. if (id== null){
  260. return error("项目编号不能为空");
  261. }
  262. return projectTaskService.details(id);
  263. }
  264. /**
  265. * 项目列表
  266. */
  267. @GetMapping ("/list")
  268. @ApiOperation("项目列表")
  269. public TableDataInfo list(ProjectListInput in){
  270. List<ProjectTaskListOut> list=projectTaskService.list(in);
  271. return getDataTable(list);
  272. }
  273. /**
  274. * 导出项目列表
  275. */
  276. @PostMapping("/export")
  277. @ApiOperation("导出项目列表")
  278. @Log(title = "项目管理", businessType = BusinessType.EXPORT)
  279. public void export(HttpServletResponse response,ProjectListInput in)
  280. {
  281. in.setPageSize(999999);
  282. List<ProjectTaskListOut> list=projectTaskService.list(in);
  283. ExcelUtil<ProjectTaskListOut> util = new ExcelUtil<>(ProjectTaskListOut.class);
  284. util.exportExcel(response, list, "项目列表");
  285. }
  286. /**
  287. * 导入数据
  288. */
  289. @PostMapping("/importData")
  290. @Log(title = "项目管理", businessType = BusinessType.IMPORT)
  291. @ApiOperation("导入项目列表")
  292. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
  293. {
  294. ExcelUtil<ProjectTaskListOut> util = new ExcelUtil<>(ProjectTaskListOut.class);
  295. List<ProjectTaskListOut> list = util.importExcel(file.getInputStream());
  296. String message = projectTaskService.importProject(list, updateSupport, getUsername());
  297. return success(message);
  298. }
  299. @PostMapping("/importTemplate")
  300. @ApiOperation("项目导出模版")
  301. public void importTemplate(HttpServletResponse response)
  302. {
  303. ExcelUtil<ProjectTaskListOut> util = new ExcelUtil<>(ProjectTaskListOut.class);
  304. util.importTemplateExcel(response, "项目列表");
  305. }
  306. /**
  307. * 上传项目文件
  308. */
  309. @PostMapping("/upload")
  310. @ApiOperation("上传文件")
  311. public AjaxResult upload(@RequestParam("file") MultipartFile file) throws Exception{
  312. if (!file.isEmpty()){
  313. String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
  314. AjaxResult ajax = AjaxResult.success();
  315. logger.debug(avatar);
  316. ajax.put("imgUrl", avatar);
  317. return ajax;
  318. }
  319. return error("上传图片异常,请联系管理员");
  320. }
  321. /**
  322. * 查询剩余时间
  323. */
  324. @GetMapping("/myDuration")
  325. @ApiOperation("查询剩余打卡时间")
  326. public AjaxResult myDuration(Long id,String recordTime){
  327. return projectStaffRecordService.myDuration(id,recordTime);
  328. }
  329. /**
  330. * 查询我的月份数据
  331. */
  332. @GetMapping("/myDurationMonth")
  333. @ApiOperation("查询我的月份数据")
  334. public AjaxResult myDurationMonth(Long id,Integer year,Integer month){
  335. return projectStaffRecordService.myDurationMonth(id,year,month);
  336. }
  337. /**
  338. * 项目附件目录
  339. */
  340. @GetMapping("/selectProjectImg")
  341. public AjaxResult selectProjectImg(Long pid){
  342. if (pid==null){
  343. return AjaxResult.error("项目编号不能为空!");
  344. }
  345. return projectTaskService.selectProjectImg(pid);
  346. }
  347. /**
  348. * 下载项目打卡数据包
  349. */
  350. @GetMapping("/download")
  351. public void downloadFiles(HttpServletResponse response,String ids) {
  352. if (StringUtils.isEmpty(ids)){
  353. throw new ServiceException("编号不能为空");
  354. }
  355. projectStaffRecordService.downloadFiles(ids, response);
  356. }
  357. /**
  358. * 打卡数据考勤匹配到打卡时间
  359. */
  360. @PostMapping("/mateUserRecord")
  361. public AjaxResult mateUserRecord(ProjectStaffRecordInput in) {
  362. if (in.getClockStatus()==null||in.getClockStatus()!=2){
  363. return error("请先查询需要合并的数据");
  364. }
  365. return projectStaffRecordService.mateUserRecord(in);
  366. }
  367. /**
  368. * 项目及日志上传天河链
  369. */
  370. @GetMapping("/saveProjectTaskTianhe")
  371. public AjaxResult saveProjectTaskTianhe(@RequestParam("id") String id){
  372. if (StringUtils.isEmpty(id)){
  373. return AjaxResult.error("项目编号不能为空");
  374. }
  375. projectTaskService.saveProjectTaskTianhe(id);
  376. return AjaxResult.success();
  377. }
  378. /**
  379. * 项目日志上传天河链
  380. */
  381. @GetMapping("/saveProjectStaffRecordTianhe")
  382. public AjaxResult saveProjectStaffRecordTianhe(@RequestParam("id") String id){
  383. if (StringUtils.isEmpty(id)){
  384. return AjaxResult.error("项目日志编号不能为空");
  385. }
  386. projectTaskService.saveProjectStaffRecordTianhe(id);
  387. return AjaxResult.success();
  388. }
  389. /**
  390. * 文字上传天河链
  391. */
  392. @GetMapping("/saveText")
  393. public AjaxResult saveText(@RequestParam("content") String content){
  394. if (StringUtils.isEmpty(content)){
  395. return AjaxResult.error("内容不能为空");
  396. }
  397. projectTaskService.saveText(content);
  398. return AjaxResult.success();
  399. }
  400. /**
  401. * 获取项目月份打卡数据
  402. * @param id 项目编号
  403. * @param yearMonth 年月份
  404. * @return 数据
  405. */
  406. @GetMapping("/getMonthClock")
  407. public AjaxResult getMonthClock(@RequestParam("id") Integer id,@RequestParam("yearMonth") String yearMonth){
  408. if (id==null){
  409. return AjaxResult.error("项目编号不能为空");
  410. }
  411. if (yearMonth==null){
  412. return AjaxResult.error("年月日期不能为空");
  413. }
  414. return AjaxResult.success(projectStaffRecordService.getMonthClock(id,yearMonth));
  415. }
  416. /**
  417. * 新项目月份打卡数据 模拟设置最长工时为8
  418. * @param id 项目编号
  419. * @param yearMonth 年月份
  420. * @return 数据
  421. */
  422. @GetMapping("/getNewMonthClock")
  423. public AjaxResult getNewMonthClock(@RequestParam("id") Integer id,@RequestParam("yearMonth") String yearMonth,@RequestParam("duration") String duration){
  424. if (id==null){
  425. return AjaxResult.error("项目编号不能为空");
  426. }
  427. if (yearMonth==null){
  428. return AjaxResult.error("年月日期不能为空");
  429. }
  430. return AjaxResult.success(projectStaffRecordService.getNewMonthClock(id,yearMonth,duration));
  431. }
  432. /**
  433. * 获取项目月份打卡数据
  434. * @param id 项目编号
  435. * @param yearMonth 年月份
  436. */
  437. @PostMapping("/getMonthClockExport")
  438. public void getMonthClockExport(@RequestParam("id") Integer id,@RequestParam("yearMonth") String yearMonth,HttpServletResponse response){
  439. projectStaffRecordService.getMonthClockExport(id,yearMonth,response);
  440. }
  441. /**
  442. * 获取项目对应打卡月份
  443. */
  444. @GetMapping("/allProjectMonthData")
  445. public AjaxResult getAllProjectMonth(){
  446. return AjaxResult.success(projectStaffRecordService.getAllProjectMonth());
  447. }
  448. /**
  449. * 导入打卡数据
  450. */
  451. @PostMapping("/importClockData")
  452. @Log(title = "项目管理", businessType = BusinessType.IMPORT)
  453. @ApiOperation("导入打卡数据")
  454. public AjaxResult importClockData(@RequestParam(value = "file") MultipartFile file) throws Exception
  455. {
  456. ExcelUtil<HashMap> util = new ExcelUtil<>(HashMap.class);
  457. List<Map<Integer,String >> list = util.importMapExcel(file.getInputStream(),0);
  458. return success(projectStaffRecordService.importClockData(list));
  459. }
  460. /**
  461. * 考勤打卡导入模版
  462. */
  463. @PostMapping("/importClockDataTemplate")
  464. @Log(title = "考勤管理", businessType = BusinessType.EXPORT)
  465. @ApiOperation("考勤打卡导入模版")
  466. public void importClockDataTemplate(HttpServletResponse response){
  467. try{
  468. String realFileName = System.currentTimeMillis() + "_考勤模版".substring("考勤模版".indexOf("_") + 1);
  469. String filePath = RuoYiConfig.getDownloadPath() + "考勤模版.xlsx";
  470. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  471. FileUtils.setAttachmentResponseHeader(response, realFileName);
  472. FileUtils.writeBytes(filePath, response.getOutputStream());
  473. }catch (Exception e){
  474. throw new ServiceException("下载文件失败", HttpStatus.SC_BAD_REQUEST);
  475. }
  476. }
  477. /**
  478. * 获取公司打卡数据
  479. */
  480. @GetMapping("/getCompanyClock")
  481. public TableDataInfo getCompanyClock(Integer deptId){
  482. startPage();
  483. List<CompanyClockBo> companyClock = projectStaffRecordService.getCompanyClock(deptId);
  484. return getDataTable(companyClock);
  485. }
  486. /**
  487. * 获取公司打卡数据
  488. */
  489. @GetMapping("/getCompanyDep")
  490. public AjaxResult getCompanyDep(Integer deptId){
  491. return AjaxResult.success(projectStaffRecordService.getCompanyClock(deptId));
  492. }
  493. }