package com.stylefeng.guns.modular.system.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.google.maps.model.LatLng; import com.stylefeng.guns.modular.system.dao.*; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.stylefeng.guns.modular.system.utils.GoogleMap.GeocodeVo; import com.stylefeng.guns.modular.system.utils.GoogleMap.GoogleMapUtil; import io.swagger.annotations.ApiModel; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** *

* 卡车公司 服务实现类 *

* * @author stylefeng * @since 2023-01-30 */ @Service public class TCompanyServiceImpl extends ServiceImpl implements ITCompanyService { @Autowired private ITQuoteService quoteService; @Autowired private ITOrderService orderService; @Autowired private ITGoodsService goodsService; @Autowired private TCompanyMapper companyMapper; @Autowired private TPriceMapper priceMapper; @Autowired private GoogleMapUtil googleMapUtil; @Autowired private TCountryMapper tCountryMapper; @Autowired private TPortMapper tPortMapper; @Autowired private WareHouseMapper wareHouseMapper; @Autowired private UserMapper userMapper; @Autowired private ITUserService itUserService; @Override public List selectList1(Page tCompanyVoPage, String name, String account) { return this.baseMapper.selectList1(tCompanyVoPage,name,account); } @Override public List selectList2(Page tCompanyVoPage, String name, String account, Integer state) { return this.baseMapper.selectList2(tCompanyVoPage,name,account,state); } @Override public TCompanyCalculationRespOne getQuotaFromId(Long id) { TQuote quote = quoteService.selectById(id); TCompanyCalculationRespOne tCompanyCalculationRespOne = new TCompanyCalculationRespOne(); tCompanyCalculationRespOne.setQuoteId(quote.getId()); List goods = goodsService.selectList(new EntityWrapper()); // 找出所有的订单 List orders = orderService.selectList(new EntityWrapper().eq("e_zip_z", quote.getOrderId())); TOrder tOrder = orders.get(0); TUser user = itUserService.selectById(quote.getUserId()); tCompanyCalculationRespOne.setPickupStr(tOrder.getAccessorialStr()); tCompanyCalculationRespOne.setDestinationStr(tOrder.getDeliveryStr()); tCompanyCalculationRespOne.setCustomer(user.getCompanyName()); User user1 = userMapper.selectById(quote.getCreateId()); tCompanyCalculationRespOne.setCreateUser(user1.getName()); Integer port = tOrder.getPort(); TPort tPort = tPortMapper.selectById(port); TCountry tCountry = tCountryMapper.selectById(tPort.getCity()); tCompanyCalculationRespOne.setMetro(tCountry.getName()); tCompanyCalculationRespOne.setZipCode(tPort.getZipCode()); TCountry tCountry1 = tCountryMapper.selectById(tCountry.getParentId()); tCompanyCalculationRespOne.setState(tCountry1.getName()); tCompanyCalculationRespOne.setShipmentEta(tOrder.getShipmentDate()); String warehouse = tOrder.getWarehouse(); if(!"0".equals(warehouse)){ List code = wareHouseMapper.selectList(new EntityWrapper().eq("code", warehouse)); if(code.size()>0){ tCompanyCalculationRespOne.setWarehouse(code.get(0).getAddress()); } } tCompanyCalculationRespOne.setDeliveryDate(tOrder.getDeliveryDate()); Integer companyId = tOrder.getCompanyId(); List orders1 = orderService.selectList(new EntityWrapper().eq("e_zip_z", quote.getOrderId()).eq("company_id", companyId)); ArrayList lonLats = new ArrayList<>(); LonLat latLng = new LonLat(); latLng.setLat("-113.6510249618184"); latLng.setLng("37.8924429618184"); lonLats.add(latLng); latLng=new LonLat(); latLng.setLat("-113.066919618184"); latLng.setLng("37.684389618184"); lonLats.add(latLng); tCompanyCalculationRespOne.setLonLats(lonLats); ArrayList tGoods = new ArrayList<>(); // 获取其中一个订单 去获取货物 for (TOrder order : orders1) { List goodsList = goods.stream().filter(good -> good.getOrderId().equals(order.getId())).collect(Collectors.toList()); tGoods.addAll(goodsList); } tCompanyCalculationRespOne.setTGoods(tGoods); ArrayList companyInfos = new ArrayList<>(); for (TOrder order : orders) { CompanyInfo tCompanyCalculationResp = new CompanyInfo(); // 查询公司 TCompany company = companyMapper.selectById(order.getCompanyId()); tCompanyCalculationResp.setCompanyName(company.getName()); tCompanyCalculationResp.setCompanyId(company.getId()); tCompanyCalculationResp.setCarGoNumber(String.valueOf(company.getMcNumber())); tCompanyCalculationResp.setImg(company.getHeadImg()); tCompanyCalculationResp.setExpirationDate(company.getExpirationTime()); // 查询公司下的价格集合 List prices = priceMapper.selectList(new EntityWrapper().eq("order_id", order.getId())); List tCompanyRespList = new ArrayList<>(); for (TPrice price : prices) { TCompanyResp tCompanyResp = new TCompanyResp(); tCompanyResp.setOrderId(order.getId()); tCompanyResp.setName(price.getType()); tCompanyResp.setPrice(price.getPrice()); tCompanyRespList.add(tCompanyResp); } BigDecimal bigDecimal = tCompanyRespList.stream().map(TCompanyResp::getPrice).reduce(BigDecimal::add).orElse(new BigDecimal(0.00)); tCompanyCalculationResp.setAllTotal(bigDecimal); tCompanyCalculationResp.setList(tCompanyRespList); // 过滤订单 List orderList = orders.stream().filter(o -> o.getCompanyId().equals(company.getId())).collect(Collectors.toList()); tCompanyCalculationResp.setOrderList(orderList); companyInfos.add(tCompanyCalculationResp); } ArrayList collect = companyInfos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompanyInfo::getCompanyId))), ArrayList::new)); tCompanyCalculationRespOne.setCompanyInfos(collect); return tCompanyCalculationRespOne; } @Override public TCompanyCalculationRespOne getQuotaFromIdAndCompanyId(Long id, Integer companyIds) { TQuote quote = quoteService.selectById(id); TCompanyCalculationRespOne tCompanyCalculationRespOne = new TCompanyCalculationRespOne(); tCompanyCalculationRespOne.setQuoteId(quote.getId()); List goods = goodsService.selectList(new EntityWrapper()); // 找出所有的订单 List orders = orderService.selectList(new EntityWrapper().eq("e_zip_z", quote.getOrderId())); TOrder tOrder = orders.get(0); TUser user = itUserService.selectById(quote.getUserId()); tCompanyCalculationRespOne.setPickupStr(tOrder.getAccessorialStr()); tCompanyCalculationRespOne.setDestinationStr(tOrder.getDeliveryStr()); tCompanyCalculationRespOne.setCustomer(user.getCompanyName()); User user1 = userMapper.selectById(quote.getCreateId()); tCompanyCalculationRespOne.setCreateUser(user1.getName()); Integer port = tOrder.getPort(); TPort tPort = tPortMapper.selectById(port); TCountry tCountry = tCountryMapper.selectById(tPort.getCity()); tCompanyCalculationRespOne.setMetro(tCountry.getName()); tCompanyCalculationRespOne.setZipCode(tPort.getZipCode()); TCountry tCountry1 = tCountryMapper.selectById(tCountry.getParentId()); tCompanyCalculationRespOne.setState(tCountry1.getName()); tCompanyCalculationRespOne.setShipmentEta(tOrder.getShipmentDate()); String warehouse = tOrder.getWarehouse(); if(!"0".equals(warehouse)){ List code = wareHouseMapper.selectList(new EntityWrapper().eq("code", warehouse)); if(code.size()>0){ tCompanyCalculationRespOne.setWarehouse(code.get(0).getAddress()); } } tCompanyCalculationRespOne.setDeliveryDate(tOrder.getDeliveryDate()); List orders1 = orderService.selectList(new EntityWrapper().eq("e_zip_z", quote.getOrderId()).eq("company_id", companyIds)); ArrayList lonLats = new ArrayList<>(); LonLat latLng = new LonLat(); latLng.setLat("-113.6510249618184"); latLng.setLng("37.8924429618184"); lonLats.add(latLng); latLng=new LonLat(); latLng.setLat("-113.066919618184"); latLng.setLng("37.684389618184"); lonLats.add(latLng); tCompanyCalculationRespOne.setLonLats(lonLats); ArrayList tGoods = new ArrayList<>(); // 获取其中一个订单 去获取货物 for (TOrder order : orders1) { List goodsList = goods.stream().filter(good -> good.getOrderId().equals(order.getId())).collect(Collectors.toList()); tGoods.addAll(goodsList); } tCompanyCalculationRespOne.setTGoods(tGoods); ArrayList companyInfos = new ArrayList<>(); for (TOrder order : orders1) { CompanyInfo tCompanyCalculationResp = new CompanyInfo(); // 查询公司 TCompany company = companyMapper.selectById(order.getCompanyId()); tCompanyCalculationResp.setCompanyName(company.getName()); tCompanyCalculationResp.setCompanyId(company.getId()); tCompanyCalculationResp.setCarGoNumber(String.valueOf(company.getMcNumber())); tCompanyCalculationResp.setImg(company.getHeadImg()); tCompanyCalculationResp.setExpirationDate(company.getExpirationTime()); // 查询公司下的价格集合 List prices = priceMapper.selectList(new EntityWrapper().eq("order_id", order.getId())); List tCompanyRespList = new ArrayList<>(); for (TPrice price : prices) { TCompanyResp tCompanyResp = new TCompanyResp(); tCompanyResp.setOrderId(order.getId()); tCompanyResp.setName(price.getType()); tCompanyResp.setPrice(price.getPrice()); tCompanyRespList.add(tCompanyResp); } BigDecimal bigDecimal = tCompanyRespList.stream().map(TCompanyResp::getPrice).reduce(BigDecimal::add).orElse(new BigDecimal(0.00)); tCompanyCalculationResp.setAllTotal(bigDecimal); tCompanyCalculationResp.setList(tCompanyRespList); // 过滤订单 List orderList = orders.stream().filter(o -> o.getCompanyId().equals(company.getId())).collect(Collectors.toList()); tCompanyCalculationResp.setOrderList(orderList); companyInfos.add(tCompanyCalculationResp); } ArrayList collect = companyInfos.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CompanyInfo::getCompanyId))), ArrayList::new)); tCompanyCalculationRespOne.setCompanyInfos(collect); return tCompanyCalculationRespOne; } public List getQuotaFromId1(Long id) { TQuote quote = quoteService.selectById(id); List list = new ArrayList<>(); List goods = goodsService.selectList(new EntityWrapper()); // 找出所有的订单 List orders = orderService.selectList(new EntityWrapper().eq("e_zip_z", quote.getOrderId())); for (TOrder order : orders) { TCompanyCalculationResp tCompanyCalculationResp = new TCompanyCalculationResp(); // 过滤订单 List goodsList = goods.stream().filter(good -> good.getOrderId().equals(order.getId())).collect(Collectors. collectingAndThen(Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(TGoods::getId))),ArrayList::new)); tCompanyCalculationResp.setTGoods(goodsList); // 查询公司 TCompany company = companyMapper.selectById(order.getCompanyId()); tCompanyCalculationResp.setCompanyName(company.getName()); tCompanyCalculationResp.setCompanyId(company.getId()); tCompanyCalculationResp.setCarGoNumber(String.valueOf(company.getMcNumber())); tCompanyCalculationResp.setImg(company.getHeadImg()); // 查询公司下的价格集合 List prices = priceMapper.selectList(new EntityWrapper().eq("order_id", order.getId())); List tCompanyRespList = new ArrayList<>(); for (TPrice price : prices) { TCompanyResp tCompanyResp = new TCompanyResp(); tCompanyResp.setOrderId(order.getId()); tCompanyResp.setName(price.getType()); tCompanyResp.setPrice(price.getPrice()); tCompanyRespList.add(tCompanyResp); } // 过滤订单 List orderList = orders.stream().filter(o -> o.getCompanyId().equals(company.getId())).collect(Collectors.toList()); tCompanyCalculationResp.setOrderList(orderList); // 经纬度 tCompanyCalculationResp.setStartLon(order.getStartLon()); tCompanyCalculationResp.setStartLat(order.getStartLat()); // GeocodeVo geocode = googleMapUtil.getGeocode(order.geteAddress()); // if(Objects.nonNull(geocode)){ // tCompanyCalculationResp.setEndLon(String.valueOf(geocode.getLng())); // tCompanyCalculationResp.setEndLat(String.valueOf(geocode.getLat())); // } list.add(tCompanyCalculationResp); } return list; } }