zouyu
2023-11-14 a7a6f62fdcfde8bad76e39b0afc5615461bc1583
mes-plan/src/main/java/com/chinaztt/mes/plan/service/impl/CustomerOrderServiceImpl.java
@@ -26,7 +26,6 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaztt.ifs.api.feign.IfsFeignClient;
import com.chinaztt.mes.basic.entity.Part;
import com.chinaztt.mes.basic.entity.Staff;
import com.chinaztt.mes.basic.mapper.PartMapper;
import com.chinaztt.mes.basic.mapper.StaffMapper;
import com.chinaztt.mes.basic.util.RedisUtils;
@@ -37,7 +36,6 @@
import com.chinaztt.mes.common.oa.OAResult;
import com.chinaztt.mes.common.util.StateResult;
import com.chinaztt.mes.common.util.WechatMsgTips;
import com.chinaztt.mes.common.util.WxCpUtils;
import com.chinaztt.mes.common.wechat.WechatProperty;
import com.chinaztt.mes.plan.dto.*;
import com.chinaztt.mes.plan.entity.*;
@@ -83,7 +81,6 @@
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.messaging.Message;
@@ -103,14 +100,12 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
 * 客户订单表
@@ -673,26 +668,27 @@
         if (StringUtils.isBlank(selectTime)) {
            return R.failed("缺少查询时间");
         }
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime startDate = LocalDateTime.parse(selectTime, formatter);
         Long days = LocalDate.now().toEpochDay() - startDate.toLocalDate().toEpochDay();
         if (days > 30) {
            return R.failed("超出查询时间范围");
         }
         //DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         //LocalDateTime startDate = LocalDateTime.parse(selectTime, formatter);
         //Long days = LocalDate.now().toEpochDay() - startDate.toLocalDate().toEpochDay();
         //if (days > 30) {
         //   return R.failed("超出查询时间范围");
         //}
         String token = customerOrderUtil.getToken();
         if (pathCode.equals("0")) {
            return addCustomerFromOtc(selectTime, token);
         } else if (pathCode.equals("1")) {
            return addCustomerFromOtcForJointStockCompany(selectTime, token);
         } else {
            throw new RuntimeException("路径请求码 = 【" + pathCode + "】非法");
         }
         //if (pathCode.equals("0")) {
         //   return addCustomerFromOtc(selectTime, token);
         //} else if (pathCode.equals("1")) {
         //   return addCustomerFromOtcForJointStockCompany(selectTime, token);
         //} else {
         //   throw new RuntimeException("路径请求码 = 【" + pathCode + "】非法");
         //}
         return addCustomerFromOtc(selectTime, token);
      } catch (Exception e) {
         return R.failed(e.getMessage());
      }
   }
   /**
    * 添加主表信息
@@ -707,10 +703,13 @@
         if (StringUtils.isNotBlank(selectTime)) {
            map.put("selectTime", selectTime);
         }
         String str = HttpRequest.get(customerOrderClientConfigure.getOtcHost() + customerOrderClientConfigure.getOtcCusomerUrl())
         String str = HttpRequest.get(customerOrderClientConfigure.getOtcHost() + customerOrderClientConfigure.getOtcCustomerUrl())
               .contentType("application/json")
               .header("Authorization", "Bearer " + token).form(map).execute().body();
         JSONObject result = JSONObject.parseObject(str);
         //JSONArray jsonArray = result.getJSONArray("data");
         //jsonArray.forEach();
         //return null;
         //主表参数表
         List<OrderParam> orderParams = orderParamService.list();
         if (result.getInteger("code") == 0) {
@@ -725,6 +724,12 @@
               String otcMainStatus = customerJSONObject.getString("status");
               //所属公司
               String affiliatedCompany = customerJSONObject.getString("affiliatedCompany");
               //所属工厂
               String affiliatedContract=customerJSONObject.getString("affiliatedContract");
               //只拉取所属公司为中天海洋系统有限公司的数据
               if (!"中天材料厂".equals(affiliatedContract)){
                  continue;
               }
               // 不在这几个状态中的数据就跳过
               if (!Arrays.asList(CustomerOrderStateStringValues.GETOTCSTATE).contains(otcMainStatus)) {
                  continue;
@@ -734,15 +739,15 @@
                  customer = new Customer();
               }
               //如果OTC中主表状态是取消那就跳过或者删除已经同步的数据
               if (otcMainStatus.equals("已取消")) {
               if ("已取消".equals(otcMainStatus)) {
                  if (customer.getId() != null) {
                     customerMapper.deleteById(customer.getId());
                     baseMapper.delete(Wrappers.<CustomerOrder>lambdaQuery().eq(CustomerOrder::getCustomerId, customer.getId()));
                  }
                  continue;
               }
               if (null == affiliatedCompany || !Arrays.asList("已审核", "已下达").contains(otcMainStatus) || affiliatedCompany.equals("江苏中天科技股份有限公司")) {
                  continue;//只获取OTC中已审核及已下达的订单,且所属公司不是中天科技
               if (!"已下达".equals(otcMainStatus)) {//null == affiliatedCompany || !Arrays.asList("已下达").contains(otcMainStatus) /*|| affiliatedCompany.equals("江苏中天科技股份有限公司")*/) {
                  continue;//只获取OTC中已审核及已下达的订单,
               }
               //客户编号
               customer.setCustomerNo(customerJSONObject.getString("customerNo"));
