|
|
@@ -12,7 +12,6 @@ import com.usoftchina.saas.commons.dto.DocSavedDTO;
|
|
|
import com.usoftchina.saas.commons.dto.ListReqDTO;
|
|
|
import com.usoftchina.saas.commons.exception.BizExceptionCode;
|
|
|
import com.usoftchina.saas.commons.po.BillCodeSeq;
|
|
|
-import com.usoftchina.saas.commons.po.Maxnumbers;
|
|
|
import com.usoftchina.saas.commons.po.Status;
|
|
|
import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
import com.usoftchina.saas.document.api.WarehouseApi;
|
|
|
@@ -22,7 +21,6 @@ import com.usoftchina.saas.page.PageRequest;
|
|
|
import com.usoftchina.saas.sale.dto.ProdIODetailDTO;
|
|
|
import com.usoftchina.saas.sale.dto.ProdInOutDTO;
|
|
|
import com.usoftchina.saas.sale.dto.ProdInOutFormDTO;
|
|
|
-import com.usoftchina.saas.sale.dto.ProdInOutReqDTO;
|
|
|
import com.usoftchina.saas.sale.mapper.*;
|
|
|
import com.usoftchina.saas.sale.service.ProdInOutService;
|
|
|
import com.usoftchina.saas.storage.po.ProdIODetail;
|
|
|
@@ -56,7 +54,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
public ProdInOutFormDTO getFormData(Long id) {
|
|
|
ProdInOutFormDTO prodInOutFormDTO = new ProdInOutFormDTO();
|
|
|
//查询主表
|
|
|
- ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
|
|
|
+ ProdInOut prodInOut = checkAndReturnOrder(id);
|
|
|
//将prodInOut实体对象转化为传输对象
|
|
|
ProdInOutDTO main = BeanMapper.map(prodInOut,ProdInOutDTO.class);
|
|
|
//查询从表
|
|
|
@@ -166,7 +164,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
singleDelete(id);
|
|
|
}
|
|
|
private void singleDelete(Long id) {
|
|
|
- ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
|
|
|
+ ProdInOut prodInOut = checkAndReturnOrder(id);
|
|
|
//从表删除
|
|
|
prodIODetailMapper.deleteByForeignKey(id);
|
|
|
//主表删除
|
|
|
@@ -175,8 +173,9 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
//更新已转数
|
|
|
updateYqty(prodInOut);
|
|
|
//日志
|
|
|
- messageLogService.deleteDetail(docBaseDTO);
|
|
|
+ messageLogService.deleteDetail(docBaseDTO);
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public DocBaseDTO audit(ProdInOutFormDTO formData) {
|
|
|
@@ -216,16 +215,14 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public Result unAudit(Long id) {
|
|
|
- if (null == id) {
|
|
|
- return Result.error(BizExceptionCode.SALE_NULL_BILL);
|
|
|
- }
|
|
|
+ ProdInOut prodInOut = checkAndReturnOrder(id);
|
|
|
String code = prodInOutMapper.validateUnAudit(id);
|
|
|
- if (null != code) {
|
|
|
+ if (!prodInOut.getPi_statuscode().equals(Status.AUDITED.name())) {
|
|
|
throw new BizException(BizExceptionCode.SALE_NULL_BILL);
|
|
|
}
|
|
|
- ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
|
|
|
ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut, ProdInOutDTO.class);
|
|
|
String res = singleUnAudit(prodInOutDTO);
|
|
|
if(res!=null){
|
|
|
@@ -247,6 +244,13 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
if(result!=null){
|
|
|
return result.toString();
|
|
|
}else{
|
|
|
+ //更新状态为未审核
|
|
|
+ ProdInOut prodInOut = BeanMapper.map(prodInOutDTO, ProdInOut.class);
|
|
|
+ prodInOut.setPi_statuscode(Status.UNAUDITED.name());
|
|
|
+ prodInOut.setPi_status(Status.UNAUDITED.getDisplay());
|
|
|
+ prodInOut.setUpdateTime(new Date());
|
|
|
+ prodInOut.setUpdaterId(BaseContextHolder.getUserId());
|
|
|
+ getMapper().updateByPrimaryKeySelective(prodInOut);
|
|
|
//记录日志
|
|
|
DocBaseDTO docBaseDTO = getBaseDTOById(prodInOutDTO.getId(),pi_class);
|
|
|
//日志
|
|
|
@@ -254,6 +258,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public void batchAudit(BatchDealBaseDTO baseDTOs) {
|
|
|
if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
|
|
|
@@ -271,7 +276,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
|
|
|
error+=singleAudit(prodInOutDTO);
|
|
|
}
|
|
|
- if(error!=null&&!error.equals("")){
|
|
|
+ if(!StringUtils.isEmpty(error)){
|
|
|
new BizException(501,error);
|
|
|
}
|
|
|
}
|
|
|
@@ -294,7 +299,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
|
|
|
error+=singleUnAudit(prodInOutDTO);
|
|
|
}
|
|
|
- if(error!=null&&!error.equals("")){
|
|
|
+ if(!StringUtils.isEmpty(error)){
|
|
|
new BizException(501,error);
|
|
|
}
|
|
|
}
|
|
|
@@ -302,15 +307,16 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
@Override
|
|
|
public Integer deleteItem(Long id) {
|
|
|
ProdIODetail prodIODetail = prodIODetailMapper.selectByPrimaryKey(id);
|
|
|
- ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(prodIODetail.getPd_piid());
|
|
|
+ ProdInOut prodInOut = checkAndReturnOrder(prodIODetail.getPd_piid());
|
|
|
Integer num = prodIODetailMapper.deleteByPrimaryKey(id);
|
|
|
//更新已转数
|
|
|
updateYqty(prodInOut);
|
|
|
DocBaseDTO docBaseDTO = getBaseDTOById(id,prodInOut.getPi_class());
|
|
|
//日志
|
|
|
- messageLogService.deleteDetail(docBaseDTO);
|
|
|
+ messageLogService.deleteDetail(docBaseDTO);
|
|
|
return num;
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public void batchDelete(BatchDealBaseDTO baseDTOs) {
|
|
|
if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
|
|
|
@@ -337,6 +343,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
PageInfo<ProdInOutList> pageInfo = new PageInfo<ProdInOutList>(lists);
|
|
|
return pageInfo;
|
|
|
}
|
|
|
+
|
|
|
private List<ProdInOutList> getListByMode(ListReqDTO req) {
|
|
|
List<ProdInOutList> list = null;
|
|
|
Long companyId = BaseContextHolder.getCompanyId();
|
|
|
@@ -351,12 +358,13 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public Result turnProdin(Long id) {
|
|
|
Integer count=0;
|
|
|
double pdOutqty=0;
|
|
|
double pdYqty=0;
|
|
|
- ProdInOut sourcePi = prodInOutMapper.selectByPrimaryKey(id);
|
|
|
+ ProdInOut sourcePi = checkAndReturnOrder(id);
|
|
|
List<ProdIODetail> sourceDetails =prodIODetailMapper.selectByFK(id);
|
|
|
if (null == sourcePi || StringUtils.isEmpty(sourcePi.getPi_inoutno()) || sourceDetails.size() == 0) {
|
|
|
throw new BizException(BizExceptionCode.SALE_NULL_BILL);
|
|
|
@@ -383,7 +391,9 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
//插入销售退货单主表
|
|
|
ProdInOut targetPi = new ProdInOut();
|
|
|
//生成单号
|
|
|
- String piInoutno = maxnumberService.getMaxnumber(BillCodeSeq.SALEIN.getCaller(),true).getData();
|
|
|
+ String piInoutno =
|
|
|
+ //BillCodeSeq.SALEIN.getCaller() + Math.abs(Math.random()*100);
|
|
|
+ maxnumberService.getMaxnumber(BillCodeSeq.SALEIN.getCaller(),true).getData();
|
|
|
targetPi.setPi_inoutno(piInoutno);
|
|
|
targetPi.setPi_class(BillCodeSeq.SALEIN.getName());
|
|
|
targetPi.setPi_date(new Date());
|
|
|
@@ -442,81 +452,96 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void close(Long id) {
|
|
|
- if(id == null || id <= 0) {
|
|
|
- throw new BizException(BizExceptionCode.ILLEGAL_ID);
|
|
|
- }
|
|
|
- ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
|
|
|
- if(prodInOut==null){
|
|
|
- throw new BizException(BizExceptionCode.NO_DATA);
|
|
|
+ public Result close(Long id) {
|
|
|
+ String res = singleClose(id);
|
|
|
+ if(StringUtils.hasText(res)){
|
|
|
+ return Result.error(res);
|
|
|
+ }else{
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private String singleClose(Long id){
|
|
|
+ ProdInOut prodInOut = checkAndReturnOrder(id);
|
|
|
+ //状态校验
|
|
|
if(Status.CLOSE.name().equals(prodInOut.getPi_status())){
|
|
|
- throw new BizException(BizExceptionCode.BIZ_CLOSE);
|
|
|
+ return BizExceptionCode.BIZ_CLOSE.getMessage();
|
|
|
}
|
|
|
+ //更新状态
|
|
|
prodInOut.setPi_status(Status.CLOSE.getDisplay());
|
|
|
prodInOut.setPi_statuscode(Status.CLOSE.name());
|
|
|
|
|
|
prodInOutMapper.updateByPrimaryKeySelective(prodInOut);
|
|
|
- DocBaseDTO docBaseDTO = getBaseDTOById(id,prodInOut.getPi_class());
|
|
|
- //日志
|
|
|
- messageLogService.close(docBaseDTO);
|
|
|
+ //记录日志
|
|
|
+ DocBaseDTO docBaseDTO = getBaseDTOById(prodInOut.getId(),prodInOut.getPi_class());
|
|
|
+ messageLogService.close(docBaseDTO);
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
- public void open(Long id){
|
|
|
- ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
|
|
|
- if(prodInOut==null){
|
|
|
- throw new BizException(BizExceptionCode.NO_DATA);
|
|
|
+ public void batchClose(BatchDealBaseDTO baseDTOs){
|
|
|
+ if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
|
|
|
+ baseDTOs.getBaseDTOs().size() == 0) {
|
|
|
+ return;
|
|
|
}
|
|
|
- List<ProdIODetail> prodIODetailList = prodIODetailMapper.selectByFK(id);
|
|
|
- //部分入库、全部入库
|
|
|
- int partTurnCount = 0,turnCount = 0;
|
|
|
- Double yqty=0.0,qty=0.0;
|
|
|
- Boolean isIn = false;
|
|
|
- if(BillCodeSeq.SALEIN.getName().equals(prodInOut.getPi_class())){
|
|
|
- isIn=true;
|
|
|
- }
|
|
|
- if(prodIODetailList!=null&&prodIODetailList.size()>0){
|
|
|
- for (ProdIODetail prodiodetail :prodIODetailList){
|
|
|
- yqty = prodiodetail.getPd_yqty() ==null?0.0:prodiodetail.getPd_yqty();
|
|
|
- if(isIn){
|
|
|
- qty = prodiodetail.getPd_inqty() ==null?0.0:prodiodetail.getPd_yqty();
|
|
|
- }else{
|
|
|
- qty = prodiodetail.getPd_outqty() ==null?0.0:prodiodetail.getPd_outqty();
|
|
|
- }
|
|
|
- if(yqty >= qty){
|
|
|
- turnCount++;
|
|
|
- }else if(yqty>0&&yqty<qty){
|
|
|
- partTurnCount++;
|
|
|
- }
|
|
|
- }
|
|
|
+ String validate = prodInOutMapper.validateBatchClose(baseDTOs.getBaseDTOs());
|
|
|
+ if (!StringUtils.isEmpty(validate)) {
|
|
|
+ throw new BizException(503, "存在非已审核单据,单据编号:" + validate);
|
|
|
}
|
|
|
- if(partTurnCount>0){
|
|
|
- if(isIn){
|
|
|
- prodInOut.setPi_status(Status.PART2IN.getDisplay());
|
|
|
- prodInOut.setPi_statuscode(Status.PART2IN.name());
|
|
|
- }else {
|
|
|
- prodInOut.setPi_status(Status.PARTOUT.getDisplay());
|
|
|
- prodInOut.setPi_statuscode(Status.PARTOUT.name());
|
|
|
- }
|
|
|
- }else if(turnCount == prodIODetailList.size()){
|
|
|
- if(isIn){
|
|
|
- prodInOut.setPi_status(Status.TURNIN.getDisplay());
|
|
|
- prodInOut.setPi_statuscode(Status.TURNIN.name());
|
|
|
- }else {
|
|
|
- prodInOut.setPi_status(Status.TURNOUT.getDisplay());
|
|
|
- prodInOut.setPi_statuscode(Status.TURNOUT.name());
|
|
|
- }
|
|
|
+ String error = null;
|
|
|
+ for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
|
|
|
+ error+=singleClose(base.getId());
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(error)){
|
|
|
+ new BizException(501,error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Result open(Long id){
|
|
|
+ String res = singleOpen(id);
|
|
|
+ if(StringUtils.hasText(res)){
|
|
|
+ return Result.error(res);
|
|
|
}else{
|
|
|
- prodInOut.setPi_status(Status.AUDITED.getDisplay());
|
|
|
- prodInOut.setPi_statuscode(Status.AUDITED.getDisplay());
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private String singleOpen(Long id){
|
|
|
+ ProdInOut prodInOut = checkAndReturnOrder(id);
|
|
|
+ String pi_statuscode = prodInOut.getPi_statuscode();
|
|
|
+ if(!StringUtils.isEmpty(pi_statuscode)&&!pi_statuscode.equals(Status.CLOSE.getDisplay())){
|
|
|
+ return BizExceptionCode.BIZ_OPEN.getMessage();
|
|
|
+ };
|
|
|
+ prodInOut.setPi_status(Status.AUDITED.getDisplay());
|
|
|
+ prodInOut.setPi_statuscode(Status.AUDITED.getDisplay());
|
|
|
prodInOutMapper.updateByPrimaryKeySelective(prodInOut);
|
|
|
- DocBaseDTO docBaseDTO = getBaseDTOById(id,prodInOut.getPi_class());
|
|
|
//记录日志
|
|
|
+ DocBaseDTO docBaseDTO = getBaseDTOById(prodInOut.getId(),prodInOut.getPi_class());
|
|
|
messageLogService.open(docBaseDTO);
|
|
|
+ return "";
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchOpen(BatchDealBaseDTO baseDTOs){
|
|
|
+ if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
|
|
|
+ baseDTOs.getBaseDTOs().size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String validate = prodInOutMapper.validateBatchOpen(baseDTOs.getBaseDTOs());
|
|
|
+ if (!StringUtils.isEmpty(validate)) {
|
|
|
+ throw new BizException(503, "存在非已关闭单据,单据编号:" + validate);
|
|
|
+ }
|
|
|
+ String error = null;
|
|
|
+ for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
|
|
|
+ error+=singleOpen(base.getId());
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(error)){
|
|
|
+ new BizException(501,error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 检验获取并更新单号
|
|
|
* @Param: [code, id]
|
|
|
@@ -528,6 +553,10 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
if (null == code) {
|
|
|
throw new BizException(BizExceptionCode.NULL_CODE);
|
|
|
}
|
|
|
+ ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
|
|
|
+ if(prodInOut==null){
|
|
|
+ throw new BizException(BizExceptionCode.NO_DATA);
|
|
|
+ }
|
|
|
Integer count = "0".equals(String.valueOf(id)) ? prodInOutMapper.validateCodeWhenInsert(code,pi_class) :
|
|
|
prodInOutMapper.validateCodeWhenUpdate(code, id);
|
|
|
String caller ="";
|
|
|
@@ -537,7 +566,9 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
caller = BillCodeSeq.SALEIN.getCaller();
|
|
|
}
|
|
|
return maxnumberService.pushMaxnubmer(count, code, caller).getData();
|
|
|
+ //return caller+Math.abs(Math.random()*100);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 更新已转数
|
|
|
* @Param: [code, id]
|
|
|
@@ -573,6 +604,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
baseDTO.setName(caller);
|
|
|
return baseDTO;
|
|
|
}
|
|
|
+
|
|
|
//更新最新明细总额
|
|
|
private void getTotal(Long id,String pi_class) {
|
|
|
if(BillCodeSeq.SALEOUT.getName().equals(pi_class)){
|
|
|
@@ -581,4 +613,22 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
|
|
|
prodIODetailMapper.updatePDSaleIN(id);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description
|
|
|
+ * @Param: [id]
|
|
|
+ * @return: com.usoftchina.saas.commons.dto.DocBaseDTO
|
|
|
+ * @Author: wuyx
|
|
|
+ * @Date: 2018/10/25
|
|
|
+ * */
|
|
|
+ private ProdInOut checkAndReturnOrder (Long id){
|
|
|
+ if(id == null || id <= 0) {
|
|
|
+ throw new BizException(BizExceptionCode.ILLEGAL_ID);
|
|
|
+ }
|
|
|
+ ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
|
|
|
+ if(prodInOut==null){
|
|
|
+ throw new BizException(BizExceptionCode.NO_DATA);
|
|
|
+ }
|
|
|
+ return prodInOut;
|
|
|
+ }
|
|
|
}
|