package com.stylefeng.guns.modular.system.controller;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.date.DateUnit;
|
import cn.hutool.core.date.DateUtil;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.base.tips.ErrorTip;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
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.*;
|
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.tips.SuccessTip;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
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.util.CollectionUtils;
|
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.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 控制器
|
*
|
* @author fengshuonan
|
* @Date 2022-12-28 09:33:09
|
*/
|
@Controller
|
@Api(tags = "主页")
|
@RequestMapping("/api/demand")
|
public class DemandController extends BaseController {
|
|
@Autowired
|
private ITOrderService orderService;
|
|
@Autowired
|
private ITCountryService service;
|
|
@Autowired
|
private ITPortService itPortService;
|
|
@Autowired
|
private IWarehouseService warehouseService;
|
|
@Autowired
|
private GoogleMapUtil googleMapUtil;
|
|
@Autowired
|
private ITCompanyServiceService tCompanyServiceService;
|
@Autowired
|
private ITCompanyService tCompanyService;
|
|
@Autowired
|
private ITCompanyBasicService companyBasicService;
|
|
@Autowired
|
private ITCompanyFeeSettingService companyFeeSettingService;
|
|
@Autowired
|
private ITPortService portService;
|
|
@Autowired
|
private ITQuoteService quoteService;
|
|
@Autowired
|
private ITGoodsService goodsService;
|
|
@Autowired
|
private ITRatesService ratesService;
|
|
@Autowired
|
private ITCountryService countryService;
|
|
@Autowired
|
private ITCompanyService companyService;
|
|
@Autowired
|
private ITPriceService priceService;
|
|
@Autowired
|
private ITUserService userService;
|
|
@Autowired
|
private ITGroupService groupService;
|
|
@Autowired
|
private ITUserFeeSettingService userFeeSettingService;
|
|
|
@ApiOperation(value = "发布需求-第一步",notes="发布需求-第一步")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@PostMapping(value = "/addDemand")
|
@ResponseBody
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
public Object addDemand(@RequestBody DemandDto demandDto) throws Exception {
|
|
int breakNum=0;
|
// 计数
|
int count=0;
|
Integer id = demandDto.getId();
|
String s1 = System.currentTimeMillis() + ToolUtil.getRandomString(5);
|
String s2 = System.currentTimeMillis() + ToolUtil.getRandomString(5);
|
// 生成需求
|
TQuote tQuote = new TQuote();
|
tQuote.setCreateTime(new Date());
|
// 需求订单号
|
tQuote.setOrderId(s1);
|
// 总重量
|
tQuote.setTotal(demandDto.getTotal());
|
tQuote.setState(0);
|
tQuote.setUserId(demandDto.getUserId());
|
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",userId).isNotNull("fee").gt("fee",0));
|
|
// }
|
|
|
String accessorialStr = demandDto.getAccessorialStr();
|
String[] split = accessorialStr.split(",");
|
Map<String,String> map = new HashMap<>(split.length);
|
for (String s :split){
|
if(!s.equals("CTF")&& !s.equals("URGENT FEE")&&!s.equals("PIPERPASS")){
|
map.put(s,s);
|
}
|
|
}
|
|
List<TCompanyService> companyServiceList = new ArrayList<>();
|
|
String accessorialStr1 = getStr(demandDto.getAccessorialStr());
|
|
|
|
|
//
|
if(ToolUtil.isNotEmpty(accessorialStr1) && !"".equals(accessorialStr1)){
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
if(!entry.getKey().equals("CTF")&& !entry.getKey().equals("URGENT FEE")&&!entry.getKey().equals("PIPERPASS")) {
|
companyServiceList.addAll(tCompanyServiceService.selectList(new EntityWrapper<TCompanyService>()
|
.eq("service_name", entry.getKey()).ne("service_value", 0)));
|
}
|
}
|
}else {
|
companyServiceList.addAll(tCompanyServiceService.selectList(null));
|
}
|
|
|
// 根据公司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).eq("work",1));
|
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);
|
|
GeocodeVo geocode = googleMapUtil.getGeocode(tPort.getAddress());
|
|
|
// 获取码头上级id
|
TCountry city = countryService.selectById(tPort.getCity());
|
TCountry state = countryService.selectById(city.getParentId());
|
String address = tPort.getAddress();
|
|
List<TCompanyCalculationResp> tCompanyCalculationRespList = new ArrayList<>(tCompanyList.size());
|
|
|
// 没有满足公司
|
if(CollectionUtils.isEmpty(set)){
|
quoteService.deleteById(tQuote.getId());
|
return new com.stylefeng.guns.modular.system.utils.tips.ErrorTip(5001,"No truck company was matched to meet the demand");
|
}else {
|
List<TCompany> companies = companyService.selectList(new EntityWrapper<TCompany>().in("id", set));
|
for (TCompany company : companies) {
|
breakNum=0;
|
TCompanyCalculationResp tCompanyCalculationResp = new TCompanyCalculationResp();
|
ArrayList<TOrder> tOrders = new ArrayList<>();
|
// 超重 价格
|
ArrayList<TCompanyResp> objects = new ArrayList<>();
|
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 {
|
tRates1 = ratesService.selectOne(new EntityWrapper<TRates>().eq("metro_id", tCountry.getId()).eq("type", 1).eq("company_id", company.getId()));
|
if(tRates1!=null){
|
ratesId=tRates1.getId();
|
}else {
|
break;
|
}
|
}
|
|
for (GoodsListDto goodsListDto : list1) {
|
if(breakNum==1){
|
break;
|
}
|
ArrayList<TPrice> tPrices = new ArrayList<>();
|
|
List<GoodsDto> list = goodsListDto.getList();
|
ArrayList<TGoods> tGoods1 = new ArrayList<>();
|
objects = new ArrayList<>();
|
Long orderId= null;
|
for (GoodsDto goodsDto : list) {
|
tPrices = new ArrayList<>();
|
objects = new ArrayList<>();
|
TCompanyResp tCompanyResp = new TCompanyResp();
|
if("0".equals(demandDto.getWarehouse())){
|
tCompanyResp=new TCompanyResp();
|
TCompanyFeeSetting feeSetting = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id", ratesId).eq("set_name", demandDto.getDelivery()));
|
if(feeSetting==null){
|
// breakNum=1;
|
// count++;
|
// break;
|
}else {
|
tCompanyResp.setName(demandDto.getDelivery());
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(demandDto.getDelivery())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue());
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue());
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}
|
// tCompanyResp.setPrice(feeSetting.getSetValue());
|
// tCompanyResp.setAdminPrice(feeSetting.getSetValue());
|
objects.add(tCompanyResp);
|
}
|
|
// 基础价格
|
String zipCode = demandDto.getZipCode();
|
// 地址信息
|
String address1 = AddressLookup.getAddress(zipCode);
|
System.out.println("地址信息+"+address1);
|
|
if(address1==null){
|
return new com.stylefeng.guns.modular.system.utils.tips.ErrorTip(5001,"Please enter the correct zipcode");
|
}
|
|
List<TCompanyBasic> tCompanyBasic = companyBasicService.selectList(new EntityWrapper<TCompanyBasic>().eq("port_id",ratesId).eq("zip_code", zipCode).eq("type", 1));
|
System.out.println(tCompanyBasic);
|
|
if(tCompanyBasic.size()>0){
|
System.out.println("点对点++++++++++++");
|
tCompanyResp=new TCompanyResp();
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals("LH+FSC")).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(tCompanyBasic.get(0).getFee()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setPrice(tCompanyBasic.get(0).getFee());
|
tCompanyResp.setAdminPrice(tCompanyBasic.get(0).getFee().add(bigDecimal));
|
}else {
|
tCompanyResp.setPrice(tCompanyBasic.get(0).getFee());
|
tCompanyResp.setAdminPrice(tCompanyBasic.get(0).getFee());
|
}
|
}else {
|
tCompanyResp.setPrice(tCompanyBasic.get(0).getFee());
|
tCompanyResp.setAdminPrice(tCompanyBasic.get(0).getFee());
|
}
|
|
tCompanyResp.setName("LH+FSC");
|
objects.add(tCompanyResp);
|
}else {
|
// 画圈 拿到的zipcode集合 去对比当前zipcode是否在集合中
|
List<TCompanyBasic> type = companyBasicService.selectList(new EntityWrapper<TCompanyBasic>().eq("type", 2).eq("port_id",ratesId).orderBy("fee",true));
|
System.out.println(type);
|
tCompanyResp=new TCompanyResp();
|
if(type.size()>0){
|
GeocodeVo geocode1 = googleMapUtil.getGeocode(address1);
|
System.out.println("谷歌终点经纬度"+geocode1.getLat()+"|"+geocode1.getLng());
|
for (TCompanyBasic companyBasic : type) {
|
boolean inPolygon = PointInPolygon.isInPolygon(geocode1.getLat(), geocode1.getLng(), companyBasic.getLonLat());
|
if(inPolygon){
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals("LH+FSC")).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(companyBasic.getFee()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setPrice(companyBasic.getFee());
|
tCompanyResp.setAdminPrice(companyBasic.getFee().add(bigDecimal));
|
}else {
|
tCompanyResp.setPrice(companyBasic.getFee());
|
tCompanyResp.setAdminPrice(companyBasic.getFee());
|
}
|
}else {
|
tCompanyResp.setPrice(companyBasic.getFee());
|
tCompanyResp.setAdminPrice(companyBasic.getFee());
|
}
|
|
// tCompanyResp.setPrice(companyBasic.getFee());
|
// tCompanyResp.setAdminPrice(companyBasic.getFee());
|
tCompanyResp.setName("LH+FSC");
|
objects.add(tCompanyResp);
|
break;
|
}
|
}
|
if(tCompanyResp==null || "".equals(tCompanyResp.getName()) || tCompanyResp.getName()==null){
|
// 距离
|
tCompanyResp=new TCompanyResp();
|
// 1条数据 不需要zipcode
|
DistancematrixVo distancematrix = googleMapUtil.getDistancematrix(address, address1);
|
double distance = distancematrix.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);
|
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals("LH+FSC")).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal1 = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(multiply).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setPrice(multiply);
|
tCompanyResp.setAdminPrice(multiply.add(bigDecimal1));
|
}else {
|
tCompanyResp.setPrice(multiply);
|
tCompanyResp.setAdminPrice(multiply);
|
}
|
}else {
|
tCompanyResp.setPrice(multiply);
|
tCompanyResp.setAdminPrice(multiply);
|
}
|
// tCompanyResp.setPrice(multiply);
|
// tCompanyResp.setAdminPrice(multiply);
|
tCompanyResp.setName("LH+FSC");
|
objects.add(tCompanyResp);
|
}else {
|
breakNum=1;
|
count++;
|
break;
|
}
|
}
|
}else {
|
// 距离
|
tCompanyResp=new TCompanyResp();
|
// 1条数据 不需要zipcode
|
DistancematrixVo distancematrix = googleMapUtil.getDistancematrix(address, address1);
|
double distance = distancematrix.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);
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals("LH+FSC")).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal1 = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(multiply).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setPrice(multiply);
|
tCompanyResp.setAdminPrice(multiply.add(bigDecimal1));
|
}else {
|
tCompanyResp.setPrice(multiply);
|
tCompanyResp.setAdminPrice(multiply);
|
}
|
}else {
|
tCompanyResp.setPrice(multiply);
|
tCompanyResp.setAdminPrice(multiply);
|
}
|
tCompanyResp.setName("LH+FSC");
|
objects.add(tCompanyResp);
|
}else {
|
breakNum=1;
|
count++;
|
break;
|
}
|
}
|
}
|
|
}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) && tWarehouse.getWarePrice().doubleValue()>0){
|
tCompanyResp.setPrice(tWarehouse.getWarePrice());
|
tCompanyResp.setAdminPrice(tWarehouse.getWarePrice());
|
}else {
|
breakNum=1;
|
count++;
|
break;
|
}
|
objects.add(tCompanyResp);
|
}
|
|
// 是否超重
|
Integer weight = goodsDto.getWeight();
|
// long between = DateUtil.between(demandDto.getShipmentDate(), demandDto.getDeliveryDate(), DateUnit.DAY);
|
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){
|
breakNum=1;
|
count++;
|
break;
|
}
|
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();
|
GoodsDto 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);
|
// arg1="WBCT";
|
// arg2="Ontario";
|
// arg3="55";
|
// arg4="COSCO";
|
// arg5="Drop & hook";
|
// arg6="40ft";
|
// arg7="None";
|
// arg8="44806";
|
BigDecimal days = new BigDecimal(ChassisRentalDaysUtil.chassisRentalDays(1, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)).setScale(0, RoundingMode.HALF_UP);
|
// if(between==0){
|
// between=1;
|
// }
|
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()));
|
if(feeSetting==null){
|
breakNum=1;
|
count++;
|
break;
|
}else {
|
tCompanyResp=new TCompanyResp();
|
tCompanyResp.setName(UserFeeSettingEnum.OVERWEIGHT.getDesc());
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.OVERWEIGHT.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue());
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue());
|
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"));
|
if(feeSetting1==null){
|
breakNum=1;
|
count++;
|
break;
|
}else {
|
tCompanyResp=new TCompanyResp();
|
tCompanyResp.setName(UserFeeSettingEnum.CHASSIS_FEE.getDesc());
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.CHASSIS_FEE.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting1.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
tCompanyResp.setDay(days.toString());
|
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("rates_id",ratesId).eq("set_name", "Pool chassis"));
|
if(feeSetting==null){
|
breakNum=1;
|
count++;
|
break;
|
}else {
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.CHASSIS_FEE.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting.getSetValue().multiply(days)).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().multiply(days).add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().multiply(days));
|
tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().multiply(days));
|
tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
|
}
|
|
tCompanyResp.setDay(days.toString());
|
// tCompanyResp.setPrice(feeSetting.getSetValue().multiply(new BigDecimal(between)));
|
}
|
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()));
|
if(feeSetting==null){
|
tCompanyResp.setName(UserFeeSettingEnum.PREPULL.getDesc());
|
tCompanyResp.setPrice(new BigDecimal(0));
|
}else {
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.PREPULL.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue());
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue());
|
tCompanyResp.setPrice(feeSetting.getSetValue());
|
}
|
tCompanyResp.setName(UserFeeSettingEnum.PREPULL.getDesc());
|
}
|
// BigDecimal setValue = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", UserFeeSettingEnum.PREPULL.getDesc())).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()));
|
if(feeSetting!=null){
|
days = new BigDecimal(ChassisRentalDaysUtil.chassisRentalDays(4, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)).setScale(0, RoundingMode.HALF_UP);
|
tCompanyResp.setName(UserFeeSettingEnum.DETENTION_CONGESTION.getDesc());
|
// tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
|
tCompanyResp.setDay(days.toString());
|
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.DETENTION_CONGESTION.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting.getSetValue().multiply(days)).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().multiply(days).add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().multiply(days));
|
tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting.getSetValue().multiply(days));
|
tCompanyResp.setPrice(feeSetting.getSetValue().multiply(days));
|
}
|
|
}else {
|
tCompanyResp.setName(UserFeeSettingEnum.DETENTION_CONGESTION.getDesc());
|
tCompanyResp.setPrice(new BigDecimal(0));
|
tCompanyResp.setAdminPrice(new BigDecimal(0));
|
}
|
// BigDecimal setValue = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", UserFeeSettingEnum.DETENTION_CONGESTION.getDesc())).getSetValue();
|
|
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));
|
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.STORAGE.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(storage.getSetValue().multiply(days)).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(storage.getSetValue().multiply(days).add(bigDecimal));
|
tCompanyResp.setPrice(storage.getSetValue().multiply(days));
|
}else {
|
tCompanyResp.setAdminPrice(storage.getSetValue().multiply(days));
|
tCompanyResp.setPrice(storage.getSetValue().multiply(days));
|
}
|
}else {
|
tCompanyResp.setAdminPrice(storage.getSetValue().multiply(days));
|
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(goodsDto.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()));
|
if(feeSetting1!=null){
|
tCompanyResp.setName(UserFeeSettingEnum.HAZMAT.getDesc());
|
// tCompanyResp.setPrice(feeSetting1.getSetValue());
|
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.HAZMAT.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting1.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
objects.add(tCompanyResp);
|
}else {
|
breakNum=1;
|
count++;
|
break;
|
}
|
// BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", UserFeeSettingEnum.HAZMAT.getDesc())).getSetValue();
|
|
}
|
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()));
|
if(feeSetting1!=null){
|
tCompanyResp.setName(UserFeeSettingEnum.URGENT_SEE.getDesc());
|
|
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.URGENT_SEE.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting1.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
// tCompanyResp.setPrice(feeSetting1.getSetValue());
|
objects.add(tCompanyResp);
|
}else {
|
breakNum=1;
|
count++;
|
break;
|
}
|
// BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", UserFeeSettingEnum.URGENT_SEE.getDesc())).getSetValue();
|
|
}
|
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()));
|
if(feeSetting1!=null){
|
tCompanyResp.setName(UserFeeSettingEnum.PIERPASS.getDesc());
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.PIERPASS.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting1.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
objects.add(tCompanyResp);
|
}else {
|
breakNum=1;
|
count++;
|
break;
|
}
|
// BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", UserFeeSettingEnum.PIERPASS.getDesc())).getSetValue();
|
}
|
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()));
|
if(feeSetting1!=null){
|
tCompanyResp.setName(UserFeeSettingEnum.CTF.getDesc());
|
if(tUserFeeSettings!=null){
|
List<TUserFeeSetting> collect = tUserFeeSettings.stream().filter(e -> e.getName().equals(UserFeeSettingEnum.CTF.getDesc())).collect(Collectors.toList());
|
if(collect.size()>0){
|
BigDecimal bigDecimal = new BigDecimal(collect.get(0).getFee().doubleValue() / 100).multiply(feeSetting1.getSetValue()).setScale(2, RoundingMode.HALF_UP);
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue().add(bigDecimal));
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
}else {
|
tCompanyResp.setAdminPrice(feeSetting1.getSetValue());
|
tCompanyResp.setPrice(feeSetting1.getSetValue());
|
}
|
objects.add(tCompanyResp);
|
}else {
|
breakNum=1;
|
count++;
|
break;
|
}
|
// BigDecimal setValue1 = companyFeeSettingService.selectOne(new EntityWrapper<TCompanyFeeSetting>().eq("company_id", company.getId()).eq("rates_id",ratesId).eq("set_name", UserFeeSettingEnum.CTF.getDesc())).getSetValue();
|
// tCompanyResp.setName(UserFeeSettingEnum.CTF.getDesc());
|
// tCompanyResp.setPrice(setValue1);
|
// objects.add(tCompanyResp);
|
}
|
|
|
|
BigDecimal bigDecimal = objects.stream().map(e -> e.getPrice()==null?new BigDecimal(0):e.getPrice()).reduce(BigDecimal::add).get();
|
// 生成订单
|
TOrder tOrder = new TOrder();
|
tOrder.setCity(city.getId());
|
tOrder.setState(state.getId());
|
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());
|
if("0".equals(demandDto.getWarehouse())){
|
tOrder.seteAddress(AddressLookup.getAddress(demandDto.getZipCode()));
|
}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.setWarehouse(demandDto.getWarehouse());
|
tOrder.setStatus("17");
|
tOrder.setInvoiceNumber(s2);
|
tOrder.setCompanyId(company.getId());
|
tOrder.setCreateTime(new Date());
|
orderService.insert(tOrder);
|
tOrders.add(tOrder);
|
tOrder.setAllTotal(bigDecimal);
|
orderService.updateById(tOrder);
|
objects.stream().forEach(e->e.setOrderId(tOrder.getId()));
|
orderId= tOrder.getId();
|
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());
|
tGoods.setLineStr(goodsDto.getLineStr());
|
tGoods1.add(tGoods);
|
|
String randomNumber = ToolUtil.getRandomNumber(10);
|
for (TCompanyResp object : objects) {
|
TPrice tPrice = new TPrice();
|
tPrice.setCreateTime(new Date());
|
tPrice.setOrderId(orderId);
|
tPrice.setState("1");
|
tPrice.setPrice(object.getAdminPrice());
|
tPrice.setCarPrice(object.getPrice());
|
tPrice.setType(object.getName());
|
tPrice.setStatus(1);
|
tPrice.setNumber(randomNumber);
|
tPrice.setDay(object.getDay());
|
tPrices.add(tPrice);
|
}
|
if(tPrices.size()>0){
|
priceService.insertBatch(tPrices);
|
}
|
}
|
if(tGoods1.size()>0){
|
|
goodsService.insertBatch(tGoods1);
|
}
|
|
|
|
}
|
|
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());
|
tCompanyCalculationResp.setCompanyName(company.getName());
|
tCompanyCalculationResp.setImg(company.getHeadImg());
|
tCompanyCalculationResp.setExpirationDate(company.getExpirationTime());
|
|
// 起点经纬度
|
tCompanyCalculationResp.setStartLon(String.valueOf(1));
|
tCompanyCalculationResp.setStartLat(String.valueOf(1));
|
|
// 目的地经纬度
|
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));
|
System.out.println(company.getId());
|
System.out.println(ratesId);
|
GeocodeVo geocode1 = googleMapUtil.getGeocode(tWarehouse.getAddress());
|
tCompanyCalculationResp.setEndLon(String.valueOf(geocode1.getLng()));
|
tCompanyCalculationResp.setEndLat(String.valueOf(geocode1.getLat()));
|
tCompanyCalculationRespList.add(tCompanyCalculationResp);
|
}else {
|
String zipCode = demandDto.getZipCode();
|
GeocodeVo geocode1 = googleMapUtil.getGeocode(AddressLookup.getAddress(zipCode));
|
tCompanyCalculationResp.setEndLon(String.valueOf(geocode1.getLng()));
|
tCompanyCalculationResp.setEndLat(String.valueOf(geocode1.getLat()));
|
// tCompanyCalculationResp.setEndLon(String.valueOf(1));
|
// tCompanyCalculationResp.setEndLat(String.valueOf(1));
|
tCompanyCalculationRespList.add(tCompanyCalculationResp);
|
}
|
|
|
}
|
if(count==companies.size()){
|
return new com.stylefeng.guns.modular.system.utils.tips.ErrorTip(5001,"No truck company was matched to meet the demand");
|
}
|
}
|
for (TCompanyCalculationResp tCompanyCalculationResp : tCompanyCalculationRespList) {
|
tCompanyCalculationResp.setQuoteId(tQuote.getId());
|
}
|
if(0==tCompanyCalculationRespList.size()){
|
return new com.stylefeng.guns.modular.system.utils.tips.ErrorTip(5001,"No truck company was matched to meet the demand");
|
}
|
return new SuccessTip(tCompanyCalculationRespList);
|
}
|
|
|
|
private String getStr(String str){
|
if(str==null){
|
return null;
|
}
|
String s = "";
|
String[] split = str.split(",");
|
if(split.length==1){
|
if(split[0].equals("CTF") || split[0].equals("URGENT FEE") || split[0].equals("PIPERPASS")){
|
return s;
|
}else {
|
s=split[0];
|
return s;
|
}
|
}else {
|
for (int i = 0; i < split.length; i++) {
|
if(!split[i].equals("CTF")&&!split[i].equals("URGENT FEE") && !split[i].equals("PIPERPASS")){
|
if(i==split.length-1){
|
s+=split[i];
|
}else {
|
s+=split[i]+",";
|
}
|
}
|
}
|
return s;
|
}
|
}
|
|
public static String getRandomNumber(int length) {
|
String base = "0123456789";
|
Random random = new Random();
|
StringBuffer sb = new StringBuffer();
|
|
for(int i = 0; i < length; ++i) {
|
int number = random.nextInt(base.length());
|
sb.append(base.charAt(number));
|
}
|
|
return sb.toString();
|
}
|
|
|
|
|
@ApiOperation(value = "支付前获取订单信息",notes="支付前获取订单信息")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "id", value = "需求id", required = true, dataType = "Long"),
|
})
|
@GetMapping(value = "/getQuotaFromIdForPay")
|
@ResponseBody
|
public Object getQuotaFromIdForPay(Long id) {
|
TQuote quote = quoteService.selectById(id);
|
List<TOrder> orders = orderService.selectList(new EntityWrapper<TOrder>().eq("e_zip_z", quote.getOrderId()).eq("status", 0));
|
ArrayList<TGoods> goods = new ArrayList<>();
|
BigDecimal bigDecimal = new BigDecimal(0);
|
ArrayList<TPrice> tPrices = new ArrayList<>();
|
for (TOrder order : orders) {
|
TGoods tGoods = goodsService.selectOne(new EntityWrapper<TGoods>().eq("order_id", order.getId()));
|
goods.add(tGoods);
|
List<TPrice> prices = priceService.selectList(new EntityWrapper<TPrice>().eq("order_id", order.getId()));
|
tPrices.addAll(prices);
|
bigDecimal=bigDecimal.add(prices.stream().map(TPrice::getPrice).reduce(BigDecimal.ZERO,BigDecimal::add));
|
}
|
Map<String, BigDecimal> sumMap = tPrices.stream()
|
.collect(Collectors.groupingBy(TPrice::getType, Collectors.reducing(BigDecimal.ZERO, TPrice::getPrice, BigDecimal::add)));
|
List<PriceList> pricesList = sumMap.entrySet().stream()
|
.map(entry -> new PriceList(entry.getKey(), entry.getValue()))
|
.collect(Collectors.toList());
|
Integer userId = orders.get(0).getUserId();
|
TUser tUser = userService.selectById(userId);
|
String residueLimit = tUser.getResidueLimit();
|
HashMap<String, Object> map = new HashMap<>();
|
map.put("money",bigDecimal);
|
map.put("data",goods);
|
map.put("residueLimit",residueLimit);
|
map.put("prices",pricesList);
|
return new SuccessTip(map);
|
}
|
|
|
|
@ApiOperation(value = "发布需求-第二步/修改需求",notes="发布需求-第二步/修改需求")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@PostMapping(value = "/updateDemandTwo")
|
@ResponseBody
|
public Object updateDemandTwo(@RequestBody DemandTwoDto demandDtoTwo) {
|
Set<Long> integers = new HashSet<>();
|
for (DemandDtoTwo dtoTwo : demandDtoTwo.getDemandDtoTwo()) {
|
List<TGoods> list = dtoTwo.getList();
|
for (TGoods tGoods : list) {
|
integers.add(tGoods.getOrderId());
|
}
|
goodsService.updateBatchById(list);
|
}
|
List<TOrder> orders = new ArrayList<>();
|
for (DemandDtoTwo dtoTwo : demandDtoTwo.getDemandDtoTwo()) {
|
TOrder tOrder = new TOrder();
|
TOrder tOrder1 = orderService.selectById(dtoTwo.getId());
|
List<TOrder> orders1 = orderService.selectList(new EntityWrapper<TOrder>().eq("e_zip_z", tOrder1.geteZipZ()));
|
for (TOrder order : orders1) {
|
order.setsName(dtoTwo.getSName());
|
order.setsPhone(dtoTwo.getSPhone());
|
order.setsEmail(dtoTwo.getSEmail());
|
order.setePhone(dtoTwo.getEPhone());
|
order.seteEmail(dtoTwo.getEEmail());
|
order.seteName(dtoTwo.getEName());
|
if(dtoTwo.getEAddress()!=null && !"".equals(dtoTwo.getEAddress())){
|
order.seteAddress(dtoTwo.getEAddress());
|
}
|
orders.add(order);
|
}
|
}
|
orderService.updateBatchById(orders);
|
List<TUserFeeSetting> tUserFeeSettings =null;
|
Long next = integers.iterator().next();
|
TOrder tOrder1 = orderService.selectById(next);
|
Integer userId = tOrder1.getUserId();
|
TUser tUser = userService.selectById(userId);
|
if(tUser.getGroupId()!=null){
|
TGroup tGroup = groupService.selectById(tUser.getGroupId());
|
if(tGroup!=null) {
|
tUserFeeSettings = userFeeSettingService.selectList(new EntityWrapper<TUserFeeSetting>().eq("user_id", tGroup.getSalesId()));
|
}
|
}
|
|
for (Long order : integers) {
|
TOrder tOrder = orderService.selectById(order);
|
String s = tOrder.geteZipZ();
|
TQuote quote = quoteService.selectOne(new EntityWrapper<TQuote>().eq("order_id", s));
|
quote.setState(1);
|
quoteService.updateById(quote);
|
tOrder.setStatus("0");
|
BigDecimal bigDecimal = new BigDecimal(0);
|
// 通过每个订单 找出当前的用户的sale 找出提成算出应给卡车公司的价格
|
List<TPrice> prices = priceService.selectList(new EntityWrapper<TPrice>().eq("order_id", order).eq("status",1));
|
// if(tUserFeeSettings!=null && tUserFeeSettings.size()>0){
|
// for (TUserFeeSetting tUserFeeSetting : tUserFeeSettings) {
|
// for (TPrice price : prices) {
|
// if(tUserFeeSetting.getName().equals(price.getType())){
|
// double v = (double) tUserFeeSetting.getFee() / 100;
|
// BigDecimal multiply = price.getPrice().multiply(new BigDecimal(v));
|
// // 付卡车的钱
|
// BigDecimal subtract = price.getPrice().subtract(multiply);
|
// price.setCarPrice(subtract);
|
// bigDecimal = bigDecimal.add(subtract);
|
// }else {
|
// price.setCarPrice(price.getPrice());
|
// bigDecimal = bigDecimal.add(price.getPrice());
|
// }
|
// }
|
// }
|
// }else {
|
// prices.stream().forEach(e->e.setCarPrice(e.getPrice()));
|
// }
|
// priceService.updateBatchById(prices);
|
for (TPrice price : prices) {
|
bigDecimal = bigDecimal.add(price.getPrice());
|
}
|
tOrder.setPayMoney(bigDecimal);
|
orderService.updateById(tOrder);
|
|
}
|
return new SuccessTip();
|
}
|
|
@ApiOperation(value = "发布需求-第二步-通过订单id查询货物",notes="发布需求-第二步-通过订单id查询货物")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@PostMapping(value = "/queryDemandTwo")
|
@ResponseBody
|
public Object queryDemandTwo(@RequestBody String ids) {
|
List<String> strings = Arrays.asList(ids.split(","));
|
|
List<TGoods> goods = goodsService.selectList(new EntityWrapper<TGoods>().in("order_id", strings));
|
return new SuccessTip(goods);
|
|
}
|
|
@ApiOperation(value = "需求列表",notes="需求列表")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@PostMapping(value = "/queryDemandList")
|
@ResponseBody
|
public Object queryDemandList( @RequestBody QueryDemandListDto queryDemandListDto ) {
|
Page<DemandListVo> objectPage = new Page<>(queryDemandListDto.getPageNumber(),queryDemandListDto.getPageSize());
|
List<DemandListVo> list = new ArrayList<>();
|
list = quoteService.queryDemandList(objectPage,queryDemandListDto.getTime(),queryDemandListDto.getState(),queryDemandListDto.getUserId(),queryDemandListDto.getAccount());
|
objectPage.setRecords(list);
|
return new SuccessTip(objectPage);
|
}
|
|
@ApiOperation(value = "需求列表导出",notes="需求列表导出")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@GetMapping(value = "/demandListExport")
|
@ResponseBody
|
public Object demandListExport( String time,Integer state,Integer userId,String account, HttpServletResponse response ) {
|
List<DemandListVo> list = new ArrayList<>();
|
list = quoteService.queryDemandListExport(time,state,userId,account);
|
try {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String time1 = format.format(date);
|
String fileName = "Quote"+time1+".xls";
|
String[] title = new String[] {"ID","CUSTOMER","PICKUP DATE","ORIGIN","DESTINATION",
|
"LOAD","STATE"};
|
String[][] values = new String[list.size()][];
|
for (int i = 0; i < list.size(); i++) {
|
DemandListVo d = list.get(i);
|
values[i] = new String[title.length];
|
values[i][0] = d.getId().toString();
|
values[i][1] = d.getUserCompanyName()+"、"+d.getUserId();
|
values[i][2] = d.getPickupDate()==null?"":d.getPickupDate().toString();
|
values[i][3] = d.getOrigin();
|
values[i][4] = d.getDestination();
|
values[i][5] = d.getWeight();
|
values[i][6] = d.getState()==0?"In quotation":(d.getState()==1?"Pending payment":"canceled");
|
}
|
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Quote"+time1, title, values, null);
|
this.setResponseHeader(response, fileName);
|
OutputStream os = response.getOutputStream();
|
wb.write(os);
|
os.flush();
|
os.close();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new ErrorTip(5001,"ERROR");
|
}
|
return SUCCESS_TIP;
|
|
|
}
|
|
private void setResponseHeader(HttpServletResponse response, String fileName) {
|
try {
|
/*try {
|
fileName = new String(fileName.getBytes(), "UTF-8");
|
} catch (UnsupportedEncodingException e) {
|
e.printStackTrace();
|
}*/
|
response.setContentType("application/octet-stream;charset=UTF-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
|
response.addHeader("Pargam", "no-cache");
|
response.addHeader("Cache-Control", "no-cache");
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
}
|
}
|
|
@ApiOperation(value = "删除需求",notes="删除需求")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "id", value = "需求id", required = true, dataType = "Long"),
|
})
|
@PostMapping(value = "/deleteDemand")
|
@ResponseBody
|
public Object deleteDemand( Long id ) {
|
TQuote tQuote = quoteService.selectById(id);
|
tQuote.setState(3);
|
quoteService.updateById(tQuote);
|
return new SuccessTip();
|
}
|
|
|
|
@ApiOperation(value = "获取state",notes="获取state")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "name", value = "state name", required = false, dataType = "String"),
|
})
|
@GetMapping(value = "/getState")
|
@ResponseBody
|
public Object getState( String name) {
|
EntityWrapper<TCountry> tCountryEntityWrapper = new EntityWrapper<>();
|
tCountryEntityWrapper.eq("type",2).eq("remove",0);
|
if(Objects.nonNull(name)){
|
tCountryEntityWrapper.like("name",name);
|
}
|
List<TCountry> tCountries = service.selectList(tCountryEntityWrapper);
|
return new SuccessTip(tCountries);
|
}
|
|
@ApiOperation(value = "获取city",notes="获取city")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "name", value = "city name", required = false, dataType = "String"),
|
@ApiImplicitParam(name = "id", value = "state id", required = true, dataType = "String"),
|
})
|
@GetMapping(value = "/getCity")
|
@ResponseBody
|
public Object getState( String name,Integer id) {
|
EntityWrapper<TCountry> tCountryEntityWrapper = new EntityWrapper<>();
|
tCountryEntityWrapper.eq("type",3).eq("remove",0).eq("parent_id",id);
|
if(Objects.nonNull(name)){
|
tCountryEntityWrapper.like("name",name);
|
}
|
List<TCountry> tCountries = service.selectList(tCountryEntityWrapper);
|
return new SuccessTip(tCountries);
|
}
|
|
|
@ApiOperation(value = "获取port",notes="获取port")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "name", value = "port name", required = false, dataType = "String"),
|
@ApiImplicitParam(name = "id", value = "city id", required = true, dataType = "String"),
|
})
|
@GetMapping(value = "/getPort")
|
@ResponseBody
|
public Object getPort( String name,Integer id) {
|
EntityWrapper<TPort> wrapper = new EntityWrapper<>();
|
wrapper.eq("remove",0).eq("city",id);
|
if(Objects.nonNull(name)){
|
wrapper.like("name",name);
|
}
|
List<TPort> tCountries = itPortService.selectList(wrapper);
|
return new SuccessTip(tCountries);
|
}
|
|
|
@ApiOperation(value = "获取亚马逊仓库",notes="获取亚马逊仓库")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@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"),
|
})
|
@GetMapping(value = "/getWarehouse")
|
@ResponseBody
|
public Object getWarehouse( String address,int pageNumber,int pageSize) {
|
Page<TWarehouse> tWarehousePage = new Page<>(pageNumber, pageSize);
|
|
EntityWrapper<TWarehouse> tWarehouseEntityWrapper = new EntityWrapper<>();
|
tWarehouseEntityWrapper.eq("company_id",0);
|
if(Objects.nonNull(address)){
|
tWarehouseEntityWrapper.like("code",address);
|
}
|
Page<TWarehouse> tWarehousePage1 = warehouseService.selectPage(tWarehousePage, tWarehouseEntityWrapper);
|
|
return new SuccessTip(tWarehousePage1);
|
}
|
|
@ApiOperation(value = "获取服务",notes="获取服务")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
})
|
@GetMapping(value = "/getServices")
|
@ResponseBody
|
public Object getServices() {
|
List<TCompanyService> companyServiceList = tCompanyServiceService.selectList(new EntityWrapper<TCompanyService>().eq("company_id", 2));
|
return new SuccessTip(companyServiceList);
|
}
|
|
@ApiOperation(value = "根据需求id获取需求",notes="根据需求id获取需求")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "id", value = "需求id", required = true, dataType = "Long"),
|
})
|
@GetMapping(value = "/getQuotaFromId")
|
@ResponseBody
|
public Object getQuotaFromId(Long id) {
|
TCompanyCalculationRespOne list =tCompanyService.getQuotaFromId(id);
|
return new SuccessTip(list);
|
}
|
|
|
@ApiOperation(value = "根据需求id获取需求-选择公司",notes="根据需求id获取需求-选择公司")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
|
@ApiImplicitParam(name = "id", value = "需求id", required = true, dataType = "Long"),
|
@ApiImplicitParam(name = "companyId", value = "companyId", required = true, dataType = "int"),
|
})
|
@GetMapping(value = "/getQuotaFromIdAndCompanyId")
|
@ResponseBody
|
public Object getQuotaFromIdAndCompanyId(Long id,Integer companyId) {
|
TCompanyCalculationRespOne list =tCompanyService.getQuotaFromIdAndCompanyId(id,companyId);
|
return new SuccessTip(list);
|
}
|
|
|
}
|