package com.stylefeng.guns.modular.system.controller; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.stylefeng.guns.modular.system.dao.TPortMapper; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; 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.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @Controller @Api(tags = "费用设置") @RequestMapping("/api/rates") public class RatesController { @Resource private ITRatesService ratesService; @Resource private ITCountryService countryService; @Resource private IWarehouseService warehouseService; @Resource private ITCompanyBasicService basicService; @ApiOperation(value = "卡车公司-获取港区设置列表",notes="卡车公司-获取港区设置列表") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "id", value = "当前公司id", required = true, dataType = "int",paramType = "query"), }) @GetMapping(value = "/metroList") @ResponseBody public Object metroList(int pageNumber,int pageSize,int id) { Page tRatesPage = new Page<>(pageNumber, pageSize); Page tRates = ratesService.selectPage(tRatesPage,new EntityWrapper().eq("company_id", id).eq("type", 1)); Page tRatesVoPage = new Page<>(); BeanUtil.copyProperties(tRates,tRatesVoPage); ArrayList tRatesVos = new ArrayList<>(); for (TRates record : tRates.getRecords()) { TRatesVo tRatesVo = new TRatesVo(); tRatesVo.setId(record.getId()); tRatesVo.setRemarks(record.getRemarks()); // city TCountry tCountry = countryService.selectById(record.getMetroId()); tRatesVo.setMetro(tCountry.getName()); tRatesVo.setZipCode(tCountry.getZipCode()); // state TCountry tCountry1 = countryService.selectById(tCountry.getParentId()); tRatesVo.setState(tCountry1.getName()); tRatesVos.add(tRatesVo); } tRatesVoPage.setRecords(tRatesVos); return new SuccessTip(tRatesVoPage); } @Resource private TPortMapper tPortMapper; @ApiOperation(value = "卡车公司-获取特殊码头列表",notes="卡车公司-获取特殊码头列表") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "id", value = "当前公司id", required = true, dataType = "int",paramType = "query"), }) @GetMapping(value = "/specialPortList") @ResponseBody public Object specialPortList(int pageNumber,int pageSize,int id) { Page tRatesPage = new Page<>(pageNumber, pageSize); Page tRates = ratesService.selectPage(tRatesPage,new EntityWrapper().eq("company_id", id).eq("type", 2)); Page tRatesVoPage = new Page<>(); BeanUtil.copyProperties(tRates,tRatesVoPage); ArrayList tRatesVos = new ArrayList<>(); for (TRates record : tRates.getRecords()) { TRatesVoOne tRatesVo = new TRatesVoOne(); tRatesVo.setId(record.getId()); tRatesVo.setRemarks(record.getRemarks()); // city TPort tPort = tPortMapper.selectById(record.getMetroId()); tRatesVo.setAddress(tPort.getAddress()); tRatesVo.setZipCode(tPort.getZipCode()); TCountry tCountry = countryService.selectById(tPort.getCity()); tRatesVo.setMetro(tCountry.getName()); // state TCountry tCountry1 = countryService.selectById(tCountry.getParentId()); tRatesVo.setState(tCountry1.getName()); tRatesVos.add(tRatesVo); } tRatesVoPage.setRecords(tRatesVos); return new SuccessTip(tRatesVoPage); } @ApiOperation(value = "卡车公司-获取所有port",notes="卡车公司-获取所有port") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @GetMapping(value = "/portList") @ResponseBody public Object portList() { List tCountries = tPortMapper.selectList(new EntityWrapper().eq("remove", 0)); return new SuccessTip(tCountries); } @ApiOperation(value = "卡车公司-获取所有state",notes="卡车公司-获取所有state") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @GetMapping(value = "/stateList") @ResponseBody public Object stateList() { List tCountries = countryService.selectList(new EntityWrapper().eq("type", 2).eq("remove", 0)); return new SuccessTip(tCountries); } @ApiOperation(value = "卡车公司-根据stateId获取所有city",notes="卡车公司-根据stateId获取所有city") @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 = "int",paramType = "query"), }) @GetMapping(value = "/cityList") @ResponseBody public Object cityList(int id) { List tCountries = countryService.selectList(new EntityWrapper().eq("type", 3).eq("remove", 0).eq("parent_id",id)); return new SuccessTip(tCountries); } @ApiOperation(value = "卡车公司- 添加港区设置/特殊码头",notes="卡车公司-添加港区设置/特殊码头") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @PostMapping(value = "/addMetro") @ResponseBody public Object addMetro(@RequestBody TRates tRates) { ratesService.insert(tRates); List tWarehouses = warehouseService.selectList(new EntityWrapper().eq("company_id", 0)); tWarehouses.stream().forEach(e->{ e.setPortId(tRates.getId()); }); ExecutorService executorService = Executors.newCachedThreadPool(); executorService.submit(new Runnable() { @Override public void run() { warehouseService.insertBatch(tWarehouses); } }); return new SuccessTip(); } @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 = "int",paramType = "query"), }) @GetMapping(value = "/metroInfo") @ResponseBody public Object metroInfo(int id) { TRatesInfo tRatesInfo = new TRatesInfo(); TRates tRates = ratesService.selectById(id); tRatesInfo.setId(tRates.getId()); tRatesInfo.setRemarks(tRates.getRemarks()); tRatesInfo.setMetroId(tRates.getMetroId()); TCountry tCountry = countryService.selectById(tRates.getMetroId()); tRatesInfo.setStateId(tCountry.getParentId()); return new SuccessTip(tRatesInfo); } @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 = "int",paramType = "query"), }) @GetMapping(value = "/specialPortInfo") @ResponseBody public Object specialPortInfo(int id) { TRatesInfoOne tRatesInfo = new TRatesInfoOne(); TRates tRates = ratesService.selectById(id); tRatesInfo.setId(tRates.getId()); tRatesInfo.setRemarks(tRates.getRemarks()); tRatesInfo.setPortId(tRates.getMetroId()); return new SuccessTip(tRatesInfo); } @ApiOperation(value = "卡车公司- 修改港区设置",notes="卡车公司-修改港区设置") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @PostMapping(value = "/updateMetro") @ResponseBody public Object updateMetro(@RequestBody TRates tRates) { ratesService.updateById(tRates); return new SuccessTip(); } @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 = "int",paramType = "query"), }) @GetMapping(value = "/deleteMetro") @ResponseBody public Object deleteMetro( int id) { ratesService.deleteById(id); warehouseService.delete(new EntityWrapper().eq("port_id",id)); return new SuccessTip(); } @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/特殊码头id", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), }) @GetMapping(value = "/getWarehouseFromId") @ResponseBody public Object getWarehouseFromId(int id,int pageNumber,int pageSize) { Page tWarehousePage = new Page<>(pageNumber, pageSize); Page tWarehouses = warehouseService.selectPage(tWarehousePage,new EntityWrapper().eq("port_id", id)); return new SuccessTip(tWarehouses); } @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/特殊码头id", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "money", value = "money", required = true, dataType = "double",paramType = "query"), }) @GetMapping(value = "/setWarehousePrice") @ResponseBody public Object setWarehousePrice(int id,double money) { List tWarehouses = warehouseService.selectList(new EntityWrapper().eq("port_id", id)); tWarehouses.stream().forEach(e->e.setWarePrice(new BigDecimal(money))); warehouseService.updateBatchById(tWarehouses); return new SuccessTip(tWarehouses); } @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/特殊码头id", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "type", value = "1/2/3 点对点/范围/距离", required = true, dataType = "int",paramType = "query"), }) @GetMapping(value = "/getLane") @ResponseBody public Object getLane(int id,int pageNumber,int pageSize,int type) { Page tCompanyBasicPage = new Page<>(pageNumber, pageSize); Page basicPage = basicService.selectPage(tCompanyBasicPage,new EntityWrapper().eq("port_id", id).eq("type",type)); return new SuccessTip(basicPage); } @ApiOperation(value = "卡车公司- 添加点对点/范围/距离",notes="卡车公司-添加点对点/范围/距离") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @PostMapping(value = "/addLane") @ResponseBody public Object addLane(@RequestBody TCompanyBasic basic) { basicService.insert(basic); return new SuccessTip(); } @ApiOperation(value = "卡车公司- 编辑点对点/范围/距离",notes="卡车公司-编辑点对点/范围/距离") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @PostMapping(value = "/updateLane") @ResponseBody public Object updateLane(@RequestBody TCompanyBasic basic) { basicService.updateById(basic); return new SuccessTip(); } @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 = "int",paramType = "query"), }) @GetMapping(value = "/delLane") @ResponseBody public Object delLane( int id) { basicService.deleteById(id); return new SuccessTip(); } @Resource private ITCompanyFeeSettingService tCompanyFeeSettingMapper; @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 = "int",paramType = "query"), @ApiImplicitParam(name = "companyId", value = "当前公司id", required = true, dataType = "int",paramType = "query"), }) @GetMapping(value = "/getFee") @ResponseBody public Object getFee( int id,int companyId) { List feeSettings = tCompanyFeeSettingMapper.selectList(new EntityWrapper().eq("rates_id", id).eq("company_id", companyId)); return new SuccessTip(feeSettings); } @ApiOperation(value = "卡车公司- 添加费用",notes="卡车公司-添加费用\"") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @PostMapping(value = "/addFee") @ResponseBody public Object addFee(@RequestBody List feeSettings) { tCompanyFeeSettingMapper.insertBatch(feeSettings); return new SuccessTip(); } @ApiOperation(value = "卡车公司- 修改费用",notes="卡车公司-修改费用") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @PostMapping(value = "/updateFee") @ResponseBody public Object updateFee(@RequestBody List feeSettings) { tCompanyFeeSettingMapper.updateBatchById(feeSettings); return new SuccessTip(); } }