个人周报填报增加父亲id、周数字段,修改add方法判断父亲是否存在并创建

This commit is contained in:
zty 2024-07-10 14:54:02 +08:00
parent a0e27bb63a
commit f5f551a7d8
3 changed files with 79 additions and 50 deletions

View File

@ -38,6 +38,7 @@ public class ProjectInitListener implements ExecutionListener {
ISystemUserLoginService systemUserLoginService; ISystemUserLoginService systemUserLoginService;
@Autowired @Autowired
ProjectQuarterlyEvaluationService projectQuarterlyEvaluationService; ProjectQuarterlyEvaluationService projectQuarterlyEvaluationService;
@Override @Override
@Transactional @Transactional
public void notify(DelegateExecution execution) throws Exception { public void notify(DelegateExecution execution) throws Exception {
@ -59,17 +60,17 @@ public class ProjectInitListener implements ExecutionListener {
} }
//根据部门批量添加部门周报填报 //根据部门批量添加部门周报填报
JSONArray depts = (JSONArray) ext.get("executeDepts"); // JSONArray depts = (JSONArray) ext.get("executeDepts");
ArrayList<ProjectWeekly> weeklyArrayList = new ArrayList<>(); ArrayList<ProjectWeekly> weeklyArrayList = new ArrayList<>();
if (!ObjectUtils.isEmpty(depts)) { // if (!ObjectUtils.isEmpty(depts)) {
depts.forEach(a -> { // depts.forEach(a -> {
ProjectWeekly projectWeekly = new ProjectWeekly(); // ProjectWeekly projectWeekly = new ProjectWeekly();
projectWeekly.setProjectId(String.valueOf(projectInfo.getId())); // projectWeekly.setProjectId(String.valueOf(projectInfo.getId()));
projectWeekly.setWeeklyType("1"); // projectWeekly.setWeeklyType("1");
projectWeekly.setCreatedAt(new Timestamp(System.currentTimeMillis())); // projectWeekly.setCreatedAt(new Timestamp(System.currentTimeMillis()));
projectWeekly.setDeptId(a.toString()); // projectWeekly.setDeptId(a.toString());
weeklyArrayList.add(projectWeekly); // weeklyArrayList.add(projectWeekly);
}); // });
//添加项目专员/负责人假数据方便周报填报页面查看所有暂时 //添加项目专员/负责人假数据方便周报填报页面查看所有暂时
String draftManId = String.valueOf(ext.get("draftManId")); String draftManId = String.valueOf(ext.get("draftManId"));
@ -99,7 +100,7 @@ public class ProjectInitListener implements ExecutionListener {
projectQuarterlyEvaluationService.insert(quarterlyEvaluation); projectQuarterlyEvaluationService.insert(quarterlyEvaluation);
} }
} }
} // }
} catch (Exception e) { } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
log.error("ProjectInitListener.notify", e); log.error("ProjectInitListener.notify", e);

View File

