|
@@ -14,14 +14,12 @@ import com.lframework.starter.mq.core.service.MqProducerService; |
|
@@ -14,14 +14,12 @@ import com.lframework.starter.mq.core.service.MqProducerService; |
|
14
|
import com.lframework.starter.web.core.components.security.SecurityUtil;
|
14
|
import com.lframework.starter.web.core.components.security.SecurityUtil;
|
|
15
|
import com.lframework.starter.web.inner.dto.message.SysSiteMessageDto;
|
15
|
import com.lframework.starter.web.inner.dto.message.SysSiteMessageDto;
|
|
16
|
import com.lframework.starter.web.inner.entity.SysDataDicItem;
|
16
|
import com.lframework.starter.web.inner.entity.SysDataDicItem;
|
|
17
|
-import com.lframework.starter.web.inner.entity.SysRole;
|
|
|
|
18
|
import com.lframework.starter.web.inner.service.system.SysDataDicItemService;
|
17
|
import com.lframework.starter.web.inner.service.system.SysDataDicItemService;
|
|
19
|
import com.lframework.starter.web.inner.service.system.SysRoleService;
|
18
|
import com.lframework.starter.web.inner.service.system.SysRoleService;
|
|
20
|
import com.lframework.starter.web.inner.service.system.SysUserDeptService;
|
19
|
import com.lframework.starter.web.inner.service.system.SysUserDeptService;
|
|
21
|
import com.lframework.starter.web.inner.service.system.SysUserRoleService;
|
20
|
import com.lframework.starter.web.inner.service.system.SysUserRoleService;
|
|
22
|
import com.lframework.xingyun.basedata.entity.Workshop;
|
21
|
import com.lframework.xingyun.basedata.entity.Workshop;
|
|
23
|
import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
|
22
|
import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
|
|
24
|
-import com.lframework.xingyun.basedata.vo.workshop.QueryWorkshopVo;
|
|
|
|
25
|
import com.lframework.xingyun.sc.controller.contract.ContractDistributorStandardController;
|
23
|
import com.lframework.xingyun.sc.controller.contract.ContractDistributorStandardController;
|
|
26
|
import com.lframework.xingyun.sc.entity.*;
|
24
|
import com.lframework.xingyun.sc.entity.*;
|
|
27
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
25
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
|
@@ -53,13 +51,12 @@ import com.lframework.xingyun.sc.vo.contract.updateVo.UpdateContractStdProcessin |
|
@@ -53,13 +51,12 @@ import com.lframework.xingyun.sc.vo.contract.updateVo.UpdateContractStdProcessin |
|
53
|
import com.lframework.xingyun.sc.vo.order.CreatePurchaseOrderInfoVo;
|
51
|
import com.lframework.xingyun.sc.vo.order.CreatePurchaseOrderInfoVo;
|
|
54
|
import com.lframework.xingyun.sc.vo.order.CreatePurchaseOrderLineVo;
|
52
|
import com.lframework.xingyun.sc.vo.order.CreatePurchaseOrderLineVo;
|
|
55
|
import com.lframework.xingyun.sc.vo.order.QueryPurchaseOrderLineVo;
|
53
|
import com.lframework.xingyun.sc.vo.order.QueryPurchaseOrderLineVo;
|
|
|
|
54
|
+import cn.hutool.core.bean.BeanUtil;
|
|
56
|
import lombok.extern.slf4j.Slf4j;
|
55
|
import lombok.extern.slf4j.Slf4j;
|
|
57
|
import org.apache.commons.collections4.CollectionUtils;
|
56
|
import org.apache.commons.collections4.CollectionUtils;
|
|
58
|
import org.apache.commons.lang3.StringUtils;
|
57
|
import org.apache.commons.lang3.StringUtils;
|
|
59
|
import org.springframework.beans.factory.annotation.Autowired;
|
58
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
60
|
import org.springframework.cache.annotation.CacheEvict;
|
59
|
import org.springframework.cache.annotation.CacheEvict;
|
|
61
|
-import org.springframework.cache.annotation.Cacheable;
|
|
|
|
62
|
-import org.springframework.security.core.parameters.P;
|
|
|
|
63
|
import org.springframework.stereotype.Service;
|
60
|
import org.springframework.stereotype.Service;
|
|
64
|
import org.springframework.transaction.annotation.Transactional;
|
61
|
import org.springframework.transaction.annotation.Transactional;
|
|
65
|
|
62
|
|
|
@@ -217,7 +214,9 @@ public class ContractDistributorStandardServiceImpl extends |
|
@@ -217,7 +214,9 @@ public class ContractDistributorStandardServiceImpl extends |
|
217
|
@Override
|
214
|
@Override
|
|
218
|
public List<ContractDistributorStandard> query(QueryContractDistributorStandardVo vo) {
|
215
|
public List<ContractDistributorStandard> query(QueryContractDistributorStandardVo vo) {
|
|
219
|
|
216
|
|
|
220
|
- return getBaseMapper().query(vo);
|
217
|
+ List<ContractDistributorStandard> datas = getBaseMapper().query(vo);
|
|
|
|
218
|
+ CollectionUtils.emptyIfNull(datas).forEach(data -> data.setCanSplit(isCanSplitByCode(data.getCode())));
|
|
|
|
219
|
+ return datas;
|
|
221
|
}
|
220
|
}
|
|
222
|
|
221
|
|
|
223
|
@Override
|
222
|
@Override
|
|
@@ -227,6 +226,7 @@ public class ContractDistributorStandardServiceImpl extends |
|
@@ -227,6 +226,7 @@ public class ContractDistributorStandardServiceImpl extends |
|
227
|
if (data == null) {
|
226
|
if (data == null) {
|
|
228
|
return null;
|
227
|
return null;
|
|
229
|
}
|
228
|
}
|
|
|
|
229
|
+ data.setCanSplit(isCanSplitByCode(data.getCode()));
|
|
230
|
Wrapper<PurchaseOrderInfo> orderInfoWrapper = Wrappers.lambdaQuery(PurchaseOrderInfo.class)
|
230
|
Wrapper<PurchaseOrderInfo> orderInfoWrapper = Wrappers.lambdaQuery(PurchaseOrderInfo.class)
|
|
231
|
.eq(PurchaseOrderInfo::getContractId, data.getId());
|
231
|
.eq(PurchaseOrderInfo::getContractId, data.getId());
|
|
232
|
List<PurchaseOrderInfo> purchaseOrderInfoList = purchaseOrderInfoService.list(orderInfoWrapper);
|
232
|
List<PurchaseOrderInfo> purchaseOrderInfoList = purchaseOrderInfoService.list(orderInfoWrapper);
|
|
@@ -259,6 +259,13 @@ public class ContractDistributorStandardServiceImpl extends |
|
@@ -259,6 +259,13 @@ public class ContractDistributorStandardServiceImpl extends |
|
259
|
return data;
|
259
|
return data;
|
|
260
|
}
|
260
|
}
|
|
261
|
|
261
|
|
|
|
|
262
|
+ private boolean isCanSplitByCode(String code) {
|
|
|
|
263
|
+ if (StringUtils.isBlank(code)) {
|
|
|
|
264
|
+ return false;
|
|
|
|
265
|
+ }
|
|
|
|
266
|
+ return !code.matches(".*_\\d{2}$");
|
|
|
|
267
|
+ }
|
|
|
|
268
|
+
|
|
262
|
@OpLog(type = OtherOpLogType.class, name = "新增合同,ID:{}", params = {"#id"})
|
269
|
@OpLog(type = OtherOpLogType.class, name = "新增合同,ID:{}", params = {"#id"})
|
|
263
|
@Transactional(rollbackFor = Exception.class)
|
270
|
@Transactional(rollbackFor = Exception.class)
|
|
264
|
@Override
|
271
|
@Override
|
|
@@ -726,6 +733,119 @@ public class ContractDistributorStandardServiceImpl extends |
|
@@ -726,6 +733,119 @@ public class ContractDistributorStandardServiceImpl extends |
|
726
|
}
|
733
|
}
|
|
727
|
}
|
734
|
}
|
|
728
|
|
735
|
|
|
|
|
736
|
+ @Override
|
|
|
|
737
|
+ @OpLog(type = OtherOpLogType.class, name = "合同拆分,ID:{}", params = {"#vo.id"})
|
|
|
|
738
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
739
|
+ public void splitInventoryContract(UpdateContractDistributorStandardVo vo) {
|
|
|
|
740
|
+ if (vo == null || StringUtils.isBlank(vo.getId())) {
|
|
|
|
741
|
+ throw new DefaultClientException("参数错误!");
|
|
|
|
742
|
+ }
|
|
|
|
743
|
+
|
|
|
|
744
|
+ List<UpdateContractDistributorLineVo> lineVoList = vo.getContractDistributorLineList();
|
|
|
|
745
|
+ if (CollectionUtils.isEmpty(lineVoList)) {
|
|
|
|
746
|
+ return;
|
|
|
|
747
|
+ }
|
|
|
|
748
|
+
|
|
|
|
749
|
+ BigDecimal splitTotalQuantity = BigDecimal.ZERO;
|
|
|
|
750
|
+ List<UpdateContractDistributorLineVo> splitLineVoList = new ArrayList<>();
|
|
|
|
751
|
+ for (UpdateContractDistributorLineVo lineVo : lineVoList) {
|
|
|
|
752
|
+ if (lineVo == null) {
|
|
|
|
753
|
+ continue;
|
|
|
|
754
|
+ }
|
|
|
|
755
|
+ BigDecimal currentQuantity = lineVo.getCurrentQuantity();
|
|
|
|
756
|
+ if (currentQuantity != null && currentQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
757
|
+ splitLineVoList.add(lineVo);
|
|
|
|
758
|
+ splitTotalQuantity = splitTotalQuantity.add(currentQuantity);
|
|
|
|
759
|
+ }
|
|
|
|
760
|
+ }
|
|
|
|
761
|
+ if (splitLineVoList.isEmpty() || splitTotalQuantity.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
762
|
+ return;
|
|
|
|
763
|
+ }
|
|
|
|
764
|
+
|
|
|
|
765
|
+ ContractDistributorStandard original = getBaseMapper().selectById(vo.getId());
|
|
|
|
766
|
+ if (ObjectUtil.isNull(original)) {
|
|
|
|
767
|
+ throw new DefaultClientException("合同不存在!");
|
|
|
|
768
|
+ }
|
|
|
|
769
|
+ if (original.getTotalQuantity() == null) {
|
|
|
|
770
|
+ throw new DefaultClientException("合同合计数量为空,无法拆分!");
|
|
|
|
771
|
+ }
|
|
|
|
772
|
+
|
|
|
|
773
|
+ BigDecimal newOriginalTotalQuantity = original.getTotalQuantity().subtract(splitTotalQuantity);
|
|
|
|
774
|
+ if (newOriginalTotalQuantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
775
|
+ throw new DefaultClientException("拆分数量不能大于合同合计数量!");
|
|
|
|
776
|
+ }
|
|
|
|
777
|
+
|
|
|
|
778
|
+ String baseCode = original.getCode();
|
|
|
|
779
|
+ if (StringUtils.isBlank(baseCode)) {
|
|
|
|
780
|
+ throw new DefaultClientException("合同编号为空,无法拆分!");
|
|
|
|
781
|
+ }
|
|
|
|
782
|
+ Wrapper<ContractDistributorStandard> splitWrapper = Wrappers.lambdaQuery(ContractDistributorStandard.class)
|
|
|
|
783
|
+ .likeRight(ContractDistributorStandard::getCode, baseCode + "_");
|
|
|
|
784
|
+ long splitCount = count(splitWrapper);
|
|
|
|
785
|
+ String suffix = String.format("%02d", splitCount + 1);
|
|
|
|
786
|
+ String newCode = baseCode + "_" + suffix;
|
|
|
|
787
|
+
|
|
|
|
788
|
+ ContractDistributorStandard newContract = new ContractDistributorStandard();
|
|
|
|
789
|
+ BeanUtil.copyProperties(original, newContract);
|
|
|
|
790
|
+ newContract.setId(IdUtil.getUUID());
|
|
|
|
791
|
+ newContract.setCode(newCode);
|
|
|
|
792
|
+ newContract.setParentId(null);
|
|
|
|
793
|
+ newContract.setTotalQuantity(splitTotalQuantity);
|
|
|
|
794
|
+ newContract.setCreateTime(LocalDateTime.now());
|
|
|
|
795
|
+ newContract.setUpdateTime(LocalDateTime.now());
|
|
|
|
796
|
+ getBaseMapper().insert(newContract);
|
|
|
|
797
|
+
|
|
|
|
798
|
+ Wrapper<ContractDistributorStandard> updateOriginal = Wrappers.lambdaUpdate(ContractDistributorStandard.class)
|
|
|
|
799
|
+ .set(ContractDistributorStandard::getTotalQuantity, newOriginalTotalQuantity)
|
|
|
|
800
|
+ .eq(ContractDistributorStandard::getId, original.getId());
|
|
|
|
801
|
+ getBaseMapper().update(updateOriginal);
|
|
|
|
802
|
+
|
|
|
|
803
|
+ Wrapper<ContractDistributorLine> lineWrapper = Wrappers.lambdaQuery(ContractDistributorLine.class)
|
|
|
|
804
|
+ .eq(ContractDistributorLine::getContractId, original.getId());
|
|
|
|
805
|
+ List<ContractDistributorLine> oldLineList = contractDistributorLineService.list(lineWrapper);
|
|
|
|
806
|
+ Map<String, ContractDistributorLine> oldLineMap = CollectionUtils.emptyIfNull(oldLineList)
|
|
|
|
807
|
+ .stream()
|
|
|
|
808
|
+ .filter(Objects::nonNull)
|
|
|
|
809
|
+ .filter(l -> StringUtils.isNotBlank(l.getId()))
|
|
|
|
810
|
+ .collect(Collectors.toMap(ContractDistributorLine::getId, Function.identity(), (a, b) -> a));
|
|
|
|
811
|
+
|
|
|
|
812
|
+ for (UpdateContractDistributorLineVo splitLineVo : splitLineVoList) {
|
|
|
|
813
|
+ if (StringUtils.isBlank(splitLineVo.getId())) {
|
|
|
|
814
|
+ throw new DefaultClientException("合同行数据不存在!");
|
|
|
|
815
|
+ }
|
|
|
|
816
|
+ ContractDistributorLine oldLine = oldLineMap.get(splitLineVo.getId());
|
|
|
|
817
|
+ if (oldLine == null) {
|
|
|
|
818
|
+ throw new DefaultClientException("合同行数据不存在!");
|
|
|
|
819
|
+ }
|
|
|
|
820
|
+ if (oldLine.getQuantity() == null) {
|
|
|
|
821
|
+ throw new DefaultClientException("原产品数量为空,无法拆分!");
|
|
|
|
822
|
+ }
|
|
|
|
823
|
+ if (oldLine.getQuantity().compareTo(splitLineVo.getCurrentQuantity()) < 0) {
|
|
|
|
824
|
+ throw new DefaultClientException("拆分数量不能大于原产品数量!");
|
|
|
|
825
|
+ }
|
|
|
|
826
|
+
|
|
|
|
827
|
+ ContractDistributorLine newLine = new ContractDistributorLine();
|
|
|
|
828
|
+ BeanUtil.copyProperties(oldLine, newLine);
|
|
|
|
829
|
+ newLine.setId(IdUtil.getUUID());
|
|
|
|
830
|
+ newLine.setContractId(newContract.getId());
|
|
|
|
831
|
+ newLine.setQuantity(splitLineVo.getCurrentQuantity());
|
|
|
|
832
|
+ newLine.setCreateTime(LocalDateTime.now());
|
|
|
|
833
|
+ newLine.setUpdateTime(LocalDateTime.now());
|
|
|
|
834
|
+ contractDistributorLineService.getBaseMapper().insert(newLine);
|
|
|
|
835
|
+
|
|
|
|
836
|
+ BigDecimal remainingQuantity = oldLine.getQuantity().subtract(splitLineVo.getCurrentQuantity());
|
|
|
|
837
|
+ Wrapper<ContractDistributorLine> updateOldLineWrapper = Wrappers.lambdaUpdate(ContractDistributorLine.class)
|
|
|
|
838
|
+ .set(ContractDistributorLine::getQuantity, remainingQuantity)
|
|
|
|
839
|
+ .set(ContractDistributorLine::getUpdateTime, LocalDateTime.now())
|
|
|
|
840
|
+ .eq(ContractDistributorLine::getId, oldLine.getId());
|
|
|
|
841
|
+ contractDistributorLineService.update(updateOldLineWrapper);
|
|
|
|
842
|
+ contractDistributorLineService.cleanCacheByKey(oldLine.getId());
|
|
|
|
843
|
+ }
|
|
|
|
844
|
+
|
|
|
|
845
|
+ cleanCacheByKey(original.getId());
|
|
|
|
846
|
+ cleanCacheByKey(newContract.getId());
|
|
|
|
847
|
+ }
|
|
|
|
848
|
+
|
|
729
|
/**
|
849
|
/**
|
|
730
|
* 创建订货单
|
850
|
* 创建订货单
|
|
731
|
*
|
851
|
*
|