liujie
2023-08-31 d6811336d546e4963a9af3bd7cd8654d14193bce
src/main/java/com/stylefeng/guns/modular/system/controller/DemandController.java
@@ -10,11 +10,13 @@
import com.stylefeng.guns.modular.system.enums.UserFeeSettingEnum;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.utils.AddressLookup;
import com.stylefeng.guns.modular.system.utils.ChassisRentalDaysUtil;
import com.stylefeng.guns.modular.system.utils.ExcelUtil;
import com.stylefeng.guns.modular.system.utils.GoogleMap.DistancematrixVo;
import com.stylefeng.guns.modular.system.utils.GoogleMap.GeocodeVo;
import com.stylefeng.guns.modular.system.utils.GoogleMap.GoogleMapUtil;
import com.stylefeng.guns.modular.system.utils.UserInfoUtil;
import com.stylefeng.guns.modular.system.utils.PointInPolygon;
import com.stylefeng.guns.modular.system.utils.tips.ErrorTip;
import com.stylefeng.guns.modular.system.utils.tips.SuccessTip;
import io.swagger.annotations.Api;
@@ -24,12 +26,14 @@
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -109,8 +113,9 @@
    })
    @PostMapping(value = "/addDemand")
    @ResponseBody
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public Object addDemand(@RequestBody DemandDto demandDto) throws Exception {
        Integer id = UserInfoUtil.getId();
        Integer id = demandDto.getId();
        String s1 = System.currentTimeMillis() + ToolUtil.getRandomString(5);
        String s2 = System.currentTimeMillis() + ToolUtil.getRandomString(5);
        // 生成需求
@@ -124,310 +129,356 @@
        tQuote.setCreateId(id);
        quoteService.insert(tQuote);
        List<TUserFeeSetting> tUserFeeSettings=null;
        //获取当前用户的sale
        Integer userId = demandDto.getUserId();
        TUser tUser = userService.selectById(userId);
        if(tUser.getGroupId()!=null){
            TGroup tGroup = groupService.selectById(tUser.getGroupId());
             tUserFeeSettings = userFeeSettingService.selectList(new EntityWrapper<TUserFeeSetting>().eq("user_id",tGroup.getSalesId()));
        }
        String accessorialStr = demandDto.getAccessorialStr();
        String[] split = accessorialStr.split(",");
        Map<String,String> map = new HashMap<>(split.length);
        for (String s :split){
            map.put(s,s);
        }
        List<TCompanyService> companyServiceList = new ArrayList<>();
        //
        for (Map.Entry<String, String> entry : map.entrySet()) {
                companyServiceList.addAll(tCompanyServiceService.selectList(new EntityWrapper<TCompanyService>()
                    .eq("service_name", entry.getKey()).ne("service_value", 0)));
        }
        // TODO size 是否包含   收费  收费站、收费基础
        // 根据公司id去重
        List<TCompanyService> companyServices = companyServiceList.stream().collect(Collectors.
                collectingAndThen(Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(TCompanyService::getCompanyId))),ArrayList::new));
        // 拿出符合规则的公司id
        List<Integer> companyIds = companyServices.stream().map(TCompanyService::getCompanyId).collect(Collectors.toList());
        List<TCompany> tCompanyList = new ArrayList<>();
        for (Integer companyId : companyIds) {
            List<TCompanyService> collect = companyServiceList.stream().filter(company -> company.getCompanyId().equals(companyId)).collect(Collectors.toList());
            if(map.size() == collect.size()){
                // 找出符合规则的公司
                TCompany company = tCompanyService.selectOne(new EntityWrapper<TCompany>().eq("status", 1)
                        .eq("id",companyId));
                if(Objects.nonNull(company)){
                    tCompanyList.add(company);
                }
            }
        }
        // 符合规则的公司id集合
        List<Integer> companyIdList = tCompanyList.stream().map(TCompany::getId).collect(Collectors.toList());
        HashSet<Integer> set = new HashSet<>();
        // 找出目前公司是否符合添加的码头
        // 看当前码头是否为特殊码头
        // 找出当前码头所在的cityid
//
//        // 找出目前公司是否符合添加的码头
//        // 看当前码头是否为特殊码头
//        // 找出当前码头所在的cityid
        TPort tPort1 = portService.selectById(demandDto.getPortId());
        TCountry tCountry = countryService.selectById(tPort1.getCity());
        List<Integer> integers = Arrays.asList(demandDto.getPortId(), tCountry.getId());
        List<TRates> tRates = ratesService.selectList(new EntityWrapper<TRates>().in("metro_id", integers));
        // 满足码头的公司
        companyIdList.stream().forEach(t->{
            for (TRates tRate : tRates) {
                if(tRate.getCompanyId().equals(t)){
                    set.add(t);
                }
            }
        });
        Integer portId = demandDto.getPortId();
        TPort tPort = itPortService.selectById(portId);
        String address = tPort.getAddress();
