| | |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.framework.config.AliDingConfig; |
| | | import com.ruoyi.productionPlan.dto.ProductionPlanDto; |
| | | import com.ruoyi.productionPlan.dto.ProductionPlanSummaryDto; |
| | | import com.ruoyi.productionPlan.mapper.ProductionPlanMapper; |
| | | import com.ruoyi.productionPlan.pojo.ProductionPlan; |
| | | import com.ruoyi.productionPlan.service.ProductionPlanService; |
| | |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <br> |
| | |
| | | List<ProductionPlan> list = parseProductionPlans(dataArr, dataSyncType, totalCount); |
| | | if (!list.isEmpty()) { |
| | | // 处理更新或新增 |
| | | processSaveOrUpdate(list); |
| | | totalSynced += list.size(); |
| | | int affected = processSaveOrUpdate(list); |
| | | totalSynced += affected; |
| | | } |
| | | |
| | | // 判断是否还有下一页 |
| | |
| | | return list; |
| | | } |
| | | |
| | | private void processSaveOrUpdate(List<ProductionPlan> list) { |
| | | private int processSaveOrUpdate(List<ProductionPlan> list) { |
| | | if (list == null || list.isEmpty()) { |
| | | return 0; |
| | | } |
| | | int affected = 0; |
| | | |
| | | // 去重 formInstanceId |
| | | Set<String> formIds = list.stream() |
| | | .map(ProductionPlan::getFormInstanceId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | // 查询数据库已有数据 |
| | | List<ProductionPlan> existList = this.list(new LambdaQueryWrapper<ProductionPlan>().in(ProductionPlan::getFormInstanceId, formIds)); |
| | | |
| | | // Map (formInstanceId + materialCode) |
| | | Map<String, ProductionPlan> existMap = new HashMap<>(); |
| | | for (ProductionPlan p : existList) { |
| | | String key = p.getFormInstanceId() + "_" + p.getMaterialCode(); |
| | | existMap.put(key, p); |
| | | } |
| | | |
| | | // 遍历同步数据 |
| | | for (ProductionPlan plan : list) { |
| | | LambdaQueryWrapper<ProductionPlan> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(ProductionPlan::getFormInstanceId, plan.getFormInstanceId()) |
| | | .eq(ProductionPlan::getMaterialCode, plan.getMaterialCode()); |
| | | ProductionPlan existing = this.getOne(queryWrapper); |
| | | if (existing != null) { |
| | | plan.setId(existing.getId()); |
| | | this.updateById(plan); |
| | | } else { |
| | | String key = plan.getFormInstanceId() + "_" + plan.getMaterialCode(); |
| | | ProductionPlan exist = existMap.get(key); |
| | | if (exist == null) { |
| | | // 新增 |
| | | this.save(plan); |
| | | affected++; |
| | | log.info("新增数据 formInstanceId={}, materialCode={}", plan.getFormInstanceId(), plan.getMaterialCode()); |
| | | } else { |
| | | // 判断是否需要更新 |
| | | if (exist.getFormModifiedTime() == null || !exist.getFormModifiedTime().equals(plan.getFormModifiedTime())) { |
| | | plan.setId(exist.getId()); |
| | | plan.setCreateTime(exist.getCreateTime()); |
| | | this.updateById(plan); |
| | | affected++; |
| | | log.info("更新数据 formInstanceId={}, materialCode={}", plan.getFormInstanceId(), plan.getMaterialCode()); |
| | | } |
| | | } |
| | | } |
| | | return affected; |
| | | } |
| | | |
| | | private LocalDateTime parseUtcTime(String utcString) { |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<ProductionPlanSummaryDto> summaryByProductType(ProductionPlanSummaryDto query) { |
| | | return baseMapper.selectSummaryByProductType(query); |
| | | } |
| | | } |