jiangping
2024-12-20 53b6400ec10c8ca61ccec91c82c358d2488eead8
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/thrid/BoardServiceImpl.java
@@ -14,9 +14,12 @@
import com.doumee.core.haikang.model.param.respose.*;
import com.doumee.core.haikang.service.HKCarOpenService;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.tms.model.request.TmsFacrotyCodeListRequest;
import com.doumee.core.tms.model.request.TmsOutQtyAndVehicleQtyRequest;
import com.doumee.core.tms.model.response.TmsDistributionOfDeliveryLocResponse;
import com.doumee.core.tms.model.response.TmsInventoryListResponse;
import com.doumee.core.tms.model.response.TmsOutQtyAndVehicleQtyResponse;
import com.doumee.core.tms.model.response.TmsTotalAndReportVehicleQtyResponse;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
@@ -30,8 +33,8 @@
import com.doumee.dao.web.reqeust.CarsJobAndContractDTO;
import com.doumee.dao.web.response.platformReport.*;
import com.doumee.service.business.impl.PlatformJobServiceImpl;
import com.doumee.service.business.impl.VisitsServiceImpl;
import com.doumee.service.business.third.BoardService;
import com.doumee.service.business.third.TmsService;
import com.doumee.service.business.third.WmsService;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -40,9 +43,7 @@
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@@ -66,6 +67,8 @@
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private TmsFactoryParamMapper tmsFactoryParamMapper;
    @Autowired
    private PlatformWarnEventJoinMapper platformWarnEventJoinMapper;
    @Autowired
    private PlatformJobMapper platformJobMapper;
