Showing
12 changed files
with
88 additions
and
38 deletions
... | ... | @@ -62,7 +62,7 @@ public class TkPreserveRecordController extends BaseController { |
62 | 62 | throw new TkDataValidationException("保养记录不存在!"); |
63 | 63 | } |
64 | 64 | |
65 | - tkPreserveRecordServcie.updateStatus(dto.getId(), dto.getPreserveStatus()); | |
65 | + tkPreserveRecordServcie.updateStatus(dto.getId(), dto.getPreserveStatus().name()); | |
66 | 66 | return ResponseEntity.ok(orderInfo); |
67 | 67 | } |
68 | 68 | ... | ... |
... | ... | @@ -91,7 +91,7 @@ public class TkRepairOrderController extends BaseController { |
91 | 91 | throws ThingsboardException { |
92 | 92 | params.put(PAGE, page); |
93 | 93 | params.put(PAGE_SIZE, pageSize); |
94 | - return tkRepairOrderService.page(getCurrentUser().getCurrentTenantId(), params); | |
94 | + return tkRepairOrderService.page(params); | |
95 | 95 | } |
96 | 96 | |
97 | 97 | @PostMapping("/updateStatus") | ... | ... |
... | ... | @@ -6,6 +6,7 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; |
6 | 6 | import io.swagger.annotations.ApiModelProperty; |
7 | 7 | import lombok.Data; |
8 | 8 | import lombok.EqualsAndHashCode; |
9 | +import org.thingsboard.server.common.data.yunteng.enums.PreserveRecordStatusEnum; | |
9 | 10 | |
10 | 11 | import java.time.LocalDateTime; |
11 | 12 | |
... | ... | @@ -27,7 +28,7 @@ public class TkPreserveRecordDTO extends TenantDTO { |
27 | 28 | private String preserveBy; |
28 | 29 | |
29 | 30 | @ApiModelProperty(value = "状态(INCOMPLETE未完成,COMPLETE已完成)") |
30 | - private String preserveStatus; | |
31 | + private PreserveRecordStatusEnum preserveStatus; | |
31 | 32 | |
32 | 33 | @ApiModelProperty(value = "保养人员姓名") |
33 | 34 | private String preserveByName; | ... | ... |
... | ... | @@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.entities; |
3 | 3 | import com.baomidou.mybatisplus.annotation.TableName; |
4 | 4 | import lombok.Data; |
5 | 5 | import lombok.EqualsAndHashCode; |
6 | +import org.thingsboard.server.common.data.yunteng.enums.PreserveRecordStatusEnum; | |
6 | 7 | import org.thingsboard.server.dao.model.ModelConstants; |
7 | 8 | |
8 | 9 | import java.time.LocalDateTime; |
... | ... | @@ -18,5 +19,5 @@ public class TkPreserveRecordEntity extends TenantBaseEntity { |
18 | 19 | private String preservePlanId; |
19 | 20 | private LocalDateTime preserveDate; |
20 | 21 | private String preserveBy; |
21 | - private String preserveStatus; | |
22 | + private PreserveRecordStatusEnum preserveStatus; | |
22 | 23 | } | ... | ... |
... | ... | @@ -130,7 +130,7 @@ public class TkPreserveDetailServiceImpl extends AbstractBaseService<TkPreserveD |
130 | 130 | @Override |
131 | 131 | public List<TkPreserveDetailDTO> listByPlanId(String planId) throws ThingsboardException { |
132 | 132 | if (StringUtils.isBlank(planId)) { |
133 | - throw new TkDataValidationException("方案id不能为空!"); | |
133 | + throw new TkDataValidationException("计划id不能为空!"); | |
134 | 134 | } |
135 | 135 | QueryWrapper<TkPreserveDetailEntity> wrapper = new QueryWrapper<>(); |
136 | 136 | LambdaQueryWrapper<TkPreserveDetailEntity> lambda = wrapper.lambda(); |
... | ... | @@ -163,6 +163,24 @@ public class TkPreserveDetailServiceImpl extends AbstractBaseService<TkPreserveD |
163 | 163 | } |
164 | 164 | |
165 | 165 | @Override |
166 | + public List<String> getPlanIdByDeviceId(String deviceId) throws ThingsboardException { | |
167 | + if (StringUtils.isBlank(deviceId)) { | |
168 | + throw new TkDataValidationException("设备id不能为空!"); | |
169 | + } | |
170 | + QueryWrapper<TkPreserveDetailEntity> wrapper = new QueryWrapper<>(); | |
171 | + LambdaQueryWrapper<TkPreserveDetailEntity> lambda = wrapper.lambda(); | |
172 | + TenantId tenantId = SpringBeanUtils.getTenantId(); | |
173 | + lambda.eq(TkPreserveDetailEntity::getTenantId, tenantId.getId().toString()); | |
174 | + lambda.eq(TkPreserveDetailEntity::getDeviceId, deviceId); | |
175 | + List<TkPreserveDetailEntity> entities = baseMapper.selectList(wrapper); | |
176 | + if (CollectionUtils.isNotEmpty(entities)) { | |
177 | + return entities.stream().map(TkPreserveDetailEntity::getPreservePlanId).distinct().collect(Collectors.toList()); | |
178 | + } else { | |
179 | + return null; | |
180 | + } | |
181 | + } | |
182 | + | |
183 | + @Override | |
166 | 184 | public void updateStatus(String id, String status) throws ThingsboardException { |
167 | 185 | TkPreserveDetailEntity entity = baseMapper.selectById(id); |
168 | 186 | if (entity == null) { | ... | ... |
... | ... | @@ -20,10 +20,7 @@ import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; |
20 | 20 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
21 | 21 | import org.thingsboard.server.dao.yunteng.entities.TkPreserveRecordEntity; |
22 | 22 | import org.thingsboard.server.dao.yunteng.mapper.TkPreserveRecordMapper; |
23 | -import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
24 | -import org.thingsboard.server.dao.yunteng.service.TkPreservePlanService; | |
25 | -import org.thingsboard.server.dao.yunteng.service.TkPreserveRecordServcie; | |
26 | -import org.thingsboard.server.dao.yunteng.service.TkUserService; | |
23 | +import org.thingsboard.server.dao.yunteng.service.*; | |
27 | 24 | |
28 | 25 | import java.util.HashMap; |
29 | 26 | import java.util.List; |
... | ... | @@ -37,7 +34,7 @@ import java.util.stream.Collectors; |
37 | 34 | public class TkPreserveRecordServcieImpl extends AbstractBaseService<TkPreserveRecordMapper, TkPreserveRecordEntity> |
38 | 35 | implements TkPreserveRecordServcie { |
39 | 36 | |
40 | - private final TkUserService tkUserService; | |
37 | + private final TkPreserveDetailService tkPreserveDetailService; | |
41 | 38 | |
42 | 39 | @Override |
43 | 40 | public TkPageData<TkPreserveRecordDTO> page(Map<String, Object> params) throws ThingsboardException { |
... | ... | @@ -47,6 +44,14 @@ public class TkPreserveRecordServcieImpl extends AbstractBaseService<TkPreserveR |
47 | 44 | IPage<TkPreserveRecordEntity> page = |
48 | 45 | getPage(params, "create_time", false); |
49 | 46 | |
47 | + Object deviceId = params.get("deviceId"); | |
48 | + if (deviceId != null && StringUtils.isNotBlank(deviceId.toString())) { | |
49 | + List<String> planIdList = tkPreserveDetailService.getPlanIdByDeviceId(deviceId.toString()); | |
50 | + if (CollectionUtils.isNotEmpty(planIdList)) { | |
51 | + params.put("planIdList", planIdList); | |
52 | + } | |
53 | + } | |
54 | + | |
50 | 55 | IPage<TkPreserveRecordDTO> pageData = baseMapper.getPreserveRecordPage(page, params); |
51 | 56 | if (pageData != null) { |
52 | 57 | result.setItems(pageData.getRecords()); |
... | ... | @@ -91,8 +96,8 @@ public class TkPreserveRecordServcieImpl extends AbstractBaseService<TkPreserveR |
91 | 96 | dto.setTenantId(SpringBeanUtils.getTenantId().getId().toString()); |
92 | 97 | } |
93 | 98 | |
94 | - if (StringUtils.isBlank(dto.getPreserveStatus())) { | |
95 | - dto.setPreserveStatus(PreserveRecordStatusEnum.INCOMPLETE.name()); | |
99 | + if (dto.getPreserveStatus() != null) { | |
100 | + dto.setPreserveStatus(PreserveRecordStatusEnum.INCOMPLETE); | |
96 | 101 | } |
97 | 102 | } |
98 | 103 | |
... | ... | @@ -126,11 +131,11 @@ public class TkPreserveRecordServcieImpl extends AbstractBaseService<TkPreserveR |
126 | 131 | if (entity == null) { |
127 | 132 | throw new TkDataValidationException("保养记录不存在!"); |
128 | 133 | } |
129 | - PreservePlanStatusEnum statusEnum = PreservePlanStatusEnum.valueOf(status); | |
134 | + PreserveRecordStatusEnum statusEnum = PreserveRecordStatusEnum.valueOf(status); | |
130 | 135 | if (statusEnum == null) { |
131 | 136 | throw new TkDataValidationException("保养记录状态不存在!"); |
132 | 137 | } |
133 | - entity.setPreserveStatus(statusEnum.name()); | |
138 | + entity.setPreserveStatus(statusEnum); | |
134 | 139 | LambdaQueryWrapper<TkPreserveRecordEntity> filter = new QueryWrapper<TkPreserveRecordEntity>().lambda() |
135 | 140 | .eq(TkPreserveRecordEntity::getId, entity.getId()); |
136 | 141 | baseMapper.update(entity, filter); | ... | ... |
... | ... | @@ -13,6 +13,7 @@ import org.thingsboard.server.common.data.id.TenantId; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
15 | 15 | import org.thingsboard.server.common.data.yunteng.dto.TkDeviceAccountDTO; |
16 | +import org.thingsboard.server.common.data.yunteng.dto.TkPreserveRecordDTO; | |
16 | 17 | import org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO; |
17 | 18 | import org.thingsboard.server.common.data.yunteng.enums.RepairOrderStatusEnum; |
18 | 19 | import org.thingsboard.server.common.data.yunteng.utils.SpringBeanUtils; |
... | ... | @@ -28,6 +29,7 @@ import org.thingsboard.server.dao.yunteng.service.TkRepairOrderService; |
28 | 29 | import java.time.LocalDateTime; |
29 | 30 | import java.util.HashMap; |
30 | 31 | import java.util.Map; |
32 | +import java.util.Optional; | |
31 | 33 | import java.util.UUID; |
32 | 34 | |
33 | 35 | @Service |
... | ... | @@ -41,12 +43,15 @@ public class TkRepairOrderServiceImpl extends AbstractBaseService<TkRepairOrderM |
41 | 43 | private final TkDeviceAccountService tkDeviceAccountService; |
42 | 44 | |
43 | 45 | @Override |
44 | - public TkPageData<TkRepairOrderDTO> page(String tenantId, Map<String, Object> params) throws ThingsboardException { | |
46 | + public TkPageData<TkRepairOrderDTO> page(Map<String, Object> params) throws ThingsboardException { | |
45 | 47 | params.put("tenantId", SpringBeanUtils.getTenantId().getId().toString()); |
46 | 48 | TkPageData<TkRepairOrderDTO> result = new TkPageData<>(); |
47 | 49 | IPage<TkRepairOrderEntity> page = |
48 | 50 | getPage(params, "create_time", false); |
49 | - | |
51 | + Object emergency = params.get("emergency"); | |
52 | + if (emergency != null && StringUtils.isBlank(emergency.toString())) { | |
53 | + params.remove("emergency"); | |
54 | + } | |
50 | 55 | IPage<TkRepairOrderDTO> pageData = baseMapper.getRepairOrderPage(page, params); |
51 | 56 | if (pageData != null) { |
52 | 57 | result.setItems(pageData.getRecords()); |
... | ... | @@ -79,19 +84,15 @@ public class TkRepairOrderServiceImpl extends AbstractBaseService<TkRepairOrderM |
79 | 84 | |
80 | 85 | @Override |
81 | 86 | public TkRepairOrderDTO detail(String id) throws ThingsboardException { |
82 | - TkRepairOrderDTO detail = new TkRepairOrderDTO(); | |
83 | - TkRepairOrderEntity entity = baseMapper.selectById(id); | |
84 | - if (entity == null) { | |
85 | - throw new TkDataValidationException("数据不存在!"); | |
86 | - } | |
87 | - entity.copyToDTO(detail); | |
88 | - String deviceId = entity.getDeviceId(); | |
89 | - if (StringUtils.isNotBlank(deviceId)) { | |
90 | - TkDeviceAccountDTO deviceDTO = tkDeviceAccountService.load(deviceId); | |
91 | - detail.setDeviceInfo(deviceDTO); | |
87 | + Map<String, Object> params = new HashMap<>(); | |
88 | + params.put("id", id); | |
89 | + TkPageData<TkRepairOrderDTO> page = page(params); | |
90 | + if (page != null && CollectionUtils.isNotEmpty(page.getItems())) { | |
91 | + Optional<TkRepairOrderDTO> first = page.getItems().stream().findFirst(); | |
92 | + return first.get(); | |
93 | + } else { | |
94 | + return null; | |
92 | 95 | } |
93 | - | |
94 | - return detail; | |
95 | 96 | } |
96 | 97 | |
97 | 98 | @Override | ... | ... |
... | ... | @@ -24,5 +24,7 @@ public interface TkPreserveDetailService extends BaseService<TkPreserveDetailEnt |
24 | 24 | |
25 | 25 | List<TkPreserveDetailDTO> listByPlanId(String planId) throws ThingsboardException; |
26 | 26 | |
27 | + List<String> getPlanIdByDeviceId(String deviceId) throws ThingsboardException; | |
28 | + | |
27 | 29 | void updateStatus(String id, String status) throws ThingsboardException; |
28 | 30 | } | ... | ... |
... | ... | @@ -10,7 +10,7 @@ import java.util.Map; |
10 | 10 | |
11 | 11 | public interface TkRepairOrderService extends BaseService<TkRepairOrderEntity> { |
12 | 12 | |
13 | - TkPageData<TkRepairOrderDTO> page(String tenantId,Map<String, Object> params) throws ThingsboardException; | |
13 | + TkPageData<TkRepairOrderDTO> page(Map<String, Object> params) throws ThingsboardException; | |
14 | 14 | |
15 | 15 | TkRepairOrderDTO save(TkRepairOrderDTO dto) throws ThingsboardException; |
16 | 16 | ... | ... |
... | ... | @@ -2,6 +2,12 @@ |
2 | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
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 | + <result property="id" column="id"/> | |
6 | + <result property="preservePlanId" column="preserve_plan_id"/> | |
7 | + <result property="preserveDate" column="preserve_date"/> | |
8 | + <result property="preserveBy" column="preserve_by"/> | |
9 | + <result property="preserveStatus" column="preserve_status" | |
10 | + typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | |
5 | 11 | <result property="preserveByName" column="preserveByName"/> |
6 | 12 | <result property="preservePlanName" column="preserveName"/> |
7 | 13 | </resultMap> |
... | ... | @@ -14,27 +20,34 @@ |
14 | 20 | inner join sys_user su on su.id=r.preserve_by |
15 | 21 | inner join qg_preserve_plan p on p.id=r.preserve_plan_id |
16 | 22 | <where> |
17 | - <if test="queryMap.id !=null "> | |
23 | + <if test="queryMap.id !=null and queryMap.id !=''"> | |
18 | 24 | AND r.id = #{queryMap.id} |
19 | 25 | </if> |
20 | - <if test="queryMap.tenantId !=null "> | |
26 | + <if test="queryMap.tenantId !=null and queryMap.tenantId !=''"> | |
21 | 27 | AND r.tenant_id = #{queryMap.tenantId} |
22 | 28 | </if> |
23 | - <if test="queryMap.preserve_plan_id !=null "> | |
29 | + <if test="queryMap.preserve_plan_id !=null and queryMap.preserve_plan_id !=''"> | |
24 | 30 | AND r.status = #{queryMap.preservePlanId} |
25 | 31 | </if> |
26 | - <if test="queryMap.preserve_by !=null "> | |
32 | + <if test="queryMap.preserve_by !=null and queryMap.preserve_by !=''"> | |
27 | 33 | AND r.device_id = #{queryMap.preserveBy} |
28 | 34 | </if> |
29 | - <if test="queryMap.preserve_status !=null "> | |
35 | + <if test="queryMap.preserve_status !=null and queryMap.preserve_status !=''"> | |
30 | 36 | AND r.emergency = #{queryMap.preserveStatus} |
31 | 37 | </if> |
32 | - <if test="queryMap.startDate !=null "> | |
38 | + <if test="queryMap.startDate !=null and queryMap.startDate !=''"> | |
33 | 39 | AND to_char(r.preserve_date, 'YYYY-MM-DD HH24:MI:SS') >= #{queryMap.startDate} |
34 | 40 | </if> |
35 | - <if test="queryMap.endDate !=null "> | |
41 | + <if test="queryMap.endDate !=null and queryMap.endDate !=''"> | |
36 | 42 | AND to_char(r.preserve_date, 'YYYY-MM-DD HH24:MI:SS') <= #{queryMap.endDate} |
37 | 43 | </if> |
44 | + <if test="queryMap.planIdList !=null"> | |
45 | + AND r.preserve_plan_id in | |
46 | + <foreach collection="queryMap.planIdList" item="item" index="index" | |
47 | + separator="," open="(" close=")"> | |
48 | + #{item} | |
49 | + </foreach> | |
50 | + </if> | |
38 | 51 | </where> |
39 | 52 | </select> |
40 | 53 | </mapper> |
\ No newline at end of file | ... | ... |
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | |
4 | 4 | <mapper namespace="org.thingsboard.server.dao.yunteng.mapper.TkRepairOrderMapper"> |
5 | 5 | <resultMap type="org.thingsboard.server.common.data.yunteng.dto.TkRepairOrderDTO" id="repairOrderMap"> |
6 | + <result property="id" column="id"/> | |
6 | 7 | <result property="orderCode" column="order_code"/> |
7 | 8 | <result property="deviceId" column="device_id"/> |
8 | 9 | <result property="reportDate" column="report_date"/> |
... | ... | @@ -37,6 +38,7 @@ |
37 | 38 | <result property="registeDate" column="registe_date"/> |
38 | 39 | <result property="supplierId" column="supplier_id"/> |
39 | 40 | <result property="description" column="daDescription"/> |
41 | + <result property="directorName" column="directorName"/> | |
40 | 42 | </association> |
41 | 43 | </resultMap> |
42 | 44 | <select id="getRepairOrderPage" resultMap="repairOrderMap"> |
... | ... | @@ -44,12 +46,16 @@ |
44 | 46 | o.id,o.device_id,o.order_code,o.report_date,o.report_by,o.status,o.emergency,o.situation_img,o.description, |
45 | 47 | da.name as daName,da.code as daCode,da.category_id,da.status as daStatus,da.director_id,da.is_online, |
46 | 48 | da.brand,da.model_num,da.specifications,da.manufacturer,da.buy_date,da.price,da.product_date, |
47 | - da.receive_date,da.registe_date,da.supplier_id,da.device_img,da.description as daDescription, | |
49 | + da.receive_date,da.registe_date,da.supplier_id,da.device_img,da.description as daDescription,su2.real_name as directorName, | |
48 | 50 | o.tenant_id,o.create_time,o.updater,o.update_time,o.creator,su.real_name as reportByName |
49 | 51 | from qg_repair_order o |
50 | 52 | inner join sys_user su on su.id=o.report_by |
51 | 53 | inner join qg_device_account da on da.id=o.device_id |
54 | + inner join sys_user su2 on su2.id=da.director_id | |
52 | 55 | <where> |
56 | + <if test="queryMap.id !=null "> | |
57 | + AND o.id = #{queryMap.id} | |
58 | + </if> | |
53 | 59 | <if test="queryMap.tenantId !=null and queryMap.tenantId !=''"> |
54 | 60 | AND o.tenant_id = #{queryMap.tenantId} |
55 | 61 | </if> |
... | ... | @@ -59,7 +65,7 @@ |
59 | 65 | <if test="queryMap.deviceId !=null and queryMap.deviceId !=''"> |
60 | 66 | AND o.device_id = #{queryMap.deviceId} |
61 | 67 | </if> |
62 | - <if test="queryMap.emergency !=null and queryMap.emergency !=''"> | |
68 | + <if test="queryMap.emergency !=null"> | |
63 | 69 | AND o.emergency = #{queryMap.emergency} |
64 | 70 | </if> |
65 | 71 | <if test="queryMap.startDate !=null and queryMap.startDate !=''"> | ... | ... |
... | ... | @@ -45,6 +45,9 @@ |
45 | 45 | <if test="queryMap.reportBy !=null and queryMap.reportBy !=''"> |
46 | 46 | AND ro.report_by = #{queryMap.reportBy} |
47 | 47 | </if> |
48 | + <if test="queryMap.deviceId !=null and queryMap.deviceId !=''"> | |
49 | + AND ro.device_id = #{queryMap.deviceId} | |
50 | + </if> | |
48 | 51 | <if test="queryMap.orderCode !=null and queryMap.orderCode !=''"> |
49 | 52 | AND ro.order_code LIKE concat('%',#{queryMap.orderCode}::TEXT,'%') |
50 | 53 | </if> | ... | ... |