| | |
| | | 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 org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | 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.*; |
| | |
| | | }) |
| | | @PostMapping(value = "/addDemand") |
| | | @ResponseBody |
| | | @Transactional(propagation = Propagation.REQUIRES_NEW) |
| | | public Object addDemand(@RequestBody DemandDto demandDto) throws Exception { |
| | | Integer id = demandDto.getId(); |
| | | String s1 = System.currentTimeMillis() + ToolUtil.getRandomString(5); |
| | |
| | | |
| | | 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 |
| | | 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<>(); |
| | | // List<Integer> collect1 = set.stream().filter(e -> e.equals(demandDto.getId())).collect(Collectors.toList()); |
| | |
| | | if(tRates1!=null){ |
| | | ratesId=tRates1.getId(); |
| | | }else { |
| | | ratesId=tCountry.getId(); |
| | | 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<>(); |
| | | |
| | | |
| | | 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()); |
| | | TOrder tOrder = new TOrder(); |
| | | tOrder.setUserId(demandDto.getUserId()); |
| | | tOrder.setAccessorial(demandDto.getAccessorial()); |
| | |
| | | tOrder.setDeliveryDate(demandDto.getDeliveryDate()); |
| | | tOrder.seteZipZ(s1); |
| | | tOrder.setCreateTime(new Date()); |
| | | tOrder.setStartLat("1"); |
| | | tOrder.setStartLon("1"); |
| | | 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.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 { |
| | |
| | | TCompanyResp tCompanyResp = new TCompanyResp(); |
| | | // 是否超重 |
| | | Integer weight = goodsListDto.getWeight(); |
| | | // 相差天数 |
| | | long between = DateUtil.between(demandDto.getShipmentDate(), demandDto.getDeliveryDate(), DateUnit.DAY); |
| | | if(between==0){ |
| | | between=1; |
| | | 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); |
| | | |
| | | 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)); |
| | |
| | | if(feeSetting1==null){ |
| | | tCompanyResp.setPrice(new BigDecimal(0)); |
| | | }else { |
| | | tCompanyResp.setPrice(feeSetting1.getSetValue().multiply(new BigDecimal(between))); |
| | | tCompanyResp.setPrice(feeSetting1.getSetValue().multiply(days)); |
| | | tCompanyResp.setDay(days.toString()); |
| | | } |
| | | |
| | | objects.add(tCompanyResp); |
| | |
| | | if(feeSetting==null){ |
| | | tCompanyResp.setPrice(new BigDecimal(0)); |
| | | }else { |
| | | tCompanyResp.setPrice(feeSetting.getSetValue().multiply(new BigDecimal(between))); |
| | | tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days)); |
| | | tCompanyResp.setDay(days.toString()); |
| | | } |
| | | |
| | | objects.add(tCompanyResp); |
| | |
| | | if(feeSetting==null){ |
| | | tCompanyResp.setPrice(new BigDecimal(0)); |
| | | }else { |
| | | tCompanyResp.setPrice(feeSetting.getSetValue()); |
| | | 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(); |
| | |
| | | |
| | | if("0".equals(demandDto.getWarehouse())){ |
| | | tCompanyResp=new TCompanyResp(); |
| | | BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", demandDto.getDelivery())).getSetValue(); |
| | | 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(setValue1); |
| | | tCompanyResp.setPrice(feeSetting1.getSetValue()); |
| | | }else { |
| | | tCompanyResp.setName(demandDto.getDelivery()); |
| | | tCompanyResp.setPrice(new BigDecimal(0)); |
| | | } |
| | | objects.add(tCompanyResp); |
| | | |
| | | // 基础价格 |
| | |
| | | boolean inPolygon = PointInPolygon.isInPolygon(geocode1.getLat(), geocode1.getLng(), companyBasic.getLonLat()); |
| | | if(inPolygon){ |
| | | tCompanyResp=new TCompanyResp(); |
| | | tCompanyResp.setPrice(type.get(0).getFee()); |
| | | tCompanyResp.setPrice(companyBasic.getFee()); |
| | | tCompanyResp.setName("LH+FSC"); |
| | | objects.add(tCompanyResp); |
| | | break; |
| | |
| | | // 距离 |
| | | tCompanyResp=new TCompanyResp(); |
| | | // 1条数据 不需要zipcode |
| | | DistancematrixVo distancematrix = googleMapUtil.getDistancematrix(address, address1); |
| | | double distance = distancematrix.getDistance().doubleValue(); |
| | | 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) { |
| | |
| | | // 1条数据 不需要zipcode |
| | | TCompanyBasic type1 = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("type", 3).eq("port_id",ratesId)); |
| | | if(type1!=null) { |
| | | DistancematrixVo distancematrix = googleMapUtil.getDistancematrix(address, type1.getAddress()); |
| | | double distance = distancematrix.getDistance().doubleValue(); |
| | | 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); |
| | |
| | | } |
| | | 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())); |
| | | |
| | |
| | | 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); |
| | |
| | | |
| | | |
| | | // 目的地经纬度 |
| | | 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); |
| | | } |
| | | |
| | |
| | | EntityWrapper<TWarehouse> tWarehouseEntityWrapper = new EntityWrapper<>(); |
| | | 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); |
| | | |