diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java index 7ad1bd2..d921708 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/controller/AppDeviceController.java @@ -44,7 +44,6 @@ public class AppDeviceController extends BaseController { */ @GetMapping("/list") public TableDataInfo list(DeviceQueryCriteria bo, PageQuery pageQuery) { - return appDeviceService.queryAppDeviceList(bo,pageQuery); } diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java index 2439513..c5acd24 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java @@ -1,5 +1,6 @@ package com.fuyuanshen.app.service; +import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -82,23 +83,23 @@ public class AppDeviceBizService { public int sendMessage(AppDeviceSendMsgBo bo) { List deviceIds = bo.getDeviceIds(); - if(deviceIds == null || deviceIds.isEmpty()){ + if (deviceIds == null || deviceIds.isEmpty()) { throw new ServiceException("请选择设备"); } - for (Long deviceId : deviceIds){ + for (Long deviceId : deviceIds) { Device deviceObj = deviceMapper.selectById(deviceId); - if(deviceObj==null) { - throw new ServiceException("设备不存在"+deviceId); + if (deviceObj == null) { + throw new ServiceException("设备不存在" + deviceId); } byte[] msg = ReliableTextToBitmap.textToBitmapBytes(bo.getSendMsg()); ArrayList intData = new ArrayList<>(); intData.add(2); - buildArr(convertHexToDecimal(msg),intData); + buildArr(convertHexToDecimal(msg), intData); Map map = new HashMap<>(); map.put("instruct", intData); - mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 ,JSON.toJSONString(map)); - log.info("发送设备消息:topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(),bo.getSendMsg()); + mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map)); + log.info("发送设备消息:topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo.getSendMsg()); UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq("id", deviceId) @@ -147,7 +148,7 @@ public class AppDeviceBizService { .set("update_time", new Date()) .set("binding_time", new Date()); return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper); - }else{ + } else { AppDeviceBindRecord bindRecord = new AppDeviceBindRecord(); bindRecord.setDeviceId(device.getId()); bindRecord.setBindingUserId(userId); @@ -183,7 +184,7 @@ public class AppDeviceBizService { .set("binding_user_id", userId) .set("binding_time", new Date()); return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper); - }else{ + } else { AppDeviceBindRecord bindRecord = new AppDeviceBindRecord(); bindRecord.setDeviceId(device.getId()); bindRecord.setBindingUserId(userId); @@ -204,7 +205,12 @@ public class AppDeviceBizService { } + public int unBindDevice(Long id) { + return unBindDevice(id, null, 1); + } + + public int unBindDevice(Long id, Long userId, int type) { Device device = deviceMapper.selectById(id); if (device == null) { throw new RuntimeException("请先将设备入库!!!"); @@ -216,18 +222,31 @@ public class AppDeviceBizService { .set("binding_time", null); deviceMapper.update(null, deviceUpdateWrapper); - Long userId = AppLoginHelper.getUserId(); + if (userId == null) { + userId = AppLoginHelper.getUserId(); + } QueryWrapper bindRecordQueryWrapper = new QueryWrapper<>(); bindRecordQueryWrapper.eq("device_id", device.getId()); - bindRecordQueryWrapper.eq("binding_user_id", userId); - AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper); - if (appDeviceBindRecord != null) { - return appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()); + // 设备端解绑 0:设备端解绑 1:web端解绑 + if (type == 1) { + bindRecordQueryWrapper.eq("binding_user_id", userId); + } + + // AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper); + // if (appDeviceBindRecord != null) { + // return appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()); + // } + + List appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(bindRecordQueryWrapper); + if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) { + appDeviceBindRecordList.forEach(appDeviceBindRecord -> + appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId())); } return 1; } + public AppDeviceDetailVo getInfo(Long id) { Device device = deviceMapper.selectById(id); if (device == null) { @@ -241,7 +260,7 @@ public class AppDeviceBizService { vo.setDeviceMac(device.getDeviceMac()); vo.setDeviceStatus(device.getDeviceStatus()); DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType()); - if(deviceType!=null){ + if (deviceType != null) { vo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode())); vo.setTypeName(deviceType.getTypeName()); } @@ -252,7 +271,7 @@ public class AppDeviceBizService { QueryWrapper qw = new QueryWrapper() .eq("device_id", device.getId()); AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectOne(qw); - if(appPersonnelInfo != null){ + if (appPersonnelInfo != null) { AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class); vo.setPersonnelInfo(personnelInfoVo); } @@ -281,24 +300,24 @@ public class AppDeviceBizService { // int[] a = new int[]{6,6,6,6,6,6}; ArrayList intData = new ArrayList<>(); intData.add(2); - buildArr(convertHexToDecimal(unitName),intData); - buildArr(convertHexToDecimal(position),intData); - buildArr(convertHexToDecimal(name),intData); - buildArr(convertHexToDecimal(id),intData); + buildArr(convertHexToDecimal(unitName), intData); + buildArr(convertHexToDecimal(position), intData); + buildArr(convertHexToDecimal(name), intData); + buildArr(convertHexToDecimal(id), intData); intData.add(0); intData.add(0); intData.add(0); intData.add(0); Map map = new HashMap<>(); map.put("instruct", intData); - System.out.println(JSON.toJSONString( map)); + System.out.println(JSON.toJSONString(map)); } public boolean registerPersonInfo(AppPersonnelInfoBo bo) { Long deviceId = bo.getDeviceId(); Device deviceObj = deviceMapper.selectById(deviceId); - if(deviceObj == null){ + if (deviceObj == null) { throw new RuntimeException("请先将设备入库!!!"); } QueryWrapper qw = new QueryWrapper() @@ -311,30 +330,30 @@ public class AppDeviceBizService { byte[] id = generateFixedBitmapData(bo.getCode(), 120); ArrayList intData = new ArrayList<>(); intData.add(2); - buildArr(convertHexToDecimal(unitName),intData); - buildArr(convertHexToDecimal(position),intData); - buildArr(convertHexToDecimal(name),intData); - buildArr(convertHexToDecimal(id),intData); + buildArr(convertHexToDecimal(unitName), intData); + buildArr(convertHexToDecimal(position), intData); + buildArr(convertHexToDecimal(name), intData); + buildArr(convertHexToDecimal(id), intData); intData.add(0); intData.add(0); intData.add(0); intData.add(0); Map map = new HashMap<>(); map.put("instruct", intData); - mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 , JSON.toJSONString( map)); - log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(),bo); + mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map)); + log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo); - if(ObjectUtils.length(appPersonnelInfoVos) == 0){ + if (ObjectUtils.length(appPersonnelInfoVos) == 0) { AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class); return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo); - }else { + } else { UpdateWrapper uw = new UpdateWrapper<>(); uw.eq("device_id", deviceId) .set("name", bo.getName()) .set("position", bo.getPosition()) .set("unit_name", bo.getUnitName()) - .set("code",bo.getCode()); - return appPersonnelInfoMapper.update(null, uw)>0; + .set("code", bo.getCode()); + return appPersonnelInfoMapper.update(null, uw) > 0; } @@ -343,20 +362,20 @@ public class AppDeviceBizService { public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) { try { Device device = deviceMapper.selectById(bo.getDeviceId()); - if(device == null){ + if (device == null) { throw new ServiceException("设备不存在"); } MultipartFile file = bo.getFile(); - byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80,25600); - System.out.println("长度:"+largeData.length); + byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600); + System.out.println("长度:" + largeData.length); System.out.println("原始数据大小: " + largeData.length + " 字节"); int[] ints = convertHexToDecimal(largeData); - RedisUtils.setCacheObject("app_logo_data:"+device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30*60L)); + RedisUtils.setCacheObject("app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L)); - String data = RedisUtils.getCacheObject("app_logo_data:"+device.getDeviceImei()); + String data = RedisUtils.getCacheObject("app_logo_data:" + device.getDeviceImei()); byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data); byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512); diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java index 5becac6..557191c 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java @@ -3,6 +3,7 @@ package com.fuyuanshen.global.mqtt.rule; import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.json.utils.JsonUtils; import com.fuyuanshen.common.redis.utils.RedisUtils; +import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil; import com.fuyuanshen.equipment.utils.c.map.GetAddressFromLatUtil; import com.fuyuanshen.equipment.utils.c.map.LngLonUtil; import com.fuyuanshen.global.mqtt.base.MqttMessageRule; diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/WEBDeviceController.java b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/WEBDeviceController.java new file mode 100644 index 0000000..eadb157 --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/controller/device/WEBDeviceController.java @@ -0,0 +1,46 @@ +package com.fuyuanshen.web.controller.device; + + +import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.common.web.core.BaseController; +import com.fuyuanshen.web.service.WEBDeviceService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +@Slf4j +@Tag(name = "web:设备管理", description = "web:设备管理") +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/device") +public class WEBDeviceController extends BaseController { + + private final WEBDeviceService deviceService; + + + /** + * @param id + * @return + * @ModelAttribute 主要用于将请求参数绑定到 Java 对象上,它会从 HTTP 请求的查询参数(Query Parameters) + * 或表单数据(Form Data)中提取值,并自动填充到指定的对象属性中。 + */ + // @Log("解绑设备") + @Operation(summary = "WEB端解绑设备") + @DeleteMapping(value = "/unbind") + public R unbindDevice(Long id, Long userId) { + return toAjax(deviceService.webUnBindDevice(id, userId)); + } + + +} + + diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/WEBDeviceService.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/WEBDeviceService.java new file mode 100644 index 0000000..0274717 --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/WEBDeviceService.java @@ -0,0 +1,32 @@ +package com.fuyuanshen.web.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.equipment.domain.Device; +import com.fuyuanshen.equipment.domain.dto.AppDeviceBo; +import com.fuyuanshen.equipment.domain.form.DeviceForm; +import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria; +import com.fuyuanshen.equipment.domain.vo.AppDeviceVo; +import com.fuyuanshen.equipment.domain.vo.CustomerVo; + +import java.io.IOException; +import java.util.List; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +public interface WEBDeviceService extends IService { + + /** + * WEB端解绑设备 + * + * @param id + * @return + */ + int webUnBindDevice(Long id, Long userId); + +} diff --git a/fys-admin/src/main/java/com/fuyuanshen/web/service/impl/WEBDeviceServiceImpl.java b/fys-admin/src/main/java/com/fuyuanshen/web/service/impl/WEBDeviceServiceImpl.java new file mode 100644 index 0000000..9f8e041 --- /dev/null +++ b/fys-admin/src/main/java/com/fuyuanshen/web/service/impl/WEBDeviceServiceImpl.java @@ -0,0 +1,51 @@ +package com.fuyuanshen.web.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fuyuanshen.app.service.AppDeviceBizService; +import com.fuyuanshen.equipment.domain.Device; +import com.fuyuanshen.equipment.domain.DeviceAssignments; +import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper; +import com.fuyuanshen.equipment.mapper.DeviceMapper; +import com.fuyuanshen.web.service.WEBDeviceService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +@Slf4j +@Service +@RequiredArgsConstructor +public class WEBDeviceServiceImpl extends ServiceImpl implements WEBDeviceService { + + private final AppDeviceBizService appDeviceService; + + private final DeviceAssignmentsMapper deviceAssignmentsMapper; + + + /** + * WEB端解绑设备 + * + * @param id + * @return + */ + @Override + public int webUnBindDevice(Long id, Long userId) { + // 设备端解绑 0:设备端解绑 1:web端解绑 + int type = 1; + if (userId == null) { + DeviceAssignments deviceAssignments = deviceAssignmentsMapper.selectById(id); + if (deviceAssignments == null) { + throw new RuntimeException("请先将设备入库!!!"); + } + id = deviceAssignments.getDeviceId(); + type = 0; + } + return appDeviceService.unBindDevice(id, userId, type); + } + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/controller/DeviceController.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/controller/DeviceController.java index 0e9f3de..229c2da 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/controller/DeviceController.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/controller/DeviceController.java @@ -147,19 +147,19 @@ public class DeviceController extends BaseController { return R.ok(); } - - /** - * @param id - * @return - * @ModelAttribute 主要用于将请求参数绑定到 Java 对象上,它会从 HTTP 请求的查询参数(Query Parameters) - * 或表单数据(Form Data)中提取值,并自动填充到指定的对象属性中。 - */ - // @Log("解绑设备") - @Operation(summary = "WEB端解绑设备") - @GetMapping(value = "/unbind") - public R unbindDevice(@Validated Long id) { - return toAjax(deviceService.webUnBindDevice(id)); - } + // + // /** + // * @param id + // * @return + // * @ModelAttribute 主要用于将请求参数绑定到 Java 对象上,它会从 HTTP 请求的查询参数(Query Parameters) + // * 或表单数据(Form Data)中提取值,并自动填充到指定的对象属性中。 + // */ + // // @Log("解绑设备") + // @Operation(summary = "WEB端解绑设备") + // @GetMapping(value = "/unbind") + // public R unbindDevice(@Validated Long id) { + // return toAjax(deviceService.webUnBindDevice(id)); + // } @Operation(summary = "导出数据设备") diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/controller/DeviceLogController.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/controller/DeviceLogController.java new file mode 100644 index 0000000..61b3c8a --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/controller/DeviceLogController.java @@ -0,0 +1,106 @@ +package com.fuyuanshen.equipment.controller; + +import java.util.List; + +import lombok.RequiredArgsConstructor; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.*; +import cn.dev33.satoken.annotation.SaCheckPermission; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit; +import com.fuyuanshen.common.log.annotation.Log; +import com.fuyuanshen.common.web.core.BaseController; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.fuyuanshen.common.core.domain.R; +import com.fuyuanshen.common.core.validate.AddGroup; +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.common.log.enums.BusinessType; +import com.fuyuanshen.common.excel.utils.ExcelUtil; +import com.fuyuanshen.equipment.domain.vo.DeviceLogVo; +import com.fuyuanshen.equipment.domain.bo.DeviceLogBo; +import com.fuyuanshen.equipment.service.IDeviceLogService; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; + +/** + * 设备日志 + * + * @author Lion Li + * @date 2025-07-29 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/equipment/log") +public class DeviceLogController extends BaseController { + + private final IDeviceLogService deviceLogService; + + /** + * 查询设备日志列表 + */ + @SaCheckPermission("equipment:log:list") + @GetMapping("/list") + public TableDataInfo list(DeviceLogBo bo, PageQuery pageQuery) { + return deviceLogService.queryPageList(bo, pageQuery); + } + + /** + * 导出设备日志列表 + */ + @SaCheckPermission("equipment:log:export") + @Log(title = "设备日志", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(DeviceLogBo bo, HttpServletResponse response) { + List list = deviceLogService.queryList(bo); + ExcelUtil.exportExcel(list, "设备日志", DeviceLogVo.class, response); + } + + /** + * 获取设备日志详细信息 + * + * @param id 主键 + */ + @SaCheckPermission("equipment:log:query") + @GetMapping("/{id}") + public R getInfo(@NotNull(message = "主键不能为空") + @PathVariable Long id) { + return R.ok(deviceLogService.queryById(id)); + } + + /** + * 新增设备日志 + */ + @SaCheckPermission("equipment:log:add") + @Log(title = "设备日志", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping() + public R add(@Validated(AddGroup.class) @RequestBody DeviceLogBo bo) { + return toAjax(deviceLogService.insertByBo(bo)); + } + + /** + * 修改设备日志 + */ + @SaCheckPermission("equipment:log:edit") + @Log(title = "设备日志", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping() + public R edit(@Validated(EditGroup.class) @RequestBody DeviceLogBo bo) { + return toAjax(deviceLogService.updateByBo(bo)); + } + + /** + * 删除设备日志 + * + * @param ids 主键串 + */ + @SaCheckPermission("equipment:log:remove") + @Log(title = "设备日志", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public R remove(@NotEmpty(message = "主键不能为空") + @PathVariable Long[] ids) { + return toAjax(deviceLogService.deleteWithValidByIds(List.of(ids), true)); + } + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceLog.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceLog.java index 2ccd0a3..0aaddb0 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceLog.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/DeviceLog.java @@ -1,40 +1,51 @@ package com.fuyuanshen.equipment.domain; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.bean.copier.CopyOptions; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.fuyuanshen.common.tenant.core.TenantEntity; +import com.baomidou.mybatisplus.annotation.*; +import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serial; /** - * @Description: - * @Author: WY - * @Date: 2025/5/24 - **/ + * 设备日志对象 device_log + * + * @author Lion Li + * @date 2025-07-29 + */ @Data +@EqualsAndHashCode(callSuper = true) @TableName("device_log") -public class DeviceLog extends TenantEntity { +public class DeviceLog extends BaseEntity { - @TableId(value = "id", type = IdType.AUTO) - // @Schema(value = "ID") + @Serial + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @TableId(value = "id") private Long id; - // @Schema(value = "设备行为") + /** + * 设备行为 + */ private String deviceAction; - // @Schema(value = "设备名称") + /** + * 设备名称 + */ private String deviceName; - // @Schema(value = "数据来源") + /** + * 数据来源 + */ private String dataSource; - // @Schema(value = "内容") + /** + * 内容 + */ private String content; - public void copy(DeviceLog source){ - BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); - } } diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceLogBo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceLogBo.java new file mode 100644 index 0000000..71900d5 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/bo/DeviceLogBo.java @@ -0,0 +1,49 @@ +package com.fuyuanshen.equipment.domain.bo; + +import com.fuyuanshen.common.core.validate.EditGroup; +import com.fuyuanshen.equipment.domain.DeviceLog; +import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; +import jakarta.validation.constraints.*; + +/** + * 设备日志业务对象 device_log + * + * @author Lion Li + * @date 2025-07-29 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceLog.class, reverseConvertGenerate = false) +public class DeviceLogBo extends BaseEntity { + + /** + * ID + */ + @NotNull(message = "ID不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 设备行为 + */ + private String deviceAction; + + /** + * 设备名称 + */ + private String deviceName; + + /** + * 数据来源 + */ + private String dataSource; + + /** + * 内容 + */ + private String content; + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceLogVo.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceLogVo.java new file mode 100644 index 0000000..cbfbc6a --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/domain/vo/DeviceLogVo.java @@ -0,0 +1,62 @@ +package com.fuyuanshen.equipment.domain.vo; + +import com.fuyuanshen.equipment.domain.DeviceLog; +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; +import cn.idev.excel.annotation.ExcelProperty; +import com.fuyuanshen.common.excel.annotation.ExcelDictFormat; +import com.fuyuanshen.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + + +/** + * 设备日志视图对象 device_log + * + * @author Lion Li + * @date 2025-07-29 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = DeviceLog.class) +public class DeviceLogVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @ExcelProperty(value = "ID") + private Long id; + + /** + * 设备行为 + */ + @ExcelProperty(value = "设备行为") + private String deviceAction; + + /** + * 设备名称 + */ + @ExcelProperty(value = "设备名称") + private String deviceName; + + /** + * 数据来源 + */ + @ExcelProperty(value = "数据来源") + private String dataSource; + + /** + * 内容 + */ + @ExcelProperty(value = "内容") + private String content; + + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceLogMapper.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceLogMapper.java new file mode 100644 index 0000000..adff5de --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/mapper/DeviceLogMapper.java @@ -0,0 +1,15 @@ +package com.fuyuanshen.equipment.mapper; + +import com.fuyuanshen.equipment.domain.DeviceLog; +import com.fuyuanshen.equipment.domain.vo.DeviceLogVo; +import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; + +/** + * 设备日志Mapper接口 + * + * @author Lion Li + * @date 2025-07-29 + */ +public interface DeviceLogMapper extends BaseMapperPlus { + +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceLogService.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceLogService.java new file mode 100644 index 0000000..5605d20 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/IDeviceLogService.java @@ -0,0 +1,68 @@ +package com.fuyuanshen.equipment.service; + +import com.fuyuanshen.equipment.domain.vo.DeviceLogVo; +import com.fuyuanshen.equipment.domain.bo.DeviceLogBo; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; + +import java.util.Collection; +import java.util.List; + +/** + * 设备日志Service接口 + * + * @author Lion Li + * @date 2025-07-29 + */ +public interface IDeviceLogService { + + /** + * 查询设备日志 + * + * @param id 主键 + * @return 设备日志 + */ + DeviceLogVo queryById(Long id); + + /** + * 分页查询设备日志列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备日志分页列表 + */ + TableDataInfo queryPageList(DeviceLogBo bo, PageQuery pageQuery); + + /** + * 查询符合条件的设备日志列表 + * + * @param bo 查询条件 + * @return 设备日志列表 + */ + List queryList(DeviceLogBo bo); + + /** + * 新增设备日志 + * + * @param bo 设备日志 + * @return 是否新增成功 + */ + Boolean insertByBo(DeviceLogBo bo); + + /** + * 修改设备日志 + * + * @param bo 设备日志 + * @return 是否修改成功 + */ + Boolean updateByBo(DeviceLogBo bo); + + /** + * 校验并批量删除设备日志信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceLogServiceImpl.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceLogServiceImpl.java new file mode 100644 index 0000000..60d46df --- /dev/null +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceLogServiceImpl.java @@ -0,0 +1,135 @@ +package com.fuyuanshen.equipment.service.impl; + +import com.fuyuanshen.common.core.utils.MapstructUtils; +import com.fuyuanshen.common.mybatis.core.page.TableDataInfo; +import com.fuyuanshen.common.mybatis.core.page.PageQuery; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import com.fuyuanshen.equipment.domain.bo.DeviceLogBo; +import com.fuyuanshen.equipment.domain.vo.DeviceLogVo; +import com.fuyuanshen.equipment.domain.DeviceLog; +import com.fuyuanshen.equipment.mapper.DeviceLogMapper; +import com.fuyuanshen.equipment.service.IDeviceLogService; + +import java.util.List; +import java.util.Map; +import java.util.Collection; + +/** + * 设备日志Service业务层处理 + * + * @author Lion Li + * @date 2025-07-29 + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class DeviceLogServiceImpl implements IDeviceLogService { + + private final DeviceLogMapper baseMapper; + + /** + * 查询设备日志 + * + * @param id 主键 + * @return 设备日志 + */ + @Override + public DeviceLogVo queryById(Long id){ + return baseMapper.selectVoById(id); + } + + /** + * 分页查询设备日志列表 + * + * @param bo 查询条件 + * @param pageQuery 分页参数 + * @return 设备日志分页列表 + */ + @Override + public TableDataInfo queryPageList(DeviceLogBo bo, PageQuery pageQuery) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result); + } + + /** + * 查询符合条件的设备日志列表 + * + * @param bo 查询条件 + * @return 设备日志列表 + */ + @Override + public List queryList(DeviceLogBo bo) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + return baseMapper.selectVoList(lqw); + } + + private LambdaQueryWrapper buildQueryWrapper(DeviceLogBo bo) { + Map params = bo.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.orderByAsc(DeviceLog::getId); + lqw.eq(StringUtils.isNotBlank(bo.getDeviceAction()), DeviceLog::getDeviceAction, bo.getDeviceAction()); + lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), DeviceLog::getDeviceName, bo.getDeviceName()); + lqw.eq(StringUtils.isNotBlank(bo.getDataSource()), DeviceLog::getDataSource, bo.getDataSource()); + lqw.eq(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent()); + return lqw; + } + + /** + * 新增设备日志 + * + * @param bo 设备日志 + * @return 是否新增成功 + */ + @Override + public Boolean insertByBo(DeviceLogBo bo) { + DeviceLog add = MapstructUtils.convert(bo, DeviceLog.class); + validEntityBeforeSave(add); + boolean flag = baseMapper.insert(add) > 0; + if (flag) { + bo.setId(add.getId()); + } + return flag; + } + + /** + * 修改设备日志 + * + * @param bo 设备日志 + * @return 是否修改成功 + */ + @Override + public Boolean updateByBo(DeviceLogBo bo) { + DeviceLog update = MapstructUtils.convert(bo, DeviceLog.class); + validEntityBeforeSave(update); + return baseMapper.updateById(update) > 0; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(DeviceLog entity){ + //TODO 做一些数据校验,如唯一约束 + } + + /** + * 校验并批量删除设备日志信息 + * + * @param ids 待删除的主键集合 + * @param isValid 是否进行有效性校验 + * @return 是否删除成功 + */ + @Override + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + if(isValid){ + //TODO 做一些业务上的校验,判断是否需要校验 + } + return baseMapper.deleteByIds(ids) > 0; + } +} diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/c/map/GetAddressFromLatUtil.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/map/GetAddressFromLatUtil.java similarity index 98% rename from fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/c/map/GetAddressFromLatUtil.java rename to fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/map/GetAddressFromLatUtil.java index c0fa47c..2744977 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/c/map/GetAddressFromLatUtil.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/map/GetAddressFromLatUtil.java @@ -1,4 +1,4 @@ -package com.fuyuanshen.equipment.utils.c.map; +package com.fuyuanshen.equipment.utils.map; import com.alibaba.fastjson2.JSONObject; import lombok.Data; diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/c/map/LngLonUtil.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/map/LngLonUtil.java similarity index 99% rename from fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/c/map/LngLonUtil.java rename to fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/map/LngLonUtil.java index 51aa345..397e4b6 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/c/map/LngLonUtil.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/utils/map/LngLonUtil.java @@ -1,4 +1,4 @@ -package com.fuyuanshen.equipment.utils.c.map; +package com.fuyuanshen.equipment.utils.map; /** * @author: 默苍璃 diff --git a/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceLogMapper.xml b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceLogMapper.xml new file mode 100644 index 0000000..d4c99d6 --- /dev/null +++ b/fys-modules/fys-equipment/src/main/resources/mapper/equipment/DeviceLogMapper.xml @@ -0,0 +1,7 @@ + + + + +