|
|
@@ -4,12 +4,25 @@ import com.zswl.dataservice.dao.UserDao;
|
|
|
import com.zswl.dataservice.dao.iot.IotMainDao;
|
|
|
import com.zswl.dataservice.dao.iot.IotTemplateDao;
|
|
|
import com.zswl.dataservice.dao.iot.IotTopicDao;
|
|
|
+import com.zswl.dataservice.dataConfig.ResultMessage;
|
|
|
+import com.zswl.dataservice.domain.iot.IotMain;
|
|
|
import com.zswl.dataservice.domain.iot.IotTemplate;
|
|
|
-import com.zswl.dataservice.model.iot.IotTemplateParam;
|
|
|
+import com.zswl.dataservice.domain.iot.IotTopic;
|
|
|
+import com.zswl.dataservice.domain.mqtt.DeviceInfo;
|
|
|
+import com.zswl.dataservice.model.iot.*;
|
|
|
+import com.zswl.dataservice.model.mqtt.DeviceInfoModel;
|
|
|
+import com.zswl.dataservice.model.mqtt.DeviceInfoSearchParam;
|
|
|
import com.zswl.dataservice.service.base.SuperService;
|
|
|
+import com.zswl.dataservice.utils.bean.BeanUtil;
|
|
|
+import com.zswl.dataservice.utils.bean.BeanUtils;
|
|
|
+import com.zswl.dataservice.utils.page.PageEntityUtil;
|
|
|
import com.zswl.dataservice.utils.result.ResultContent;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
/**
|
|
|
@@ -32,9 +45,193 @@ public class IotServiceImpl extends SuperService {
|
|
|
@Autowired
|
|
|
UserDao userDao;
|
|
|
|
|
|
- public ResultContent addIotTemplate(IotTemplateParam iotTemplate) {
|
|
|
+ //----------------------------- 模版 start----------------------------
|
|
|
+ public ResultContent addIotTemplate(IotTemplateParam param) {
|
|
|
+ IotTemplate template = null;
|
|
|
+ initDefaultUser(param);
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ template = iotTemplateDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(template)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, param.getId()));
|
|
|
+ }
|
|
|
+ IotTemplate temp = iotTemplateDao.findTopByName(param.getName());
|
|
|
+ if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ template = new IotTemplate();
|
|
|
+ IotTemplate temp = iotTemplateDao.findTopByName(param.getName());
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, template);
|
|
|
+ iotTemplateDao.save(template);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteTemplate(String id) {
|
|
|
+ IotTemplate template = iotTemplateDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(template)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, id));
|
|
|
+ }
|
|
|
+ iotTemplateDao.delete(template);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<IotTemplateModel> getIotTemplate(String id) {
|
|
|
+ IotTemplate template = iotTemplateDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(template)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(template));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<IotTemplateModel>> pageTemplate(Pageable pageable, IotTemplateSearch param) {
|
|
|
+ initSearchParam(param);
|
|
|
+ Page<IotTemplate> page = iotTemplateDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+ //----------------------------- 模版 end------------------------------
|
|
|
|
|
|
+ //----------------------------- Topic start----------------------------
|
|
|
+ public ResultContent addIotTopic(IotTopicParam param) {
|
|
|
+ initDefaultUser(param);
|
|
|
+ String iotTemplateId = param.getIotTemplateId();
|
|
|
+ IotTemplate iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
|
|
|
+ if (ObjectUtils.isEmpty(iotTemplate)) {
|
|
|
+ return ResultContent.buildFail(String.format("模版不存在:%s", iotTemplateId));
|
|
|
+ }
|
|
|
|
|
|
+ IotTopic entity = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ entity = iotTopicDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, param.getId()));
|
|
|
+ }
|
|
|
+ IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getTopic(), iotTemplate);
|
|
|
+ if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getTopic()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ entity = new IotTopic();
|
|
|
+ IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getTopic(), iotTemplate);
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getTopic()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ entity.setIotTemplate(iotTemplate);
|
|
|
+ iotTopicDao.save(entity);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
+
|
|
|
+ public ResultContent deleteIotTopic(String id) {
|
|
|
+ IotTopic entity = iotTopicDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, id));
|
|
|
+ }
|
|
|
+ iotTopicDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<IotTopicModel> getIotTopic(String id) {
|
|
|
+ IotTopic entity = iotTopicDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<IotTopicModel>> pageIotTopic(Pageable pageable, IotTopicSearch param) {
|
|
|
+ initSearchParam(param);
|
|
|
+ Page<IotTopic> page = iotTopicDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+ //----------------------------- Topic end------------------------------
|
|
|
+
|
|
|
+ //----------------------------- 物模型 start----------------------------
|
|
|
+ public ResultContent addIotMain(IotMainParam param) {
|
|
|
+ initDefaultUser(param);
|
|
|
+ String iotTemplateId = param.getIotTemplateId();
|
|
|
+ IotTemplate iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
|
|
|
+ if (ObjectUtils.isEmpty(iotTemplate)) {
|
|
|
+ return ResultContent.buildFail(String.format("模版不存在:%s", iotTemplateId));
|
|
|
+ }
|
|
|
+
|
|
|
+ IotMain entity = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ entity = iotMainDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, param.getId()));
|
|
|
+ }
|
|
|
+ IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
|
|
|
+ if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ entity = new IotMain();
|
|
|
+ IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ entity.setIotTemplate(iotTemplate);
|
|
|
+ iotMainDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteIotMain(String id) {
|
|
|
+ IotMain entity = iotMainDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, id));
|
|
|
+ }
|
|
|
+ iotMainDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<IotMainModel> getIotMain(String id) {
|
|
|
+ IotMain entity = iotMainDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIT, id));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<IotMainModel>> pageIotMain(Pageable pageable, IotMainSearch param) {
|
|
|
+ initSearchParam(param);
|
|
|
+ Page<IotMain> page = iotMainDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+ //----------------------------- 物模型 end------------------------------
|
|
|
+
|
|
|
+ public IotTemplateModel toModel(IotTemplate entity) {
|
|
|
+ IotTemplateModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new IotTemplateModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IotTopicModel toModel(IotTopic entity) {
|
|
|
+ IotTopicModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new IotTopicModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IotMainModel toModel(IotMain entity) {
|
|
|
+ IotMainModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new IotMainModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|