|
|
@@ -0,0 +1,323 @@
|
|
|
+package org.springblade.purchase.sales.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import io.seata.common.util.CollectionUtils;
|
|
|
+import io.seata.spring.annotation.GlobalTransactional;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.check.dto.AuditProecessDTO;
|
|
|
+import org.springblade.check.entity.AuditPathsActs;
|
|
|
+import org.springblade.check.entity.AuditPathsLevels;
|
|
|
+import org.springblade.check.feign.ICheckClient;
|
|
|
+import org.springblade.client.feign.ISerialClient;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.finance.vo.CostMessage;
|
|
|
+import org.springblade.purchase.sales.entity.Biding;
|
|
|
+import org.springblade.purchase.sales.entity.BidingAgent;
|
|
|
+import org.springblade.purchase.sales.entity.BidingItems;
|
|
|
+import org.springblade.purchase.sales.entity.Order;
|
|
|
+import org.springblade.purchase.sales.enums.OrderStatusEnum;
|
|
|
+import org.springblade.purchase.sales.mapper.BidingMapper;
|
|
|
+import org.springblade.purchase.sales.service.IBidingService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 标书表 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2022-09-07
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class BidingServiceImpl extends ServiceImpl<BidingMapper, Biding> implements IBidingService {
|
|
|
+
|
|
|
+ private final BidingItemsServiceImpl bidingItemsService;//明细
|
|
|
+ private final BidingAgentServiceImpl bidingAgentService;//代理信息
|
|
|
+ private ISerialClient serialClient;//生成系统编号
|
|
|
+ private final ICheckClient iCheckClient;//审批
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得标书详情
|
|
|
+ * @param biding
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Biding getBidingMassage(Biding biding) {
|
|
|
+ //获得主表信息
|
|
|
+ Biding bidingMassage = baseMapper.selectById(biding.getId());
|
|
|
+ if (bidingMassage == null){
|
|
|
+ throw new SecurityException("信息异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据主表id获得明细信息
|
|
|
+ List<BidingItems> bidingItemsList = bidingItemsService.getBidingItems(bidingMassage, 0);
|
|
|
+ bidingMassage.setItemsList(bidingItemsList);
|
|
|
+
|
|
|
+ //获得代理明细
|
|
|
+ List<BidingAgent> agentList = bidingAgentService.getBidingAgent(bidingMassage);
|
|
|
+ bidingMassage.setAgentList(agentList);
|
|
|
+
|
|
|
+ //获得标书对比明细
|
|
|
+ List<BidingItems> contrastList = bidingItemsService.getBidingItems(bidingMassage, 1);
|
|
|
+ bidingMassage.setContrastList(contrastList);
|
|
|
+
|
|
|
+ return bidingMassage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * app列表分页数据
|
|
|
+ * @param biding
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<Biding> appPage(IPage<Biding> page, Biding biding){
|
|
|
+ List<Biding> list = baseMapper.salaryBiding(biding, page);
|
|
|
+ return page.setRecords(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增或修改
|
|
|
+ *
|
|
|
+ * @param biding
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R saveBidingMessage(Biding biding) {
|
|
|
+ //校验合同号是否重复
|
|
|
+ if (biding.getId() == null && StringUtil.isNotBlank(biding.getContractNo())){//新增
|
|
|
+ LambdaQueryWrapper<Biding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper
|
|
|
+ .eq(Biding::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Biding::getIsDeleted, 0)
|
|
|
+ .eq(Biding::getContractNo, biding.getContractNo());
|
|
|
+ Integer count = baseMapper.selectCount(lambdaQueryWrapper);
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ throw new SecurityException("合同号:" + biding.getContractNo() + "已存在,禁止重复添加");
|
|
|
+ }
|
|
|
+ }else {//编辑
|
|
|
+ LambdaQueryWrapper<Biding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper
|
|
|
+ .ne(Biding::getId, biding.getId())
|
|
|
+ .eq(Biding::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Biding::getIsDeleted, 0)
|
|
|
+ .eq(Biding::getContractNo, biding.getContractNo());
|
|
|
+ Integer count = baseMapper.selectCount(lambdaQueryWrapper);
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ throw new SecurityException("合同号:" + biding.getContractNo() + "已存在,禁止重复添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存箱型箱量
|
|
|
+ StringBuilder boxTypeQuantity = new StringBuilder();
|
|
|
+ if (CollectionUtils.isNotEmpty(biding.getItemsList())){
|
|
|
+ biding.getItemsList().forEach(e -> {
|
|
|
+ if (StringUtil.isNotBlank(e.getBoxType())){
|
|
|
+ boxTypeQuantity.append(e.getBoxType()).append("*").append(e.getBoxAmount()).append(",");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ biding.setBoxTypeQuantity(boxTypeQuantity.toString().substring(0, boxTypeQuantity.toString().length() - 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (biding.getId() == null){//id为空代表新单据
|
|
|
+ //生成系统编号
|
|
|
+ R billNo = serialClient.getBillNo("BS", "BS", "BS");
|
|
|
+ if (billNo.getCode() != 200) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成系统编号失败");
|
|
|
+ }
|
|
|
+ biding.setSysNo((String) billNo.getData());
|
|
|
+ biding.setTenantId(SecureUtil.getTenantId());
|
|
|
+ biding.setCreateUser(AuthUtil.getUserId());
|
|
|
+ biding.setCreateTime(new Date());
|
|
|
+ baseMapper.insert(biding);
|
|
|
+ }else {//id不为空修改单据
|
|
|
+ biding.setTenantId(SecureUtil.getTenantId());
|
|
|
+ biding.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ biding.setUpdateTime(new Date());
|
|
|
+ baseMapper.updateById(biding);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存明细
|
|
|
+ if (CollectionUtils.isNotEmpty(biding.getItemsList())){
|
|
|
+ List<BidingItems> list = bidingItemsService.saveBidingItemsMessage(biding.getItemsList(), biding.getId(), 0);
|
|
|
+ biding.setItemsList(list);
|
|
|
+ }else {
|
|
|
+ throw new SecurityException("明细为空");
|
|
|
+ }
|
|
|
+ //保存代理信息
|
|
|
+ if (CollectionUtils.isNotEmpty(biding.getAgentList())){
|
|
|
+ List<BidingAgent> list = bidingAgentService.saveBidingAgentMassage(biding.getAgentList(), biding.getId());
|
|
|
+ biding.setAgentList(list);
|
|
|
+ }else {
|
|
|
+ throw new SecurityException("代理信息为空");
|
|
|
+ }
|
|
|
+ //保存标书对比
|
|
|
+ if (CollectionUtils.isNotEmpty(biding.getContrastList()))
|
|
|
+ {
|
|
|
+ List<BidingItems> list = bidingItemsService.saveBidingItemsMessage(biding.getContrastList(), biding.getId(), 1);
|
|
|
+ biding.setContrastList(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.data(biding);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布
|
|
|
+ * @param biding
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void release(Biding biding){
|
|
|
+ Biding salesBiding = baseMapper.selectById(biding.getId());
|
|
|
+ if (salesBiding == null){
|
|
|
+ throw new SecurityException("发布失败,未找到单据");
|
|
|
+ }
|
|
|
+ if (salesBiding.getStatus() == 0){
|
|
|
+ throw new SecurityException("订单未请核");
|
|
|
+ }
|
|
|
+ if (salesBiding.getStatus() == 7){
|
|
|
+ throw new SecurityException("订单已作废");
|
|
|
+ }
|
|
|
+
|
|
|
+ salesBiding.setStatus(4);
|
|
|
+ baseMapper.updateById(salesBiding);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 作废
|
|
|
+ * @param biding
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void invalid(Biding biding){
|
|
|
+ Biding salesBiding = baseMapper.selectById(biding.getId());
|
|
|
+ if (salesBiding == null){
|
|
|
+ throw new SecurityException("作废失败,未找到单据");
|
|
|
+ }
|
|
|
+ salesBiding.setStatus(7);
|
|
|
+ baseMapper.updateById(salesBiding);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请核
|
|
|
+ * @param biding
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public void checkBiding(Biding biding){
|
|
|
+ Biding salesBiding = baseMapper.selectById(biding.getId());
|
|
|
+ if (salesBiding.getStatus() == 1){
|
|
|
+ throw new SecurityException("订单已请核,请勿重复请核");
|
|
|
+ }
|
|
|
+ //生成平台审核数据
|
|
|
+ AuditPathsActs pathsActs = iCheckClient.getApprovalActId(15, "status",AuthUtil.getTenantId());
|
|
|
+ if (pathsActs == null || pathsActs.getIsEnable() == 2) {
|
|
|
+ throw new SecurityException("当前租户未查询到审批流配置");
|
|
|
+ } else {
|
|
|
+ //获取审批级次
|
|
|
+ List<AuditPathsLevels> auditPathsLevels = iCheckClient.listApproval(15, "status", AuthUtil.getTenantId());
|
|
|
+ if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(auditPathsLevels)) {
|
|
|
+ throw new SecurityException("开启审批失败:未查询到审批信息");
|
|
|
+ }
|
|
|
+ //修改订单信息
|
|
|
+ AuditProecessDTO auditProecessDTO = new AuditProecessDTO();
|
|
|
+ // 绑定审核类型
|
|
|
+ auditProecessDTO.setCheckType("bsdd");//代理订单
|
|
|
+ // 追加跳转路由url
|
|
|
+ auditProecessDTO.setUrl(biding.getUrl());
|
|
|
+ auditProecessDTO.setPageStatus(biding.getPageStatus());
|
|
|
+ auditProecessDTO.setPageLabel(biding.getPageLabel());
|
|
|
+ //增加审批类型
|
|
|
+ auditProecessDTO.setProcessType("标书审批");
|
|
|
+ auditProecessDTO.setOrderRemark(salesBiding.getRemark());//订单备注
|
|
|
+ auditProecessDTO.setPathsLevelsList(auditPathsLevels);
|
|
|
+ auditProecessDTO.setActId(1);
|
|
|
+ auditProecessDTO.setSrcBillId(salesBiding.getId());//申请表id
|
|
|
+ auditProecessDTO.setBillId(salesBiding.getId());//业务id
|
|
|
+ auditProecessDTO.setBillNo(salesBiding.getSysNo());//业务编号
|
|
|
+ auditProecessDTO.setSendUserId(AuthUtil.getUserId());//请核人id
|
|
|
+ auditProecessDTO.setSendName(AuthUtil.getUserName());//请核人名称
|
|
|
+ auditProecessDTO.setSendTime(new Date());//请核时间
|
|
|
+ auditProecessDTO.setTenantId(AuthUtil.getTenantId());//租户id
|
|
|
+ R financeProcess = iCheckClient.createFinanceProcess(auditProecessDTO);
|
|
|
+ if (!financeProcess.isSuccess()) {
|
|
|
+ throw new SecurityException("操作失败,请联系管理员");
|
|
|
+ }
|
|
|
+ Biding upBiding = new Biding();
|
|
|
+ upBiding.setId(salesBiding.getId());
|
|
|
+ upBiding.setStatus(5);
|
|
|
+ baseMapper.updateById(upBiding);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核通过
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void passCheck(Long id) {
|
|
|
+ LambdaQueryWrapper<Biding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(Biding::getId, id);
|
|
|
+ lambdaQueryWrapper.eq(Biding::getTenantId, AuthUtil.getTenantId());
|
|
|
+ lambdaQueryWrapper.eq(Biding::getIsDeleted, 0);
|
|
|
+ Biding biding = baseMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (biding == null){
|
|
|
+ throw new SecurityException("审批通过失败");
|
|
|
+ }
|
|
|
+ if (biding.getStatus() == 3){
|
|
|
+ throw new SecurityException("订单已审批通过请勿重复审批");
|
|
|
+ }
|
|
|
+ biding.setStatus(3);
|
|
|
+ baseMapper.updateById(biding);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批中
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void underReview(Long id) {
|
|
|
+ LambdaQueryWrapper<Biding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(Biding::getId, id);
|
|
|
+ lambdaQueryWrapper.eq(Biding::getTenantId, AuthUtil.getTenantId());
|
|
|
+ lambdaQueryWrapper.eq(Biding::getIsDeleted, 0);
|
|
|
+ Biding biding = baseMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (biding == null) {
|
|
|
+ throw new SecurityException("审批失败");
|
|
|
+ }
|
|
|
+ biding.setStatus(2);
|
|
|
+ baseMapper.updateById(biding);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核不通过
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void passCancel(Long id) {
|
|
|
+ LambdaQueryWrapper<Biding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(Biding::getId, id);
|
|
|
+ lambdaQueryWrapper.eq(Biding::getTenantId, AuthUtil.getTenantId());
|
|
|
+ lambdaQueryWrapper.eq(Biding::getIsDeleted, 0);
|
|
|
+ Biding biding = baseMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (biding == null){
|
|
|
+ throw new SecurityException("审批驳回失败,未找到单据");
|
|
|
+ }
|
|
|
+ if (biding.getStatus() == 0){
|
|
|
+ throw new SecurityException("订单已驳回或未提交审批,请勿重复操作");
|
|
|
+ }
|
|
|
+ biding.setStatus(0);
|
|
|
+ baseMapper.updateById(biding);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|