初始代码
This commit is contained in:
31
yunzhupaas-crm/yunzhupaas-crm-biz/pom.xml
Normal file
31
yunzhupaas-crm/yunzhupaas-crm-biz/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-crm</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-crm-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-crm-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-generater-base</artifactId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
|
||||
import com.yunzhupaas.base.entity.CrmCustomerEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
|
||||
/**
|
||||
* mdm_company
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
public interface CrmCustomerMapper extends SuperMapper<CrmCustomerEntity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
|
||||
import com.yunzhupaas.base.entity.CrmLeadEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
|
||||
/**
|
||||
* crm_lead
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
public interface CrmLeadMapper extends SuperMapper<CrmLeadEntity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
|
||||
import com.yunzhupaas.base.entity.CrmOpportunityEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
|
||||
/**
|
||||
* crm_opportunity
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
public interface CrmOpportunityMapper extends SuperMapper<CrmOpportunityEntity> {
|
||||
|
||||
String selectCustomerBycustomerId(String customerId);
|
||||
|
||||
int updateByCustomerByCustomerId(CrmOpportunityEntity entity);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
|
||||
/**
|
||||
* mdm_company
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
public interface CrmCustomerService extends SuperService<CrmCustomerEntity> {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
import com.yunzhupaas.base.model.crmlead.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* crm_lead
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
public interface CrmLeadService extends SuperService<CrmLeadEntity> {
|
||||
List<CrmLeadEntity> getList(CrmLeadPagination crmLeadPagination);
|
||||
|
||||
List<CrmLeadEntity> getTypeList(CrmLeadPagination crmLeadPagination,String dataType);
|
||||
|
||||
CrmLeadEntity getInfo(String leadid);
|
||||
|
||||
void delete(CrmLeadEntity entity);
|
||||
|
||||
void create(CrmLeadEntity entity);
|
||||
|
||||
boolean update(String leadid, CrmLeadEntity entity);
|
||||
|
||||
String checkForm(CrmLeadForm form,int i);
|
||||
|
||||
void saveOrUpdate(CrmLeadForm crmLeadForm,String id, boolean isSave) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
import com.yunzhupaas.base.model.crmopportunity.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* crm_opportunity
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
public interface CrmOpportunityService extends SuperService<CrmOpportunityEntity> {
|
||||
List<CrmOpportunityEntity> getList(CrmOpportunityPagination crmOpportunityPagination);
|
||||
|
||||
List<CrmOpportunityEntity> getTypeList(CrmOpportunityPagination crmOpportunityPagination,String dataType);
|
||||
|
||||
CrmOpportunityEntity getInfo(String opportunityid);
|
||||
|
||||
void delete(CrmOpportunityEntity entity);
|
||||
|
||||
void create(CrmOpportunityEntity entity);
|
||||
|
||||
boolean update(String opportunityid, CrmOpportunityEntity entity);
|
||||
|
||||
String checkForm(CrmOpportunityForm form,int i);
|
||||
|
||||
void saveOrUpdate(CrmOpportunityForm crmOpportunityForm,String id, boolean isSave) throws Exception;
|
||||
|
||||
String selectCustomerBycustomerId(String customerId);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.mapper.CrmCustomerMapper;
|
||||
import com.yunzhupaas.base.service.*;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.yunzhupaas.util.GeneraterSwapUtil;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import lombok.Cleanup;
|
||||
import com.yunzhupaas.database.plugins.DynamicSourceGeneratorInterface;
|
||||
import com.yunzhupaas.database.util.DynamicDataSourceUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import com.yunzhupaas.i18n.util.I18nUtil;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
/**
|
||||
*
|
||||
* mdm_company
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
@Service
|
||||
public class CrmCustomerServiceImpl extends SuperServiceImpl<CrmCustomerMapper, CrmCustomerEntity> implements CrmCustomerService{
|
||||
@Autowired
|
||||
private GeneraterSwapUtil generaterSwapUtil;
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.mapper.CrmLeadMapper;
|
||||
import com.yunzhupaas.base.service.*;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yunzhupaas.base.model.crmlead.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.yunzhupaas.util.GeneraterSwapUtil;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import lombok.Cleanup;
|
||||
import com.yunzhupaas.database.plugins.DynamicSourceGeneratorInterface;
|
||||
import com.yunzhupaas.database.util.DynamicDataSourceUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import com.yunzhupaas.i18n.util.I18nUtil;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import java.math.BigDecimal;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import java.lang.reflect.Field;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.yunzhupaas.model.QueryAllModel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.yunzhupaas.util.*;
|
||||
import java.util.*;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
/**
|
||||
*
|
||||
* crm_lead
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
@Service
|
||||
public class CrmLeadServiceImpl extends SuperServiceImpl<CrmLeadMapper, CrmLeadEntity> implements CrmLeadService{
|
||||
@Autowired
|
||||
private GeneraterSwapUtil generaterSwapUtil;
|
||||
@Autowired
|
||||
private UserProvider userProvider;
|
||||
@Override
|
||||
public List<CrmLeadEntity> getList(CrmLeadPagination crmLeadPagination){
|
||||
return getTypeList(crmLeadPagination,crmLeadPagination.getDataType());
|
||||
}
|
||||
/** 列表查询 */
|
||||
@Override
|
||||
public List<CrmLeadEntity> getTypeList(CrmLeadPagination crmLeadPagination,String dataType){
|
||||
String userId=userProvider.get().getUserId();
|
||||
Map<String,Class> tableClassMap=new HashMap<>();
|
||||
tableClassMap.put("crm_lead",CrmLeadEntity.class);
|
||||
|
||||
MPJLambdaWrapper<CrmLeadEntity> wrapper = JoinWrappers
|
||||
.lambda("crm_lead",CrmLeadEntity.class)
|
||||
.selectAll(CrmLeadEntity.class);
|
||||
MPJLambdaWrapper<CrmLeadEntity> wrapper2 = JoinWrappers
|
||||
.lambda("crm_lead",CrmLeadEntity.class)
|
||||
.distinct().select(CrmLeadEntity::getLeadId);
|
||||
|
||||
QueryAllModel queryAllModel = new QueryAllModel();
|
||||
queryAllModel.setWrapper(wrapper);
|
||||
queryAllModel.setClassMap(tableClassMap);
|
||||
queryAllModel.setDbLink(CrmLeadConstant.DBLINKID);
|
||||
//数据过滤
|
||||
boolean isPc = ServletUtil.getHeader("yunzhupaas-origin").equals("pc");
|
||||
String columnData = !isPc ? CrmLeadConstant.getAppColumnData() : CrmLeadConstant.getColumnData();
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class);
|
||||
String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList());
|
||||
queryAllModel.setRuleJson(ruleJson);
|
||||
//高级查询
|
||||
boolean hasSuperQuery = true;
|
||||
if (hasSuperQuery) {
|
||||
queryAllModel.setSuperJson(crmLeadPagination.getSuperQueryJson());
|
||||
}
|
||||
//数据权限
|
||||
boolean pcPermission = true;
|
||||
boolean appPermission = false;
|
||||
if (isPc && pcPermission) {
|
||||
queryAllModel.setModuleId(crmLeadPagination.getMenuId());
|
||||
}
|
||||
if (!isPc && appPermission) {
|
||||
queryAllModel.setModuleId(crmLeadPagination.getMenuId());
|
||||
}
|
||||
//拼接复杂条件
|
||||
wrapper = generaterSwapUtil.getConditionAllTable(queryAllModel);
|
||||
if(wrapper == null) return new ArrayList<>();
|
||||
queryAllModel.setWrapper(wrapper2);
|
||||
wrapper2 = generaterSwapUtil.getConditionAllTable(queryAllModel);
|
||||
//其他条件拼接
|
||||
otherConditions(crmLeadPagination, wrapper, isPc);
|
||||
otherConditions(crmLeadPagination, wrapper2, isPc);
|
||||
|
||||
if("0".equals(dataType)){
|
||||
com.github.pagehelper.Page<Object> objects = PageHelper.startPage((int) crmLeadPagination.getCurrentPage(), (int) crmLeadPagination.getPageSize(), true);
|
||||
List<CrmLeadEntity> userIPage = this.selectJoinList(CrmLeadEntity.class, wrapper2);
|
||||
List<Object> collect = userIPage.stream().map(t -> t.getLeadId()).collect(Collectors.toList());
|
||||
if(CollectionUtils.isNotEmpty(collect)){
|
||||
wrapper.in(CrmLeadEntity::getLeadId,collect);
|
||||
}
|
||||
List<CrmLeadEntity> result = this.selectJoinList(CrmLeadEntity.class, wrapper);
|
||||
return crmLeadPagination.setData(result,objects.getTotal());
|
||||
}else{
|
||||
List<CrmLeadEntity> list = this.selectJoinList(CrmLeadEntity.class, wrapper);
|
||||
if("2".equals(dataType)){
|
||||
List<Object> selectIds = Arrays.asList(crmLeadPagination.getSelectIds());
|
||||
return list.stream().filter(t -> selectIds.contains(t.getLeadId())).collect(Collectors.toList());
|
||||
}else{
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他条件拼接
|
||||
*/
|
||||
private void otherConditions(CrmLeadPagination crmLeadPagination, MPJLambdaWrapper<CrmLeadEntity> wrapper, boolean isPc) {
|
||||
String databaseName;
|
||||
try {
|
||||
@Cleanup Connection cnn = DynamicDataSourceUtil.getCurrentConnection();
|
||||
databaseName = cnn.getMetaData().getDatabaseProductName().trim();
|
||||
} catch (SQLException e) {
|
||||
throw new DataException(e.getMessage());
|
||||
}
|
||||
//假删除标志
|
||||
wrapper.isNull(CrmLeadEntity::getDeleteMark);
|
||||
|
||||
wrapper.isNull(CrmLeadEntity::getFlowId);
|
||||
//关键词
|
||||
if(ObjectUtil.isNotEmpty(crmLeadPagination.getYunzhupaasKeyword())){
|
||||
if(isPc){
|
||||
wrapper.and(t -> {
|
||||
t.like(CrmLeadEntity::getMobile,crmLeadPagination.getYunzhupaasKeyword()).or();
|
||||
});
|
||||
}
|
||||
}
|
||||
//普通查询
|
||||
if(isPc){
|
||||
if(ObjectUtil.isNotEmpty(crmLeadPagination.getMobile())){
|
||||
String value = crmLeadPagination.getMobile() instanceof List ?
|
||||
JsonUtil.getObjectToString(crmLeadPagination.getMobile()) :
|
||||
String.valueOf(crmLeadPagination.getMobile());
|
||||
wrapper.like(CrmLeadEntity::getMobile,value);
|
||||
}
|
||||
|
||||
if(ObjectUtil.isNotEmpty(crmLeadPagination.getCustomerSource())){
|
||||
List<String> idList = new ArrayList<>();
|
||||
try {
|
||||
String[][] customerSource = JsonUtil.getJsonToBean(crmLeadPagination.getCustomerSource(),String[][].class);
|
||||
for(int i=0;i<customerSource.length;i++){
|
||||
if(customerSource[i].length>0){
|
||||
idList.add(JsonUtil.getObjectToString(Arrays.asList(customerSource[i])));
|
||||
}
|
||||
}
|
||||
}catch (Exception e1){
|
||||
try {
|
||||
List<String> customerSource = JsonUtil.getJsonToList(crmLeadPagination.getCustomerSource(),String.class);
|
||||
if(customerSource.size()>0){
|
||||
idList.addAll(customerSource);
|
||||
}
|
||||
}catch (Exception e2){
|
||||
idList.add(String.valueOf(crmLeadPagination.getCustomerSource()));
|
||||
}
|
||||
}
|
||||
wrapper.and(t->{
|
||||
idList.forEach(tt->{
|
||||
if(StringUtil.isNotEmpty(tt) && "Microsoft SQL Server".equalsIgnoreCase(databaseName)){
|
||||
tt = tt.replaceFirst("\\[","[[]");
|
||||
}
|
||||
t.like(CrmLeadEntity::getCustomerSource, tt).or();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
//排序
|
||||
if(StringUtil.isEmpty(crmLeadPagination.getSidx())){
|
||||
wrapper.orderByDesc(CrmLeadEntity::getLeadId);
|
||||
}else{
|
||||
try {
|
||||
String[] split = crmLeadPagination.getSidx().split(",");
|
||||
for(String sidx:split){
|
||||
CrmLeadEntity crmLeadEntity = new CrmLeadEntity();
|
||||
String oderTableField = crmLeadEntity.getClass().getAnnotation(TableName.class).value();
|
||||
boolean descFlag = sidx.startsWith("-");
|
||||
String sidxField = descFlag ? sidx.substring(1) : sidx;
|
||||
try{
|
||||
Field declaredField = crmLeadEntity.getClass().getDeclaredField(sidxField);
|
||||
declaredField.setAccessible(true);
|
||||
sidxField = declaredField.getAnnotation(TableField.class).value();
|
||||
}catch (Exception e){
|
||||
}
|
||||
String finalOderTableField = oderTableField;
|
||||
String finalSidxField = sidxField;
|
||||
Object select = wrapper.getSelectColumns().stream().filter(t -> Objects.equals(finalOderTableField, t.getTableAlias())
|
||||
&& Objects.equals(finalSidxField, t.getColumn())).findFirst().orElse(null);
|
||||
oderTableField = oderTableField + "." + sidxField;
|
||||
if (select == null) {
|
||||
wrapper.select(oderTableField);
|
||||
}
|
||||
if (descFlag) {
|
||||
wrapper.orderByDesc(oderTableField);
|
||||
} else {
|
||||
wrapper.orderByAsc(oderTableField);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public CrmLeadEntity getInfo(String leadid){
|
||||
MPJLambdaWrapper<CrmLeadEntity> wrapper = JoinWrappers
|
||||
.lambda("crm_lead",CrmLeadEntity.class)
|
||||
.selectAll(CrmLeadEntity.class);
|
||||
wrapper.and(
|
||||
t->t.eq(CrmLeadEntity::getLeadId, leadid )
|
||||
.or().eq(CrmLeadEntity::getFlowTaskId, leadid)
|
||||
);
|
||||
return this.selectJoinOne(CrmLeadEntity.class,wrapper);
|
||||
}
|
||||
@Override
|
||||
public void create(CrmLeadEntity entity){
|
||||
this.save(entity);
|
||||
}
|
||||
@Override
|
||||
public boolean update(String leadid, CrmLeadEntity entity){
|
||||
return this.updateById(entity);
|
||||
}
|
||||
@Override
|
||||
public void delete(CrmLeadEntity entity){
|
||||
if(entity!=null){
|
||||
this.removeById(entity.getLeadId());
|
||||
}
|
||||
}
|
||||
/** 验证表单唯一字段,正则,非空 i-0新增-1修改*/
|
||||
@Override
|
||||
public String checkForm(CrmLeadForm form,int i) {
|
||||
boolean isUp =StringUtil.isNotEmpty(form.getLeadId()) && !form.getLeadId().equals("0");
|
||||
Object id= null;
|
||||
String countRecover = "";
|
||||
String fieldTipName = "";
|
||||
String canNotNull = I18nUtil.getMessageStr("sys.validate.textRequiredSuffix", "不能为空");
|
||||
String canNotRepeated = I18nUtil.getMessageStr("EXIST103", "不能重复");
|
||||
if (isUp){
|
||||
id = form.getLeadId();
|
||||
}
|
||||
//主表字段验证
|
||||
fieldTipName = "线索名称";
|
||||
if(StringUtil.isEmpty(form.getLeadName())){
|
||||
return fieldTipName + canNotNull;
|
||||
}
|
||||
fieldTipName = "手机号";
|
||||
if(StringUtil.isEmpty(form.getMobile())){
|
||||
return fieldTipName + canNotNull;
|
||||
}
|
||||
if(StringUtil.isNotEmpty(form.getMobile())){
|
||||
form.setMobile(form.getMobile().trim());
|
||||
QueryWrapper<CrmLeadEntity> mobileWrapper=new QueryWrapper<>();
|
||||
mobileWrapper.lambda().eq(CrmLeadEntity::getMobile,form.getMobile());
|
||||
mobileWrapper.lambda().isNull(CrmLeadEntity::getFlowId);
|
||||
//假删除标志
|
||||
mobileWrapper.lambda().isNull(CrmLeadEntity::getDeleteMark);
|
||||
if (isUp){
|
||||
mobileWrapper.lambda().ne(CrmLeadEntity::getLeadId, id);
|
||||
}
|
||||
if((int) this.count(mobileWrapper)>0){
|
||||
countRecover = fieldTipName + canNotRepeated;
|
||||
}
|
||||
}
|
||||
if(StringUtil.isNotEmpty(form.getMobile())){
|
||||
if(!Pattern.compile("^1[3456789]\\d{9}$").matcher(String.valueOf(form.getMobile())).matches()){
|
||||
return I18nUtil.getMessageStr("sys.validate.mobilePhone", "请输入正确的手机号码");
|
||||
}
|
||||
}
|
||||
fieldTipName = "邮箱";
|
||||
if(StringUtil.isNotEmpty(form.getEmail())){
|
||||
if(!Pattern.compile("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$").matcher(String.valueOf(form.getEmail())).matches()){
|
||||
return I18nUtil.getMessageStr("sys.validate.email", "请输入正确的邮箱");
|
||||
}
|
||||
}
|
||||
fieldTipName = "状态";
|
||||
fieldTipName = "销售人员";
|
||||
fieldTipName = "来源";
|
||||
fieldTipName = "备注";
|
||||
return countRecover;
|
||||
}
|
||||
/**
|
||||
* 新增修改数据(事务回滚)
|
||||
* @param id
|
||||
* @param crmLeadForm
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveOrUpdate(CrmLeadForm crmLeadForm,String id, boolean isSave) throws Exception{
|
||||
UserInfo userInfo=userProvider.get();
|
||||
UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId());
|
||||
crmLeadForm = JsonUtil.getJsonToBean(
|
||||
generaterSwapUtil.swapDatetime(CrmLeadConstant.getFormData(),crmLeadForm,CrmLeadConstant.TABLERENAMES),CrmLeadForm.class);
|
||||
CrmLeadEntity entity = JsonUtil.getJsonToBean(crmLeadForm, CrmLeadEntity.class);
|
||||
String mainUuid = StringUtil.isEmpty(id) ? RandomUtil.uuId() : id;
|
||||
if(isSave){
|
||||
entity.setFlowTaskId(mainUuid);
|
||||
entity.setLeadId(mainUuid);
|
||||
entity.setVersion(0);
|
||||
} else {
|
||||
}
|
||||
boolean b = this.saveOrUpdate(entity);
|
||||
if(!b){
|
||||
throw new DataException("当前表单原数据已被调整,请重新进入该页面编辑并提交数据");
|
||||
}
|
||||
CrmLeadEntity info = this.getInfo(mainUuid);
|
||||
if (info == null) throw new RuntimeException(MsgCode.FA001.get());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.mapper.CrmOpportunityMapper;
|
||||
import com.yunzhupaas.base.service.*;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yunzhupaas.base.model.crmopportunity.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.yunzhupaas.util.GeneraterSwapUtil;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import lombok.Cleanup;
|
||||
import com.yunzhupaas.database.plugins.DynamicSourceGeneratorInterface;
|
||||
import com.yunzhupaas.database.util.DynamicDataSourceUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import com.yunzhupaas.i18n.util.I18nUtil;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import java.math.BigDecimal;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import java.lang.reflect.Field;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.toolkit.JoinWrappers;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.yunzhupaas.model.QueryAllModel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.yunzhupaas.util.*;
|
||||
import java.util.*;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
/**
|
||||
*
|
||||
* crm_opportunity
|
||||
* 版本: V5.2.7
|
||||
* 版权: Copyright @ 2025 深圳市乐程软件有限公司版权所有
|
||||
* 作者: 深圳市乐程软件有限公司
|
||||
* 日期: 2026-03-27
|
||||
*/
|
||||
@Service
|
||||
public class CrmOpportunityServiceImpl extends SuperServiceImpl<CrmOpportunityMapper, CrmOpportunityEntity> implements CrmOpportunityService{
|
||||
@Autowired
|
||||
private GeneraterSwapUtil generaterSwapUtil;
|
||||
@Autowired
|
||||
private UserProvider userProvider;
|
||||
@Override
|
||||
public List<CrmOpportunityEntity> getList(CrmOpportunityPagination crmOpportunityPagination){
|
||||
return getTypeList(crmOpportunityPagination,crmOpportunityPagination.getDataType());
|
||||
}
|
||||
/** 列表查询 */
|
||||
@Override
|
||||
public List<CrmOpportunityEntity> getTypeList(CrmOpportunityPagination crmOpportunityPagination,String dataType){
|
||||
String userId=userProvider.get().getUserId();
|
||||
Map<String,Class> tableClassMap=new HashMap<>();
|
||||
tableClassMap.put("crm_opportunity",CrmOpportunityEntity.class);
|
||||
tableClassMap.put("crm_customer",CrmCustomerEntity.class);
|
||||
|
||||
MPJLambdaWrapper<CrmOpportunityEntity> wrapper = JoinWrappers
|
||||
.lambda("crm_opportunity",CrmOpportunityEntity.class)
|
||||
.selectAssociation(CrmCustomerEntity.class,CrmOpportunityEntity::getCrmCustomer)
|
||||
.leftJoin(CrmCustomerEntity.class,"crm_customer",CrmCustomerEntity::getCustomerId,CrmOpportunityEntity::getCustomerId)
|
||||
.selectAll(CrmOpportunityEntity.class);
|
||||
MPJLambdaWrapper<CrmOpportunityEntity> wrapper2 = JoinWrappers
|
||||
.lambda("crm_opportunity",CrmOpportunityEntity.class)
|
||||
.leftJoin(CrmCustomerEntity.class,"crm_customer",CrmCustomerEntity::getCustomerId,CrmOpportunityEntity::getCustomerId)
|
||||
.distinct().select(CrmOpportunityEntity::getOpportunityId);
|
||||
|
||||
QueryAllModel queryAllModel = new QueryAllModel();
|
||||
queryAllModel.setWrapper(wrapper);
|
||||
queryAllModel.setClassMap(tableClassMap);
|
||||
queryAllModel.setDbLink(CrmOpportunityConstant.DBLINKID);
|
||||
//数据过滤
|
||||
boolean isPc = ServletUtil.getHeader("yunzhupaas-origin").equals("pc");
|
||||
String columnData = !isPc ? CrmOpportunityConstant.getAppColumnData() : CrmOpportunityConstant.getColumnData();
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class);
|
||||
String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList());
|
||||
queryAllModel.setRuleJson(ruleJson);
|
||||
//高级查询
|
||||
boolean hasSuperQuery = true;
|
||||
if (hasSuperQuery) {
|
||||
queryAllModel.setSuperJson(crmOpportunityPagination.getSuperQueryJson());
|
||||
}
|
||||
//数据权限
|
||||
boolean pcPermission = false;
|
||||
boolean appPermission = false;
|
||||
if (isPc && pcPermission) {
|
||||
queryAllModel.setModuleId(crmOpportunityPagination.getMenuId());
|
||||
}
|
||||
if (!isPc && appPermission) {
|
||||
queryAllModel.setModuleId(crmOpportunityPagination.getMenuId());
|
||||
}
|
||||
//拼接复杂条件
|
||||
wrapper = generaterSwapUtil.getConditionAllTable(queryAllModel);
|
||||
if(wrapper == null) return new ArrayList<>();
|
||||
queryAllModel.setWrapper(wrapper2);
|
||||
wrapper2 = generaterSwapUtil.getConditionAllTable(queryAllModel);
|
||||
//其他条件拼接
|
||||
otherConditions(crmOpportunityPagination, wrapper, isPc);
|
||||
otherConditions(crmOpportunityPagination, wrapper2, isPc);
|
||||
|
||||
if("0".equals(dataType)){
|
||||
com.github.pagehelper.Page<Object> objects = PageHelper.startPage((int) crmOpportunityPagination.getCurrentPage(), (int) crmOpportunityPagination.getPageSize(), true);
|
||||
List<CrmOpportunityEntity> userIPage = this.selectJoinList(CrmOpportunityEntity.class, wrapper2);
|
||||
List<Object> collect = userIPage.stream().map(t -> t.getOpportunityId()).collect(Collectors.toList());
|
||||
if(CollectionUtils.isNotEmpty(collect)){
|
||||
wrapper.in(CrmOpportunityEntity::getOpportunityId,collect);
|
||||
}
|
||||
List<CrmOpportunityEntity> result = this.selectJoinList(CrmOpportunityEntity.class, wrapper);
|
||||
return crmOpportunityPagination.setData(result,objects.getTotal());
|
||||
}else{
|
||||
List<CrmOpportunityEntity> list = this.selectJoinList(CrmOpportunityEntity.class, wrapper);
|
||||
if("2".equals(dataType)){
|
||||
List<Object> selectIds = Arrays.asList(crmOpportunityPagination.getSelectIds());
|
||||
return list.stream().filter(t -> selectIds.contains(t.getOpportunityId())).collect(Collectors.toList());
|
||||
}else{
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他条件拼接
|
||||
*/
|
||||
private void otherConditions(CrmOpportunityPagination crmOpportunityPagination, MPJLambdaWrapper<CrmOpportunityEntity> wrapper, boolean isPc) {
|
||||
String databaseName;
|
||||
try {
|
||||
@Cleanup Connection cnn = DynamicDataSourceUtil.getCurrentConnection();
|
||||
databaseName = cnn.getMetaData().getDatabaseProductName().trim();
|
||||
} catch (SQLException e) {
|
||||
throw new DataException(e.getMessage());
|
||||
}
|
||||
//假删除标志
|
||||
wrapper.isNull(CrmOpportunityEntity::getDeleteMark);
|
||||
|
||||
wrapper.isNull(CrmOpportunityEntity::getFlowId);
|
||||
//关键词
|
||||
if(ObjectUtil.isNotEmpty(crmOpportunityPagination.getYunzhupaasKeyword())){
|
||||
if(isPc){
|
||||
wrapper.and(t -> {
|
||||
t.like(CrmOpportunityEntity::getOpportunityName,crmOpportunityPagination.getYunzhupaasKeyword()).or();
|
||||
});
|
||||
}
|
||||
}
|
||||
//普通查询
|
||||
if(isPc){
|
||||
if(ObjectUtil.isNotEmpty(crmOpportunityPagination.getOpportunityName())){
|
||||
String value = crmOpportunityPagination.getOpportunityName() instanceof List ?
|
||||
JsonUtil.getObjectToString(crmOpportunityPagination.getOpportunityName()) :
|
||||
String.valueOf(crmOpportunityPagination.getOpportunityName());
|
||||
wrapper.like(CrmOpportunityEntity::getOpportunityName,value);
|
||||
}
|
||||
|
||||
if(ObjectUtil.isNotEmpty(crmOpportunityPagination.getOpportunityStage())){
|
||||
List<String> idList = new ArrayList<>();
|
||||
try {
|
||||
String[][] opportunityStage = JsonUtil.getJsonToBean(crmOpportunityPagination.getOpportunityStage(),String[][].class);
|
||||
for(int i=0;i<opportunityStage.length;i++){
|
||||
if(opportunityStage[i].length>0){
|
||||
idList.add(JsonUtil.getObjectToString(Arrays.asList(opportunityStage[i])));
|
||||
}
|
||||
}
|
||||
}catch (Exception e1){
|
||||
try {
|
||||
List<String> opportunityStage = JsonUtil.getJsonToList(crmOpportunityPagination.getOpportunityStage(),String.class);
|
||||
if(opportunityStage.size()>0){
|
||||
idList.addAll(opportunityStage);
|
||||
}
|
||||
}catch (Exception e2){
|
||||
idList.add(String.valueOf(crmOpportunityPagination.getOpportunityStage()));
|
||||
}
|
||||
}
|
||||
wrapper.and(t->{
|
||||
idList.forEach(tt->{
|
||||
if(StringUtil.isNotEmpty(tt) && "Microsoft SQL Server".equalsIgnoreCase(databaseName)){
|
||||
tt = tt.replaceFirst("\\[","[[]");
|
||||
}
|
||||
t.like(CrmOpportunityEntity::getOpportunityStage, tt).or();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if(ObjectUtil.isNotEmpty(crmOpportunityPagination.getCloseDate())){
|
||||
List CloseDateList = JsonUtil.getJsonToList(crmOpportunityPagination.getCloseDate(),String.class);
|
||||
for(int i=0;i<CloseDateList.size();i++){
|
||||
String id = String.valueOf(CloseDateList.get(i));
|
||||
boolean idAll = StringUtil.isNotEmpty(id) && !id.equals("null");
|
||||
if(idAll){
|
||||
Object b= new Date(Long.valueOf(id));
|
||||
if(i==0){
|
||||
wrapper.ge(CrmOpportunityEntity::getCloseDate,b);
|
||||
}else{
|
||||
wrapper.le(CrmOpportunityEntity::getCloseDate,b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//排序
|
||||
if(StringUtil.isEmpty(crmOpportunityPagination.getSidx())){
|
||||
wrapper.orderByDesc(CrmOpportunityEntity::getOpportunityId);
|
||||
}else{
|
||||
try {
|
||||
String[] split = crmOpportunityPagination.getSidx().split(",");
|
||||
for(String sidx:split){
|
||||
CrmOpportunityEntity crmOpportunityEntity = new CrmOpportunityEntity();
|
||||
String oderTableField = crmOpportunityEntity.getClass().getAnnotation(TableName.class).value();
|
||||
boolean descFlag = sidx.startsWith("-");
|
||||
String sidxField = descFlag ? sidx.substring(1) : sidx;
|
||||
try{
|
||||
Field declaredField = crmOpportunityEntity.getClass().getDeclaredField(sidxField);
|
||||
declaredField.setAccessible(true);
|
||||
sidxField = declaredField.getAnnotation(TableField.class).value();
|
||||
}catch (Exception e){
|
||||
}
|
||||
String finalOderTableField = oderTableField;
|
||||
String finalSidxField = sidxField;
|
||||
Object select = wrapper.getSelectColumns().stream().filter(t -> Objects.equals(finalOderTableField, t.getTableAlias())
|
||||
&& Objects.equals(finalSidxField, t.getColumn())).findFirst().orElse(null);
|
||||
oderTableField = oderTableField + "." + sidxField;
|
||||
if (select == null) {
|
||||
wrapper.select(oderTableField);
|
||||
}
|
||||
if (descFlag) {
|
||||
wrapper.orderByDesc(oderTableField);
|
||||
} else {
|
||||
wrapper.orderByAsc(oderTableField);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public CrmOpportunityEntity getInfo(String opportunityid){
|
||||
MPJLambdaWrapper<CrmOpportunityEntity> wrapper = JoinWrappers
|
||||
.lambda("crm_opportunity",CrmOpportunityEntity.class)
|
||||
.selectAssociation(CrmCustomerEntity.class,CrmOpportunityEntity::getCrmCustomer)
|
||||
.leftJoin(CrmCustomerEntity.class,"crm_customer",CrmCustomerEntity::getCustomerId,CrmOpportunityEntity::getCustomerId)
|
||||
.selectAll(CrmOpportunityEntity.class);
|
||||
wrapper.and(
|
||||
t->t.eq(CrmOpportunityEntity::getOpportunityId, opportunityid )
|
||||
.or().eq(CrmOpportunityEntity::getFlowTaskId, opportunityid)
|
||||
);
|
||||
return this.selectJoinOne(CrmOpportunityEntity.class,wrapper);
|
||||
}
|
||||
@Override
|
||||
public void create(CrmOpportunityEntity entity){
|
||||
this.save(entity);
|
||||
}
|
||||
@Override
|
||||
public boolean update(String opportunityid, CrmOpportunityEntity entity){
|
||||
return this.updateById(entity);
|
||||
}
|
||||
@Override
|
||||
public void delete(CrmOpportunityEntity entity){
|
||||
if(entity!=null){
|
||||
this.removeById(entity.getOpportunityId());
|
||||
}
|
||||
}
|
||||
/** 验证表单唯一字段,正则,非空 i-0新增-1修改*/
|
||||
@Override
|
||||
public String checkForm(CrmOpportunityForm form,int i) {
|
||||
boolean isUp =StringUtil.isNotEmpty(form.getOpportunityId()) && !form.getOpportunityId().equals("0");
|
||||
Object id= null;
|
||||
String countRecover = "";
|
||||
String fieldTipName = "";
|
||||
String canNotNull = I18nUtil.getMessageStr("sys.validate.textRequiredSuffix", "不能为空");
|
||||
String canNotRepeated = I18nUtil.getMessageStr("EXIST103", "不能重复");
|
||||
if (isUp){
|
||||
id = form.getOpportunityId();
|
||||
}
|
||||
//主表字段验证
|
||||
fieldTipName = "商机编码";
|
||||
fieldTipName = "商机名称";
|
||||
fieldTipName = "客户";
|
||||
fieldTipName = "商机负责人";
|
||||
fieldTipName = "商机阶段";
|
||||
fieldTipName = "预计金额";
|
||||
fieldTipName = "预计成交日期";
|
||||
fieldTipName = "商机简介";
|
||||
fieldTipName = "赢单概率";
|
||||
fieldTipName = "最后跟进日期";
|
||||
fieldTipName = "竞争对手信息";
|
||||
fieldTipName = "决策分析";
|
||||
fieldTipName = "备注";
|
||||
return countRecover;
|
||||
}
|
||||
/**
|
||||
* 新增修改数据(事务回滚)
|
||||
* @param id
|
||||
* @param crmOpportunityForm
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveOrUpdate(CrmOpportunityForm crmOpportunityForm,String id, boolean isSave) throws Exception{
|
||||
UserInfo userInfo=userProvider.get();
|
||||
UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId());
|
||||
crmOpportunityForm = JsonUtil.getJsonToBean(
|
||||
generaterSwapUtil.swapDatetime(CrmOpportunityConstant.getFormData(),crmOpportunityForm,CrmOpportunityConstant.TABLERENAMES),CrmOpportunityForm.class);
|
||||
CrmOpportunityEntity entity = JsonUtil.getJsonToBean(crmOpportunityForm, CrmOpportunityEntity.class);
|
||||
String mainUuid = StringUtil.isEmpty(id) ? RandomUtil.uuId() : id;
|
||||
if(isSave){
|
||||
entity.setFlowTaskId(mainUuid);
|
||||
entity.setOpportunityId(mainUuid);
|
||||
entity.setVersion(0);
|
||||
} else {
|
||||
}
|
||||
boolean b = this.saveOrUpdate(entity);
|
||||
int i = this.baseMapper.updateByCustomerByCustomerId(entity);
|
||||
if(!b){
|
||||
throw new DataException("当前表单原数据已被调整,请重新进入该页面编辑并提交数据");
|
||||
}
|
||||
CrmOpportunityEntity info = this.getInfo(mainUuid);
|
||||
if (info == null) throw new RuntimeException(MsgCode.FA001.get());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String selectCustomerBycustomerId(String customerId) {
|
||||
return this.baseMapper.selectCustomerBycustomerId(customerId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user