|
|
|
|
@ -1,14 +1,25 @@
|
|
|
|
|
package org.dromara.oa.crm.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.apache.seata.spring.annotation.GlobalTransactional;
|
|
|
|
|
import org.dromara.common.core.enums.BusinessStatusEnum;
|
|
|
|
|
import org.dromara.common.core.enums.OAStatusEnum;
|
|
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
|
|
import org.dromara.oa.base.domain.BaseMaterialInfo;
|
|
|
|
|
import org.dromara.oa.base.domain.BaseRelationMaterial;
|
|
|
|
|
import org.dromara.oa.crm.domain.*;
|
|
|
|
|
import org.dromara.oa.crm.domain.bo.CrmQuoteInfoBo;
|
|
|
|
|
import org.dromara.oa.crm.domain.bo.CrmQuoteMaterialBo;
|
|
|
|
|
@ -19,6 +30,10 @@ import org.dromara.oa.crm.mapper.CrmQuoteInfoMapper;
|
|
|
|
|
import org.dromara.oa.crm.mapper.CrmQuoteMaterialMapper;
|
|
|
|
|
import org.dromara.oa.crm.service.ICrmCustomerContactService;
|
|
|
|
|
import org.dromara.oa.crm.service.ICrmQuoteInfoService;
|
|
|
|
|
import org.dromara.workflow.api.RemoteWorkflowService;
|
|
|
|
|
import org.dromara.workflow.api.domain.RemoteStartProcess;
|
|
|
|
|
import org.dromara.workflow.api.event.ProcessEvent;
|
|
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
@ -35,12 +50,18 @@ import java.util.stream.Collectors;
|
|
|
|
|
*/
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService {
|
|
|
|
|
|
|
|
|
|
//报价单主子表
|
|
|
|
|
private final CrmQuoteInfoMapper baseMapper;
|
|
|
|
|
private final CrmQuoteMaterialMapper quoteMaterialMapper;
|
|
|
|
|
//客户联系人
|
|
|
|
|
private final ICrmCustomerContactService customerContactService;
|
|
|
|
|
|
|
|
|
|
@DubboReference(timeout = 30000)
|
|
|
|
|
private RemoteWorkflowService remoteWorkflowService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询报价单信息
|
|
|
|
|
*
|
|
|
|
|
@ -52,13 +73,20 @@ public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService {
|
|
|
|
|
CrmQuoteInfoVo vo = baseMapper.selectVoById(quoteId);
|
|
|
|
|
if (vo != null) {
|
|
|
|
|
// 关联查询子表明细
|
|
|
|
|
List<CrmQuoteMaterialVo> items = quoteMaterialMapper.selectVoList(
|
|
|
|
|
JoinWrappers.lambda(CrmQuoteMaterial.class)
|
|
|
|
|
.selectAll(CrmQuoteMaterial.class)
|
|
|
|
|
.eq("t.del_flag", "0")
|
|
|
|
|
.eq(CrmQuoteMaterial::getQuoteId, quoteId)
|
|
|
|
|
.orderByAsc(CrmQuoteMaterial::getItemNo)
|
|
|
|
|
);
|
|
|
|
|
MPJLambdaWrapper<CrmQuoteMaterial> lqw = JoinWrappers.lambda(CrmQuoteMaterial.class)
|
|
|
|
|
.selectAll(CrmQuoteMaterial.class)
|
|
|
|
|
.eq("t.del_flag", "0")
|
|
|
|
|
// 联表基础物料与销售物料,带出物料编码/名称等业务字段
|
|
|
|
|
.select(BaseMaterialInfo::getMaterialCode)
|
|
|
|
|
.select(BaseMaterialInfo::getMaterialName)
|
|
|
|
|
.select(BaseRelationMaterial::getSaleMaterialName)
|
|
|
|
|
.leftJoin(BaseMaterialInfo.class, BaseMaterialInfo::getMaterialId, CrmQuoteMaterial::getMaterialId)
|
|
|
|
|
.leftJoin(BaseRelationMaterial.class, BaseRelationMaterial::getRelationMaterialId, CrmQuoteMaterial::getRelationMaterialId)
|
|
|
|
|
.eq(CrmQuoteMaterial::getQuoteId, quoteId)
|
|
|
|
|
.orderByAsc(CrmQuoteMaterial::getItemNo);
|
|
|
|
|
|
|
|
|
|
// 直接使用 MPJ 的联表查询映射到 VO,避免实体中 exist=false 字段无法通过 BaseMapperPlus 自动填充
|
|
|
|
|
List<CrmQuoteMaterialVo> items = quoteMaterialMapper.selectJoinList(CrmQuoteMaterialVo.class, lqw);
|
|
|
|
|
vo.setItemsVo(items);
|
|
|
|
|
}
|
|
|
|
|
return vo;
|
|
|
|
|
@ -100,6 +128,10 @@ public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService {
|
|
|
|
|
.selectAs("CustomerContact", CrmCustomerContact::getContactName, CrmQuoteInfo::getCustomerContactRealName)
|
|
|
|
|
.leftJoin(CrmCustomerContact.class, "CustomerContact", CrmCustomerContact::getContactId, CrmQuoteInfo::getCustomerContactId)
|
|
|
|
|
|
|
|
|
|
// 客户公司名称(CrmCustomerInfo)
|
|
|
|
|
.select(CrmCustomerInfo::getCustomerName)
|
|
|
|
|
.leftJoin(CrmCustomerInfo.class, CrmCustomerInfo::getCustomerId, CrmCustomerContact::getCustomerId)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// 供货方联系人(CrmCustomerContact,别名:SupplierContact)
|
|
|
|
|
.selectAs("SupplierContact", CrmCustomerContact::getContactName, CrmQuoteInfo::getSupplierContactRealName)
|
|
|
|
|
@ -287,8 +319,10 @@ public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService {
|
|
|
|
|
// 别名连接与派生字段选择
|
|
|
|
|
.selectAs("CustomerContact", CrmCustomerContact::getContactName, CrmQuoteInfo::getCustomerContactRealName)
|
|
|
|
|
.leftJoin(CrmCustomerContact.class, "CustomerContact", CrmCustomerContact::getContactId, CrmQuoteInfo::getCustomerContactId)
|
|
|
|
|
// .leftJoin(CrmCustomerContact.class, "SupplierContact", CrmCustomerContact::getContactId, CrmQuoteInfo::getSupplierContactId)
|
|
|
|
|
// 客户公司名称
|
|
|
|
|
.select(CrmCustomerInfo::getCustomerName)
|
|
|
|
|
.leftJoin(CrmCustomerInfo.class, "Customer", CrmCustomerInfo::getCustomerId, CrmCustomerContact::getCustomerId)
|
|
|
|
|
// .leftJoin(CrmCustomerContact.class, "SupplierContact", CrmCustomerContact::getContactId, CrmQuoteInfo::getSupplierContactId)
|
|
|
|
|
//供应商信息
|
|
|
|
|
.select(CrmSupplierInfo::getSupplierName)
|
|
|
|
|
.leftJoin(CrmSupplierInfo.class, CrmSupplierInfo::getSupplierId, CrmQuoteInfo::getSupplierContactId)
|
|
|
|
|
@ -345,4 +379,76 @@ public class CrmQuoteInfoServiceImpl implements ICrmQuoteInfoService {
|
|
|
|
|
update.setTotalPrice(totalPrice.setScale(2, RoundingMode.HALF_UP));
|
|
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提交报价单并发起审批流程
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@GlobalTransactional(rollbackFor = Exception.class)
|
|
|
|
|
public CrmQuoteInfoVo quoteSubmitAndFlowStart(CrmQuoteInfoBo bo) {
|
|
|
|
|
// 先按当前表单数据进行保存(主子表统一处理)
|
|
|
|
|
if (bo.getQuoteId() == null) {
|
|
|
|
|
this.insertByBo(bo);
|
|
|
|
|
} else {
|
|
|
|
|
this.updateByBo(bo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bo.getQuoteId() == null) {
|
|
|
|
|
throw new ServiceException("报价单ID为空,无法发起流程");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 后端发起流程需忽略节点权限
|
|
|
|
|
bo.getVariables().put("ignore", true);
|
|
|
|
|
RemoteStartProcess startProcess = new RemoteStartProcess();
|
|
|
|
|
startProcess.setBusinessId(bo.getQuoteId().toString());
|
|
|
|
|
startProcess.setFlowCode(bo.getFlowCode());
|
|
|
|
|
startProcess.setVariables(bo.getVariables());
|
|
|
|
|
startProcess.setBizExt(bo.getBizExt());
|
|
|
|
|
bo.getBizExt().setBusinessId(startProcess.getBusinessId());
|
|
|
|
|
|
|
|
|
|
boolean flag = remoteWorkflowService.startCompleteTask(startProcess);
|
|
|
|
|
if (!flag) {
|
|
|
|
|
throw new ServiceException("流程发起异常");
|
|
|
|
|
}
|
|
|
|
|
// 返回最新数据
|
|
|
|
|
return this.queryById(bo.getQuoteId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 报价单流程事件监听
|
|
|
|
|
*/
|
|
|
|
|
@EventListener(condition = "#processEvent.flowCode =='OACQ'")
|
|
|
|
|
public void processHandler(ProcessEvent processEvent) {
|
|
|
|
|
TenantHelper.dynamic(processEvent.getTenantId(), () -> {
|
|
|
|
|
log.info("报价单流程回调: {}", processEvent);
|
|
|
|
|
CrmQuoteInfo quoteInfo = baseMapper.selectById(Convert.toLong(processEvent.getBusinessId()));
|
|
|
|
|
if (quoteInfo == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 同步流程状态
|
|
|
|
|
quoteInfo.setFlowStatus(processEvent.getStatus());
|
|
|
|
|
|
|
|
|
|
Map<String, Object> params = processEvent.getParams();
|
|
|
|
|
if (MapUtil.isNotEmpty(params)) {
|
|
|
|
|
// 预留:当前节点办理人
|
|
|
|
|
String handler = Convert.toStr(params.get("handler"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 按通用规范映射业务状态
|
|
|
|
|
if (Objects.equals(processEvent.getStatus(), BusinessStatusEnum.WAITING.getStatus())) {
|
|
|
|
|
quoteInfo.setQuoteStatus(OAStatusEnum.APPROVING.getStatus());
|
|
|
|
|
} else if (Objects.equals(processEvent.getStatus(), BusinessStatusEnum.FINISH.getStatus())) {
|
|
|
|
|
quoteInfo.setQuoteStatus(OAStatusEnum.COMPLETED.getStatus());
|
|
|
|
|
} else if (Objects.equals(processEvent.getStatus(), BusinessStatusEnum.INVALID.getStatus())
|
|
|
|
|
|| Objects.equals(processEvent.getStatus(), BusinessStatusEnum.TERMINATION.getStatus())) {
|
|
|
|
|
quoteInfo.setQuoteStatus(OAStatusEnum.INVALID.getStatus());
|
|
|
|
|
} else if (Objects.equals(processEvent.getStatus(), BusinessStatusEnum.BACK.getStatus())
|
|
|
|
|
|| Objects.equals(processEvent.getStatus(), BusinessStatusEnum.CANCEL.getStatus())) {
|
|
|
|
|
// 退回或撤销回到草稿
|
|
|
|
|
quoteInfo.setQuoteStatus(OAStatusEnum.DRAFT.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
baseMapper.updateById(quoteInfo);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|