anderx 2 anni fa
parent
commit
ce15b1ae90

+ 16 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -56,6 +56,19 @@ public class ProjectTaskController extends BaseController {
     }
 
     /**
+     * 修改项目
+     * @param projectTask
+     * @return
+     */
+    @PutMapping("/update")
+    public AjaxResult update( @RequestBody ProjectTask projectTask){
+        if (projectTask.getAid()== null){
+            return error("负责人不能为空");
+        }
+        return projectTaskService.updateProjectTask(projectTask);
+    }
+
+    /**
      * 新增项目成员
      * @param in
      * @return
@@ -238,17 +251,17 @@ public class ProjectTaskController extends BaseController {
     /**
      * 导入数据
      * @param file
-     * @param isUpdateSupport
+     * @param updateSupport
      * @return
      * @throws Exception
      */
     @PostMapping("/importData")
-    public AjaxResult importData(MultipartFile file, boolean isUpdateSupport) throws Exception
+    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
     {
         ExcelUtil<ProjectTaskListOut> util = new ExcelUtil<>(ProjectTaskListOut.class);
         List<ProjectTaskListOut> list = util.importExcel(file.getInputStream());
         String operName = getUsername();
-        String message = projectTaskService.importProject(list, isUpdateSupport, operName);
+        String message = projectTaskService.importProject(list, updateSupport, operName);
         return success(message);
     }
 

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectTaskService.java

@@ -18,4 +18,5 @@ public interface ProjectTaskService {
 
     String importProject(List<ProjectTaskListOut> list, boolean updateSupport, String operName);
 
+    AjaxResult updateProjectTask(ProjectTask projectTask);
 }

+ 49 - 18
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectTaskServiceImpl.java

@@ -13,6 +13,7 @@ import com.ruoyi.project.bo.ProjectListInput;
 import com.ruoyi.project.bo.ProjectTaskListOut;
 import com.ruoyi.project.bo.ProjectTaskOut;
 import com.ruoyi.project.domain.ProjectStaff;
+import com.ruoyi.project.domain.ProjectStaffRecord;
 import com.ruoyi.project.domain.ProjectTask;
 import com.ruoyi.project.mapper.ProjectStaffMapper;
 import com.ruoyi.project.mapper.ProjectStaffRecordMapper;
@@ -104,7 +105,7 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
 
 
     @Override
