package com.stylefeng.guns.modular.system.controller.specialTrain;
|
|
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.common.constant.factory.PageFactory;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.util.SinataUtil;
|
import com.stylefeng.guns.modular.system.model.TServerCarmodel;
|
import com.stylefeng.guns.modular.system.service.ITServerCarmodelService;
|
import com.stylefeng.guns.modular.system.util.PushMinistryOfTransportUtil;
|
import net.sf.json.JSONObject;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import com.stylefeng.guns.core.log.LogObjectHolder;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import com.stylefeng.guns.modular.system.model.TSystemPrice;
|
import com.stylefeng.guns.modular.system.service.ITSystemPriceService;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 专车价格设置控制器
|
*
|
* @author fengshuonan
|
* @Date 2020-08-29 10:50:13
|
*/
|
@Controller
|
@RequestMapping("/tSystemPrice")
|
public class TSystemPriceController extends BaseController {
|
|
private String PREFIX = "/system/tSystemPrice/";
|
|
@Autowired
|
private ITSystemPriceService tSystemPriceService;
|
|
@Autowired
|
private ITServerCarmodelService tServerCarmodelService;
|
|
@Autowired
|
private PushMinistryOfTransportUtil pushMinistryOfTransportUtil;
|
|
@Value("${pushMinistryOfTransport}")
|
private boolean pushMinistryOfTransport;
|
|
|
|
|
/**
|
* 跳转到专车价格设置首页
|
*/
|
@RequestMapping("/special")
|
public String index() {
|
return PREFIX + "tSystemPrice.html";
|
}
|
|
/**
|
* 跳转到小件物流价格设置首页
|
*/
|
@RequestMapping("/small")
|
public String small(Model model) {
|
//跨城小件物流
|
TSystemPrice one = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 5).eq("companyId", ShiroKit.getUser().getObjectId()));
|
if (SinataUtil.isNotEmpty(one)){
|
JSONObject json1 = JSONObject.fromObject(one.getContent());
|
model.addAttribute("json1",json1);
|
}
|
//同城小件物流
|
TSystemPrice two = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 4).eq("companyId", ShiroKit.getUser().getObjectId()));
|
if (SinataUtil.isNotEmpty(two)){
|
JSONObject json2 = JSONObject.fromObject(two.getContent());
|
model.addAttribute("json2",json2);
|
}
|
return PREFIX + "small.html";
|
}
|
|
/**
|
* 跳转到添加专车价格设置
|
*/
|
@RequestMapping("/tSystemPrice_add")
|
public String tSystemPriceAdd(Model model) {
|
//查询所有专车车型
|
List<TSystemPrice> tSystemPrices = tSystemPriceService.selectList(new EntityWrapper<TSystemPrice>().eq("type", 1).ne("state", 3));
|
List<TServerCarmodel> modelList = tServerCarmodelService.selectList(new EntityWrapper<TServerCarmodel>().eq("type", 1).eq("state", 1));
|
List<TServerCarmodel> serverCarmodels = new ArrayList<>();
|
for(TServerCarmodel tsc : modelList){
|
boolean b = true;
|
for(TSystemPrice tsp : tSystemPrices){
|
if(tsc.getId() == tsp.getServerCarModelId()){
|
b = false;
|
break;
|
}
|
}
|
if(b){
|
serverCarmodels.add(tsc);
|
}
|
}
|
model.addAttribute("modelList",serverCarmodels);
|
return PREFIX + "tSystemPrice_add.html";
|
}
|
|
/**
|
* 跳转到修改专车价格设置
|
*/
|
@RequestMapping("/tSystemPrice_update/{tSystemPriceId}")
|
public String tSystemPriceUpdate(@PathVariable Integer tSystemPriceId, Model model) {
|
TSystemPrice tSystemPrice = tSystemPriceService.selectById(tSystemPriceId);
|
model.addAttribute("item",tSystemPrice);
|
LogObjectHolder.me().set(tSystemPrice);
|
|
JSONObject json = JSONObject.fromObject(tSystemPrice.getContent());
|
model.addAttribute("json",json);
|
|
//查询所有专车车型
|
List<TSystemPrice> tSystemPrices = tSystemPriceService.selectList(new EntityWrapper<TSystemPrice>().eq("type", 1).ne("state", 3));
|
List<TServerCarmodel> modelList = tServerCarmodelService.selectList(new EntityWrapper<TServerCarmodel>().eq("type", 1).eq("state", 1));
|
List<TServerCarmodel> serverCarmodels = new ArrayList<>();
|
for(TServerCarmodel tsc : modelList){
|
boolean b = true;
|
for(TSystemPrice tsp : tSystemPrices){
|
if(tsc.getId() == tsp.getServerCarModelId() && tsc.getId() != tSystemPriceId){
|
b = false;
|
break;
|
}
|
}
|
if(b){
|
serverCarmodels.add(tsc);
|
}
|
}
|
model.addAttribute("modelList",serverCarmodels);
|
|
return PREFIX + "tSystemPrice_edit.html";
|
}
|
|
/**
|
* 获取专车价格设置列表
|
*/
|
@RequestMapping(value = "/listSpecial")
|
@ResponseBody
|
public Object list(String name,Integer state) {
|
Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
|
page.setRecords(tSystemPriceService.getSpecialPriceList(page,ShiroKit.getUser().getObjectId(),name,state));
|
return super.packForBT(page);
|
}
|
|
/**
|
* 新增专车价格设置
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TSystemPrice tSystemPrice) {
|
//判断当前公司是否添加过该专车车型价格配置
|
int count = tSystemPriceService.selectCount(new EntityWrapper<TSystemPrice>()
|
.eq("type", 1)
|
.eq("serverCarModelId", tSystemPrice.getServerCarModelId())
|
.eq("companyId",ShiroKit.getUser().getObjectId())
|
.last(" and not FIND_IN_SET(state,'3')"));
|
if (count > 0){
|
TServerCarmodel one = tServerCarmodelService.selectById(tSystemPrice.getServerCarModelId());
|
return new ErrorTip(500, "【"+one.getName()+"】已存在,请重新选择");
|
}
|
tSystemPrice.setCompanyId(ShiroKit.getUser().getObjectId());
|
tSystemPrice.setType(1);
|
tSystemPrice.setState(1);
|
tSystemPriceService.insert(tSystemPrice);
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
if(pushMinistryOfTransport){//上传数据
|
pushMinistryOfTransportUtil.baseInfoCompanyFare(tSystemPrice.getId());
|
}
|
}
|
}).start();
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改专车价格设置
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TSystemPrice tSystemPrice) {
|
TSystemPrice obj = tSystemPriceService.selectById(tSystemPrice.getId());
|
if (obj.getServerCarModelId() != tSystemPrice.getServerCarModelId()){
|
//判断当前公司是否添加过该专车车型价格配置
|
int count = tSystemPriceService.selectCount(new EntityWrapper<TSystemPrice>()
|
.eq("type", 1)
|
.eq("serverCarModelId", tSystemPrice.getServerCarModelId())
|
.eq("companyId",ShiroKit.getUser().getObjectId())
|
.last(" and not FIND_IN_SET(state,'3')"));
|
if (count > 0){
|
TServerCarmodel one = tServerCarmodelService.selectById(tSystemPrice.getServerCarModelId());
|
return new ErrorTip(500, "【"+one.getName()+"】已存在,请重新选择");
|
}
|
}
|
tSystemPriceService.updateById(tSystemPrice);
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
if(pushMinistryOfTransport) {//上传数据
|
pushMinistryOfTransportUtil.baseInfoCompanyFare(tSystemPrice.getId());
|
}
|
}
|
}).start();
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改状态
|
*/
|
@RequestMapping(value = "/opt")
|
@ResponseBody
|
public Object opt(Integer optType,Integer tSystemPriceId) {
|
TSystemPrice systemPrice = new TSystemPrice();
|
if (1 == optType){ //冻结
|
systemPrice.setState(2);
|
}else if (2 == optType){ //解冻
|
systemPrice.setState(1);
|
}else if (3 == optType){ //删除
|
systemPrice.setState(3);
|
}
|
tSystemPriceService.update(systemPrice,new EntityWrapper<TSystemPrice>().eq("id",tSystemPriceId));
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 小件物流价格设置
|
*/
|
@RequestMapping(value = "/smallSubmit")
|
@ResponseBody
|
public Object smallSubmit(String json1,String json2) {
|
//跨城小件物流
|
TSystemPrice one = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 5).eq("companyId", ShiroKit.getUser().getObjectId()));
|
if (SinataUtil.isNotEmpty(one)){
|
one.setContent(json1);
|
tSystemPriceService.updateById(one);
|
}else{
|
one = new TSystemPrice();
|
one.setState(1);
|
one.setType(5);
|
one.setCompanyId(ShiroKit.getUser().getObjectId());
|
one.setContent(json1);
|
tSystemPriceService.insert(one);
|
}
|
//同城小件物流
|
TSystemPrice two = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 4).eq("companyId", ShiroKit.getUser().getObjectId()));
|
if (SinataUtil.isNotEmpty(two)){
|
two.setContent(json2);
|
tSystemPriceService.updateById(two);
|
}else{
|
two = new TSystemPrice();
|
two.setState(1);
|
two.setType(4);
|
two.setCompanyId(ShiroKit.getUser().getObjectId());
|
two.setContent(json2);
|
tSystemPriceService.insert(two);
|
}
|
return SUCCESS_TIP;
|
}
|
|
}
|