ProjectTaskController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.entity.SysUser;
  7. import com.ruoyi.common.core.domain.model.LoginUser;
  8. import com.ruoyi.common.core.page.TableDataInfo;
  9. import com.ruoyi.common.enums.BusinessType;
  10. import com.ruoyi.common.utils.SecurityUtils;
  11. import com.ruoyi.common.utils.file.FileUploadUtils;
  12. import com.ruoyi.common.utils.file.MimeTypeUtils;
  13. import com.ruoyi.common.utils.poi.ExcelUtil;
  14. import com.ruoyi.project.bo.ProjectListInput;
  15. import com.ruoyi.project.bo.ProjectStaffRecordInput;
  16. import com.ruoyi.project.bo.ProjectStaffRecordOut;
  17. import com.ruoyi.project.bo.ProjectTaskListOut;
  18. import com.ruoyi.project.domain.ProjectStaff;
  19. import com.ruoyi.project.domain.ProjectStaffRecord;
  20. import com.ruoyi.project.domain.ProjectTask;
  21. import com.ruoyi.project.service.ProjectStaffRecordService;
  22. import com.ruoyi.project.service.ProjectStaffService;
  23. import com.ruoyi.project.service.ProjectTaskService;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiOperation;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.validation.annotation.Validated;
  28. import org.springframework.web.bind.annotation.*;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.util.Date;
  32. import java.util.List;
  33. /**
  34. * 项目管理
  35. */
  36. @Api("项目管理")
  37. @RestController
  38. @RequestMapping("/api/project")
  39. public class ProjectTaskController extends BaseController {
  40. @Autowired
  41. private ProjectTaskService projectTaskService;
  42. @Autowired
  43. private ProjectStaffService projectStaffService;
  44. @Autowired
  45. private ProjectStaffRecordService projectStaffRecordService;
  46. /**
  47. * 新增项目任务
  48. * @param projectTask
  49. * @return
  50. */
  51. @PostMapping("/add")
  52. @ApiOperation("新增项目")
  53. @Log(title = "项目管理", businessType = BusinessType.INSERT)
  54. public AjaxResult add( @RequestBody ProjectTask projectTask){
  55. if (projectTask.getAid()== null){
  56. return error("负责人不能为空");
  57. }
  58. return projectTaskService.addProjectTask(projectTask);
  59. }
  60. /**
  61. * 修改项目
  62. * @param projectTask
  63. * @return
  64. */
  65. @PutMapping("/update")
  66. @ApiOperation("修改项目")
  67. @Log(title = "项目管理", businessType = BusinessType.UPDATE)
  68. public AjaxResult update( @RequestBody ProjectTask projectTask){
  69. if (projectTask.getAid()== null){
  70. return error("负责人不能为空");
  71. }
  72. return projectTaskService.updateProjectTask(projectTask);
  73. }
  74. /**
  75. * 新增项目成员
  76. * @param in
  77. * @return
  78. */
  79. @PostMapping("/addStaff")
  80. @ApiOperation("新增项目成员")
  81. public AjaxResult addStaff( @RequestBody ProjectStaff in){
  82. return projectStaffService.addStaff(in);
  83. }
  84. /**
  85. * 新增成员打卡
  86. * @param in
  87. * @return
  88. */
  89. @PostMapping("/addRecord")
  90. @ApiOperation("新增项目打卡")
  91. @Log(title = "项目管理", businessType = BusinessType.INSERT)
  92. public AjaxResult addRecord( @RequestBody ProjectStaffRecord in){
  93. if (in.getRecordTime()==null){
  94. in.setRecordTime(new Date());
  95. }
  96. Long userId = SecurityUtils.getUserId();
  97. in.setAid(userId);
  98. AjaxResult ajaxResult = projectStaffRecordService.addCheckMaxDuration(in);
  99. if (ajaxResult.isError()){
  100. return ajaxResult;
  101. }
  102. return projectStaffRecordService.add(in);
  103. }
  104. /**
  105. * 修改成员打卡
  106. * @param in
  107. * @return
  108. */
  109. @PostMapping("/updateRecord")
  110. @ApiOperation("修改成员打卡")
  111. @Log(title = "项目日志管理", businessType = BusinessType.UPDATE)
  112. public AjaxResult updateRecord( @RequestBody ProjectStaffRecord in){
  113. Long userId = SecurityUtils.getUserId();
  114. in.setAid(userId);
  115. AjaxResult ajaxResult = projectStaffRecordService.updateCheckMaxDuration(in);
  116. if (ajaxResult.isError()){
  117. return ajaxResult;
  118. }
  119. return projectStaffRecordService.update(in);
  120. }
  121. /**
  122. * 研发打卡日志详情
  123. * @param id
  124. * @return
  125. */
  126. @GetMapping("/recordDetails")
  127. @ApiOperation("打卡日志详情")
  128. public AjaxResult recordDetails( Long id){
  129. return projectStaffRecordService.recordDetails(id);
  130. }
  131. /**
  132. * 审核成员打卡
  133. * @param in
  134. * @return
  135. */
  136. @PostMapping("/examineRecord")
  137. @ApiOperation("审核成员打卡")
  138. public AjaxResult examineRecord( @RequestBody ProjectStaffRecord in){
  139. if (in.getProcessStatus()!=2 && in.getProcessStatus()!=3){
  140. return AjaxResult.error("审核状态错误");
  141. }
  142. return projectStaffRecordService.examineRecord(in);
  143. }
  144. /**
  145. * 成员打卡列表
  146. * @param in
  147. * @return
  148. */
  149. @GetMapping("/listRecord")
  150. @ApiOperation("成员打卡列表")
  151. public TableDataInfo listRecord( ProjectStaffRecordInput in){
  152. startPage();
  153. List<ProjectStaffRecordOut> list = projectStaffRecordService.listRecord(in);
  154. return getDataTable(list);
  155. }
  156. /**
  157. * 导出项目列表
  158. * @param response
  159. */
  160. @PostMapping("/listRecord/export")
  161. @ApiOperation("导出项目打卡列表")
  162. @Log(title = "项目日志管理", businessType = BusinessType.EXPORT)
  163. public void listRecordExport(HttpServletResponse response, ProjectStaffRecordInput in){
  164. List<ProjectStaffRecordOut> list=projectStaffRecordService.listRecord(in);
  165. ExcelUtil<ProjectStaffRecordOut> util = new ExcelUtil<>(ProjectStaffRecordOut.class);
  166. util.exportExcel(response, list, "项目研发日志列表");
  167. }
  168. /**
  169. * 导入数据
  170. * @param file
  171. * @param isUpdateSupport
  172. * @return
  173. * @throws Exception
  174. */
  175. @PostMapping("/listRecord/importData")
  176. @ApiOperation("导入项目打卡数据")
  177. @Log(title = "项目日志管理", businessType = BusinessType.IMPORT)
  178. public AjaxResult listRecordImportData(MultipartFile file, boolean isUpdateSupport) throws Exception
  179. {
  180. ExcelUtil<ProjectStaffRecordOut> util = new ExcelUtil<>(ProjectStaffRecordOut.class);
  181. List<ProjectStaffRecordOut> list = util.importExcel(file.getInputStream());
  182. String operName = getUsername();
  183. String message = projectStaffRecordService.importProject(list, isUpdateSupport, operName);
  184. return success(message);
  185. }
  186. /**
  187. * 删除项目成员
  188. * @param in
  189. * @return
  190. */
  191. @PostMapping("/deleteStaff")
  192. @ApiOperation("删除项目成员")
  193. @Log(title = "项目管理", businessType = BusinessType.DELETE)
  194. public AjaxResult deleteStaff( @RequestBody ProjectStaff in){
  195. if (in.getId()== null){
  196. return error("项目成员编号不能为空");
  197. }
  198. return projectStaffService.deleteStaff(in);
  199. }
  200. /**
  201. * 项目成员列表
  202. * @param in
  203. * @return
  204. */
  205. @GetMapping("/listStaff")
  206. @ApiOperation("项目成员列表")
  207. public AjaxResult listStaff( ProjectStaff in){
  208. if (in.getPid()== null){
  209. return error("项目编号不能为空");
  210. }
  211. return projectStaffService.listStaff(in);
  212. }
  213. /**
  214. * 删除项目
  215. * @param in
  216. * @return
  217. */
  218. @PostMapping("/deleteProject")
  219. @ApiOperation("删除项目")
  220. @Log(title = "项目管理", businessType = BusinessType.DELETE)
  221. public AjaxResult deleteProject( @RequestBody ProjectTask in){
  222. if (in.getId()== null){
  223. return error("项目编号不能为空");
  224. }
  225. return projectTaskService.deleteProject(in);
  226. }
  227. /**
  228. * 项目详情
  229. * @param id
  230. * @return
  231. */
  232. @GetMapping ("/details")
  233. @ApiOperation("项目详情")
  234. public AjaxResult details( Long id){
  235. if (id== null){
  236. return error("项目编号不能为空");
  237. }
  238. return projectTaskService.details(id);
  239. }
  240. /**
  241. * 项目列表
  242. * @param
  243. * @return
  244. */
  245. @GetMapping ("/list")
  246. @ApiOperation("项目列表")
  247. public TableDataInfo list(ProjectListInput in){
  248. startPage();
  249. List<ProjectTaskListOut> list=projectTaskService.list(in);
  250. return getDataTable(list);
  251. }
  252. /**
  253. * 导出项目列表
  254. * @param response
  255. */
  256. @PostMapping("/export")
  257. @ApiOperation("导出项目列表")
  258. @Log(title = "项目管理", businessType = BusinessType.EXPORT)
  259. public void export(HttpServletResponse response,ProjectListInput in)
  260. {
  261. List<ProjectTaskListOut> list=projectTaskService.list(in);
  262. ExcelUtil<ProjectTaskListOut> util = new ExcelUtil<>(ProjectTaskListOut.class);
  263. util.exportExcel(response, list, "项目列表");
  264. }
  265. /**
  266. * 导入数据
  267. * @param file
  268. * @param updateSupport
  269. * @return
  270. * @throws Exception
  271. */
  272. @PostMapping("/importData")
  273. @Log(title = "项目管理", businessType = BusinessType.IMPORT)
  274. @ApiOperation("导入项目列表")
  275. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
  276. {
  277. ExcelUtil<ProjectTaskListOut> util = new ExcelUtil<>(ProjectTaskListOut.class);
  278. List<ProjectTaskListOut> list = util.importExcel(file.getInputStream());
  279. String operName = getUsername();
  280. String message = projectTaskService.importProject(list, updateSupport, operName);
  281. return success(message);
  282. }
  283. @PostMapping("/importTemplate")
  284. @ApiOperation("项目导出模版")
  285. public void importTemplate(HttpServletResponse response)
  286. {
  287. ExcelUtil<ProjectTaskListOut> util = new ExcelUtil<ProjectTaskListOut>(ProjectTaskListOut.class);
  288. util.importTemplateExcel(response, "项目列表");
  289. }
  290. /**
  291. * 上传项目文件
  292. * @param file
  293. * @return
  294. * @throws Exception
  295. */
  296. @PostMapping("/upload")
  297. @ApiOperation("上传文件")
  298. public AjaxResult upload(@RequestParam("file") MultipartFile file) throws Exception{
  299. if (!file.isEmpty()){
  300. String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
  301. AjaxResult ajax = AjaxResult.success();
  302. logger.debug(avatar);
  303. ajax.put("imgUrl", avatar);
  304. return ajax;
  305. }
  306. return error("上传图片异常,请联系管理员");
  307. }
  308. /**
  309. * 查询剩余时间
  310. * @param id
  311. * @return
  312. */
  313. @GetMapping("/myDuration")
  314. @ApiOperation("查询剩余打卡时间")
  315. public AjaxResult myDuration(Long id,String recordTime){
  316. return projectStaffRecordService.myDuration(id,recordTime);
  317. }
  318. @GetMapping("/myDurationMonth")
  319. @ApiOperation("查询我的月份数据")
  320. public AjaxResult myDurationMonth(Long id){
  321. return projectStaffRecordService.myDurationMonth(id);
  322. }
  323. }