|
|
@@ -0,0 +1,149 @@
|
|
|
+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.DeviceInfoService;
|
|
|
+import com.zhongshu.card.server.core.dao.school.AreaDao;
|
|
|
+import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
|
|
|
+import com.zhongshu.card.server.core.domain.school.Area;
|
|
|
+import com.zhongshu.card.server.core.domain.school.BookInfo;
|
|
|
+import com.zhongshu.card.server.core.domain.school.DeviceInfo;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+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/6/14
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DeviceInfoDao deviceInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AreaServiceImpl areaService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AreaDao areaDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加-编辑设备
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent addDeviceInfo(DeviceInfoParam param) {
|
|
|
+ initDefaultUserAndOid(param);
|
|
|
+ Assert.hasText(param.getCode(), "code不能为空");
|
|
|
+
|
|
|
+ String oid = param.getOid();
|
|
|
+ DeviceInfo deviceInfo = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getId())) {
|
|
|
+ deviceInfo = deviceInfoDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
|
|
|
+ }
|
|
|
+ DeviceInfo temp = deviceInfoDao.findTopByCodeAndOid(param.getCode(), oid);
|
|
|
+ if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(deviceInfo.getId())) {
|
|
|
+ return ResultContent.buildFail(String.format("设备号已存在:%s", param.getCode()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ deviceInfo = new DeviceInfo();
|
|
|
+ DeviceInfo temp = deviceInfoDao.findTopByCodeAndOid(param.getCode(), oid);
|
|
|
+ if (ObjectUtils.isNotEmpty(temp)) {
|
|
|
+ return ResultContent.buildFail(String.format("设备号已存在:%s", param.getCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, deviceInfo);
|
|
|
+ Area area = null;
|
|
|
+ if (StringUtils.isNotEmpty(param.getAreaId())) {
|
|
|
+ area = areaDao.findTopById(param.getAreaId());
|
|
|
+ if (ObjectUtils.isEmpty(area)) {
|
|
|
+ return ResultContent.buildFail(String.format("区域ID不存在:%s", param.getAreaId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ deviceInfo.setArea(area);
|
|
|
+ deviceInfoDao.save(deviceInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备分页列表
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<Page<DeviceInfoModel>> page(DeviceInfoSearch param, Pageable pageable) {
|
|
|
+ initOidSearchParam(param);
|
|
|
+ Page<DeviceInfo> page = deviceInfoDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除设备
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent deleteDeviceInfo(String id) {
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ deviceInfoDao.delete(deviceInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到设备详情
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent<DeviceInfoMoreModel> getDeviceDetail(String id) {
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, id));
|
|
|
+ }
|
|
|
+ DeviceInfoMoreModel model = toMoreModel(deviceInfo);
|
|
|
+ return ResultContent.buildSuccess(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceInfoMoreModel toMoreModel(DeviceInfo entity) {
|
|
|
+ DeviceInfoMoreModel model = null;
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ model = new DeviceInfoMoreModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ model.setArea(areaService.toModel(entity.getArea()));
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceInfoModel toModel(DeviceInfo entity) {
|
|
|
+ DeviceInfoModel model = null;
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ model = new DeviceInfoModel();
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ model.setArea(areaService.toModel(entity.getArea()));
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|