Commit 78dbe0d9e5869c661e202abe714b737cccde401f

Authored by 胡翰林
1 parent d733eea5

接口联调修改

... ... @@ -11,10 +11,12 @@ import org.springframework.web.bind.annotation.*;
11 11 import org.thingsboard.server.common.data.exception.ThingsboardException;
12 12 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
13 13 import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
  14 +import org.thingsboard.server.common.data.yunteng.dto.TkDeviceAccountDTO;
14 15 import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO;
15 16 import org.thingsboard.server.common.data.yunteng.enums.RepairOrderStatusEnum;
16 17 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
17 18 import org.thingsboard.server.controller.BaseController;
  19 +import org.thingsboard.server.dao.yunteng.service.TkDeviceAccountService;
18 20 import org.thingsboard.server.dao.yunteng.service.TkDeviceService;
19 21 import org.thingsboard.server.dao.yunteng.service.TkRepairOrderService;
20 22 import org.thingsboard.server.queue.util.TbCoreComponent;
... ... @@ -35,7 +37,7 @@ public class TkRepairOrderController extends BaseController {
35 37
36 38 private final TkRepairOrderService tkRepairOrderService;
37 39
38   - private final TkDeviceService tkdeviceService;
  40 + private final TkDeviceAccountService tkDeviceAccountService;
39 41
40 42 @PostMapping("/save")
41 43 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
... ... @@ -44,8 +46,7 @@ public class TkRepairOrderController extends BaseController {
44 46 String currentTenantId = getCurrentUser().getCurrentTenantId();
45 47 dto.setTenantId(currentTenantId);
46 48 if (StringUtils.isNotBlank(dto.getDeviceId())) {
47   - DeviceDTO deviceInfo = tkdeviceService.checkDeviceByTenantIdAndDeviceId
48   - (UUID.fromString(currentTenantId), UUID.fromString(dto.getDeviceId()));
  49 + TkDeviceAccountDTO deviceInfo = tkDeviceAccountService.load(dto.getDeviceId());
49 50 if (deviceInfo == null) {
50 51 throw new TkDataValidationException("设备不存在!");
51 52 }
... ...
... ... @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 5 import com.baomidou.mybatisplus.core.metadata.IPage;
6 6 import lombok.RequiredArgsConstructor;
7 7 import lombok.extern.slf4j.Slf4j;
  8 +import org.apache.commons.collections4.CollectionUtils;
8 9 import org.apache.commons.lang3.StringUtils;
9 10 import org.springframework.stereotype.Service;
10 11 import org.thingsboard.server.common.data.exception.ThingsboardException;
... ... @@ -17,11 +18,13 @@ import org.thingsboard.server.common.data.yunteng.dto.UserDTO;
17 18 import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils;
18 19 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
19 20 import org.thingsboard.server.dao.yunteng.entities.TkDeviceAccountEntity;
  21 +import org.thingsboard.server.dao.yunteng.entities.TkPreserveDetailEntity;
20 22 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceAccountMapper;
21 23 import org.thingsboard.server.dao.yunteng.service.*;
22 24
23 25 import java.util.List;
24 26 import java.util.Map;
  27 +import java.util.stream.Collectors;
25 28
26 29 @Service
27 30 @RequiredArgsConstructor
... ... @@ -135,6 +138,24 @@ public class TkDeviceAccountServiceImpl extends AbstractBaseService<TkDeviceAcco
135 138 }
136 139
137 140 @Override
  141 + public List<String> getIdByDeviceName(String deviceName) throws ThingsboardException {
  142 + if (StringUtils.isBlank(deviceName)) {
  143 + throw new TkDataValidationException("设备名称不能为空!");
  144 + }
  145 + QueryWrapper<TkDeviceAccountEntity> wrapper = new QueryWrapper<>();
  146 + LambdaQueryWrapper<TkDeviceAccountEntity> lambda = wrapper.lambda();
  147 + TenantId tenantId = SpringBeanUtils.getTenantId();
  148 + lambda.eq(TkDeviceAccountEntity::getTenantId, tenantId.getId().toString());
  149 + lambda.like(TkDeviceAccountEntity::getName, deviceName);
  150 + List<TkDeviceAccountEntity> entities = baseMapper.selectList(wrapper);
  151 + if (CollectionUtils.isNotEmpty(entities)) {
  152 + return entities.stream().map(TkDeviceAccountEntity::getId).distinct().collect(Collectors.toList());
  153 + } else {
  154 + return null;
  155 + }
  156 + }
  157 +
  158 + @Override
138 159 public boolean delete(String id) {
139 160 int count = baseMapper.deleteById(id);
140 161 return count > 0;
... ...
... ... @@ -38,6 +38,8 @@ public class TkPreserveDetailServiceImpl extends AbstractBaseService<TkPreserveD
38 38
39 39 private final TkCheckPlanService tkCheckPlanService;
40 40
  41 + private final TkDeviceAccountService tkDeviceAccountService;
  42 +
41 43 @Override
42 44 public TkPageData<TkPreserveDetailDTO> page(Map<String, Object> params) throws ThingsboardException {
43 45 params.put("tenantId", SpringBeanUtils.getTenantId().getId().toString());
... ... @@ -181,6 +183,30 @@ public class TkPreserveDetailServiceImpl extends AbstractBaseService<TkPreserveD
181 183 }
182 184
183 185 @Override
  186 + public List<String> getPlanIdByDeviceName(String deviceName) throws ThingsboardException {
  187 + if (StringUtils.isBlank(deviceName)) {
  188 + throw new TkDataValidationException("设备名称不能为空!");
  189 + }
  190 +
  191 + List<String> deviceIdList = tkDeviceAccountService.getIdByDeviceName(deviceName);
  192 + if (CollectionUtils.isEmpty(deviceIdList)) {
  193 + return null;
  194 + }
  195 +
  196 + QueryWrapper<TkPreserveDetailEntity> wrapper = new QueryWrapper<>();
  197 + LambdaQueryWrapper<TkPreserveDetailEntity> lambda = wrapper.lambda();
  198 + TenantId tenantId = SpringBeanUtils.getTenantId();
  199 + lambda.eq(TkPreserveDetailEntity::getTenantId, tenantId.getId().toString());
  200 + lambda.in(TkPreserveDetailEntity::getDeviceId, deviceIdList);
  201 + List<TkPreserveDetailEntity> entities = baseMapper.selectList(wrapper);
  202 + if (CollectionUtils.isNotEmpty(entities)) {
  203 + return entities.stream().map(TkPreserveDetailEntity::getPreservePlanId).distinct().collect(Collectors.toList());
  204 + } else {
  205 + return null;
  206 + }
  207 + }
  208 +
  209 + @Override
184 210 public void updateStatus(String id, String status) throws ThingsboardException {
185 211 TkPreserveDetailEntity entity = baseMapper.selectById(id);
186 212 if (entity == null) {
... ...
... ... @@ -50,6 +50,10 @@ public class TkPreservePlanServiceImpl extends AbstractBaseService<TkPreservePla
50 50 lambda.like(TkPreservePlanEntity::getPreserveName, condition.getPreserveName());
51 51 }
52 52
  53 + if (condition.getStatus() != null) {
  54 + lambda.eq(TkPreservePlanEntity::getStatus, condition.getStatus());
  55 + }
  56 +
53 57 lambda.orderByDesc(TenantBaseEntity::getCreateTime);
54 58
55 59 Page<TkPreservePlanEntity> page = new Page<>();
... ...
... ... @@ -52,6 +52,14 @@ public class TkPreserveRecordServcieImpl extends AbstractBaseService<TkPreserveR
52 52 }
53 53 }
54 54
  55 + Object deviceName = params.get("deviceName");
  56 + if (deviceName != null && StringUtils.isNotBlank(deviceName.toString())) {
  57 + List<String> planIdList = tkPreserveDetailService.getPlanIdByDeviceName(deviceName.toString());
  58 + if (CollectionUtils.isNotEmpty(planIdList)) {
  59 + params.put("planIdList", planIdList);
  60 + }
  61 + }
  62 +
55 63 IPage<TkPreserveRecordDTO> pageData = baseMapper.getPreserveRecordPage(page, params);
56 64 if (pageData != null) {
57 65 result.setItems(pageData.getRecords());
... ...
... ... @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 5 import com.baomidou.mybatisplus.core.metadata.IPage;
6 6 import lombok.RequiredArgsConstructor;
7 7 import lombok.extern.slf4j.Slf4j;
  8 +import org.apache.commons.collections4.CollectionUtils;
8 9 import org.apache.commons.lang3.StringUtils;
9 10 import org.springframework.stereotype.Service;
10 11 import org.thingsboard.server.common.data.exception.ThingsboardException;
... ... @@ -25,6 +26,7 @@ import org.thingsboard.server.dao.yunteng.service.TkUserService;
25 26 import java.time.LocalDateTime;
26 27 import java.util.HashMap;
27 28 import java.util.Map;
  29 +import java.util.Optional;
28 30
29 31 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE;
30 32 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE;
... ... @@ -97,25 +99,15 @@ public class TkRepairRecordServiceImpl extends AbstractBaseService<TkRepairRecor
97 99
98 100 @Override
99 101 public TkRepairRecordDTO detail(String id) throws ThingsboardException {
100   - TkRepairRecordDTO detail = new TkRepairRecordDTO();
101   - TkRepairRecordEntity entity = baseMapper.selectById(id);
102   - if (entity == null) {
103   - throw new TkDataValidationException("数据不存在!");
104   - }
105   - entity.copyToDTO(detail);
106   - String orderId = entity.getOrderId();
107   - if (StringUtils.isNotBlank(orderId)) {
108   - TkRepairOrderDTO repairOrderDTO = tkRepairOrderService.load(orderId);
109   - if (StringUtils.isNotBlank(repairOrderDTO.getReportBy())) {
110   - UserDTO reportInfo = tkUserService.findUserInfoById(repairOrderDTO.getReportBy());
111   - repairOrderDTO.setReportByName(reportInfo.getRealName());
112   - }
113   - detail.setTkRepairOrderDTO(repairOrderDTO);
  102 + Map<String, Object> params = new HashMap<>();
  103 + params.put("id", id);
  104 + TkPageData<TkRepairRecordDTO> page = page(params);
  105 + if (page != null && CollectionUtils.isNotEmpty(page.getItems())) {
  106 + Optional<TkRepairRecordDTO> first = page.getItems().stream().findFirst();
  107 + return first.get();
  108 + } else {
  109 + return null;
114 110 }
115   - UserDTO userInfo = tkUserService.findUserInfoById(detail.getRepairBy());
116   - detail.setRepairName(userInfo.getRealName());
117   -
118   - return detail;
119 111 }
120 112
121 113 @Override
... ...
... ... @@ -5,6 +5,7 @@ import org.thingsboard.server.common.data.yunteng.dto.TkDeviceAccountDTO;
5 5 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
6 6 import org.thingsboard.server.dao.yunteng.entities.TkDeviceAccountEntity;
7 7
  8 +import java.util.List;
8 9 import java.util.Map;
9 10
10 11 public interface TkDeviceAccountService extends BaseService<TkDeviceAccountEntity> {
... ... @@ -16,6 +17,8 @@ public interface TkDeviceAccountService extends BaseService<TkDeviceAccountEntit
16 17
17 18 TkDeviceAccountDTO load(String id) throws ThingsboardException;
18 19
  20 + List<String> getIdByDeviceName(String deviceName) throws ThingsboardException;
  21 +
19 22 boolean delete(String id);
20 23
21 24 }
... ...
... ... @@ -26,5 +26,7 @@ public interface TkPreserveDetailService extends BaseService<TkPreserveDetailEnt
26 26
27 27 List<String> getPlanIdByDeviceId(String deviceId) throws ThingsboardException;
28 28
  29 + List<String> getPlanIdByDeviceName(String deviceName) throws ThingsboardException;
  30 +
29 31 void updateStatus(String id, String status) throws ThingsboardException;
30 32 }
... ...
... ... @@ -46,7 +46,7 @@
46 46 o.tenant_id,o.create_time,o.updater,o.update_time,o.creator,su.real_name as directorName
47 47 from qg_device_account o
48 48 inner join sys_user su on su.id=o.director_id
49   - inner join qg_supplier sp on sp.id=o.supplier_id
  49 + left join qg_supplier sp on sp.id=o.supplier_id
50 50 inner join qg_device_cagegory dc on dc.id=o.category_id
51 51 <where>
52 52 <if test="queryMap.tenantId !=null and queryMap.tenantId !=''">
... ...
... ... @@ -3,6 +3,7 @@
3 3 <mapper namespace="org.thingsboard.server.dao.yunteng.mapper.TkPreserveRecordMapper">
4 4 <resultMap type="org.thingsboard.server.common.data.yunteng.dto.TkPreserveRecordDTO" id="preserveRecordMap">
5 5 <result property="id" column="id"/>
  6 + <result property="recordCode" column="record_code"/>
6 7 <result property="preservePlanId" column="preserve_plan_id"/>
7 8 <result property="preserveDate" column="preserve_date"/>
8 9 <result property="preserveBy" column="preserve_by"/>
... ... @@ -13,7 +14,7 @@
13 14 </resultMap>
14 15 <select id="getPreserveRecordPage" resultMap="preserveRecordMap">
15 16 SELECT
16   - r.record_code,r.preserve_plan_id,r.preserve_date,r.preserve_by,r.preserve_status
  17 + r.id,r.record_code,r.preserve_plan_id,r.preserve_date,r.preserve_by,r.preserve_status
17 18 ,r.tenant_id,r.create_time,r.updater,r.update_time,r.creator
18 19 ,su.real_name as preserveByName,p.preserve_name as preserveName
19 20 from qg_preserve_record r
... ... @@ -23,9 +24,15 @@
23 24 <if test="queryMap.id !=null and queryMap.id !=''">
24 25 AND r.id = #{queryMap.id}
25 26 </if>
  27 + <if test="queryMap.preservePlanName !=null and queryMap.preservePlanName !=''">
  28 + AND p.preserve_name LIKE concat('%',#{queryMap.preservePlanName}::TEXT,'%')
  29 + </if>
26 30 <if test="queryMap.tenantId !=null and queryMap.tenantId !=''">
27 31 AND r.tenant_id = #{queryMap.tenantId}
28 32 </if>
  33 + <if test="queryMap.preserveStatus !=null and queryMap.preserveStatus !=''">
  34 + AND r.preserve_status = #{queryMap.preserveStatus}
  35 + </if>
29 36 <if test="queryMap.preserve_plan_id !=null and queryMap.preserve_plan_id !=''">
30 37 AND r.status = #{queryMap.preservePlanId}
31 38 </if>
... ...
... ... @@ -40,6 +40,9 @@
40 40 inner join qg_device_account da on da.id=ro.device_id
41 41 inner join qg_malfunction_reason mr on mr.id=rr.malfunction_reason_id
42 42 <where>
  43 + <if test="queryMap.id !=null and queryMap.id !=''">
  44 + AND rr.id = #{queryMap.id}
  45 + </if>
43 46 <if test="queryMap.tenantId !=null and queryMap.tenantId !=''">
44 47 AND rr.tenant_id = #{queryMap.tenantId}
45 48 </if>
... ... @@ -55,6 +58,9 @@
55 58 <if test="queryMap.deviceId !=null and queryMap.deviceId !=''">
56 59 AND ro.device_id = #{queryMap.deviceId}
57 60 </if>
  61 + <if test="queryMap.deviceName !=null and queryMap.deviceName !=''">
  62 + AND da.name LIKE concat('%',#{queryMap.deviceName}::TEXT,'%')
  63 + </if>
58 64 <if test="queryMap.orderCode !=null and queryMap.orderCode !=''">
59 65 AND ro.order_code LIKE concat('%',#{queryMap.orderCode}::TEXT,'%')
60 66 </if>
... ...