|
|
@@ -1,12 +1,335 @@
|
|
|
package com.usoftchina.saas.storage.service.impl;
|
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.usoftchina.saas.base.Result;
|
|
|
import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
|
|
|
+import com.usoftchina.saas.commons.api.MaxnumberService;
|
|
|
+import com.usoftchina.saas.commons.dto.BatchDealBaseDTO;
|
|
|
+import com.usoftchina.saas.commons.dto.DocBaseDTO;
|
|
|
+import com.usoftchina.saas.commons.dto.DocSavedDTO;
|
|
|
+import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
+import com.usoftchina.saas.document.api.WarehouseApi;
|
|
|
+import com.usoftchina.saas.exception.BizException;
|
|
|
+import com.usoftchina.saas.exception.ExceptionCode;
|
|
|
+import com.usoftchina.saas.page.PageRequest;
|
|
|
+import com.usoftchina.saas.storage.dto.ProdIODetailDTO;
|
|
|
+import com.usoftchina.saas.storage.dto.ProdInOutDTO;
|
|
|
+import com.usoftchina.saas.storage.dto.ProdInOutFormDTO;
|
|
|
+import com.usoftchina.saas.storage.dto.ProdInOutReqDTO;
|
|
|
+import com.usoftchina.saas.storage.entities.ProdIODetail;
|
|
|
import com.usoftchina.saas.storage.entities.ProdInOut;
|
|
|
+import com.usoftchina.saas.storage.entities.ProdInOutList;
|
|
|
+import com.usoftchina.saas.storage.mapper.ProdIODetailMapper;
|
|
|
+import com.usoftchina.saas.storage.mapper.ProdInOutListMapper;
|
|
|
import com.usoftchina.saas.storage.mapper.ProdInOutMapper;
|
|
|
import com.usoftchina.saas.storage.service.ProdInOutService;
|
|
|
+import com.usoftchina.saas.utils.BeanMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class ProdInoutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper, ProdInOut> implements ProdInOutService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProdIODetailMapper prodIODetailMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProdInOutListMapper prodInOutListMapper;
|
|
|
+ @Autowired
|
|
|
+ private WarehouseApi warehouseApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MaxnumberService maxnumberService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo<ProdInOutList> getListData(PageRequest page, ProdInOutReqDTO req) {
|
|
|
+ //设置默认分页
|
|
|
+ //设置默认分页
|
|
|
+ if (null == page || page.getSize() == 0 || page.getNumber() == 0) {
|
|
|
+ page = new PageRequest();
|
|
|
+ page.setNumber(1);
|
|
|
+ page.setSize(10);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(page.getNumber(), page.getSize());
|
|
|
+ //查询数据
|
|
|
+ List<ProdInOutList> lists = getListByMode(req);
|
|
|
+ //取分页信息
|
|
|
+ PageInfo<ProdInOutList> pageInfo = new PageInfo<ProdInOutList>(lists);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ProdInOutList> getListByMode(ProdInOutReqDTO req) {
|
|
|
+ List<ProdInOutList> list = null;
|
|
|
+ if (null == req || StringUtils.isEmpty(req.getMode()) || "Main".equals(req.getMode())) {
|
|
|
+ list = prodInOutListMapper.selectProdInOutListByCondition(req);
|
|
|
+ } else {
|
|
|
+ list = prodInOutListMapper.selectProdInOutBycondition(req);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProdInOutFormDTO getFormData(Long id) {
|
|
|
+ ProdInOutFormDTO prodInOutFormDTO = new ProdInOutFormDTO();
|
|
|
+ //查询主表
|
|
|
+ ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
|
|
|
+ //将prodInOut实体对象转化为传输对象
|
|
|
+ ProdInOutDTO main = BeanMapper.map(prodInOut,ProdInOutDTO.class);
|
|
|
+ //查询从表
|
|
|
+
|
|
|
+ List<ProdIODetail> prodIODetails =prodIODetailMapper.selectByFK(id);
|
|
|
+ List<ProdIODetailDTO> items = BeanMapper.mapList(prodIODetails,ProdIODetailDTO.class);
|
|
|
+ prodInOutFormDTO.setMain(main);
|
|
|
+ prodInOutFormDTO.setItems(items);
|
|
|
+ return prodInOutFormDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DocSavedDTO saveFormData(ProdInOutFormDTO formdata, Boolean isbfaudit) {
|
|
|
+ if (null == formdata || null == formdata.getMain()){
|
|
|
+ throw new BizException(500, "数据为空,请填写后再保存");
|
|
|
+ }
|
|
|
+ //公司ID
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ //人员Id
|
|
|
+ Long userId = BaseContextHolder.getUserId();
|
|
|
+ //获取主表信息
|
|
|
+ ProdInOutDTO main = formdata.getMain();
|
|
|
+ List<ProdIODetailDTO> items = formdata.getItems();
|
|
|
+ //插入从表数据
|
|
|
+ List<ProdIODetail> insertDetails = new ArrayList<>();
|
|
|
+ //更新从表数据
|
|
|
+ List<ProdIODetail> updateDetails = new ArrayList<>();
|
|
|
+ DocSavedDTO saveDTO = new DocSavedDTO();
|
|
|
+ Long pi_id = main.getId();
|
|
|
+ String pi_inoutno = main.getPi_inoutno();
|
|
|
+ ProdInOut prodInOut = BeanMapper.map(main,ProdInOut.class);
|
|
|
+ prodInOut.setCompanyId(companyId);
|
|
|
+ prodInOut.setCreatorId(userId);
|
|
|
+ prodInOut.setCreateTime(new Date());
|
|
|
+ prodInOut.setPi_date(new Date());
|
|
|
+ prodInOut.setPi_puid(main.getPi_puid());
|
|
|
+ prodInOut.setPi_pucode(main.getPi_pucode());
|
|
|
+ //编号获取
|
|
|
+ //pi_inoutno = pushMaxnubmer(pi_inoutno, pi_id);
|
|
|
+ prodInOut.setPi_inoutno(pi_inoutno);
|
|
|
+ saveDTO.setCode(pi_inoutno);
|
|
|
+ //判断更新与保存动作
|
|
|
+ if (StringUtils.isEmpty(pi_id) || "0".equals(pi_id.toString())){
|
|
|
+ //插入操作
|
|
|
+ getMapper().insertSelective(prodInOut);
|
|
|
+ pi_id = prodInOut.getId();
|
|
|
+ //添加从表传输对象
|
|
|
+ for (ProdIODetailDTO item : items) {
|
|
|
+ ProdIODetail detail = BeanMapper.map(item,ProdIODetail.class);
|
|
|
+ detail.setPd_piid(pi_id);
|
|
|
+ detail.setPd_inoutno(pi_inoutno);
|
|
|
+ detail.setPd_piclass(prodInOut.getPi_class());
|
|
|
+ detail.setPd_yqty(0);
|
|
|
+ insertDetails.add(detail);
|
|
|
+ }
|
|
|
+ //插入从表
|
|
|
+ if (insertDetails.size()>0) {
|
|
|
+ prodIODetailMapper.batchInsert(insertDetails);
|
|
|
+ }
|
|
|
+ saveDTO.setId(pi_id);
|
|
|
+ return saveDTO;
|
|
|
+ }
|
|
|
+ //更新操作
|
|
|
+ getMapper().updateByPrimaryKeySelective(prodInOut);
|
|
|
+ //添加从表传输对象
|
|
|
+ for (ProdIODetailDTO item : items) {
|
|
|
+ ProdIODetail detail = BeanMapper.map(item, ProdIODetail.class);
|
|
|
+ detail.setPd_piid(pi_id);
|
|
|
+ detail.setPd_inoutno(pi_inoutno);
|
|
|
+ detail.setPd_piclass(prodInOut.getPi_class());
|
|
|
+ if (StringUtils.isEmpty(detail.getId()) || "0".equals(detail.getId().toString())) {
|
|
|
+ insertDetails.add(detail);
|
|
|
+ } else {
|
|
|
+ updateDetails.add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //插入从表
|
|
|
+ if (insertDetails.size()>0) {
|
|
|
+ prodIODetailMapper.batchInsert(insertDetails);
|
|
|
+ }
|
|
|
+ //更新从表
|
|
|
+ if (updateDetails.size()>0) {
|
|
|
+ prodIODetailMapper.batchUpdate(updateDetails);
|
|
|
+ }
|
|
|
+ saveDTO.setId(pi_id);
|
|
|
+ //更新已转数
|
|
|
+ if (!isbfaudit)
|
|
|
+ updateYqty(prodInOut);
|
|
|
+ return saveDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ singleDelete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void singleDelete(Long id) {
|
|
|
+ if (null != id) {
|
|
|
+ ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
|
|
|
+ //删除主键
|
|
|
+ getMapper().deleteByPrimaryKey(prodInOut.getId());
|
|
|
+ //TODO 删除从表
|
|
|
+
|
|
|
+ //更新已转数
|
|
|
+// updateYqty(prodInOut.getPi_puid(),prodInOut.getPi_class());
|
|
|
+ updateYqty(prodInOut);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DocSavedDTO audit(ProdInOutFormDTO formData) {
|
|
|
+ Long id = null;
|
|
|
+ DocSavedDTO savedDTO = new DocSavedDTO();
|
|
|
+ if (null != formData) {
|
|
|
+ id = formData.getMain().getId();
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ DocSavedDTO saveDTO = saveFormData(formData,true);
|
|
|
+ id = saveDTO.getId();
|
|
|
+ }
|
|
|
+ singleAudit(formData.getMain());
|
|
|
+ }
|
|
|
+ savedDTO.setId(id);
|
|
|
+ return savedDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void unAudit(Long id) {
|
|
|
+ ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
|
|
|
+ ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
|
|
|
+ singleAudit(prodInOutDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchAudit(BatchDealBaseDTO baseDTOs) {
|
|
|
+ for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
|
|
|
+ Long id = base.getId();
|
|
|
+ ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
|
|
|
+ ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
|
|
|
+ singleAudit(prodInOutDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void singleAudit(ProdInOutDTO prodInOutDTO) {
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("inoutNo",prodInOutDTO.getPi_inoutno() );
|
|
|
+ map.put("class",prodInOutDTO.getPi_class() );
|
|
|
+ map.put("commitid",prodInOutDTO.getPi_recordmanid());
|
|
|
+ map.put("companyid",prodInOutDTO.getCompanyId());
|
|
|
+ map.put("result","");
|
|
|
+ warehouseApi.post(map);
|
|
|
+ Object result = map.get("result");
|
|
|
+ System.out.println("result");
|
|
|
+ //记录日志
|
|
|
+ if (!StringUtils.isEmpty(result))
|
|
|
+ throw new BizException(500, "存在已审核单据,单据编号:" + result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteItem(Long id) {
|
|
|
+ ProdIODetail prodIODetail = prodIODetailMapper.selectByPrimaryKey(id);
|
|
|
+ prodIODetailMapper.deleteByPrimaryKey(id);
|
|
|
+ ProdInOut prodInOut = getMapper().selectByPrimaryKey(prodIODetail.getPd_piid());
|
|
|
+ //更新已转数
|
|
|
+ updateYqty(prodInOut);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchDelete(BatchDealBaseDTO baseDTOs) {
|
|
|
+ if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
|
|
|
+ baseDTOs.getBaseDTOs().size() == 0)
|
|
|
+ return;
|
|
|
+ for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
|
|
|
+ singleDelete(base.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateYqty(ProdInOut prodInOut) {
|
|
|
+ //TODO 更新已转数
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result turnProdOut(Long id) {
|
|
|
+ ProdInOut sourcePi = getMapper().selectByPrimaryKey(id);
|
|
|
+ Integer count=0;
|
|
|
+ double pdInqty=0, pdYqty=0;
|
|
|
+ List<ProdIODetail> sourcePids =prodIODetailMapper.selectByFK(id);
|
|
|
+ //检查从表
|
|
|
+ for (ProdIODetail prodIODetail : sourcePids) {
|
|
|
+ pdInqty = prodIODetail.getPd_inqty();
|
|
|
+ pdYqty = prodIODetail.getPd_yqty();
|
|
|
+ if (pdInqty-pdYqty>0){
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断可转数
|
|
|
+ if (count==0) {
|
|
|
+ return Result.error(ExceptionCode.TURNINNUM_NOT_EXIST);
|
|
|
+ }
|
|
|
+ //插入验退单主表
|
|
|
+ ProdInOut targetPi = new ProdInOut();
|
|
|
+ //生成单号
|
|
|
+ String piInoutno = "YT0001";
|
|
|
+ targetPi.setPi_inoutno(piInoutno);
|
|
|
+ targetPi.setPi_class("采购验退单");
|
|
|
+ targetPi.setPi_date(new Date());
|
|
|
+ targetPi.setPi_recorddate(new Date());
|
|
|
+ targetPi.setPi_vendcode(sourcePi.getPi_vendcode());
|
|
|
+ targetPi.setPi_vendname(sourcePi.getPi_vendname());
|
|
|
+ targetPi.setPi_puid(sourcePi.getPi_puid());
|
|
|
+ targetPi.setPi_pucode(sourcePi.getPi_pucode());
|
|
|
+ //设置公司id
|
|
|
+ targetPi.setCompanyId(sourcePi.getCompanyId());
|
|
|
+ //保存数据
|
|
|
+ getMapper().insertSelective(targetPi);
|
|
|
+ //插入验退单从表
|
|
|
+ long pi_id = targetPi.getId();
|
|
|
+ for (int i = 0;i<sourcePids.size();i++){
|
|
|
+ ProdIODetail sourcePid = sourcePids.get(i);
|
|
|
+ ProdIODetail targetPid = new ProdIODetail();
|
|
|
+ if(sourcePid.getPd_inqty()-sourcePid.getPd_yqty()>0){
|
|
|
+ targetPid.setPd_piid(pi_id);
|
|
|
+ targetPid.setPd_inoutno(piInoutno);
|
|
|
+ targetPid.setPd_piclass("采购验退单");
|
|
|
+ targetPid.setPd_pdno(i);
|
|
|
+ targetPid.setPd_orderid(sourcePid.getPd_orderid());
|
|
|
+ targetPid.setPd_ordercode(sourcePid.getPd_ordercode());
|
|
|
+ targetPid.setPd_orderdetno(sourcePid.getPd_orderdetno());
|
|
|
+ targetPid.setPd_orderprice(sourcePid.getPd_orderprice());
|
|
|
+ targetPid.setPd_prodid(sourcePid.getPd_prodid());
|
|
|
+ targetPid.setPd_prodcode(sourcePid.getPd_prodcode());
|
|
|
+ targetPid.setPd_ioid(sourcePid.getId());
|
|
|
+ //公司id
|
|
|
+ targetPid.setCompanyId(sourcePid.getCompanyId());
|
|
|
+ //本次转单数
|
|
|
+ targetPid.setPd_outqty(sourcePid.getPd_inqty()-sourcePid.getPd_yqty());
|
|
|
+ prodIODetailMapper.insertSelective(targetPid);
|
|
|
+ //更新已转数
|
|
|
+ sourcePid.setPd_yqty(sourcePid.getPd_inqty());
|
|
|
+ prodIODetailMapper.updateByPrimaryKeySelective(sourcePid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /*private String pushMaxnubmer(String code, Long id) {
|
|
|
+ if (null == code) {
|
|
|
+ throw new BizException(BizExceptionCode.NULL_CODE);
|
|
|
+ }
|
|
|
|
|
|
+ return maxnumberService.pushMaxnubmer(count, code, "Purchase");
|
|
|
+ }*/
|
|
|
|
|
|
}
|