@@ -83,6 +86,8 @@
    private RetentionMapper retentionMapper;
    @Autowired
    private PlatformGroupMapper platformGroupMapper;
    @Autowired
    private TmsService tmsService;
    /**
     * 获取区域树形结构数据
     * @return
@@ -2036,7 +2041,242 @@
            return null;
        }
    }
    /**
     * 出库能力李永利
     * @return
     */
    @Override
    public WholeProvinceZXTVO outAbilityUseRate(){
        WholeProvinceZXTVO result = new WholeProvinceZXTVO();
        result.setCurrentNum(new BigDecimal(0));
        result.setTotalNum(new BigDecimal(0));
        result.setUseRate(new BigDecimal(0));
        result.setDetailList(new ArrayList<>());
        List<TmsFactoryParam> paramList = factoryList();
        List<WholeProvinceZxtDetailVO> list = new ArrayList<>();
        TmsOutQtyAndVehicleQtyRequest param = new TmsOutQtyAndVehicleQtyRequest();
        if(paramList!=null){
            String startDate = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
            String endDate = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
            for(TmsFactoryParam p : paramList){
                WholeProvinceZxtDetailVO t = new WholeProvinceZxtDetailVO();
                t.setFactoryName(p.getName());
                t.setCurrentNum(new BigDecimal(0));
                t.setUseRate(new BigDecimal(0));
                t.setTotalNum(Constants.formatBigdecimal(p.getNum2()));//总出库能力
                if(StringUtils.isBlank(p.getCode())){
                    param.setFacrotyCodeList(new ArrayList<>());
                    param.setDateStart(startDate);
                    param.setDateEnd(endDate);
                    param.getFacrotyCodeList().add(p.getCode());
                    List<TmsOutQtyAndVehicleQtyResponse> response = tmsService.getOutQtyAndVehicleQty(param);//查询出库量
                    t.setCurrentNum(getCurrentOutQryByList(response));
                    if(t.getTotalNum().compareTo(new BigDecimal(0)) !=0){
                        t.setUseRate(t.getCurrentNum().divide(t.getTotalNum(),4,BigDecimal.ROUND_HALF_UP));
                    }
                }
                result.getDetailList().add(t);
                result.setCurrentNum(result.getCurrentNum().add(t.getCurrentNum()));
                result.setTotalNum(result.getTotalNum().add(t.getTotalNum()));
            }
        }
        if(result.getTotalNum().compareTo(new BigDecimal(0)) !=0){
            result.setUseRate(result.getCurrentNum().divide(result.getTotalNum(),4,BigDecimal.ROUND_HALF_UP));
        }
        return result;
    }
    /**
     * 出库能力李永利
     * @return
     */
    @Override
    public    TotalOutQtyNumVO totalOutQtyNum(){
        TotalOutQtyNumVO  data = new TotalOutQtyNumVO();
        data.setCurrentInYearNum(new BigDecimal(0));
        data.setCurrentInWeekNum(new BigDecimal(0));
        data.setCurrentInMonthNum(new BigDecimal(0));
        data.setLastInYearNum(new BigDecimal(0));
        data.setLastInMonthNum(new BigDecimal(0));
        data.setLastInWeekNum(new BigDecimal(0));
        data.setSameInMonthNum(new BigDecimal(0));
        //---------省外----------------
        data.setCurrentOutYearNum(new BigDecimal(0));
        data.setCurrentOutWeekNum(new BigDecimal(0));
        data.setCurrentOutMonthNum(new BigDecimal(0));
        data.setLastOutYearNum(new BigDecimal(0));
        data.setLastOutMonthNum(new BigDecimal(0));
        data.setLastOutWeekNum(new BigDecimal(0));
        data.setSameOutMonthNum(new BigDecimal(0));
        return data;
    }
    /**
     * 出库能力李永利
     * @return
     */
    @Override
    public    List<WholeProvinceMapVO> mapYearAndMonthOutList(){
        List<WholeProvinceMapVO> result = new ArrayList<>();
        List<TmsFactoryParam> paramList =factoryList();
        if(paramList!=null && paramList.size()>0){
            List<String> codes = new ArrayList<>();
            for(TmsFactoryParam p : paramList){
                if(StringUtils.isBlank(p.getCode())){
                    continue;
                }
                codes.add(p.getCode());
            }
            if(codes.size()>0){
                TmsFacrotyCodeListRequest param = new TmsFacrotyCodeListRequest();
                param.setFacrotyCodeList(codes);
                List<TmsDistributionOfDeliveryLocResponse> response  = tmsService.getDistributionOfDeliveryLocations(param);//查询出库量
                if(response!=null &&response.size()>0){
                    for(TmsDistributionOfDeliveryLocResponse model : response){
                        WholeProvinceMapVO tt = getFromProvinceResultList(model ,result);
                        if(tt == null){
                            tt =new WholeProvinceMapVO();
                            tt.setMonthNum( Constants.formatBigdecimal0Float(model.getMonthOutboundQuantity()));
                            tt.setYearNum( Constants.formatBigdecimal0Float(model.getYearOutboundQuantity()));
                            tt.setProvinceCode(model.getFromProvinceCode());
                            tt.setProvinceName(model.getFromProvinceName());
                            result.add(tt);
                        }
                    }
                }
            }
        }
        return result;
    }
    private WholeProvinceMapVO getFromProvinceResultList(TmsDistributionOfDeliveryLocResponse model, List<WholeProvinceMapVO> result) {
        for(WholeProvinceMapVO t : result){
            if(StringUtils.equals(t.getProvinceCode(), model.getFromProvinceCode())){
                t.setMonthNum(Constants.formatBigdecimal(t.getMonthNum()).add(Constants.formatBigdecimal0Float(model.getMonthOutboundQuantity())));
                t.setYearNum(Constants.formatBigdecimal(t.getYearNum()).add(Constants.formatBigdecimal0Float(model.getYearOutboundQuantity())));
                return   t;
            }
        }
        return  null;
    }
    /**
     * 出库能力李永利
     * @return
     */
    @Override
    public     List<TmsFactoryParam> factoryList(){
        List<TmsFactoryParam> paramList = tmsFactoryParamMapper.selectList(new QueryWrapper<TmsFactoryParam>().lambda()
                .eq(TmsFactoryParam::getIsdeleted,Constants.ZERO)
                .orderByAsc(TmsFactoryParam::getSortnum));
        return paramList;
    }
    /**
     * 出库能力李永利
     * @return
     */
    @Override
    public WholeProvinceZXTVO tranportAbilityUseRate(){
        WholeProvinceZXTVO result = new WholeProvinceZXTVO();
        result.setCurrentNum(new BigDecimal(0));
        result.setTotalNum(new BigDecimal(0));
        result.setUseRate(new BigDecimal(0));
        result.setDetailList(new ArrayList<>());
        List<TmsFactoryParam> paramList =factoryList();
        if(paramList!=null){
            List<TmsTotalAndReportVehicleQtyResponse> response = tmsService.getTotalAndReportVehicleQty();//查询出库量
            for(TmsFactoryParam p : paramList){
                WholeProvinceZxtDetailVO t = new WholeProvinceZxtDetailVO();
                t.setFactoryName(p.getName());
                t.setCurrentNum(new BigDecimal(0));
                t.setTotalNum(Constants.formatBigdecimal(p.getNum1()));//总库存量
                getFromReportVehicleQtyList(p.getCode(),t,response);//处理提报运力和总运力数据
                t.setUseRate(new BigDecimal(0));
                if(t.getTotalNum().compareTo(new BigDecimal(0)) !=0){
                    t.setUseRate(t.getCurrentNum().divide(t.getTotalNum(),4,BigDecimal.ROUND_HALF_UP));
                }
                result.getDetailList().add(t);
                result.setCurrentNum(result.getCurrentNum().add(t.getCurrentNum()));
                result.setTotalNum(result.getTotalNum().add(t.getTotalNum()));
            }
        }
        if(result.getTotalNum().compareTo(new BigDecimal(0)) !=0){
            result.setUseRate(result.getCurrentNum().divide(result.getTotalNum(),4,BigDecimal.ROUND_HALF_UP));
        }
        return result;
    }
    private void getFromReportVehicleQtyList(String code,WholeProvinceZxtDetailVO t, List<TmsTotalAndReportVehicleQtyResponse> responses) {
        BigDecimal current = new BigDecimal(0);
        BigDecimal total= new BigDecimal(0);
        if(responses!=null && responses.size()>0){
            for(TmsTotalAndReportVehicleQtyResponse model: responses){
                if(StringUtils.equals(model.getFactoryCode(),code)){
                    total = total.add(Constants.formatBigdecimal(model.getTotalQty()));
                    current = current.add(Constants.formatBigdecimal(model.getReportQty()));
                }
            }
        }
        t.setCurrentNum(current);
        t.setTotalNum(total);
    }
    private BigDecimal getCurrentOutQryByList(List<TmsOutQtyAndVehicleQtyResponse> response) {
        BigDecimal r = new BigDecimal(0);
        if(response!=null && response.size()>0){
            for(TmsOutQtyAndVehicleQtyResponse model: response){
                    r = r.add(Constants.formatBigdecimal(model.getTotalOutQty()));
            }
        }
        return r ;
    }
    /**
     * 仓库资源利用率
     * @return
     */
    @Override
    public WholeProvinceZXTVO inventoryUseRate(){
        WholeProvinceZXTVO result = new WholeProvinceZXTVO();
        result.setCurrentNum(new BigDecimal(0));
        result.setTotalNum(new BigDecimal(0));
        result.setUseRate(new BigDecimal(0));
        result.setDetailList(new ArrayList<>());
        List<TmsFactoryParam> paramList = factoryList();
        List<TmsInventoryListResponse> responses = tmsService.getRealTimeInventory();
        if(paramList!=null){
            for(TmsFactoryParam p : paramList){
                WholeProvinceZxtDetailVO t = new WholeProvinceZxtDetailVO();
                t.setFactoryName(p.getName());
                t.setCurrentNum(new BigDecimal(0));
                t.setTotalNum(Constants.formatBigdecimal(p.getNum1()));//总库存量
                t.setCurrentNum(getFromInventoryList(p.getCode(),responses));
                t.setUseRate(new BigDecimal(0));
                if(t.getTotalNum().compareTo(new BigDecimal(0)) !=0){
                    t.setUseRate(t.getCurrentNum().divide(t.getTotalNum(),4,BigDecimal.ROUND_HALF_UP));
                }
                result.getDetailList().add(t);
                result.setCurrentNum(result.getCurrentNum().add(t.getCurrentNum()));
                result.setTotalNum(result.getTotalNum().add(t.getTotalNum()));
            }
        }
        if(result.getTotalNum().compareTo(new BigDecimal(0)) !=0){
            result.setUseRate(result.getCurrentNum().divide(result.getTotalNum(),4,BigDecimal.ROUND_HALF_UP));
        }
        return result;
    }
    private BigDecimal getFromInventoryList(String code, List<TmsInventoryListResponse> responses) {
        BigDecimal r = new BigDecimal(0);
        if(responses!=null && responses.size()>0){
            for(TmsInventoryListResponse model: responses){
                if(StringUtils.equals(model.getFactoryCode(),code)){
                   r = r.add(Constants.formatBigdecimal(model.getStockQty()));
                }
            }
        }
        return r ;
    }
}