Showing
4 changed files
with
57 additions
and
8 deletions
... | ... | @@ -32,6 +32,9 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag |
32 | 32 | @Override |
33 | 33 | public TkDeviceCagegoryDTO save(TkDeviceCagegoryDTO tkDeviceCagegoryDTO) throws ThingsboardException { |
34 | 34 | checkDto(tkDeviceCagegoryDTO); |
35 | + if (StringUtils.isBlank(tkDeviceCagegoryDTO.getId()) && checkDuplicateData(tkDeviceCagegoryDTO)) { | |
36 | + throw new TkDataValidationException("同级目录下存在重名类别!"); | |
37 | + } | |
35 | 38 | String parentId = tkDeviceCagegoryDTO.getParentId(); |
36 | 39 | TkDeviceCagegoryDTO parentDto = null; |
37 | 40 | if (StringUtils.isNotBlank(parentId)) { |
... | ... | @@ -61,6 +64,27 @@ public class TkDeviceCagegoryServiceImpl extends AbstractBaseService<TkDeviceCag |
61 | 64 | return tkDeviceCagegoryDTO; |
62 | 65 | } |
63 | 66 | |
67 | + private boolean checkDuplicateData(TkDeviceCagegoryDTO tkDeviceCagegoryDTO) throws ThingsboardException { | |
68 | + Boolean result = false; | |
69 | + if (StringUtils.isBlank(tkDeviceCagegoryDTO.getParentId())) { | |
70 | + return result; | |
71 | + } | |
72 | + QueryWrapper<TkDeviceCagegoryEntity> queryWrapper = new QueryWrapper(); | |
73 | + LambdaQueryWrapper<TkDeviceCagegoryEntity> lambda = queryWrapper.lambda(); | |
74 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
75 | + lambda.eq(TkDeviceCagegoryEntity::getTenantId, tenantId.getId().toString()); | |
76 | + lambda.eq(TkDeviceCagegoryEntity::getParentId, tkDeviceCagegoryDTO.getParentId()); | |
77 | + lambda.eq(TkDeviceCagegoryEntity::getName, tkDeviceCagegoryDTO.getName()); | |
78 | + | |
79 | + List<TkDeviceCagegoryEntity> entityList = baseMapper.selectList(queryWrapper); | |
80 | + if (CollectionUtils.isNotEmpty(entityList)) { | |
81 | + return true; | |
82 | + } | |
83 | + | |
84 | + return result; | |
85 | + | |
86 | + } | |
87 | + | |
64 | 88 | private void checkDto(TkDeviceCagegoryDTO dto) throws ThingsboardException { |
65 | 89 | if (StringUtils.isBlank(dto.getName())) { |
66 | 90 | throw new TkDataValidationException("类型名称不能为空!"); | ... | ... |
... | ... | @@ -15,6 +15,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkMalfunctionReasonDTO; |
15 | 15 | import org.thingsboard.server.common.data.yunteng.enums.MalfunctionReasonStatusEnum; |
16 | 16 | import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
18 | +import org.thingsboard.server.dao.yunteng.entities.TenantBaseEntity; | |
18 | 19 | import org.thingsboard.server.dao.yunteng.entities.TkMalfunctionReasonEntity; |
19 | 20 | import org.thingsboard.server.dao.yunteng.mapper.TkMalfunctionReasonMapper; |
20 | 21 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
... | ... | @@ -48,6 +49,7 @@ public class TkMalfunctionReasonServiceImpl extends AbstractBaseService<TkMalfun |
48 | 49 | lambda.eq(TkMalfunctionReasonEntity::getStatus, condition.getStatus()); |
49 | 50 | } |
50 | 51 | |
52 | + lambda.orderByDesc(TenantBaseEntity::getCreateTime); | |
51 | 53 | Page<TkMalfunctionReasonEntity> page = new Page<>(); |
52 | 54 | page.setCurrent(condition.getPage()); |
53 | 55 | page.setSize(condition.getPageSize()); |
... | ... | @@ -82,6 +84,17 @@ public class TkMalfunctionReasonServiceImpl extends AbstractBaseService<TkMalfun |
82 | 84 | @Override |
83 | 85 | public TkMalfunctionReasonDTO save(TkMalfunctionReasonDTO tkMalfunctionReasonDTO) throws ThingsboardException { |
84 | 86 | checkDto(tkMalfunctionReasonDTO); |
87 | + if (StringUtils.isBlank(tkMalfunctionReasonDTO.getId())) { | |
88 | + List<TkMalfunctionReasonDTO> reasonEntities = checkDuplicateData(tkMalfunctionReasonDTO.getReason()); | |
89 | + if (CollectionUtils.isNotEmpty(reasonEntities)) { | |
90 | + throw new TkDataValidationException("该故障原因已存在!"); | |
91 | + } | |
92 | + List<TkMalfunctionReasonDTO> codeEntities = checkDuplicateData(tkMalfunctionReasonDTO.getCode()); | |
93 | + if (CollectionUtils.isNotEmpty(codeEntities)) { | |
94 | + throw new TkDataValidationException("该故障编码已存在!"); | |
95 | + } | |
96 | + } | |
97 | + | |
85 | 98 | TkMalfunctionReasonEntity entity = new TkMalfunctionReasonEntity(); |
86 | 99 | if (StringUtils.isBlank(tkMalfunctionReasonDTO.getId())) { |
87 | 100 | tkMalfunctionReasonDTO.copyToEntity(entity); |
... | ... | @@ -98,6 +111,19 @@ public class TkMalfunctionReasonServiceImpl extends AbstractBaseService<TkMalfun |
98 | 111 | return tkMalfunctionReasonDTO; |
99 | 112 | } |
100 | 113 | |
114 | + private List<TkMalfunctionReasonDTO> checkDuplicateData(String key) throws ThingsboardException { | |
115 | + QueryWrapper<TkMalfunctionReasonEntity> wrapper = new QueryWrapper<>(); | |
116 | + LambdaQueryWrapper<TkMalfunctionReasonEntity> lambda = wrapper.lambda(); | |
117 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
118 | + lambda.eq(TkMalfunctionReasonEntity::getTenantId, tenantId.getId().toString()); | |
119 | + if (StringUtils.isNotBlank(key)) { | |
120 | + lambda.and(e -> e.eq(TkMalfunctionReasonEntity::getCode, key).or().eq(TkMalfunctionReasonEntity::getReason, key)); | |
121 | + } | |
122 | + List<TkMalfunctionReasonEntity> entitys = baseMapper.selectList(wrapper); | |
123 | + return Optional.ofNullable(entitys).map(all -> all.stream().map(item -> item.getDTO(TkMalfunctionReasonDTO.class)) | |
124 | + .collect(Collectors.toList())).orElse(null); | |
125 | + } | |
126 | + | |
101 | 127 | @Override |
102 | 128 | public TkMalfunctionReasonDTO detail(String id) throws ThingsboardException { |
103 | 129 | TkMalfunctionReasonDTO result = null; | ... | ... |
... | ... | @@ -21,6 +21,7 @@ import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
21 | 21 | import org.thingsboard.server.dao.yunteng.service.TkSupplierService; |
22 | 22 | |
23 | 23 | import java.util.List; |
24 | +import java.util.Locale; | |
24 | 25 | import java.util.Optional; |
25 | 26 | import java.util.stream.Collectors; |
26 | 27 | |
... | ... | @@ -32,19 +33,17 @@ public class TkSupplierServiceImpl extends AbstractBaseService<TkSupplierMapper, |
32 | 33 | @Override |
33 | 34 | public TkPageData<TkSupplierDTO> page(TkSupplierDTO condition) throws ThingsboardException { |
34 | 35 | QueryWrapper<TkSupplierEntity> wrapper = new QueryWrapper<>(); |
35 | - LambdaQueryWrapper<TkSupplierEntity> lambda = wrapper.lambda(); | |
36 | 36 | TenantId tenantId = SpringBeanUtils.getTenantId(); |
37 | - lambda.eq(TkSupplierEntity::getTenantId, tenantId.getId().toString()); | |
37 | + wrapper.eq("tenant_id", tenantId.getId().toString()); | |
38 | 38 | if (StringUtils.isNotBlank(condition.getCode())) { |
39 | - lambda.like(TkSupplierEntity::getCode, condition.getCode()); | |
39 | + wrapper.like("lower(code)", condition.getCode().toLowerCase(Locale.ROOT)); | |
40 | 40 | } |
41 | 41 | |
42 | 42 | if (StringUtils.isNotBlank(condition.getName())) { |
43 | - lambda.like(TkSupplierEntity::getName, condition.getName()); | |
43 | + wrapper.like("lower(name)", condition.getName().toLowerCase(Locale.ROOT)); | |
44 | 44 | } |
45 | 45 | |
46 | - lambda.orderByDesc(TenantBaseEntity::getCreateTime); | |
47 | - | |
46 | + wrapper.orderByDesc("create_time"); | |
48 | 47 | Page<TkSupplierEntity> page = new Page<>(); |
49 | 48 | page.setCurrent(condition.getPage()); |
50 | 49 | page.setSize(condition.getPageSize()); |
... | ... | @@ -114,7 +113,7 @@ public class TkSupplierServiceImpl extends AbstractBaseService<TkSupplierMapper, |
114 | 113 | } |
115 | 114 | |
116 | 115 | @Override |
117 | - public boolean delete(String id){ | |
116 | + public boolean delete(String id) { | |
118 | 117 | int count = baseMapper.deleteById(id); |
119 | 118 | return count > 0; |
120 | 119 | } | ... | ... |
... | ... | @@ -53,7 +53,7 @@ |
53 | 53 | AND o.tenant_id = #{queryMap.tenantId} |
54 | 54 | </if> |
55 | 55 | <if test="queryMap.code !=null and queryMap.code !=''"> |
56 | - AND o.code LIKE concat('%',#{queryMap.code}::TEXT,'%') | |
56 | + AND o.code ILIKE concat('%',#{queryMap.code}::TEXT,'%') | |
57 | 57 | </if> |
58 | 58 | <if test="queryMap.status !=null and queryMap.status !=''"> |
59 | 59 | AND o.status = #{queryMap.status} | ... | ... |