diff --git a/fys-common/fys-common-encrypt/src/main/java/com/fuyuanshen/common/encrypt/utils/EncryptUtilsTest.java b/fys-common/fys-common-encrypt/src/main/java/com/fuyuanshen/common/encrypt/utils/EncryptUtilsTest.java index 06b72d0..bb7413d 100644 --- a/fys-common/fys-common-encrypt/src/main/java/com/fuyuanshen/common/encrypt/utils/EncryptUtilsTest.java +++ b/fys-common/fys-common-encrypt/src/main/java/com/fuyuanshen/common/encrypt/utils/EncryptUtilsTest.java @@ -39,8 +39,8 @@ public class EncryptUtilsTest { loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e"); loginBody.setGrantType("password"); loginBody.setTenantId("894078"); - loginBody.setCode("9"); - loginBody.setUuid("64d5a9107e4949f3ba8f57ede00bd034"); + loginBody.setCode("10"); + loginBody.setUuid("390942eb87174dcc9c2c074b066b1b79"); // loginBody.setUsername("admin"); // loginBody.setPassword("admin123"); loginBody.setUsername("dyf"); diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/controller/equipment/APPDeviceController.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/controller/equipment/APPDeviceController.java new file mode 100644 index 0000000..df1098f --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/controller/equipment/APPDeviceController.java @@ -0,0 +1,89 @@ +package com.fuyuanshen.app.controller.equipment; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuyuanshen.app.domain.APPDevice; +import com.fuyuanshen.app.domain.APPDeviceType; +import com.fuyuanshen.app.domain.dto.APPUnbindDTO; +import com.fuyuanshen.app.domain.query.APPDeviceQueryCriteria; +import com.fuyuanshen.app.service.equipment.APPDeviceService; +import com.fuyuanshen.common.core.domain.PageResult; +import com.fuyuanshen.common.core.domain.ResponseVO; +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +@Slf4j +@Tag(name = "APP:客户设备管理", description = "APP:客户设备管理") +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/app/device") +public class APPDeviceController { + + private final APPDeviceService appDeviceService; + + + @PostMapping(value = "/list") + @Operation(summary = "APP客户设备列表") + public ResponseVO> appDeviceList(@RequestBody APPDeviceQueryCriteria criteria) { + Page page = new Page<>(criteria.getPage(), criteria.getSize()); + PageResult devices = null; + try { + devices = appDeviceService.appDeviceList(page, criteria); + } catch (Exception e) { + log.error("queryDevice error: " + e.getMessage()); + return ResponseVO.fail(""); + } + return ResponseVO.success(devices); + } + + + @PostMapping(value = "/typeList") + @Operation(summary = "APP客户设备类型列表") + public ResponseVO> appTypeList(@RequestBody APPDeviceQueryCriteria criteria) { + List typeList = appDeviceService.appTypeList(criteria); + return ResponseVO.success(typeList); + } + + + @PostMapping(value = "/bind") + @Operation(summary = "APP客户设备绑定") + public ResponseVO appBindDevice(@RequestBody APPDeviceQueryCriteria criteria) { + appDeviceService.appBindDevice(criteria); + return ResponseVO.success("绑定成功!"); + } + + + @GetMapping + @Operation(summary = "WEB端查看APP客户设备绑定") + public ResponseVO> queryAPPDevice(APPDeviceQueryCriteria criteria) { + Page page = new Page<>(criteria.getPage(), criteria.getSize()); + PageResult devices = null; + try { + devices = appDeviceService.queryAll(page, criteria); + } catch (Exception e) { + log.error("queryDevice error: " + e.getMessage()); + return ResponseVO.fail(""); + } + return ResponseVO.success(devices); + } + + + @PostMapping(value = "/unbind") + @Operation(summary = "WEB端APP客户设备解绑") + public ResponseVO unbindAPPDevice(@Validated @ModelAttribute APPUnbindDTO deviceForm) { + appDeviceService.unbindAPPDevice(deviceForm); + return ResponseVO.success("解绑成功!!!"); + } + + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/APPDevice.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/APPDevice.java new file mode 100644 index 0000000..a7e1537 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/APPDevice.java @@ -0,0 +1,106 @@ +package com.fuyuanshen.app.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.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fuyuanshen.common.tenant.core.TenantEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * @Description: 设备表 + * @Author: WY + * @Date: 2025/5/16 + **/ +@Data +@TableName("app_device") +public class APPDevice extends TenantEntity { + + @TableId(value = "app_device_id", type = IdType.AUTO) + @Schema(name = "ID") + private Long id; + + @Schema(name = "设备类型") + private Long deviceType; + + @Schema(name = "设备类型名称") + private String deviceTypeName; + + @Schema(name = "客户号") + private Long customerId; + + @Schema(name = "所属客户") + private String customerName; + + /*@Schema(name = "设备编号") + private String deviceNo;*/ + + @Schema(name = "设备名称") + private String deviceName; + + @Schema(name = "设备图片") + private String devicePic; + + @Schema(name = "设备MAC") + private String deviceMac; + + @Schema(name = "设备IMEI") + private String deviceImei; + + @Schema(name = "设备SN") + private String deviceSn; + + @Schema(name = "经度") + private String longitude; + + @Schema(name = "纬度") + private String latitude; + + @Schema(name = "备注") + private String remark; + + @TableField(exist = false) + @Schema(name = "设备类型名称") + private String typeName; + + /** + * 租户ID + */ + @TableField(value = "tenant_id") + @Schema(hidden = true) + private String tenantId; + + /** + * 设备状态 + * 0 失效 + * 1 正常 + */ + @Schema(name = "设备状态") + private Integer deviceStatus; + + /** + * 绑定状态 + * 0 未绑定 + * 1 已绑定 + */ + @Schema(name = "绑定状态") + private Integer bindingStatus; + + /** + * 绑定类型 + * 0 APP + * 1 小程序 + */ + @Schema(name = "绑定类型") + private Integer bindingType; + + + public void copy(APPDevice source) { + BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true)); + } + + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/APPDeviceType.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/APPDeviceType.java new file mode 100644 index 0000000..ce56330 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/APPDeviceType.java @@ -0,0 +1,56 @@ +package com.fuyuanshen.app.domain; + +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 io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description: 设备类型 + * @Author: WY + * @Date: 2025/5/14 + **/ +@Data +@TableName("app_device_type") +public class APPDeviceType extends TenantEntity { + + @TableId(value = "id", type = IdType.AUTO) + @Schema(name = "ID", hidden = true) + private Long id; + + @Schema(name = "客户号") + private Long customerId; + + @Schema(name = "创建该类型的客户") + private Long ownerCustomerId; + + /** + * 租户ID + */ + // @TableField(value = "tenant_id") + // @ApiModelProperty(hidden = true) + // private Long tenantId; + + @NotBlank(message = "设备类型名称不能为空") + @Schema(name = "类型名称", required = true) + private String typeName; + + @Schema(name = "是否支持蓝牙") + private Boolean isSupportBle; + + @Schema(name = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗") + private String locateMode; + + @Schema(name = "联网方式", example = "0:无;1:4G;2:WIFI") + private String networkWay; + + @Schema(name = "通讯方式", example = "0:4G;1:蓝牙") + private String communicationMode; + + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/dto/APPUnbindDTO.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/dto/APPUnbindDTO.java new file mode 100644 index 0000000..40dc18e --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/dto/APPUnbindDTO.java @@ -0,0 +1,26 @@ +package com.fuyuanshen.app.domain.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + + +/** + * @author: 默苍璃 + * @date: 2025-06-1818:36 + */ +@Data +public class APPUnbindDTO { + + // @NotBlank(message = "设备MAC不能为空") + @Schema(name = "设备MAC", required = true) + private String deviceMac; + + @Schema(name = "设备IMEI") + private String deviceImei; + + @NotNull(message = "客户号不能为空") + @Schema(name = "客户号") + private Long customerId; + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/query/APPDeviceQueryCriteria.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/query/APPDeviceQueryCriteria.java new file mode 100644 index 0000000..11d4411 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/domain/query/APPDeviceQueryCriteria.java @@ -0,0 +1,65 @@ +package com.fuyuanshen.app.domain.query; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.sql.Timestamp; +import java.util.List; +import java.util.Set; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +@Data +public class APPDeviceQueryCriteria { + + @Schema(name = "设备名称") + private String deviceName; + + @Schema(name = "设备类型") + private Long deviceType; + + @Schema(name = "设备MAC") + private String deviceMac; + + @Schema(name = "设备IMEI") + private String deviceImei; + + @Schema(name = "设备SN") + private String deviceSn; + + /** + * 设备状态 + * 0 失效 + * 1 正常 + */ + @Schema(name = "设备状态 0 失效 1 正常 ") + private Integer deviceStatus; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") + @Schema(name = "创建时间") + private List createTime; + + @Schema(name = "页码", example = "1") + private Integer page = 1; + + @Schema(name = "每页数据量", example = "10") + private Integer size = 10; + + @Schema(name = "客户id") + private Long customerId; + private Set customerIds; + + @Schema(name = "当前所有者") + private Long currentOwnerId; + + @Schema(name = "租户ID") + private Long tenantId; + + @Schema(name = "通讯方式", example = "0:4G;1:蓝牙") + private Integer communicationMode; + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/equipment/APPDeviceMapper.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/equipment/APPDeviceMapper.java new file mode 100644 index 0000000..0ccf897 --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/mapper/equipment/APPDeviceMapper.java @@ -0,0 +1,39 @@ +package com.fuyuanshen.app.mapper.equipment; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuyuanshen.app.domain.APPDevice; +import com.fuyuanshen.app.domain.query.APPDeviceQueryCriteria; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +@Mapper +public interface APPDeviceMapper extends BaseMapper { + + /** + * APP用户设备列表 + * + * @param page + * @param criteria + * @return + */ + IPage appDeviceList(Page page,@Param("criteria") APPDeviceQueryCriteria criteria); + + + /** + * 分页查询APP/小程序设备 + * + * @param criteria + * @param page + * @return + */ + IPage queryAll(Page page, @Param("criteria") APPDeviceQueryCriteria criteria); + + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/equipment/APPDeviceService.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/equipment/APPDeviceService.java new file mode 100644 index 0000000..3f7160d --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/equipment/APPDeviceService.java @@ -0,0 +1,60 @@ +package com.fuyuanshen.app.service.equipment; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.fuyuanshen.app.domain.APPDevice; +import com.fuyuanshen.app.domain.APPDeviceType; +import com.fuyuanshen.app.domain.dto.APPUnbindDTO; +import com.fuyuanshen.app.domain.query.APPDeviceQueryCriteria; +import com.fuyuanshen.common.core.domain.PageResult; + +import java.util.List; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +public interface APPDeviceService extends IService { + + /** + * APP用户设备列表 + * + * @param criteria + */ + PageResult appDeviceList(Page page, APPDeviceQueryCriteria criteria); + + + /** + * APP用户设备类型列表 + * + * @param criteria + * @return + */ + List appTypeList(APPDeviceQueryCriteria criteria); + + /** + * APP/小程序用户设备绑定 + * + * @param criteria + */ + void appBindDevice(APPDeviceQueryCriteria criteria); + + /** + * 分页查询APP/小程序设备绑定 + * + * @param criteria + * @param page + * @return + */ + PageResult queryAll(Page page, APPDeviceQueryCriteria criteria); + + /** + * APP/小程序用户设备解绑 + * + * @param deviceForm + */ + void unbindAPPDevice(APPUnbindDTO deviceForm); + + +} diff --git a/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/equipment/APPDeviceServiceImpl.java b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/equipment/APPDeviceServiceImpl.java new file mode 100644 index 0000000..d5c659b --- /dev/null +++ b/fys-modules/fys-app/src/main/java/com/fuyuanshen/app/service/impl/equipment/APPDeviceServiceImpl.java @@ -0,0 +1,182 @@ +package com.fuyuanshen.app.service.impl.equipment; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fuyuanshen.app.domain.APPDevice; +import com.fuyuanshen.app.domain.APPDeviceType; +import com.fuyuanshen.app.domain.dto.APPUnbindDTO; +import com.fuyuanshen.app.domain.query.APPDeviceQueryCriteria; +import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper; +import com.fuyuanshen.app.service.equipment.APPDeviceService; +import com.fuyuanshen.common.core.domain.PageResult; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Description: + * @Author: WY + * @Date: 2025/5/16 + **/ +@Slf4j +@Service +@RequiredArgsConstructor +public class APPDeviceServiceImpl extends ServiceImpl implements APPDeviceService { + + private final APPDeviceMapper appDeviceMapper; + + + /** + * APP用户设备列表 + * + * @param criteria + */ + @Override + public PageResult appDeviceList(Page page, APPDeviceQueryCriteria criteria) { + // criteria.setCustomerId(SecurityUtils.getCurrentUserId()); + // IPage devices = appDeviceMapper.appDeviceList(page, criteria); + // return new PageResult<>(devices.getRecords(), devices.getTotal()); + return null; + } + + + /** + * APP用户设备类型列表 + * + * @param criteria + * @return + */ + @Override + public List appTypeList(APPDeviceQueryCriteria criteria) { + // criteria.setCustomerId(SecurityUtils.getCurrentUserId()); + // return appDeviceTypeMapper.appTypeList(criteria); + return null; + } + + + /** + * APP/小程序用户设备绑定 + * + * @param criteria + */ + @Override + @Transactional + public void appBindDevice(APPDeviceQueryCriteria criteria) { + // + // List devices = new ArrayList<>(); + // + // if (criteria.getCommunicationMode().equals(CommunicationModeEnum.BLUETOOTH.getValue())) { + // devices = deviceMapper.selectList(new QueryWrapper().eq("device_mac", criteria.getDeviceMac())); + // if (CollectionUtil.isEmpty(devices)) { + // throw new BadRequestException("请先将设备入库!!!"); + // } + // List appDevices = appDeviceMapper.selectList(new QueryWrapper() + // .eq("device_mac", criteria.getDeviceMac()).eq("binding_type", UserType.APP.getValue())); + // if (CollectionUtil.isNotEmpty(appDevices)) { + // throw new BadRequestException("该设备已绑定!!!"); + // } + // } + // + // if (criteria.getCommunicationMode().equals(CommunicationModeEnum.FOUR_G.getValue())) { + // devices = deviceMapper.selectList(new QueryWrapper().eq("device_imei", criteria.getDeviceImei())); + // if (CollectionUtil.isEmpty(devices)) { + // throw new BadRequestException("请先将设备入库!!!"); + // } + // List appDevices = appDeviceMapper.selectList(new QueryWrapper() + // .eq("device_imei", criteria.getDeviceImei()).eq("binding_type", UserType.APP.getValue())); + // if (CollectionUtil.isNotEmpty(appDevices)) { + // throw new BadRequestException("该设备已绑定!!!"); + // } + // } + // + // Device device = devices.get(0); + // device.setBindingStatus(BindingStatusEnum.BOUND.getCode()); + // deviceMapper.updateById(device); + // + // APPDevice appDevice = new APPDevice(); + // BeanUtil.copyProperties(device, appDevice); + // appDevice.setBindingType(UserType.APP.getValue()); + // appDevice.setBindingStatus(BindingStatusEnum.BOUND.getCode()); + // Long currentUserId = SecurityUtils.getCurrentUserId(); + // appDevice.setCustomerId(currentUserId); + // appDevice.setCreateTime(new Timestamp(System.currentTimeMillis())); + // // 设备类型名称 + // appDevice.setDeviceTypeName(device.getTypeName()); + // appDeviceMapper.insert(appDevice); + // + // APPDeviceType appDeviceType = appDeviceTypeMapper.selectById(device.getDeviceType()); + // if (appDeviceType == null) { + // DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType()); + // APPDeviceType type = new APPDeviceType(); + // BeanUtil.copyProperties(deviceType, type); + // type.setCustomerId(currentUserId); + // appDeviceTypeMapper.insert(type); + // } + + } + + + /** + * 分页查询APP/小程序设备 + * + * @param criteria + * @param page + * @return + */ + @Override + public PageResult queryAll(Page page, APPDeviceQueryCriteria criteria) { + // IPage devices = appDeviceMapper.queryAll(page, criteria); + // return new PageResult<>(devices.getRecords(), devices.getTotal()); + + return null; + } + + + /** + * APP/小程序用户设备解绑 + * + * @param deviceForm + */ + @Override + @Transactional + public void unbindAPPDevice(APPUnbindDTO deviceForm) { + // QueryWrapper queryWrapper = new QueryWrapper<>(); + // QueryWrapper qw = new QueryWrapper<>(); + // if (StringUtils.isNotEmpty(deviceForm.getDeviceMac())) { + // queryWrapper.eq("device_mac", deviceForm.getDeviceMac()); + // qw.eq("device_mac", deviceForm.getDeviceMac()); + // } + // if (StringUtils.isNotEmpty(deviceForm.getDeviceImei())) { + // queryWrapper.eq("device_imei", deviceForm.getDeviceImei()); + // qw.eq("device_imei", deviceForm.getDeviceImei()); + // } + // queryWrapper.eq("binding_type", UserType.APP.getValue()); + // APPDevice appDevice = appDeviceMapper.selectOne(queryWrapper); + // appDeviceMapper.delete(queryWrapper); + // + // List devices = deviceMapper.selectList(qw); + // List ids = devices.stream() + // .map(Device::getId) + // .collect(Collectors.toList()); + // if (CollectionUtil.isNotEmpty(ids)) { + // appDeviceTypeMapper.deleteBatchIds(ids); + // } + // Device device = new Device(); + // device.setId(appDevice.getId()); + // device.setBindingStatus(BindingStatusEnum.UNBOUND.getCode()); + // deviceMapper.updateById(device); + + } + + +} diff --git a/fys-modules/fys-app/src/main/resources/mapper/app/equipment/APPDeviceMapper.xml b/fys-modules/fys-app/src/main/resources/mapper/app/equipment/APPDeviceMapper.xml new file mode 100644 index 0000000..27b0ac9 --- /dev/null +++ b/fys-modules/fys-app/src/main/resources/mapper/app/equipment/APPDeviceMapper.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file