2023-06-20 15:29:46 配合前端方面,优化完善策略管理的增、删、改查功能,现在目前基本上没有没有太大问题了!

master
魔神煜修罗皇 2 years ago
parent 4ac9a65215
commit 70c9ca73f1
  1. 4
      psdc-business/src/main/java/com/psdc/entity/request/PsdcSceneRequest.java
  2. 28
      psdc-business/src/main/java/com/psdc/entity/res/PsdcSceneRes.java
  3. 15
      psdc-business/src/main/java/com/psdc/mapper/PsdcStrategyMapper.java
  4. 5
      psdc-business/src/main/java/com/psdc/service/IPsdcSceneService.java
  5. 178
      psdc-business/src/main/java/com/psdc/service/impl/PsdcSceneServiceImpl.java
  6. 2
      psdc-business/src/main/resources/mapper/business/PsdcDeviceMapper.xml
  7. 42
      psdc-business/src/main/resources/mapper/business/PsdcStrategyMapper.xml
  8. 2
      psdc-web/src/main/java/com/psdc/controller/manager/PsdcSceneController.java

@ -24,8 +24,10 @@ public class PsdcSceneRequest {
/** 场景名 */ /** 场景名 */
private String sceneName ; private String sceneName ;
/** 策略码 */ /** 场景策略码 */
private Long sceneCode; private Long sceneCode;
/** 模式策略码 */
private Long strategyCode;
/** 用户id */ /** 用户id */
private Long userId; private Long userId;
/** 设备id */ /** 设备id */

@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @AuthorStone * @AuthorStone
@ -21,6 +22,10 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class PsdcSceneRes { public class PsdcSceneRes {
/**
* 步骤序号
*/
private Integer ID;
/** 场景值 */ /** 场景值 */
private Integer sceneId ; private Integer sceneId ;
/** 场景名称 */ /** 场景名称 */
@ -51,17 +56,22 @@ public class PsdcSceneRes {
private String judgeElement ; private String judgeElement ;
/** 判断条件元素的数据值 */ /** 判断条件元素的数据值 */
private String judgeData ; private String judgeData ;
/**
* 步骤标题
*/
private String title;
/**
* 选择设备集合
*/
private List checkedSblb;
/**
* 可控设备列表
*/
private List sblb;
public PsdcSceneRes(Integer sceneId, String sceneName, Long sceneCode, Long userId, String createTime, String sceneRemark) {
this.sceneId = sceneId;
this.sceneName = sceneName;
this.sceneCode = sceneCode;
this.userId = userId;
this.createTime = createTime;
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) { public PsdcSceneRes(Integer ID, Integer sceneId, String sceneName, Long sceneCode, Long userId, String createTime, String sceneRemark, Integer isJudge, Integer judgeDevice, String judgeElement, String judgeData) {
this.ID = ID;
this.sceneId = sceneId; this.sceneId = sceneId;
this.sceneName = sceneName; this.sceneName = sceneName;
this.sceneCode = sceneCode; this.sceneCode = sceneCode;

@ -37,4 +37,19 @@ public interface PsdcStrategyMapper {
* @return 影响行数 * @return 影响行数
*/ */
Integer insert(PsdcStrategy psdcStrategy); Integer insert(PsdcStrategy psdcStrategy);
/**
* 更新数据
*
* @param psdcStrategy 实例对象
* @return 影响行数
*/
Integer update(PsdcStrategy psdcStrategy);
/**
* 通过策略名称删除模式策略
* @param sceneCode
* @return
*/
Integer deleteByStrategyName(@Param(value = "sceneCode") Long sceneCode);
} }

@ -4,6 +4,7 @@ import com.psdc.entity.PsdcScene;
import com.psdc.entity.PsdcStrategy; import com.psdc.entity.PsdcStrategy;
import com.psdc.entity.request.PsdcSceneRequest; import com.psdc.entity.request.PsdcSceneRequest;
import com.psdc.entity.res.PsdcSceneRes; import com.psdc.entity.res.PsdcSceneRes;
import com.psdc.entity.vo.DeviceVo;
import com.psdc.entity.vo.StrategyVo; import com.psdc.entity.vo.StrategyVo;
import java.util.List; import java.util.List;
@ -25,12 +26,14 @@ public interface IPsdcSceneService {
List<StrategyVo> queryScene(Long strategyCode); List<StrategyVo> queryScene(Long strategyCode);
List selUserAllControlDevs(Long userId, List<DeviceVo> devVoList);
/** /**
* 更新数据 * 更新数据
* @param scenes 实例对象 * @param scenes 实例对象
* @return 实例对象 * @return 实例对象
*/ */
Boolean update(PsdcSceneRes scenes); Boolean update(StrategyVo scenes);
/** /**
* 通过策略名称删除数据 * 通过策略名称删除数据

@ -1,15 +1,14 @@
package com.psdc.service.impl; package com.psdc.service.impl;
import com.psdc.entity.PsdcDevice;
import com.psdc.entity.PsdcStrategy; import com.psdc.entity.PsdcStrategy;
import com.psdc.entity.request.PsdcSceneRequest; import com.psdc.entity.request.PsdcSceneRequest;
import com.psdc.entity.res.PsdcSceneRes; import com.psdc.entity.res.PsdcSceneRes;
import com.psdc.entity.vo.DeviceVo; import com.psdc.entity.vo.DeviceVo;
import com.psdc.entity.vo.ModelVo;
import com.psdc.entity.vo.SceneVo; import com.psdc.entity.vo.SceneVo;
import com.psdc.entity.vo.StrategyVo; import com.psdc.entity.vo.StrategyVo;
import com.psdc.mapper.PsdcModelMapper; import com.psdc.mapper.*;
import com.psdc.mapper.PsdcSceneMapper;
import com.psdc.mapper.PsdcStrategyMapper;
import com.psdc.mapper.SysUserMapper;
import com.psdc.service.IPsdcSceneService; import com.psdc.service.IPsdcSceneService;
import com.psdc.utils.SecurityUtils; import com.psdc.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -35,10 +34,10 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
private PsdcSceneMapper psdcSceneMapper; private PsdcSceneMapper psdcSceneMapper;
@Resource @Resource
private SysUserMapper sysUserMapper; private PsdcModelMapper psdcModelMapper;
@Resource @Resource
private PsdcModelMapper psdcModelMapper; private PsdcDeviceMapper psdcDeviceMapper;
@Resource @Resource
private PsdcStrategyMapper psdcStrategyMapper; private PsdcStrategyMapper psdcStrategyMapper;
@ -46,7 +45,6 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/** /**
* 新增数据 * 新增数据
* *
@ -60,12 +58,14 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
String userName = SecurityUtils.getUsername(); String userName = SecurityUtils.getUsername();
List<SceneVo> scenesList = new ArrayList<>(); List<SceneVo> scenesList = new ArrayList<>();
String s = null; String s = null;
for (PsdcSceneRes sc : scenes.getScenesList()){ // System.out.println("\n步骤集合: " + scenes.getScenesList() + "\n,步骤条数: " + scenes.getScenesList().size() + "\n");
for (int i = scenes.getScenesList().size() - 1; i >= 0; i--) {
Date date2 = new Date(); Date date2 = new Date();
long timestamp = getSecondTimestampTwo(date2); PsdcSceneRes sc = scenes.getScenesList().get(i);
s = timestamp + ","; long timestamp = getSecondTimestampTwo(date2) - i;
s = timestamp + "," + s;
for (DeviceVo dev : sc.getDeviceVos()) { for (DeviceVo dev : sc.getDeviceVos()) {
for (Map m : dev.getTempList()){ for (Map m : dev.getTempList()) {
String desc = (String) m.get("label"); String desc = (String) m.get("label");
String tempValue = (String) m.get("value"); String tempValue = (String) m.get("value");
String sceneKey = sceneKey(desc); String sceneKey = sceneKey(desc);
@ -77,6 +77,7 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
} }
} }
} }
s = s.substring(0, s.length() - 5);
PsdcStrategy strategy = new PsdcStrategy(userId, scenes.getStrategyName(), getSecondTimestampTwo(date), s, scenes.getStrategyInfo(), userName, sdf.format(date)); PsdcStrategy strategy = new PsdcStrategy(userId, scenes.getStrategyName(), getSecondTimestampTwo(date), s, scenes.getStrategyInfo(), userName, sdf.format(date));
try { try {
@ -105,21 +106,66 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
List<StrategyVo> ary = new ArrayList<>(); List<StrategyVo> ary = new ArrayList<>();
List<PsdcStrategy> list = psdcStrategyMapper.queryByUser(userId, strategyCode); List<PsdcStrategy> list = psdcStrategyMapper.queryByUser(userId, strategyCode);
for (PsdcStrategy srt : list){ int i = 1;
for (PsdcStrategy srt : list) {
String[] codes = srt.getScenes().split(","); String[] codes = srt.getScenes().split(",");
List<PsdcSceneRes> list2 = new ArrayList<>(); List<PsdcSceneRes> list2 = new ArrayList<>();
for (String s : codes){ for (String s : codes) {
List<PsdcSceneRes> list3 = findSceneByUserAndSceneName(Long.parseLong(s)); List<PsdcSceneRes> list3 = findSceneByUserAndSceneName(Long.parseLong(s));
if (null != list3 && list3.size() > 0){ if (null != list3 && list3.size() > 0) {
list2.add(list3.get(0)); PsdcSceneRes res = list3.get(0);
List<DeviceVo> devVoList = res.getDeviceVos();
List<Integer> ary2 = new ArrayList<>();
for (DeviceVo d : devVoList) {
ary2.add(d.getDeviceId());
}
res.setID(i);
res.setTitle("第" + i + "步");
res.setCheckedSblb(ary2);
res.setSblb(selUserAllControlDevs(userId, devVoList));
i++;
list2.add(res);
} }
} }
i = 1;
StrategyVo strategyVo = new StrategyVo(srt.getStrategyId(), userId, srt.getStrategyName(), Math.toIntExact(srt.getStrategyCode()), list2, srt.getStrategyInfo(), srt.getCreateTime()); StrategyVo strategyVo = new StrategyVo(srt.getStrategyId(), userId, srt.getStrategyName(), Math.toIntExact(srt.getStrategyCode()), list2, srt.getStrategyInfo(), srt.getCreateTime());
ary.add(strategyVo); ary.add(strategyVo);
} }
return ary; return ary;
} }
@Override
public List<Map> selUserAllControlDevs(Long userId, List<DeviceVo> devVoList) {
List<PsdcDevice> list = psdcDeviceMapper.controlQueryByUserId(userId);
List<Map> maps = new ArrayList<>();
for (PsdcDevice dev : list) {
Map<String, Object> map = new HashMap<>();
map.put("deviceId", dev.getDeviceId());
map.put("deviceName", dev.getDeviceName());
for (DeviceVo vo : devVoList) {
if (dev.getDeviceId().equals(vo.getDeviceId())) {
map.put("controlKey", vo.getTempValue());
} else {
List<Map> maps2 = new ArrayList<>();
Map<String, Object> map2 = new HashMap<>();
map2.put("label", "控制启停");
map2.put("value", "Start-Stop");
maps2.add(map2);
List<ModelVo> models = psdcModelMapper.selDevIsControlByModelName(dev.getDeviceModel());
for (ModelVo model : models) {
Map<String, Object> map3 = new HashMap<>();
map3.put("label", model.getIoDesc());
map3.put("value", model.getRelationField());
maps2.add(map3);
}
map.put("controlKey", maps2);
}
}
maps.add(map);
}
return maps;
}
/** /**
* 更新数据 * 更新数据
* *
@ -128,30 +174,61 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
*/ */
@Override @Override
@Transactional(propagation = REQUIRES_NEW) @Transactional(propagation = REQUIRES_NEW)
public Boolean update(PsdcSceneRes scenes) { public Boolean update(StrategyVo scenes) {
psdcSceneMapper.deleteBySceneName(scenes.getSceneCode());
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
Date date = new Date(); Long code = Long.valueOf(scenes.getStrategyCode());
String userName = sysUserMapper.selectUserById(userId).getUserName(); String userName = SecurityUtils.getUsername();
List<SceneVo> scenesList = new ArrayList<>(); List<SceneVo> scenesList = new ArrayList<>();
for (DeviceVo dev : scenes.getDeviceVos()) { String s = null;
for (Map m : dev.getTempList()){ Date date = new Date();
String desc = (String) m.get("label"); Long thisSceneCode = null;
String tempValue = (String) m.get("value"); for (int i = scenes.getScenesList().size() - 1; i >= 0; i--) {
String sceneKey = sceneKey(desc); PsdcSceneRes sc = scenes.getScenesList().get(i);
SceneVo sceneVo = new SceneVo(scenes.getSceneName(), scenes.getSceneCode(), userId, scenes.getIsJudge(), if (null != sc.getSceneCode() && !"".equals(sc.getSceneCode())){
scenes.getJudgeDevice(), scenes.getJudgeElement(), scenes.getJudgeData(), dev.getDeviceId(), thisSceneCode = sc.getSceneCode();
desc, sceneKey, tempValue, scenes.getSceneRemark()); } else {
scenesList.add(sceneVo); thisSceneCode = getSecondTimestampTwo(date);
}
s = thisSceneCode + "," + s;
psdcSceneMapper.deleteBySceneName(sc.getSceneCode());
for (DeviceVo dev : sc.getDeviceVos()) {
for (Map m : dev.getTempList()) {
String desc = (String) m.get("label");
String tempValue = (String) m.get("value");
String sceneKey = sceneKey(desc);
SceneVo sceneVo = new SceneVo(sc.getSceneName(), thisSceneCode, userId, sc.getIsJudge(),
sc.getJudgeDevice(), sc.getJudgeElement(), sc.getJudgeData(), dev.getDeviceId(),
desc, sceneKey, tempValue, sc.getSceneRemark());
sceneVo.setCreateBy(userName);
sceneVo.setCreateTime(sdf.format(date));
scenesList.add(sceneVo);
}
} }
} }
s = s.substring(0, s.length() - 5);
try { /* for (PsdcSceneRes sc : scenes.getScenesList()){
for (SceneVo sc : scenesList) { s = sc.getSceneCode() + "," + s;
sc.setCreateBy(userName); psdcSceneMapper.deleteBySceneName(sc.getSceneCode());
sc.setCreateTime(sdf.format(date)); for (DeviceVo dev : sc.getDeviceVos()) {
for (Map m : dev.getTempList()){
String desc = (String) m.get("label");
String tempValue = (String) m.get("value");
String sceneKey = sceneKey(desc);
SceneVo sceneVo = new SceneVo(sc.getSceneName(), sc.getSceneCode(), userId, sc.getIsJudge(),
sc.getJudgeDevice(), sc.getJudgeElement(), sc.getJudgeData(), dev.getDeviceId(),
desc, sceneKey, tempValue, sc.getSceneRemark());
sceneVo.setCreateBy(userName);
sceneVo.setCreateTime(sdf.format(date));
scenesList.add(sceneVo);
}
} }
}*/
PsdcStrategy strategy = new PsdcStrategy(userId, scenes.getStrategyName(), code, s, scenes.getStrategyInfo(), userName, sdf.format(date));
strategy.setUpdateBy(userName);
strategy.setUpdateTime(sdf.format(date));
try {
psdcSceneMapper.InsertSceneData(scenesList); psdcSceneMapper.InsertSceneData(scenesList);
psdcStrategyMapper.update(strategy);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -167,12 +244,23 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
* @return 是否成功 * @return 是否成功
*/ */
@Override @Override
@Transactional(propagation = REQUIRES_NEW)
public Boolean deleteByScene(PsdcSceneRequest scene) { public Boolean deleteByScene(PsdcSceneRequest scene) {
int count = 0; int count = 0;
if (null != scene.getSceneCode() && !"".equals(scene.getSceneCode())) { Long userId = SecurityUtils.getUserId();
count = psdcSceneMapper.deleteBySceneName(scene.getSceneCode()); Long code = scene.getStrategyCode();
List<PsdcStrategy> list = psdcStrategyMapper.queryByUser(userId, code);
for (PsdcStrategy scr : list) {
String[] split = scr.getScenes().split(",");
for (String s : split) {
if (null != s && !"".equals(s)) {
count = count + psdcSceneMapper.deleteBySceneName(Long.parseLong(s));
}
}
} }
if (count > 0) { int strategyName = psdcStrategyMapper.deleteByStrategyName(code);
if (count > 0 && strategyName > 0) {
return true; return true;
} else { } else {
return false; return false;
@ -204,7 +292,7 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
map.put("value", sv.getSceneValue()); map.put("value", sv.getSceneValue());
list.add(map); list.add(map);
deviceVo.setTempValue(list); deviceVo.setTempValue(list);
if (1 == listByCode.size() || i == listByCode.size() - 1){ if (1 == listByCode.size() || i == listByCode.size() - 1) {
ary.add(deviceVo); ary.add(deviceVo);
} }
@ -242,7 +330,9 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
String sceneName = ""; String sceneName = "";
List<PsdcSceneRes> sceneRes = psdcSceneMapper.queryScenes(userId, sceneCode); List<PsdcSceneRes> sceneRes = psdcSceneMapper.queryScenes(userId, sceneCode);
for (PsdcSceneRes psr : sceneRes) {
for (int h = 0; h < sceneRes.size(); h++) {
PsdcSceneRes psr = sceneRes.get(h);
Long code = psr.getSceneCode(); Long code = psr.getSceneCode();
List<SceneVo> listByCode = psdcSceneMapper.findSceneByUserAndSceneCode(userId, code, sceneName); List<SceneVo> listByCode = psdcSceneMapper.findSceneByUserAndSceneCode(userId, code, sceneName);
List<DeviceVo> ary = new ArrayList<>(); List<DeviceVo> ary = new ArrayList<>();
@ -261,7 +351,7 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
map.put("value", sv.getSceneValue()); map.put("value", sv.getSceneValue());
list.add(map); list.add(map);
deviceVo.setTempValue(list); deviceVo.setTempValue(list);
if (1 == listByCode.size() || i == listByCode.size() - 1){ if (1 == listByCode.size() || i == listByCode.size() - 1) {
ary.add(deviceVo); ary.add(deviceVo);
} }
@ -308,11 +398,11 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
return Long.valueOf(timestamp); return Long.valueOf(timestamp);
} }
private String sceneKey(String desc){ private String sceneKey(String desc) {
String s = desc.substring(0,2); String s = desc.substring(0, 2);
switch (s){ switch (s) {
case "开启": case "控制启停":
return "open"; return "open-close";
case "关闭": case "关闭":
return "close"; return "close";
default: default:

@ -9,6 +9,7 @@
<result property="deviceModel" column="device_model" /> <result property="deviceModel" column="device_model" />
<result property="deviceSn" column="device_sn" /> <result property="deviceSn" column="device_sn" />
<result property="deviceName" column="device_name" /> <result property="deviceName" column="device_name" />
<result property="deviceModel" column="device_model" />
<result property="isControl" column="is_control" /> <result property="isControl" column="is_control" />
<result property="hardVersion" column="hard_version" /> <result property="hardVersion" column="hard_version" />
<result property="softVersion" column="soft_version" /> <result property="softVersion" column="soft_version" />
@ -362,6 +363,7 @@
user_id, user_id,
device_type, device_type,
device_sn, device_sn,
device_model,
device_name, device_name,
hard_version, hard_version,
soft_version, soft_version,

@ -29,13 +29,47 @@
Group By strategy_code Group By strategy_code
</select> </select>
<select id="strategyList" resultMap="PsdcStrategyMap">
SELECT * FROM `psdc_strategy` WHERE user_id = ${userId} Group By strategy_code
</select>
<!--新增数据--> <!--新增数据-->
<insert id="insert" parameterType="com.psdc.entity.PsdcStrategy"> <insert id="insert" parameterType="com.psdc.entity.PsdcStrategy">
Insert into psdc_strategy(user_id,strategy_name,strategy_code,scenes,strategy_info,create_by,create_time,update_by,update_time) Insert into psdc_strategy(user_id,strategy_name,strategy_code,scenes,strategy_info,create_by,create_time,update_by,update_time)
Values (#{userId},#{strategyName},#{strategyCode},#{scenes},#{strategyInfo},#{createBy},#{createTime},#{updateBy},#{updateTime}) Values (#{userId},#{strategyName},#{strategyCode},#{scenes},#{strategyInfo},#{createBy},#{createTime},#{updateBy},#{updateTime})
</insert> </insert>
<delete id="deleteByStrategyName">
Delete From psdc_strategy Where strategy_code = #{sceneCode}
</delete>
<!-- 更新数据 -->
<update id="update">
Update psdc_strategy
<set>
<if test="strategyName != null and strategyName != ''">
strategy_name = #{strategyName},
</if>
<if test="scenes != null and scenes != ''">
scenes = #{scenes},
</if>
<if test="strategyInfo != null and strategyInfo != ''">
strategy_info = #{strategyInfo},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="updateTime != null and updateTime != ''">
update_time = #{updateTime},
</if>
</set>
<where>
<if test="userId != null and userId != ''">
And user_id = #{userId}
</if>
<if test="strategyCode != null and strategyCode != ''">
And strategy_code = #{strategyCode}
</if>
</where>
</update>
<select id="strategyList" resultMap="PsdcStrategyMap">
SELECT * FROM `psdc_strategy` WHERE user_id = ${userId} Group By strategy_code
</select>
</mapper> </mapper>

@ -81,7 +81,7 @@ public class PsdcSceneController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:cl:list')") @PreAuthorize("@ss.hasPermi('system:cl:list')")
@Log(title = "策略管理", businessType = BusinessType.UPDATE) @Log(title = "策略管理", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@Validated @RequestBody PsdcSceneRes scenes) { public AjaxResult edit(@Validated @RequestBody StrategyVo scenes) {
return toAjax(psdcSceneService.update(scenes)); return toAjax(psdcSceneService.update(scenes));
} }

Loading…
Cancel
Save