|
|
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.enums.UserRolesType;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.exception.base.BaseException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
@@ -14,6 +15,7 @@ import com.ruoyi.project.bo.ProjectTaskOut;
|
|
|
import com.ruoyi.project.domain.ProjectStaff;
|
|
|
import com.ruoyi.project.domain.ProjectTask;
|
|
|
import com.ruoyi.project.mapper.ProjectStaffMapper;
|
|
|
+import com.ruoyi.project.mapper.ProjectStaffRecordMapper;
|
|
|
import com.ruoyi.project.mapper.ProjectTaskMapper;
|
|
|
import com.ruoyi.project.service.ProjectTaskService;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
@@ -42,6 +44,8 @@ public class ProjectTaskServiceImpl implements ProjectTaskService {
|
|
|
private Validator validator;
|
|
|
@Autowired
|
|
|
private SysUserMapper userMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProjectStaffRecordMapper projectStaffRecordMapper;
|
|
|
|
|
|
@Override
|
|
|
public AjaxResult addProjectTask(ProjectTask projectTask) {
|
|
|
@@ -67,7 +71,7 @@ public class ProjectTaskServiceImpl implements ProjectTaskService {
|
|
|
|
|
|
if (projectTask!=null){
|
|
|
BeanUtils.copyBeanProp(out, projectTask);
|
|
|
- List<ProjectStaff> projectStaffs = projectStaffMapper.selectBypid(id);
|
|
|
+ List<ProjectStaff> projectStaffs = projectStaffMapper.selectByPid(id);
|
|
|
if (!projectStaffs.isEmpty())out.setList(projectStaffs);
|
|
|
return AjaxResult.success(out);
|
|
|
}
|
|
|
@@ -77,18 +81,24 @@ public class ProjectTaskServiceImpl implements ProjectTaskService {
|
|
|
@Override
|
|
|
public List<ProjectTaskListOut> list(ProjectListInput in) {
|
|
|
pushRoleType(in);
|
|
|
- in.setUid(SecurityUtils.getUserId());
|
|
|
- Long companyId = deptService.selectCompanyByDeptId();
|
|
|
- if (companyId!=null)in.setCompanyId(companyId);
|
|
|
+ if (!SecurityUtils.isSuperAdmin()){
|
|
|
+ in.setUid(SecurityUtils.getUserId());
|
|
|
+ Long companyId = deptService.selectCompanyByDeptId();
|
|
|
+ if (companyId!=null)in.setCompanyId(companyId);
|
|
|
+ }
|
|
|
if (in.getEndTime()!=null)in.setEndTime(in.getEndTime()+" 23:59:59");
|
|
|
return projectTaskMapper.selectList(in);
|
|
|
}
|
|
|
|
|
|
private void pushRoleType(ProjectListInput in) {
|
|
|
- if (in.getRoleType()==null)in.setRoleType(0);
|
|
|
if (SecurityUtils.hashRoles(UserRolesType.CEO.getCode())){
|
|
|
in.setRoleType(1);
|
|
|
+ }else if (SecurityUtils.hashRoles(UserRolesType.ADMIN.getCode())){
|
|
|
+ in.setRoleType(3);
|
|
|
+ }else if (SecurityUtils.hashRoles(UserRolesType.MANAGE.getCode())){
|
|
|
+ in.setRoleType(2);
|
|
|
}
|
|
|
+ if (in.getRoleType()==null)in.setRoleType(0);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -111,11 +121,29 @@ public class ProjectTaskServiceImpl implements ProjectTaskService {
|
|
|
ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(p.getId());
|
|
|
if (StringUtils.isNull(projectTask)){
|
|
|
BeanValidators.validateWithException(validator, projectTask);
|
|
|
+ if(p.getStaffName()!=null) {
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ newPs.setAid(sysUser.getUserId());
|
|
|
+ newPs.setName(sysUser.getNickName());
|
|
|
+ newPs.setPid(p.getId());
|
|
|
+ projectStaffMapper.insertSelective(newPs);
|
|
|
+ }
|
|
|
+ }
|
|
|
projectTaskMapper.insertSelective(projectTask);
|
|
|
successNum++;
|
|
|
successMsg.append("<br/>" + successNum + "、项目: " + projectTask.getName() + " 导入成功");
|
|
|
}else if (isUpdateSupport){
|
|
|
BeanValidators.validateWithException(validator, p);
|
|
|
+ if(p.getStaffName()!=null) {
|
|
|
+ addStaffAndDelete(successNum, successMsg, p);
|
|
|
+ }
|
|
|
projectTaskMapper.updateByPrimaryKeySelective(p);
|
|
|
successNum++;
|
|
|
successMsg.append("<br/>" + successNum + "、项目: " + projectTask.getName() + " 更新成功");
|
|
|
@@ -146,5 +174,57 @@ public class ProjectTaskServiceImpl implements ProjectTaskService {
|
|
|
return successMsg.toString();
|
|
|
}
|
|
|
|
|
|
+ private void addStaffAndDelete(int successNum, StringBuilder successMsg, 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteStaff(int successNum, StringBuilder successMsg, ProjectTaskListOut p, String[] split, List<ProjectStaff> projectStaffs) {
|
|
|
+ //预设需要删除,如果找到相同名字的就无需删除
|
|
|
+ for (ProjectStaff ps : projectStaffs) {
|
|
|
+ boolean flag = true;
|
|
|
+ for (String s : split) {
|
|
|
+ if (ps.getName().equals(s)) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag) {
|
|
|
+ int sum = projectStaffRecordMapper.selectById(ps.getId());
|
|
|
+ if (sum > 0) {
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目: " + p.getName() + " 更新失败,[" + ps.getName() + "]存在打卡不能删除");
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ projectStaffMapper.deleteByPrimaryKey(ps.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addStaff(int successNum, StringBuilder successMsg, ProjectTaskListOut p, String[] split, List<ProjectStaff> projectStaffs) {
|
|
|
+ for (String s : split) {
|
|
|
+ boolean flag = true;
|
|
|
+ for (ProjectStaff ps : projectStaffs) {
|
|
|
+ if (ps.getName().equals(s)) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag) {
|
|
|
+ ProjectStaff newPs = new ProjectStaff();
|
|
|
+ SysUser sysUser = userMapper.selectByNikeName(s);
|
|
|
+ if (sysUser == null) {
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目: " + p.getName() + " 更新失败,[" + s + "]不存在");
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ newPs.setAid(sysUser.getUserId());
|
|
|
+ newPs.setName(sysUser.getNickName());
|
|
|
+ newPs.setPid(p.getId());
|
|
|
+ projectStaffMapper.insertSelective(newPs);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|