【职工信息】优化交互

master
zengchenxi 10 months ago
parent e8c4837c54
commit 7516f53be0

@ -11,6 +11,7 @@ import com.chanko.yunxi.mes.framework.common.exception.ErrorCode;
* x -
* 3
* 001
* 002
* 3
*/
public interface ErrorCodeConstants {

@ -1,146 +0,0 @@
package com.chanko.yunxi.mes.module.heli.service.client;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import com.chanko.yunxi.mes.framework.test.core.ut.BaseDbUnitTest;
import com.chanko.yunxi.mes.module.heli.controller.admin.client.vo.*;
import com.chanko.yunxi.mes.module.heli.dal.dataobject.client.ClientDO;
import com.chanko.yunxi.mes.module.heli.dal.mysql.client.ClientMapper;
import com.chanko.yunxi.mes.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static com.chanko.yunxi.mes.module.heli.enums.ErrorCodeConstants.*;
import static com.chanko.yunxi.mes.framework.test.core.util.AssertUtils.*;
import static com.chanko.yunxi.mes.framework.test.core.util.RandomUtils.*;
import static com.chanko.yunxi.mes.framework.common.util.date.LocalDateTimeUtils.*;
import static com.chanko.yunxi.mes.framework.common.util.object.ObjectUtils.*;
import static com.chanko.yunxi.mes.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link ClientServiceImpl}
*
* @author
*/
@Import(ClientServiceImpl.class)
public class ClientServiceImplTest extends BaseDbUnitTest {
@Resource
private ClientServiceImpl clientService;
@Resource
private ClientMapper clientMapper;
@Test
public void testCreateClient_success() {
// 准备参数
ClientSaveReqVO createReqVO = randomPojo(ClientSaveReqVO.class).setId(null);
// 调用
Long clientId = clientService.createClient(createReqVO);
// 断言
assertNotNull(clientId);
// 校验记录的属性是否正确
ClientDO client = clientMapper.selectById(clientId);
assertPojoEquals(createReqVO, client, "id");
}
@Test
public void testUpdateClient_success() {
// mock 数据
ClientDO dbClient = randomPojo(ClientDO.class);
clientMapper.insert(dbClient);// @Sql: 先插入出一条存在的数据
// 准备参数
ClientSaveReqVO updateReqVO = randomPojo(ClientSaveReqVO.class, o -> {
o.setId(dbClient.getId()); // 设置更新的 ID
});
// 调用
clientService.updateClient(updateReqVO);
// 校验是否更新正确
ClientDO client = clientMapper.selectById(updateReqVO.getId()); // 获取最新的
assertPojoEquals(updateReqVO, client);
}
@Test
public void testUpdateClient_notExists() {
// 准备参数
ClientSaveReqVO updateReqVO = randomPojo(ClientSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> clientService.updateClient(updateReqVO), CLIENT_NOT_EXISTS);
}
@Test
public void testDeleteClient_success() {
// mock 数据
ClientDO dbClient = randomPojo(ClientDO.class);
clientMapper.insert(dbClient);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbClient.getId();
// 调用
clientService.deleteClient(id);
// 校验数据不存在了
assertNull(clientMapper.selectById(id));
}
@Test
public void testDeleteClient_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> clientService.deleteClient(id), CLIENT_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetClientPage() {
// mock 数据
ClientDO dbClient = randomPojo(ClientDO.class, o -> { // 等会查询到
o.setCode(null);
o.setSimpleName(null);
o.setName(null);
o.setTelephone(null);
o.setStatus(null);
});
clientMapper.insert(dbClient);
// 测试 code 不匹配
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setCode(null)));
// 测试 simpleName 不匹配
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setSimpleName(null)));
// 测试 name 不匹配
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setName(null)));
// 测试 telephone 不匹配
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setTelephone(null)));
// 测试 status 不匹配
clientMapper.insert(cloneIgnoreId(dbClient, o -> o.setStatus(null)));
// 准备参数
ClientPageReqVO reqVO = new ClientPageReqVO();
reqVO.setCode(null);
reqVO.setSimpleName(null);
reqVO.setName(null);
reqVO.setTelephone(null);
reqVO.setStatus(null);
// 调用
PageResult<ClientDO> pageResult = clientService.getClientPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbClient, pageResult.getList().get(0));
}
}

@ -1,6 +1,8 @@
package com.chanko.yunxi.mes.module.system.controller.admin.user.vo.user;
import cn.hutool.core.util.ObjectUtil;
import com.chanko.yunxi.mes.framework.common.enums.CommonStatusEnum;
import com.chanko.yunxi.mes.framework.common.validation.InEnum;
import com.chanko.yunxi.mes.framework.common.validation.Mobile;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
@ -17,14 +19,14 @@ public class UserSaveReqVO {
@Schema(description = "用户编号", example = "1024")
private Long id;
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "mes")
@NotBlank(message = "用户账号不能为空")
@Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成")
@Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符")
@Schema(description = "号", requiredMode = Schema.RequiredMode.REQUIRED, example = "mes")
@NotBlank(message = "号不能为空")
@Pattern(regexp = "^[a-zA-Z0-9]{1,30}$", message = "工号由 数字、字母 组成")
@Size(max = 30, message = "工号长度不能超过 30 个字符")
private String username;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
@Schema(description = "姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@Size(max = 30, message = "姓名长度不能超过30个字符")
private String nickname;
@Schema(description = "备注", example = "我是一个用户")
@ -57,6 +59,11 @@ public class UserSaveReqVO {
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
@Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
private Integer status;
@AssertTrue(message = "密码不能为空")
@JsonIgnore
public boolean isPasswordValid() {

@ -88,6 +88,20 @@
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="启用状态" prop="status">
<el-select v-model="formData.status" clearable placeholder="请选择启用状态">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.HELI_SYSTEM_COMMON_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
@ -131,6 +145,7 @@ const formRules = reactive<FormRules>({
username: [{ required: true, message: '工号不能为空', trigger: 'blur' }],
nickname: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
password: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
status: [{ required: true, message: '启用状态不能为空', trigger: 'blur' }],
email: [
{
type: 'email',

@ -3,7 +3,7 @@
<!-- 左侧部门树 -->
<el-col :span="4" :xs="24">
<ContentWrap class="h-1/1">
<DeptTree @node-click="handleDeptNodeClick" />
<DeptTree @node-click="handleDeptNodeClick" :key="queryParams.deptId === null"/>
</ContentWrap>
</el-col>
<el-col :span="20" :xs="24">
@ -34,30 +34,30 @@
class="!w-240px"
/>
</el-form-item>
<!-- <el-form-item label="手机号码" prop="mobile">
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机号码"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-form-item label="启用状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="状态"
placeholder="请选择启用状态"
clearable
class="!w-240px"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
v-for="dict in getIntDictOptions(DICT_TYPE.HELI_SYSTEM_COMMON_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<!-- <el-form-item label="手机号码" prop="mobile">
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机号码"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
@ -122,14 +122,9 @@
:show-overflow-tooltip="true"
/>
<el-table-column label="手机号码" align="center" prop="mobile" width="120" />
<el-table-column label="状态" key="status">
<el-table-column prop="status" label="启用状态">
<template #default="scope">
<el-switch
v-model="scope.row.status"
:active-value="0"
:inactive-value="1"
@change="handleStatusChange(scope.row)"
/>
<dict-tag :type="DICT_TYPE.HELI_SYSTEM_COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column
@ -256,6 +251,7 @@ const handleQuery = () => {
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
queryParams.deptId = null;
handleQuery()
}

Loading…
Cancel
Save