|
@@ -0,0 +1,220 @@
|
|
|
+package com.galaxis.manatee.service;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.galaxis.manatee.dao.ChuanyunSelfWorkHourDao;
|
|
|
+import com.galaxis.manatee.dao.ChuanyunUserCompanyDao;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunMemberHourDO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunSelfWorkHourDO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunUserCompanyDO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.ChuanyunSaveDTO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.ChuanyunSelfWorkHourDTO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.Filter;
|
|
|
+import com.galaxis.manatee.exception.BigSizeException;
|
|
|
+import com.galaxis.manatee.manager.ChuanYunManager;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.RandomStringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 快速更新数据方法
|
|
|
+ * @author zcj
|
|
|
+ * @version 0.1
|
|
|
+ * @date 2021/3/6 5:55 上午
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class DataArcherService {
|
|
|
+
|
|
|
+ private final ChuanYunManager chuanYunManager;
|
|
|
+ private final ChuanyunSelfWorkHourDao chuanyunSelfWorkHourDao;
|
|
|
+ private final ChuanyunUserCompanyDao chuanyunUserCompanyDao;
|
|
|
+
|
|
|
+ public DataArcherService(ChuanYunManager chuanYunManager, ChuanyunSelfWorkHourDao chuanyunSelfWorkHourDao, ChuanyunUserCompanyDao chuanyunUserCompanyDao) {
|
|
|
+ this.chuanYunManager = chuanYunManager;
|
|
|
+ this.chuanyunSelfWorkHourDao = chuanyunSelfWorkHourDao;
|
|
|
+ this.chuanyunUserCompanyDao = chuanyunUserCompanyDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新所有日工时
|
|
|
+ */
|
|
|
+ public void updateAllChuanyunSelfWorkHour(){
|
|
|
+ long startTime = Instant.now().getEpochSecond();
|
|
|
+ var pageSize = 20;
|
|
|
+ var page = 0;
|
|
|
+ while (true){
|
|
|
+ var pageable = PageRequest.of(page, pageSize);
|
|
|
+ var updateList = chuanyunSelfWorkHourDao.findAll(pageable);
|
|
|
+ if (page <= updateList.getTotalPages()) {
|
|
|
+ page += 1;
|
|
|
+ this.updateChuanyunSelfWorkHourList(updateList.toList());
|
|
|
+ }else{
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("更新所有每日工时花费"+(Instant.now().getEpochSecond()-startTime)+"秒");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新最近一个月的标准每日工时
|
|
|
+ */
|
|
|
+ public void updateRecentChuanyunSelfWorkHour(){
|
|
|
+ long startTime = Instant.now().getEpochSecond();
|
|
|
+ var pageSize = 20;
|
|
|
+ var page = 0;
|
|
|
+ while (true){
|
|
|
+ var pageable = PageRequest.of(page, pageSize);
|
|
|
+ var updateList = chuanyunSelfWorkHourDao.getRecentlyDayHour(pageable);
|
|
|
+ if (page <= updateList.getTotalPages()) {
|
|
|
+ page += 1;
|
|
|
+ this.updateChuanyunSelfWorkHourList(updateList.toList());
|
|
|
+ }else{
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("更新最近一个月每日工时花费"+(Instant.now().getEpochSecond()-startTime)+"秒");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户Id更新氚云每日工时列表
|
|
|
+ * @param userId 用户ID
|
|
|
+ */
|
|
|
+ public void updateChuanyunSelfWorkHourListByUserId(String userId){
|
|
|
+ long startTime = Instant.now().getEpochSecond();
|
|
|
+ List<ChuanyunSelfWorkHourDO> updateList=chuanyunSelfWorkHourDao.findByUserId(userId);
|
|
|
+ this.updateChuanyunSelfWorkHourList(updateList);
|
|
|
+ log.info("用户工时花费"+(Instant.now().getEpochSecond()-startTime)+"秒");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据标准日工时列表更新
|
|
|
+ * @param updateList 更新列表
|
|
|
+ */
|
|
|
+ public void updateChuanyunSelfWorkHourList(List<ChuanyunSelfWorkHourDO> updateList){
|
|
|
+ updateList.forEach(chuanyunSelfWorkHourDO -> {
|
|
|
+ try {
|
|
|
+ //
|
|
|
+ ChuanyunSelfWorkHourDTO chuanyunSelfWorkHourDTO = new ChuanyunSelfWorkHourDTO();
|
|
|
+ BeanUtils.copyProperties(chuanyunSelfWorkHourDO, chuanyunSelfWorkHourDTO);
|
|
|
+ ChuanyunUserCompanyDO chuanyunUserCompanyDO = chuanyunUserCompanyDao.findByUserId(chuanyunSelfWorkHourDO.getUserId());
|
|
|
+ if (chuanyunUserCompanyDO != null) {
|
|
|
+ chuanyunSelfWorkHourDTO.setUserName(chuanyunUserCompanyDO.getUserName());
|
|
|
+ chuanyunSelfWorkHourDTO.setBg(chuanyunUserCompanyDO.getBg());
|
|
|
+ //由于人员所在部门信息可能会表,所以每次更新的时候需要获取人员最新的部门信息
|
|
|
+ chuanyunSelfWorkHourDTO.setDepartmentId(chuanyunUserCompanyDO.getDepartmentId());
|
|
|
+ } else {
|
|
|
+ chuanyunSelfWorkHourDTO.setUserName(chuanyunSelfWorkHourDTO.getUserId());
|
|
|
+ chuanyunSelfWorkHourDTO.setBg("IBG");
|
|
|
+ chuanyunSelfWorkHourDTO.setDepartmentId(chuanyunSelfWorkHourDO.getDepartmentId());
|
|
|
+ }
|
|
|
+ chuanyunSelfWorkHourDTO.setDepartmentName(chuanyunSelfWorkHourDO.getDepartmentName());
|
|
|
+ //更新到氚云
|
|
|
+ updateSelfWorkHour(chuanyunSelfWorkHourDTO);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.warn("更新标准工时异常");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异步更新每日工时
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ protected void updateSelfWorkHour(ChuanyunSelfWorkHourDTO chuanyunSelfWorkHourDTO) {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ try {
|
|
|
+ List<String> matchers = new ArrayList<>();
|
|
|
+ matchers.add("F0000001_2," + chuanyunSelfWorkHourDTO.getProjectId());
|
|
|
+ matchers.add("F0000002_2," + chuanyunSelfWorkHourDTO.getUserId());
|
|
|
+ matchers.add("F0000003_2," + chuanyunSelfWorkHourDTO.getDayLogDate());
|
|
|
+ matchers.add("F0000005_2," + chuanyunSelfWorkHourDTO.getProjectType());
|
|
|
+ var filter = Filter.instance(0, 1, true, "And", matchers);
|
|
|
+ var chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunSelfWorkHourDTO.SCHEMA_CODE, filter);
|
|
|
+ var selfMonthString = objectMapper.writeValueAsString(chuanyunSelfWorkHourDTO);
|
|
|
+ ChuanyunSaveDTO chuanyunSaveDTO;
|
|
|
+ if (chuanyunFindAllResponse.getReturnData() != null) {
|
|
|
+ List<ChuanyunMemberHourDO> result = objectMapper.convertValue(chuanyunFindAllResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ ChuanyunMemberHourDO firstResult = result.get(0);
|
|
|
+ //增加工时不相等再更新每日工时数据的
|
|
|
+ if (0 != firstResult.getStandardWorkHour().compareTo(chuanyunSelfWorkHourDTO.getStandardWorkHour())) {
|
|
|
+ chuanyunSaveDTO = chuanYunManager.update(ChuanyunMemberHourDO.SCHEMA_CODE, firstResult.getObjectId(), selfMonthString);
|
|
|
+ if (!chuanyunSaveDTO.getSuccessful()) {
|
|
|
+ log.warn("更新工时标准化失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ chuanyunSaveDTO = chuanYunManager.save(ChuanyunMemberHourDO.SCHEMA_CODE, selfMonthString, true);
|
|
|
+ if (!chuanyunSaveDTO.getSuccessful()) {
|
|
|
+ log.warn("新增工时标准化失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.warn("更新标准工时异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void loose() throws JsonProcessingException, BigSizeException {
|
|
|
+
|
|
|
+ @Data
|
|
|
+ class ApiTestDTO {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表名
|
|
|
+ */
|
|
|
+ public static final String SCHEMA_CODE = "D001789test_api";
|
|
|
+ @JsonProperty(value = "F0000001")
|
|
|
+ private String a;
|
|
|
+ @JsonProperty(value = "F0000002")
|
|
|
+ private String b;
|
|
|
+ @JsonProperty(value = "F0000003")
|
|
|
+ private String c;
|
|
|
+ @JsonProperty(value = "F0000004")
|
|
|
+ private String d;
|
|
|
+ @JsonProperty(value = "F0000005")
|
|
|
+ private String e;
|
|
|
+ @JsonProperty(value = "F0000006")
|
|
|
+ private String f;
|
|
|
+
|
|
|
+ public ApiTestDTO(String a, String b, String c, String d, String e, String f) {
|
|
|
+ this.a = a;
|
|
|
+ this.b = b;
|
|
|
+ this.c = c;
|
|
|
+ this.d = d;
|
|
|
+ this.e = e;
|
|
|
+ this.f = f;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ long tmpStart = System.currentTimeMillis();
|
|
|
+ ApiTestDTO apiTestDTO = new ApiTestDTO(RandomStringUtils.random(5, true, true),
|
|
|
+ RandomStringUtils.random(5, true, true),
|
|
|
+ RandomStringUtils.random(5, true, true),
|
|
|
+ RandomStringUtils.random(5, true, true),
|
|
|
+ RandomStringUtils.random(5, true, true),
|
|
|
+ RandomStringUtils.random(5, true, true));
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String data = objectMapper.writeValueAsString(apiTestDTO);
|
|
|
+ chuanYunManager.save(ApiTestDTO.SCHEMA_CODE, data, true);
|
|
|
+
|
|
|
+ log.info((System.currentTimeMillis() - tmpStart) + "s");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|