|
@@ -1,102 +1,179 @@
|
|
|
package org.jeecg.modules.saleCode.service.impl;
|
|
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.jeecg.modules.purCode.entity.PurDeliveryNoteArrival;
|
|
|
import org.jeecg.modules.saleCode.entity.SaleDelivery;
|
|
|
import org.jeecg.modules.saleCode.entity.SaleDeliveryShip;
|
|
|
import org.jeecg.modules.saleCode.entity.SaleDeliveryDetails;
|
|
|
+import org.jeecg.modules.saleCode.entity.SaleOrderProduct;
|
|
|
import org.jeecg.modules.saleCode.mapper.SaleDeliveryShipMapper;
|
|
|
import org.jeecg.modules.saleCode.mapper.SaleDeliveryDetailsMapper;
|
|
|
import org.jeecg.modules.saleCode.mapper.SaleDeliveryMapper;
|
|
|
+import org.jeecg.modules.saleCode.mapper.SaleOrderProductMapper;
|
|
|
import org.jeecg.modules.saleCode.service.ISaleDeliveryService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Collection;
|
|
|
|
|
|
/**
|
|
|
* @Description: 发货通知单(delivery notice)
|
|
|
* @Author: jeecg-boot
|
|
|
- * @Date: 2024-12-11
|
|
|
+ * @Date: 2024-12-11
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Service
|
|
|
public class SaleDeliveryServiceImpl extends ServiceImpl<SaleDeliveryMapper, SaleDelivery> implements ISaleDeliveryService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private SaleDeliveryMapper saleDeliveryMapper;
|
|
|
- @Autowired
|
|
|
- private SaleDeliveryShipMapper saleDeliveryShipMapper;
|
|
|
- @Autowired
|
|
|
- private SaleDeliveryDetailsMapper saleDeliveryDetailsMapper;
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void saveMain(SaleDelivery saleDelivery, List<SaleDeliveryShip> saleDeliveryShipList,List<SaleDeliveryDetails> saleDeliveryDetailsList) {
|
|
|
- saleDeliveryMapper.insert(saleDelivery);
|
|
|
- if(saleDeliveryShipList!=null && saleDeliveryShipList.size()>0) {
|
|
|
- for(SaleDeliveryShip entity:saleDeliveryShipList) {
|
|
|
- entity.setId(null);
|
|
|
- //外键设置
|
|
|
- entity.setHeadId(saleDelivery.getId());
|
|
|
- saleDeliveryShipMapper.insert(entity);
|
|
|
- }
|
|
|
- }
|
|
|
- if(saleDeliveryDetailsList!=null && saleDeliveryDetailsList.size()>0) {
|
|
|
- for(SaleDeliveryDetails entity:saleDeliveryDetailsList) {
|
|
|
- entity.setId(null);
|
|
|
- //外键设置
|
|
|
- entity.setHeadId(saleDelivery.getId());
|
|
|
- saleDeliveryDetailsMapper.insert(entity);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateMain(SaleDelivery saleDelivery,List<SaleDeliveryShip> saleDeliveryShipList,List<SaleDeliveryDetails> saleDeliveryDetailsList) {
|
|
|
- saleDeliveryMapper.updateById(saleDelivery);
|
|
|
-
|
|
|
- //1.先删除子表数据
|
|
|
- saleDeliveryShipMapper.deleteByMainId(saleDelivery.getId());
|
|
|
- saleDeliveryDetailsMapper.deleteByMainId(saleDelivery.getId());
|
|
|
-
|
|
|
- //2.子表数据重新插入
|
|
|
- if(saleDeliveryShipList!=null && saleDeliveryShipList.size()>0) {
|
|
|
- for(SaleDeliveryShip entity:saleDeliveryShipList) {
|
|
|
- entity.setId(null);
|
|
|
- //外键设置
|
|
|
- entity.setHeadId(saleDelivery.getId());
|
|
|
- saleDeliveryShipMapper.insert(entity);
|
|
|
- }
|
|
|
- }
|
|
|
- if(saleDeliveryDetailsList!=null && saleDeliveryDetailsList.size()>0) {
|
|
|
- for(SaleDeliveryDetails entity:saleDeliveryDetailsList) {
|
|
|
- entity.setId(null);
|
|
|
- //外键设置
|
|
|
- entity.setHeadId(saleDelivery.getId());
|
|
|
- saleDeliveryDetailsMapper.insert(entity);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void delMain(String id) {
|
|
|
- saleDeliveryShipMapper.deleteByMainId(id);
|
|
|
- saleDeliveryDetailsMapper.deleteByMainId(id);
|
|
|
- saleDeliveryMapper.deleteById(id);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void delBatchMain(Collection<? extends Serializable> idList) {
|
|
|
- for(Serializable id:idList) {
|
|
|
- saleDeliveryShipMapper.deleteByMainId(id.toString());
|
|
|
- saleDeliveryDetailsMapper.deleteByMainId(id.toString());
|
|
|
- saleDeliveryMapper.deleteById(id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private SaleDeliveryMapper saleDeliveryMapper;
|
|
|
+ @Autowired
|
|
|
+ private SaleDeliveryShipMapper saleDeliveryShipMapper;
|
|
|
+ @Autowired
|
|
|
+ private SaleDeliveryDetailsMapper saleDeliveryDetailsMapper;
|
|
|
+ @Autowired
|
|
|
+ private SaleOrderProductMapper saleOrderProductMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void saveMain(SaleDelivery saleDelivery, List<SaleDeliveryShip> saleDeliveryShipList, List<SaleDeliveryDetails> saleDeliveryDetailsList) {
|
|
|
+ saleDeliveryMapper.insert(saleDelivery);
|
|
|
+ if (saleDeliveryShipList != null && saleDeliveryShipList.size() > 0) {
|
|
|
+ for (SaleDeliveryShip entity : saleDeliveryShipList) {
|
|
|
+ entity.setId(null);
|
|
|
+ //外键设置
|
|
|
+ entity.setHeadId(saleDelivery.getId());
|
|
|
+ saleDeliveryShipMapper.insert(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (saleDeliveryDetailsList != null && saleDeliveryDetailsList.size() > 0) {
|
|
|
+ for (SaleDeliveryDetails entity : saleDeliveryDetailsList) {
|
|
|
+ entity.setId(null);
|
|
|
+ //外键设置
|
|
|
+ entity.setHeadId(saleDelivery.getId());
|
|
|
+ saleDeliveryDetailsMapper.insert(entity);
|
|
|
+
|
|
|
+
|
|
|
+ String sourceId = entity.getSourceId();
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(sourceId)) {
|
|
|
+
|
|
|
+ BigDecimal stockInQuantity = entity.getQuantity() == null ? BigDecimal.ZERO : entity.getQuantity();//入库数量
|
|
|
+
|
|
|
+ SaleOrderProduct arrival = saleOrderProductMapper.selectById(sourceId);
|
|
|
+ if (arrival != null) {
|
|
|
+ BigDecimal arrivalQuantity = arrival.getDeliveryQuantity() == null ? BigDecimal.ZERO : arrival.getDeliveryQuantity();//到货数量
|
|
|
+
|
|
|
+ arrivalQuantity = arrivalQuantity.add(stockInQuantity);
|
|
|
+ arrival.setDeliveryQuantity(arrivalQuantity);
|
|
|
+ saleOrderProductMapper.updateById(arrival);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updateMain(SaleDelivery saleDelivery, List<SaleDeliveryShip> saleDeliveryShipList, List<SaleDeliveryDetails> saleDeliveryDetailsList) {
|
|
|
+
|
|
|
+ List<SaleDeliveryDetails> detailsList = saleDeliveryDetailsMapper.selectByMainId(saleDelivery.getId());
|
|
|
+
|
|
|
+ if (detailsList != null && detailsList.size() > 0) {
|
|
|
+
|
|
|
+ for (SaleDeliveryDetails entity : detailsList) {
|
|
|
+
|
|
|
+ String sourceId = entity.getSourceId();
|
|
|
+ if (StringUtils.isNotBlank(sourceId)) {
|
|
|
+
|
|
|
+ BigDecimal deliveryQuantity = entity.getDeliveryQuantity() == null ? BigDecimal.ZERO : entity.getDeliveryQuantity();//入库数量
|
|
|
+ SaleOrderProduct arrival = saleOrderProductMapper.selectById(sourceId);
|
|
|
+
|
|
|
+ if (arrival != null) {
|
|
|
+ BigDecimal arrivalQuantity = arrival.getDeliveryQuantity() == null ? BigDecimal.ZERO : arrival.getDeliveryQuantity();//到货数量
|
|
|
+
|
|
|
+ arrivalQuantity = arrivalQuantity.subtract(deliveryQuantity);
|
|
|
+
|
|
|
+ if (arrivalQuantity.compareTo(BigDecimal.ZERO) < 1) {
|
|
|
+ arrival.setDeliveryQuantity(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ arrival.setDeliveryQuantity(arrivalQuantity);
|
|
|
+ }
|
|
|
+ saleOrderProductMapper.updateById(arrival);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ saleDeliveryMapper.updateById(saleDelivery);
|
|
|
+
|
|
|
+ //1.先删除子表数据
|
|
|
+ saleDeliveryShipMapper.deleteByMainId(saleDelivery.getId());
|
|
|
+ saleDeliveryDetailsMapper.deleteByMainId(saleDelivery.getId());
|
|
|
+
|
|
|
+ //2.子表数据重新插入
|
|
|
+ if (saleDeliveryShipList != null && saleDeliveryShipList.size() > 0) {
|
|
|
+ for (SaleDeliveryShip entity : saleDeliveryShipList) {
|
|
|
+ entity.setId(null);
|
|
|
+ //外键设置
|
|
|
+ entity.setHeadId(saleDelivery.getId());
|
|
|
+ saleDeliveryShipMapper.insert(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (saleDeliveryDetailsList != null && saleDeliveryDetailsList.size() > 0) {
|
|
|
+ for (SaleDeliveryDetails entity : saleDeliveryDetailsList) {
|
|
|
+ entity.setId(null);
|
|
|
+ //外键设置
|
|
|
+ entity.setHeadId(saleDelivery.getId());
|
|
|
+ saleDeliveryDetailsMapper.insert(entity);
|
|
|
+
|
|
|
+ String sourceId = entity.getSourceId();
|
|
|
+ if(StringUtils.isNotBlank(sourceId)){
|
|
|
+
|
|
|
+ BigDecimal stockInQuantity = entity.getQuantity() == null ? BigDecimal.ZERO : entity.getQuantity();//入库数量
|
|
|
+
|
|
|
+ SaleOrderProduct arrival = saleOrderProductMapper.selectById(sourceId);
|
|
|
+ if (arrival != null) {
|
|
|
+ BigDecimal arrivalQuantity = arrival.getDeliveryQuantity() == null ? BigDecimal.ZERO : arrival.getDeliveryQuantity();//到货数量
|
|
|
+
|
|
|
+ arrivalQuantity = arrivalQuantity.add(stockInQuantity);
|
|
|
+ arrival.setDeliveryQuantity(arrivalQuantity);
|
|
|
+ saleOrderProductMapper.updateById(arrival);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void delMain(String id) {
|
|
|
+ saleDeliveryShipMapper.deleteByMainId(id);
|
|
|
+ saleDeliveryDetailsMapper.deleteByMainId(id);
|
|
|
+ saleDeliveryMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void delBatchMain(Collection<? extends Serializable> idList) {
|
|
|
+ for (Serializable id : idList) {
|
|
|
+ saleDeliveryShipMapper.deleteByMainId(id.toString());
|
|
|
+ saleDeliveryDetailsMapper.deleteByMainId(id.toString());
|
|
|
+ saleDeliveryMapper.deleteById(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|