package com.doumee.service.business.impl.wms;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.wms.model.request.*;
|
import com.doumee.core.wms.model.response.WmsBaseDataResponse;
|
import com.doumee.core.wms.model.response.WmsBaseResponse;
|
import com.doumee.dao.business.CarsMapper;
|
import com.doumee.dao.business.PlatformJobMapper;
|
import com.doumee.dao.business.PlatformWmsDetailMapper;
|
import com.doumee.dao.business.PlatformWmsJobMapper;
|
import com.doumee.dao.business.model.Cars;
|
import com.doumee.dao.business.model.PlatformJob;
|
import com.doumee.dao.business.model.PlatformWmsDetail;
|
import com.doumee.dao.business.model.PlatformWmsJob;
|
import com.doumee.service.business.WmsService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* WMS平台对接Service实现
|
* @author 江蹄蹄
|
* @date 2023/11/30 15:33
|
*/
|
@Service
|
public class WmsServiceImpl implements WmsService {
|
@Autowired
|
private PlatformWmsJobMapper platformWmsJobMapper;
|
@Autowired
|
private CarsMapper carsMapper;
|
@Autowired
|
private PlatformJobMapper platformJobMapper;
|
@Autowired
|
private PlatformWmsDetailMapper platformWmsDetailMapper;
|
|
/**
|
* 入库通知任务业务处理
|
* @param list 参数
|
* @return
|
*/
|
@Override
|
@Transactional
|
public WmsBaseResponse inboundNotice(List<WmsInboundNoticeRequest> list) {
|
if(list ==null || list.size() ==0){
|
return returnFailReuslt("请求参数不正确,参数不能为空");
|
}
|
List<PlatformJob> jobList = new ArrayList<>();
|
List<PlatformWmsDetail> details = new ArrayList<>();
|
List<String> iocodeList = new ArrayList<>();
|
for(WmsInboundNoticeRequest param : list){
|
if(StringUtils.isBlank(param.getIoCode()) ||
|
StringUtils.isBlank(param.getCarrierBillCode())||
|
StringUtils.isBlank(param.getPlateNumber())||
|
StringUtils.isBlank(param.getDriverPhone())){
|
return returnFailReuslt("请求参数不正确,参数不合法!");
|
}
|
//根据承运单号查询任务信息
|
PlatformWmsJob job = platformWmsJobMapper.selectOne(new QueryWrapper<PlatformWmsJob>().lambda()
|
.eq(PlatformWmsJob::getCarryBillCode,param.getCarrierBillCode())
|
.eq(PlatformWmsJob::getIsdeleted, Constants.ZERO)
|
.last("limit 1" ));
|
|
if(job == null){
|
PlatformJob model =dealJobBizInbound(param);
|
job = new PlatformWmsJob();
|
job.setCreateDate(new Date());
|
job.setIsdeleted(Constants.ZERO);
|
job.setIsNew(Constants.ONE);
|
job.setCarryBillCode(param.getCarrierBillCode());
|
job.setIocode(param.getIoCode());
|
job.setCarrierName(param.getCarrierName());
|
job.setPlateNumber(param.getPlateNumber());
|
job.setType(Constants.ONE);
|
job.setIoCreatedate(param.getCreateDate());
|
job.setJobId(model.getId());
|
job.setDriverPhone(param.getDriverPhone());
|
platformWmsJobMapper.insert(job);
|
jobList.add(model);
|
}
|
if(param.getDetails()!=null && param.getDetails().size()>0){
|
for(WmsInboundDetailRequest d :param.getDetails()){
|
PlatformWmsDetail entity = new PlatformWmsDetail();
|
entity.setCreateDate(new Date());
|
entity.setIsdeleted(Constants.ZERO);
|
entity.setIocode(d.getIoCode());
|
entity.setJobId(job.getId());
|
entity.setIoQty(d.getIoQty());
|
entity.setRate(d.getRate());
|
entity.setMaterialName(d.getMaterialName());
|
entity.setInRepertotyCode(d.getInRepertotyCode());
|
iocodeList.add(d.getIoCode());
|
details.add(entity);
|
}
|
if(job.getIsNew() == 1&& iocodeList.size()>0){
|
//先清理同一个承运单号下重复推送的iocode数据,以最后一次推送为主
|
platformWmsDetailMapper.update(null,new UpdateWrapper<PlatformWmsDetail>().lambda()
|
.set(PlatformWmsDetail::getIsdeleted,Constants.ONE)
|
.eq(PlatformWmsDetail::getIsdeleted,Constants.ZERO)
|
.eq(PlatformWmsDetail::getJobId,job.getJobId())
|
.in(PlatformWmsDetail::getIocode,iocodeList)
|
);
|
}
|
}
|
}
|
if(details.size()>0){
|
platformWmsDetailMapper.insert(details);
|
}
|
if(jobList.size()>0){
|
startEndNoticeToDriver(jobList);
|
}
|
return returnSuccessReuslt(null);
|
}
|
|
private void startEndNoticeToDriver(List<PlatformJob> jobList) {
|
for(PlatformJob job : jobList){
|
//-----TODO-----------任康,发送司机公众号和短信通知
|
}
|
}
|
|
private PlatformJob dealJobBizInbound(WmsInboundNoticeRequest param) {
|
PlatformJob job = new PlatformJob();
|
job.setCreateDate(new Date());
|
job.setIsdeleted(Constants.ZERO);
|
job.setType(Constants.platformJobType.wxcxh);//默认是外协车卸货
|
job.setStatus(Constants.PlatformJobStatus.WAIT_CONFIRM.getKey());//默认待确认状态
|
Cars car = carsMapper.selectOne(new QueryWrapper<Cars>()
|
.select("*,(select count(1) from platform_job b where b.plate_num='"+param.getPlateNumber()+"' and b.status in()) as jobNum")
|
.lambda()
|
.eq(Cars::getIsdeleted,Constants.ZERO)
|
.eq(Cars::getType,Constants.ONE)
|
.eq(Cars::getCode,param.getPlateNumber()));
|
if(car !=null){
|
//如果是自有物流车
|
job.setType(Constants.platformJobType.zycxh);//自有车卸货
|
if(Constants.equalsInteger(car.getInStatus(),Constants.ONE) && car.getJobNum() == 0) {
|
//如果车辆在园
|
job.setStatus(Constants.PlatformJobStatus.WAIT_CALL.getKey());//在园无作业状态,则自动【已签到】处理
|
}
|
}
|
platformJobMapper.insert(job);
|
return job;
|
}
|
private PlatformJob dealJobBizOutbound(WmsOutboundNoticeRequest param) {
|
PlatformJob job = new PlatformJob();
|
job.setCreateDate(new Date());
|
job.setIsdeleted(Constants.ZERO);
|
job.setType(Constants.platformJobType.wxczh);//默认是外协车装好
|
job.setStatus(Constants.PlatformJobStatus.WAIT_CONFIRM.getKey());//默认待确认状态
|
Cars car = carsMapper.selectOne(new QueryWrapper<Cars>()
|
.select("*,(select count(1) from platform_job b where b.plate_num='"+param.getPlateNumber()+"' and b.status in()) as jobNum")
|
.lambda()
|
.eq(Cars::getIsdeleted,Constants.ZERO)
|
.eq(Cars::getType,Constants.ONE)
|
.eq(Cars::getCode,param.getPlateNumber()));
|
if(car !=null){
|
//如果是自有物流车
|
job.setType(Constants.platformJobType.zyczh);//自有车装货
|
if(Constants.equalsInteger(car.getInStatus(),Constants.ONE) && car.getJobNum() == 0) {
|
//如果车辆在园
|
job.setStatus(Constants.PlatformJobStatus.WAIT_CALL.getKey());//在园无作业状态,则自动【已签到】处理
|
}
|
}
|
platformJobMapper.insert(job);
|
return job;
|
}
|
|
|
/**
|
* 出库通知任务业务处理
|
* @param list 参数
|
* @return
|
*/
|
@Override
|
public WmsBaseResponse outboundNotice(List<WmsOutboundNoticeRequest> list) {
|
if(list ==null || list.size() ==0){
|
return returnFailReuslt("请求参数不正确,参数不能为空");
|
}
|
List<PlatformJob> jobList = new ArrayList<>();
|
List<PlatformWmsDetail> details = new ArrayList<>();
|
List<String> iocodeList = new ArrayList<>();
|
for(WmsOutboundNoticeRequest param : list){
|
if(StringUtils.isBlank(param.getIoCode()) ||
|
StringUtils.isBlank(param.getCarrierBillCode())||
|
StringUtils.isBlank(param.getPlateNumber())||
|
StringUtils.isBlank(param.getDriverPhone())){
|
return returnFailReuslt("请求参数不正确,参数不合法!");
|
}
|
//根据承运单号查询任务信息
|
PlatformWmsJob job = platformWmsJobMapper.selectOne(new QueryWrapper<PlatformWmsJob>().lambda()
|
.eq(PlatformWmsJob::getCarryBillCode,param.getCarrierBillCode())
|
.eq(PlatformWmsJob::getIsdeleted, Constants.ZERO)
|
.last("limit 1" ));
|
|
if(job == null){
|
PlatformJob model =dealJobBizOutbound(param);
|
job = new PlatformWmsJob();
|
job.setCreateDate(new Date());
|
job.setIsdeleted(Constants.ZERO);
|
job.setIsNew(Constants.ONE);
|
job.setCarryBillCode(param.getCarrierBillCode());
|
job.setIocode(param.getIoCode());
|
job.setCarrierName(param.getCarrierName());
|
job.setPlateNumber(param.getPlateNumber());
|
job.setType(Constants.ONE);
|
job.setIoCreatedate(param.getCreateDate());
|
job.setJobId(model.getId());
|
job.setDriverPhone(param.getDriverPhone());
|
platformWmsJobMapper.insert(job);
|
jobList.add(model);
|
}
|
if(param.getDetails()!=null && param.getDetails().size()>0){
|
for(WmsOutboundDetailRequest d :param.getDetails()){
|
PlatformWmsDetail entity = new PlatformWmsDetail();
|
entity.setCreateDate(new Date());
|
entity.setIsdeleted(Constants.ZERO);
|
entity.setIocode(d.getIoCode());
|
entity.setJobId(job.getId());
|
entity.setIoQty(d.getIoQty());
|
entity.setRate(d.getRate());
|
entity.setMaterialName(d.getMaterialName());
|
iocodeList.add(d.getIoCode());
|
details.add(entity);
|
}
|
if(job.getIsNew() == 1&& iocodeList.size()>0){
|
//先清理同一个承运单号下重复推送的iocode数据,以最后一次推送为主
|
platformWmsDetailMapper.update(null,new UpdateWrapper<PlatformWmsDetail>().lambda()
|
.set(PlatformWmsDetail::getIsdeleted,Constants.ONE)
|
.eq(PlatformWmsDetail::getIsdeleted,Constants.ZERO)
|
.eq(PlatformWmsDetail::getJobId,job.getJobId())
|
.in(PlatformWmsDetail::getIocode,iocodeList)
|
);
|
}
|
}
|
}
|
if(details.size()>0){
|
platformWmsDetailMapper.insert(details);
|
}
|
if(jobList.size()>0){
|
startEndNoticeToDriver(jobList);
|
}
|
return returnSuccessReuslt(null);
|
}
|
/**
|
* 入库取消通知任务业务处理
|
* @param list 参数
|
* @return
|
*/
|
@Override
|
public WmsBaseResponse cancelInbound(List<WmsActionNoticeRequest> list) {
|
//TODO-------------------处理入库取消通知业务--------------------
|
if(list ==null || list.size() ==0){
|
return returnFailReuslt("请求参数不正确,参数不能为空");
|
}
|
|
|
return returnSuccessReuslt(null);
|
}
|
/**
|
* 出库取消通知任务业务处理
|
* @param list 参数
|
* @return
|
*/
|
@Override
|
public WmsBaseResponse cancelOutbound(List<WmsActionNoticeRequest> list) {
|
//TODO-------------------处理出库取消通知业务--------------------
|
if(list ==null || list.size() ==0){
|
return returnFailReuslt("请求参数不正确,参数不能为空");
|
}
|
|
return returnSuccessReuslt(null);
|
}
|
/**
|
* 作业完成通知任务业务处理
|
* @param list 参数
|
* @return
|
*/
|
@Override
|
public WmsBaseResponse doneTask(List<WmsActionNoticeRequest> list) {
|
//TODO-------------------处理出入库作业完成通知业务--------------------
|
if(list ==null || list.size() ==0){
|
return returnFailReuslt("请求参数不正确,参数不能为空");
|
}
|
|
return returnSuccessReuslt(null);
|
}
|
|
/**
|
* 封装错误返回对象
|
* @param msg
|
* @return
|
*/
|
|
private WmsBaseResponse returnFailReuslt(String msg) {
|
WmsBaseResponse response = new WmsBaseResponse();
|
response.setData(new ArrayList<>());
|
WmsBaseDataResponse rData = new WmsBaseDataResponse();
|
rData.setMsgDescr(msg);
|
rData.setSuccess("-1");
|
response.getData().add(rData);
|
return response;
|
}
|
/**
|
* 封装成功返回对象
|
* @param msg
|
* @return
|
*/
|
|
private WmsBaseResponse returnSuccessReuslt(String msg) {
|
WmsBaseResponse response = new WmsBaseResponse();
|
response.setData(new ArrayList<>());
|
WmsBaseDataResponse rData = new WmsBaseDataResponse();
|
rData.setMsgDescr(StringUtils.defaultString(msg,"操作成功"));
|
rData.setSuccess("1");
|
response.getData().add(rData);
|
return response;
|
}
|
}
|