package com.mandi.fendan.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.UUID;
|
|
import javax.annotation.Resource;
|
import javax.transaction.Transactional;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
|
import com.mandi.common.ParamFileter.RegexCheck;
|
import com.mandi.dao.common.Daomethod;
|
import com.mandi.dao.common.ObjectResult;
|
import com.mandi.dao.common.PageRequest;
|
import com.mandi.dao.common.PageResult;
|
import com.mandi.fendan.mapper.Fd_BsheetMapper;
|
import com.mandi.fendan.mapper.Fd_CompanyMapper;
|
import com.mandi.fendan.mapper.Fd_VehicleMapper;
|
import com.mandi.fendan.mapper.VehicleXSTDMapper;
|
import com.mandi.fendan.persist.Fd_Bsheet;
|
import com.mandi.fendan.persist.Fd_Company;
|
import com.mandi.fendan.persist.Fd_Vehicle;
|
import com.mandi.fendan.persist.VehicleStatus;
|
import com.mandi.fendan.persist.VehicleType;
|
import com.mandi.fendan.persist.Vehicle_XSTD;
|
import com.mandi.fendan.service.Ifd_vehicleService;
|
import com.mandi.fendan.util.persist.Serviceenum;
|
import com.mandi.system.persist.Login;
|
import com.mandi.system.persist.UserType;
|
@Service
|
public class Fd_VehicleService implements Ifd_vehicleService {
|
@Resource
|
private Fd_VehicleMapper Fd_Vcper;
|
@Resource
|
private Fd_CompanyMapper fdcper;
|
@Resource
|
private Fd_BsheetMapper fdbper;
|
@Resource
|
private VehicleXSTDMapper vxper;
|
|
|
@Override
|
public ObjectResult<Fd_Vehicle> getFd_VehicleById(String id) {
|
ObjectResult<Fd_Vehicle> prr = new ObjectResult<Fd_Vehicle>();
|
if(!StringUtils.isBlank(id)){
|
Fd_Vehicle fve = Fd_Vcper.get(id);
|
prr.setCode(0);
|
prr.setItem(fve);
|
}else{
|
prr.setCode(1);
|
prr.setErrmsg("查询值为空,不能查询!");;
|
}
|
|
return prr;
|
|
}
|
public ObjectResult<Fd_Vehicle> getFd_VehicleByFd_VehicleId(String vehicleId) {
|
ObjectResult<Fd_Vehicle> prr = new ObjectResult<Fd_Vehicle>();
|
if(!StringUtils.isBlank(vehicleId)){
|
Fd_Vehicle fcy = Fd_Vcper.getByVehicleId(vehicleId);
|
prr.setCode(0);
|
prr.setItem(fcy);
|
}else{
|
prr.setCode(1);
|
prr.setErrmsg("车牌号不能为空");;
|
}
|
|
return prr;
|
}
|
@Override
|
public PageResult<Map<String, Object>> getList(Map<String,Object> map,PageRequest pr) {
|
PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
|
|
map.put("pagesize", pr.getPageSize());
|
map.put("page", pr.getStart());
|
map.put("type", VehicleType.公司车.toString());
|
List<Map<String, Object>> list;
|
if(pr.isNeedPages())
|
{
|
int pages=Fd_Vcper.getPages(map);
|
pages=Daomethod.countpages(pages, pr.getPageSize());
|
prr.setPages(pages);
|
list=Fd_Vcper.getList2(map);
|
}else{
|
list=Fd_Vcper.getList1(map);
|
prr.setPages(0);
|
}
|
|
prr.setCode(0);
|
prr.setList(list);
|
return prr;
|
}
|
|
@Override
|
public PageResult<Map<String, Object>> getalllist(Login lg,String companyNo,String vId) {
|
PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
|
List<Map<String, Object>> ll=new ArrayList<Map<String,Object>>();
|
if(lg==null){
|
prr.setCode(1);
|
prr.setErrmsg("请登录账号!");
|
return prr;
|
}
|
String cmc=companyNo;
|
Map<String, Object> map=new HashMap<String, Object>();
|
if(StringUtils.isEmpty(companyNo)){
|
if(UserType.admin.toString().equals(lg.getWorkerno())){
|
map.put("companyNo","");
|
cmc="";
|
}else{
|
prr.setList(ll);
|
prr.setCode(0);
|
return prr;
|
}
|
}else{
|
map.put("companyNo",companyNo);
|
}
|
map.put("vehicleId",vId);
|
List<Map<String, Object>> clist=Fd_Vcper.getCompanyVehicle(map);
|
if(clist==null){
|
clist=new ArrayList<Map<String,Object>>();
|
}
|
List<Map<String, Object>> rlist=new ArrayList<Map<String,Object>>();
|
if(clist!=null){
|
List<Vehicle_XSTD> vxlist=vxper.getlistbycomNo(cmc);
|
for (Map<String, Object> map2 : clist) {
|
String vehicleId=map2.get("vehicleId")==null?"":map2.get("vehicleId").toString();
|
// List<Vehicle_XSTD> vxlist=vxper.getlistbyVehicleId(vehicleId);
|
if(vxlist!=null){
|
for (Vehicle_XSTD vehicle_XSTD2 : vxlist) {
|
try{
|
if(vehicle_XSTD2.getVehicleId().equals(vehicleId)){
|
map2.put("fdCnum", Integer.parseInt(map2.get("fdCnum")==null?"0":map2.get("fdCnum").toString())+vehicle_XSTD2.getFd_num());
|
map2.put("fdCweight", Double.parseDouble(map2.get("fdCweight")==null?"0":map2.get("fdCweight").toString())+vehicle_XSTD2.getFd_weight());
|
if(vehicle_XSTD2.getCompanyNo()!=null&&vehicle_XSTD2.getCompanyNo().equals(lg.getDepartno())){
|
map2.put("fdnum", Double.parseDouble(map2.get("fdnum")==null?"0":map2.get("fdnum").toString())+vehicle_XSTD2.getFd_weight());
|
map2.put("fdweight", Double.parseDouble(map2.get("fdweight")==null?"0":map2.get("fdweight").toString())+vehicle_XSTD2.getFd_weight());
|
}
|
}
|
} catch (Exception e) {
|
prr.setCode(1);
|
prr.setErrmsg("数据转换错误,请刷新页面重新获取数据!");
|
return prr;
|
}
|
}
|
}
|
rlist.add(map2);
|
}
|
}
|
prr.setCode(0);
|
prr.setList(rlist);
|
return prr;
|
}
|
|
@Override
|
public ObjectResult<Boolean> validVehicle(Login lg, String vehicleId) {
|
ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
|
if(!StringUtils.isEmpty(vehicleId)){
|
boolean boo=RegexCheck.isVehicleID(vehicleId);
|
if(!boo){
|
orr.setCode(1);
|
orr.setErrmsg("车牌号验证不正确,请输入正确的车牌号!");
|
return orr;
|
}
|
}else{
|
orr.setCode(1);
|
orr.setErrmsg("参数车牌号为空,请输入!");
|
return orr;
|
}
|
orr.setCode(0);
|
return orr;
|
}
|
|
@Override
|
@Transactional(rollbackOn=Exception.class)
|
public ObjectResult<Fd_Vehicle> saveFd_Vehicle(Fd_Vehicle cq,Login lg) throws Exception {
|
ObjectResult<Fd_Vehicle> or = new ObjectResult<Fd_Vehicle>();
|
if(lg==null){
|
or.setCode(1);
|
or.setErrmsg("请登录账号!");
|
return or;
|
}
|
if(cq==null){
|
or.setCode(1);
|
or.setErrmsg("车辆对象为空,不能保存!");
|
}else{
|
if(StringUtils.isEmpty(cq.getVehicleId())||StringUtils.isEmpty(cq.getIDNum())||StringUtils.isEmpty(cq.getPhone())||StringUtils.isEmpty(cq.getDriver())){
|
or.setCode(1);
|
or.setErrmsg("必填项不能为空!");
|
return or;
|
}
|
String companyNo=cq.getCompanyNo();
|
Fd_Company fdc=fdcper.getByCompanyNo(companyNo);
|
if(fdc==null){
|
or.setCode(1);
|
or.setErrmsg("运输公司未找到,车辆信息不能保存,请选择正确的运输公司!");
|
return or;
|
}
|
if(StringUtils.isEmpty(cq.getVehicleId())){
|
or.setCode(1);
|
or.setErrmsg("车牌号不能为空,请修改后保存!");
|
return or;
|
}
|
boolean boo=RegexCheck.isVehicleID(cq.getVehicleId());
|
if(!boo){
|
or.setCode(1);
|
or.setErrmsg("车牌号不正确,请修改!");
|
return or;
|
}
|
Fd_Vehicle cc=Fd_Vcper.getByVehicleId(cq.getVehicleId());
|
if(cc!=null){
|
if(!cc.getId().equals(cq.getId())){
|
or.setCode(1);
|
or.setErrmsg("该车牌号已经存在,不能重复保存!");
|
return or;
|
}
|
}
|
|
// if(cq.getId()!=null){
|
Fd_Vehicle fd_Vehicle = Fd_Vcper.getByVehicleId(cq.getVehicleId());
|
if(fd_Vehicle==null){
|
cq.setId(UUID.randomUUID()+"");
|
cq.setState(true);
|
cq.setStatus(VehicleStatus.未配车);
|
cq.setType(VehicleType.公司车);
|
int insert = Fd_Vcper.insert(cq);
|
if(insert>0){
|
or.setCode(0);
|
or.setItem(cq);
|
}else{
|
or.setCode(1);
|
or.setErrmsg("保存失败");
|
}
|
}else{
|
cq.setStatus(cc.getStatus());
|
cq.setType(cc.getType());
|
int update = Fd_Vcper.update(cq);
|
or.setCode(0);
|
or.setItem(cq);
|
}
|
// }else{
|
// or.setCode(1);
|
// or.setErrmsg("对象主键不能为空");
|
// }
|
|
// Fd_Company_Vehicle fdvc=fdcvper.getbyIDs(cq.getVehicleId(), lg.getDepartno());
|
// if(fdvc==null){
|
// fdvc=new Fd_Company_Vehicle();
|
// fdvc.setCompanyNo(lg.getDepartno());
|
// fdvc.setVehicleId(cq.getVehicleId());
|
// fdcvper.insert(fdvc);
|
// }
|
|
|
}
|
return or;
|
}
|
|
|
|
|
@Override
|
@Transactional(rollbackOn=Exception.class)
|
public ObjectResult<Boolean> changeState(String vehicleId, Login lg, boolean state)
|
throws Exception {
|
ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
|
if(lg==null){
|
orr.setCode(1);
|
orr.setErrmsg("账号未登录,请重新登录!");
|
return orr;
|
}
|
Fd_Vehicle fv= Fd_Vcper.getByVehicleId(vehicleId);
|
if(fv==null){
|
orr.setCode(1);
|
orr.setErrmsg("该车辆不存在!");
|
return orr;
|
}
|
if(!UserType.admin.toString().equals(lg.getWorkerno())){
|
if(!StringUtils.isEmpty(lg.getDepartno())){
|
if(!lg.getDepartno().equals(fv.getCompanyNo())){
|
orr.setCode(1);
|
orr.setErrmsg("你没有权限修改分本公司车辆!");
|
return orr;
|
}
|
}
|
}
|
fv.setState(state);
|
Fd_Vcper.update(fv);
|
orr.setCode(0);
|
orr.setItem(state);
|
return orr;
|
}
|
@Override
|
@Transactional(rollbackOn=Exception.class)
|
public ObjectResult<Boolean> delFd_Vehicle(String vehicleId) throws Exception {
|
|
ObjectResult<Boolean> prr = new ObjectResult<Boolean>();
|
if(!StringUtils.isBlank(vehicleId)){
|
Fd_Vehicle fdv=Fd_Vcper.getByVehicleId(vehicleId);
|
if(fdv!=null){
|
List<Fd_Bsheet> fdb=fdbper.getListbyVehicleId(vehicleId,Serviceenum.在办);
|
if(fdb!=null&&!fdb.isEmpty()){
|
prr.setCode(1);
|
prr.setErrmsg("车辆有在办的提单,不能删除,等业务办完之后再删除!");
|
return prr;
|
}
|
// if(fdv.getStatus()!=VehicleStatus.未配车){
|
// prr.setCode(1);
|
// prr.setErrmsg("车辆状态不是未配车状态,不能删除!");
|
// return prr;
|
// }
|
}
|
int i = Fd_Vcper.delByVehicleId(vehicleId);
|
// fdcvper.delbyID(vehicleId);
|
prr.setCode(0);
|
prr.setItem(true);
|
}else{
|
prr.setCode(1);
|
prr.setItem(false);
|
prr.setErrmsg("车牌号不能为空");;
|
}
|
|
return prr;
|
}
|
|
}
|