diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/constant/DeviceModelConstants.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/constant/DeviceModelConstants.java new file mode 100644 index 0000000..830afcd --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/constant/DeviceModelConstants.java @@ -0,0 +1,94 @@ +package com.ecell.internationalize.system.constant; + +public class DeviceModelConstants { + public static final String ZERO ="0"; + public static final String ONE ="1"; + public static final String TWO ="2"; + public static final String THREE ="3"; + public static final String FOUR ="4"; + public static final String TWO_ZERO ="20000"; + public static final String JU_FENG ="菊风"; + public static final String SHENG_WANG ="声网"; + public static final String BAI_RUI ="佰锐"; + public static final String TI_HU ="鹈鹕"; + public static final String VIDEO_CALL="视频通话规则"; + public static final String DEFAULT_CONFIG="(默认配置)"; + public static final String WATCH_ALARM_CLOCK="手表闹钟"; + public static final String CLASS_DISABLE="上课禁用"; + public static final String SOS_PHONE="sos号码"; + public static final String ELECTRONIC_FENCE="电子围栏"; + public static final String STEP_RECORDER="计步"; + public static final String CHAT_FUN="微聊"; + public static final String LOOKUP_FUN="查找设备"; + public static final String WATCH_WIFF="手表WIFI"; + public static final String HEART_RATE="心率"; + public static final String TEMPERATURE="体温"; + public static final String BLOOD_PRESSURE="血压"; + public static final String BLOOD_OXYGEN="血氧"; + public static final String WHITE_LIST="白名单"; + public static final String DIAL="拨号盘"; + public static final String TIMING_SWITCH="定时开关机"; + public static final String TELECOM="电信"; + + public static final String MINUTE="分钟"; + + public static final String USER_NAME="admin"; + + public static final String DELLETE_MODE_ZERO ="根据imei批量删除"; + public static final String DELLETE_MODE_ONE ="根据IMEI导入删除"; + + public static final String UNBING_MODE_ZERO ="根据imei单个解绑"; + public static final String UNBING_MODE_ONE ="根据IMEI批量解绑"; + + /** 校验返回结果码 */ + public final static String UNIQUE = "0"; + + public final static String NOT_UNIQUE = "1"; + + + /** + * 用户ID字段 + */ + public static final String DETAILS_USER_ID = "user_id"; + + /** + * 用户名字段 + */ + public static final String DETAILS_USERNAME = "username"; + + /** + * 授权信息字段 + */ + public static final String AUTHORIZATION_HEADER = "authorization"; + + /** + * 请求来源 + */ + public static final String FROM_SOURCE = "from-source"; + + /** + * 内部请求 + */ + public static final String INNER = "inner"; + + /** + * 用户标识 + */ + public static final String USER_KEY = "user_key"; + + /** + * 登录用户 + */ + public static final String LOGIN_USER = "login_user"; + + public static final int NUMBER_ZERO =0; + public static final int NUMBER_ONE =1; + + /** redis key*/ + public static final String AGENT="agent"; + public static final String V="v"; + + /**TCP-TOPIC*/ + public static final String WATCHPUSH_KAFKA="jianyou_tongxin_WatchPUSH_Kafka"; + +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/controller/DeviceInfoController.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/controller/DeviceInfoController.java new file mode 100644 index 0000000..4104056 --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/controller/DeviceInfoController.java @@ -0,0 +1,377 @@ +package com.ecell.internationalize.system.controller; +import com.ecell.internationalize.common.core.context.SecurityContextHolder; +import com.ecell.internationalize.common.core.exception.ServiceException; +import com.ecell.internationalize.common.core.utils.StringUtils; +import com.ecell.internationalize.common.core.utils.locale.LocaleUtil; +import com.ecell.internationalize.common.core.utils.poi.ExcelUtil; +import com.ecell.internationalize.common.core.web.domain.AjaxResult; +import com.ecell.internationalize.common.security.annotation.RequiresPermissions; +import com.ecell.internationalize.common.security.utils.SecurityUtils; +import com.ecell.internationalize.common.system.constant.FieldConstant; +import com.ecell.internationalize.system.annotation.DelImeiLog; +import com.ecell.internationalize.system.annotation.FactoryLog; +import com.ecell.internationalize.system.annotation.InputLog; +import com.ecell.internationalize.system.constant.DeviceModelConstants; +import com.ecell.internationalize.system.entity.DeviceInfo; +import com.ecell.internationalize.system.entity.dto.*; +import com.ecell.internationalize.system.service.DeviceInfoService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +/** + *

+ * 设备信息表 前端控制器 + *

+ * + * @author ${author} + * @since 2022-07-10 + */ +@Api(value="设备管理",tags={"设备管理接口"}) +@RestController +@RequestMapping("/device-info") +public class DeviceInfoController { + @Autowired + private DeviceInfoService deviceInfoService; + + /** + * 设备单个录入 + * @return + */ + @InputLog(inputType = DeviceModelConstants.ZERO) //如果是单个录入 + @PostMapping("/input/imei") + public AjaxResult singleEntry(@RequestBody DeviceDTO dto){ + return deviceInfoService.singleEntry(dto) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + } + + /** + * 设备批量录入 + * @return + */ + @InputLog(inputType = DeviceModelConstants.ONE) //如果是批量录入 + @PostMapping("/import/imei") + public AjaxResult importImei(MultipartFile file, DeviceDTO dto) throws Exception{ + if (!StringUtils.isNotEmpty(dto.getDeviceModelId())){ + throw new ServiceException("messages.parameter.error"); + } + if (!StringUtils.isNotEmpty(dto.getFirmId())){ + throw new ServiceException("messages.parameter.error"); + } + + ExcelUtil util = new ExcelUtil(DeviceDTO.class); + if (StringUtils.isNull(file)){ + throw new ServiceException("接收到的 MultipartFile 为空,请重试"); + } + List imeiList = util.importExcel(file.getInputStream()); + + + return AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS), deviceInfoService.importImei(imeiList,dto)); + + + } + + /** + * 设备批量录入 + * @return + */ + @InputLog(inputType = DeviceModelConstants.ONE) //如果是批量录入 + @PostMapping("/import/imei/two") + public AjaxResult importImeiTwo(MultipartFile file, DeviceDTO dto) throws Exception{ + if (!StringUtils.isNotEmpty(dto.getDeviceModelId())){ + throw new ServiceException("messages.parameter.error"); + } + if (!StringUtils.isNotEmpty(dto.getFirmId())){ + throw new ServiceException("messages.parameter.error"); + } + + ExcelUtil util = new ExcelUtil(DeviceDTO.class); + if (StringUtils.isNull(file)){ + throw new ServiceException("接收到的 MultipartFile 为空,请重试"); + } + List imeiList = util.importExcel(file.getInputStream()); + + + return AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS), deviceInfoService.importImeiTwo(file,imeiList,dto)); + + + } + + + + /** + * 设备分页查询 + * @return + */ + @GetMapping("/page/list") + public AjaxResult queryByPageList(DevicePageDTO dto) { + + return AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS), deviceInfoService.queryByPageList(dto)); + + } + + + /** + * 设备审核 + * @return + */ + @RequiresPermissions(value="system:equipmentexamination:list") + @GetMapping("/update/status/{id}/{status}") + public AjaxResult updateStatus(@PathVariable String id,@PathVariable String status){ + + return deviceInfoService.updateStatus(id,status) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + + } + + + /** + * 设备批次审核 + * @return + */ + @RequiresPermissions(value="system:equipmentexamination:list") + @GetMapping("/update/inputBach/status/{inputBach}/{status}") + public AjaxResult updateInputBachStatus(@PathVariable String inputBach,@PathVariable String status){ + + return deviceInfoService.updateInputBachStatus(inputBach,status) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + + } + + /** + * 根据批次号分页查询 + * @param dto + * @return + */ + @GetMapping("/query/inputBach/List") + public AjaxResult queryInputBatchList(DevicePageDTO dto){ + + return AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS),deviceInfoService.queryInputBatchList(dto)); + + } + + + /** + * 批次初始化 + * @return + */ + @GetMapping("/update/initInputBach") + public AjaxResult initInputBach(){ + + return AjaxResult.success(deviceInfoService.initInputBach()); + + } + + + + + /** + * 分页查询设备激活信息 + * @return + */ + @PostMapping("/query/list") + public AjaxResult queryActivationInfoPageList(@RequestBody DeviceActivaPageDTO dto) { + + return AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS), deviceInfoService.queryActivationInfoPageList(dto)); + + + } + + + + /** + * 根据设备Imei批量删除设备 + * @return + */ + @DelImeiLog(delType = DeviceModelConstants.ZERO) + @DeleteMapping("/del/list") + public AjaxResult delDeviceByIds(@RequestBody List imeis) { + + if (!SecurityUtils.isAdminString(SecurityContextHolder.getStringUserId()) && imeis.size()>1){ + // 不是管理员只能删除单个设备 + throw new ServiceException("messages.delete.device.sing.error"); + } + return deviceInfoService.delDeviceByIds(imeis) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + + + } + + + + /** + * 根据设备IMEI批量删除设备(导入删除) + * @return + */ + @DelImeiLog(delType = DeviceModelConstants.ONE) + @DeleteMapping("/del/imei") + public AjaxResult delDeviceByImei(MultipartFile file) throws Exception { + ExcelUtil util = new ExcelUtil(DeviceDTO.class); + if (StringUtils.isNull(file)){ + throw new ServiceException("接收到的 MultipartFile 为空,请重试"); + } + List imeiList = util.importExcel(file.getInputStream()); + if (StringUtils.isEmpty(imeiList) || imeiList.size()<=0){ + throw new ServiceException("接收到的 参数 为空,请重试"); + } + List imeis = imeiList.parallelStream().filter(s->StringUtils.isNotEmpty(s.getImei())).map(DeviceDTO::getImei).collect(Collectors.toList()); + + return deviceInfoService.delDeviceByImei(imeis,DeviceModelConstants.ZERO) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + + } + + + /** + * 根据设备批次删除设备 + * @return + */ + @DelImeiLog(delType = DeviceModelConstants.ZERO) + @DeleteMapping("/del/inputBach/list/{inputBach}") + public AjaxResult delDeviceInputBach(@PathVariable String inputBach) { + //根据批次号查询设备 + List infos = deviceInfoService.queryInputBatchListTwo(inputBach); + List imeiList=new ArrayList<>(); + if (StringUtils.isNotEmpty(infos) && infos.size()>0){ + imeiList = infos.stream().map(DeviceInfo::getImei).collect(Collectors.toList()); + } + + if (!SecurityUtils.isAdminString(SecurityContextHolder.getStringUserId()) && imeiList.size()>1){ + // 不是管理员只能删除单个设备 + throw new ServiceException("messages.delete.device.sing.error"); + } + return deviceInfoService.delDeviceByIds(imeiList) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + + + } + + /** + * 单个设备Imei解绑 + * @return + */ + @FactoryLog + @GetMapping("/device/unBing/{imei}") + public AjaxResult deviceUnBingByImei(@PathVariable String imei) { + return deviceInfoService.deviceUnBingByImei(imei,DeviceModelConstants.ONE) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + + + } + + /** + * 批量设备Imei解绑 + * @return + */ + @FactoryLog(unBingType = DeviceModelConstants.ONE) + @PostMapping("/device/unBing/list") + public AjaxResult deviceUnBingListByImei(MultipartFile file) throws Exception { + ExcelUtil util = new ExcelUtil(DeviceDTO.class); + if (StringUtils.isNull(file)){ + throw new ServiceException("接收到的 MultipartFile 为空,请重试"); + } + List imeiList = util.importExcel(file.getInputStream()); + if (StringUtils.isEmpty(imeiList) || imeiList.size()<=0){ + throw new ServiceException("接收到的 参数 为空,请重试"); + } + List list = imeiList.parallelStream().filter(s->StringUtils.isNotEmpty(s.getImei())).map(DeviceDTO::getImei).collect(Collectors.toList()); + return deviceInfoService.delDeviceByImei(list,DeviceModelConstants.ONE) ? AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : AjaxResult.error(LocaleUtil.getMessage(FieldConstant.MESSAGES_ERROR)); + + + } + + + + + + /** + * 查询所有审核通过未删除的设备 + * @return + */ + @GetMapping("/query/device/approve") + public AjaxResult queryApprovedDevice(){ + return AjaxResult.success(LocaleUtil.getMessage(FieldConstant.MESSAGES_SUCCESS), deviceInfoService.queryApprovedDevice()); + + } + + /** + * 根据imei 查询设备信息 对APP使用 + * @return + */ + @GetMapping("/query/deviceInfo/{imei}") + public DeviceInfo queryDeviceInfoByImei(@PathVariable String imei){ + return deviceInfoService.queryDeviceInfoByImei(imei); + + } + + + + /** + * 根据imei和日期查询轨迹信息 + * @return + */ + @PostMapping("/query/track") + public AjaxResult queryTrackInfo(@RequestBody TrackDTO dto){ + return AjaxResult.success(deviceInfoService.queryTrackInfo(dto)); + + } + + + /** + * 远程控制 + * @return + */ + @PostMapping("/query/remote") + public AjaxResult queryRemoteControl(@RequestBody RemoteControlDTO dto){ + return AjaxResult.success(deviceInfoService.queryRemoteControl(dto)); + + } + + /** + * 远程控制指令下发 + * @return + */ + @PostMapping("/send/instructions") + public AjaxResult sendInstructions(@RequestBody sendInstructionDTO dto){ + return AjaxResult.success(deviceInfoService.sendInstructions(dto)); + + } + + /** + * 查询设备功能信息 + * @param dto + * @return + */ + + @PostMapping("/query/equipmentFunction") + public AjaxResult queryEquipmentFunction(@RequestBody RemoteControlDTO dto){ + return AjaxResult.success(deviceInfoService.queryEquipmentFunction(dto)); + + } + + /** + * 设备使用状况统计 + * @return + */ + @GetMapping("/query/deviceNumber") + public AjaxResult queryDeviceNumberInfo(){ + return AjaxResult.success(deviceInfoService.queryDeviceNumberInfo()); + + } + + + + + // /** +// * 根据设备imei批量删除设备 +// * @return +// */ +// @DelImeiLog(delType = DeviceModelConstants.ZERO) +// @DeleteMapping("/del/list") +// public AjaxResult delDeviceByImei(@RequestBody List imeis) { +// +// return deviceInfoService.delDeviceByIds(ids) ? success(I18nUtil.getMessage(FieldConstant.MESSAGES_SUCCESS)) : error(I18nUtil.getMessage(FieldConstant.MESSAGES_ERROR)); +// +// +// } + +} + diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/controller/DeviceModelController.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/controller/DeviceModelController.java new file mode 100644 index 0000000..c610a2b --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/controller/DeviceModelController.java @@ -0,0 +1,71 @@ +package com.ecell.internationalize.system.controller; +import com.ecell.internationalize.common.core.constant.UserConstants; +import com.ecell.internationalize.common.core.web.controller.BaseController; +import com.ecell.internationalize.common.core.web.domain.AjaxResult; +import com.ecell.internationalize.common.core.web.page.TableDataInfo; +import com.ecell.internationalize.common.security.utils.SecurityUtils; +import com.ecell.internationalize.system.entity.DeviceModel; +import com.ecell.internationalize.system.entity.vo.DeviceModelVO; +import com.ecell.internationalize.system.service.DeviceModelService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 设备类型管理信息 + */ +@RestController +@RequestMapping("/deviceModel") +@Deprecated +public class DeviceModelController extends BaseController { + @Autowired + private DeviceModelService modelService; + /** + * 新增设备类型 + */ + @PostMapping("/add") + public AjaxResult add(@Validated @RequestBody DeviceModel model) { + if (UserConstants.NOT_UNIQUE.equals(modelService.checkModelNameUnique(model))) + { + return AjaxResult.error("新增设备型号'" + model.getDeviceModelName() + "'失败,同一厂商下该名称已存在"); + } + return toAjax(modelService.insertDeviceModel(model)); + + } + + /** + * 根据条件分页查询设备型号 + * @param model + * @return + */ + @GetMapping("/list") + public TableDataInfo list(DeviceModel model) { + + startPage(); + List list = modelService.selectModelList(model); + return getDataTable(list); + + } + + /** + * 更新设备型号信息 + * @param model + * @return + */ + @PostMapping("/edit") + public AjaxResult edit( @RequestBody DeviceModel model) { + model.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(modelService.updateDeviceModel(model)); + } + + @DeleteMapping("/del/{id}") + public AjaxResult remove(@PathVariable String id) { + //TODO 这里要判断录入总数是否为0 不为0就不能删除 + + return toAjax(modelService.deleteDeviceModelById(id)); + } + + +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/DeviceInfo.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/DeviceInfo.java new file mode 100644 index 0000000..4018f38 --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/DeviceInfo.java @@ -0,0 +1,137 @@ +package com.ecell.internationalize.system.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 设备信息表 + *

+ * + * @author ${author} + * @since 2022-07-10 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value="DeviceInfo对象", description="设备信息表") +public class DeviceInfo implements Serializable { + +private static final long serialVersionUID=1L; + + @TableId(value = "device_id",type = IdType.INPUT) + @ApiModelProperty(value = "设备ID") + private String deviceId; + + @ApiModelProperty(value = "IMEI") + private String imei; + + @NotEmpty(message = "厂商id不能为空") + @ApiModelProperty(value = "厂商id") + private String firmId; + + @NotEmpty(message = "厂商名称不能为空") + @ApiModelProperty(value = "厂商名称") + private String firmName; + + @NotEmpty(message = "设备型号id不能为空") + @ApiModelProperty(value = "设备型号id") + private String deviceModelId; + + @NotEmpty(message = "设备型号名称不能为空") + @ApiModelProperty(value = "设备型号名称") + private String deviceModelName; + + @ApiModelProperty(value = "导入数量") + private Integer totalImport; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "审核时间") + private Date auditTime; + + @ApiModelProperty(value = "审核者") + private String reviewer; + + @ApiModelProperty(value = "审核设备(1.单个录入这里存的是设备的IMEI,如果是批量录入这里存的是文件的唯一标识)") + private String auditDevice; + + @ApiModelProperty(value = "录入标志(0.是单个录入,1.是批量录入") + private String inputFlag; + + @ApiModelProperty(value = "审核状态(0.是拒绝,1.是待审核,2.是通过,默认为1)") + private String auditStatus; + + @ApiModelProperty(value = "是否删除(0.是,1.否。默认为1)") + private String delFlag; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "授权时间") + private Date authorizaTime; + + @ApiModelProperty(value = "代理商id") + private String agentId; + + @ApiModelProperty(value = "代理商名称") + private String agentName; + + @ApiModelProperty(value = "授权标志(0.未授权,1.是已授权。默认为0)") + private String authorizaFlag; + + @ApiModelProperty(value = "创建人") + @TableField(value = "create_user",fill = FieldFill.INSERT) + private String createUser; + + @ApiModelProperty(value = "修改人") + @TableField(value = "update_user",fill = FieldFill.UPDATE) + private String updateUser; + + @TableField(value = "create_time",fill = FieldFill.INSERT) + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE) + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "修改时间") + private Date updateTime; + + @ApiModelProperty(value = "录入批次号") + private String inputBatch; + + @ApiModelProperty(value = "是否激活(0.未激活,1.是已激活。默认为0 这个字段没用)") + private String whetherActivation; + + @ApiModelProperty(value = "是否绑定(0.未绑定,1.是已绑定。默认为0 这个字段没用)") + private String whetherBinding; + @TableField(value = "firstLoginTime") + @ApiModelProperty(value = "设备首次登录时间") + private Date firstLoginTime; + + @TableField(value = "lastLoginTime") + @ApiModelProperty(value = "设备最后登录时间") + private Date lastLoginTime; + + /** 功能模块说明 */ + @TableField(exist = false) + private String funDescription; + /** 录入成功条数 */ + @TableField(exist = false) + private int inputSuccessTotal; + + +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/DeviceModel.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/DeviceModel.java new file mode 100644 index 0000000..a98a211 --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/DeviceModel.java @@ -0,0 +1,82 @@ +package com.ecell.internationalize.system.entity; + +import com.ecell.internationalize.common.core.web.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "设备型号信息") +@Deprecated +public class DeviceModel extends BaseEntity { + /**设备型号id */ + @ApiModelProperty("设备型号id ") + private String deviceModelId; + /** 设备型号名称 */ + @NotBlank(message = "设备型号名称不能为空") + @ApiModelProperty("设备型号名称 ") + private String deviceModelName; + /** 厂商id */ + @NotBlank(message = "厂商id不能为空") + private String firmId; + /** 厂商名称 */ + @ApiModelProperty("厂商名称 ") + private String firmName; + /** 定位功能(1.基站,2.基站+wiff,3.基站+GPS,4.基站+wiff+GPS) */ + private String locationFun; + /** 视频类型名称(0.不支持,其余就是类型的名称) */ + private String videoModelName; + /** 视频规则(0.默认,其余就是类型的名称) */ + private String videoRule; + /** 公视频类型id */ + private String videoModelId; + /** 设备类型(0.默认 1.手表,2.学生卡,3.老人机) */ + private String deviceType; + /** 公众号平台名称(0.不支持,其余就是公众号的名称) */ + private String officialAccountName; + /** 手表闹钟(0.不支持,1.支持) */ + private String watchAlarmClock; + /** 上课禁用(0.不支持,1.支持)*/ + private String classDisable; + /** SOS号码(0.不支持,1.支持) */ + private String sosPhone; + /** 电子围栏(0.不支持,1.支持)*/ + private String electronicFence; + /** 记步功能(0.不支持,1.支持) */ + private String stepRecorder; + /** 微聊功能(0.不支持,1.支持) */ + private String chatFun; + /** 查找设备功能(0.不支持,1.支持) */ + private String lookupFun; + /** 手表WIFF(0.不支持,1.支持) */ + private String watchWiff; + /** 心率(0.不支持,1.支持)*/ + private String heartRate; + /** 体温(0.不支持,1.支持) */ + private String temperature; + /** 血压(0.不支持,1.支持)*/ + private String bloodPressure; + /** 血氧(0.不支持,1.支持 */ + private String bloodOxygen; + /** 白名单(0.不支持,1.支持) */ + private String whiteList; + /** 拨号盘(0.不支持,1.支持)*/ + private String dial; + /** 定时开关机(0.不支持,1.支持) */ + private String timingSwitch; + /** 电信版本号(0,否,1.是)*/ + private String telecomVersion; + /** 是否删除(0,是,1.否)*/ + private String delFlag; + + + + + +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/dto/DeviceFamilyPageDTO.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/dto/DeviceFamilyPageDTO.java new file mode 100644 index 0000000..6e7e802 --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/entity/dto/DeviceFamilyPageDTO.java @@ -0,0 +1,27 @@ +package com.ecell.internationalize.system.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@ApiModel(description = "设备家庭情况分页对象") +@Data +@AllArgsConstructor +@NoArgsConstructor +public class DeviceFamilyPageDTO { + + @ApiModelProperty("设备imei ") + private String imei; + + @ApiModelProperty(value = "设备手机号") + private String phone; + + @ApiModelProperty(value = "每页展示的条数") + private Integer pageSize; + + @ApiModelProperty(value = "当前的页码") + private Integer current; + +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/mapper/DeviceInfoMapper.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/mapper/DeviceInfoMapper.java new file mode 100644 index 0000000..cd9ff9f --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/mapper/DeviceInfoMapper.java @@ -0,0 +1,229 @@ +package com.ecell.internationalize.system.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ecell.internationalize.system.entity.DeviceInfo; +import com.ecell.internationalize.system.entity.LatestLocationApp; +import com.ecell.internationalize.system.entity.dto.*; +import com.ecell.internationalize.system.entity.vo.*; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + *

+ * 设备信息表 Mapper 接口 + *

+ * + * @author ${author} + * @since 2022-07-10 + */ +public interface DeviceInfoMapper extends BaseMapper { + + Page queryActivationInfoPageList(@Param("page") Page page, @Param("dto") DeviceActivaPageDTO dto); + + /** + * 根据批次分组查询审批通过的总数 + * @param page + * @param dto + * @return + */ + Page queryActivationInfoList(@Param("page") Page page, @Param("dto") DeviceActivaPageDTO dto); + + /** + * 根据imeis查询最新位置信息表统计激活数据 + * @param list + * @return + */ + int queryActivateDeviceCount(@Param("list") List list); + /** + * 根据imeis查询绑定表统计绑定数据 + * @param list + * @return + */ + int queryBindDeviceCount(@Param("list") List list); + + void updateDeviceOwnerInfo(@Param("pId")String positioningModelId, @Param("mId")String deviceModelId); + /** + * 查询管理员id,设备拥有者名称,imei + */ + List queryBingOrOwnerInfo(@Param("imei") Listimei); + /** + * 根据群组id 管理id 查询群组成员信息表 + */ + List queryChatMemberById(@Param("groupId")String groupId,@Param("adminId")String adminId); + + /** + * 查询已绑定的imei + * @param list + * @return + */ + List queryBindImeiByList(@Param("list") Listlist); + /** + * 查询绑定表管理员id (暂时不用) + */ + List queryBindAdminInfoByImei(@Param("list") Listlist); + + /** + * 删除设备拥有者信息表deleteDeviceOwnerInfo + * @param imei + */ + void deleteDeviceOwnerInfo(@Param("imei") Listimei); + + /** + * 删除绑定数据 + */ + void deleteUserBindInfo(@Param("imei") Listimei); + /** + * 删除群组表 + */ + void deleteChatGroup(@Param("imei") Listimei); + + /** + * 根据imei查询聊天群组表ID + * @param imei + * @return + */ + List queryChatGroupIdByImei(@Param("imei") Listimei); + /** + * 删除聊天成员表 + */ + void deleteGroupMember(@Param("ids") Listids); + /** + * 删除聊天信息表 + */ + void deleteMessage(@Param("ids") Listids); + /** + * 删除通讯录表 + */ + void deleteAddressBook(@Param("imei") Listimei); + /** + * 删除申请关注记录表 + */ + void deleteDeviceAttention(@Param("imei") Listimei); + /** + * 删除最新位置表 + */ + void deleteLatestLocation(@Param("imei") Listimei); + /** + * 删除解析后的位置表 + */ + void deleteDeviceLocation(@Param("imei") Listimei); + /** + * 删除闹钟信息 + */ + void deleteAlarm(@Param("imei") Listimei); + /** + * 删除上课免打扰信息表 + */ + void deleteDeviceDisable(@Param("imei") Listimei); + /** + * 删除定时开关机信息表 + */ + void deleteDeviceTimeSwitch(@Param("imei") Listimei); + /** + * 删除安全信息围栏表 + */ + void deleteSafetyRail(@Param("imei") Listimei); + /** + * 删除SOS信息表 + */ + void deleteSOSInfo(@Param("imei") Listimei); + /** + * 删除消息提醒信息表 + */ + void deleteReminderMessage(@Param("imei") Listimei); + /** + * 删除可是视频信息表 + */ + void deleteVideoInfo(@Param("imei") Listimei); + /** + * 删除轨迹信息 + */ + void deleteTrackInfo(@Param("imei") Listimei); + + /** + * 根据imei 日期查询轨迹信息 + * @param dto + */ + List queryTrackInfo(@Param("dto") TrackDTO dto); + + /** + * 查询远程控制 + * @param page + * @param dto + * @return + */ + Page queryRemoteControl(@Param("page")Page page, @Param("dto") RemoteControlDTO dto); + + /** + * 查询设备功能信息 + * @param page + * @param dto + * @return + */ + Page queryEquipmentFunction(@Param("page") IPage page, @Param("dto")RemoteControlDTO dto); + + /** + * 根据imei查询电话本信息 + * @param imei + * @return + */ + List queryBookByImei(@Param("imei")String imei); + + /** + * //根据imei查询闹钟信息 + * @param imei + * @return + */ + ListqueryAlarmByImei( @Param("imei")String imei); + + /** + * //根据imei查询上课禁用信息 + * @param imei + * @return + */ + ListqueryDisableByImei( @Param("imei")String imei); + + /** + * //根据imei查询安全围栏信息 + * @param imei + * @return + */ + ListquerySafetyRaliByImei( @Param("imei")String imei); + + List queryByiMei(@Param("imei") String imei, @Param("iMeiList") List iMeiList); + + List locationTotal(@Param("iMeiList") List iMeiList); + + List provinceTotal(@Param("country") String country,@Param("iMeiList") List iMeiList); + /** + * 查询设备激活数 + * @return + */ + int queryDeviceActivate(@Param("dto")RemoteControlDTO dto); + /** + * 查询设备今日新增数量 + */ + int queryDeviceTodayAdd(@Param("dto")RemoteControlDTO dto); + + /** + * 厂商列表录入统计专用 + * @param firmId + * @param agentId + * @return + */ + List queryFirmInputCountDevice(@Param("firmId") String firmId, @Param("agentId")String agentId); + /** + * 厂商列表录激活计专用 + * @param firmId + * @param agentId + * @return + */ + int queryFirmActivateCountDevice(@Param("firmId") String firmId, @Param("agentId")String agentId); + + List queryByCountryOrProvince(@Param("countryOrProvince") String countryOrProvince,@Param("type") String type,@Param("iMeiList") List iMeiList); + List initInputBach(); +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/service/DeviceInfoService.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/service/DeviceInfoService.java new file mode 100644 index 0000000..13e1891 --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/service/DeviceInfoService.java @@ -0,0 +1,139 @@ +package com.ecell.internationalize.system.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.ecell.internationalize.system.entity.DeviceInfo; +import com.ecell.internationalize.system.entity.LatestLocationApp; +import com.ecell.internationalize.system.entity.dto.*; +import com.ecell.internationalize.system.entity.vo.DeviceCountInfo; +import com.ecell.internationalize.system.entity.vo.TrackVO; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 设备信息表 服务类 + *

+ * + * @author ${author} + * @since 2022-07-10 + */ +public interface DeviceInfoService extends IService { + + boolean singleEntry(DeviceDTO dto); + + String importImei(List userList, DeviceDTO dto); + + IPage queryByPageList(DevicePageDTO dto); + + /** + * 根据IMEI查询批次号 + * @param ids + * @return + */ + String queryInputBatchById(String ids); + + /** + * 审批状态更新 + * @param id + * @param status + * @return + */ + boolean updateStatus(String id,String status); + + DeviceInfo queryDeviceByImei(String imei); + + IPage queryActivationInfoPageList(DeviceActivaPageDTO dto); + + boolean delDeviceByIds(List imei); + + boolean delDeviceByImei(List imeis,String sign); + + List queryApprovedDevice(); + + /** + * 根据 imei 查询设备信息 对APP使用 + * @return + */ + DeviceInfo queryDeviceInfoByImei(String imei); + + /** + * 单个解绑 + * @param imei + * @param one + * @return + */ + boolean deviceUnBingByImei(String imei, String one); + + /** + * 查询轨迹信息 + * @param dto + * @return + */ + List queryTrackInfo(TrackDTO dto); + + /** + * 设备远程控制查询 + * @param dto + * @return + */ + IPage queryRemoteControl(RemoteControlDTO dto); + + /** + * 远程控制指令下发 + * @param dto + * @return + */ + MapsendInstructions(sendInstructionDTO dto); + + /** + * 查询设备功能信息 + * @param dto + * @return + */ + IPage queryEquipmentFunction(RemoteControlDTO dto); + + /** + * 设备使用状况统计 + * @return + */ + DeviceCountInfo queryDeviceNumberInfo(); + + List queryByiMei(String imei); + + List locationTotal(); + + List queryByCountryOrProvince(String countryOrProvince, String type); + + Object importImeiTwo(MultipartFile file, List imeiList, DeviceDTO dto); + + /** + * 根据批次审核 + * @param inputBach + * @param status + * @return + */ + boolean updateInputBachStatus(String inputBach, String status); + + /** + * 初始化批次号 + * @return + */ + List initInputBach(); + + /** + * 根据批次分页查询设备信息 + * @param dto + * @return + */ + IPage queryInputBatchList(DevicePageDTO dto); + + /** + * 根据批次号查询设备信息 + * @param inputBach + * @return + */ + List queryInputBatchListTwo(String inputBach); +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/service/impl/DeviceInfoServiceImpl.java b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/service/impl/DeviceInfoServiceImpl.java new file mode 100644 index 0000000..ca1e7a5 --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/java/com/ecell/internationalize/system/service/impl/DeviceInfoServiceImpl.java @@ -0,0 +1,1396 @@ +package com.ecell.internationalize.system.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +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.ecell.internationalize.common.core.context.SecurityContextHolder; +import com.ecell.internationalize.common.core.exception.ServiceException; +import com.ecell.internationalize.common.core.utils.DateUtils; +import com.ecell.internationalize.common.core.utils.StringUtils; +import com.ecell.internationalize.common.core.utils.locale.LocaleUtil; +import com.ecell.internationalize.common.core.utils.uuid.UUID; +import com.ecell.internationalize.common.issue.entity.ChatGroupDisbandMessageInfo; +import com.ecell.internationalize.common.issue.entity.DistributeParent; +import com.ecell.internationalize.common.issue.mqtt.AppSingleMqttClient; +import com.ecell.internationalize.common.redis.service.RedisService; +import com.ecell.internationalize.common.security.utils.SecurityUtils; +import com.ecell.internationalize.common.system.constant.FieldConstant; +import com.ecell.internationalize.common.system.entity.SysUser; +import com.ecell.internationalize.common.system.utlis.UploadUtil; +import com.ecell.internationalize.system.api.UserFirmApi; +import com.ecell.internationalize.system.constant.DeviceModelConstants; +import com.ecell.internationalize.system.entity.DeviceInfo; +import com.ecell.internationalize.system.entity.DeviceModelInfo; +import com.ecell.internationalize.system.entity.FirmManage; +import com.ecell.internationalize.system.entity.LatestLocationApp; +import com.ecell.internationalize.system.entity.dto.*; +import com.ecell.internationalize.system.entity.vo.*; +import com.ecell.internationalize.system.mapper.DeviceInfoMapper; +import com.ecell.internationalize.system.mapper.DeviceModelInfoMapper; +import com.ecell.internationalize.system.mapper.FirmManageMapper; +import com.ecell.internationalize.system.service.DeviceInfoService; +import com.ecell.internationalize.system.utils.DeviceModelInfoUtli; +import com.ecell.internationalize.system.utils.RandomUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * 设备信息表 服务实现类 + *

+ * + * @author ${author} + * @since 2022-07-10 + */ +@Service +public class DeviceInfoServiceImpl extends ServiceImpl implements DeviceInfoService { + private static final Logger log = LoggerFactory.getLogger(DeviceInfoServiceImpl.class); + private static final NumberFormat nf = NumberFormat.getNumberInstance(); + private static final String USER_MQTT_PREDIX = "iot08/user/"; + @Autowired + private DeviceInfoMapper mapper; + @Autowired + private UserFirmApi api; + @Autowired + private FirmManageMapper firmManageMapper; + @Autowired + private DeviceModelInfoMapper deviceModelInfoMapper; + @Autowired + private RedisService redisService; + @Autowired + @Lazy + private DeviceInfoServiceImpl deviceInfoServiceImpl; + @Autowired + private KafkaTemplate kafkaTemplate; + + @Override + public boolean singleEntry(DeviceDTO dto) { + //判断IMEI的长度 + if (dto.getImei().trim().length() != 15) { + throw new ServiceException("IMEI长度有误"); + } + //判断IMEI的长度 + if (!StringUtils.isNumeric(dto.getImei())) { + throw new ServiceException("messagesParameterError"); + } + //根据imei查询该imei有没有绑定过设备模型 + List infos = checkAuditStatus(dto.getImei()); + if (StringUtils.isNotEmpty(infos)) { + //"该设备正在审批中或者已审批通过不能重复添加" + throw new ServiceException("messageDeviceAuditError"); + } + + DeviceInfo info = new DeviceInfo(); + info.setDeviceModelId(dto.getDeviceModelId()); + info.setFirmId(dto.getFirmId()); + info.setFirmName(dto.getFirmName()); + info.setDeviceModelName(dto.getDeviceModelName()); + info.setImei(dto.getImei()); + info.setAgentId(dto.getAgentId()); + info.setAgentName(dto.getAgentName()); + //设置id + info.setDeviceId(com.ecell.internationalize.common.core.utils.uuid.UUID.fastUUID().toString(true)); + //设置录入标志 + info.setInputFlag(DeviceModelConstants.ZERO); + //设置审核设备 + info.setAuditDevice(info.getImei()); + //设置导入数量 + info.setTotalImport(1); + String inputBatch= DateUtils.dateTimeNow()+ RandomUtils.generateVerCode(6); + //设置批次号 + info.setInputBatch(inputBatch); + DeviceInfo info1 = queryInputBatch(inputBatch); + if (StringUtils.isNotNull(info1)){ + return false; + } + return save(info); + } + + + + /** + * 批量导入 + * + * @param userList + * @param dto + * @return + */ + @Override + public String importImei(List userList, DeviceDTO dto) { + List infos = new ArrayList<>(userList.size()); + if (StringUtils.isNotEmpty(userList) && userList.size() > 0) { + //设置批次号 + String inputBatch = DateUtils.dateTimeNow()+ RandomUtils.generateVerCode(6); + DeviceInfo info1 = queryInputBatch(inputBatch); + if (StringUtils.isNotNull(info1)){ + return "Batch import failed"; + } + infos = userList.stream().map(DeviceDTO::getImei).filter(StringUtils::isNotEmpty).map( + s -> convertStringToClass(s, dto, userList.size(), inputBatch)).collect(Collectors.toList()); + } + + + return checkImei(infos); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Object importImeiTwo(MultipartFile file, List imeiList, DeviceDTO dto){ + + List infos = new ArrayList<>(imeiList.size()); + String inputBatchOne=null; + if (StringUtils.isNotEmpty(imeiList) && imeiList.size() > 0) { + //设置批次号 + String inputBatchTwo = DateUtils.dateTimeNow()+ RandomUtils.generateVerCode(6); + inputBatchOne=inputBatchTwo; + infos = imeiList.stream().map(DeviceDTO::getImei).filter(StringUtils::isNotEmpty).map( + s -> convertStringToClass(s, dto, imeiList.size(), inputBatchTwo)).collect(Collectors.toList()); + } + + return checkImeiTwo(file,infos,inputBatchOne); + } + + /** + * 分页查询 + * + * @param dto + * @return + */ + @Override + public IPage queryByPageList(DevicePageDTO dto) { + IPage page = new Page(dto.getCurrent(), dto.getPageSize()); + Map map = SecurityUtils.getFirmIdOrSecondFirmId(SecurityUtils.getUserLogin()); + QueryWrapper wrapper = new QueryWrapper<>(); + if (StringUtils.isNotEmpty(map)) { + //是厂商 + if (StringUtils.isNotEmpty(map.get("firmFlag")) && DeviceModelConstants.ONE.equals(map.get("firmFlag"))) { + DeviceModelInfoUtli.dataPermissions(wrapper, "firm_id", map.get("firmId")); + } else { + //代理商 + DeviceModelInfoUtli.dataPermissions(wrapper, "agent_id", map.get("firmId")); + } + } + if (StringUtils.isNotEmpty(dto.getStatus())) { + wrapper.eq("audit_status", dto.getStatus()); + } + + if (StringUtils.isNotEmpty(dto.getImei())) { + wrapper.eq("imei", dto.getImei()); + } + wrapper.eq("del_flag", DeviceModelConstants.ONE); + wrapper.groupBy("input_batch"); +// if (DeviceModelConstants.TWO.equals(dto.getStatus())){ +// wrapper.orderByDesc("audit_time"); +// }else { +// wrapper.orderByDesc("create_time"); +// } + wrapper.orderByDesc("create_time"); + + IPage page1 = mapper.selectPage(page, wrapper); + + this.convertIPage(page1); + + + return page1; + + } + + /** + * 根据批次号查询设备信息 + * @param dto + * @return + */ + @Override + public IPage queryInputBatchList(DevicePageDTO dto){ + IPage page = new Page(dto.getCurrent(), dto.getPageSize()); + QueryWrapper wrapper =new QueryWrapper<>(); +// wrapper.eq("audit_status",dto.getStatus()); + wrapper.eq("del_flag",DeviceModelConstants.ONE); + wrapper.eq("input_batch",dto.getInputBatch()); + wrapper.orderByDesc("create_time"); + return baseMapper.selectPage(page,wrapper); + } + + + /** + * 根据IMEI查询批次号(imei是唯一的) + * + * @param imei + * @return + */ + @Override + public String queryInputBatchById(String imei) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("imei", imei); + wrapper.eq("del_flag", DeviceModelConstants.ONE); + //加上limit 不加如果有多条记录会抛异常 + wrapper.last("LIMIT 1"); + DeviceInfo info = mapper.selectOne(wrapper); + if (StringUtils.isNotNull(info)) { + return info.getInputBatch(); + } + return ""; + } + + /** + * 审批 + * + * @param id + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateStatus(String id, String status) { + DeviceInfo info = mapper.selectById(id); + if (StringUtils.isNull(info)) { + throw new ServiceException("此设备ID不存在"); + } + //修改审批状态 + info.setAuditStatus(status); + + info.setReviewer(SecurityUtils.getUsername()); + //审核时间 + info.setAuditTime(new Date()); + //审核通过要存入缓存 App上传指令要用到 + if (DeviceModelConstants.TWO.equals(status)) { + //根据厂商id,查询厂商编号 + // FirmManage firmManage = firmManageMapper.selectById(info.getFirmId()); + //写死 + redisService.setCacheMapValue(info.getImei(), DeviceModelConstants.AGENT, DeviceModelConstants.TWO_ZERO); + } + return super.updateById(info); + } + + @Override + public boolean updateInputBachStatus(String inputBath,String status){ + //根据批次号查询设备信息 + QueryWrapper wrapper =new QueryWrapper(); + wrapper.eq("input_batch",inputBath); + wrapper.eq("audit_status",DeviceModelConstants.ONE); + wrapper.eq("del_flag",DeviceModelConstants.ONE); + List list = baseMapper.selectList(wrapper); + if (StringUtils.isNotEmpty(list) && list.size()>0){ + List collect = list.stream().map(s -> { + s.setAuditStatus(status); + return s; + }).collect(Collectors.toList()); + return super.updateBatchById(collect); + + }else { + return false; + } + } + @Override + public List initInputBach(){ + List infos = baseMapper.initInputBach(); + if (StringUtils.isNotEmpty(infos) && infos.size()>0){ + infos = infos.stream().map(s -> { + if (StringUtils.isNotEmpty(s.getFirmId()) && StringUtils.isNotEmpty(s.getAgentId())) { + //查询代理商名称 + FirmManage firmManage = firmManageMapper.selectById(s.getAgentId()); + if (StringUtils.isNotNull(firmManage)) { + s.setAgentName(firmManage.getFirmName()); + } + } else { + //查询代理商名称 + FirmManage firmManage = firmManageMapper.selectById(s.getFirmId()); + if (StringUtils.isNotNull(firmManage)) { + s.setAgentName(firmManage.getFirmName()); + } + } + + return s; + + }).collect(Collectors.toList()); + } + return infos; + } + + /** + * 根据imei 查询设备信息 + * + * @param imei + * @return + */ + @Override + public DeviceInfo queryDeviceByImei(String imei) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("imei", imei); + wrapper.eq("del_flag", DeviceModelConstants.ONE); + wrapper.lambda().and(s -> s.eq(DeviceInfo::getAuditStatus, DeviceModelConstants.ONE).or().eq(DeviceInfo::getAuditStatus, DeviceModelConstants.TWO)); + //加上limit 不加如果有多条记录会抛异常 + wrapper.last("LIMIT 1"); + return mapper.selectOne(wrapper); + } + + /** + * 查询设备激活信息 + * + * @param dto + * @return + */ + + @Override + public IPage queryActivationInfoPageList(DeviceActivaPageDTO dto) { + // Page deviceActivation = mapper.queryActivationInfoPageList(page, dto); + Page page = new Page(dto.getCurrent(), dto.getPageSize()); + Page deviceActivation = mapper.queryActivationInfoList(page,dto); + if (StringUtils.isNotNull(deviceActivation) && StringUtils.isNotEmpty(deviceActivation.getRecords()) && deviceActivation.getRecords().size() > 0) { + List collect = deviceActivation.getRecords().stream().filter(s-> null != s.getInputBatch()).map(this::calculation).collect(Collectors.toList()); + deviceActivation.setRecords(collect); + + } + + return deviceActivation; + } + + /** + * 单个解绑 + * @param imei + * @param one + * @return + */ + @Transactional(rollbackFor = Exception.class) + @Override + public boolean deviceUnBingByImei(String imei, String one) { + //获取当前用户 + Map map = SecurityUtils.getFirmIdOrSecondFirmId(SecurityUtils.getUserLogin()); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("audit_status", DeviceModelConstants.TWO); + wrapper.eq("imei", imei); + wrapper.eq("del_flag", DeviceModelConstants.ONE); + if (StringUtils.isNotEmpty(map)) { + if (StringUtils.isNotEmpty(map.get("firmFlag")) && DeviceModelConstants.ONE.equals(map.get("firmFlag"))) {//是厂商 + DeviceModelInfoUtli.dataPermissions(wrapper, "firm_id", map.get("firmId")); + } else { + //代理商 + DeviceModelInfoUtli.dataPermissions(wrapper, "agent_id", map.get("firmId")); + } + } + DeviceInfo info = baseMapper.selectOne(wrapper); + if (!StringUtils.isNotNull(info)){ + // 该设备不可用,请检查该设备是否已经审批通过或已经进行了绑定 + throw new ServiceException("messages.device.unBing.error"); + } + List list = Collections.singletonList(imei); + log.info("开始解绑------->imei:{}",imei); + return deviceInfoServiceImpl.delDeviceByImei(list,DeviceModelConstants.ONE); + + } + + /** + * 根据imei查询轨迹信息 + * @param dto + * @return + */ + @Override + public List queryTrackInfo(TrackDTO dto) { + if(!StringUtils.isNotEmpty(dto.getImei()) || dto.getImei().length() !=15){ + throw new ServiceException("IMEI长度有误"); + } + //获取当前用户 + Map map = SecurityUtils.getFirmIdOrSecondFirmId(SecurityUtils.getUserLogin()); + if (StringUtils.isNotEmpty(map)) { + //是厂商 + if (StringUtils.isNotEmpty(map.get("firmFlag")) && DeviceModelConstants.ONE.equals(map.get("firmFlag"))) { + dto.setFirmId(map.get("firmId")); + } else { + //代理商 + dto.setAgentId(map.get("firmId")); + } + } + //根据imei查询设备信息 + QueryWrapper wrapper =new QueryWrapper(); + wrapper.eq("imei",dto.getImei()); + wrapper.eq("audit_status",DeviceModelConstants.TWO); + wrapper.eq("del_flag",DeviceModelConstants.ONE); + if (StringUtils.isNotEmpty(dto.getFirmId())){ + wrapper.eq("firm_id",dto.getFirmId()); + } + if (StringUtils.isNotEmpty(dto.getAgentId())){ + wrapper.eq("agent_id",dto.getAgentId()); + } + wrapper.last("LIMIT 1"); + DeviceInfo info = baseMapper.selectOne(wrapper); + if (StringUtils.isNull(info)){ + //此设备,不在您的设备中,或此设备未审批或此设备已经删除,请联系管理员 + throw new ServiceException("messages.imei.track.error"); + } + + + return baseMapper.queryTrackInfo(dto); + } + + /** + * 设备远程控制查询 + * @param dto + * @return + */ + @Override + public IPage queryRemoteControl(RemoteControlDTO dto) { + Page page =new Page(dto.getCurrent(),dto.getPageSize()); + return baseMapper.queryRemoteControl(page, dto); + } + + /** + * 远程指令下发 + * @param dto + * @return + */ + @Override + public Map sendInstructions(sendInstructionDTO dto) { + Map map =new HashMap<>(2); + try { + Object onlineStatus = redisService.getCacheMapValue(dto.getImei(), "onlineStatus"); + map.put("onlineStatus",onlineStatus.toString()); + }catch (Exception e){ + map.put("onlineStatus",DeviceModelConstants.ZERO); + } + if (StringUtils.isNotEmpty(map.get("onlineStatus")) && DeviceModelConstants.ZERO.equals(map.get("onlineStatus"))){ + return map; + } + DistributeParent parent =new DistributeParent(); + parent.setIdent(RandomUtils.generateVerCode(6)); + parent.setImei(dto.getImei()); + parent.setOpenid(SecurityContextHolder.getStringUserId()); + parent.setVender(DeviceModelConstants.TWO_ZERO); + parent.setTime(System.currentTimeMillis()); + //定位指令下发 + if (DeviceModelConstants.ONE.equals(dto.getType())){ + + parent.setType("requestLocation"); + + + //远程关机指令下发 + }else if (DeviceModelConstants.TWO.equals(dto.getType())){ + parent.setType("PowerOff"); + + } + //下发指令 + sendKafka(parent); + map.put("onlineStatus",DeviceModelConstants.ONE); + return map; + } + /** + * 查询设备功能信息 + * @param dto + * @return + */ + @Override + public IPage queryEquipmentFunction(RemoteControlDTO dto) { + IPage page = new Page(dto.getCurrent(), dto.getPageSize()); + Map map = SecurityUtils.getFirmIdOrSecondFirmId(SecurityUtils.getUserLogin()); + if (StringUtils.isNotEmpty(map)) { + //是厂商 + if (StringUtils.isNotEmpty(map.get("firmFlag")) && DeviceModelConstants.ONE.equals(map.get("firmFlag"))) { + dto.setFirmId(dto.getFirmId()); + } else { + //代理商 + dto.setAgentId(dto.getAgentId()); + } + } + Page equipmentFunctionVOPage = baseMapper.queryEquipmentFunction(page, dto); + if (StringUtils.isNotNull(equipmentFunctionVOPage) && StringUtils.isNotEmpty(equipmentFunctionVOPage.getRecords())&& equipmentFunctionVOPage.getRecords().size()>0){ + + List equipmentFunctionVOS = fillProperties(equipmentFunctionVOPage.getRecords()); + equipmentFunctionVOPage.setRecords(equipmentFunctionVOS); + } + + return equipmentFunctionVOPage; + } + + @Override + public List queryByiMei(String imei) { + String userId= SecurityContextHolder.getStringUserId(); + SysUser sysUser = firmManageMapper.queryFirmId(userId); + if (FieldConstant.ADMIN.equals(userId) || "3".equals(sysUser.getFirmFlag())){ + //管理员或者超级厂商可查询所有设备位置信息 + return baseMapper.queryByiMei(imei,null); + } + LambdaQueryWrapper lambdaQueryWrapper=new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DeviceInfo::getDelFlag,FieldConstant.DEL_FLAG); + //厂商 + if (FieldConstant.MATH_ONE.equals(sysUser.getFirmFlag())){ + //如果该用户选择的是厂商,显示厂商以及厂商下面的所有代理商设备数据 + lambdaQueryWrapper.eq(DeviceInfo::getFirmId,sysUser.getFirmId()); + } + else { + lambdaQueryWrapper.eq(DeviceInfo::getAgentId,sysUser.getSecondFirmId()); + } + List deviceInfoList = mapper.selectList(lambdaQueryWrapper); + if (CollectionUtils.isEmpty(deviceInfoList)){ + return null; + } + List iMeiList= deviceInfoList.stream().map(DeviceInfo::getImei).collect(Collectors.toList()); + return baseMapper.queryByiMei(imei,iMeiList); + } + + @Override + public List locationTotal() { + String userId= SecurityContextHolder.getStringUserId(); + SysUser sysUser = firmManageMapper.queryFirmId(userId); + if (FieldConstant.ADMIN.equals(userId) || "3".equals(sysUser.getFirmFlag())){ + //管理员或者超级厂商可查询所有设备位置信息 + List locationDtoList = baseMapper.locationTotal(null); + if (!CollectionUtils.isEmpty(locationDtoList)){ + for (LocationDto locationDto:locationDtoList){ + List childDtoList = baseMapper.provinceTotal(locationDto.getCountry(),null); + locationDto.setChildList(childDtoList); + } + } + return locationDtoList; + } + LambdaQueryWrapper lambdaQueryWrapper=new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DeviceInfo::getDelFlag,FieldConstant.DEL_FLAG); + //厂商 + if (FieldConstant.MATH_ONE.equals(sysUser.getFirmFlag())){ + //如果该用户选择的是厂商,显示厂商以及厂商下面的所有代理商设备数据 + lambdaQueryWrapper.eq(DeviceInfo::getFirmId,sysUser.getFirmId()); + } + else { + lambdaQueryWrapper.eq(DeviceInfo::getAgentId,sysUser.getSecondFirmId()); + } + List deviceInfoList = mapper.selectList(lambdaQueryWrapper); + if (CollectionUtils.isEmpty(deviceInfoList)){ + return null; + } + List iMeiList= deviceInfoList.stream().map(DeviceInfo::getImei).collect(Collectors.toList()); + List locationDtoList = baseMapper.locationTotal(iMeiList); + if (!CollectionUtils.isEmpty(locationDtoList)){ + for (LocationDto locationDto:locationDtoList){ + List childDtoList = baseMapper.provinceTotal(locationDto.getCountry(),iMeiList); + locationDto.setChildList(childDtoList); + } + } + return locationDtoList; + + } + + @Override + public List queryByCountryOrProvince(String countryOrProvince, String type) { + String userId= SecurityContextHolder.getStringUserId(); + SysUser sysUser = firmManageMapper.queryFirmId(userId); + if (FieldConstant.ADMIN.equals(userId) || "3".equals(sysUser.getFirmFlag())){ + //管理员或者超级厂商可查询所有设备位置信息 + List locationFindDtoList = baseMapper.queryByCountryOrProvince(countryOrProvince, type,null); + if (!CollectionUtils.isEmpty(locationFindDtoList)){ + for (LocationFindDto locationFindDto:locationFindDtoList){ + String onlineStatus = null != redisService.getCacheMapValue(locationFindDto.getImei(), "onlineStatus")? redisService.getCacheMapValue(locationFindDto.getImei(), "onlineStatus").toString():"0"; + locationFindDto.setOnLineStatus(onlineStatus); + } + } + return locationFindDtoList; + } + LambdaQueryWrapper lambdaQueryWrapper=new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DeviceInfo::getDelFlag,FieldConstant.DEL_FLAG); + //厂商 + if (FieldConstant.MATH_ONE.equals(sysUser.getFirmFlag())){ + //如果该用户选择的是厂商,显示厂商以及厂商下面的所有代理商设备数据 + lambdaQueryWrapper.eq(DeviceInfo::getFirmId,sysUser.getFirmId()); + } + else { + lambdaQueryWrapper.eq(DeviceInfo::getAgentId,sysUser.getSecondFirmId()); + } + List deviceInfoList = mapper.selectList(lambdaQueryWrapper); + if (CollectionUtils.isEmpty(deviceInfoList)){ + return null; + } + List iMeiList= deviceInfoList.stream().map(DeviceInfo::getImei).collect(Collectors.toList()); + //管理员或者超级厂商可查询所有设备位置信息 + List locationFindDtoList = baseMapper.queryByCountryOrProvince(countryOrProvince, type,iMeiList); + if (!CollectionUtils.isEmpty(locationFindDtoList)){ + for (LocationFindDto locationFindDto:locationFindDtoList){ + String onlineStatus = null != redisService.getCacheMapValue(locationFindDto.getImei(), "onlineStatus")? redisService.getCacheMapValue(locationFindDto.getImei(), "onlineStatus").toString():"0"; + locationFindDto.setOnLineStatus(onlineStatus); + } + } + + return locationFindDtoList; + } + + /** + * 设备统计信息 + * @return + */ + @Override + public DeviceCountInfo queryDeviceNumberInfo() { + RemoteControlDTO dto =new RemoteControlDTO(); + //获取当前用户 + Map map = SecurityUtils.getFirmIdOrSecondFirmId(SecurityUtils.getUserLogin()); + QueryWrapper wrapper =new QueryWrapper(); + if (StringUtils.isNotEmpty(map)) { + //是厂商 + if (StringUtils.isNotEmpty(map.get("firmFlag")) && DeviceModelConstants.ONE.equals(map.get("firmFlag"))) { + wrapper.eq("firm_id",map.get("firmId")); + dto.setFirmId(map.get("firmId")); + } else { + //代理商 + wrapper.eq("agent_id",map.get("firmId")); + dto.setAgentId(map.get("firmId")); + } + } + wrapper.eq("audit_status",DeviceModelConstants.TWO); + wrapper.eq("del_flag",DeviceModelConstants.ONE); + List infos = baseMapper.selectList(wrapper); + DeviceCountInfo info =new DeviceCountInfo(); + if (StringUtils.isNotEmpty(infos) && infos.size()>0){ + List collect = infos.parallelStream().map(DeviceInfo::getImei).collect(Collectors.toList()); + //查询今日新增数 + info.setDeviceTodayAddNumber(baseMapper.queryDeviceTodayAdd(dto)); + //查询激活设备数 + // int activateNumber = baseMapper.queryDeviceActivate(dto); + int activateNumber=queryDeviceActivateCount(collect); + info.setDeviceActivateNumber(activateNumber); + //设备总数 + int size = infos.size(); + info.setDeviceTotal(size); + //查询设备在线数 + int OnLineNumber= queryOneLineNumber(infos); + info.setDeviceOnlineNumber(OnLineNumber); + //查询设备离线数, + info.setDeviceOfflineNumber(activateNumber-OnLineNumber); + //设备未激活数, + info.setDeviceNotActivateNumber(size-activateNumber); + + }else { + info.setDeviceActivateNumber(0); + info.setDeviceNotActivateNumber(0); + info.setDeviceTotal(0); + info.setDeviceOnlineNumber(0); + info.setDeviceTodayAddNumber(0); + info.setDeviceOfflineNumber(0); + } + + return info; + } + //查询设备激活数 + private int queryDeviceActivateCount(List list){ + int count=0; + for (String s : list) { + if (redisService.hasKey(s)){ + //在线 + if (StringUtils.isNotNull(redisService.getCacheMapValue(s,"firstLogin"))){ + count++; + } + } + } + return count; + + } + //查询设备在线数 + private int queryOneLineNumber(List list){ + List collect = list.parallelStream().map(DeviceInfo::getImei).collect(Collectors.toList()); + int count=0; + for (String s : collect) { + if (redisService.hasKey(s)){ + //在线 + if (DeviceModelConstants.ONE.equals(Optional.ofNullable(redisService.getCacheMapValue(s,"onlineStatus")).orElse(DeviceModelConstants.ZERO))){ + count++; + } + } + } + return count; + + } + + + /** + * 填充属性 + * @param list + */ + private List fillProperties( List list){ + return list.stream().map(this::fillEquipmentFunctionVOProperties).collect(Collectors.toList()); + + } + + private EquipmentFunctionVO fillEquipmentFunctionVOProperties( EquipmentFunctionVO vo){ + String imei = vo.getImei(); + if (vo.getPositioningInterval()==0){ + vo.setPositioningInterval(10); + } + //根据imei查询电话本 + List telephoneBookVOS = baseMapper.queryBookByImei(imei); + //根据imei查询闹钟信息 + List alarmVOS = baseMapper.queryAlarmByImei(imei); + //根据imei查询上课禁用信息 + List disableVOS = baseMapper.queryDisableByImei(imei); + //根据imei查询安全围栏信息 + List safetyRailVOS = baseMapper.querySafetyRaliByImei(imei); + vo.setBooks(telephoneBookVOS); + vo.setAlarms(alarmVOS); + vo.setDisables(disableVOS); + vo.setSafetyRail(safetyRailVOS); + return vo; + } + + /** + * 根据id + * 批量删除设备 + * + * @param imeis + * @return + */ + @Transactional(rollbackFor = Exception.class) + @Override + public boolean delDeviceByIds(List imeis) { + if (!StringUtils.isNotEmpty(imeis)) { + throw new ServiceException("删除失败,数据不能为空"); + } + return deviceInfoServiceImpl.delDeviceByImei(imeis, DeviceModelConstants.ZERO); + + + } + + /** + * 导入imei批量删除 + * + * @param imeis + * @param sign(0.就是删除设备,1就是解绑设备) + * @return + */ + @Transactional(rollbackFor = Exception.class) + @Override + public boolean delDeviceByImei(List imeis, String sign) { + + if (StringUtils.isNotEmpty(imeis) && imeis.size() > 0) { + if (imeis.size() > 10000) { + // 已超过10000条,请分批导入 + throw new ServiceException("messages.import.money.thousand.error"); + } + //查询绑定表,该imei已经绑定,这里自己写SQL + List list = baseMapper.queryBindImeiByList(imeis); + if (StringUtils.isNotEmpty(list) && list.size() > 200) { + // "绑定设备已超过200条,请分批导入" + throw new ServiceException("messages.import.two.hundred.error"); + } + //如果删除设备 + if (DeviceModelConstants.ZERO.equals(sign)) { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("audit_status", DeviceModelConstants.TWO); + wrapper.eq("del_flag", DeviceModelConstants.ONE); + wrapper.in("imei", imeis); + List infos = mapper.selectList(wrapper); + if (!StringUtils.isNotEmpty(infos) || infos.size() <= 0) { + throw new ServiceException("删除失败,请联系管理员"); + } + //这里做的目的是减少字段的更新操作 + List collect = infos.parallelStream().map(s -> { + DeviceInfo info = new DeviceInfo(); + info.setDelFlag(DeviceModelConstants.ZERO); + info.setDeviceId(s.getDeviceId()); + return info; + }).collect(Collectors.toList()); + log.info("要删除的条数:{},实际删除的条数:{},相差的条数:{}", imeis.size(), infos.size(), imeis.size() - infos.size()); + updateBatchById(collect); + } + log.info("查询绑定表的数据是:{}",list); + if (StringUtils.isNotEmpty(list) && list.size() > 0) { + //查询绑定表管理员ID + List adminIds = baseMapper.queryBingOrOwnerInfo(imeis); + +// //查询群组表成员 +// if (StringUtils.isNotEmpty(adminIds) && adminIds.size() > DeviceModelConstants.NUMBER_ZERO) { +// for (DeviceAdminOwnerInfo info : adminIds) { +// String groupId = info.getGroupId(); +// String adminId = info.getUserId(); +// List list1 =null; +// //根据群组ID and 管理员ID 查询群组成员信息表 +// if (StringUtils.isNotEmpty(groupId)){ +// list1 = baseMapper.queryChatMemberById(groupId, adminId); +// } +// if (StringUtils.isNotNull(list1)){ +// info.setIds(list1); +// } +// +// } +// //删除设备绑定信息相关表,及redis缓存 +// deviceInfoServiceImpl.deletaBingImeiInfo(list, adminIds); +// } + + if (StringUtils.isNotEmpty(adminIds) && adminIds.size()>0){ + List collect = adminIds.stream().map(s -> { + if (StringUtils.isNull(s)) { + String groupId = s.getGroupId(); + String adminId = s.getUserId(); + List list1 = null; + //根据群组ID and 管理员ID 查询群组成员信息表 + if (StringUtils.isNotEmpty(groupId)) { + list1 = baseMapper.queryChatMemberById(groupId, adminId); + } + if (StringUtils.isNotNull(list1)) { + s.setIds(list1); + } + + } + return s; + + }).collect(Collectors.toList()); + //删除设备绑定信息相关表,及redis缓存 + deviceInfoServiceImpl.deletaBingImeiInfo(list, collect); + } + + } + + } + + + return true; + } + + /** + * 删除设备绑定信息相关表,及redis缓存 + * + * @param imei + */ + public void deletaBingImeiInfo(List imei, List adminIds) { + + //删除设备拥有者信息表deleteDeviceOwnerInfo + baseMapper.deleteDeviceOwnerInfo(imei); + // 删除绑定数据 + baseMapper.deleteUserBindInfo(imei); + //查询群组id + List ids = baseMapper.queryChatGroupIdByImei(imei); + baseMapper.deleteChatGroup(imei); + baseMapper.deleteGroupMember(ids); + baseMapper.deleteMessage(ids); + baseMapper.deleteAddressBook(imei); + baseMapper.deleteDeviceAttention(imei); + baseMapper.deleteLatestLocation(imei); + baseMapper.deleteDeviceLocation(imei); + baseMapper.deleteAlarm(imei); + baseMapper.deleteDeviceDisable(imei); + baseMapper.deleteDeviceTimeSwitch(imei); + baseMapper.deleteSafetyRail(imei); + baseMapper.deleteSOSInfo(imei); + baseMapper.deleteReminderMessage(imei); + baseMapper.deleteVideoInfo(imei); + baseMapper.deleteTrackInfo(imei); + log.info("删除设备成功,开始下发指令到设备"); + //异步下发指令 + if (StringUtils.isNotEmpty(adminIds) && adminIds.size() > 0) { + deviceInfoServiceImpl.sendIssueInstruction(adminIds); + } + // 异步返送信息给APP先不做 + // sendUnbindInfoToApp(adminIds); + } + + /** + * 下发指令 + */ + @Async + public void sendIssueInstruction(List adminIds) { + for (DeviceAdminOwnerInfo bingInfo : adminIds) { + String imei = bingInfo.getImei(); + //获取设备状态是否在线 + String onlineStatus = redisService.getCacheMapValue(imei, "onlineStatus"); + //组装参数 + DistributeParent distributeParent = new DistributeParent(); + distributeParent.setTime(System.currentTimeMillis()); + distributeParent.setOpenid(bingInfo.getUserId()); + distributeParent.setType("reset"); + distributeParent.setVender("20000"); + distributeParent.setIdent(RandomUtils.generateVerCode(6)); + distributeParent.setImei(imei); + restRedis(imei); + //在线才下发 + if (DeviceModelConstants.ONE.equals(onlineStatus)) { + sendKafka(distributeParent); + } + } + + + } + + /** + * 发送信息到APP + */ + @Async + public void sendUnbindInfoToApp(List infos) { + log.info("异步发送信息,异步线程名称:{}", Thread.currentThread().getName()); + if (StringUtils.isNotEmpty(infos) && infos.size() > DeviceModelConstants.NUMBER_ZERO) { + for (DeviceAdminOwnerInfo info : infos) { + String groupId = info.getGroupId(); + String adminId = info.getUserId(); + String imei = info.getImei(); + String name = info.getName(); + //根据群组ID and 管理员ID 查询群组成员信息表 + List list = info.getIds(); + if (StringUtils.isNotEmpty(list) && list.size() > 0) { + for (String s : list) { + ChatGroupDisbandMessageInfo message = new ChatGroupDisbandMessageInfo(); + message.setType("chatGroupDisband"); + message.setDisbandTime(new Date()); + message.setName(name); + message.setImei(imei); + message.setOperator(adminId); + message.setGroupId(groupId); + String s1 = JSON.toJSONString(message); + String topic = USER_MQTT_PREDIX + s; + //发送到APP + AppSingleMqttClient.publishCustomMessage(2, s1, topic); + } + } + + } + + } + + } + + /** + * 恢复出厂设置 + * + * @param imei + */ + public void restRedis(String imei) { + List list = Arrays.asList("messageVoice", "messageVoiceSync", "centerPhone", "weather", "weather_time", "weather_adcode", "locMode_rate", "locMode_rateSync", "reject", "rejectSync", "dialSwitch", + "dialSwitchSync", "volume", "volumeSync", "downSchoolTimeTable", "downSchoolTimeTableSync", "setHeartRate", "setHeartRateSync", "setBodyTemperature", "setBodyTemperatureSync", + "setBootOff", "setBootOffSync", "setSetpSwitch", "setSetpSwitchSync", "ppmessage", "ppmessageSync", "sos", "sosSync", "familyPhoneList", "familyPhoneListSync", "whitePhoneList", + "whitePhoneListSync", "studentInfo", "studentInfoSync"); + log.info("设备恢复出厂设置:{}", imei); + // delRedisKey(imei,list); + if (redisService.deleteObject(imei)) { + redisService.setCacheMapValue(imei, "contacts", "{\"last\":0,\"ident\":1616,\"contact\":[],\"index\":0,\"type\":'contact'}"); + redisService.setCacheMapValue(imei, "contactsSync", "1"); + redisService.setCacheMapValue(imei, "alarms", "{\"ident\":3030,\"alarm\":[],\"type\":'alarm'}"); + redisService.setCacheMapValue(imei, "alarmsSync", "1"); + redisService.setCacheMapValue(imei, "disBan", "{\"disturb\": [], \"ident\": 2828, \"type\": 'disturb'}"); + redisService.setCacheMapValue(imei, "disBanSync", "1"); + redisService.setCacheMapValue(imei, "onlineStatus", "0"); + redisService.setCacheMapValue(imei, "agent", "20000"); + redisService.setCacheMapValue(imei, "deviceHead", "YS"); + } + + } + + // 下发KAFKA + public void sendKafka(Object object) { + log.info("下发到kafka的数据信息:{}", object); + kafkaTemplate.send(DeviceModelConstants.WATCHPUSH_KAFKA, JSON.toJSONString(object)).addCallback(success -> { + log.info("发送到kafka具体信息{},partition 分区 {},offset {}", success.getRecordMetadata().topic(), success.getRecordMetadata().partition(), success.getRecordMetadata().offset()); + + }, failure -> { + //失败 + log.info("下发到kafka的数据信息失败:{}", failure.getMessage()); + log.info("发送到kafka具体信息{}", JSON.toJSONString(object)); + + }); + + + } + + + /** + * 查询所有审核通过未删除的设备 + * + * @return + */ + @Override + public List queryApprovedDevice() { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("audit_status", DeviceModelConstants.TWO); + wrapper.eq("del_flag", DeviceModelConstants.ONE); + + return deviceModelInfoMapper.selectList(wrapper); + } + + /** + * 根据 imei 查询设备信息 对APP使用 + * + * @return + */ + @Override + public DeviceInfo queryDeviceInfoByImei(String imei) { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("imei", imei); + wrapper.eq("del_flag", DeviceModelConstants.ONE); + //加上limit 不加如果有多条记录会抛异常 + wrapper.last("LIMIT 1"); + return mapper.selectOne(wrapper); + } + + + + private DeviceInfo convertStringToClass(String imei, DeviceDTO dto, int TotalImport, String inputBatch) { + DeviceInfo info = new DeviceInfo(); + info.setDeviceModelId(dto.getDeviceModelId()); + info.setFirmId(dto.getFirmId()); + info.setFirmName(dto.getFirmName()); + info.setDeviceModelName(dto.getDeviceModelName()); + info.setImei(imei); + info.setAgentId(dto.getAgentId()); + info.setAgentName(dto.getAgentName()); + //设置id + info.setDeviceId(UUID.fastUUID().toString(true)); + //设置录入标志 + info.setInputFlag(DeviceModelConstants.ONE); + //info.setAuditDevice(imei); + //设置导入数量 + info.setTotalImport(TotalImport); + //设置批次号 + info.setInputBatch(inputBatch); + return info; + + } + + + private String checkImei(List imeiList) { + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + if (StringUtils.isNull(imeiList) && imeiList.size() == 0) { + throw new ServiceException("导入IMEI数据不能为空"); + } + for (DeviceInfo dto : imeiList) { + try { + if (dto.getImei().trim().length() != 15) { // I18nUtil.getMessage(ServiceExceptionResultConstant.RESULT_MSG_MAP.get("messages.length.error")) + failureNum++; + failureMsg.append("
" + failureNum + "、IMEI:" + dto.getImei() + LocaleUtil.getMessage("messages.length.error") + dto.getImei().length()); + continue; + }else if (!org.apache.commons.lang3.StringUtils.isNumeric((dto.getImei()))){ + failureNum++; + failureMsg.append("
" + failureNum + "、IMEI:" + dto.getImei() + LocaleUtil.getMessage("messages.incorrect.content.error")); + continue; + } else { + if (StringUtils.isNotNull(queryDeviceByImei(dto.getImei()))) { + failureNum++; + failureMsg.append("
" + failureNum + "、IMEI " + dto.getImei() + LocaleUtil.getMessage("messages.already.exists")); + continue; + } else { + this.save(dto); + successNum++; + successMsg.append("
" + successNum + "、IMEI " + dto.getImei() +LocaleUtil.getMessage("messages.import.success")); + + } + } + + + } catch (Exception e) { + failureNum++; + String msg = "
" + failureNum + "、IMEI " + dto.getImei() + LocaleUtil.getMessage("messages.import.failed"); + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + + } + + + } + +// if (failureNum > 0) +// { +// failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); +// // throw new ServiceException(failureMsg.toString()); +// return failureMsg.toString(); +// } +// else +// { +// successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); +// return successMsg.toString(); +// } + + if (failureNum > 0 && successNum > 0) { + + failureMsg.insert(0, LocaleUtil.getMessage("messages.sorry.import.success") + failureNum + LocaleUtil.getMessage("messages.data.import.failed") + successNum + LocaleUtil.getMessage("messages.data.import.success") + successNum + LocaleUtil.getMessage("messages.data.import.error")); + return failureMsg.toString(); + } else if (failureNum > 0) { + + failureMsg.insert(0, LocaleUtil.getMessage("messages.data.import.common.failed") + failureNum + LocaleUtil.getMessage("messages.import.format.error")); + return failureMsg.toString(); + + } else { + successMsg.insert(0, LocaleUtil.getMessage("messages.import.congratulations.success") + successNum + LocaleUtil.getMessage("messages.data.are")); + return successMsg.toString(); + } + + } + + @Transactional(rollbackFor = Exception.class) + public String checkImeiTwo(MultipartFile file,List imeiList,String inputBatch) { + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + List list =new ArrayList(); + if (StringUtils.isNull(imeiList) && imeiList.size() == 0) { + throw new ServiceException("导入IMEI数据不能为空"); + } +// for (DeviceInfo dto : imeiList) { +// try { +// if (dto.getImei().trim().length() != 15) { // I18nUtil.getMessage(ServiceExceptionResultConstant.RESULT_MSG_MAP.get("messages.length.error")) +// failureNum++; +// failureMsg.append("
" + failureNum + "、IMEI:" + dto.getImei() + I18nUtil.getMessage("messages.length.error") + dto.getImei().length()); +// } else { +// if (StringUtils.isNotNull(queryDeviceByImei(dto.getImei()))) { +// failureNum++; +// failureMsg.append("
" + failureNum + "、IMEI " + dto.getImei() + I18nUtil.getMessage("messages.length.error")); +// } else { +// this.save(dto); +// successNum++; +// successMsg.append("
" + successNum + "、IMEI " + I18nUtil.getMessage("messages.import.success")); +// +// } +// } +// +// +// } catch (Exception e) { +// failureNum++; +// String msg = "
" + failureNum + "、IMEI " + dto.getImei() + I18nUtil.getMessage("messages.import.failed"); +// failureMsg.append(msg + e.getMessage()); +// log.error(msg, e); +// +// } +// +// +// } + Iterator iterator = imeiList.iterator(); + while (iterator.hasNext()){ + DeviceInfo dto = iterator.next(); + + try { + if (dto.getImei().trim().length() != 15) { // I18nUtil.getMessage(ServiceExceptionResultConstant.RESULT_MSG_MAP.get("messages.length.error")) + failureNum++; + failureMsg.append("
" + failureNum + "、IMEI:" + dto.getImei() + LocaleUtil.getMessage("messages.length.error") + dto.getImei().length()); + iterator.remove(); + continue; + }else if (!org.apache.commons.lang3.StringUtils.isNumeric((dto.getImei()))){ + failureNum++; + failureMsg.append("
" + failureNum + "、IMEI:" + dto.getImei() + LocaleUtil.getMessage("messages.incorrect.content.error")); + iterator.remove(); + continue; + } else { + if (StringUtils.isNotNull(queryDeviceByImei(dto.getImei()))) { + failureNum++; + failureMsg.append("
" + failureNum + "、IMEI " + dto.getImei() + LocaleUtil.getMessage("messages.length.error")); + iterator.remove(); + continue; + } else { + this.save(dto); + successNum++; + successMsg.append("
" + successNum + "、IMEI " + LocaleUtil.getMessage("messages.import.success")); + list.add(dto); + } + } + + + + } catch (Exception e) { + failureNum++; + iterator.remove(); + String msg = "
" + failureNum + "、IMEI " + dto.getImei() + LocaleUtil.getMessage("messages.import.failed"); + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + + } + + } + log.info("录入的设备数:{},实际录入的设备数:{}",imeiList.size(),list.size()); + if (list.size()==imeiList.size()){ + try { + UploadUtil.uploadTwo(file,inputBatch); + } catch (IOException e) { + throw new ServiceException(e.getMessage()); + } + }else { + String originalFilename = file.getOriginalFilename(); + String substring = originalFilename.substring(originalFilename.lastIndexOf(".") + 1); + + + + } + + if (failureNum > 0 && successNum > 0) { + + failureMsg.insert(0, LocaleUtil.getMessage("messages.sorry.import.success") + failureNum + LocaleUtil.getMessage("messages.data.import.failed") + successNum + LocaleUtil.getMessage("messages.data.import.success") + successNum + LocaleUtil.getMessage("messages.data.import.error")); + return failureMsg.toString(); + } else if (failureNum > 0) { + + failureMsg.insert(0, LocaleUtil.getMessage("messages.data.import.common.failed") + failureNum + LocaleUtil.getMessage("messages.import.format.error")); + return failureMsg.toString(); + + } else { + successMsg.insert(0, LocaleUtil.getMessage("messages.import.congratulations.success") + successNum + LocaleUtil.getMessage("messages.data.are")); + return successMsg.toString(); + } + + } + + + private DeviceActivaVO calculation(DeviceActivaVO vo) { + //根据批次查询出imei + List list = queryImeiListByInputBatch(vo.getInputBatch()); + if (StringUtils.isNotEmpty(list)){ + List collect = list.stream().map(DeviceInfo::getImei).collect(Collectors.toList()); + //根据imei查询设备激活的数量(这里查询位置信息最新的表) + // int i = baseMapper.queryActivateDeviceCount(collect); + //激活数量 + int i= queryDeviceActivateCount(collect); + vo.setActivateDevice(i); + if (i==0){ + //激活数量为0,激活比例也为0 + vo.setActivationRatio("0"); + }else { + double v = vo.getInputDevice().doubleValue(); + nf.setMaximumFractionDigits(2); + vo.setActivationRatio(nf.format(i / v)); + } + // 根据imei查询绑定设备数量(这里查询位置信息最新的表,设备绑定表) + int bindCount= baseMapper.queryBindDeviceCount(collect); + vo.setWhetherBinding(bindCount); + + } + return vo; + } + + + private List queryImeiListByInputBatch(String inputBatch){ + QueryWrapper wrapper =new QueryWrapper<>(); + wrapper.eq("input_batch",inputBatch); + wrapper.eq("del_flag",DeviceModelConstants.ONE); + wrapper.eq("audit_status",DeviceModelConstants.TWO); + return baseMapper.selectList(wrapper); + + } + + /** + * 厂商列表统计专用 + * @return + */ + public DeviceActivaVO queryFirmCountDevice(String firmId,String agentId){ + DeviceActivaVO vo =new DeviceActivaVO(); + //根据厂商ID或代理商id查询设备统计信息 + List list = baseMapper.queryFirmInputCountDevice(firmId, agentId); + if (StringUtils.isNotEmpty(list) && list.size()>0){ + //设备录入数 + vo.setInputDevice(list.size()); + //设备激活数 + int i = queryDeviceActivateCount(list); + vo.setActivateDevice(i); + } + return vo; + } + + + + /** + * 根据用户名称 查询 厂商,代理商ID + * + * @param username + * @return + */ + private List queryFrimId(String username) { + List list = new ArrayList<>(); + SysUser sysUser = api.queryByUserName(username); + if (StringUtils.isNotNull(sysUser)) { + //是厂商 + if (DeviceModelConstants.ONE.equals(sysUser.getFirmFlag())) { + //TODO 根据厂商查询下面的代理商 + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("parent_id", sysUser.getFirmId()); + List firmManages = firmManageMapper.selectList(wrapper); + if (StringUtils.isNotEmpty(firmManages) && firmManages.size() > 0) { + list = firmManages.stream().map(FirmManage::getFirmId).collect(Collectors.toList()); + } + list.add(sysUser.getFirmId()); + + } else {//是代理商 + //TODO 代理商直接看代理商的 + // list.add(sysUser.getFirmId()); + list.add(sysUser.getSecondFirmId()); + } + } + + return list; + + + } + + /*** + * 转换 + * @return + */ + private void convertIPage(IPage page) { + if (StringUtils.isNotNull(page) && page.getRecords().size() > 0) { + + //设备型号id + List records = page.getRecords(); + List collect = records.stream().map(s -> { + DeviceModelInfo info = deviceModelInfoMapper.selectById(s.getDeviceModelId()); + if (StringUtils.isNotNull(info)){ + String s1 = DeviceModelInfoUtli.assembleFunDescription(info); + s.setFunDescription(s1); + } + //根据批次号查询录入总数 + List infos = queryInputBatchListTwo(s.getInputBatch()); + if (StringUtils.isNotEmpty(infos) && infos.size()>0){ + s.setInputSuccessTotal(infos.size()); + } + + return s; + }).collect(Collectors.toList()); + + page.setRecords(collect); + + } + + } + + /** + * 根据imei查询该设备有没有正在审批或者审批通过 + * + * @param imei + */ + private List checkAuditStatus(String imei) { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("imei", imei); + wrapper.eq("del_flag", DeviceModelConstants.ONE); + //查询待审核或者已审批的设备 + wrapper.lambda().and(s -> s.eq(DeviceInfo::getAuditStatus, DeviceModelConstants.ONE).or().eq(DeviceInfo::getAuditStatus, DeviceModelConstants.TWO)); + List infos = baseMapper.selectList(wrapper); + + return infos; + } + + /** + * 根据批次号查询设备信息 + * @param inputBatch + * @return + */ + private DeviceInfo queryInputBatch(String inputBatch){ + QueryWrapper wrapper =new QueryWrapper<>(); + wrapper.eq("input_batch",inputBatch); + wrapper.eq("audit_status",DeviceModelConstants.ONE); + wrapper.eq("del_flag",DeviceModelConstants.ONE); + wrapper.last("LIMIT 1"); + return baseMapper.selectOne(wrapper); + } + + /** + * 根据批次号查询设备信息 + * @param inputBatch + * @return + */ + @Override + public List queryInputBatchListTwo(String inputBatch){ + QueryWrapper wrapper =new QueryWrapper<>(); + wrapper.eq("input_batch",inputBatch); + wrapper.eq("del_flag",DeviceModelConstants.ONE); + return baseMapper.selectList(wrapper); + } +} diff --git a/ecell-internationalize/ecell-internationalize-system/src/main/resources/com/ecell/internationalize/system/mapper/DeviceInfoMapper.xml b/ecell-internationalize/ecell-internationalize-system/src/main/resources/com/ecell/internationalize/system/mapper/DeviceInfoMapper.xml new file mode 100644 index 0000000..6aa4b17 --- /dev/null +++ b/ecell-internationalize/ecell-internationalize-system/src/main/resources/com/ecell/internationalize/system/mapper/DeviceInfoMapper.xml @@ -0,0 +1,481 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + update device_owner_info_app set positioning_model_id=#{pId} where imei in (select imei from device_info where del_flag ='1'and device_model_id=#{mId}) + + + + + + + + + + + delete from device_owner_info_app where imei in + + #{item} + + + + + + delete from user_device_bind_app where imei in + + #{item} + + + + + + delete from chant_group_app where imei in + + #{item} + + + + + + + + + delete from chat_group_member_app where group_id in + + #{item} + + + + + + delete from chat_group_message_app where group_id in + + #{item} + + + + + + delete from address_book_app where imei in + + #{item} + + + + + + + delete from device_attention_app where imei in + + #{item} + + + + + + + delete from latest_location_app where imei in + + #{item} + + + + + + + delete from device_location_app where imei in + + #{item} + + + + + + delete from device_alarm where i_mei in + + #{item} + + + + + + + delete from device_disable_app where imei in + + #{item} + + + + + + + + delete from device_time_switch_app where imei in + + #{item} + + + + + + delete from safety_rail_app where imei in + + #{item} + + + + + + delete from imei_sos_info where imei in + + #{item} + + + + + + + delete from reminder_message_app where imei in + + #{item} + + + + + + delete from device_video_app where imei in + + #{item} + + + + + + + delete from track_info_app where imei in + + #{item} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file