浏览代码

Merge remote-tracking branch 'origin/1.0' into 1.0

WoNiu 4 年之前
父节点
当前提交
6abf334ef3

+ 19 - 4
src/main/java/com/galaxis/manatee/controller/TestController.java

@@ -1,19 +1,26 @@
 package com.galaxis.manatee.controller;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.galaxis.manatee.exception.BigSizeException;
+import com.galaxis.manatee.service.DataArcherService;
 import lombok.Data;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author zcj
  * @version 0.1
  * @date 2020/10/27 11:39 上午
  */
+@Slf4j
 @RestController
 public class TestController {
 
+    private DataArcherService dataArcherService;
+
+    public TestController(DataArcherService dataArcherService) {
+        this.dataArcherService = dataArcherService;
+    }
 
     @GetMapping("/test/helloGet")
     public String testGet(){
@@ -30,4 +37,12 @@ public class TestController {
         private String a;
         private String b;
     }
+
+    @GetMapping("/test/api/gogogo")
+    public void testApi(@RequestParam("userId")String userId) throws JsonProcessingException, BigSizeException {
+        dataArcherService.updateChuanyunSelfWorkHourListByUserId(userId);
+    }
+
 }
+
+

+ 1 - 2
src/main/java/com/galaxis/manatee/controller/WorkHourController.java

@@ -41,9 +41,8 @@ public class WorkHourController {
      * @return  固定字符串
      */
     @GetMapping("/test/workHour/updateWorkHour")
-    public String updateWorkHour(){
+    public void updateWorkHour(){
         workHourStatistics.updateHour();
-        return "go ahead";
     }
 
 

+ 40 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ApiTestDO.java

@@ -0,0 +1,40 @@
+package com.galaxis.manatee.entity.chuanyun.data.object;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.persistence.Entity;
+
+/**
+ * 测试类,用于测试接口传输速度
+ * @author zcj
+ * @version 0.1
+ * @date 2021/3/6 5:24 上午
+ */
+@EqualsAndHashCode(callSuper = true)
+@Slf4j
+@Data
+@Entity(name = "API_TEST")
+public class ApiTestDO extends BasicDO{
+
+
+    /**
+     * 表名
+     */
+    public static final String SCHEMA_CODE ="D001789api_test";
+
+    @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;
+}

+ 85 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/dto/ChuanyunSelfWorkHourDTO.java

@@ -0,0 +1,85 @@
+package com.galaxis.manatee.entity.chuanyun.dto;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.galaxis.manatee.util.ChuanyunLocalDateTimeDeserializer;
+import com.galaxis.manatee.util.ChuanyunLocalDateTimeSerializer;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * 氚云日标准工时更新DTO
+ * @author zcj
+ * @version 0.1
+ * @date 2021/3/6 6:18 上午
+ */
+@Data
+public class ChuanyunSelfWorkHourDTO {
+
+    /**
+     * 表名
+     */
+    public static final String SCHEMA_CODE ="D0017899cae010a8a5741b5be13a1fa7f67330d";
+
+    /**
+     * 用户ID
+     */
+    @JsonProperty("F0000002")
+    private String userId;
+
+    /**
+     * 项目ID
+     */
+    @JsonProperty("F0000001")
+    private String projectId;
+
+    /**
+     * 项目类型
+     */
+    @JsonProperty("F0000005")
+    private String projectType;
+
+    /**
+     * 部门名称
+     */
+    @JsonProperty("F0000009")
+    private String departmentName;
+
+    /**
+     * 流程状态
+     */
+    @JsonProperty("F0000006")
+    private String status;
+
+    /**
+     * 日志日期
+     */
+    @JsonProperty("F0000003")
+    @JsonSerialize(using = ChuanyunLocalDateTimeSerializer.class)
+    @JsonDeserialize(using = ChuanyunLocalDateTimeDeserializer.class)
+    private LocalDateTime dayLogDate;
+
+    @JsonProperty("F0000004")
+    private BigDecimal standardWorkHour;
+
+    /**
+     * 部门Id
+     */
+    @JsonProperty("F0000007")
+    private String departmentId;
+
+    /**
+     * 用户名称
+     */
+    @JsonProperty("F0000008")
+    private String userName;
+
+    /**
+     * 所属BG
+     */
+    @JsonProperty("F0000010")
+    private String bg;
+}

+ 220 - 0
src/main/java/com/galaxis/manatee/service/DataArcherService.java

@@ -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");
+
+    }
+
+}