//        GeocodeVo geocode = googleMapUtil.getGeocode(address);
        GeocodeVo geocode = googleMapUtil.getGeocode(address);
        List<TCompanyCalculationResp> tCompanyCalculationRespList = new ArrayList<>(tCompanyList.size());
        List<TCompanyCalculationResp> tCompanyCalculationRespList = new ArrayList<>();
//        List<Integer> collect1 = set.stream().filter(e -> e.equals(demandDto.getId())).collect(Collectors.toList());
        // 没有满足公司
        if(CollectionUtils.isEmpty(set)){
            quoteService.deleteById(tQuote.getId());
            return  new ErrorTip(5001,"No truck company was matched to meet the demand");
        }else {
            for (TCompany company : tCompanyList) {
            TCompany company = companyService.selectById(demandDto.getId());
                TCompanyCalculationResp tCompanyCalculationResp = new TCompanyCalculationResp();
                ArrayList<TOrder> tOrders = new ArrayList<>();
                // 超重 价格
                ArrayList<TCompanyResp> objects = new ArrayList<>();
                List<GoodsListDto> list1 = demandDto.getList();
                // 判断是否特殊码头
            List<GoodsListDto> list1 = demandDto.getList();
            // 判断是否特殊码头
                TRates tRates1 = ratesService.selectOne(new EntityWrapper<TRates>().eq("metro_id", demandDto.getPortId()).eq("type", 2).eq("company_id", company.getId()));
                int ratesId=0;
                if(tRates1!=null){
                    ratesId=tRates1.getId();
                }else {
                    ratesId=tCountry.getId();
        if(tRates1!=null){
            ratesId=tRates1.getId();
        }else {
            TRates t = ratesService.selectOne(new EntityWrapper<TRates>().eq("metro_id", tCountry.getId()).eq("type", 1).eq("company_id", company.getId()));
            ratesId=t.getId();
                }
                for (GoodsListDto goodsListDto : list1) {
                    ArrayList<TPrice> tPrices = new ArrayList<>();
                    // 生成订单
                    TOrder tOrder = new TOrder();
                    tOrder.setUserId(demandDto.getUserId());
                    tOrder.setAccessorial(demandDto.getAccessorial());
                    tOrder.setAccessorialStr(demandDto.getAccessorialStr());
                    tOrder.setPort(demandDto.getPortId());
                    tOrder.setShipmentDate(demandDto.getShipmentDate());
                    tOrder.setDeliveryDate(demandDto.getDeliveryDate());
                    tOrder.seteZipZ(s1);
                    tOrder.setCreateTime(new Date());
                    tOrder.setStartLat("1");
                    tOrder.setStartLon("1");
                    tOrder.setDeliveryStr(demandDto.getDelivery());
                    tOrder.setType(demandDto.getType());
                    tOrder.setZipCode(demandDto.getZipCode());
                    tOrder.setWarehouse(demandDto.getWarehouse());
                    tOrder.setStatus("0");
                    tOrder.setInvoiceNumber(s2);
                    tOrder.setCompanyId(company.getId());
                    tOrder.setCreateTime(new Date());
                    orderService.insert(tOrder);
                    tOrders.add(tOrder);
                    List<TGoods> list = goodsListDto.getList();
                    for (TGoods e : list) {
                        e.setShippingLine(goodsListDto.getShippingLine());
                        e.setCustRef(goodsListDto.getCustRef());
                        e.setEntry(goodsListDto.getEntry());
                        e.setOurRef(goodsListDto.getOurRef());
                        e.setPo(goodsListDto.getPo());
                        e.setSb(goodsListDto.getSb());
                        e.setBillNumber(goodsListDto.getBillNumber());
                        TOrder tOrder = new TOrder();
                        tOrder.setUserId(demandDto.getUserId());
                        tOrder.setAccessorial(demandDto.getAccessorial());
                        tOrder.setAccessorialStr(demandDto.getAccessorialStr());
                        tOrder.setPort(demandDto.getPortId());
                        tOrder.setShipmentDate(demandDto.getShipmentDate());
                        tOrder.setDeliveryDate(demandDto.getDeliveryDate());
                        tOrder.seteZipZ(s1);
                        tOrder.setCreateTime(new Date());
                        tOrder.setStartLat(String.valueOf(geocode.getLat()));
                        tOrder.setStartLon(String.valueOf(geocode.getLng()));
                        tOrder.setDeliveryStr(demandDto.getDelivery());
                        tOrder.setType(demandDto.getType());
                        tOrder.setZipCode(demandDto.getZipCode());
                        tOrder.setWarehouse(demandDto.getWarehouse());
                        tOrder.setStatus("0");
                        tOrder.setInvoiceNumber(s2);
                        tOrder.setCompanyId(company.getId());
                        tOrder.setCreateTime(new Date());
                        tOrder.setsName(demandDto.getContactName());
                        tOrder.setsEmail(demandDto.getContactEmail());
                        tOrder.setsPhone(demandDto.getContactPhone());
                        tOrder.seteCompanyName(demandDto.getECompanyName());
                        tOrder.seteName(demandDto.getEContactName());
                        tOrder.seteEmail(demandDto.getEContactEmail());
                        tOrder.setePhone(demandDto.getEContactPhone());
                        if("0".equals(demandDto.getWarehouse())){
                            tOrder.seteAddress(demandDto.getEAddress());
                        }else {
                            TWarehouse tWarehouse = warehouseService.selectOne(new EntityWrapper<TWarehouse>().eq("company_id", company.getId()).eq("code", demandDto.getWarehouse()).eq("port_id",ratesId));
                            tOrder.seteAddress(tWarehouse.getAddress());
                        }
                        tOrder.setOrderType(1);
                        orderService.insert(tOrder);
                        tOrders.add(tOrder);
                        e.setOrderId(tOrder.getId());
                        TCompanyResp tCompanyResp = new TCompanyResp();
                        // 是否超重
                        Integer weight = goodsListDto.getWeight();
                        String arg1 = tPort.getName();
                        String arg2="";
                        if(!"0".equals(demandDto.getWarehouse())){
                            System.out.println("公司id:"+company.getId());
                            System.out.println("公司ratesId:"+ratesId);
                            TWarehouse tWarehouse = warehouseService.selectOne(new EntityWrapper<TWarehouse>().eq("company_id", company.getId()).eq("code", demandDto.getWarehouse()).eq("port_id",ratesId));
                            if(tWarehouse==null){
                                return "Please set the relevant price first";
                            }
                            arg2=tWarehouse.getZipCode();
                        }else {
                            arg2 = demandDto.getZipCode();
                        }
                        System.out.println("arg2:"+arg2);
                        DistancematrixVo distancematrix = googleMapUtil.getDistancematrix(tPort.getAddress(), arg2);
                        String arg3=String.valueOf(distancematrix.getDistance()/1609);
                        String arg4= demandDto.getList().get(0).getShippingLine();
                        String arg5 = demandDto.getType();
                        TGoods goodsDto1 = demandDto.getList().get(0).getList().get(0);
                        String arg6 =goodsDto1.getSize()+"ft";
                        String arg7="None";
                        String arg8 = goodsDto1.getKg();
                        System.out.println("参数:"+arg1+"|"+arg2+"|"+arg3+"|"+arg4+"|"+arg5+"|"+arg6+"|"+arg7+"|"+arg8);
                        BigDecimal days = new BigDecimal(ChassisRentalDaysUtil.chassisRentalDays(1, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)).setScale(0, RoundingMode.HALF_UP);
                        // 相差天数
//                        long between = DateUtil.between(demandDto.getShipmentDate(), demandDto.getDeliveryDate(), DateUnit.DAY);
                    List<GoodsDto> list = goodsListDto.getList();
                    ArrayList<TGoods> tGoods1 = new ArrayList<>();
                    for (GoodsDto goodsDto : list) {
                        TGoods tGoods = new TGoods();
                        tGoods.setShippingLine(goodsListDto.getShippingLine());
                        tGoods.setDanger(goodsListDto.getDanger());
                        tGoods.setKg(goodsDto.getKg());
                        tGoods.setOrderId(tOrder.getId());
                        tGoods.setSize(goodsDto.getSize());
                        tGoods.setType(goodsDto.getType());
                        tGoods.setWeight(goodsListDto.getWeight());
                        tGoods.setTypeClass(goodsDto.getTypeClass());
                        tGoods1.add(tGoods);
                    }
                    goodsService.insertBatch(tGoods1);
                    TCompanyResp tCompanyResp = new TCompanyResp();
                    // 是否超重
                    Integer weight = goodsListDto.getWeight();
                    long between = DateUtil.between(demandDto.getShipmentDate(), demandDto.getDeliveryDate(), DateUnit.DAY);
                    if(between==0){
                        between=1;
                    }
                    if(weight==1){
                        TCompanyFeeSetting feeSetting = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", UserFeeSettingEnum.OVERWEIGHT.getDesc()));
                        tCompanyResp.setName(UserFeeSettingEnum.OVERWEIGHT.getDesc());
                        tCompanyResp.setPrice(feeSetting.getSetValue());
                        objects.add(tCompanyResp);
                        TCompanyFeeSetting feeSetting1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", "trl-axle chassis"));
                        tCompanyResp=new TCompanyResp();
                        tCompanyResp.setName(UserFeeSettingEnum.CHASSIS_FEE.getDesc());
                        tCompanyResp.setPrice(feeSetting1.getSetValue().multiply(new BigDecimal(between)));
                        objects.add(tCompanyResp);
                    }else {
                        tCompanyResp=new TCompanyResp();
                        tCompanyResp.setName(UserFeeSettingEnum.CHASSIS_FEE.getDesc());
                        TCompanyFeeSetting feeSetting = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", "Pool chassis"));
                        tCompanyResp.setPrice(feeSetting.getSetValue().multiply(new BigDecimal(between)));
                        objects.add(tCompanyResp);
                    }
                    // type
                    if ("Live Unload".equals(demandDto.getType())) {
                        // 计算当前公司的价格
                        tCompanyResp=new TCompanyResp();
                        BigDecimal setValue = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", UserFeeSettingEnum.PREPULL.getDesc())).getSetValue();
                        tCompanyResp.setName(UserFeeSettingEnum.PREPULL.getDesc());
                        tCompanyResp.setPrice(setValue);
                        objects.add(tCompanyResp);
                    }
                    // 滞留费
                    tCompanyResp=new TCompanyResp();
                    BigDecimal setValue = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", UserFeeSettingEnum.DETENTION_CONGESTION.getDesc())).getSetValue();
                    tCompanyResp.setName(UserFeeSettingEnum.DETENTION_CONGESTION.getDesc());
                    tCompanyResp.setPrice(setValue);
                    objects.add(tCompanyResp);
                    if(goodsListDto.getDanger()==1){
                        tCompanyResp=new TCompanyResp();
                        BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", UserFeeSettingEnum.HAZMAT.getDesc())).getSetValue();
                        tCompanyResp.setName(UserFeeSettingEnum.HAZMAT.getDesc());
                        tCompanyResp.setPrice(setValue1);
                        objects.add(tCompanyResp);
                    }
                    if(demandDto.getUrgent()==1){
                        tCompanyResp=new TCompanyResp();
                        BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", UserFeeSettingEnum.URGENT_SEE.getDesc())).getSetValue();
                        tCompanyResp.setName(UserFeeSettingEnum.URGENT_SEE.getDesc());
                        tCompanyResp.setPrice(setValue1);
                        objects.add(tCompanyResp);
                    }
                    if(demandDto.getPiperpass()==1){
                        tCompanyResp=new TCompanyResp();
                        BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", UserFeeSettingEnum.PIERPASS.getDesc())).getSetValue();
                        tCompanyResp.setName(UserFeeSettingEnum.PIERPASS.getDesc());
                        tCompanyResp.setPrice(setValue1);
                        objects.add(tCompanyResp);
                    }
                    if(demandDto.getCTF()==1){
                        tCompanyResp=new TCompanyResp();
                        BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", UserFeeSettingEnum.CTF.getDesc())).getSetValue();
                        tCompanyResp.setName(UserFeeSettingEnum.CTF.getDesc());
                        tCompanyResp.setPrice(setValue1);
                        objects.add(tCompanyResp);
                    }
                    if("0".equals(demandDto.getWarehouse())){
                        tCompanyResp=new TCompanyResp();
                        BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("set_name", demandDto.getDelivery())).getSetValue();
                        tCompanyResp.setName(demandDto.getDelivery());
                        tCompanyResp.setPrice(setValue1);
                        objects.add(tCompanyResp);
                        // 基础价格
                        String zipCode = demandDto.getZipCode();
                        TCompanyBasic tCompanyBasic = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("port_id",ratesId).eq("zip_code", zipCode).eq("type", 1));
                        if(Objects.nonNull(tCompanyBasic)){
                        if(weight==1){
                            TCompanyFeeSetting feeSetting = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", UserFeeSettingEnum.OVERWEIGHT.getDesc()));
                            tCompanyResp.setName(UserFeeSettingEnum.OVERWEIGHT.getDesc());
                            if(feeSetting==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting.getSetValue());
                            }
                            objects.add(tCompanyResp);
                            TCompanyFeeSetting feeSetting1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", "trl-axle chassis"));
                            tCompanyResp=new TCompanyResp();
                            tCompanyResp.setPrice(tCompanyBasic.getFee());
                            tCompanyResp.setName("LH+FSC");
                            tCompanyResp.setName(UserFeeSettingEnum.CHASSIS_FEE.getDesc());
                            if(feeSetting1==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting1.getSetValue().multiply(days));
                                tCompanyResp.setDay(days.toString());
                            }
                            objects.add(tCompanyResp);
                        }else {
                            // 画圈 拿到的zipcode集合 去对比当前zipcode是否在集合中
                            TCompanyBasic type = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("type", 2).eq("port_id",ratesId).like("zip_code", zipCode));
                            if(Objects.nonNull(type)){
                            tCompanyResp=new TCompanyResp();
                            tCompanyResp.setName(UserFeeSettingEnum.CHASSIS_FEE.getDesc());
                            TCompanyFeeSetting feeSetting = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", "Pool chassis"));
                            if(feeSetting==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
                                tCompanyResp.setDay(days.toString());
                            }
                            objects.add(tCompanyResp);
                        }
                        // type
                        if ("Live Unload".equals(demandDto.getType())) {
                            // 计算当前公司的价格
                            tCompanyResp=new TCompanyResp();
                            TCompanyFeeSetting feeSetting = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", UserFeeSettingEnum.PREPULL.getDesc()));
                            tCompanyResp.setName(UserFeeSettingEnum.PREPULL.getDesc());
                            if(feeSetting==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting.getSetValue());
                            }
                            objects.add(tCompanyResp);
                        }
                        // 滞留费
                        tCompanyResp=new TCompanyResp();
                        TCompanyFeeSetting feeSetting = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", UserFeeSettingEnum.DETENTION_CONGESTION.getDesc()));
                        tCompanyResp.setName(UserFeeSettingEnum.DETENTION_CONGESTION.getDesc());
                        if(feeSetting==null){
                            tCompanyResp.setPrice(new BigDecimal(0));
                        }else {
                            days = new BigDecimal(ChassisRentalDaysUtil.chassisRentalDays(4, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)).setScale(0, RoundingMode.HALF_UP);
                            tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
                            tCompanyResp.setDay(days.toString());
                        }
                        objects.add(tCompanyResp);
                        // 仓储费
                        tCompanyResp=new TCompanyResp();
                        days = new BigDecimal(ChassisRentalDaysUtil.chassisRentalDays(2, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)).add(new BigDecimal(ChassisRentalDaysUtil.chassisRentalDays(3, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))).setScale(0, RoundingMode.HALF_UP);
                        System.out.println("仓储费"+days);
                        TCompanyFeeSetting storage = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", UserFeeSettingEnum.STORAGE.getDesc()));
                        System.out.println(storage);
                        if(storage!=null){
                            tCompanyResp.setName(UserFeeSettingEnum.STORAGE.getDesc());
                            tCompanyResp.setPrice(storage.getSetValue().multiply(days));
                            tCompanyResp.setDay(days.toString());
                            objects.add(tCompanyResp);
                        }else {
                            tCompanyResp.setName(UserFeeSettingEnum.STORAGE.getDesc());
                            tCompanyResp.setPrice(new BigDecimal(0));
                            objects.add(tCompanyResp);
                        }
                        if(goodsListDto.getDanger()==1){
                            tCompanyResp=new TCompanyResp();
                            TCompanyFeeSetting feeSetting1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", UserFeeSettingEnum.HAZMAT.getDesc()));
                            tCompanyResp.setName(UserFeeSettingEnum.HAZMAT.getDesc());
                            if(feeSetting1==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting1.getSetValue());
                            }
                            objects.add(tCompanyResp);
                        }
                        if(demandDto.getUrgent()==1){
                            tCompanyResp=new TCompanyResp();
                            TCompanyFeeSetting feeSetting1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", UserFeeSettingEnum.URGENT_SEE.getDesc()));
                            tCompanyResp.setName(UserFeeSettingEnum.URGENT_SEE.getDesc());
                            if(feeSetting1==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting1.getSetValue());
                            }
                            objects.add(tCompanyResp);
                        }
                        if(demandDto.getPiperpass()==1){
                            tCompanyResp=new TCompanyResp();
                            TCompanyFeeSetting feeSetting1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", UserFeeSettingEnum.PIERPASS.getDesc()));
                            tCompanyResp.setName(UserFeeSettingEnum.PIERPASS.getDesc());
                            if(feeSetting1==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting1.getSetValue());
                            }
                            objects.add(tCompanyResp);
                        }
                        if(demandDto.getCTF()==1){
                            tCompanyResp=new TCompanyResp();
                            TCompanyFeeSetting feeSetting1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", UserFeeSettingEnum.CTF.getDesc()));
                            tCompanyResp.setName(UserFeeSettingEnum.CTF.getDesc());
                            if(feeSetting1==null){
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }else {
                                tCompanyResp.setPrice(feeSetting1.getSetValue());
                            }
                            objects.add(tCompanyResp);
                        }
                        if("0".equals(demandDto.getWarehouse())){
                            tCompanyResp=new TCompanyResp();
                            TCompanyFeeSetting feeSetting1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", demandDto.getDelivery()));
                            if(feeSetting1!=null){
                                tCompanyResp.setName(demandDto.getDelivery());
                                tCompanyResp.setPrice(feeSetting1.getSetValue());
                            }else {
                                tCompanyResp.setName(demandDto.getDelivery());
                                tCompanyResp.setPrice(new BigDecimal(0));
                            }
                            objects.add(tCompanyResp);
                            // 基础价格
                            String zipCode = demandDto.getZipCode();
                            String address1 = AddressLookup.getAddress(zipCode);
                            TCompanyBasic tCompanyBasic = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("port_id",ratesId).eq("zip_code", zipCode).eq("type", 1));
                            if(Objects.nonNull(tCompanyBasic)){
                                tCompanyResp=new TCompanyResp();
                                tCompanyResp.setPrice(type.getFee());
                                tCompanyResp.setPrice(tCompanyBasic.getFee());
                                tCompanyResp.setName("LH+FSC");
                                objects.add(tCompanyResp);
                            }else {
                                tCompanyResp=new TCompanyResp();
                                // 1条数据  不需要zipcode
                                TCompanyBasic type1 = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("type", 3).eq("port_id",ratesId));
                                DistancematrixVo distancematrix = googleMapUtil.getDistancematrix(address, type1.getAddress());
                                double distance = distancematrix.getDistance().doubleValue();
                                BigDecimal bigDecimal = new BigDecimal(distance * 0.0006214);
                                BigDecimal multiply = type1.getFee().multiply(bigDecimal);
                                tCompanyResp.setPrice(multiply);
                                tCompanyResp.setName("LH+FSC");
                                objects.add(tCompanyResp);
                                // 画圈 拿到的zipcode集合 去对比当前zipcode是否在集合中
                                // 画圈 拿到的zipcode集合 去对比当前zipcode是否在集合中
                                List<TCompanyBasic> type = companyBasicService.selectList(new EntityWrapper<TCompanyBasic>().eq("type", 2).eq("port_id",ratesId).orderBy("fee",true));
                                if(type.size()>0){
                                    GeocodeVo geocode1 = googleMapUtil.getGeocode(zipCode);
                                    for (TCompanyBasic companyBasic : type) {
                                        boolean inPolygon = PointInPolygon.isInPolygon(geocode1.getLat(), geocode1.getLng(), companyBasic.getLonLat());
                                        if(inPolygon){
                                            tCompanyResp=new TCompanyResp();
                                            tCompanyResp.setPrice(companyBasic.getFee());
                                            tCompanyResp.setName("LH+FSC");
                                            objects.add(tCompanyResp);
                                            break;
                                        }
                                    }
                                    if(tCompanyResp==null){
                                        // 距离
                                        tCompanyResp=new TCompanyResp();
                                        // 1条数据  不需要zipcode
                                        DistancematrixVo distancematrix2 = googleMapUtil.getDistancematrix(address, address1);
                                        double distance = distancematrix2.getDistance().doubleValue();
                                        BigDecimal bigDecimal = new BigDecimal(distance * 0.0006214);
                                        List<TCompanyBasic> type1 = companyBasicService.selectList(new EntityWrapper<TCompanyBasic>().eq("type", 3).eq("port_id",ratesId).le("start",bigDecimal.doubleValue()).orderBy("start",true));
                                        if(type1.size()>0) {
                                            BigDecimal multiply = type1.get(0).getFee().multiply(bigDecimal);
                                            tCompanyResp.setPrice(multiply);
                                            tCompanyResp.setName("LH+FSC");
                                            objects.add(tCompanyResp);
                                        }else {
                                            tCompanyResp.setPrice(new BigDecimal(0));
                                            tCompanyResp.setName("LH+FSC");
                                            objects.add(tCompanyResp);
                                        }
                                    }
                                }else {
                                    tCompanyResp=new TCompanyResp();
                                    // 1条数据  不需要zipcode
                                    TCompanyBasic type1 = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("type", 3).eq("port_id",ratesId));
                                    if(type1!=null) {
                                        DistancematrixVo distancematrix1 = googleMapUtil.getDistancematrix(address, type1.getAddress());
                                        double distance = distancematrix1.getDistance().doubleValue();
                                        BigDecimal bigDecimal = new BigDecimal(distance * 0.0006214);
                                        BigDecimal multiply = type1.getFee().multiply(bigDecimal);
                                        tCompanyResp.setPrice(multiply);
                                        tCompanyResp.setName("LH+FSC");
                                        objects.add(tCompanyResp);
                                    }else {
                                        tCompanyResp.setPrice(new BigDecimal(0));
                                        tCompanyResp.setName("LH+FSC");
                                        objects.add(tCompanyResp);
                                    }
                                }
                            }
                        }
                    }else {
                        tCompanyResp=new TCompanyResp();
                        TWarehouse tWarehouse = warehouseService.selectOne(new EntityWrapper<TWarehouse>().eq("company_id", company.getId()).eq("code", demandDto.getWarehouse()).eq("port_id",ratesId));
                        tCompanyResp.setName(UserFeeSettingEnum.LH_FSH.getDesc());
                        if(Objects.nonNull(tWarehouse)){
                            tCompanyResp.setPrice(tWarehouse.getWarePrice());
                        }else {
                            tCompanyResp.setPrice(new BigDecimal("0"));
                            tCompanyResp=new TCompanyResp();
                            TWarehouse tWarehouse = warehouseService.selectOne(new EntityWrapper<TWarehouse>().eq("company_id", company.getId()).eq("code", demandDto.getWarehouse()).eq("port_id",ratesId));
                            tCompanyResp.setName(UserFeeSettingEnum.LH_FSH.getDesc());
                            if(Objects.nonNull(tWarehouse)){
                                tCompanyResp.setPrice(tWarehouse.getWarePrice());
                            }else {
                                tCompanyResp.setPrice(new BigDecimal("0"));
                            }
                            objects.add(tCompanyResp);
                        }
                        objects.add(tCompanyResp);
                    }
                    BigDecimal bigDecimal = objects.stream().map(e -> e.getPrice()).reduce(BigDecimal::add).get();
                    tOrder.setAllTotal(bigDecimal);
                    orderService.updateById(tOrder);
                    objects.stream().forEach(e->e.setOrderId(tOrder.getId()));
                        BigDecimal bigDecimal = objects.stream().map(e1 -> e1.getPrice()).reduce(BigDecimal::add).get();
                        tOrder.setAllTotal(bigDecimal);
                        tOrder.setPayMoney(bigDecimal);
                        orderService.updateById(tOrder);
                        objects.stream().forEach(e2->e2.setOrderId(tOrder.getId()));
                    for (TCompanyResp object : objects) {
                        TPrice tPrice = new TPrice();
                        tPrice.setCreateTime(new Date());
                        tPrice.setOrderId(object.getOrderId());
                        tPrice.setState("1");
                        tPrice.setPrice(object.getPrice());
                        tPrice.setType(object.getName());
                        tPrices.add(tPrice);
                        for (TCompanyResp object : objects) {
                            TPrice tPrice = new TPrice();
                            tPrice.setCreateTime(new Date());
                            tPrice.setOrderId(object.getOrderId());
                            tPrice.setState("1");
                            tPrice.setPrice(object.getPrice());
                            tPrice.setCarPrice(object.getPrice());
                            tPrice.setType(object.getName());
                            tPrice.setDay(object.getDay());
                            tPrices.add(tPrice);
                        }
                        priceService.insertBatch(tPrices);
                    }
                    priceService.insertBatch(tPrices);
                    goodsService.insertBatch(list);
                }
                tCompanyCalculationResp.setOrderList(tOrders);
