2023-06-13 11:18:44 优化完善查询策略列表接口!

master
魔神煜修罗皇 2 years ago
parent c95eca8479
commit 3da70dced6
  1. 33
      psdc-business/src/main/java/com/psdc/entity/PsdcModel.java
  2. 27
      psdc-business/src/main/java/com/psdc/entity/res/PsdcSceneRes.java
  3. 32
      psdc-business/src/main/java/com/psdc/mapper/PsdcModelMapper.java
  4. 2
      psdc-business/src/main/java/com/psdc/service/IPsdcSceneService.java
  5. 108
      psdc-business/src/main/java/com/psdc/service/impl/PsdcSceneServiceImpl.java
  6. 55
      psdc-business/src/main/resources/mapper/business/PsdcModelMapper.xml
  7. 6
      psdc-business/src/main/resources/mapper/business/PsdcSceneMapper.xml
  8. 3
      psdc-web/src/main/java/com/psdc/controller/control/ManualController.java

@ -0,0 +1,33 @@
package com.psdc.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;
import java.io.Serializable;
/**
* @AuthorStone
* @Projectpsdc
* @date : 2023-6-9 09:25:14
* @Version 1.0
*/
@Data
@Component
@AllArgsConstructor
@NoArgsConstructor
public class PsdcModel implements Serializable,Cloneable {
/** 模型Id */
private Integer modelId ;
/** 模型名称 */
private String modelName ;
/** 关联域 */
private String relationField ;
/** io描述 */
private String ioDesc ;
/** io类型【serve服务;event事件,attribute属性】 */
private String ioType ;
}

@ -29,6 +29,11 @@ public class PsdcSceneRes {
private Long sceneCode; private Long sceneCode;
/** 用户id */ /** 用户id */
private Long userId; private Long userId;
/**
* 该策略是否选中
*/
private Boolean isCheck;
/** 创建时间 */ /** 创建时间 */
private String createTime ; private String createTime ;
/** 场景策略备注 */ /** 场景策略备注 */
@ -38,6 +43,15 @@ public class PsdcSceneRes {
*/ */
private List<DeviceVo> deviceVos; private List<DeviceVo> deviceVos;
/** 是否有执行判断条件【0:没有;1:有】 */
private Integer isJudge ;
/** 判断条件设备Id */
private Integer judgeDevice ;
/** 判断条件设备的元素 */
private String judgeElement ;
/** 判断条件元素的数据值 */
private String judgeData ;
public PsdcSceneRes(Integer sceneId, String sceneName, Long sceneCode, Long userId, String createTime, String sceneRemark) { public PsdcSceneRes(Integer sceneId, String sceneName, Long sceneCode, Long userId, String createTime, String sceneRemark) {
this.sceneId = sceneId; this.sceneId = sceneId;
this.sceneName = sceneName; this.sceneName = sceneName;
@ -46,4 +60,17 @@ public class PsdcSceneRes {
this.createTime = createTime; this.createTime = createTime;
this.sceneRemark = sceneRemark; this.sceneRemark = sceneRemark;
} }
public PsdcSceneRes(Integer sceneId, String sceneName, Long sceneCode, Long userId, String createTime, String sceneRemark, Integer isJudge, Integer judgeDevice, String judgeElement, String judgeData) {
this.sceneId = sceneId;
this.sceneName = sceneName;
this.sceneCode = sceneCode;
this.userId = userId;
this.createTime = createTime;
this.sceneRemark = sceneRemark;
this.isJudge = isJudge;
this.judgeDevice = judgeDevice;
this.judgeElement = judgeElement;
this.judgeData = judgeData;
}
} }

@ -1,5 +1,6 @@
package com.psdc.mapper; package com.psdc.mapper;
import com.psdc.entity.PsdcModel;
import com.psdc.entity.vo.ModelVo; import com.psdc.entity.vo.ModelVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -24,4 +25,35 @@ public interface PsdcModelMapper {
@Param("modelKey") String modelKey); @Param("modelKey") String modelKey);
String querySceneKeyByDesc(@Param("ioDesc") String ioDesc); String querySceneKeyByDesc(@Param("ioDesc") String ioDesc);
/**
* 新增数据
* @param psdcModel 实例对象
* @return 影响行数
*/
Boolean insertModel(PsdcModel psdcModel);
/**
* 通过主键删除数据
* @param modelId 主键
* @return 影响行数
*/
Integer deleteById(@Param("modelId") Integer modelId);
/**
* 更新数据
*
* @param psdcModel 实例对象
* @return 影响行数
*/
Boolean updateModel(PsdcModel psdcModel);
/**
* 分页查询指定行数据
* @param psdcModel 查询条件
* @return 对象列表
*/
List<PsdcModel> queryAllByLimit(PsdcModel psdcModel);
} }

@ -35,7 +35,7 @@ public interface IPsdcSceneService {
*/ */
Boolean deleteByScene(PsdcSceneRequest scene); Boolean deleteByScene(PsdcSceneRequest scene);
List<Map<String, Object>> getStrategyList(); List getStrategyList();
List<PsdcSceneRes> findSceneByUserAndSceneName(Long sceneCode); List<PsdcSceneRes> findSceneByUserAndSceneName(Long sceneCode);
} }

