|
@@ -7,7 +7,6 @@ import com.management.platform.entity.vo.TisTimeVO;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.*;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
@@ -20,7 +19,6 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -30,44 +28,45 @@ import java.util.stream.Collectors;
|
|
|
@EnableScheduling
|
|
|
@Component
|
|
|
public class DataCollectTask {
|
|
|
-
|
|
|
+ public static final String PREFIX_URL = "http://58.210.104.138:10020";
|
|
|
+ public static final int HONGHU_COMP_ID = 7536;
|
|
|
@Value("${configEnv.isDev}")
|
|
|
public boolean isDev;
|
|
|
//是否是私有化部署
|
|
|
@Value("${configEnv.isPrivateDeploy}")
|
|
|
boolean isPrivateDeploy;
|
|
|
@Resource
|
|
|
- private UserFvTimeMapper userFvTimeMapper;
|
|
|
- @Resource
|
|
|
- private BusinessTripMapper businessTripMapper;
|
|
|
+ private LeaveSheetService leaveSheetService;
|
|
|
@Resource
|
|
|
- private LeaveSheetMapper leaveSheetMapper;
|
|
|
+ private BusinessTripService businessTripService;
|
|
|
|
|
|
- @Resource
|
|
|
- private ErpOrderInfoMapper erpOrderInfoMapper;
|
|
|
@Resource
|
|
|
private ErpOrderInfoService erpOrderInfoService;
|
|
|
|
|
|
@Resource
|
|
|
- private ProjectMapper projectMapper;
|
|
|
- @Resource
|
|
|
- private UserSalaryService userSalaryService;
|
|
|
+ private GroupTemplateMapper groupTemplateMapper;
|
|
|
|
|
|
@Resource
|
|
|
- private ProjectCategoryMapper projectCategoryMapper;
|
|
|
+ private GroupTmpstagesMapper groupTmpstagesMapper;
|
|
|
|
|
|
- public static final String PREFIX_URL = "http://58.210.104.138:10020";
|
|
|
+ @Resource
|
|
|
+ private StagesService stagesService;
|
|
|
|
|
|
- private static final int specialCompanyId = 7536;
|
|
|
+ @Resource
|
|
|
+ private GtemplateTaskMapper gtemplateTaskMapper;
|
|
|
+ @Resource
|
|
|
+ private TaskGroupMapper taskGroupMapper;
|
|
|
|
|
|
@Resource
|
|
|
- private UserMapper userMapper;
|
|
|
+ private TaskService taskService;
|
|
|
@Resource
|
|
|
- private BustripProjectMapper bustripProjectMapper;
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
|
|
|
@Resource
|
|
|
- private ReportMapper reportMapper;
|
|
|
+ private ProjectCategoryMapper projectCategoryMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
@Resource
|
|
|
private FmwDetailMapper fmwDetailMapper;
|
|
|
@Resource
|
|
@@ -75,81 +74,10 @@ public class DataCollectTask {
|
|
|
@Resource
|
|
|
private CompanyMapper companyMapper;
|
|
|
@Autowired
|
|
|
- private LeaveSheetService leaveSheetService;
|
|
|
- @Autowired
|
|
|
private UserFvTimeService userFvTimeService;
|
|
|
|
|
|
|
|
|
- @Scheduled(cron = "0 30 0 28-31 * ?")
|
|
|
- @Async
|
|
|
- public void caDayTisTask(){
|
|
|
- if(isDev){return;}
|
|
|
- if(isPrivateDeploy) return;
|
|
|
- LocalDate nowDate = LocalDate.now();
|
|
|
- int today = nowDate.getMonthValue();
|
|
|
- int lastDay = Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
- if(today != lastDay){
|
|
|
- return ;
|
|
|
- }
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- String insertUrl = PREFIX_URL+"/dataCollect/insertCisData";
|
|
|
- String checkUrl = PREFIX_URL+"/dataCollect/checkCisData";
|
|
|
-// SimpleDateFormat sdfYmd = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- SimpleDateFormat sdfYm = new SimpleDateFormat("yyyy-MM");
|
|
|
- Date date = new Date();
|
|
|
- String dateYm = sdfYm.format(date);
|
|
|
-
|
|
|
- List<FinanceMonthlyWorktime> financeMonthlyWorktimes = financeMonthlyWorktimeMapper.selectList(new LambdaQueryWrapper<FinanceMonthlyWorktime>()
|
|
|
- .eq(FinanceMonthlyWorktime::getCompanyId, specialCompanyId)
|
|
|
- .eq(FinanceMonthlyWorktime::getYmonth, dateYm)
|
|
|
- .eq(FinanceMonthlyWorktime::getStatus, 1)
|
|
|
- );
|
|
|
- if(!CollectionUtils.isEmpty(financeMonthlyWorktimes)){
|
|
|
- List<TisTimeVO> toSendList = new ArrayList<>();
|
|
|
- for (FinanceMonthlyWorktime financeMonthlyWorktime : financeMonthlyWorktimes) {
|
|
|
- String ymd = financeMonthlyWorktime.getTimesheetDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
- List<TisTimeVO> timeVOList = fmwDetailMapper.getTisTime(financeMonthlyWorktime.getId());
|
|
|
- if(!CollectionUtils.isEmpty(timeVOList)){
|
|
|
- timeVOList.forEach(t->t.setDateStr(ymd));
|
|
|
- toSendList.addAll(timeVOList);
|
|
|
- }
|
|
|
- }
|
|
|
- if(!CollectionUtils.isEmpty(toSendList)){
|
|
|
- //校验cppid
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- Map<String, Object> requestBody = new HashMap<>();
|
|
|
- requestBody.put("toSendList", toSendList);
|
|
|
- HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
- ResponseEntity<List<TisTimeVO>> checkResponse = restTemplate.exchange(checkUrl, HttpMethod.POST, requestEntity
|
|
|
- ,new ParameterizedTypeReference<List<TisTimeVO>>(){});
|
|
|
- if (checkResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- List<TisTimeVO> resList = checkResponse.getBody();
|
|
|
- List<TisTimeVO> tmpCheck = resList.stream().filter(t -> null != t.getCoId()).collect(Collectors.toList());
|
|
|
- if(tmpCheck.size() == resList.size()){
|
|
|
- //执行插入操作
|
|
|
- HttpHeaders insertHeaders = new HttpHeaders();
|
|
|
- insertHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- Map<String, Object> insertBody = new HashMap<>();
|
|
|
- insertBody.put("tisList", resList);
|
|
|
- HttpEntity<Object> insertEntity = new HttpEntity<>(insertBody, insertHeaders);
|
|
|
- ResponseEntity<String> tisResponse = restTemplate.exchange(insertUrl, HttpMethod.POST, insertEntity, String.class);
|
|
|
- if (tisResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- System.out.println("插入成功");
|
|
|
- }else{
|
|
|
- System.out.println("插入失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
|
|
-// @Scheduled(cron = "10 43 17 * * ?")
|
|
|
@Async
|
|
|
public void sqlServerTask() {
|
|
|
if(isDev){return;}
|
|
@@ -158,7 +86,6 @@ public class DataCollectTask {
|
|
|
}
|
|
|
|
|
|
@Scheduled(cron = "0 38 2 * * ?")
|
|
|
-//@Scheduled(cron = "20 58 14 * * ?")
|
|
|
public void workDayTask(){
|
|
|
if(isDev){return;}
|
|
|
if(isPrivateDeploy) return;
|
|
@@ -167,186 +94,25 @@ public class DataCollectTask {
|
|
|
LocalDate endDate = now.minusDays(1);
|
|
|
LocalDate startDate = now.minusDays(8);
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- userFvTimeService.syncUserFvTime(specialCompanyId, null, formatter.format(startDate),formatter.format(endDate));
|
|
|
+ userFvTimeService.syncUserFvTime(HONGHU_COMP_ID, null, formatter.format(startDate),formatter.format(endDate));
|
|
|
}
|
|
|
|
|
|
@Scheduled(cron = "0 28 2 * * ?")
|
|
|
-//@Scheduled(cron = "30 35 15 * * ?")
|
|
|
@Async
|
|
|
public void leaveSheetTask(){
|
|
|
if(isDev){return;}
|
|
|
if(isPrivateDeploy) return;
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- String sumUrl = PREFIX_URL + "/dataCollect/getLeaveSheetDataSum";
|
|
|
- String listUrl = PREFIX_URL + "/dataCollect/getLeaveSheetDataList";
|
|
|
-
|
|
|
- try {
|
|
|
- ResponseEntity<String> sumResponse = restTemplate.exchange(
|
|
|
- sumUrl,
|
|
|
- HttpMethod.GET,
|
|
|
- null,
|
|
|
- String.class
|
|
|
- );
|
|
|
- Integer totalNum = 0;
|
|
|
- if (sumResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- totalNum = Integer.parseInt(sumResponse.getBody());
|
|
|
- } else {
|
|
|
- System.out.println("请求失败,状态码: " + sumResponse.getStatusCode());
|
|
|
- }
|
|
|
- if(totalNum > 0){
|
|
|
- int pageSize = 1000;
|
|
|
- int offset = 0;
|
|
|
- List<LeaveSheet> toAddList = new ArrayList<>();
|
|
|
- List<LeaveSheet> toUpdateList = new ArrayList<>();
|
|
|
- List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, specialCompanyId));
|
|
|
- Map<String, User> userMap = users.stream().filter(t -> StringUtils.isNotBlank(t.getJobNumber()))
|
|
|
- .collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
- while (offset < totalNum) {
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- Map<String, Object> requestBody = new HashMap<>();
|
|
|
- requestBody.put("pageNo", offset);
|
|
|
- requestBody.put("pageSize", pageSize);
|
|
|
- HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
- ResponseEntity<List<LeaveSheet>> listResponse = restTemplate.exchange(
|
|
|
- listUrl,
|
|
|
- HttpMethod.POST,
|
|
|
- requestEntity,
|
|
|
- new ParameterizedTypeReference<List<LeaveSheet>>(){}
|
|
|
- );
|
|
|
- if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- List<LeaveSheet> dataList = listResponse.getBody();
|
|
|
- if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
- for (LeaveSheet leaveSheet : dataList) {
|
|
|
- User ownerTmp = userMap.get(leaveSheet.getOwnerId());
|
|
|
- User opTmp = userMap.get(leaveSheet.getOperatorId());
|
|
|
- leaveSheet.setOwnerId(null==ownerTmp?null:ownerTmp.getId());
|
|
|
- leaveSheet.setOperatorId(null==opTmp?null:opTmp.getId());
|
|
|
- if(null != ownerTmp && null != opTmp){
|
|
|
- leaveSheet.setOperatorId(ownerTmp.getId());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- List<LeaveSheet> realDataList = dataList.stream().filter(t -> StringUtils.isNotBlank(t.getOwnerId())).collect(Collectors.toList());
|
|
|
- if(!CollectionUtils.isEmpty(realDataList)){
|
|
|
- List<String> collect = realDataList.stream().map(LeaveSheet::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
- List<LeaveSheet> existLeaveSheetList = leaveSheetMapper.selectList(new LambdaQueryWrapper<LeaveSheet>().in(LeaveSheet::getProcinstId, collect).eq(LeaveSheet::getCompanyId, specialCompanyId));
|
|
|
-// List<String> existIds = existLeaveSheetList.stream().map(LeaveSheet::getProcinstId).collect(Collectors.toList());
|
|
|
-// List<String> existIds = leaveSheetMapper.getExistIds(collect,specialCompanyId);
|
|
|
- for (LeaveSheet tmp : realDataList) {
|
|
|
- Optional<LeaveSheet> first = existLeaveSheetList.stream().filter(t -> t.getProcinstId().equals(tmp.getProcinstId())).findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- tmp.setId(first.get().getId());
|
|
|
- toUpdateList.add(tmp);
|
|
|
- } else {
|
|
|
- toAddList.add(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
- leaveSheetMapper.batchInsert(toAddList);
|
|
|
- }
|
|
|
- if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
- leaveSheetService.updateBatchById(toUpdateList);
|
|
|
- }
|
|
|
- //自动生成审核通过的请假工时日报
|
|
|
- for (LeaveSheet tmp : realDataList) {
|
|
|
- //获取某人每天请假的时长合计
|
|
|
- String ownerId = tmp.getOwnerId();
|
|
|
- User owner = userMapper.selectById(ownerId);
|
|
|
- //停用的/不需要填写日报的用户不生成日报
|
|
|
- if (owner.getIsActive() == 0 || owner.getReportStatus() == 1) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- Project project = projectMapper.selectOne(new QueryWrapper<Project>().eq("project_code", "HH-QJ-0000001").eq("company_id", specialCompanyId));
|
|
|
- TaskGroup leaveGroup = taskGroupMapper.selectOne(new LambdaQueryWrapper<TaskGroup>().eq(TaskGroup::getProjectId, project.getId()).eq(TaskGroup::getName, "请假工时"));
|
|
|
- for (LocalDate date = tmp.getStartDate(); date.compareTo(tmp.getEndDate()) <= 0; date = date.plusDays(1)) {
|
|
|
- //先计算每一天的请假工时数合计
|
|
|
- List<LeaveSheet> leaveSheetList = leaveSheetMapper.selectList(new LambdaQueryWrapper<LeaveSheet>()
|
|
|
- .eq(LeaveSheet::getOwnerId, ownerId)
|
|
|
- .eq(LeaveSheet::getCompanyId, specialCompanyId)
|
|
|
- .le(LeaveSheet::getStartDate, date).ge(LeaveSheet::getEndDate, date));
|
|
|
- if (!CollectionUtils.isEmpty(leaveSheetList)) {
|
|
|
- double leaveHours = leaveSheetList.stream().mapToDouble(LeaveSheet::getTimeHours).sum();
|
|
|
- if (leaveHours > 0) {
|
|
|
- //跨天请假的
|
|
|
- if (leaveHours > 8.0) {
|
|
|
- leaveHours = 8.0;
|
|
|
- }
|
|
|
- //检查当天是否已经生成了请假工时的日报
|
|
|
- List<Report> reportList = reportMapper.selectList(new QueryWrapper<Report>().eq("company_id", specialCompanyId).eq("project_id", project.getId()).eq("create_date", date).eq("creator_id", ownerId));
|
|
|
- //取第一条
|
|
|
- Report oneReport = reportList.size() > 0?reportList.get(0):new Report();
|
|
|
- if (oneReport.getId() != null) {
|
|
|
- if (!oneReport.getWorkingTime().equals(leaveHours)) {
|
|
|
- //更新时长
|
|
|
- reportMapper.updateById(new Report().setId(oneReport.getId()).setWorkingTime(leaveHours));
|
|
|
- }
|
|
|
- } else {
|
|
|
- //生成请假工时的日报
|
|
|
- Report report = new Report();
|
|
|
- report.setProjectId(project.getId());
|
|
|
- report.setGroupId(leaveGroup.getId());
|
|
|
- report.setReportTimeType(1);
|
|
|
- report.setMultiWorktime(0);
|
|
|
- report.setContent("请假");
|
|
|
- report.setState(1);//自动生成的审核通过
|
|
|
- report.setCompanyId(specialCompanyId);
|
|
|
- report.setStage("-");
|
|
|
- report.setCreateDate(date);
|
|
|
- report.setCreatorId(ownerId);
|
|
|
- report.setDeptId(owner.getDepartmentId());
|
|
|
- report.setProjectAuditState(0);
|
|
|
- report.setWorkingTime(leaveHours);
|
|
|
-
|
|
|
- LocalDate now = LocalDate.now();
|
|
|
- DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- BigDecimal hourCost = null;
|
|
|
- if (owner.getCostApplyDate() != null) {
|
|
|
- //检查有效期
|
|
|
- if (owner.getCostApplyDate().compareTo(dtf.format(now)) > 0) {
|
|
|
- //取上一个历史成本
|
|
|
- List<UserSalary> list = userSalaryService.list(new QueryWrapper<UserSalary>().eq("user_id", owner.getId()).orderByDesc("indate").last("limit 2"));
|
|
|
- if (list.size() > 1) {
|
|
|
- hourCost = list.get(1).getCost();
|
|
|
- } else {
|
|
|
- //没有记录,又没有达到预设的起效时间,则默认为0
|
|
|
- hourCost = new BigDecimal(0);
|
|
|
- }
|
|
|
- } else {
|
|
|
- hourCost = owner.getCost();
|
|
|
- }
|
|
|
- } else {
|
|
|
- hourCost = owner.getCost();
|
|
|
- }
|
|
|
- if (hourCost == null) {
|
|
|
- hourCost = new BigDecimal(0);
|
|
|
- }
|
|
|
- //计算工时和成本
|
|
|
- report.setCost(hourCost.multiply(new BigDecimal(leaveHours)));
|
|
|
- reportMapper.insert(report);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- toUpdateList.clear();
|
|
|
- toAddList.clear();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- offset += pageSize;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("请求发生异常: " + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ leaveSheetService.syncHongHuLeaveSheet(null,null,HONGHU_COMP_ID);
|
|
|
}
|
|
|
|
|
|
+ @Scheduled(cron = "0 0 3 * * ?")
|
|
|
+ @Async
|
|
|
+ public void businessTripTask(){
|
|
|
+ if(isDev){return;}
|
|
|
+ if(isPrivateDeploy) return;
|
|
|
+ businessTripService.syncHongHuData(HONGHU_COMP_ID);
|
|
|
+ }
|
|
|
@Scheduled(cron = "0 30 3 * * ?")
|
|
|
-//@Scheduled(cron = "0 12 16 * * ?")
|
|
|
@Async
|
|
|
public void sqlServerProjectTask() {
|
|
|
if(isDev){return;}
|
|
@@ -354,7 +120,7 @@ public class DataCollectTask {
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
String sumUrl = PREFIX_URL+"/dataCollect/getSqlServerProjectDataSum";
|
|
|
String listUrl = PREFIX_URL+"/dataCollect/getSqlServerProjectDataList";
|
|
|
- Company company = companyMapper.selectById(specialCompanyId);
|
|
|
+ Company company = companyMapper.selectById(HONGHU_COMP_ID);
|
|
|
try {
|
|
|
ResponseEntity<String> sumResponse = restTemplate.exchange(
|
|
|
sumUrl,
|
|
@@ -390,7 +156,7 @@ public class DataCollectTask {
|
|
|
List<Project> dataList = listResponse.getBody();
|
|
|
if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
List<String> collect = dataList.stream().map(Project::getProjectCode).distinct().collect(Collectors.toList());
|
|
|
- List<String> existIds = projectMapper.getExistIds(collect,specialCompanyId);
|
|
|
+ List<String> existIds = projectMapper.getExistIds(collect, HONGHU_COMP_ID);
|
|
|
if(!CollectionUtils.isEmpty(existIds)){
|
|
|
toUpdateList.addAll(dataList.stream().filter(t -> existIds.contains(t.getProjectCode())).collect(Collectors.toList()));
|
|
|
toAddList.addAll(dataList.stream().filter(t -> !existIds.contains(t.getProjectCode())).collect(Collectors.toList()));
|
|
@@ -403,7 +169,7 @@ public class DataCollectTask {
|
|
|
String categoryName = project.getProjectCode().substring(0,5);
|
|
|
project.setCategoryName(categoryName);
|
|
|
ProjectCategory category = projectCategoryMapper.selectOne(new LambdaQueryWrapper<ProjectCategory>()
|
|
|
- .eq(ProjectCategory::getCompanyId, specialCompanyId)
|
|
|
+ .eq(ProjectCategory::getCompanyId, HONGHU_COMP_ID)
|
|
|
.eq(ProjectCategory::getName, project.getCategoryName())
|
|
|
.last(" limit 1 ")
|
|
|
);
|
|
@@ -413,7 +179,7 @@ public class DataCollectTask {
|
|
|
}else{
|
|
|
ProjectCategory tmp = new ProjectCategory();
|
|
|
tmp.setName(project.getCategoryName());
|
|
|
- tmp.setCompanyId(specialCompanyId);
|
|
|
+ tmp.setCompanyId(HONGHU_COMP_ID);
|
|
|
projectCategoryMapper.insert(tmp);
|
|
|
categoryId = tmp.getId();
|
|
|
}
|
|
@@ -421,12 +187,10 @@ public class DataCollectTask {
|
|
|
project.setCategory(categoryId);
|
|
|
projectMapper.insert(project);
|
|
|
if (company.getPackageProject() == 1) {
|
|
|
- initGroup(specialCompanyId,project.getId());
|
|
|
+ initGroup(HONGHU_COMP_ID,project.getId());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-// projectMapper.batchInsert(toAddList);
|
|
|
}
|
|
|
if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
for (Project orderInfo : toUpdateList) {
|
|
@@ -447,22 +211,6 @@ public class DataCollectTask {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Resource
|
|
|
- private GroupTemplateMapper groupTemplateMapper;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private GroupTmpstagesMapper groupTmpstagesMapper;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private StagesService stagesService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private GtemplateTaskMapper gtemplateTaskMapper;
|
|
|
- @Resource
|
|
|
- private TaskGroupMapper taskGroupMapper;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private TaskService taskService;
|
|
|
|
|
|
public void initGroup(Integer companyId, Integer projectId) {
|
|
|
User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
|
|
@@ -520,153 +268,71 @@ public class DataCollectTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Scheduled(cron = "0 0 3 * * ?")
|
|
|
-//@Scheduled(cron = "30 34 14 * * ?")
|
|
|
+ /**
|
|
|
+ * 发送工时数据到财务系统
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 30 0 28-31 * ?")
|
|
|
@Async
|
|
|
- public void businessTripTask(){
|
|
|
+ public void caDayTisTask(){
|
|
|
if(isDev){return;}
|
|
|
if(isPrivateDeploy) return;
|
|
|
+ LocalDate nowDate = LocalDate.now();
|
|
|
+ int today = nowDate.getMonthValue();
|
|
|
+ int lastDay = Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
+ if(today != lastDay){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
- String sumUrl = PREFIX_URL+"/dataCollect/getBusinessTripDataSum";
|
|
|
- String listUrl = PREFIX_URL+"/dataCollect/getBusinessTripDataList";
|
|
|
+ String insertUrl = PREFIX_URL+"/dataCollect/insertCisData";
|
|
|
+ String checkUrl = PREFIX_URL+"/dataCollect/checkCisData";
|
|
|
+ SimpleDateFormat sdfYm = new SimpleDateFormat("yyyy-MM");
|
|
|
+ Date date = new Date();
|
|
|
+ String dateYm = sdfYm.format(date);
|
|
|
|
|
|
- try {
|
|
|
- ResponseEntity<String> sumResponse = restTemplate.exchange(
|
|
|
- sumUrl,
|
|
|
- HttpMethod.GET,
|
|
|
- null,
|
|
|
- String.class
|
|
|
- );
|
|
|
- Integer totalNum = 0;
|
|
|
- if (sumResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- totalNum = Integer.parseInt(sumResponse.getBody());
|
|
|
- } else {
|
|
|
- System.out.println("请求失败,状态码: " + sumResponse.getStatusCode());
|
|
|
+ List<FinanceMonthlyWorktime> financeMonthlyWorktimes = financeMonthlyWorktimeMapper.selectList(new LambdaQueryWrapper<FinanceMonthlyWorktime>()
|
|
|
+ .eq(FinanceMonthlyWorktime::getCompanyId, HONGHU_COMP_ID)
|
|
|
+ .eq(FinanceMonthlyWorktime::getYmonth, dateYm)
|
|
|
+ .eq(FinanceMonthlyWorktime::getStatus, 1)
|
|
|
+ );
|
|
|
+ if(!CollectionUtils.isEmpty(financeMonthlyWorktimes)){
|
|
|
+ List<TisTimeVO> toSendList = new ArrayList<>();
|
|
|
+ for (FinanceMonthlyWorktime financeMonthlyWorktime : financeMonthlyWorktimes) {
|
|
|
+ String ymd = financeMonthlyWorktime.getTimesheetDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ List<TisTimeVO> timeVOList = fmwDetailMapper.getTisTime(financeMonthlyWorktime.getId());
|
|
|
+ if(!CollectionUtils.isEmpty(timeVOList)){
|
|
|
+ timeVOList.forEach(t->t.setDateStr(ymd));
|
|
|
+ toSendList.addAll(timeVOList);
|
|
|
+ }
|
|
|
}
|
|
|
- System.out.println("出差数据:"+totalNum);
|
|
|
- if(totalNum > 0){
|
|
|
- int pageSize = 1000;
|
|
|
- int offset = 0;
|
|
|
- List<BusinessTrip> toAddList = new ArrayList<>();
|
|
|
- List<BusinessTrip> toUpdateList = new ArrayList<>();
|
|
|
- List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, specialCompanyId));
|
|
|
- Map<String, User> userMap = users.stream().filter(t -> StringUtils.isNotBlank(t.getJobNumber()))
|
|
|
- .collect(Collectors.toMap(User::getJobNumber, t -> t));
|
|
|
- List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getCompanyId, specialCompanyId));
|
|
|
- Map<String, Project> projectCodeMap = projects.stream().collect(Collectors.toMap(Project::getProjectCode, t -> t));
|
|
|
- while (offset < totalNum) {
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- Map<String, Object> requestBody = new HashMap<>();
|
|
|
- requestBody.put("pageNo", offset);
|
|
|
- requestBody.put("pageSize", pageSize);
|
|
|
- HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
- ResponseEntity<List<BusinessTrip>> listResponse = restTemplate.exchange(
|
|
|
- listUrl,
|
|
|
- HttpMethod.POST,
|
|
|
- requestEntity,
|
|
|
- new ParameterizedTypeReference<List<BusinessTrip>>(){}
|
|
|
- );
|
|
|
- if (listResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
- List<BusinessTrip> dataList = listResponse.getBody();
|
|
|
- if(org.apache.commons.collections.CollectionUtils.isNotEmpty(dataList)){
|
|
|
- for (BusinessTrip businessTrip : dataList) {
|
|
|
- User ownerTmp = userMap.get(businessTrip.getOwnerId());
|
|
|
- businessTrip.setOwnerId(null==ownerTmp?null:ownerTmp.getId());
|
|
|
- }
|
|
|
- List<BusinessTrip> realDataList = dataList.stream().filter(t -> StringUtils.isNotBlank(t.getOwnerId())).collect(Collectors.toList());
|
|
|
- if(!CollectionUtils.isEmpty(realDataList)){
|
|
|
- List<String> collect = realDataList.stream().map(BusinessTrip::getProcinstId).distinct().collect(Collectors.toList());
|
|
|
- List<BusinessTrip> existBTripList = businessTripMapper.selectList(new QueryWrapper<BusinessTrip>().in("procinst_id", collect));
|
|
|
- for (BusinessTrip businessTrip : realDataList) {
|
|
|
- if (existBTripList.stream().anyMatch(t -> t.getProcinstId().equals(businessTrip.getProcinstId()))) {
|
|
|
- businessTrip.setId(existBTripList.stream().filter(t -> t.getProcinstId().equals(businessTrip.getProcinstId())).findFirst().get().getId());
|
|
|
- toUpdateList.add(businessTrip);
|
|
|
- } else {
|
|
|
- toAddList.add(businessTrip);
|
|
|
- }
|
|
|
- }
|
|
|
- if(!CollectionUtils.isEmpty(toAddList)){
|
|
|
- for (BusinessTrip businessTrip : toAddList) {
|
|
|
- businessTripMapper.insert(businessTrip);
|
|
|
- if (!StringUtils.isEmpty(businessTrip.getCCcxmNo())) {
|
|
|
- String[] split = businessTrip.getCCcxmNo().split(",");
|
|
|
- for (String s : split) {
|
|
|
- Project project = projectCodeMap.get(s);
|
|
|
- if (project != null) {
|
|
|
- BustripProject bustripProject = new BustripProject();
|
|
|
- bustripProject.setBustripId(businessTrip.getId());
|
|
|
- bustripProject.setProjectId(project.getId());
|
|
|
- bustripProject.setStartDate(businessTrip.getStartDate());
|
|
|
- bustripProject.setEndDate(businessTrip.getEndDate());
|
|
|
- bustripProjectMapper.insert(bustripProject);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(!CollectionUtils.isEmpty(toUpdateList)){
|
|
|
- for (BusinessTrip tmp : toUpdateList) {
|
|
|
- businessTripMapper.updateById(tmp);
|
|
|
- //检查出差项目
|
|
|
- if (!StringUtils.isEmpty(tmp.getCCcxmNo())) {
|
|
|
- String[] split = tmp.getCCcxmNo().split(",");
|
|
|
- for (String s : split) {
|
|
|
- Project project = projectCodeMap.get(s);
|
|
|
- if (project != null) {
|
|
|
- //查找是否已经存在
|
|
|
- BustripProject existBustripProject = bustripProjectMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<BustripProject>().eq(BustripProject::getBustripId, tmp.getId()).eq(BustripProject::getProjectId, project.getId()).between(BustripProject::getStartDate, tmp.getStartDate(), tmp.getEndDate()));
|
|
|
- if (existBustripProject == null) {
|
|
|
- BustripProject bustripProject = new BustripProject();
|
|
|
- bustripProject.setBustripId(tmp.getId());
|
|
|
- bustripProject.setProjectId(project.getId());
|
|
|
- bustripProject.setStartDate(tmp.getStartDate());
|
|
|
- bustripProject.setEndDate(tmp.getEndDate());
|
|
|
- bustripProjectMapper.insert(bustripProject);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //自动生成考勤数据
|
|
|
- for (BusinessTrip trip : realDataList) {
|
|
|
- LocalDate startDate = trip.getStartDate();
|
|
|
- LocalDate endDate = trip.getEndDate();
|
|
|
- while (!startDate.isAfter(endDate)) {
|
|
|
- //检查是否已经有当天的考勤
|
|
|
- int cnt = userFvTimeMapper.selectCount(new QueryWrapper<UserFvTime>().eq("work_date", startDate).eq("user_id", trip.getOwnerId()));
|
|
|
- if (cnt == 0) {
|
|
|
- UserFvTime time = new UserFvTime();
|
|
|
- time.setUserId(trip.getOwnerId());
|
|
|
- time.setWorkDate(startDate);
|
|
|
- time.setStartTime("09:00");
|
|
|
- time.setEndTime("18:00");
|
|
|
- time.setWorkHours(8.0f);
|
|
|
- time.setCompanyId(trip.getCompanyId());
|
|
|
- time.setProcinstId("bustrip_"+UUID.randomUUID().toString().replace("-",""));
|
|
|
- userFvTimeMapper.insert(time);
|
|
|
- }
|
|
|
- startDate = startDate.plusDays(1);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- toUpdateList.clear();
|
|
|
- toAddList.clear();
|
|
|
- } else {
|
|
|
- System.out.println("出差数据为空");
|
|
|
+ if(!CollectionUtils.isEmpty(toSendList)){
|
|
|
+ //校验cppid
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ Map<String, Object> requestBody = new HashMap<>();
|
|
|
+ requestBody.put("toSendList", toSendList);
|
|
|
+ HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
+ ResponseEntity<List<TisTimeVO>> checkResponse = restTemplate.exchange(checkUrl, HttpMethod.POST, requestEntity
|
|
|
+ ,new ParameterizedTypeReference<List<TisTimeVO>>(){});
|
|
|
+ if (checkResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ List<TisTimeVO> resList = checkResponse.getBody();
|
|
|
+ List<TisTimeVO> tmpCheck = resList.stream().filter(t -> null != t.getCoId()).collect(Collectors.toList());
|
|
|
+ if(tmpCheck.size() == resList.size()){
|
|
|
+ //执行插入操作
|
|
|
+ HttpHeaders insertHeaders = new HttpHeaders();
|
|
|
+ insertHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ Map<String, Object> insertBody = new HashMap<>();
|
|
|
+ insertBody.put("tisList", resList);
|
|
|
+ HttpEntity<Object> insertEntity = new HttpEntity<>(insertBody, insertHeaders);
|
|
|
+ ResponseEntity<String> tisResponse = restTemplate.exchange(insertUrl, HttpMethod.POST, insertEntity, String.class);
|
|
|
+ if (tisResponse.getStatusCode() == HttpStatus.OK) {
|
|
|
+ System.out.println("插入成功");
|
|
|
+ }else{
|
|
|
+ System.out.println("插入失败");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- offset += pageSize;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("请求发生异常: " + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|