|
|
@ -2,24 +2,29 @@ package com.win.module.wms.service.countPlan; |
|
|
|
|
|
|
|
import cn.hutool.core.exceptions.UtilException; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.module.infra.api.trends.TrendsApi; |
|
|
|
import com.win.module.infra.enums.TrendsTypeEnum; |
|
|
|
import com.win.module.wms.controller.countPlan.vo.CountPlanMainCreateReqVO; |
|
|
|
import com.win.module.wms.controller.countPlan.vo.CountPlanMainExportReqVO; |
|
|
|
import com.win.module.wms.controller.countPlan.vo.CountPlanMainPageReqVO; |
|
|
|
import com.win.module.wms.controller.countPlan.vo.CountPlanMainUpdateReqVO; |
|
|
|
import com.win.module.wms.convert.countPlan.CountPlanMainConvert; |
|
|
|
import com.win.module.wms.dal.dataobject.countPlan.CountPlanDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.countPlan.CountPlanMainDO; |
|
|
|
import com.win.module.wms.dal.mysql.countPlan.CountPlanDetailMapper; |
|
|
|
import com.win.module.wms.dal.mysql.countPlan.CountPlanMainMapper; |
|
|
|
import com.win.module.wms.dal.mysql.countRequest.CountRequestMainMapper; |
|
|
|
import com.win.module.wms.enums.plan.PlanStatusState; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import com.win.module.wms.dal.dataobject.countPlan.CountPlanMainDO; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
|
|
|
|
import com.win.module.wms.convert.countPlan.CountPlanMainConvert; |
|
|
|
import com.win.module.wms.dal.mysql.countPlan.CountPlanMainMapper; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
|
@ -35,40 +40,46 @@ public class CountPlanMainServiceImpl implements CountPlanMainService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private CountPlanMainMapper countPlanMainMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private CountPlanDetailMapper countPlanDetailMapper; |
|
|
|
@Resource |
|
|
|
private CountRequestMainMapper countRequestMainMapper; |
|
|
|
@Resource |
|
|
|
private TrendsApi trendsApi; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Long createCountPlanMain(CountPlanMainCreateReqVO createReqVO) { |
|
|
|
// 插入
|
|
|
|
CountPlanMainDO countPlanMain = CountPlanMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
countPlanMainMapper.insert(countPlanMain); |
|
|
|
// 返回
|
|
|
|
trendsApi.createTrends(countPlanMain.getId(), "countPlan", "增加了盘点计划", TrendsTypeEnum.CREATE); |
|
|
|
return countPlanMain.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateCountPlanMain(CountPlanMainUpdateReqVO updateReqVO) { |
|
|
|
public int updateCountPlanMain(CountPlanMainUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validateCountPlanMainExists(updateReqVO.getId()); |
|
|
|
// 更新
|
|
|
|
CountPlanMainDO updateObj = CountPlanMainConvert.INSTANCE.convert(updateReqVO); |
|
|
|
countPlanMainMapper.updateById(updateObj); |
|
|
|
trendsApi.createTrends(updateObj.getId(), "countPlan", "增加了盘点计划", TrendsTypeEnum.CREATE); |
|
|
|
return countPlanMainMapper.updateById(updateObj); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteCountPlanMain(Long id) { |
|
|
|
public int deleteCountPlanMain(Long id) { |
|
|
|
// 校验存在
|
|
|
|
validateCountPlanMainExists(id); |
|
|
|
// 删除
|
|
|
|
countPlanMainMapper.deleteById(id); |
|
|
|
trendsApi.createTrends(id, "countPlan", "删除了盘点计划", TrendsTypeEnum.DELETE); |
|
|
|
return countPlanMainMapper.deleteById(id); |
|
|
|
} |
|
|
|
|
|
|
|
private void validateCountPlanMainExists(Long id) { |
|
|
|
if (countPlanMainMapper.selectById(id) == null) { |
|
|
|
private CountPlanMainDO validateCountPlanMainExists(Long id) { |
|
|
|
CountPlanMainDO countPlanMainDO = countPlanMainMapper.selectById(id); |
|
|
|
if (countPlanMainDO == null) { |
|
|
|
throw exception(COUNT_PLAN_MAIN_NOT_EXISTS); |
|
|
|
} |
|
|
|
return countPlanMainDO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -84,6 +95,12 @@ public class CountPlanMainServiceImpl implements CountPlanMainService { |
|
|
|
public PageResult<CountPlanMainDO> getCountPlanMainSenior(CustomConditions conditions) { |
|
|
|
return countPlanMainMapper.selectSenior(conditions); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<CountPlanMainDO> getCountPlanMainList(CustomConditions conditions) { |
|
|
|
return countPlanMainMapper.selectSeniorList(conditions); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageResult<CountPlanMainDO> getCountPlanMainPage(CountPlanMainPageReqVO pageReqVO) { |
|
|
|
return countPlanMainMapper.selectPage(pageReqVO); |
|
|
@ -96,26 +113,139 @@ public class CountPlanMainServiceImpl implements CountPlanMainService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public CountPlanDetailDO selectCountPlanExist(String pnumber){ |
|
|
|
QueryWrapper queryWrapperMain = new QueryWrapper(); |
|
|
|
QueryWrapper<CountPlanMainDO> queryWrapperMain = new QueryWrapper<>(); |
|
|
|
queryWrapperMain.eq("number",pnumber); |
|
|
|
queryWrapperMain.eq("available","TRUE"); |
|
|
|
CountPlanMainDO countPlanMainDO = countPlanMainMapper.selectOne(queryWrapperMain); |
|
|
|
if(countPlanMainDO != null){ |
|
|
|
if(!"ClOSE".equals(countPlanMainDO.getStatus())){ |
|
|
|
QueryWrapper queryWrapperDetail = new QueryWrapper(); |
|
|
|
queryWrapperDetail.eq("number",pnumber); |
|
|
|
queryWrapperDetail.eq("available","TRUE"); |
|
|
|
CountPlanDetailDO countPlanDetailDO = countPlanDetailMapper.selectOne(queryWrapperDetail); |
|
|
|
if(countPlanDetailDO != null){ |
|
|
|
return countPlanDetailDO; |
|
|
|
}else { |
|
|
|
throw new UtilException("盘点计划" + pnumber + "无效"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
throw new UtilException("盘点计划" + pnumber + "已关闭"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
if(countPlanMainDO == null) { |
|
|
|
throw new UtilException("盘点计划" + pnumber + "无效"); |
|
|
|
} |
|
|
|
if("ClOSE".equals(countPlanMainDO.getStatus())) { |
|
|
|
throw new UtilException("盘点计划" + pnumber + "已关闭"); |
|
|
|
} |
|
|
|
QueryWrapper<CountPlanDetailDO> queryWrapperDetail = new QueryWrapper<>(); |
|
|
|
queryWrapperDetail.eq("number", pnumber); |
|
|
|
queryWrapperDetail.eq("available","TRUE"); |
|
|
|
CountPlanDetailDO countPlanDetailDO = countPlanDetailMapper.selectOne(queryWrapperDetail); |
|
|
|
if(countPlanDetailDO != null) { |
|
|
|
return countPlanDetailDO; |
|
|
|
} else { |
|
|
|
throw new UtilException("盘点计划" + pnumber + "无效"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer closeCountPlanMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
CountPlanMainDO mainDO = validateCountPlanMainExists(id); |
|
|
|
Long count = countRequestMainMapper.selectByCountPlanNumber(mainDO.getNumber()); |
|
|
|
if(count > 0) { |
|
|
|
throw new ServiceException(COUNT_PLAN_REQUEST_EXISTS); |
|
|
|
} |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.close(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(COUNT_PLAN_CANNOT_CLOSE); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode());//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "countPlan", "关闭了盘点计划", TrendsTypeEnum.UPDATE); |
|
|
|
return countPlanMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer openCountPlanMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
CountPlanMainDO mainDO = validateCountPlanMainExists(id); |
|
|
|
Long count = countRequestMainMapper.selectByCountPlanNumber(mainDO.getNumber()); |
|
|
|
if(count > 0) { |
|
|
|
throw new ServiceException(COUNT_PLAN_REQUEST_EXISTS); |
|
|
|
} |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.open(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(COUNT_PLAN_CANNOT_OPEN); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode());//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "countPlan", "打开了盘点计划", TrendsTypeEnum.UPDATE); |
|
|
|
return countPlanMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer submitCountPlanMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
CountPlanMainDO mainDO = validateCountPlanMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.submit(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(COUNT_PLAN_CANNOT_SUBMIT); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode());//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "countPlan", "提交了盘点计划", TrendsTypeEnum.UPDATE); |
|
|
|
return countPlanMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer agreeCountPlanMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
CountPlanMainDO mainDO = validateCountPlanMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.agree(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(COUNT_PLAN_CANNOT_AGREE); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode());//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "countPlan", "审批通过了盘点计划", TrendsTypeEnum.UPDATE); |
|
|
|
return countPlanMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer rejectCountPlanMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
CountPlanMainDO mainDO = validateCountPlanMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.reject(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(COUNT_PLAN_CANNOT_REFUSE); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode());//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "countPlan", "审批驳回了盘点计划", TrendsTypeEnum.UPDATE); |
|
|
|
return countPlanMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer publishCountPlanMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
CountPlanMainDO mainDO = validateCountPlanMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.execute(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(COUNT_PLAN_CANNOT_PUBLISH); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode());//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "countPlan", "发布了盘点计划", TrendsTypeEnum.UPDATE); |
|
|
|
return countPlanMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer resettingCountPlanMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
CountPlanMainDO mainDO = validateCountPlanMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.resetting(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(COUNT_PLAN_CANNOT_RESETTING); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode());//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "countPlan", "重置了盘点计划", TrendsTypeEnum.UPDATE); |
|
|
|
return countPlanMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|