@@ -799,6 +804,112 @@
      }
   }
   ///**
   // * 添加主表信息
   // *
   // * @param selectTime 时间
   // * @param token      token
   // * @return
   // */
   //private R addCustomerFromOtc(String selectTime, String token) {
   //   try {
   //      Map<String, Object> map = new HashMap<>();
   //      if (StringUtils.isNotBlank(selectTime)) {
   //         map.put("selectTime", selectTime);
   //      }
   //      String str = HttpRequest.get(customerOrderClientConfigure.getOtcHost() + customerOrderClientConfigure.getOtcCusomerUrl())
   //            .contentType("application/json")
   //            .header("Authorization", "Bearer " + token).form(map).execute().body();
   //      JSONObject result = JSONObject.parseObject(str);
   //      //主表参数表
   //      List<OrderParam> orderParams = orderParamService.list();
   //      if (result.getInteger("code") == 0) {
   //         int num = 0;
   //         int detailNum = 0;
   //         JSONArray jsonArray = result.getJSONArray("data");
   //         for (Object obj : jsonArray) {
   //            JSONObject customerJSONObject = JSONObject.parseObject(obj.toString());
   //            //合同编号
   //            String contractNo = customerJSONObject.getString("orderNo");
   //            //主表在OTC中的状态
   //            String otcMainStatus = customerJSONObject.getString("status");
   //            //所属公司
   //            String affiliatedCompany = customerJSONObject.getString("affiliatedCompany");
   //            // 不在这几个状态中的数据就跳过
   //            if (!Arrays.asList(CustomerOrderStateStringValues.GETOTCSTATE).contains(otcMainStatus)) {
   //               continue;
   //            }
   //            Customer customer = customerMapper.selectOne(Wrappers.<Customer>lambdaQuery().eq(Customer::getContractNo, contractNo));
   //            if (customer == null) {
   //               customer = new Customer();
   //            }
   //            //如果OTC中主表状态是取消那就跳过或者删除已经同步的数据
   //            if (otcMainStatus.equals("已取消")) {
   //               if (customer.getId() != null) {
   //                  customerMapper.deleteById(customer.getId());
   //                  baseMapper.delete(Wrappers.<CustomerOrder>lambdaQuery().eq(CustomerOrder::getCustomerId, customer.getId()));
   //               }
   //               continue;
   //            }
   //            if (null == affiliatedCompany || !Arrays.asList("已审核", "已下达").contains(otcMainStatus) || affiliatedCompany.equals("江苏中天科技股份有限公司")) {
   //               continue;//只获取OTC中已审核及已下达的订单,且所属公司不是中天科技
   //            }
   //            //客户编号
   //            customer.setCustomerNo(customerJSONObject.getString("customerNo"));
   //            //合同号
   //            customer.setContractNo(contractNo);
   //            //客户合同号
   //            customer.setCustomerContractNo(customerJSONObject.getString("customerContractNumber"));
   //            //客户名称
   //            customer.setCustomerName(customerJSONObject.getString("customerName"));
   //            //工程名称
   //            customer.setEntityName(customerJSONObject.getString("projectName"));
   //            //交货日期
   //            customer.setDeliveryDate(customerJSONObject.get("wantedDeliveryDate") != null ?
   //                  customerJSONObject.getDate("wantedDeliveryDate").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() : null);
   //            //事业部
   //            customer.setSalesDepartment(customerJSONObject.getString("division"));
   //            //省份
   //            customer.setProvince(customerJSONObject.getString("province"));
   //            //业务员名称
   //            customer.setSalesMan(customerJSONObject.getString("salesmanName"));
   //            //业务员编号
   //            customer.setSalerWorkCode(customerJSONObject.getString("salesmanNo"));
   //            //正本状态
   //            customer.setOriginalContractStatus(customerJSONObject.getString("originalStatus"));
   //            //合同正本状态
   //            customer.setReturnStatus(customerJSONObject.getString("returnStatus"));
   //            //项目性质
   //            customer.setIsCp(customerJSONObject.getString("natureOfProjectExecution"));
   //            //下单日期
   //            customer.setPlaceOrderDate(customerJSONObject.getDate("orderDate").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
   //            //审核日期
   //            customer.setVerifyDate(customerJSONObject.get("reviewTime") != null ?
   //                  customerJSONObject.getDate("reviewTime").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() : null);
   //            //工厂下单日期
   //            customer.setFactoryPlaceOrderDate(customerJSONObject.get("factoryOrderDate") != null ?
   //                  customerJSONObject.getDate("factoryOrderDate").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() : null);
   //            //备注
   //            customer.setComment(customerJSONObject.getString("comment"));
   //            if (customer.getId() == null) {
   //               customerMapper.insert(customer);
   //            } else {
   //               customerMapper.updateById(customer);
   //            }
   //            num += 1;
   //
   //            detailNum += addCustomerOrderFromOtc(customerJSONObject, customer, token, orderParams, otcMainStatus);
   //         }
   //         return R.ok().setMsg("同步或更新合同主体" + num + "条,合同明细" + detailNum + "条!");
   //      } else {
   //         return R.failed("订单主体获取失败");
   //      }
   //   } catch (Exception e) {
   //      throw new RuntimeException(e.getMessage());
   //   }
   //}
   //
   /**
    * 添加子表信息
@@ -1832,7 +1943,7 @@
         if (StringUtils.isNotBlank(selectTime)) {
            map.put("selectTime", selectTime);
         }
         String str = HttpRequest.get(customerOrderClientConfigure.getOtcHost() + customerOrderClientConfigure.getOtcCusomerUrl())
         String str = HttpRequest.get(customerOrderClientConfigure.getOtcHost() + customerOrderClientConfigure.getOtcCustomerUrl())
               .contentType("application/json")
               .header("Authorization", "Bearer " + token).form(map).execute().body();
         JSONObject result = JSONObject.parseObject(str);