|
|
@ -1,21 +1,29 @@ |
|
|
|
package com.psdc.service.impl; |
|
|
|
package com.psdc.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.psdc.entity.PsdcDevice; |
|
|
|
import com.psdc.entity.PsdcScene; |
|
|
|
import com.psdc.entity.PsdcScene; |
|
|
|
import com.psdc.entity.vo.SceneVo; |
|
|
|
import com.psdc.entity.vo.SceneVo; |
|
|
|
import com.psdc.mapper.PsdcSceneMapper; |
|
|
|
import com.psdc.mapper.PsdcSceneMapper; |
|
|
|
import com.psdc.service.IPsdcSceneService; |
|
|
|
import com.psdc.service.IPsdcSceneService; |
|
|
|
import com.psdc.utils.SecurityUtils; |
|
|
|
import com.psdc.utils.SecurityUtils; |
|
|
|
|
|
|
|
import com.psdc.utils.poi.ExcelUtil; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 场景设定;(psdc_scene)表服务实现类 |
|
|
|
* 场景设定;(psdc_scene)表服务实现类 |
|
|
|
* @date : 2023-5-10 |
|
|
|
* @date : 2023-5-10 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
public class PsdcSceneServiceImpl implements IPsdcSceneService { |
|
|
|
public class PsdcSceneServiceImpl implements IPsdcSceneService { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
@ -35,13 +43,27 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 新增数据 |
|
|
|
* 新增数据 |
|
|
|
* |
|
|
|
* @param scenes 实例对象集合 |
|
|
|
* @param psdcScene 实例对象 |
|
|
|
* @return Boolean |
|
|
|
* @return 实例对象 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PsdcScene insert(PsdcScene psdcScene){ |
|
|
|
@Override |
|
|
|
psdcSceneMapper.insert(psdcScene); |
|
|
|
@Transactional(propagation = REQUIRES_NEW) |
|
|
|
return psdcScene; |
|
|
|
public Boolean insert(List<SceneVo> scenes){ |
|
|
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
|
|
|
long timestamp = getSecondTimestampTwo(date); |
|
|
|
|
|
|
|
long userId = SecurityUtils.getUserId(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
for (SceneVo sc : scenes){ |
|
|
|
|
|
|
|
sc.setSceneCode(timestamp); |
|
|
|
|
|
|
|
sc.setUserId(userId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
psdcSceneMapper.InsertSceneData(scenes); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
log.info("Sorry,新增场景策略失败!+ 错误原因: {}", e.getMessage()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -50,17 +72,26 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService { |
|
|
|
return psdcSceneMapper.sceneList(userId); |
|
|
|
return psdcSceneMapper.sceneList(userId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 更新数据 |
|
|
|
* 更新数据 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param psdcScene 实例对象 |
|
|
|
* @param scenes 实例对象 |
|
|
|
* @return 实例对象 |
|
|
|
* @return 实例对象 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PsdcScene update(PsdcScene psdcScene){ |
|
|
|
@Override |
|
|
|
psdcSceneMapper.update(psdcScene); |
|
|
|
@Transactional(propagation = REQUIRES_NEW) |
|
|
|
return queryById(psdcScene.getSceneId()); |
|
|
|
public Boolean update(List<SceneVo> scenes) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
psdcSceneMapper.UpdateSceneData(scenes); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
log.info("Sorry,修改场景策略失败!+ 错误原因: {}", e.getMessage()); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通过主键删除数据 |
|
|
|
* 通过主键删除数据 |
|
|
|
* |
|
|
|
* |
|
|
@ -103,7 +134,24 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<SceneVo> findSceneByUserAndSceneName(Integer sceneId) { |
|
|
|
public List<SceneVo> findSceneByUserAndSceneName(Integer sceneId) { |
|
|
|
Long userId = SecurityUtils.getUserId(); |
|
|
|
Long userId = SecurityUtils.getUserId(); |
|
|
|
String sceneName = psdcSceneMapper.queryById(sceneId).getSceneName(); |
|
|
|
String sceneName = ""; |
|
|
|
|
|
|
|
if (0 != sceneId){ |
|
|
|
|
|
|
|
psdcSceneMapper.queryById(sceneId).getSceneName(); |
|
|
|
|
|
|
|
} |
|
|
|
return psdcSceneMapper.findSceneByUserAndSceneName(userId, sceneName); |
|
|
|
return psdcSceneMapper.findSceneByUserAndSceneName(userId, sceneName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取精确到秒的时间戳 |
|
|
|
|
|
|
|
* @param date |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static long getSecondTimestampTwo(Date date){ |
|
|
|
|
|
|
|
if (null == date) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String timestamp = String.valueOf(date.getTime()/1000); |
|
|
|
|
|
|
|
return Long.valueOf(timestamp); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |