ganzi-api/inventory-ent/src/main/java/com/rzyc/service/AssignmentTaskThread.java

379 lines
15 KiB
Java
Raw Normal View History

package com.rzyc.service;
import com.common.utils.Constants;
import com.common.utils.DateUtils;
import com.common.utils.RandomNumber;
import com.common.utils.model.Code;
import com.common.utils.model.Message;
import com.common.utils.model.SingleResult;
import com.rzyc.bean.OaTaskTime;
import com.rzyc.controller.BaseController;
import com.rzyc.enums.DelState;
import com.rzyc.mapper.EntPostListMapper;
import com.rzyc.mapper.EntPostTaskMapper;
import com.rzyc.mapper.ent.EntUserMapper;
import com.rzyc.mapper.ent.InEntListMapper;
import com.rzyc.model.EntPostList;
import com.rzyc.model.EntPostTask;
import com.rzyc.model.dto.AddOrUpdateEntUserPostListDto;
import com.rzyc.model.ent.EntUser;
import com.rzyc.model.ent.InEntList;
import com.rzyc.model.user.SysUser;
import org.springframework.beans.BeanUtils;
import java.util.*;
/**
* 企业移动端业务 Service
* @author Xuwanxin
* @date 2022/12/8
* */
public class AssignmentTaskThread implements Runnable{
private String entUserId;
private String enterpriseId;
private String postId;
private String createByUserId;
private EntPostListMapper entPostListMapper;
private EntPostTaskMapper entPostTaskMapper;
private InEntListMapper inEntListMapper;
private EntUserMapper entUserMapper;
public AssignmentTaskThread(String entUser, String enterpriseId, String postId, EntPostListMapper entPostListMapper, EntPostTaskMapper entPostTaskMapper,InEntListMapper inEntListMapper,String createByUserId,EntUserMapper entUserMapper) {
this.entUserId = entUser;
this.enterpriseId = enterpriseId;
this.postId = postId;
this.entPostListMapper = entPostListMapper;
this.entPostTaskMapper = entPostTaskMapper;
this.inEntListMapper = inEntListMapper;
this.createByUserId = createByUserId;
this.entUserMapper = entUserMapper;
}
@Override
public void run() {
//插入清单和任务
try {
autoAssignmentTask(entUserId,enterpriseId,postId,createByUserId);
} catch (Exception e) {
e.printStackTrace();
}
}
public void autoAssignmentTask(String userId,String enterpriseId,String postId,String createByUserId) throws Exception {
entPostListMapper.deleteEntPostList(userId);
entPostTaskMapper.deleteEntPostTaskList(userId);
List<InEntList> inEntLists = inEntListMapper.selectByEnterpriseId(enterpriseId);
for (InEntList ie:inEntLists) {
AddOrUpdateEntUserPostListDto addOrUpdateEntUserPostTaskDto = new AddOrUpdateEntUserPostListDto();
addOrUpdateEntUserPostTaskDto.setEntUserId(userId);
addOrUpdateEntUserPostTaskDto.setEnterpriseId(enterpriseId);
addOrUpdateEntUserPostTaskDto.setPostId(postId);
addOrUpdateEntUserPostTaskDto.setEntListId(ie.getEntListId());
addOrUpdateEntUserPostTaskDto.setFrequency(ie.getFrequency());
addOrUpdateEntUserPostTaskDto.setItemContent(ie.getItemContent());
addOrUpdateEntUserPostTaskDto.setItemTitle(ie.getItemTitle());
addOrUpdateEntUserPostTaskDto.setListId(ie.getListId());
addOrUpdateEntUserPostTaskDto.setStandard(ie.getStandard());
insertListAndTask(addOrUpdateEntUserPostTaskDto,createByUserId);
}
}
private SingleResult insertListAndTask(AddOrUpdateEntUserPostListDto addOrUpdateEntUserPostTaskDto,String createByUserId) throws Exception {
EntPostList entPostList = new EntPostList();
SingleResult singleResult = new SingleResult();
BeanUtils.copyProperties(addOrUpdateEntUserPostTaskDto,entPostList);
entPostList.setCreateBy(createByUserId);
entPostList.setCreateTime(new Date());
entPostList.setDelState(DelState.NOT_DEL.getState());
entPostList.setPostListId(RandomNumber.getUUid());
int result = entPostListMapper.insert(entPostList);
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
//插入任务
addFactorTask(entPostList,createByUserId);
return singleResult;
}
/**
* 创建岗位任务
* @param entPostList
* @throws Exception
*/
public void addFactorTask(EntPostList entPostList,String entUserId)throws Exception{
//任务列表
List<EntPostTask> entTasks = new ArrayList<>();
if(1 == entPostList.getStandard()){
entTasks = this.getYearTask(entPostList,entUserId);
}else if(2 == entPostList.getStandard()){
entTasks = this.getHalfYearTask(entPostList,entUserId);
}else if(4 == entPostList.getStandard()){
entTasks = this.getQuarterTask(entPostList,entUserId);
}else if(12 == entPostList.getStandard()){
entTasks = this.getMonthTask(entPostList,entUserId);
}
if(null != entTasks && entTasks.size() > 0){
entPostTaskMapper.insertList(entTasks);
}
}
/**
* 获取年任务信息
* @return
* @throws Exception
*/
private List<EntPostTask> getYearTask(EntPostList entPostList, String entUserId)throws Exception{
List<EntPostTask> entPostTasks = new ArrayList<>();
EntPostTask ept = new EntPostTask();
EntUser entUser = entUserMapper.selectById(entUserId);
Integer year = Calendar.getInstance().get(Calendar.YEAR);
String startTime = year + "-01-01 00:00:01";
String endTime = year + "-12-31 23:59:59";
String subject = year+"年工作任务:"+entPostList.getItemTitle();
ept.setItemTitle(subject);
ept.setFrequency(entPostList.getFrequency());
ept.setTaskState(1);
ept.setEnterpriseId(entPostList.getEnterpriseId());
ept.setItemContent(entPostList.getItemContent());
ept.setPostId(entPostList.getPostId());
ept.setEntUserId(entPostList.getEntUserId());
ept.setListId(entPostList.getListId());
ept.setPostListId(entPostList.getPostListId());
ept.setEntListId(entPostList.getPostListId());
ept.setTaskId(RandomNumber.getUUid());
Date start = DateUtils.parseString2Date(startTime, Constants.DATA);
Date end = DateUtils.parseString2Date(endTime,Constants.DATA);
ept.setStartTime(start);
ept.setEntTime(end);
ept.setDelState(DelState.NOT_DEL.getState());
setCreateByAndModify(ept,entUser);
ept.setCreateTime(new Date());
ept.setModifyTime(new Date());
entPostTasks.add(ept);
return entPostTasks;
}
/**
* 获取半年任务信息
* @return
* @throws Exception
*/
private List<EntPostTask> getHalfYearTask(EntPostList entPostList,String entUserId)throws Exception{
List<EntPostTask> entPostTasks = new ArrayList<>();
List<OaTaskTime> taskTimes = this.getTaskTime(entPostList.getStandard());
Integer year = Calendar.getInstance().get(Calendar.YEAR);
EntUser entUser = entUserMapper.selectById(entUserId);
for (OaTaskTime taskTime : taskTimes){
EntPostTask ept = new EntPostTask();
String subject = year+"年工作任务:"+entPostList.getItemTitle();
ept.setItemTitle(subject);
ept.setFrequency(entPostList.getFrequency());
ept.setTaskState(1);
ept.setEnterpriseId(entPostList.getEnterpriseId());
ept.setItemContent(entPostList.getItemContent());
ept.setPostId(entPostList.getPostId());
ept.setEntUserId(entPostList.getEntUserId());
ept.setListId(entPostList.getListId());
ept.setPostListId(entPostList.getPostListId());
ept.setEntListId(entPostList.getPostListId());
ept.setTaskId(RandomNumber.getUUid());
Date start = DateUtils.parseString2Date(taskTime.getStartTime(),Constants.DATA);
Date end = DateUtils.parseString2Date(taskTime.getEndTime(),Constants.DATA);
ept.setStartTime(start);
ept.setEntTime(end);
ept.setDelState(DelState.NOT_DEL.getState());
setCreateByAndModify(ept,entUser);
ept.setCreateTime(new Date());
ept.setModifyTime(new Date());
entPostTasks.add(ept);
}
return entPostTasks;
}
/**
* 获取季度任务信息
* @return
* @throws Exception
*/
private List<EntPostTask> getQuarterTask(EntPostList entPostList,String entUserId)throws Exception{
List<EntPostTask> entPostTasks = new ArrayList<>();
List<OaTaskTime> taskTimes = this.getTaskTime(entPostList.getStandard());
Integer year = Calendar.getInstance().get(Calendar.YEAR);
Integer index = 1;
for (OaTaskTime taskTime : taskTimes){
EntPostTask ept = new EntPostTask();
EntUser entUser = entUserMapper.selectById(entUserId);
String subject = year+"年第"+index+"季度工作任务:"+entPostList.getItemTitle();
ept.setItemTitle(subject);
ept.setFrequency(entPostList.getFrequency());
ept.setTaskState(1);
ept.setEnterpriseId(entPostList.getEnterpriseId());
ept.setItemContent(entPostList.getItemContent());
ept.setPostId(entPostList.getPostId());
ept.setEntUserId(entPostList.getEntUserId());
ept.setListId(entPostList.getListId());
ept.setPostListId(entPostList.getPostListId());
ept.setEntListId(entPostList.getPostListId());
ept.setTaskId(RandomNumber.getUUid());
Date start = DateUtils.parseString2Date(taskTime.getStartTime(),Constants.DATA);
Date end = DateUtils.parseString2Date(taskTime.getEndTime(),Constants.DATA);
ept.setStartTime(start);
ept.setEntTime(end);
ept.setDelState(DelState.NOT_DEL.getState());
setCreateByAndModify(ept,entUser);
ept.setCreateTime(new Date());
ept.setModifyTime(new Date());
entPostTasks.add(ept);
index++;
}
return entPostTasks;
}
/**
* 获取月任务信息
* @return
* @throws Exception
*/
private List<EntPostTask> getMonthTask(EntPostList entPostList,String entUserId)throws Exception{
List<EntPostTask> entPostTasks = new ArrayList<>();
List<OaTaskTime> taskTimes = this.getTaskTime(entPostList.getStandard());
Integer year = Calendar.getInstance().get(Calendar.YEAR);
Integer index = 1;
for (OaTaskTime taskTime : taskTimes){
EntPostTask ept = new EntPostTask();
EntUser entUser = entUserMapper.selectById(entUserId);
String subject = year+"年第"+index+"月工作任务:"+entPostList.getFrequency();
ept.setItemTitle(subject);
ept.setItemContent(entPostList.getItemContent());
ept.setFrequency(entPostList.getFrequency());
ept.setTaskState(1);
ept.setEnterpriseId(entPostList.getEnterpriseId());
ept.setPostId(entPostList.getPostId());
ept.setEntUserId(entPostList.getEntUserId());
ept.setListId(entPostList.getListId());
ept.setPostListId(entPostList.getPostListId());
ept.setEntListId(entPostList.getPostListId());
ept.setTaskId(RandomNumber.getUUid());
Date start = DateUtils.parseString2Date(taskTime.getStartTime(),Constants.DATA);
Date end = DateUtils.parseString2Date(taskTime.getEndTime(),Constants.DATA);
ept.setStartTime(start);
ept.setEntTime(end);
ept.setDelState(DelState.NOT_DEL.getState());
setCreateByAndModify(ept,entUser);
ept.setCreateTime(new Date());
ept.setModifyTime(new Date());
entPostTasks.add(ept);
index++;
}
return entPostTasks;
}
/**
* 获取任务时间段
* @param checkstandard
* @return
* @throws Exception
*/
private List<OaTaskTime> getTaskTime(Integer checkstandard)throws Exception{
List<OaTaskTime> oaTaskTimes = new LinkedList<>();
List<Integer> months = new ArrayList<>();
Integer year = Calendar.getInstance().get(Calendar.YEAR);
if(2 == checkstandard){
months.add(1);
months.add(7);
for (Integer month : months){
Integer endMonth = month + 5;
Integer day = DateUtils.getMonthLastDay(year,endMonth);
OaTaskTime oaTaskTime = new OaTaskTime();
oaTaskTime.setStartTime(year+"-0"+month+"-01 00:00:01");
if(endMonth < 10){
oaTaskTime.setEndTime(year+"-0"+endMonth+"-"+day+" 23:59:59");
}else{
oaTaskTime.setEndTime(year+"-"+endMonth+"-"+day+" 23:59:59");
}
oaTaskTimes.add(oaTaskTime);
}
}else if(4 == checkstandard){
months.add(1);
months.add(4);
months.add(7);
months.add(10);
for (Integer month : months){
Integer entMonth = month + 2;
Integer day = DateUtils.getMonthLastDay(year,entMonth);
OaTaskTime oaTaskTime = new OaTaskTime();
String startMonthStr = "";
String endMonthStr = "";
if(month < 10){
startMonthStr = "0"+month;
}else{
startMonthStr = ""+month;
}
if(entMonth < 10){
endMonthStr = "0"+entMonth;
}else{
endMonthStr = entMonth+"";
}
oaTaskTime.setStartTime(year+"-"+startMonthStr+"-01 00:00:01");
oaTaskTime.setEndTime(year+"-"+endMonthStr+"-"+day+" 23:59:59");
oaTaskTimes.add(oaTaskTime);
}
}else if(12 == checkstandard){
months.add(1);
months.add(2);
months.add(3);
months.add(4);
months.add(5);
months.add(6);
months.add(7);
months.add(8);
months.add(9);
months.add(10);
months.add(11);
months.add(12);
for (Integer month : months){
Integer day = DateUtils.getMonthLastDay(year,month);
OaTaskTime oaTaskTime = new OaTaskTime();
String startMonthStr = "";
if(month < 10){
startMonthStr = "0"+month;
}else{
startMonthStr = ""+month;
}
oaTaskTime.setStartTime(year+"-"+startMonthStr+"-01 00:00:01");
oaTaskTime.setEndTime(year+"-"+startMonthStr+"-"+day+" 23:59:59");
oaTaskTimes.add(oaTaskTime);
}
}
return oaTaskTimes;
}
private void setCreateByAndModify(EntPostTask entPostTask,EntUser entUser){
if (null == entUser){
entPostTask.setCreateBy("系统导入");
entPostTask.setModifyBy("系统导入");
}else {
entPostTask.setCreateBy(entUser.getName());
entPostTask.setModifyBy(entUser.getName());
}
}
}