-    public String importProject(List<ProjectTaskListOut> list, boolean isUpdateSupport, String operName) {
+    public String importProject(List<ProjectTaskListOut> list, boolean updateSupport, String operName) {
         if (StringUtils.isNull(list) || list.size() == 0)
         {
             throw new ServiceException("导入用户数据不能为空!");
@@ -120,15 +121,14 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
                 // 验证是否存在这个用户
                 ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(p.getId());
                 if (StringUtils.isNull(projectTask)){
-                    BeanValidators.validateWithException(validator, projectTask);
-                    if(p.getStaffName()!=null) {
+                    BeanValidators.validateWithException(validator, p);
+                    if(StringUtils.isNotBlank(p.getStaffName())) {
                         String[] split = p.getStaffName().split(",");
                         for (String s : split) {
                             ProjectStaff newPs = new ProjectStaff();
                             SysUser sysUser = userMapper.selectByNikeName(s);
                             if (sysUser == null) {
-                                successMsg.append("<br/>" + successNum + "、项目: " + p.getName() + " 更新失败,[" + s + "]不存在");
-                                throw new RuntimeException();
+                                throw new ServiceException("[" + s + "]不存在");
                             }
                             newPs.setAid(sysUser.getUserId());
                             newPs.setName(sysUser.getNickName());
@@ -136,13 +136,34 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
                             projectStaffMapper.insertSelective(newPs);
                         }
                     }
-                    projectTaskMapper.insertSelective(projectTask);
+                    if(StringUtils.isNotBlank(p.getAdminName())) {
+                        SysUser sysUser = userMapper.selectByNikeName(p.getAdminName());
+                        if (sysUser == null) {
+                            throw new ServiceException(String.format("负责人[%s]不存在", p.getAdminName()));
+                        }
+                        p.setAid(sysUser.getUserId());
+                        p.setAdminName(sysUser.getNickName());
+                    }
+                    projectTaskMapper.insertSelective(p);
+                    projectTaskMapper.updateStaffName(p.getId());
                     successNum++;
                     successMsg.append("<br/>" + successNum + "、项目: " + projectTask.getName() + " 导入成功");
-                }else if (isUpdateSupport){
+                }else if (updateSupport){
                     BeanValidators.validateWithException(validator, p);
-                    if(p.getStaffName()!=null) {
-                        addStaffAndDelete(successNum, successMsg, p);
+                    if(StringUtils.isNotBlank(p.getStaffName())) {
+                        addStaffAndDelete( p);
+                    }
+                    if (p.getAdminName()!=null){
+                        SysUser sysUser = userMapper.selectByNikeName(p.getAdminName());
+                        if (sysUser == null) {
+                            throw new ServiceException(String.format("负责人[%s]不存在", p.getAdminName()));
+                        }
+                        List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByPidAndAid(p.getId(), projectTask.getAid());
+                        if (projectStaffRecords.size()>0){
+                            throw new ServiceException(String.format("负责人[%s]存在打卡,不允许切换.", projectTask.getAdminName()));
+                        }
+                        p.setAid(sysUser.getUserId());
+                        p.setAdminName(sysUser.getNickName());
                     }
                     projectTaskMapper.updateByPrimaryKeySelective(p);
                     successNum++;
@@ -174,14 +195,26 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         return successMsg.toString();
     }
 
-    private void addStaffAndDelete(int successNum, StringBuilder successMsg, ProjectTaskListOut p) {
+    @Override
+    public AjaxResult updateProjectTask(ProjectTask in) {
+        ProjectTask use = projectTaskMapper.selectByPrimaryKey(in.getId());
+        if (in.getAid().equals(use.getAid())){
+            List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByPidAndAid(in.getId(), use.getAid());
+            if (projectStaffRecords.size()>0){
+                throw new ServiceException(String.format("负责人[%s]存在打卡,不允许切换.", use.getAdminName()));
+            }
+        }
+        return AjaxResult.success(projectTaskMapper.updateByPrimaryKeySelective(in));
+    }
+
+    private void addStaffAndDelete(  ProjectTaskListOut p) {
         String[] split = p.getStaffName().split(",");
         List<ProjectStaff> projectStaffs = projectStaffMapper.selectByPid(p.getId());
-        addStaff(successNum, successMsg, p, split, projectStaffs);
-        deleteStaff(successNum, successMsg, p, split, projectStaffs);
+        addStaff( p, split, projectStaffs);
+        deleteStaff( p, split, projectStaffs);
     }
 
-    private void deleteStaff(int successNum, StringBuilder successMsg, ProjectTaskListOut p, String[] split, List<ProjectStaff> projectStaffs) {
+    private void deleteStaff( ProjectTaskListOut p, String[] split, List<ProjectStaff> projectStaffs) {
         //预设需要删除,如果找到相同名字的就无需删除
         for (ProjectStaff ps : projectStaffs) {
             boolean flag = true;
@@ -193,8 +226,7 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
             if (flag) {
                 int sum = projectStaffRecordMapper.selectById(ps.getId());
                 if (sum > 0) {
-                    successMsg.append("<br/>" + successNum + "、项目: " + p.getName() + " 更新失败,[" + ps.getName() + "]存在打卡不能删除");
-                    throw new RuntimeException();
+                    throw new ServiceException("[" + ps.getName() + "]存在打卡不能删除");
                 }
                 projectStaffMapper.deleteByPrimaryKey(ps.getId());
             }
@@ -202,7 +234,7 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         }
     }
 
-    private void addStaff(int successNum, StringBuilder successMsg, ProjectTaskListOut p, String[] split, List<ProjectStaff> projectStaffs) {
+    private void addStaff( ProjectTaskListOut p, String[] split, List<ProjectStaff> projectStaffs) {
         for (String s : split) {
             boolean flag = true;
             for (ProjectStaff ps : projectStaffs) {
@@ -214,8 +246,7 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
                 ProjectStaff newPs = new ProjectStaff();
                 SysUser sysUser = userMapper.selectByNikeName(s);
                 if (sysUser == null) {
-                    successMsg.append("<br/>" + successNum + "、项目: " + p.getName() + " 更新失败,[" + s + "]不存在");
-                    throw new RuntimeException();
+                    throw new ServiceException("[" + s + "]不存在");
                 }
                 newPs.setAid(sysUser.getUserId());
                 newPs.setName(sysUser.getNickName());