|
@@ -0,0 +1,196 @@
|
|
|
+package com.jeeplus.sys.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.jeeplus.aop.demo.annotation.DemoMode;
|
|
|
+import com.jeeplus.aop.logging.annotation.ApiLog;
|
|
|
+import com.jeeplus.common.beanvalidator.BeanValidators;
|
|
|
+import com.jeeplus.core.excel.utils.EasyPoiUtil;
|
|
|
+import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
|
+import com.jeeplus.security.util.SecurityUtils;
|
|
|
+import com.jeeplus.sys.constant.enums.ProjectStatusEnum;
|
|
|
+import com.jeeplus.sys.domain.UserProject;
|
|
|
+import com.jeeplus.sys.service.UserProjectService;
|
|
|
+import com.jeeplus.sys.service.UserService;
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
+import com.jeeplus.sys.service.dto.UserProjectDTO;
|
|
|
+import com.jeeplus.sys.service.mapstruct.UserProjectWrapper;
|
|
|
+import com.jeeplus.sys.service.mapstruct.UserWrapper;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.time.DateUtils;
|
|
|
+import org.dozer.inject.DozerBeanContainer;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.validation.ConstraintViolationException;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 项目Controller
|
|
|
+ *
|
|
|
+ * @author lizhenhao
|
|
|
+ * @version 2022-08-02
|
|
|
+ */
|
|
|
+@Api("项目管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "/sys/project")
|
|
|
+public class UserProjectController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserProjectService userProjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @ApiLog("查询项目列表")
|
|
|
+ @PreAuthorize("hasAuthority('sys:project:list')")
|
|
|
+ @GetMapping("list")
|
|
|
+ public ResponseEntity<IPage<UserProject>> data(UserProject userProject, Page<UserProject> page) throws Exception {
|
|
|
+ QueryWrapper<UserProject> queryWrapper = QueryWrapperGenerator.buildQueryCondition (userProject, UserProject.class);
|
|
|
+ IPage<UserProject> result = userProjectService.page (page, queryWrapper);
|
|
|
+ return ResponseEntity.ok (result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询项目数据
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiLog("查询项目详情")
|
|
|
+ @PreAuthorize ("hasAnyAuthority('sys:project:view','sys:project:add','sys:project:edit')")
|
|
|
+ @GetMapping("queryById")
|
|
|
+ public ResponseEntity queryById(@RequestParam("id") String id) {
|
|
|
+ UserProject userProject = userProjectService.getById ( id );
|
|
|
+ return ResponseEntity.ok (userProject);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存项目信息
|
|
|
+ * @param projectDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiLog("保存项目")
|
|
|
+ @PreAuthorize ("hasAnyAuthority('sys:post:add','sys:post:edit')")
|
|
|
+ @PostMapping("save")
|
|
|
+ public ResponseEntity save(@Valid @RequestBody UserProjectDTO projectDTO){
|
|
|
+ //新增或编辑表单保存
|
|
|
+ UserProject project = UserProjectWrapper.INSTANCE.toEntity (projectDTO);
|
|
|
+ UserProject pro = userProjectService.projectDtoToDate(project,projectDTO);
|
|
|
+ if(StrUtil.isEmpty(projectDTO.getId())){
|
|
|
+ userProjectService.save(pro);//新增
|
|
|
+ }else{
|
|
|
+ LambdaUpdateWrapper<UserProject> wrapper = userProjectService.getLambdaUpdateWrapper(projectDTO);
|
|
|
+ userProjectService.update (pro,wrapper);//修改
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseEntity.ok ("保存项目成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除项目
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiLog("删除项目")
|
|
|
+ @PreAuthorize ("hasAuthority('sys:project:del')")
|
|
|
+ @DeleteMapping("delete")
|
|
|
+ public ResponseEntity delete(String ids) {
|
|
|
+ String idArray[] =ids.split(",");
|
|
|
+ userProjectService.removeByIds (Lists.newArrayList (idArray));
|
|
|
+ return ResponseEntity.ok ("删除项目成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入项目数据
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @DemoMode
|
|
|
+ @PreAuthorize("hasAnyAuthority('sys:project:import')")
|
|
|
+ @PostMapping("import")
|
|
|
+ @ApiOperation(value = "导入项目数据excel")
|
|
|
+ public ResponseEntity importFile(MultipartFile file) throws ParseException {
|
|
|
+ int successNum = 0;
|
|
|
+ List<UserProjectDTO> list = EasyPoiUtil.importSheetExcel(file, 1, 1, 1, UserProjectDTO.class);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (UserProjectDTO project : list) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ if(StrUtil.isNotEmpty(project.getEvaluationReportDateUi())){
|
|
|
+ String format = sdf.format(DateUtils.parseDate(project.getEvaluationReportDateUi(), new String[]{"yyyy/MM/dd"}));
|
|
|
+ project.setEvaluationReportDate(sdf.parse(format));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ if(StrUtil.isNotEmpty(project.getEvaluationReportDateUi())){
|
|
|
+ if(project.getEvaluationReportDateUi().contains("报告已作废")){
|
|
|
+ project.setStatus(ProjectStatusEnum.INVALID.getValue());
|
|
|
+ project.setAssessReportMessage(project.getEvaluationReportDateUi());
|
|
|
+ }else{
|
|
|
+ project.setStatus(ProjectStatusEnum.STAGING.getValue());
|
|
|
+ project.setAssessReportMessage(project.getEvaluationReportDateUi());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ project.setStatus(ProjectStatusEnum.STAGING.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if(StrUtil.isNotEmpty(project.getEvaluationBaseDateUi())){
|
|
|
+ String format = sdf.format(DateUtils.parseDate(project.getEvaluationBaseDateUi(), new String[]{"yyyy/MM/dd"}));
|
|
|
+ project.setEvaluationBaseDate(sdf.parse(format));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ if(StrUtil.isNotEmpty(project.getEvaluationBaseDateUi()))
|
|
|
+ project.setAssessBaseMessage(project.getEvaluationBaseDateUi());
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if(StrUtil.isNotEmpty(project.getInvoiceDateUi())){
|
|
|
+ String format = sdf.format(DateUtils.parseDate(project.getInvoiceDateUi(), new String[]{"yyyy/MM/dd"}));
|
|
|
+ project.setInvoiceDate(sdf.parse(format));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ if(StrUtil.isNotEmpty(project.getInvoiceDateUi()))
|
|
|
+ project.setInvoiceMessage(project.getInvoiceDateUi());
|
|
|
+ }
|
|
|
+
|
|
|
+ //项目负责人、签字评估师1、签字评估师2 关联user表的id
|
|
|
+ if(StrUtil.isNotBlank(project.getProjectHead())){
|
|
|
+ project.setProjectHead(userService.getUserByLoginName(project.getProjectHead()).getId());
|
|
|
+ }else{
|
|
|
+ project.setProjectHead("");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StrUtil.isNotBlank(project.getEvaluationPersonOne())){
|
|
|
+ project.setEvaluationPersonOne(userService.getUserByLoginName(project.getEvaluationPersonOne()).getId());
|
|
|
+ }else{
|
|
|
+ project.setEvaluationPersonOne("");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StrUtil.isNotBlank(project.getEvaluationPersonTwo())){
|
|
|
+ project.setEvaluationPersonTwo(userService.getUserByLoginName(project.getEvaluationPersonTwo()).getId());
|
|
|
+ }else{
|
|
|
+ project.setEvaluationPersonTwo("");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ userProjectService.save(UserProjectWrapper.INSTANCE.toEntity(project));
|
|
|
+ successNum++;
|
|
|
+ }
|
|
|
+ return ResponseEntity.ok("已成功导入 " + successNum + " 条数据");
|
|
|
+ }
|
|
|
+}
|