@ -21,6 +21,8 @@ import com.xqopen.kehui.project.service.IProjectWeeklyService;
import com.xqopen.kehui.util.ApiResponse; import com.xqopen.kehui.util.ApiResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -48,6 +50,7 @@ public class ProjectWeeklyController implements ProjectWeeklyApi {
*/ */
@Override @Override
@PostMapping(Api.PROJECT_WEEKLY_ADD) @PostMapping(Api.PROJECT_WEEKLY_ADD)
@Transactional
public String add(@RequestHeader("userId") Long userId, @RequestBody ProjectWeeklyAddReq projectWeeklyAddReq) throws XQException { public String add(@RequestHeader("userId") Long userId, @RequestBody ProjectWeeklyAddReq projectWeeklyAddReq) throws XQException {
try { try {
if (!ObjectUtils.isEmpty(projectWeeklyAddReq)) { if (!ObjectUtils.isEmpty(projectWeeklyAddReq)) {
@ -63,10 +66,28 @@ public class ProjectWeeklyController implements ProjectWeeklyApi {
if (!StringUtils.isEmpty(projectWeekly.getId())) { if (!StringUtils.isEmpty(projectWeekly.getId())) {
projectWeekly.setUpdatedBy(String.valueOf(userId)); projectWeekly.setUpdatedBy(String.valueOf(userId));
projectWeekly.setUpdatedAt(new Timestamp(System.currentTimeMillis())); projectWeekly.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
projectWeekly.setProjectId(String.valueOf(project.getId()));
if (projectWeeklyService.updateById(projectWeekly)) return ApiResponse.fillSuccess("保存成功!"); if (projectWeeklyService.updateById(projectWeekly)) return ApiResponse.fillSuccess("保存成功!");
} }
//新增个人周报填报时判断相应的部门周报是否存在否则添加
EntityWrapper<ProjectWeekly> weeklyEntityWrapper = new EntityWrapper<>();
weeklyEntityWrapper.eq("is_deleted", "0");
weeklyEntityWrapper.eq("week", projectWeekly.getWeek());
weeklyEntityWrapper.eq("weekly_type", "1");
weeklyEntityWrapper.eq("dept_id", projectWeekly.getDeptId());
weeklyEntityWrapper.eq("project_id", projectWeekly.getProjectId());
ProjectWeekly weekly = projectWeeklyService.selectOne(weeklyEntityWrapper);
if (ObjectUtils.isEmpty(weekly)) {
weekly = new ProjectWeekly();
weekly.setWeeklyType("1");
weekly.setWeek(projectWeekly.getWeek());
weekly.setProjectId(projectWeekly.getProjectId());
weekly.setDeptId(projectWeekly.getDeptId());
weekly.setCreatedAt(new Timestamp(System.currentTimeMillis()));
projectWeeklyService.insert(weekly);
projectWeekly.setParentId(weekly.getId());
}
//将人事id转为账号id //将人事id转为账号id
EntityWrapper<SystemUserLogin> userLoginEntityWrapper = new EntityWrapper<>(); EntityWrapper<SystemUserLogin> userLoginEntityWrapper = new EntityWrapper<>();
userLoginEntityWrapper.eq("userinfo_id", Long.parseLong(projectWeekly.getUserId())); userLoginEntityWrapper.eq("userinfo_id", Long.parseLong(projectWeekly.getUserId()));
@ -79,6 +100,8 @@ public class ProjectWeeklyController implements ProjectWeeklyApi {
return ApiResponse.fillFail("操作失败"); return ApiResponse.fillFail("操作失败");
} catch (Exception e) { } catch (Exception e) {
log.error("ProjectWeeklyController.add", e); log.error("ProjectWeeklyController.add", e);
//批量新增出现异常被捕获时手动回滚事务保证数据库一致
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new XQException(ErrorCode.PROJECTINFO_EXCEPTION_ERROR, null); throw new XQException(ErrorCode.PROJECTINFO_EXCEPTION_ERROR, null);
} }
} }
@ -123,8 +146,10 @@ public class ProjectWeeklyController implements ProjectWeeklyApi {
projectWeekly.setIsDeleted("0"); projectWeekly.setIsDeleted("0");
projectWeekly.setUserId(String.valueOf(userId)); projectWeekly.setUserId(String.valueOf(userId));
projectWeekly.setWeeklyType("0"); projectWeekly.setWeeklyType("0");
if(!StringUtils.isEmpty(projectWeeklyFindReq.getId()!=null))projectWeekly.setId(projectWeeklyFindReq.getId()); if (!StringUtils.isEmpty(projectWeeklyFindReq.getId() != null))
if(!StringUtils.isEmpty(projectWeeklyFindReq.getDeptId()!=null))projectWeekly.setDeptId(projectWeeklyFindReq.getDeptId()); projectWeekly.setId(projectWeeklyFindReq.getId());
if (!StringUtils.isEmpty(projectWeeklyFindReq.getDeptId() != null))
projectWeekly.setDeptId(projectWeeklyFindReq.getDeptId());
List<ProjectWeeklyDto> list = projectWeeklyService.getList(page, projectWeekly); List<ProjectWeeklyDto> list = projectWeeklyService.getList(page, projectWeekly);
//判断当前账号是否是项目专员/负责人 //判断当前账号是否是项目专员/负责人
@ -143,8 +168,10 @@ public class ProjectWeeklyController implements ProjectWeeklyApi {
projectWeekly1.setIsDeleted("0"); projectWeekly1.setIsDeleted("0");
projectWeekly1.setWeeklyType("0"); projectWeekly1.setWeeklyType("0");
projectWeekly1.setProjectId(weekly.getProjectId()); projectWeekly1.setProjectId(weekly.getProjectId());
if(!StringUtils.isEmpty(projectWeeklyFindReq.getId()!=null))projectWeekly1.setId(projectWeeklyFindReq.getId()); if (!StringUtils.isEmpty(projectWeeklyFindReq.getId() != null))
if(!StringUtils.isEmpty(projectWeeklyFindReq.getDeptId()!=null))projectWeekly.setDeptId(projectWeeklyFindReq.getDeptId()); projectWeekly1.setId(projectWeeklyFindReq.getId());
if (!StringUtils.isEmpty(projectWeeklyFindReq.getDeptId() != null))
projectWeekly.setDeptId(projectWeeklyFindReq.getDeptId());
list.addAll(projectWeeklyService.getList(page, projectWeekly1)); list.addAll(projectWeeklyService.getList(page, projectWeekly1));
} }

View File

@ -41,7 +41,8 @@ public class ProjectWeekly extends Model<ProjectWeekly> {
private java.sql.Timestamp updatedAt ; private java.sql.Timestamp updatedAt ;
@TableField("ext_") @TableField("ext_")
private JSONObject ext; private JSONObject ext;
private String parentId;
private String week;
@Override @Override
protected Serializable pkVal() { protected Serializable pkVal() {
return null; return null;