diff --git a/src/main/java/com/gaotao/modules/finishedProduct/service/TransdetailService.java b/src/main/java/com/gaotao/modules/finishedProduct/service/TransdetailService.java index 1ab8969..f008dce 100644 --- a/src/main/java/com/gaotao/modules/finishedProduct/service/TransdetailService.java +++ b/src/main/java/com/gaotao/modules/finishedProduct/service/TransdetailService.java @@ -1,9 +1,18 @@ package com.gaotao.modules.finishedProduct.service; import com.baomidou.mybatisplus.extension.service.IService; - import com.gaotao.modules.finishedProduct.entity.Transdetail; -import com.gaotao.modules.finishedProduct.entity.Transdetailsub; + +import java.util.List; public interface TransdetailService extends IService { + + /** + * @author: sxm + * @description: 批量保存 + * @param [transdetailList] + * @return: void + * @date: 2022/12/27 16:39 + */ + void saveList(List transdetailList); } diff --git a/src/main/java/com/gaotao/modules/finishedProduct/service/TransheaderService.java b/src/main/java/com/gaotao/modules/finishedProduct/service/TransheaderService.java index 465fd7a..563b439 100644 --- a/src/main/java/com/gaotao/modules/finishedProduct/service/TransheaderService.java +++ b/src/main/java/com/gaotao/modules/finishedProduct/service/TransheaderService.java @@ -1,8 +1,11 @@ package com.gaotao.modules.finishedProduct.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.gaotao.modules.finishedProduct.entity.CRollinfoEntity; import com.gaotao.modules.finishedProduct.entity.Transheader; +import java.util.List; + public interface TransheaderService extends IService { /* @@ -13,4 +16,6 @@ public interface TransheaderService extends IService { * @return [java.lang.String] **/ Transheader getTransHeader(String pickingNo); + + void saveTransInfo(List list,String transType); } diff --git a/src/main/java/com/gaotao/modules/finishedProduct/service/impl/CRollinfoServiceImpl.java b/src/main/java/com/gaotao/modules/finishedProduct/service/impl/CRollinfoServiceImpl.java index 78c8620..5ded828 100644 --- a/src/main/java/com/gaotao/modules/finishedProduct/service/impl/CRollinfoServiceImpl.java +++ b/src/main/java/com/gaotao/modules/finishedProduct/service/impl/CRollinfoServiceImpl.java @@ -507,17 +507,25 @@ public class CRollinfoServiceImpl extends ServiceImpl cRollinfoList) { + if (CollectionUtils.isEmpty(cRollinfoList)) return; + transheaderService.saveTransInfo(cRollinfoList,"OC"); + // 修改卷状态 cRollinfoList.forEach(rollInfo -> { lambdaUpdate().set(CRollinfoEntity::getStatus, rollInfo.getStatus()) .set(CRollinfoEntity::getStatusDb, rollInfo.getStatusDb()) .set(StringUtils.isNotEmpty(rollInfo.getSynchronizedflag()), CRollinfoEntity::getSynchronizedflag, rollInfo.getSynchronizedflag()) + .set(CRollinfoEntity::getNeedsynchronizeflag,"N") .eq(StringUtils.isNotEmpty(rollInfo.getSite()), CRollinfoEntity::getSite, rollInfo.getSite()) .eq(CRollinfoEntity::getRollno, rollInfo.getRollno()) .update(); diff --git a/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransdetailServiceImpl.java b/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransdetailServiceImpl.java index e1363fb..c7172f4 100644 --- a/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransdetailServiceImpl.java +++ b/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransdetailServiceImpl.java @@ -4,8 +4,25 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gaotao.modules.finishedProduct.dao.TransdetailDao; import com.gaotao.modules.finishedProduct.entity.Transdetail; import com.gaotao.modules.finishedProduct.service.TransdetailService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.stereotype.Service; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import java.util.List; @Service +@Slf4j public class TransdetailServiceImpl extends ServiceImpl implements TransdetailService { + + @Override + public void saveList(List transDetailList) { + try{ + this.saveBatch(transDetailList,1000); + }catch (UncategorizedSQLException e){ + log.info("批量插入,卷信息"); + } catch (Exception e){ + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } + } } diff --git a/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransheaderServiceImpl.java b/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransheaderServiceImpl.java index 0328296..0a508a3 100644 --- a/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransheaderServiceImpl.java +++ b/src/main/java/com/gaotao/modules/finishedProduct/service/impl/TransheaderServiceImpl.java @@ -1,17 +1,35 @@ package com.gaotao.modules.finishedProduct.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gaotao.common.utils.RandomUtil; import com.gaotao.modules.finishedProduct.dao.TransheaderDao; +import com.gaotao.modules.finishedProduct.entity.CRollinfoEntity; +import com.gaotao.modules.finishedProduct.entity.Transdetail; +import com.gaotao.modules.finishedProduct.entity.Transdetailsub; import com.gaotao.modules.finishedProduct.entity.Transheader; +import com.gaotao.modules.finishedProduct.service.TransdetailService; +import com.gaotao.modules.finishedProduct.service.TransdetailsubService; import com.gaotao.modules.finishedProduct.service.TransheaderService; import com.gaotao.modules.sys.entity.SysUserEntity; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; +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.Calendar; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @Service public class TransheaderServiceImpl extends ServiceImpl implements TransheaderService { + @Autowired + private TransdetailService transdetailService; + @Autowired + private TransdetailsubService transdetailsubService; @Override public Transheader getTransHeader(String pickingNo) { SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); @@ -20,4 +38,63 @@ public class TransheaderServiceImpl extends ServiceImpl cRollinfoList,String tranType) { + SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + // transheader + String transHeaderNo = RandomUtil.getOrderNoByAtomic(user.getSite(), tranType); + Transheader herder = new Transheader(); + herder.setTransno(transHeaderNo); + herder.setSite(user.getSite()); + herder.setTranstypeDb("OI"); + herder.setUserid(user.getUsername()); + herder.setUsername(user.getUserDisplay()); + herder.setTransdate(Calendar.getInstance().getTime()); + herder.setStatus("已录入"); + String remark = ""; + switch (tranType){ + case "OI": + remark = "其它入库"; + break; + case "OC": + remark = "其它出库"; + break; + } + herder.setRemark(remark); + this.save(herder); + // transDetail + Map> partGroup = cRollinfoList.stream().collect(Collectors.groupingBy((CRollinfoEntity::getPartno))); + List transdetailList = new ArrayList<>(); + for (String partNo : partGroup.keySet() ){ + double itemNo = 1.0; + Double sumQty = partGroup.get(partNo).stream().collect(Collectors.summingDouble((CRollinfoEntity::getRollqty))); + Transdetail transdetail = new Transdetail(); + transdetail.setTransno(herder.getTransno()); + transdetail.setSite(user.getSite()); + transdetail.setPartno(partNo); + transdetail.setItemno(itemNo++); + transdetail.setTransqty(sumQty); + transdetail.setBatchno("*"); + transdetailList.add(transdetail); + } + transdetailService.saveBatch(transdetailList,1000); + // transDetailSub + List transdetailsubs = new ArrayList<>(); + for (int i = 0; i < cRollinfoList.size(); i++) { + CRollinfoEntity cRollinfoEntity = cRollinfoList.get(i); + Transdetailsub sub = new Transdetailsub(); + sub.setSite(cRollinfoEntity.getSite()); + sub.setSubqty(cRollinfoEntity.getRollqty()); + sub.setOrderref1(cRollinfoEntity.getOrderref1() != null ? cRollinfoEntity.getOrderref1() : ""); + sub.setOrderref3(cRollinfoEntity.getOrderref2() != null ? cRollinfoEntity.getOrderref2() : ""); + sub.setItemno(1.0 + i); + sub.setTransno(herder.getTransno()); + sub.setSubno(cRollinfoEntity.getRollno()); + sub.setDirection("-"); + transdetailsubs.add(sub); + } + transdetailsubService.saveBatch(transdetailsubs,1000); + } }