Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,50 @@ public enum BusinessModuleField {
/*------ start: PRODUCT ------*/
PRODUCT_NAME("productName", "name", Set.of("rules.required", "mobile"), FormKey.PRODUCT.getKey()),
PRODUCT_PRICE("productPrice", "price", Set.of(), FormKey.PRODUCT.getKey()),
PRODUCT_STATUS("productStatus", "status", Set.of("rules.required", "mobile"), FormKey.PRODUCT.getKey());
PRODUCT_STATUS("productStatus", "status", Set.of("rules.required", "mobile"), FormKey.PRODUCT.getKey()),
/*------ end: PRODUCT ------*/

/**
* 价格表单
*/
PRICE_NAME("priceName", "name", Set.of("rules.required", "mobile"), FormKey.PRICE.getKey()),
PRICE_STATUS("priceStatus", "status", Set.of("rules.required", "mobile"), FormKey.PRICE.getKey()),
PRICE_PRODUCT_TABLE("priceProducts", "products", Set.of("mobile"), FormKey.PRICE.getKey()),
PRICE_PRODUCT("priceProduct", "product", Set.of("rules.required", "mobile", "dataSourceType"), FormKey.PRICE.getKey()),
PRICE_PRODUCT_AMOUNT("priceProductAmount", "amount", Set.of("rules.required", "mobile"), FormKey.PRICE.getKey()),

/**
* 报价单表单
*/
QUOTATION_NAME("quotationName", "name", Set.of("rules.required", "mobile"), FormKey.QUOTATION.getKey()),
QUOTATION_OPPORTUNITY("quotationOpportunity", "opportunityId", Set.of("rules.required", "mobile"), FormKey.QUOTATION.getKey()),
QUOTATION_PRODUCT_TABLE("quotationProducts", "products", Set.of("mobile"), FormKey.QUOTATION.getKey()),
QUOTATION_PRODUCT("quotationProduct", "product", Set.of("rules.required", "mobile", "dataSourceType"), FormKey.QUOTATION.getKey()),
QUOTATION_PRODUCT_AMOUNT("quotationAmount", "amount", Set.of("rules.required", "mobile"), FormKey.QUOTATION.getKey()),

/**
* 合同回款计划
*/
/*------ start: CONTRACT_PAYMENT_PLAN ------*/
/**
* 负责人
*/
CONTRACT_PAYMENT_PLAN_OWNER("contractPaymentPlanOwner", "owner", Set.of("rules.required", "mobile"), FormKey.CONTRACT_PAYMENT_PLAN.getKey()),
/**
* 合同
*/
CONTRACT_PAYMENT_PLAN_CONTRACT("contractPaymentPlanContract", "contractId", Set.of(), FormKey.CONTRACT_PAYMENT_PLAN.getKey()),
/**
* 计划回款金额
*/
CONTRACT_PAYMENT_PLAN_PLAN_AMOUNT("contractPaymentPlanPlanAmount", "plan_amount", Set.of(), FormKey.CONTRACT_PAYMENT_PLAN.getKey()),
/**
* 计划回款时间
*/
CONTRACT_PAYMENT_PLAN_PLAN_END_TIME("contractPaymentPlanPlanEndTime", "plan_end_time", Set.of(), FormKey.CONTRACT_PAYMENT_PLAN.getKey());
/*------ end: CONTRACT_PAYMENT_PLAN ------*/


/**
* 业务字段缓存
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public enum FormKey {
/**
* 合同
*/
CONTRACT("contract");
CONTRACT("contract"),
/**
* 合同回款计划
*/
CONTRACT_PAYMENT_PLAN("contractPaymentPlan");

private final String key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void initOneTime() {
initOneTime(moduleFormService::processOldLinkData, "process.old.link.data");
initOneTime(moduleFormService::initFormScenarioProp, "init.record.form.scenario");
initOneTime(clueService::processTransferredCluePlanAndRecord, "process.transferred.clue");
initOneTime(moduleFormService::initUpgradeForm, "init.upgrade.form.v1.3.4");
initOneTime(moduleFormService::initUpgradeForm, "init.upgrade.form.v1.4.0");
} finally {
lock.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.cordys.crm.product.controller;

import cn.cordys.common.constants.FormKey;
import cn.cordys.common.constants.PermissionConstants;
import cn.cordys.common.pager.PagerWithOption;
import cn.cordys.context.OrganizationContext;
Expand All @@ -10,6 +11,8 @@
import cn.cordys.crm.product.dto.response.ProductPriceGetResponse;
import cn.cordys.crm.product.dto.response.ProductPriceResponse;
import cn.cordys.crm.product.service.ProductPriceService;
import cn.cordys.crm.system.dto.response.ModuleFormConfigDTO;
import cn.cordys.crm.system.service.ModuleFormCacheService;
import cn.cordys.security.SessionUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -30,6 +33,15 @@ public class ProductPriceController {

@Resource
private ProductPriceService priceService;
@Resource
private ModuleFormCacheService moduleFormCacheService;

@GetMapping("/module/form")
@RequiresPermissions(PermissionConstants.PRICE_READ)
@Operation(summary = "获取表单配置")
public ModuleFormConfigDTO getModuleFormConfig() {
return moduleFormCacheService.getBusinessFormConfig(FormKey.PRICE.getKey(), OrganizationContext.getOrganizationId());
}

@PostMapping("/page")
@RequiresPermissions(PermissionConstants.PRICE_READ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,14 @@ public enum FieldType {
/**
* 行业
*/
INDUSTRY
INDUSTRY,
/**
* 公式
*/
FORMULA,
/**
* 子表-产品, 子表-价格
*/
SUB_PRODUCT,
SUB_PRICE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cn.cordys.crm.system.dto.field;

import cn.cordys.crm.system.dto.field.base.BaseField;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* 公式字段
* @author song-cc-rock
*/
@Data
@JsonTypeName(value = "FORMULA")
@EqualsAndHashCode(callSuper = true)
public class FormulaField extends BaseField {

@Schema(description = "公式")
private String formula;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cn.cordys.crm.system.dto.field;

import cn.cordys.crm.system.dto.field.base.SubField;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@JsonTypeName("SUB_PRICE")
@EqualsAndHashCode(callSuper = true)
public class PriceSubField extends SubField {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cn.cordys.crm.system.dto.field;

import cn.cordys.crm.system.dto.field.base.BaseField;
import cn.cordys.crm.system.dto.field.base.SubField;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
* 产品子表字段
* @author song-cc-rock
*/
@Data
@JsonTypeName(value = "SUB_PRODUCT")
@EqualsAndHashCode(callSuper = true)
public class ProductSubField extends SubField {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.List;
import java.util.Set;

/**
* @author song-cc-rock
*/
@Data
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true)
@JsonSubTypes({
Expand All @@ -38,7 +41,10 @@
@JsonSubTypes.Type(value = SerialNumberField.class, name = "SERIAL_NUMBER"),
@JsonSubTypes.Type(value = AttachmentField.class, name = "ATTACHMENT"),
@JsonSubTypes.Type(value = LinkField.class, name = "LINK"),
@JsonSubTypes.Type(value = IndustryField.class, name = "INDUSTRY")
@JsonSubTypes.Type(value = IndustryField.class, name = "INDUSTRY"),
@JsonSubTypes.Type(value = ProductSubField.class, name = "SUB_PRODUCT"),
@JsonSubTypes.Type(value = PriceSubField.class, name = "SUB_PRICE"),
@JsonSubTypes.Type(value = FormulaField.class, name = "FORMULA"),
})
public abstract class BaseField {

Expand Down Expand Up @@ -138,7 +144,7 @@ public boolean hasOptions() {

@JsonIgnore
public boolean canImport() {
return !Strings.CS.equalsAny(type, FieldType.SERIAL_NUMBER.name())
return !Strings.CS.equalsAny(type, FieldType.SERIAL_NUMBER.name()) && !Strings.CS.equalsAny(type, FieldType.ATTACHMENT.name())
&& !Strings.CS.equalsAny(type, FieldType.PICTURE.name()) && !Strings.CS.equalsAny(type, FieldType.DIVIDER.name()) && readable;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cn.cordys.crm.system.dto.field.base;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
* 通用子表格字段(兼容子表格)
* @author song-cc-rock
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class SubField extends BaseField{

@Schema(description = "固定宽度")
private Integer fixedColumn;

@Schema(description = "表格子字段")
private List<? extends BaseField> subFields;

@Schema(description = "汇总列")
private String sumColumn;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,11 @@ public ModuleFormConfigDTO getBusinessFormConfig(String formKey, String organiza
ModuleFormConfigDTO businessModuleFormConfig = new ModuleFormConfigDTO();
businessModuleFormConfig.setFormProp(config.getFormProp());

// 获取特殊的业务字段
Map<String, BusinessModuleField> businessModuleFieldMap = Arrays.stream(BusinessModuleField.values()).
collect(Collectors.toMap(BusinessModuleField::getKey, Function.identity()));

businessModuleFormConfig.setFields(
config.getFields()
.stream()
.peek(moduleFieldDTO -> {
BusinessModuleField businessModuleFieldEnum = businessModuleFieldMap.get(moduleFieldDTO.getInternalKey());
if (businessModuleFieldEnum != null) {
// 设置特殊的业务字段 key
moduleFieldDTO.setBusinessKey(businessModuleFieldEnum.getBusinessKey());
moduleFieldDTO.setDisabledProps(businessModuleFieldEnum.getDisabledProps());
}
})
.collect(Collectors.toList())
);
// 设置业务字段参数
businessModuleFormConfig.setFields(config.getFields().stream()
.peek(moduleFormService::setFieldBusinessParam)
.collect(Collectors.toList())
);
return businessModuleFormConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class ModuleFormService {
public static final Map<String, String> TYPE_SOURCE_MAP;
private static final String DEFAULT_ORGANIZATION_ID = "100001";
private static final String CONTROL_RULES_KEY = "showControlRules";
private static final String SUB_FIELDS = "subFields";

static {
TYPE_SOURCE_MAP = Map.of(FieldType.MEMBER.name(), "sys_user",
Expand Down Expand Up @@ -132,23 +133,10 @@ public ModuleFormConfigDTO getBusinessFormConfig(String formKey, String organiza
ModuleFormConfigDTO config = getConfig(formKey, organizationId);
ModuleFormConfigDTO businessModuleFormConfig = new ModuleFormConfigDTO();
businessModuleFormConfig.setFormProp(config.getFormProp());

// 获取特殊的业务字段
Map<String, BusinessModuleField> businessModuleFieldMap = Arrays.stream(BusinessModuleField.values()).
collect(Collectors.toMap(BusinessModuleField::getKey, Function.identity()));

businessModuleFormConfig.setFields(
config.getFields()
.stream()
.peek(moduleFieldDTO -> {
BusinessModuleField businessModuleFieldEnum = businessModuleFieldMap.get(moduleFieldDTO.getInternalKey());
if (businessModuleFieldEnum != null) {
// 设置特殊的业务字段 key
moduleFieldDTO.setBusinessKey(businessModuleFieldEnum.getBusinessKey());
moduleFieldDTO.setDisabledProps(businessModuleFieldEnum.getDisabledProps());
}
})
.toList()
// 设置业务字段参数
businessModuleFormConfig.setFields(config.getFields().stream()
.peek(this::setFieldBusinessParam)
.collect(Collectors.toList())
);
return businessModuleFormConfig;
}
Expand Down Expand Up @@ -424,6 +412,25 @@ public List<String> resolveSourceNames(String type, List<String> nameList) {
return extModuleFieldMapper.resolveIdsByName(TYPE_SOURCE_MAP.get(type), nameList);
}

/**
* 设置自定义字段业务参数
* @param field 自定义字段
*/
public void setFieldBusinessParam(BaseField field) {
// 获取特殊的业务字段
Map<String, BusinessModuleField> businessModuleFieldMap = Arrays.stream(BusinessModuleField.values()).
collect(Collectors.toMap(BusinessModuleField::getKey, Function.identity()));
if (field instanceof SubField subField) {
subField.getSubFields().forEach(this::setFieldBusinessParam);
}
BusinessModuleField businessEnum = businessModuleFieldMap.get(field.getInternalKey());
if (businessEnum != null) {
// 设置特殊的业务字段 key
field.setBusinessKey(businessEnum.getBusinessKey());
field.setDisabledProps(businessEnum.getDisabledProps());
}
}

/**
* OptionProp转OptionDTO
*
Expand Down Expand Up @@ -547,6 +554,11 @@ public void initFormFields(Map<String, String> formKeyMap) {
});
initField.put(CONTROL_RULES_KEY, controlRules);
}
if (initField.containsKey(SUB_FIELDS)) {
List<BaseField> subFields = JSON.parseArray(JSON.toJSONString(initField.get(SUB_FIELDS)), BaseField.class);
subFields.forEach(subField -> subField.setId(IDGenerator.nextStr()));
initField.put(SUB_FIELDS, subFields);
}
ModuleFieldBlob fieldBlob = new ModuleFieldBlob();
fieldBlob.setId(field.getId());
fieldBlob.setProp(JSON.toJSONString(initField));
Expand All @@ -556,6 +568,7 @@ public void initFormFields(Map<String, String> formKeyMap) {
moduleFieldMapper.batchInsert(fields);
moduleFieldBlobMapper.batchInsert(fieldBlobs);
} catch (Exception e) {
LogUtils.error("表单字段初始化失败: {}", e.getMessage());
throw new GenericException("表单字段初始化失败", e);
}
}
Expand Down
Loading
Loading