院内导视页新增字段
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
package com.jojubanking.boot.module.system.controller.admin.building;
|
||||
|
||||
import com.jojubanking.boot.framework.common.enums.CommonStatusEnum;
|
||||
import com.jojubanking.boot.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import com.jojubanking.boot.module.system.controller.admin.dept.vo.dept.DeptRespVO;
|
||||
import com.jojubanking.boot.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
|
||||
import com.jojubanking.boot.module.system.convert.dept.DeptConvert;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.dept.DeptDO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -83,26 +77,6 @@ public class BuildingController {
|
||||
return success(BuildingConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/list01")
|
||||
@ApiOperation("获得楼层导视列表01")
|
||||
@PreAuthorize("@ss.hasPermission('system:building:query')")
|
||||
public CommonResult<List<BuildingRespVO>> listDepts(BuildingListReqVO reqVO) {
|
||||
List<BuildingDO> list = buildingService.getSimpleBuildings(reqVO);
|
||||
list.sort(Comparator.comparing(BuildingDO::getFid));
|
||||
return success(BuildingConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
@GetMapping("/list-all-simple")
|
||||
@ApiOperation(value = "获取楼层精简信息列表", notes = "只包含被开启的,主要用于前端的下拉选项")
|
||||
public CommonResult<List<BuildingSimpleRespVO>> getSimpleBuildings() {
|
||||
// 获得部门列表,只要开启状态的
|
||||
BuildingListReqVO reqVO = new BuildingListReqVO();
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<BuildingDO> list = buildingService.getSimpleBuildings(reqVO);
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(BuildingDO::getFid));
|
||||
return success(BuildingConvert.INSTANCE.convertList03(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得楼层导视分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:building:query')")
|
||||
|
||||
@@ -17,14 +17,20 @@ public class BuildingBaseVO {
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "父大楼id", required = true)
|
||||
@NotNull(message = "父大楼id不能为空")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty(value = "大楼状态(0正常 1停用)", required = true)
|
||||
@NotNull(message = "大楼状态(0正常 1停用)不能为空")
|
||||
@ApiModelProperty(value = "大楼状态", required = true)
|
||||
@NotNull(message = "大楼状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "楼层id")
|
||||
@NotNull(message = "楼层id不能为空")
|
||||
private Integer fid;
|
||||
|
||||
@ApiModelProperty(value = "方位")
|
||||
private String direction;
|
||||
|
||||
@ApiModelProperty(value = "位置图")
|
||||
private String imgurl;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import java.util.*;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.jojubanking.boot.framework.excel.core.annotations.DictFormat;
|
||||
import com.jojubanking.boot.framework.excel.core.convert.DictConvert;
|
||||
|
||||
|
||||
/**
|
||||
* 楼层导视 Excel VO
|
||||
@@ -23,7 +26,8 @@ public class BuildingExcelVO {
|
||||
@ExcelProperty("父大楼id")
|
||||
private Long parentId;
|
||||
|
||||
@ExcelProperty("大楼状态(0正常 1停用)")
|
||||
@ExcelProperty(value = "大楼状态", converter = DictConvert.class)
|
||||
@DictFormat("building_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("楼层id")
|
||||
@@ -32,4 +36,11 @@ public class BuildingExcelVO {
|
||||
@ExcelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ExcelProperty(value = "方位", converter = DictConvert.class)
|
||||
@DictFormat("building_direction") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private String direction;
|
||||
|
||||
@ExcelProperty("位置图")
|
||||
private String imgurl;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class BuildingExportReqVO {
|
||||
@ApiModelProperty(value = "父大楼id")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty(value = "大楼状态(0正常 1停用)")
|
||||
@ApiModelProperty(value = "大楼状态")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "楼层id")
|
||||
@@ -28,4 +28,10 @@ public class BuildingExportReqVO {
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date[] createTime;
|
||||
|
||||
@ApiModelProperty(value = "方位")
|
||||
private String direction;
|
||||
|
||||
@ApiModelProperty(value = "位置图")
|
||||
private String imgurl;
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class BuildingPageReqVO extends PageParam {
|
||||
@ApiModelProperty(value = "父大楼id")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty(value = "大楼状态(0正常 1停用)")
|
||||
@ApiModelProperty(value = "大楼状态")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "楼层id")
|
||||
@@ -30,4 +30,10 @@ public class BuildingPageReqVO extends PageParam {
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date[] createTime;
|
||||
|
||||
@ApiModelProperty(value = "方位")
|
||||
private String direction;
|
||||
|
||||
@ApiModelProperty(value = "位置图")
|
||||
private String imgurl;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.util.*;
|
||||
|
||||
import com.jojubanking.boot.framework.common.pojo.PageResult;
|
||||
|
||||
import com.jojubanking.boot.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.dept.DeptDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import com.jojubanking.boot.module.system.controller.admin.building.vo.*;
|
||||
@@ -33,7 +31,4 @@ public interface BuildingConvert {
|
||||
|
||||
List<BuildingExcelVO> convertList02(List<BuildingDO> list);
|
||||
|
||||
|
||||
List<BuildingSimpleRespVO> convertList03(List<BuildingDO> list);
|
||||
|
||||
}
|
||||
|
||||
@@ -34,12 +34,24 @@ public class BuildingDO extends BaseDO {
|
||||
*/
|
||||
private Long parentId;
|
||||
/**
|
||||
* 大楼状态(0正常 1停用)
|
||||
* 大楼状态
|
||||
*
|
||||
* 枚举 {@link TODO building_status 对应的类}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 楼层id
|
||||
*/
|
||||
private Integer fid;
|
||||
/**
|
||||
* 方位
|
||||
*
|
||||
* 枚举 {@link TODO building_direction 对应的类}
|
||||
*/
|
||||
private String direction;
|
||||
/**
|
||||
* 位置图
|
||||
*/
|
||||
private String imgurl;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,16 +2,12 @@ package com.jojubanking.boot.module.system.dal.mysql.building;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jojubanking.boot.framework.common.pojo.PageResult;
|
||||
import com.jojubanking.boot.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.jojubanking.boot.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.jojubanking.boot.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.building.BuildingDO;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.dept.DeptDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.jojubanking.boot.module.system.controller.admin.building.vo.*;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* 楼层导视 Mapper
|
||||
@@ -28,6 +24,8 @@ public interface BuildingMapper extends BaseMapperX<BuildingDO> {
|
||||
.eqIfPresent(BuildingDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(BuildingDO::getFid, reqVO.getFid())
|
||||
.betweenIfPresent(BuildingDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(BuildingDO::getDirection, reqVO.getDirection())
|
||||
.eqIfPresent(BuildingDO::getImgurl, reqVO.getImgurl())
|
||||
.orderByDesc(BuildingDO::getId));
|
||||
}
|
||||
|
||||
@@ -38,26 +36,9 @@ public interface BuildingMapper extends BaseMapperX<BuildingDO> {
|
||||
.eqIfPresent(BuildingDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(BuildingDO::getFid, reqVO.getFid())
|
||||
.betweenIfPresent(BuildingDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(BuildingDO::getDirection, reqVO.getDirection())
|
||||
.eqIfPresent(BuildingDO::getImgurl, reqVO.getImgurl())
|
||||
.orderByDesc(BuildingDO::getId));
|
||||
}
|
||||
|
||||
default List<BuildingDO> selectList01(BuildingListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<BuildingDO>()
|
||||
.likeIfPresent(BuildingDO::getName, reqVO.getName())
|
||||
.eqIfPresent(BuildingDO::getStatus, reqVO.getStatus()));
|
||||
}
|
||||
|
||||
default BuildingDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(new LambdaQueryWrapper<BuildingDO>()
|
||||
.eq(BuildingDO::getParentId, parentId)
|
||||
.eq(BuildingDO::getName, name));
|
||||
}
|
||||
|
||||
default Long selectCountByParentId(Long parentId) {
|
||||
return selectCount(BuildingDO::getParentId, parentId);
|
||||
}
|
||||
|
||||
@Select("SELECT COUNT(*) FROM hnwj_buiding WHERE update_time > #{maxUpdateTime}")
|
||||
Long selectCountByUpdateTimeGt(Date maxUpdateTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package com.jojubanking.boot.module.system.service.building;
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import com.jojubanking.boot.module.system.controller.admin.building.vo.*;
|
||||
import com.jojubanking.boot.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.building.BuildingDO;
|
||||
import com.jojubanking.boot.framework.common.pojo.PageResult;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.dept.DeptDO;
|
||||
|
||||
/**
|
||||
* 楼层导视 Service 接口
|
||||
@@ -53,16 +51,6 @@ public interface BuildingService {
|
||||
*/
|
||||
List<BuildingDO> getBuildingList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 筛选楼层导视列表
|
||||
*
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<BuildingDO> getSimpleBuildings(BuildingListReqVO reqVO);
|
||||
|
||||
List<BuildingDO> getBuildingsByParentIdFromCache(Long parentId, boolean recursive);
|
||||
|
||||
/**
|
||||
* 获得楼层导视分页
|
||||
*
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
package com.jojubanking.boot.module.system.service.building;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.jojubanking.boot.framework.common.enums.CommonStatusEnum;
|
||||
import com.jojubanking.boot.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import com.jojubanking.boot.module.system.convert.dept.DeptConvert;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.dept.DeptDO;
|
||||
import com.jojubanking.boot.module.system.enums.dept.DeptIdEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -33,145 +26,31 @@ public class BuildingServiceImpl implements BuildingService {
|
||||
|
||||
@Resource
|
||||
private BuildingMapper buildingMapper;
|
||||
private volatile Multimap<Long, BuildingDO> parentBuildingCache;
|
||||
|
||||
@Override
|
||||
public Long createBuilding(BuildingCreateReqVO createReqVO) {
|
||||
// 校验正确性
|
||||
if (createReqVO.getParentId() == null) {
|
||||
createReqVO.setParentId(DeptIdEnum.ROOT.getId());
|
||||
}
|
||||
|
||||
checkCreateOrUpdate(null, createReqVO.getParentId(), createReqVO.getName());
|
||||
// 插入
|
||||
BuildingDO building = BuildingConvert.INSTANCE.convert(createReqVO);
|
||||
buildingMapper.insert(building);
|
||||
// 发送刷新消息
|
||||
// deptProducer.sendDeptRefreshMessage();
|
||||
// 返回
|
||||
return building.getId();
|
||||
}
|
||||
private void checkCreateOrUpdate(Long id, Long parentId, String name) {
|
||||
// 校验自己存在
|
||||
checkBuildingExists(id);
|
||||
// 校验父部门的有效性
|
||||
checkParentBuildingEnable(id, parentId);
|
||||
// 校验部门名的唯一性
|
||||
checkBuildingNameUnique(id, parentId, name);
|
||||
}
|
||||
|
||||
private void checkParentBuildingEnable(Long id, Long parentId) {
|
||||
if (parentId == null || DeptIdEnum.ROOT.getId().equals(parentId)) {
|
||||
return;
|
||||
}
|
||||
// 不能设置自己为父部门
|
||||
if (parentId.equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(BUILDING_PARENT_ERROR);
|
||||
}
|
||||
// 父岗位不存在
|
||||
BuildingDO building = buildingMapper.selectById(parentId);
|
||||
if (building == null) {
|
||||
throw ServiceExceptionUtil.exception(BUILDING_PARENT_NOT_EXITS);
|
||||
}
|
||||
// 父部门被禁用
|
||||
if (!CommonStatusEnum.ENABLE.getStatus().equals(building.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(BUILDING_NOT_ENABLE);
|
||||
}
|
||||
// 父部门不能是原来的子部门
|
||||
// List<BuildingDO> children = this.getBuildingsByParentIdFromCache(id, true);
|
||||
// if (children.stream().anyMatch(building1 -> building1.getId().equals(parentId))) {
|
||||
// throw ServiceExceptionUtil.exception(BUILDING_PARENT_IS_CHILD);
|
||||
// }
|
||||
}
|
||||
@Override
|
||||
public List<BuildingDO> getBuildingsByParentIdFromCache(Long parentId, boolean recursive) {
|
||||
if (parentId == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<BuildingDO> result = new ArrayList<>(); // TODO TW:待优化,新增缓存,避免每次遍历的计算
|
||||
// 递归,简单粗暴
|
||||
this.getBuildingsByParentIdFromCache(result, parentId,
|
||||
recursive ? Integer.MAX_VALUE : 1, // 如果递归获取,则无限;否则,只递归 1 次
|
||||
parentBuildingCache);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取所有的子部门,添加到 result 结果
|
||||
*
|
||||
* @param result 结果
|
||||
* @param parentId 父编号
|
||||
* @param recursiveCount 递归次数
|
||||
* @param parentBuildingCache 父部门 Map,使用缓存,避免变化
|
||||
*/
|
||||
private void getBuildingsByParentIdFromCache(List<BuildingDO> result, Long parentId, int recursiveCount,
|
||||
Multimap<Long, BuildingDO> parentBuildingCache) {
|
||||
// 递归次数为 0,结束!
|
||||
if (recursiveCount == 0) {
|
||||
return;
|
||||
}
|
||||
// 获得子部门
|
||||
Collection<BuildingDO> depts = parentBuildingCache.get(parentId);
|
||||
if (CollUtil.isEmpty(depts)) {
|
||||
return;
|
||||
}
|
||||
result.addAll(depts);
|
||||
// 继续递归
|
||||
depts.forEach(dept -> getBuildingsByParentIdFromCache(result, dept.getId(),
|
||||
recursiveCount - 1, parentBuildingCache));
|
||||
}
|
||||
private void checkBuildingExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
BuildingDO building = buildingMapper.selectById(id);
|
||||
if (building == null) {
|
||||
throw ServiceExceptionUtil.exception(BUILDING_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkBuildingNameUnique(Long id, Long parentId, String name) {
|
||||
BuildingDO menu = buildingMapper.selectByParentIdAndName(parentId, name);
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的岗位
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(BUILDING_NAME_DUPLICATE);
|
||||
}
|
||||
if (!menu.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(BUILDING_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void updateBuilding(BuildingUpdateReqVO updateReqVO) {
|
||||
|
||||
// 校验正确性
|
||||
if (updateReqVO.getParentId() == null) {
|
||||
updateReqVO.setParentId(DeptIdEnum.ROOT.getId());
|
||||
}
|
||||
checkCreateOrUpdate(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
|
||||
// 更新部门
|
||||
// 校验存在
|
||||
this.validateBuildingExists(updateReqVO.getId());
|
||||
// 更新
|
||||
BuildingDO updateObj = BuildingConvert.INSTANCE.convert(updateReqVO);
|
||||
buildingMapper.updateById(updateObj);
|
||||
// 发送刷新消息
|
||||
// deptProducer.sendDeptRefreshMessage();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBuilding(Long id) {
|
||||
// 校验是否存在
|
||||
checkBuildingExists(id);
|
||||
// 校验是否有子部门
|
||||
if (buildingMapper.selectCountByParentId(id) > 0) {
|
||||
throw ServiceExceptionUtil.exception(BUILDING_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除部门
|
||||
// 校验存在
|
||||
this.validateBuildingExists(id);
|
||||
// 删除
|
||||
buildingMapper.deleteById(id);
|
||||
// 发送刷新消息
|
||||
// deptProducer.sendDeptRefreshMessage();
|
||||
|
||||
}
|
||||
|
||||
private void validateBuildingExists(Long id) {
|
||||
@@ -200,9 +79,4 @@ public class BuildingServiceImpl implements BuildingService {
|
||||
return buildingMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BuildingDO> getSimpleBuildings(BuildingListReqVO reqVO){
|
||||
return buildingMapper.selectList01(reqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jojubanking.boot.module.system.dal.mysql.building.BuildingMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.jojubanking.boot.module.system.service.building;
|
||||
|
||||
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.jojubanking.boot.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import com.jojubanking.boot.module.system.controller.admin.building.vo.*;
|
||||
import com.jojubanking.boot.module.system.dal.dataobject.building.BuildingDO;
|
||||
import com.jojubanking.boot.module.system.dal.mysql.building.BuildingMapper;
|
||||
import com.jojubanking.boot.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static com.jojubanking.boot.module.system.enums.ErrorCodeConstants.*;
|
||||
import static com.jojubanking.boot.framework.test.core.util.AssertUtils.*;
|
||||
import static com.jojubanking.boot.framework.test.core.util.RandomUtils.*;
|
||||
import static com.jojubanking.boot.framework.common.util.object.ObjectUtils.*;
|
||||
import static com.jojubanking.boot.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link BuildingServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author admin
|
||||
*/
|
||||
@Import(BuildingServiceImpl.class)
|
||||
public class BuildingServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private BuildingServiceImpl buildingService;
|
||||
|
||||
@Resource
|
||||
private BuildingMapper buildingMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateBuilding_success() {
|
||||
// 准备参数
|
||||
BuildingCreateReqVO reqVO = randomPojo(BuildingCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long buildingId = buildingService.createBuilding(reqVO);
|
||||
// 断言
|
||||
assertNotNull(buildingId);
|
||||
// 校验记录的属性是否正确
|
||||
BuildingDO building = buildingMapper.selectById(buildingId);
|
||||
assertPojoEquals(reqVO, building);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBuilding_success() {
|
||||
// mock 数据
|
||||
BuildingDO dbBuilding = randomPojo(BuildingDO.class);
|
||||
buildingMapper.insert(dbBuilding);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
BuildingUpdateReqVO reqVO = randomPojo(BuildingUpdateReqVO.class, o -> {
|
||||
o.setId(dbBuilding.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
buildingService.updateBuilding(reqVO);
|
||||
// 校验是否更新正确
|
||||
BuildingDO building = buildingMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, building);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBuilding_notExists() {
|
||||
// 准备参数
|
||||
BuildingUpdateReqVO reqVO = randomPojo(BuildingUpdateReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> buildingService.updateBuilding(reqVO), BUILDING_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBuilding_success() {
|
||||
// mock 数据
|
||||
BuildingDO dbBuilding = randomPojo(BuildingDO.class);
|
||||
buildingMapper.insert(dbBuilding);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbBuilding.getId();
|
||||
|
||||
// 调用
|
||||
buildingService.deleteBuilding(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(buildingMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteBuilding_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> buildingService.deleteBuilding(id), BUILDING_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetBuildingPage() {
|
||||
// mock 数据
|
||||
BuildingDO dbBuilding = randomPojo(BuildingDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setParentId(null);
|
||||
o.setStatus(null);
|
||||
o.setFid(null);
|
||||
o.setCreateTime(null);
|
||||
o.setDirection(null);
|
||||
o.setImgurl(null);
|
||||
});
|
||||
buildingMapper.insert(dbBuilding);
|
||||
// 测试 name 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setName(null)));
|
||||
// 测试 parentId 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setParentId(null)));
|
||||
// 测试 status 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setStatus(null)));
|
||||
// 测试 fid 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setFid(null)));
|
||||
// 测试 createTime 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setCreateTime(null)));
|
||||
// 测试 direction 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setDirection(null)));
|
||||
// 测试 imgurl 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setImgurl(null)));
|
||||
// 准备参数
|
||||
BuildingPageReqVO reqVO = new BuildingPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setParentId(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setFid(null);
|
||||
reqVO.setCreateTime((new Date[]{}));
|
||||
reqVO.setDirection(null);
|
||||
reqVO.setImgurl(null);
|
||||
|
||||
// 调用
|
||||
PageResult<BuildingDO> pageResult = buildingService.getBuildingPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbBuilding, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetBuildingList() {
|
||||
// mock 数据
|
||||
BuildingDO dbBuilding = randomPojo(BuildingDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setParentId(null);
|
||||
o.setStatus(null);
|
||||
o.setFid(null);
|
||||
o.setCreateTime(null);
|
||||
o.setDirection(null);
|
||||
o.setImgurl(null);
|
||||
});
|
||||
buildingMapper.insert(dbBuilding);
|
||||
// 测试 name 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setName(null)));
|
||||
// 测试 parentId 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setParentId(null)));
|
||||
// 测试 status 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setStatus(null)));
|
||||
// 测试 fid 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setFid(null)));
|
||||
// 测试 createTime 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setCreateTime(null)));
|
||||
// 测试 direction 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setDirection(null)));
|
||||
// 测试 imgurl 不匹配
|
||||
buildingMapper.insert(cloneIgnoreId(dbBuilding, o -> o.setImgurl(null)));
|
||||
// 准备参数
|
||||
BuildingExportReqVO reqVO = new BuildingExportReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setParentId(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setFid(null);
|
||||
reqVO.setCreateTime((new Date[]{}));
|
||||
reqVO.setDirection(null);
|
||||
reqVO.setImgurl(null);
|
||||
|
||||
// 调用
|
||||
List<BuildingDO> list = buildingService.getBuildingList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbBuilding, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user