TRX 1 年之前
父節點
當前提交
f81427add8

+ 27 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/DeviceBindModel.java

@@ -26,9 +26,27 @@ public class DeviceBindModel extends SuperModel {
     @Schema(description = "设备类型,如 消费机 门禁机")
     private DeviceType deviceType;
 
+    private String deviceTypeStr;
+
+    public String getDeviceTypeStr() {
+        if (deviceType != null) {
+            return deviceType.getRemark();
+        }
+        return "";
+    }
+
     @Schema(description = "是否在线")
     private OnLineState onLineState = OnLineState.OnLine;
 
+    private String onLineStateStr;
+
+    public String getOnLineStateStr() {
+        if (onLineState != null) {
+            return onLineState.getRemark();
+        }
+        return "";
+    }
+
     @Schema(description = "网关")
     private String gateWayId;
 
@@ -50,6 +68,15 @@ public class DeviceBindModel extends SuperModel {
     @Schema(description = "付费模式")
     private PaymentModeType paymentModeType;
 
+    private String paymentModeTypeStr;
+
+    public String getPaymentModeTypeStr() {
+        if (paymentModeType != null) {
+            return paymentModeType.getRemark();
+        }
+        return "";
+    }
+
     @Schema(description = "收款账号")
     private String receivingAccount;
 }

+ 19 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/service/school/DeviceBindService.java

@@ -0,0 +1,19 @@
+package com.zhongshu.card.client.service.school;
+
+import com.zhongshu.card.client.model.school.DeviceBindModel;
+import com.zhongshu.card.client.model.school.DeviceBindParam;
+import com.zhongshu.card.client.model.school.DeviceBindSearch;
+import com.zhongshu.card.client.ret.ResultContent;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+public interface DeviceBindService {
+
+    ResultContent addDeviceBind(DeviceBindParam param);
+
+    ResultContent deleteById(String id);
+
+    ResultContent<DeviceBindModel> getDetailById(String id);
+
+    ResultContent<Page<DeviceBindModel>> page(DeviceBindSearch param, Pageable pageable);
+}

+ 13 - 25
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/school/DeviceBindController.java

@@ -5,6 +5,7 @@ import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.card.client.model.base.IDParam;
 import com.zhongshu.card.client.model.school.*;
 import com.zhongshu.card.client.ret.ResultContent;
+import com.zhongshu.card.client.service.school.DeviceBindService;
 import com.zhongshu.card.client.service.school.DeviceInfoService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -29,51 +30,38 @@ import java.util.List;
 public class DeviceBindController {
 
     @Autowired
-    DeviceInfoService deviceInfoService;
+    DeviceBindService deviceBindService;
 
     //----------------------------设备基础信息 start------------------------
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "根据设备数据ID 设备详情", description = "根据设备数据ID 设备详情")
-    @RequestMapping(value = "getDeviceById", method = {RequestMethod.POST})
-    public ResultContent<DeviceInfoMoreModel> getDeviceById(@RequestBody IDParam param) {
-        return this.deviceInfoService.getDeviceDetail(param.getId());
-    }
-
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "根据设备ID 设备详情(精确匹配)", description = "根据设备ID 设备详情(精确匹配)")
-    @RequestMapping(value = "getDeviceByDeviceId", method = {RequestMethod.GET})
-    public ResultContent<DeviceInfoMoreModel> getDeviceByDeviceId(@RequestParam(name = "deviceId") String deviceId) {
-        return this.deviceInfoService.getDeviceDetailByDeviceId(deviceId);
-    }
-
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "根据设备ID 设备列表(模糊匹配)", description = "根据设备ID 设备列表(模糊匹配)")
-    @RequestMapping(value = "getDeviceDetailByDeviceIdLike", method = {RequestMethod.GET})
-    public ResultContent<List<DeviceInfoMoreModel>> getDeviceDetailByDeviceIdLike(@RequestParam(name = "deviceId") String deviceId) {
-        return this.deviceInfoService.getDeviceDetailByDeviceIdLike(deviceId);
+    @Operation(summary = "根据数据ID 设备详情", description = "根据数据ID 设备详情")
+    @RequestMapping(value = "getDetailById", method = {RequestMethod.POST})
+    public ResultContent<DeviceBindModel> getDetailById(@RequestBody IDParam param) {
+        return this.deviceBindService.getDetailById(param.getId());
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "添加-编辑设备", description = "添加-编辑设备")
     @RequestMapping(value = "addDeviceInfo", method = {RequestMethod.POST})
-    public ResultContent addDeviceInfo(@RequestBody DeviceInfoParam param) {
-        return this.deviceInfoService.addDeviceInfo(param);
+    public ResultContent addDeviceInfo(@RequestBody DeviceBindParam param) {
+        return this.deviceBindService.addDeviceBind(param);
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "删除设备", description = "删除设备")
     @RequestMapping(value = "deleteDeviceInfo", method = {RequestMethod.POST})
     public ResultContent deleteDeviceInfo(@RequestBody IDParam param) {
-        return this.deviceInfoService.deleteDeviceInfo(param.getId());
+        return this.deviceBindService.deleteById(param.getId());
     }
 
-
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "设备列表-分页查询", description = "设备列表-分页查询")
     @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
-    public ResultContent<Page<DeviceInfoModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DeviceInfoSearch param) {
-        return deviceInfoService.page(param, pageable);
+    public ResultContent<Page<DeviceBindModel>> page(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceBindSearch param) {
+        return deviceBindService.page(param, pageable);
     }
 
     //----------------------------设备基础信息 end--------------------------

+ 0 - 33
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/DeviceBindService.java

@@ -1,33 +0,0 @@
-package com.zhongshu.card.server.core.service.school;
-
-import com.zhongshu.card.server.core.dao.org.OrganizationDao;
-import com.zhongshu.card.server.core.dao.school.DeviceBindDao;
-import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
-import com.zhongshu.card.server.core.service.base.SuperService;
-import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-/**
- * @author TRX
- * @date 2024/7/2
- */
-@Slf4j
-@Service
-public class DeviceBindService extends SuperService {
-
-    @Autowired
-    DeviceBindDao deviceBindDao;
-
-    @Autowired
-    DeviceInfoDao deviceInfoDao;
-
-    @Autowired
-    OrganizationDao organizationDao;
-
-    @Autowired
-    OrganizationServiceImpl organizationService;
-
-
-}

+ 175 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/DeviceBindServiceImpl.java

@@ -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;
+    }
+
+}