|
|
@@ -3,24 +3,34 @@ package com.ruoyi.project.service.impl;
|
|
|
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.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.common.utils.bean.BeanValidators;
|
|
|
import com.ruoyi.project.bo.ProjectStaffRecordInput;
|
|
|
import com.ruoyi.project.bo.ProjectStaffRecordOut;
|
|
|
+import com.ruoyi.project.bo.ProjectTaskListOut;
|
|
|
import com.ruoyi.project.domain.ProjectStaffRecord;
|
|
|
import com.ruoyi.project.domain.ProjectStaffRecordLog;
|
|
|
+import com.ruoyi.project.domain.ProjectTask;
|
|
|
import com.ruoyi.project.mapper.ProjectStaffRecordLogMapper;
|
|
|
import com.ruoyi.project.mapper.ProjectStaffRecordMapper;
|
|
|
import com.ruoyi.project.mapper.ProjectTaskMapper;
|
|
|
import com.ruoyi.project.service.ProjectStaffRecordService;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.validation.Validator;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ProjectStaffRecordServiceImpl.class);
|
|
|
@Autowired
|
|
|
private ProjectStaffRecordMapper projectStaffRecordMapper;
|
|
|
@Autowired
|
|
|
@@ -29,6 +39,8 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
|
|
|
private SysUserMapper sysUserMapper;
|
|
|
@Autowired
|
|
|
private ProjectTaskMapper projectTaskMapper;
|
|
|
+ @Autowired
|
|
|
+ protected Validator validator;
|
|
|
|
|
|
@Override
|
|
|
public AjaxResult add(ProjectStaffRecord in) {
|
|
|
@@ -119,4 +131,57 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
|
|
|
}
|
|
|
return projectStaffRecordMapper.selectList(in);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String importProject(List<ProjectStaffRecordOut> list, boolean isUpdateSupport, String operName) {
|
|
|
+ if (StringUtils.isNull(list) || list.size() == 0)
|
|
|
+ {
|
|
|
+ throw new ServiceException("导入用户数据不能为空!");
|
|
|
+ }
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ for (ProjectStaffRecordOut p : list)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 验证是否存在
|
|
|
+ ProjectStaffRecord projectStaffRecord = projectStaffRecordMapper.selectByPrimaryKey(p.getId());
|
|
|
+ if (StringUtils.isNull(projectStaffRecord)){
|
|
|
+ BeanValidators.validateWithException(validator, projectStaffRecord);
|
|
|
+ projectStaffRecordMapper.insertSelective(p);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目: " + p.getName() + " 导入成功");
|
|
|
+ }else if (isUpdateSupport){
|
|
|
+ BeanValidators.validateWithException(validator, p);
|
|
|
+ projectStaffRecordMapper.updateByPrimaryKeySelective(p);
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、项目: " + p.getName() + " 更新成功");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ failureNum++;
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、项目: " + p.getName() + " 已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、项目: " + p.getName() + " 导入失败:";
|
|
|
+ failureMsg.append(msg + e.getMessage());
|
|
|
+ log.error(msg, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (failureNum > 0)
|
|
|
+ {
|
|
|
+ failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
+ throw new ServiceException(failureMsg.toString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
+ }
|
|
|
+ return successMsg.toString();
|
|
|
+ }
|
|
|
}
|