|
|
@@ -3,19 +3,31 @@ package com.usoftchina.saas.storage.service.impl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
|
|
|
+import com.usoftchina.saas.commons.api.MaxnumberService;
|
|
|
import com.usoftchina.saas.commons.dto.DocBaseDTO;
|
|
|
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.context.BaseContextHolder;
|
|
|
+import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
import com.usoftchina.saas.storage.dto.StockTakingDTO;
|
|
|
+import com.usoftchina.saas.storage.mapper.ProdIODetailMapper;
|
|
|
+import com.usoftchina.saas.storage.mapper.ProdInOutMapper;
|
|
|
import com.usoftchina.saas.storage.mapper.StockTakingMapper;
|
|
|
+import com.usoftchina.saas.storage.po.ProdIODetail;
|
|
|
+import com.usoftchina.saas.storage.po.ProdInOut;
|
|
|
import com.usoftchina.saas.storage.po.StockTaking;
|
|
|
import com.usoftchina.saas.storage.service.StocktakingService;
|
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by zdw
|
|
|
@@ -24,6 +36,15 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class StocktakingServiceImpl extends CommonBaseServiceImpl<StockTakingMapper, StockTaking> implements StocktakingService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MaxnumberService maxnumberService;
|
|
|
+ @Autowired
|
|
|
+ private ProdInOutMapper prodInOutMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProdIODetailMapper prodIODetailMapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public PageInfo<StockTaking> getList(PageRequest page, ListReqDTO listReqDTO) {
|
|
|
PageHelper.startPage(page.getNumber(), page.getSize());
|
|
|
@@ -44,14 +65,147 @@ public class StocktakingServiceImpl extends CommonBaseServiceImpl<StockTakingMap
|
|
|
return baseDTO;
|
|
|
}
|
|
|
|
|
|
- private List<StockTaking> getList(ListReqDTO listReqDTO) {
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void buildListDataByCondition(ListReqDTO listReqDTO) {
|
|
|
List<StockTaking> list = null;
|
|
|
Long companyId = BaseContextHolder.getCompanyId();
|
|
|
String con = listReqDTO.getFinalCondition();
|
|
|
+ //删除该companyid的数据
|
|
|
+ getMapper().deleteByCompany(companyId);
|
|
|
if (null == con) {
|
|
|
con = "1=1";
|
|
|
}
|
|
|
- list = getMapper().selectStockTakingBycondition(con,companyId);
|
|
|
+ //查询存入临时表
|
|
|
+ getMapper().insertFormProductWh(con,companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String,Object> stock() {
|
|
|
+ Map<String,Object> resultMap = new HashMap();
|
|
|
+
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ Long userId = BaseContextHolder.getUserId();
|
|
|
+ //生成入库单
|
|
|
+ ProdInOut prodIn = new ProdInOut();
|
|
|
+ String piInno = getMaxnumber(BillCodeSeq.OTHERIN);
|
|
|
+ prodIn.setPi_inoutno(piInno);
|
|
|
+ prodIn.setPi_class(BillCodeSeq.OTHERIN.getName());
|
|
|
+ prodIn.setPi_date(new Date());
|
|
|
+ prodIn.setPi_status("未审核");
|
|
|
+ prodIn.setPi_statuscode("UNAUDITED");
|
|
|
+ prodIn.setCompanyId(companyId);
|
|
|
+ prodIn.setCreateTime(new Date());
|
|
|
+ prodIn.setCreatorId(userId);
|
|
|
+ prodIn.setPi_remark("盘盈单");
|
|
|
+ prodInOutMapper.insertSelective(prodIn);
|
|
|
+ long inid = prodIn.getId();
|
|
|
+
|
|
|
+ Double purcprice = null;
|
|
|
+
|
|
|
+ List<StockTaking> inlist = getMapper().selectStockTakingBycondition("st_num>0",companyId);
|
|
|
+ for (int i=0;i<inlist.size();i++) {
|
|
|
+ StockTaking st = inlist.get(i);
|
|
|
+ ProdIODetail prodInDetail = new ProdIODetail();
|
|
|
+ prodInDetail.setPd_piid(inid);
|
|
|
+ prodInDetail.setPd_inoutno(piInno);
|
|
|
+ prodInDetail.setPd_piclass(BillCodeSeq.OTHERIN.getName());
|
|
|
+ prodInDetail.setPd_pdno(i+1);
|
|
|
+
|
|
|
+ purcprice = getMapper().getPurcpriceByProduct(st.getSt_prodid());
|
|
|
+ prodInDetail.setPd_orderprice(purcprice==null?0:purcprice);
|
|
|
+ prodInDetail.setPd_prodid(st.getSt_prodid());
|
|
|
+ prodInDetail.setPd_prodcode(st.getSt_prodcode());
|
|
|
+ prodInDetail.setPd_inqty(st.getSt_num());
|
|
|
+ //仓库
|
|
|
+ prodInDetail.setPd_whid(st.getSt_whid());
|
|
|
+ prodInDetail.setPd_whcode(st.getSt_whcode());
|
|
|
+ prodInDetail.setPd_whname(st.getSt_whname());
|
|
|
+ prodInDetail.setCompanyId(companyId);
|
|
|
+ prodInDetail.setCreateTime(new Date());
|
|
|
+ prodInDetail.setCreatorId(userId);
|
|
|
+ prodIODetailMapper.insertSelective(prodInDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成出库单
|
|
|
+ ProdInOut prodOut = new ProdInOut();
|
|
|
+ String piOutno = getMaxnumber(BillCodeSeq.OTHEROUT);
|
|
|
+ prodOut.setPi_inoutno(piOutno);
|
|
|
+ prodOut.setPi_class(BillCodeSeq.OTHEROUT.getName());
|
|
|
+ prodOut.setPi_date(new Date());
|
|
|
+ prodOut.setPi_status("未审核");
|
|
|
+ prodOut.setPi_statuscode("UNAUDITED");
|
|
|
+ prodOut.setCompanyId(companyId);
|
|
|
+ prodOut.setCreateTime(new Date());
|
|
|
+ prodOut.setCreatorId(userId);
|
|
|
+ prodOut.setPi_remark("盘亏单");
|
|
|
+ prodInOutMapper.insertSelective(prodOut);
|
|
|
+ long outid = prodOut.getId();
|
|
|
+
|
|
|
+ List<StockTaking> outlist = getMapper().selectStockTakingBycondition("st_num<0",companyId);
|
|
|
+ for (int i=0;i<outlist.size();i++) {
|
|
|
+ StockTaking st = outlist.get(i);
|
|
|
+ ProdIODetail prodOutDetail = new ProdIODetail();
|
|
|
+ prodOutDetail.setPd_piid(outid);
|
|
|
+ prodOutDetail.setPd_inoutno(piOutno);
|
|
|
+ prodOutDetail.setPd_piclass(BillCodeSeq.OTHERIN.getName());
|
|
|
+ prodOutDetail.setPd_pdno(i+1);
|
|
|
+ prodOutDetail.setPd_prodid(st.getSt_prodid());
|
|
|
+ prodOutDetail.setPd_prodcode(st.getSt_prodcode());
|
|
|
+ prodOutDetail.setPd_outqty(-st.getSt_num());
|
|
|
+ //仓库
|
|
|
+ prodOutDetail.setPd_whid(st.getSt_whid());
|
|
|
+ prodOutDetail.setPd_whcode(st.getSt_whcode());
|
|
|
+ prodOutDetail.setPd_whname(st.getSt_whname());
|
|
|
+ prodOutDetail.setCompanyId(companyId);
|
|
|
+ prodOutDetail.setCreateTime(new Date());
|
|
|
+ prodOutDetail.setCreatorId(userId);
|
|
|
+ prodIODetailMapper.insertSelective(prodOutDetail);
|
|
|
+ }
|
|
|
+ DocBaseDTO baseDTOIN = new DocBaseDTO(inid,piInno,"其它入库单");
|
|
|
+ DocBaseDTO baseDTOOUT = new DocBaseDTO(outid,piOutno,"其它出库单");
|
|
|
+ resultMap.put("inData",baseDTOIN);
|
|
|
+ resultMap.put("outData",baseDTOOUT);
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<StockTaking> getList(ListReqDTO listReqDTO) {
|
|
|
+ List<StockTaking> list = null;
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ list = getMapper().selectStockTakingBycondition(null,companyId);
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public String getMaxnumber(BillCodeSeq bill) {
|
|
|
+ String code = maxnumberService.getMaxnumber(bill.getCaller(), false).getData();
|
|
|
+ DocBaseDTO base = new DocBaseDTO(0l, code, bill.getName());
|
|
|
+ return pushMaxnubmer(base);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String pushMaxnubmer(DocBaseDTO baseDTO) {
|
|
|
+ String pi_inoutno = baseDTO.getCode();
|
|
|
+ String pi_class = baseDTO.getName();
|
|
|
+ Long id = baseDTO.getId();
|
|
|
+ if (null == pi_inoutno) {
|
|
|
+ throw new BizException(BizExceptionCode.NULL_CODE);
|
|
|
+ }
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ String billCode = null;
|
|
|
+ synchronized (ProdInOutServiceImpl.class) {
|
|
|
+ Integer count = "0".equals(String.valueOf(id)) ? prodInOutMapper.validateCodeWhenInsert(pi_inoutno, companyId) :
|
|
|
+ prodInOutMapper.validateCodeWhenUpdate(pi_inoutno, id, companyId);
|
|
|
+ String caller ="";
|
|
|
+ if("其它入库单".equals(pi_class)){
|
|
|
+ caller = BillCodeSeq.OTHERIN.getCaller();
|
|
|
+ }else if("其它出库单".equals(pi_class)) {
|
|
|
+ caller = BillCodeSeq.OTHEROUT.getCaller();
|
|
|
+ }
|
|
|
+ billCode = maxnumberService.pushMaxnubmer(count, pi_inoutno, caller).getData();
|
|
|
+ }
|
|
|
+ return billCode;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|