From c348f2b7641dcbfdbdc435dae026ea58f8d5e1b8 Mon Sep 17 00:00:00 2001 From: liwen Date: Tue, 16 Jan 2024 13:41:13 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E7=89=B9=E7=A7=8D=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/safeproduct/entity/DeviceEntity.java | 68 +++++++++++++++++++ .../hzims/safeproduct/enums/DeviceStatusEnum.java | 30 +++++++++ .../safeproduct/controller/DeviceController.java | 76 ++++++++++++++++++++++ .../com/hnac/hzims/safeproduct/jobs/DeviceJob.java | 41 ++++++++++++ .../hzims/safeproduct/mapper/DeviceMapper.java | 16 +++++ .../hnac/hzims/safeproduct/mapper/DeviceMapper.xml | 4 ++ .../hzims/safeproduct/service/IDeviceService.java | 22 +++++++ .../service/impl/DeviceServiceImpl.java | 33 ++++++++++ .../safeproduct/src/main/resources/db/1.0.2.sql | 24 ++++++- 9 files changed, 312 insertions(+), 2 deletions(-) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DeviceEntity.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/DeviceStatusEnum.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/DeviceController.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/DeviceJob.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.xml create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IDeviceService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/DeviceServiceImpl.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DeviceEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DeviceEntity.java new file mode 100644 index 0000000..34776c9 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/DeviceEntity.java @@ -0,0 +1,68 @@ +package com.hnac.hzims.safeproduct.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * @author liwen + * @date 2024-01-12 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_device") +@ApiModel(value = "特种设备实体类") +public class DeviceEntity extends BaseEntity { + + @Size(max = 50, message = "设备名称长度不能超过50") + @ApiModelProperty("设备名称") + private String name; + + @Size(max = 50, message = "规格型号长度不能超过50") + @ApiModelProperty("规格型号") + private String type; + + @Size(max = 50, message = "设备编码长度不能超过50") + @ApiModelProperty("设备编码") + private String code; + + @Size(max = 255, message = "产品合格证号长度不能超过255") + @ApiModelProperty("产品合格证号") + private String qualityCertificateNo; + + @ApiModelProperty("生产日期") + private Date productionTime; + + @ApiModelProperty("使用时间") + private Date usedTime; + + @Size(max = 255, message = "使用地点长度不能超过255") + @ApiModelProperty("使用地点") + private String usedLocation; + + @ApiModelProperty("检验周期") + private Integer inspectionPeriod; + + @ApiModelProperty("本次检验日期") + private Date inspectionCurrentTime; + + @ApiModelProperty("下次检验日期") + private Date inspectionNextTime; + + @ApiModelProperty("上次检验日期") + private Date inspectionLastTime; + + @Size(max = 50, message = "设备管理人长度不能超过50") + @ApiModelProperty("设备管理人") + private String manager; + + @Size(max = 20, message = "设备状态长度不能超过20") + @ApiModelProperty("设备状态") + private String deviceStatus; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/DeviceStatusEnum.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/DeviceStatusEnum.java new file mode 100644 index 0000000..22a183c --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/DeviceStatusEnum.java @@ -0,0 +1,30 @@ +package com.hnac.hzims.safeproduct.enums; + +/** + * 特种设备状态枚举类 + * + * @author liwen + * @date 2024-01-16 + */ +public enum DeviceStatusEnum { + + NORMAL("NORMAL", "正常"), + EXPIRED("EXPIRED", "待检修"); + + private final String value; + + private final String desc; + + DeviceStatusEnum(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public String getDesc() { + return desc; + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/DeviceController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/DeviceController.java new file mode 100644 index 0000000..768b523 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/DeviceController.java @@ -0,0 +1,76 @@ +package com.hnac.hzims.safeproduct.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzims.safeproduct.entity.DeviceEntity; +import com.hnac.hzims.safeproduct.service.IDeviceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.util.Map; + +/** + * 特种设备管理接口类 + * + * @author liwen + * @date 2024-01-12 + */ +@RequestMapping("/device") +@AllArgsConstructor +@RestController +@Api(value = "特种设备", tags = "特种设备接口") +public class DeviceController extends BladeController { + + private final IDeviceService deviceService; + + @PostMapping("/save") + @ApiOperation(value = "新增") + @ApiOperationSupport(order = 1) + public R save(@Valid @RequestBody DeviceEntity deviceEntity) { + return R.status(deviceService.save(deviceEntity)); + } + + @PostMapping("/update") + @ApiOperation(value = "修改") + @ApiOperationSupport(order = 2) + public R update(DeviceEntity deviceEntity) { + return R.status(deviceService.updateById(deviceEntity)); + } + + @PostMapping("/remove") + @ApiOperation(value = "删除") + @ApiOperationSupport(order = 3) + public R remove(@RequestParam Long id) { + return R.status(deviceService.removeById(id)); + } + + @GetMapping("/detail") + @ApiOperation(value = "详情") + @ApiOperationSupport(order = 4) + public R detail(@RequestParam Long id) { + return R.data(deviceService.getById(id)); + } + + @GetMapping("/page") + @ApiImplicitParams({ + @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "plateNumber", value = "车牌号", dataType = "query", paramType = "string") + }) + @ApiOperation(value = "分页") + @ApiOperationSupport(order = 5) + public R> page(@ApiIgnore @RequestParam Map param, Query query) { + IPage page = deviceService.page(Condition.getPage(query), Condition.getQueryWrapper(param, DeviceEntity.class) + .lambda().orderByDesc(DeviceEntity::getCreateTime)); + return R.data(page); + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/DeviceJob.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/DeviceJob.java new file mode 100644 index 0000000..dd7a622 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/DeviceJob.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.safeproduct.jobs; + +import com.hnac.hzims.safeproduct.entity.DeviceEntity; +import com.hnac.hzims.safeproduct.enums.DeviceStatusEnum; +import com.hnac.hzims.safeproduct.service.IDeviceService; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.List; + +/** + * 特种设备模块定时任务 + * + * @author liwen + * @date 2024-01-16 + */ +@Component +public class DeviceJob { + + @Autowired + IDeviceService deviceService; + + @XxlJob("autoChangeDeviceStatus") + public ReturnT autoChangeDeviceStatus(String param) { + // 获取时间范围 + Date current = DateUtil.now(); + Date before = DateUtil.minusDays(current, 1); + String today = DateUtil.format(current, "yyyy-mm-dd"); + String yesterday = DateUtil.format(before, "yyyy-mm-dd"); + // 查询昨天的过期设备 + List list = deviceService.getExpiredDeviceByTime(yesterday, today); + list.forEach(e -> e.setDeviceStatus(DeviceStatusEnum.EXPIRED.getValue())); + // 更新状态 + boolean update = deviceService.updateBatchById(list); + return update ? ReturnT.SUCCESS : ReturnT.FAIL; + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.java new file mode 100644 index 0000000..c15512d --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.safeproduct.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.safeproduct.entity.DeviceEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 特种设备Mapper类 + * + * @author liwen + * @date 2024-01-12 + */ +@Mapper +public interface DeviceMapper extends BaseMapper { + +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.xml new file mode 100644 index 0000000..a863567 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/DeviceMapper.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IDeviceService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IDeviceService.java new file mode 100644 index 0000000..5500bf9 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IDeviceService.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.safeproduct.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.entity.DeviceEntity; + +import java.util.List; + +/** + * 特种设备服务类 + * + * @author liwen + * @date 2024-01-12 + */ +public interface IDeviceService extends IService { + + /** + * 查找时间范围内的过期设备 + * @param startTime 开始时间 + * @param endTime 结束时间 + */ + List getExpiredDeviceByTime(String startTime, String endTime); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/DeviceServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/DeviceServiceImpl.java new file mode 100644 index 0000000..bee1994 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/DeviceServiceImpl.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.safeproduct.entity.DeviceEntity; +import com.hnac.hzims.safeproduct.enums.DeviceStatusEnum; +import com.hnac.hzims.safeproduct.mapper.DeviceMapper; +import com.hnac.hzims.safeproduct.service.IDeviceService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 特种设备服务实现类 + * + * @author liwen + * @date 2024-01-12 + */ +@Service +public class DeviceServiceImpl extends ServiceImpl implements IDeviceService { + + /** + * 查找时间范围内的过期设备 + */ + @Override + public List getExpiredDeviceByTime(String startTime, String endTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(DeviceEntity::getDeviceStatus, DeviceStatusEnum.NORMAL.getValue()) + .ge(DeviceEntity::getInspectionNextTime, startTime) + .le(DeviceEntity::getInspectionNextTime, endTime); + return this.list(queryWrapper); + } +} diff --git a/hzims-service/safeproduct/src/main/resources/db/1.0.2.sql b/hzims-service/safeproduct/src/main/resources/db/1.0.2.sql index 1c13094..b404b6f 100644 --- a/hzims-service/safeproduct/src/main/resources/db/1.0.2.sql +++ b/hzims-service/safeproduct/src/main/resources/db/1.0.2.sql @@ -339,7 +339,27 @@ CREATE TABLE `hzims_car_check_item` ( PRIMARY KEY (`id`) USING BTREE ) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='车检项表' ROW_FORMAT=Dynamic; -CREATE TABLE `hzims_equipment` ( +CREATE TABLE `hzims_device` ( `id` bigint(20) NOT NULL COMMENT '主键id', - `name` + `name` varchar(50) NOT NULL COMMENT '设备名称', + `type` varchar(50) NOT NULL DEFAULT '' COMMENT '规格型号', + `code` varchar(50) NOT NULL COMMENT '编码', + `quality_cerfiticate_no` varchar(255) NOT NULL DEFAULT '' COMMENT '产品合格证号', + `production_time` date DEFAULT NULL COMMENT '生产日期', + `used_time` date DEFAULT NULL COMMENT '使用日期', + `used_location` varchar(255) NOT NULL DEFAULT '' COMMENT '使用地点', + `inspection_period` int(10) DEFAULT NULL COMMENT '检验周期', + `inspection_current_time` date DEFAULT NULL COMMENT '本次检验日期', + `inspection_next_time` date DEFAULT NULL COMMENT '下次检验日期', + `inspection_last_time` date DEFAULT NULL COMMENT '上次检验日期', + `manager` varchar(50) NOT NULL DEFAULT '' COMMENT '设备管理人', + `device_status` varchar(20) NOT NULL DEFAULT 'NORMAL' COMMENT '设备状态', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE ) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='特种设备表' ROW_FORMAT=Dynamic; \ No newline at end of file