//                if(CollectionUtil.isNotEmpty(tUserFeeSettings)){
//                    for (TCompanyResp object : objects) {
//                        TPrice tPrice = new TPrice();
//                        tPrice.setCreateTime(new Date());
//                        tPrice.setOrderId(object.getOrderId());
//                        tPrice.setState("1");
//                        tPrice.setPrice(object.getPrice());
//                        tPrice.setType(object.getName());
//                        tPrices.add(tPrice);
//                        for (TUserFeeSetting tUserFeeSetting : tUserFeeSettings) {
//                            if(object.getName().equals(tUserFeeSetting.getName())){
//                                double i = (double)tUserFeeSetting.getFee() / 100;
//                                BigDecimal multiply = object.getPrice().multiply(new BigDecimal(i));
//                            }
//                        }
//                    }
//                }else {
//                    for (TCompanyResp object : objects) {
//                        TPrice tPrice = new TPrice();
//                        tPrice.setCreateTime(new Date());
//                        tPrice.setOrderId(object.getOrderId());
//                        tPrice.setState("1");
//                        tPrice.setPrice(object.getPrice());
//                        tPrice.setType(object.getName());
//                        tPrices.add(tPrice);
//
//                    }
//                }
//                priceService.insertBatch(tPrices);
                tCompanyCalculationResp.setList(objects);
                tCompanyCalculationResp.setCarGoNumber(String.valueOf(company.getMcNumber()));
                tCompanyCalculationResp.setCompanyId(company.getId());
