WS
2023-05-26 080d77ad29c431969dd34a90f3c0ec1c8b682f13
src/main/java/com/fzzy/push/shjdjw2023/ShjdjwApiRemoteService2023.java
@@ -1,6 +1,7 @@
package com.fzzy.push.shjdjw2023;
import com.alibaba.fastjson.JSON;
import com.bstek.dorado.util.DateUtils;
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiParam;
import com.fzzy.api.data.PushProtocol;
@@ -20,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DateFormat;
import java.util.*;
/**
@@ -53,6 +55,9 @@
    private Api1104Rep api1104Rep;
    @Autowired
    private Api1208Rep api1208Rep;
    @Autowired
    private Api1404Rep api1404Rep;
    @Override
    public String getProtocol() {
@@ -113,6 +118,29 @@
            resd.setSuccess(responseDto.getCode() == 1 ? 0 : responseDto.getCode());
            resd.setMsg(responseDto.getDescription());
            if (Constant.API_CODE_1403.equals(inteId)) {
                //轮换计划完成情况数据封装
                Shjdjw1502 shjdjw1502 = copy1502((Api1403) data);
                ShjdjwReqDto<Object> dto = new ShjdjwReqDto<>();
                dto.setId(getDataId(ShjdjwApiCodeConstant.API_CODE_LS1502));
                List<Object> list = new ArrayList<>();
                list.add(shjdjw1502);
                dto.setData(list);
                String json = JSON.toJSONString(dto);
                //轮换计划完成情况数据上传
                apiLog.setData(json);
                apiLog.setKqdm(kqdm);
                apiLog.setUploadTime(new Date());
                ShjdjwRespDto shjdjwresponseDto = Shjdjw2023HttpClientUtil.postPushData(conf.getApiUrl(), json, conf);
                responseDto.setBizId(bizId);
                apiLog.setStatus(shjdjwresponseDto.getCode() == 1 ? 0 : shjdjwresponseDto.getCode());
                apiLog.setResult(shjdjwresponseDto.getDescription());
                apiLogRep.save(apiLog);
                ResponseDto response = new ResponseDto();
                response.setSuccess(shjdjwresponseDto.getCode() == 1 ? 0 : shjdjwresponseDto.getCode());
                response.setMsg(shjdjwresponseDto.getDescription());
            }
            return resd;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
@@ -193,19 +221,9 @@
            list.add(shjdjwApi1310);
        } else if (Constant.API_CODE_1403.equals(inteId)) {
            //轮换计划数据封装
            ShjdjwApi1403 shjdjwApi1403 = new ShjdjwApi1403();
            Api1403 api1403 = (Api1403) data;
            BeanUtils.copyProperties(api1403, shjdjwApi1403);
            shjdjwApi1403.setJhbm(api1403.getLhjhdh());
            shjdjwApi1403.setPch("0");
            ShjdjwApi1403 shjdjwApi1403 = copyApi1403((Api1403) data);
            list.add(shjdjwApi1403);
        } else if (Constant.API_CODE_1404.equals(inteId)) {
            //轮换计划完成情况数据封装
            ShjdjwApi1404 shjdjwApi1404 = copyApi1404((Api1404) data);
            list.add(shjdjwApi1404);
        } else {
            list.add(data);
@@ -214,25 +232,74 @@
        return JSON.toJSONString(dto);
    }
    private ShjdjwApi1404 copyApi1404(Api1404 api1404) {
        ShjdjwApi1404 shjdjwApi1404 = new ShjdjwApi1404();
    private ShjdjwApi1403 copyApi1403(Api1403 api1403) {
        ShjdjwApi1403 shjdjwApi1403 = new ShjdjwApi1403();
        BeanUtils.copyProperties(api1403, shjdjwApi1403);
        BeanUtils.copyProperties(api1404, shjdjwApi1404);
        //查询单位信息
        List<Api1101> listApi1101 = api1101Rep.findPushData(api1404.getKqdm());
        if (null != listApi1101 && listApi1101.size() > 0) {
            shjdjwApi1404.setDwmc(listApi1101.get(0).getDwmc());
        List<Double> lhsl = getLhsl(api1403);
        if (null != lhsl && lhsl.size() > 0) {
            shjdjwApi1403.setLrsl(lhsl.get(1));
            shjdjwApi1403.setLrsl(lhsl.get(0));
        }
        //TODO 计划年度 计划数量 已执行数量 执行比例 招标/竞价比例
        shjdjwApi1404.setJhnd("0");
        shjdjwApi1404.setJhsl("0");
        shjdjwApi1404.setYzxsl("0");
        shjdjwApi1404.setZxbl("0");
        shjdjwApi1404.setZbjjbl("0");
        shjdjwApi1403.setJhbm(api1403.getLhjhdh());
        shjdjwApi1403.setPch("0");
        return shjdjwApi1403;
    }
        return shjdjwApi1404;
    /**
     * 获取轮入和轮出重量
     *
     * @param api1403
     * @return
     */
    private List<Double> getLhsl(Api1403 api1403) {
        List<Api1404> api1404List = api1404Rep.getDataByLhjhdh(api1403.getLhjhdh());
        List<Double> lhsl = new ArrayList<>();
        if (null != api1404List && api1404List.size() > 0) {
//            double sum = api1404List.stream().mapToDouble(Api1404::getLhsl).summaryStatistics().getSum();
            double lcSum = api1404List.stream()
                    .filter(x -> x.getLhlx().equals("1"))
                    .mapToDouble(Api1404::getLhsl)
                    .summaryStatistics().getSum();
            double lrSum = api1404List.stream()
                    .filter(x -> x.getLhlx().equals("2"))
                    .mapToDouble(Api1404::getLhsl)
                    .summaryStatistics().getSum();
            lhsl.add(lcSum);
            lhsl.add(lrSum);
        }
        return lhsl;
    }
    private Shjdjw1502 copy1502(Api1403 api1403) {
        Shjdjw1502 shjdjw1502 = new Shjdjw1502();
        shjdjw1502.setDwmc(api1403.getLhjhdh());
        shjdjw1502.setJhnd(api1403.getJhnd());
        // 计划数量
        List<Double> lhsl = getLhsl(api1403);
        Double sum = 0.0;
        if (null != lhsl && lhsl.size() > 0) {
            sum = lhsl.stream().reduce(0d, Double::sum);
        }
        // 已执行数量
        List<Api1202> api1202List = api1202Rep.getDataByTime(api1403.getKszxrq(), api1403.getJzzxrq());
//                DateUtils.format("yyyy-MM-dd HH:mm:ss", api1403.getKszxrq()),
//                DateUtils.format("yyyy-MM-dd HH:mm:ss", api1403.getJzzxrq()));
        Double yzxsl = api1202List.stream()
                .mapToDouble(Api1202::getJz)
                .summaryStatistics().getSum();
        shjdjw1502.setJhsl(sum.toString());
        shjdjw1502.setYzxsl(yzxsl.toString());
        //执行比例
        shjdjw1502.setZxbl(String.valueOf((yzxsl / sum * 100)));
        // 招标/竞价比例
        shjdjw1502.setZbjjbl("100");
        shjdjw1502.setCzbz(api1403.getCzbz());
        return shjdjw1502;
    }
    private ShjdjwApi1203 copyApi1203(Api1203 api1203) {
@@ -260,7 +327,7 @@
        shjdjwApi1310.setPznm(api1310.getLspzdm());
        shjdjwApi1310.setSkdjbm(api1310.getLsdjdm());
        shjdjwApi1310.setJylbbm(api1310.getJylb());
        if(StringUtils.isNotEmpty(shjdjwApi1310.getJyxm())){
        if (StringUtils.isNotEmpty(shjdjwApi1310.getJyxm())) {
            String[] split = shjdjwApi1310.getJyxm().split(",");
            StringBuilder jyjl = new StringBuilder();
            for (String s : split) {
@@ -437,9 +504,6 @@
            case "1403":
                //轮换计划接口编码
                return ShjdjwApiCodeConstant.API_CODE_LS1501;
            case "1404":
                //轮换计划完成情况接口编码
                return ShjdjwApiCodeConstant.API_CODE_LS1502;
            default:
                return inteId;
        }