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 Long sceneCode;
/** 模式策略码 */
private Long strategyCode;
/** 用户id */
private Long userId;
/** 设备id */

@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* @AuthorStone
@ -21,6 +22,10 @@ import java.util.List;
@NoArgsConstructor
public class PsdcSceneRes {
/**
* 步骤序号
*/
private Integer ID;
/** 场景值 */
private Integer sceneId ;
/** 场景名称 */
@ -51,17 +56,22 @@ public class PsdcSceneRes {
private String judgeElement ;
/** 判断条件元素的数据值 */
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.sceneName = sceneName;
this.sceneCode = sceneCode;

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

@ -1,15 +1,14 @@
package com.psdc.service.impl;
import com.psdc.entity.PsdcDevice;
import com.psdc.entity.PsdcStrategy;
import com.psdc.entity.request.PsdcSceneRequest;
import com.psdc.entity.res.PsdcSceneRes;
import com.psdc.entity.vo.DeviceVo;
import com.psdc.entity.vo.ModelVo;
import com.psdc.entity.vo.SceneVo;
import com.psdc.entity.vo.StrategyVo;
import com.psdc.mapper.PsdcModelMapper;
import com.psdc.mapper.PsdcSceneMapper;
import com.psdc.mapper.PsdcStrategyMapper;
import com.psdc.mapper.SysUserMapper;
import com.psdc.mapper.*;
import com.psdc.service.IPsdcSceneService;
import com.psdc.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
@ -35,10 +34,10 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
private PsdcSceneMapper psdcSceneMapper;
@Resource
private SysUserMapper sysUserMapper;
private PsdcModelMapper psdcModelMapper;
@Resource
private PsdcModelMapper psdcModelMapper;
private PsdcDeviceMapper psdcDeviceMapper;
@Resource
private PsdcStrategyMapper psdcStrategyMapper;
@ -46,7 +45,6 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 新增数据
*
@ -60,12 +58,14 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
String userName = SecurityUtils.getUsername();
List<SceneVo> scenesList = new ArrayList<>();
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();
long timestamp = getSecondTimestampTwo(date2);
s = timestamp + ",";
PsdcSceneRes sc = scenes.getScenesList().get(i);
long timestamp = getSecondTimestampTwo(date2) - i;
s = timestamp + "," + s;
for (DeviceVo dev : sc.getDeviceVos()) {
for (Map m : dev.getTempList()){
for (Map m : dev.getTempList()) {
String desc = (String) m.get("label");
String tempValue = (String) m.get("value");
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));
try {
@ -105,21 +106,66 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
Long userId = SecurityUtils.getUserId();
List<StrategyVo> ary = new ArrayList<>();
List<PsdcStrategy> list = psdcStrategyMapper.queryByUser(userId, strategyCode);
for (PsdcStrategy srt : list){
int i = 1;
for (PsdcStrategy srt : list) {
String[] codes = srt.getScenes().split(",");
List<PsdcSceneRes> list2 = new ArrayList<>();
for (String s : codes){
for (String s : codes) {
List<PsdcSceneRes> list3 = findSceneByUserAndSceneName(Long.parseLong(s));
if (null != list3 && list3.size() > 0){
list2.add(list3.get(0));
if (null != list3 && list3.size() > 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());
ary.add(strategyVo);
}
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
@Transactional(propagation = REQUIRES_NEW)
public Boolean update(PsdcSceneRes scenes) {
psdcSceneMapper.deleteBySceneName(scenes.getSceneCode());
public Boolean update(StrategyVo scenes) {
Long userId = SecurityUtils.getUserId();
Date date = new Date();
String userName = sysUserMapper.selectUserById(userId).getUserName();
Long code = Long.valueOf(scenes.getStrategyCode());
String userName = SecurityUtils.getUsername();
List<SceneVo> scenesList = new ArrayList<>();
for (DeviceVo dev : scenes.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(scenes.getSceneName(), scenes.getSceneCode(), userId, scenes.getIsJudge(),
scenes.getJudgeDevice(), scenes.getJudgeElement(), scenes.getJudgeData(), dev.getDeviceId(),
desc, sceneKey, tempValue, scenes.getSceneRemark());
scenesList.add(sceneVo);
String s = null;
Date date = new Date();
Long thisSceneCode = null;
for (int i = scenes.getScenesList().size() - 1; i >= 0; i--) {
PsdcSceneRes sc = scenes.getScenesList().get(i);
if (null != sc.getSceneCode() && !"".equals(sc.getSceneCode())){
thisSceneCode = sc.getSceneCode();
} else {
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);
}
}
}
try {
for (SceneVo sc : scenesList) {
sc.setCreateBy(userName);
sc.setCreateTime(sdf.format(date));
s = s.substring(0, s.length() - 5);
/* for (PsdcSceneRes sc : scenes.getScenesList()){
s = sc.getSceneCode() + "," + 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(), 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);
psdcStrategyMapper.update(strategy);
return true;
} catch (Exception e) {
e.printStackTrace();
@ -167,12 +244,23 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
* @return 是否成功
*/
@Override
@Transactional(propagation = REQUIRES_NEW)
public Boolean deleteByScene(PsdcSceneRequest scene) {
int count = 0;
if (null != scene.getSceneCode() && !"".equals(scene.getSceneCode())) {
count = psdcSceneMapper.deleteBySceneName(scene.getSceneCode());
Long userId = SecurityUtils.getUserId();
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;
} else {
return false;
@ -204,7 +292,7 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
map.put("value", sv.getSceneValue());
list.add(map);
deviceVo.setTempValue(list);
if (1 == listByCode.size() || i == listByCode.size() - 1){
if (1 == listByCode.size() || i == listByCode.size() - 1) {
ary.add(deviceVo);
}
@ -242,7 +330,9 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
Long userId = SecurityUtils.getUserId();
String sceneName = "";
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();
List<SceneVo> listByCode = psdcSceneMapper.findSceneByUserAndSceneCode(userId, code, sceneName);
List<DeviceVo> ary = new ArrayList<>();
@ -261,7 +351,7 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
map.put("value", sv.getSceneValue());
list.add(map);
deviceVo.setTempValue(list);
if (1 == listByCode.size() || i == listByCode.size() - 1){
if (1 == listByCode.size() || i == listByCode.size() - 1) {
ary.add(deviceVo);
}
@ -308,11 +398,11 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
return Long.valueOf(timestamp);
}
private String sceneKey(String desc){
String s = desc.substring(0,2);
switch (s){
case "开启":
return "open";
private String sceneKey(String desc) {
String s = desc.substring(0, 2);
switch (s) {
case "控制启停":
return "open-close";
case "关闭":
return "close";
default:

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

@ -29,13 +29,47 @@
Group By strategy_code
</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 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})
</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>

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

Loading…
Cancel
Save