@@ -441,27 +492,24 @@
                // 目的地经纬度
                if("0".equals(demandDto.getWarehouse())){
                if(!"0".equals(demandDto.getWarehouse())){
                    TWarehouse tWarehouse = warehouseService.selectOne(new EntityWrapper<TWarehouse>().eq("company_id", company.getId()).eq("code", demandDto.getWarehouse()).eq("port_id",ratesId));
                    GeocodeVo geocode1 = googleMapUtil.getGeocode(tWarehouse.getAddress());
                    tCompanyCalculationResp.setEndLon(String.valueOf(geocode1.getLng()));
                    tCompanyCalculationResp.setEndLat(String.valueOf(geocode1.getLat()));
                    tCompanyCalculationRespList.add(tCompanyCalculationResp);
                }else {
                    // TODO
                    String zipCode = demandDto.getZipCode();
//                    GeocodeVo geocode1 = googleMapUtil.getGeocode(zipCode);
                    tCompanyCalculationResp.setEndLon(String.valueOf(1));
                    tCompanyCalculationResp.setEndLat(String.valueOf(1));
                    GeocodeVo geocode1 = googleMapUtil.getGeocode(AddressLookup.getAddress(zipCode));
                    tCompanyCalculationResp.setEndLon(String.valueOf(geocode1.getLng()));
                    tCompanyCalculationResp.setEndLat(String.valueOf(geocode1.getLat()));
                    tCompanyCalculationRespList.add(tCompanyCalculationResp);
                }
            }
        }
        for (TCompanyCalculationResp tCompanyCalculationResp : tCompanyCalculationRespList) {
            tCompanyCalculationResp.setQuoteId(tQuote.getId());
        for (TCompanyCalculationResp tCompanyCalculationResp1 : tCompanyCalculationRespList) {
            tCompanyCalculationResp1.setQuoteId(tQuote.getId());
        }
        return new SuccessTip(tCompanyCalculationRespList);
    }
