|
|
@@ -0,0 +1,175 @@
|
|
|
+package com.zhongshu.card.server.core.service.school;
|
|
|
+
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.zhongshu.card.client.model.school.*;
|
|
|
+import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
+import com.zhongshu.card.client.service.school.DeviceBindService;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
+import com.zhongshu.card.server.core.dao.school.AreaDao;
|
|
|
+import com.zhongshu.card.server.core.dao.school.DeviceBindDao;
|
|
|
+import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
|
|
|
+import com.zhongshu.card.server.core.domain.org.DeviceInfo;
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
+import com.zhongshu.card.server.core.domain.school.Area;
|
|
|
+import com.zhongshu.card.server.core.domain.school.DeviceBind;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.org.DeviceInfoServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
|
|
|
+import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
+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;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/7/2
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class DeviceBindServiceImpl extends SuperService implements DeviceBindService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DeviceBindDao deviceBindDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DeviceInfoDao deviceInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationServiceImpl organizationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DeviceInfoServiceImpl deviceInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AreaDao areaDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AreaServiceImpl areaService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultContent addDeviceBind(DeviceBindParam param) {
|
|
|
+ initDefaultUserAndOid(param);
|
|
|
+ Assert.hasText("deviceId不能为空", param.getDeviceId());
|
|
|
+ Assert.hasText("schoolInfoOid不能为空", param.getSchoolInfoOid());
|
|
|
+ Assert.hasText("shopInfoOid不能为空", param.getShopInfoOid());
|
|
|
+
|
|
|
+ String oid = param.getOid();
|
|
|
+ String deviceId = param.getDeviceId();
|
|
|
+ DeviceBind deviceBind = null;
|
|
|
+ DeviceBind temp = deviceBindDao.findTopByDeviceIdAndOid(deviceId, oid);
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ deviceBind = deviceBindDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(deviceBind)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(deviceBind.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format("设备已添加:%s", deviceId));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ deviceBind = new DeviceBind();
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format("设备已添加:%s", deviceId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, deviceBind);
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format("设备不存在:%s", deviceId));
|
|
|
+ }
|
|
|
+
|
|
|
+ deviceBind.setDeviceId(deviceId);
|
|
|
+ deviceBind.setDeviceName(deviceInfo.getDeviceName());
|
|
|
+ deviceBind.setDeviceInfo(deviceInfo);
|
|
|
+ deviceBind.setOnLineState(deviceInfo.getOnLineState());
|
|
|
+ deviceBind.setProjectInfoCode(deviceInfo.getProjectInfoCode());
|
|
|
+ deviceBind.setGateWayId(deviceInfo.getGateWayId());
|
|
|
+ deviceBind.setDeviceType(deviceInfo.getDeviceType());
|
|
|
+
|
|
|
+ String schoolInfoOid = param.getSchoolInfoOid();
|
|
|
+ Organization schoolInfo = organizationDao.findTopByOid(schoolInfoOid);
|
|
|
+ deviceBind.setSchoolInfo(schoolInfo);
|
|
|
+
|
|
|
+ String shopInfoOid = param.getShopInfoOid();
|
|
|
+ Organization shopInfo = organizationDao.findTopByOid(shopInfoOid);
|
|
|
+ deviceBind.setShopInfo(shopInfo);
|
|
|
+
|
|
|
+ String areaId = param.getAreaId();
|
|
|
+ Area area = areaDao.findTopById(areaId);
|
|
|
+ deviceBind.setArea(area);
|
|
|
+
|
|
|
+ deviceBindDao.save(deviceBind);
|
|
|
+
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ID删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent deleteById(String id) {
|
|
|
+ DeviceBind deviceBind = deviceBindDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(deviceBind)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ deviceBindDao.delete(deviceBind);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询详情
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<DeviceBindModel> getDetailById(String id) {
|
|
|
+ DeviceBind deviceBind = deviceBindDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(deviceBind)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ DeviceBindModel model = toModel(deviceBind);
|
|
|
+ return ResultContent.buildSuccess(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备分页列表
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<Page<DeviceBindModel>> page(DeviceBindSearch param, Pageable pageable) {
|
|
|
+ initOidSearchParam(param);
|
|
|
+ Page<DeviceBind> page = deviceBindDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceBindModel toModel(DeviceBind entity) {
|
|
|
+ DeviceBindModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ model = new DeviceBindModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+
|
|
|
+ model.setDeviceInfo(deviceInfoService.toModel(entity.getDeviceInfo()));
|
|
|
+ model.setSchoolInfo(organizationService.toSimpleModel(entity.getSchoolInfo()));
|
|
|
+ model.setShopInfo(organizationService.toSimpleModel(entity.getShopInfo()));
|
|
|
+ model.setArea(areaService.toModel(entity.getArea()));
|
|
|
+
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|