@ -178,31 +178,60 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
@Override @Override
public List<Map<String, Object>> getStrategyList() { public List<PsdcSceneRes> getStrategyList() {
List<String> scenes = psdcSceneMapper.querySceneGroup(SecurityUtils.getUserId()); Long userId = SecurityUtils.getUserId();
List<Map<String, Object>> collectList = scenes.stream() List<PsdcSceneRes> sceneRes = psdcSceneMapper.queryScenes(userId, null);
.map(scene -> { for (PsdcSceneRes psr : sceneRes) {
List<SceneVo> sceneVoList = psdcSceneMapper.queryBySceneName(scene); Long code = psr.getSceneCode();
Integer[] flag = {null}; List<SceneVo> listByCode = psdcSceneMapper.findSceneByUserAndSceneCode(userId, code, null);
List<Map<String, Object>> collect = sceneVoList.stream() psr.setIsCheck(false);
.filter(sceneVo -> !Objects.equals(flag[0], sceneVo.getDeviceId())) List<DeviceVo> ary = new ArrayList<>();
.peek(sceneVo -> flag[0] = sceneVo.getDeviceId()) Integer deviceId = listByCode.get(0).getDeviceId();
.map(sceneVo -> { DeviceVo deviceVo = new DeviceVo();
Map<String, Object> map1 = new HashMap<>(); List<Map> list = new ArrayList<>();
map1.put("device_name", sceneVo.getDeviceName());
map1.put("device_id", sceneVo.getDeviceId()); for (int i = 0; i < listByCode.size(); i++) {
List<SceneVo> sceneVoList1 = psdcSceneMapper.querySceneByDeviceIdAndSceneName(SecurityUtils.getUserId(), sceneVo.getDeviceId(), scene); SceneVo sv = listByCode.get(i);
map1.put("value", sceneVoList1); if (deviceId == sv.getDeviceId()) {
return map1; deviceVo.setDeviceId(sv.getDeviceId());
}) deviceVo.setDeviceName(sv.getDeviceName());
.collect(Collectors.toList()); deviceVo.setDeviceSn(sv.getDeviceSn());
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("sceneName", scene); map.put("label", sv.getSceneContext());
map.put("data", collect); map.put("value", sv.getSceneValue());
return map; list.add(map);
}) deviceVo.setTempValue(list);
.collect(Collectors.toList()); if (1 == listByCode.size() || i == listByCode.size() - 1){
return collectList; ary.add(deviceVo);
}
} else {
ary.add(deviceVo);
deviceId = sv.getDeviceId();
deviceVo = new DeviceVo();
list = new ArrayList<>();
deviceVo.setDeviceId(sv.getDeviceId());
deviceVo.setDeviceName(sv.getDeviceName());
deviceVo.setDeviceSn(sv.getDeviceSn());
if (i == listByCode.size() - 1) {
Map<String, Object> map = new HashMap<>();
map.put("label", sv.getSceneContext());
map.put("value", sv.getSceneValue());
list.add(map);
deviceVo.setTempValue(list);
ary.add(deviceVo);
} else {
Map<String, Object> map = new HashMap<>();
map.put("label", sv.getSceneContext());
map.put("value", sv.getSceneValue());
list.add(map);
deviceVo.setTempValue(list);
}
}
}
psr.setDeviceVos(ary);
}
return sceneRes;
} }
@Override @Override
@ -224,17 +253,6 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
deviceVo.setDeviceId(sv.getDeviceId()); deviceVo.setDeviceId(sv.getDeviceId());
deviceVo.setDeviceName(sv.getDeviceName()); deviceVo.setDeviceName(sv.getDeviceName());
deviceVo.setDeviceSn(sv.getDeviceSn()); deviceVo.setDeviceSn(sv.getDeviceSn());
// switch (sv.getSceneKey()) {
// case "intemp":
// deviceVo.setIntemp(sv.getSceneValue());
// break;
// case "outtemp":
// deviceVo.setOuttemp(sv.getSceneValue());
// break;
// case "temp":
// deviceVo.setTemp(sv.getSceneValue());
// break;
// }
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("label", sv.getSceneContext()); map.put("label", sv.getSceneContext());
map.put("value", sv.getSceneValue()); map.put("value", sv.getSceneValue());
@ -253,15 +271,6 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
deviceVo.setDeviceName(sv.getDeviceName()); deviceVo.setDeviceName(sv.getDeviceName());
deviceVo.setDeviceSn(sv.getDeviceSn()); deviceVo.setDeviceSn(sv.getDeviceSn());
if (i == listByCode.size() - 1) { if (i == listByCode.size() - 1) {
// 判断是否为最后1个元素
// switch (sv.getSceneKey()) {
// case "intemp":
// deviceVo.setIntemp(sv.getSceneValue());
// case "outtemp":
// deviceVo.setOuttemp(sv.getSceneValue());
// case "temp":
// deviceVo.setTemp(sv.getSceneValue());
// }
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("label", sv.getSceneContext()); map.put("label", sv.getSceneContext());
map.put("value", sv.getSceneValue()); map.put("value", sv.getSceneValue());
@ -269,17 +278,6 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
deviceVo.setTempValue(list); deviceVo.setTempValue(list);
ary.add(deviceVo); ary.add(deviceVo);
} else { } else {
// switch (sv.getSceneKey()) {
// case "intemp":
// deviceVo.setIntemp(sv.getSceneValue());
// break;
// case "outtemp":
// deviceVo.setOuttemp(sv.getSceneValue());
// break;
// case "temp":
// deviceVo.setTemp(sv.getSceneValue());
// break;
// }
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("label", sv.getSceneContext()); map.put("label", sv.getSceneContext());
map.put("value", sv.getSceneValue()); map.put("value", sv.getSceneValue());

@ -9,6 +9,60 @@
<result property="ioType" column="io_type" /> <result property="ioType" column="io_type" />
</resultMap> </resultMap>
<!--新增数据-->
<insert id="insertModel">
Insert into psdc_model(model_id, model_name, relation_field, io_desc, io_type)
Values (#{modelId}, #{modelName}, #{relationField}, #{ioDesc}, #{ioType})
</insert>
<!--通过主键删除-->
<delete id="deleteById">
Delete From psdc_model Where model_id = ${modelId}
</delete>
<!-- 更新数据 -->
<update id="updateModel">
update psdc_model
<set>
<if test="modelName != null and modelName != ''">
model_name = #{modelName},
</if>
<if test="relationField != null and relationField != ''">
relation_field = #{relationField},
</if>
<if test="ioDesc != null and ioDesc != ''">
io_desc = #{ioDesc},
</if>
<if test="ioType != null and ioType != ''">
io_type = #{ioType},
</if>
</set>
Where model_id = ${modelId}
</update>
<select id="queryAllByLimit" resultMap="PsdcModelMap">
Select
model_id,model_name,relation_field,io_desc,io_type
From psdc_model
<where>
<if test="modelId != null and modelId != ''">
and model_id = #{modelId}
</if>
<if test="modelName != null and modelName != ''">
and model_name = #{modelName}
</if>
<if test="relationField != null and relationField != ''">
and relation_field = #{relationField}
</if>
<if test="ioDesc != null and ioDesc != ''">
and io_desc = #{ioDesc}
</if>
<if test="ioType != null and ioType != ''">
and io_type = #{ioType}
</if>
</where>
</select>
<!-- 通过model_name查询数据 --> <!-- 通过model_name查询数据 -->
<select id="selDevIsControlByModelName" resultMap="PsdcModelMap"> <select id="selDevIsControlByModelName" resultMap="PsdcModelMap">
Select Select
@ -25,4 +79,5 @@
<select id="querySceneKeyByDesc" resultType="java.lang.String"> <select id="querySceneKeyByDesc" resultType="java.lang.String">
Select relation_field From psdc_model WHERE io_desc = #{ioDesc} Group By relation_field Select relation_field From psdc_model WHERE io_desc = #{ioDesc} Group By relation_field
</select> </select>
</mapper> </mapper>

@ -38,6 +38,10 @@
<result property="userId" column="user_id"/> <result property="userId" column="user_id"/>
<result property="sceneRemark" column="scene_remark" /> <result property="sceneRemark" column="scene_remark" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="isJudge" column="is_judge" />
<result property="judgeDevice" column="judge_device" />
<result property="judgeElement" column="judge_element" />
<result property="judgeData" column="judge_data" />
</resultMap> </resultMap>
<!-- 通过ID查询单条数据 --> <!-- 通过ID查询单条数据 -->
@ -201,7 +205,7 @@
</select> </select>
<select id="queryScenes" resultMap="SceneResMap"> <select id="queryScenes" resultMap="SceneResMap">
Select ps.scene_id,ps.scene_name,ps.scene_code,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value, Select ps.scene_id,ps.scene_name,ps.scene_code,ps.user_id,is_judge,judge_device,judge_element,judge_data,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value,
ps.scene_remark,ps.create_by,ps.create_time ps.scene_remark,ps.create_by,ps.create_time
From psdc_scene ps From psdc_scene ps
Left join sys_user su On su.user_id = ps.user_id Left join sys_user su On su.user_id = ps.user_id

@ -93,8 +93,7 @@ public class ManualController extends BaseController {
@PreAuthorize("@ss.hasPermi('control:manual:strategy')") @PreAuthorize("@ss.hasPermi('control:manual:strategy')")
@GetMapping("/strategyList") @GetMapping("/strategyList")
public AjaxResult getStrategyList(){ public AjaxResult getStrategyList(){
List<Map<String, Object>> strategyList = psdcSceneService.getStrategyList(); return AjaxResult.success(psdcSceneService.getStrategyList());
return AjaxResult.success(strategyList);
} }

Loading…
Cancel
Save