@@ -524,11 +572,6 @@
            tOrder.setPayMoney(bigDecimal);
            orderService.updateById(tOrder);
        }
        return new SuccessTip();
    }
@@ -546,6 +589,7 @@
        return new SuccessTip(goods);
    }
    @ApiOperation(value = "需求列表",notes="需求列表")
    @ApiImplicitParams({
@@ -698,16 +742,38 @@
            @ApiImplicitParam(name = "address", value = "address", required = false, dataType = "String"),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "String"),
            @ApiImplicitParam(name = "portId", value = "portId", required = true, dataType = "int"),
            @ApiImplicitParam(name = "companyId", value = "companyId", required = true, dataType = "int"),
    })
    @GetMapping(value = "/getWarehouse")
    @ResponseBody
    public Object getWarehouse( String address,int pageNumber,int pageSize) {
    public Object getWarehouse( String address,int pageNumber,int pageSize,int portId,int companyId) {
        TRates tRates1 = ratesService.selectOne(new EntityWrapper<TRates>().eq("metro_id", portId).eq("type", 2).eq("company_id", companyId));
        int ratesId=0;
        if(tRates1!=null){
            ratesId=tRates1.getId();
        }else {
            // 找出city
            TPort tPort = portService.selectById(portId);
            TCountry tCountry = countryService.selectById(tPort.getCity());
            // 是否是符合的港区
            tRates1 = ratesService.selectOne(new EntityWrapper<TRates>().eq("metro_id", tCountry.getId()).eq("type", 1).eq("company_id", companyId));
            if(tRates1!=null){
                ratesId=tRates1.getId();
            }else {
                ratesId=-1;
            }
//                    ratesId=tCountry.getId();
        }
        Page<TWarehouse> tWarehousePage = new Page<>(pageNumber, pageSize);
        EntityWrapper<TWarehouse> tWarehouseEntityWrapper = new EntityWrapper<>();
        tWarehouseEntityWrapper.eq("company_id",1);
        tWarehouseEntityWrapper.eq("company_id",companyId);
        tWarehouseEntityWrapper.eq("port_id",ratesId);
        tWarehouseEntityWrapper.gt("ware_price",0);
        if(Objects.nonNull(address)){
            tWarehouseEntityWrapper.like("address",address);
            tWarehouseEntityWrapper.like("code",address);
        }
        Page<TWarehouse> tWarehousePage1 = warehouseService.selectPage(tWarehousePage, tWarehouseEntityWrapper);
@@ -752,4 +818,17 @@
    }
    @ApiOperation(value = "根据亚马逊code获取地址",notes="根据亚马逊code获取地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "code", value = "code", required = true, dataType = "String"),
    })
    @GetMapping(value = "/getWarehouseFromCode")
    @ResponseBody
    public Object getWarehouseFromCode(String code) {
        TWarehouse tWarehouse = warehouseService.selectList(new EntityWrapper<TWarehouse>().eq("code", code).eq("company_id", 0)).get(0);
        return new SuccessTip(tWarehouse.getAddress() );
    }
}