mirror of
https://github.com/1Panel-dev/CordysCRM.git
synced 2026-05-23 11:08:10 +08:00
test: add field tests
This commit is contained in:
@@ -34,27 +34,19 @@ public enum FieldType {
|
||||
*/
|
||||
SELECT,
|
||||
/**
|
||||
* 多选下拉
|
||||
*/
|
||||
MULTI_SELECT,
|
||||
/**
|
||||
* 单选成员
|
||||
* 成员
|
||||
*/
|
||||
MEMBER,
|
||||
/**
|
||||
* 多选成员
|
||||
*/
|
||||
MULTI_MEMBER,
|
||||
/**
|
||||
* 单选部门
|
||||
* 部门
|
||||
*/
|
||||
DEPARTMENT,
|
||||
/**
|
||||
* 多选部门
|
||||
*/
|
||||
MULTI_DEPARTMENT,
|
||||
/**
|
||||
* 分割线
|
||||
*/
|
||||
DIVIDER
|
||||
DIVIDER,
|
||||
/**
|
||||
* 数据源
|
||||
*/
|
||||
DATA_SOURCE
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.cordys.common.dto.DeptUserTreeNode;
|
||||
import io.cordys.common.pager.PageUtils;
|
||||
import io.cordys.common.pager.Pager;
|
||||
import io.cordys.context.OrganizationContext;
|
||||
import io.cordys.crm.system.constants.FieldType;
|
||||
import io.cordys.crm.system.dto.request.ModuleFieldRequest;
|
||||
import io.cordys.crm.system.dto.request.ModuleSourceDataRequest;
|
||||
import io.cordys.crm.system.service.ModuleFieldService;
|
||||
@@ -32,21 +33,21 @@ public class ModuleFieldController {
|
||||
@PostMapping("/dept/tree")
|
||||
@Operation(summary = "获取部门树")
|
||||
public List<DeptUserTreeNode> getDeptTree(@Valid @RequestBody ModuleFieldRequest request) {
|
||||
moduleFieldService.checkFormField(request.getFormKey(), request.getFieldId(), OrganizationContext.getOrganizationId());
|
||||
moduleFieldService.isMatchType(request.getFieldId(), FieldType.DEPARTMENT.name());
|
||||
return moduleFieldService.getDeptTree(OrganizationContext.getOrganizationId());
|
||||
}
|
||||
|
||||
@PostMapping("/user/dept/tree")
|
||||
@Operation(summary = "获取部门用户树")
|
||||
public List<DeptUserTreeNode> getDeptUserTree(@Valid @RequestBody ModuleFieldRequest request) {
|
||||
moduleFieldService.checkFormField(request.getFormKey(), request.getFieldId(), OrganizationContext.getOrganizationId());
|
||||
moduleFieldService.isMatchType(request.getFieldId(), FieldType.MEMBER.name());
|
||||
return moduleService.getDeptUserTree(OrganizationContext.getOrganizationId());
|
||||
}
|
||||
|
||||
@PostMapping("/source/data")
|
||||
@Operation(summary = "分页获取数据源数据")
|
||||
public Pager<List<? extends BaseModel>> getSourceData(@Valid @RequestBody ModuleSourceDataRequest request) {
|
||||
moduleFieldService.checkFormField(request.getFormKey(), request.getFieldId(), OrganizationContext.getOrganizationId());
|
||||
public Pager<List<? extends BaseModel>> sourceDataPage(@Valid @RequestBody ModuleSourceDataRequest request) {
|
||||
moduleFieldService.isMatchType(request.getFieldId(), FieldType.DATA_SOURCE.name());
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
|
||||
return PageUtils.setPageInfo(page, moduleFieldService.getSourceData(request, OrganizationContext.getOrganizationId()));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package io.cordys.crm.system.service;
|
||||
|
||||
import com.alibaba.excel.util.StringUtils;
|
||||
import io.cordys.common.domain.BaseModel;
|
||||
import io.cordys.common.dto.BaseTreeNode;
|
||||
import io.cordys.common.dto.DeptUserTreeNode;
|
||||
import io.cordys.common.util.Translator;
|
||||
import io.cordys.crm.system.domain.ModuleField;
|
||||
import io.cordys.crm.system.domain.ModuleForm;
|
||||
import io.cordys.crm.system.dto.request.ModuleFieldRequest;
|
||||
import io.cordys.crm.system.dto.request.ModuleSourceDataRequest;
|
||||
import io.cordys.crm.system.mapper.ExtDepartmentMapper;
|
||||
import io.cordys.mybatis.BaseMapper;
|
||||
@@ -19,8 +18,6 @@ import java.util.List;
|
||||
@Service
|
||||
public class ModuleFieldService {
|
||||
|
||||
@Resource
|
||||
private BaseMapper<ModuleForm> moduleFormMapper;
|
||||
@Resource
|
||||
private BaseMapper<ModuleField> moduleFieldMapper;
|
||||
@Resource
|
||||
@@ -42,26 +39,19 @@ public class ModuleFieldService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单字段是否存在
|
||||
* @param formKey 表单Key
|
||||
* 表单字段类型是否匹配
|
||||
* @param fieldId 字段ID
|
||||
* @param orgId 组织ID
|
||||
*/
|
||||
public void checkFormField(String formKey, String fieldId, String orgId) {
|
||||
LambdaQueryWrapper<ModuleForm> formWrapper = new LambdaQueryWrapper<>();
|
||||
formWrapper.eq(ModuleForm::getFormKey, formKey)
|
||||
.eq(ModuleForm::getOrganizationId, orgId);
|
||||
List<ModuleForm> forms = moduleFormMapper.selectListByLambda(formWrapper);
|
||||
if (forms.isEmpty()) {
|
||||
throw new ArithmeticException(Translator.get("module.field.not_exist"));
|
||||
}
|
||||
ModuleForm form = forms.getFirst();
|
||||
public void isMatchType(String fieldId, String type) {
|
||||
LambdaQueryWrapper<ModuleField> fieldWrapper = new LambdaQueryWrapper<>();
|
||||
fieldWrapper.eq(ModuleField::getFormId, form.getId())
|
||||
.eq(ModuleField::getId, fieldId);
|
||||
fieldWrapper.eq(ModuleField::getId, fieldId);
|
||||
List<ModuleField> fields = moduleFieldMapper.selectListByLambda(fieldWrapper);
|
||||
if (fields.isEmpty()) {
|
||||
throw new ArithmeticException(Translator.get("module.field.not_exist"));
|
||||
}
|
||||
ModuleField field = fields.getFirst();
|
||||
if (!StringUtils.equals(type, field.getType())) {
|
||||
throw new ArithmeticException(Translator.get("module.field.not_match_type"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ module.switch=Module switch
|
||||
module.main.nav=Primary navigation
|
||||
module.form.not_exist=Module form does not exist
|
||||
module.field.not_exist=Module field does not exist
|
||||
module.field.not_match_type=Mismatched field types
|
||||
|
||||
# permission name
|
||||
permission.system.name=System
|
||||
|
||||
@@ -102,6 +102,7 @@ module.switch=模块开关
|
||||
module.main.nav=主导航
|
||||
module.form.not_exist=模块表单不存在
|
||||
module.field.not_exist=字段不存在
|
||||
module.field.not_match_type=不匹配的字段类型
|
||||
|
||||
# permission name
|
||||
permission.system.name=系统管理
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package io.cordys.crm.system.controller;
|
||||
|
||||
import io.cordys.common.constants.FormKey;
|
||||
import io.cordys.common.util.Translator;
|
||||
import io.cordys.crm.base.BaseTest;
|
||||
import io.cordys.crm.system.constants.FieldSourceType;
|
||||
import io.cordys.crm.system.constants.FieldType;
|
||||
import io.cordys.crm.system.domain.ModuleField;
|
||||
import io.cordys.crm.system.dto.request.ModuleFieldRequest;
|
||||
import io.cordys.crm.system.dto.request.ModuleSourceDataRequest;
|
||||
import io.cordys.mybatis.BaseMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class ModuleFieldControllerTests extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private BaseMapper<ModuleField> moduleFieldMapper;
|
||||
|
||||
public static final String BASE_PATH = "/field";
|
||||
public static final String DEPT_TREE = "/dept/tree";
|
||||
public static final String USER_DEPT_TREE = "/user/dept/tree";
|
||||
public static final String SOURCE_DATA = "/source/data";
|
||||
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return BASE_PATH;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void initData() {
|
||||
ModuleField field = new ModuleField();
|
||||
field.setId("dep-test-1");
|
||||
field.setFormId("form-test-1");
|
||||
field.setType(FieldType.DEPARTMENT.name());
|
||||
field.setPos(1L);
|
||||
field.setCreateUser("admin");
|
||||
field.setCreateTime(System.currentTimeMillis());
|
||||
field.setUpdateUser("admin");
|
||||
field.setUpdateTime(System.currentTimeMillis());
|
||||
moduleFieldMapper.insert(field);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void testGetDeptTree() throws Exception {
|
||||
ModuleFieldRequest request = new ModuleFieldRequest();
|
||||
request.setFieldId("dep-test-1");
|
||||
request.setFormKey(FormKey.CUSTOMER.getKey());
|
||||
this.requestPostWithOk(DEPT_TREE, request);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void testGetUserDeptTree() throws Exception {
|
||||
ModuleFieldRequest request = new ModuleFieldRequest();
|
||||
request.setFieldId("dep-test-1");
|
||||
request.setFormKey(FormKey.CUSTOMER.getKey());
|
||||
MvcResult r1 = this.requestPost(USER_DEPT_TREE, request).andReturn();
|
||||
assert r1.getResponse().getContentAsString().contains(Translator.get("module.field.not_match_type"));
|
||||
request.setFieldId("dep-not-exit");
|
||||
MvcResult r2 = this.requestPost(USER_DEPT_TREE, request).andReturn();
|
||||
assert r2.getResponse().getContentAsString().contains(Translator.get("module.field.not_exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void testGetSourceData() throws Exception {
|
||||
ModuleSourceDataRequest sourceDataRequest = new ModuleSourceDataRequest();
|
||||
sourceDataRequest.setFieldId("dep-test-1");
|
||||
sourceDataRequest.setFormKey(FormKey.CUSTOMER.getKey());
|
||||
sourceDataRequest.setCurrent(1);
|
||||
sourceDataRequest.setPageSize(10);
|
||||
sourceDataRequest.setSourceType(FieldSourceType.CUSTOMER.name());
|
||||
this.requestPost(SOURCE_DATA, sourceDataRequest);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user