SmartTemplateParamServiceImpl.java
4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.glsx.smart.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glsx.smart.constant.Constants;
import com.glsx.smart.dao.entity.SmartDeviceOrder;
import com.glsx.smart.dao.entity.SmartDeviceOrdervalue;
import com.glsx.smart.dao.entity.SmartScenceSupstatus;
import com.glsx.smart.dao.entity.SmartTemplateParam;
import com.glsx.smart.dao.mapper.*;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.service.SmartTemplateParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
@Slf4j
@Service
public class SmartTemplateParamServiceImpl implements SmartTemplateParamService {
@Resource
private SmartTemplateParamMapper templateParamMapper;
@Resource
private SmartProductTypeMapper productTypeMapper;
@Resource
private SmartDeviceOrderMapper deviceOrderMapper;
@Resource
private SmartDeviceOrdervalueMapper orderValueMapper;
@Resource
private SmartScenceSupstatusMapper supstatusMapper;
@Override
public int deleteByPrimaryKey(Long id) {
return templateParamMapper.deleteByPrimaryKey(id);
}
@Override
public int insertOrUpdate(SmartTemplateParam templateParam) {
if (templateParam.getId() == null) {
return templateParamMapper.insertSelective(templateParam);
} else {
SmartTemplateParam record = templateParamMapper.selectByPrimaryKey(
templateParam.getId());
if (record != null) {
return templateParamMapper.updateByPrimaryKeySelective(templateParam);
} else {
throw new BusinessException(ResultEnum.ID_NOT_FOUND);
}
}
}
@Override
public int insertSelective(SmartTemplateParam record) {
return templateParamMapper.insertSelective(record);
}
@Override
public List<SmartTemplateParam> getByTemplateId(Long templateId) {
List<SmartTemplateParam> templateList = templateParamMapper.getByTemplateId(templateId);
for (SmartTemplateParam data : templateList) {
JSONObject jsonObject = JSON.parseObject(data.getParamValue());
//触发条件设备状态
if(Constants.SCENE_CONDITION_STATUS.equals(data.getParamKey())){
Long orderId = jsonObject.getLong("orderId");
Long typeId = jsonObject.getLong("select");
SmartScenceSupstatus supstatus = supstatusMapper.selectByPrimaryKey(orderId);
jsonObject.put("orderName", supstatus.getSceneSupstatusValue());
jsonObject.put("productName", productTypeMapper.selectByPrimaryKey(typeId).getTypeName());
}
//执行内容设备功能
if(Constants.SCENE_CONTENT_DEVICE.equals(data.getParamKey())){
Long orderId = jsonObject.getLong("orderId");
Long typeId = jsonObject.getLong("select");
SmartDeviceOrder order = deviceOrderMapper.selectByPrimaryKey(orderId);
jsonObject.put("orderName", order.getOrderValue());
if("2".equals(order.getOrderType())){
SmartDeviceOrdervalue orderValue =
orderValueMapper.selectByPrimaryKey(jsonObject.getLong("valueId"));
jsonObject.put("valueName", orderValue.getDeviceStatusValue());
}
jsonObject.put("productName", productTypeMapper.selectByPrimaryKey(typeId).getTypeName());
}
data.setParamValue(JSON.toJSONString(jsonObject));
}
return templateList;
}
@Override
public SmartTemplateParam selectByPrimaryKey(Long id) {
return templateParamMapper.selectByPrimaryKey(id);
}
@Override
public int updateByPrimaryKeySelective(SmartTemplateParam record) {
return templateParamMapper.updateByPrimaryKeySelective(record);
}
@Override
public int updateBatchSelective(List<SmartTemplateParam> list) {
return templateParamMapper.updateBatchSelective(list);
}
@Override
public int batchInsert(List<SmartTemplateParam> list) {
return templateParamMapper.batchInsert(list);
}
}