yys
1.设备区域
2.设备巡检,维保,保养多选
3.数采
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | CREATE TABLE `device_area` ( |
| | | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主é®ID', |
| | | `area_name` varchar(100) NOT NULL COMMENT 'åºååç§°', |
| | | `parent_id` bigint DEFAULT NULL COMMENT 'ç¶çº§ID', |
| | | `sort` bigint DEFAULT 0 COMMENT 'æåº', |
| | | `remark` varchar(255) DEFAULT NULL COMMENT '夿³¨', |
| | | `create_time` datetime DEFAULT NULL COMMENT 'å建æ¶é´', |
| | | `update_time` datetime DEFAULT NULL COMMENT 'æ´æ°æ¶é´', |
| | | `create_user` int DEFAULT NULL COMMENT 'åå»ºç¨æ·', |
| | | `update_user` int DEFAULT NULL COMMENT 'æ´æ°ç¨æ·', |
| | | `tenant_id` bigint DEFAULT NULL COMMENT 'ç§æ·ID', |
| | | `dept_id` bigint DEFAULT NULL COMMENT 'é¨é¨ID', |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='设å¤åºå'; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | ALTER TABLE `device_maintenance` |
| | | ADD COLUMN `area_id` bigint DEFAULT NULL COMMENT '设å¤åºåid' AFTER `device_ledger_id`; |
| | | |
| | | ALTER TABLE `device_repair` |
| | | ADD COLUMN `area_id` bigint DEFAULT NULL COMMENT '设å¤åºåid' AFTER `device_ledger_id`; |
| | | |
| | | ALTER TABLE `inspection_task` |
| | | ADD COLUMN `area_id` bigint DEFAULT NULL COMMENT '设å¤åºåid' AFTER `task_id`; |
| | | |
| | | ALTER TABLE `timing_task` |
| | | ADD COLUMN `area_id` bigint DEFAULT NULL COMMENT '设å¤åºåid' AFTER `task_id`; |
| | | |
| | | ALTER TABLE `maintenance_task` |
| | | ADD COLUMN `area_id` bigint DEFAULT NULL COMMENT '设å¤åºåid' AFTER `task_id`; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | ALTER TABLE `timing_task` |
| | | ADD COLUMN `task_ids_str` varchar(1000) DEFAULT NULL COMMENT '设å¤IDéå' AFTER `task_id`; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.device.controller; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.device.pojo.DeviceArea; |
| | | import com.ruoyi.device.service.IDeviceAreaService; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Api(tags = "设å¤åºå管ç") |
| | | @RestController |
| | | @RequestMapping("/device/area") |
| | | public class DeviceAreaController { |
| | | |
| | | @Autowired |
| | | private IDeviceAreaService deviceAreaService; |
| | | |
| | | @GetMapping("/tree") |
| | | @ApiOperation("设å¤åºåæ ") |
| | | public AjaxResult tree() { |
| | | return AjaxResult.success(deviceAreaService.listTree()); |
| | | } |
| | | |
| | | @GetMapping("/treeWithDevices") |
| | | @ApiOperation("设å¤åºåæ -å
å«è®¾å¤å表") |
| | | public AjaxResult treeWithDevices() { |
| | | return AjaxResult.success(deviceAreaService.listTreeWithDevices()); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @ApiOperation("设å¤åºåå页") |
| | | public AjaxResult page(Page page, DeviceArea deviceArea) { |
| | | return AjaxResult.success(deviceAreaService.queryPage(page, deviceArea)); |
| | | } |
| | | |
| | | @GetMapping("/{id}") |
| | | @ApiOperation("设å¤åºå详æ
") |
| | | public AjaxResult detail(@PathVariable Long id) { |
| | | return AjaxResult.success(deviceAreaService.getById(id)); |
| | | } |
| | | |
| | | @PostMapping |
| | | @ApiOperation("æ°å¢è®¾å¤åºå") |
| | | @Log(title = "设å¤åºå", businessType = BusinessType.INSERT) |
| | | public AjaxResult add(@RequestBody DeviceArea deviceArea) { |
| | | return deviceAreaService.saveDeviceArea(deviceArea); |
| | | } |
| | | |
| | | @PutMapping |
| | | @ApiOperation("ä¿®æ¹è®¾å¤åºå") |
| | | @Log(title = "设å¤åºå", businessType = BusinessType.UPDATE) |
| | | public AjaxResult update(@RequestBody DeviceArea deviceArea) { |
| | | return deviceAreaService.updateDeviceArea(deviceArea); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | @ApiOperation("å é¤è®¾å¤åºå") |
| | | @Log(title = "设å¤åºå", businessType = BusinessType.DELETE) |
| | | public AjaxResult delete(@RequestBody List<Long> ids) { |
| | | return deviceAreaService.removeDeviceAreas(ids); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.device.dto; |
| | | |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | public class DeviceAreaTreeDto { |
| | | |
| | | private Long id; |
| | | |
| | | private Long parentId; |
| | | |
| | | private String areaName; |
| | | |
| | | private String label; |
| | | |
| | | private Long sort; |
| | | |
| | | private String remark; |
| | | |
| | | private List<DeviceLedger> deviceList; |
| | | |
| | | private List<DeviceAreaTreeDto> children; |
| | | } |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * 设å¤å°è´¦å®ä½ç±» |
| | | */ |
| | | @Data |
| | | @TableName("device_ledger") |
| | | public class DeviceLedgerDto extends DateQueryDto { |
| | | |
| | | /** |
| | | * 主é®IDï¼èªå¢ |
| | | */ |
| | | |
| | | private Long id; |
| | | |
| | | /** |
| | | * 设å¤åç§° |
| | | */ |
| | | private String deviceName; |
| | | |
| | | /** |
| | | * è§æ ¼åå· |
| | | */ |
| | | private String deviceModel; |
| | | |
| | | /** |
| | | * 设å¤åç |
| | | */ |
| | | @ApiModelProperty("设å¤åç") |
| | | private String deviceBrand; |
| | | |
| | | /** |
| | | * åæ¾ä½ç½® |
| | | */ |
| | | @ApiModelProperty("åæ¾ä½ç½®") |
| | | private String storageLocation; |
| | | |
| | | @ApiModelProperty("设å¤åºåID") |
| | | private Long areaId; |
| | | |
| | | /** |
| | | * ä¾åºååç§° |
| | | */ |
| | | @ApiModelProperty("设å¤åºååç§°") |
| | | private String areaName; |
| | | |
| | | private String supplierName; |
| | | |
| | | /** |
| | | * åä½ |
| | | */ |
| | | private String unit; |
| | | |
| | | /** |
| | | * æ°é |
| | | */ |
| | | private BigDecimal number; |
| | | |
| | | /** |
| | | * å«ç¨åä»· |
| | | */ |
| | | private BigDecimal taxIncludingPriceUnit; |
| | | |
| | | /** |
| | | * å«ç¨æ»ä»· |
| | | */ |
| | | private BigDecimal taxIncludingPriceTotal; |
| | | |
| | | /** |
| | | * ç¨ç |
| | | */ |
| | | private BigDecimal taxRate; |
| | | |
| | | /** |
| | | * ä¸å«ç¨æ»ä»· |
| | | */ |
| | | private BigDecimal unTaxIncludingPriceTotal; |
| | | |
| | | /** |
| | | * å½å
¥æ¶é´ |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private LocalDateTime createTime; |
| | | |
| | | /** |
| | | * æ´æ°æ¶é´ |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private LocalDateTime updateTime; |
| | | |
| | | /** |
| | | * å½å
¥äºº |
| | | */ |
| | | private String createUser; |
| | | |
| | | /** |
| | | * æ´æ°äºº |
| | | */ |
| | | private String updateUser; |
| | | |
| | | /** |
| | | * ç§æ·ID |
| | | */ |
| | | private Long tenantId; |
| | | |
| | | @ApiModelProperty("ç¶æ") |
| | |
| | | |
| | | @ApiModelProperty("è¿è¡æ¶é¿") |
| | | private String runtimeDuration; |
| | | |
| | | |
| | | @ApiModelProperty("æ¯å¦ææ§ 1-æ¯ 2-å¦") |
| | | private Integer isDepr; |
| | |
| | | @Data |
| | | public class DeviceMaintenanceDto { |
| | | |
| | | |
| | | @ApiModelProperty("设å¤ä¿å
»id") |
| | | private Long id; |
| | | |
| | | @ApiModelProperty("设å¤å°è´¦id") |
| | | private Long deviceLedgerId; |
| | | |
| | | @ApiModelProperty("设å¤åºåid") |
| | | private Long areaId; |
| | | |
| | | @ApiModelProperty("设å¤åºååç§°") |
| | | private String areaName; |
| | | |
| | | @ApiModelProperty("设å¤åç§°") |
| | | private String deviceName; |
| | | |
| | |
| | | package com.ruoyi.device.dto; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | |
| | | @ApiModelProperty("设å¤å°è´¦id") |
| | | private Long deviceLedgerId; |
| | | |
| | | @ApiModelProperty("设å¤åºåid") |
| | | private Long areaId; |
| | | |
| | | @ApiModelProperty("设å¤åºååç§°") |
| | | private String areaName; |
| | | |
| | | @ApiModelProperty("设å¤åç§°") |
| | | private String deviceName; |
| | | |
| | |
| | | |
| | | @ApiModelProperty("æ¥ä¿®æ¶é´") |
| | | private Date repairTime; |
| | | |
| | | |
| | | private String repairTimeStr; |
| | | |
| | | @ApiModelProperty("æ¥ä¿®äºº") |
| | |
| | | @ApiModelProperty("ç§æ·id") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long tenantId; |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | public class DeviceLedgerExeclDto { |
| | | |
| | | @Excel(name = "设å¤ç±»å", sort = 0, combo = {"ç产设å¤", "åå
¬è®¾å¤", "æ£æµè®¾å¤", "è¿è¾è®¾å¤", "å
¶ä»è®¾å¤"}) |
| | | private String type; |
| | | |
| | | /** |
| | | * 设å¤åç§° |
| | | */ |
| | | @Excel(name = "设å¤åç§°" ,sort = 1) |
| | | @Excel(name = "设å¤åç§°", sort = 1) |
| | | private String deviceName; |
| | | |
| | | /** |
| | | * 设å¤ç±»å |
| | | */ |
| | | @Excel(name = "设å¤ç±»å",sort = 0,combo = {"ç产设å¤","åå
¬è®¾å¤","æ£æ¥è®¾å¤","è¿è¾è®¾å¤","å
¶ä»è®¾å¤"}) |
| | | private String type; |
| | | @Excel(name = "è§æ ¼åå·", sort = 2) |
| | | private String deviceModel; |
| | | |
| | | @Excel(name = "ä¾åºååç§°", sort = 3) |
| | | private String supplierName; |
| | | |
| | | @Excel(name = "åä½", sort = 4) |
| | | private String unit; |
| | | |
| | | @Excel(name = "æ°é", sort = 5, type = Excel.Type.EXPORT) |
| | | private BigDecimal number = BigDecimal.ONE; |
| | | |
| | | @Excel(name = "å«ç¨åä»·", sort = 6) |
| | | private BigDecimal taxIncludingPriceUnit; |
| | | |
| | | @Excel(name = "å«ç¨æ»ä»·", sort = 7, type = Excel.Type.EXPORT) |
| | | private BigDecimal taxIncludingPriceTotal; |
| | | |
| | | @Excel(name = "ç¨ç", sort = 8) |
| | | private BigDecimal taxRate; |
| | | |
| | | @Excel(name = "ä¸å«ç¨æ»ä»·", sort = 9, type = Excel.Type.EXPORT) |
| | | private BigDecimal unTaxIncludingPriceTotal; |
| | | |
| | | @ApiModelProperty("计åè¿è¡æ¶é´") |
| | | @JsonFormat(pattern = "yyyy-MM-dd") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @Excel(name = "计åè¿è¡æ¶é´",sort = 10,dateFormat = "yyyy-MM-dd") |
| | | @Excel(name = "计åè¿è¡æ¶é´", sort = 10, dateFormat = "yyyy-MM-dd") |
| | | private Date planRuntimeTime; |
| | | |
| | | /** |
| | | * è§æ ¼åå· |
| | | */ |
| | | @Excel(name = "è§æ ¼åå·" ,sort = 2) |
| | | private String deviceModel; |
| | | @Excel(name = "设å¤åºå", sort = 11) |
| | | private String areaName; |
| | | |
| | | /** |
| | | * ä¾åºååç§° |
| | | */ |
| | | @Excel(name = "ä¾åºååç§°",sort = 3) |
| | | private String supplierName; |
| | | |
| | | /** |
| | | * åä½ |
| | | */ |
| | | @Excel(name = "åä½",sort = 4) |
| | | private String unit; |
| | | |
| | | /** |
| | | * æ°é |
| | | */ |
| | | @Excel(name = "æ°é",sort = 5, type = Excel.Type.EXPORT) |
| | | private BigDecimal number = BigDecimal.ONE; |
| | | |
| | | /** |
| | | * å«ç¨åä»· |
| | | */ |
| | | @Excel(name = "å«ç¨åä»·",sort = 6) |
| | | private BigDecimal taxIncludingPriceUnit; |
| | | |
| | | /** |
| | | * å«ç¨æ»ä»· |
| | | */ |
| | | @Excel(name = "å«ç¨æ»ä»·",sort = 7, type = Excel.Type.EXPORT) |
| | | private BigDecimal taxIncludingPriceTotal; |
| | | |
| | | /** |
| | | * ç¨ç |
| | | */ |
| | | @Excel(name = "ç¨ç",sort = 8) |
| | | private BigDecimal taxRate; |
| | | |
| | | /** |
| | | * ä¸å«ç¨æ»ä»· |
| | | */ |
| | | @Excel(name = "ä¸å«ç¨æ»ä»·",sort = 9, type = Excel.Type.EXPORT) |
| | | private BigDecimal unTaxIncludingPriceTotal; |
| | | |
| | | |
| | | /** |
| | | * å½å
¥äºº |
| | | */ |
| | | @Excel(name = "å½å
¥äºº",sort = 9) |
| | | @Excel(name = "å½å
¥äºº", sort = 12) |
| | | private String createUser; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.device.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.ruoyi.device.pojo.DeviceArea; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | @Mapper |
| | | public interface DeviceAreaMapper extends BaseMapper<DeviceArea> { |
| | | |
| | | IPage<DeviceArea> queryPage(Page page, @Param("deviceArea") DeviceArea deviceArea); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.device.pojo; |
| | | |
| | | 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.baomidou.mybatisplus.annotation.TableName; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Data |
| | | @TableName("device_area") |
| | | @ApiModel("设å¤åºå") |
| | | public class DeviceArea { |
| | | |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | @ApiModelProperty("åºååç§°") |
| | | private String areaName; |
| | | |
| | | @ApiModelProperty("ç¶çº§ID") |
| | | private Long parentId; |
| | | |
| | | @ApiModelProperty("æåº") |
| | | private Long sort; |
| | | |
| | | @ApiModelProperty("夿³¨") |
| | | private String remark; |
| | | |
| | | @ApiModelProperty("å建æ¶é´") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private LocalDateTime createTime; |
| | | |
| | | @ApiModelProperty("æ´æ°æ¶é´") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private LocalDateTime updateTime; |
| | | |
| | | @ApiModelProperty("åå»ºç¨æ·") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Integer createUser; |
| | | |
| | | @ApiModelProperty("æ´æ°ç¨æ·") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Integer updateUser; |
| | | |
| | | @ApiModelProperty("ç§æ·ID") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long tenantId; |
| | | |
| | | @ApiModelProperty("é¨é¨ID") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long deptId; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty("ç¶çº§åç§°") |
| | | private String parentName; |
| | | } |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * 设å¤å°è´¦å®ä½ç±» |
| | | */ |
| | | @Data |
| | | @TableName("device_ledger") |
| | | @ApiModel |
| | | public class DeviceLedger { |
| | | |
| | | /** |
| | | * 主é®IDï¼èªå¢ |
| | | */ |
| | | |
| | | private Long id; |
| | | |
| | | /** |
| | | * 设å¤åç§° |
| | | */ |
| | | @ApiModelProperty("设å¤åç§°") |
| | | private String deviceName; |
| | | |
| | | /** |
| | | * è§æ ¼åå· |
| | | */ |
| | | @ApiModelProperty("è§æ ¼åå·") |
| | | private String deviceModel; |
| | | |
| | | /** |
| | | * 设å¤åç |
| | | */ |
| | | @ApiModelProperty("设å¤åç") |
| | | private String deviceBrand; |
| | | |
| | | /** |
| | | * åæ¾ä½ç½® |
| | | */ |
| | | @ApiModelProperty("åæ¾ä½ç½®") |
| | | private String storageLocation; |
| | | |
| | | /** |
| | | * ä¾åºååç§° |
| | | */ |
| | | @ApiModelProperty("设å¤åºåID") |
| | | private Long areaId; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty("设å¤åºååç§°") |
| | | private String areaName; |
| | | |
| | | private String supplierName; |
| | | |
| | | /** |
| | | * åä½ |
| | | */ |
| | | private String unit; |
| | | |
| | | /** |
| | | * æ°é |
| | | */ |
| | | private BigDecimal number; |
| | | |
| | | /** |
| | | * å«ç¨åä»· |
| | | */ |
| | | private BigDecimal taxIncludingPriceUnit; |
| | | |
| | | /** |
| | | * å«ç¨æ»ä»· |
| | | */ |
| | | private BigDecimal taxIncludingPriceTotal; |
| | | |
| | | /** |
| | | * ç¨ç |
| | | */ |
| | | private BigDecimal taxRate; |
| | | |
| | | /** |
| | | * ä¸å«ç¨æ»ä»· |
| | | */ |
| | | private BigDecimal unTaxIncludingPriceTotal; |
| | | |
| | | /** |
| | | * å½å
¥æ¶é´ |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private LocalDateTime createTime; |
| | | |
| | | /** |
| | | * æ´æ°æ¶é´ |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private LocalDateTime updateTime; |
| | | |
| | | /** |
| | | * å½å
¥äºº |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Integer createUser; |
| | | |
| | | /** |
| | | * æ´æ°äºº |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Integer updateUser; |
| | | |
| | | /** |
| | | * ç§æ·ID |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long tenantId; |
| | | |
| | | /* *************************** è¿è¡ç®¡ç *************************** */ |
| | | |
| | | @ApiModelProperty("ç¶æ") |
| | | private String status; |
| | |
| | | @ApiModelProperty("设å¤å°è´¦id") |
| | | private Long deviceLedgerId; |
| | | |
| | | @ApiModelProperty("ä¿å
»ä»»å¡id") |
| | | @ApiModelProperty("设å¤åºåid") |
| | | private Long areaId; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty("设å¤å°è´¦IDéå") |
| | | private Long[] deviceLedgerIds; |
| | | |
| | | @ApiModelProperty("设å¤ä¿å
»ä»»å¡id") |
| | | private Long maintenanceTaskId; |
| | | |
| | | @ApiModelProperty(value = "颿¬¡") |
| | |
| | | |
| | | @ApiModelProperty(value = "æåæ§è¡æ¶é´") |
| | | private LocalDateTime lastExecutionTime; |
| | | |
| | | |
| | | private String deviceName; |
| | | |
| | |
| | | private LocalDateTime createTime; |
| | | |
| | | @ApiModelProperty("æ´æ°æ¶é´") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private LocalDateTime updateTime; |
| | | |
| | | @ApiModelProperty("å建人") |
| | |
| | | @ApiModelProperty("设å¤å°è´¦id") |
| | | private Long deviceLedgerId; |
| | | |
| | | @ApiModelProperty("设å¤åºåid") |
| | | private Long areaId; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty("设å¤å°è´¦IDéå") |
| | | private Long[] deviceLedgerIds; |
| | | |
| | | private String deviceName; |
| | | |
| | | private String deviceModel; |
| | |
| | | package com.ruoyi.device.pojo; |
| | | |
| | | 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 java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * @author :yys |
| | | * @date : 2025/9/19 10:27 |
| | | */ |
| | | @Data |
| | | @ApiModel |
| | | @TableName("maintenance_task") |
| | |
| | | @ApiModelProperty(value = "è§æ ¼åå·") |
| | | private String deviceModel; |
| | | |
| | | /** |
| | | * 主é®ID |
| | | */ |
| | | @TableId(type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | |
| | | |
| | | @ApiModelProperty(value = "设å¤id") |
| | | private Long taskId; |
| | | |
| | | @ApiModelProperty(value = "设å¤åºåid") |
| | | private Long areaId; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "设å¤åºååç§°") |
| | | private String areaName; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "设å¤IDéå") |
| | | private Long[] deviceLedgerIds; |
| | | |
| | | @ApiModelProperty(value = "设å¤IDéåå符串") |
| | | private String deviceLedgerIdsStr; |
| | | |
| | | @ApiModelProperty(value = "颿¬¡") |
| | | @Excel(name = "颿¬¡") |
| | |
| | | @ApiModelProperty(value = "ç¶æ") |
| | | private String status; |
| | | |
| | | @ApiModelProperty(value = "软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤") |
| | | @ApiModelProperty(value = "软å 餿 è®°ï¼0=æªå é¤ï¼1=å·²å é¤") |
| | | private Integer deleted; |
| | | |
| | | @TableField(exist = false) |
| | | private String dateStr; |
| | | |
| | | @ApiModelProperty(value = "å建该记å½çç¨æ·") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT) |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Integer createUser; |
| | | |
| | | @ApiModelProperty(value = "è®°å½å建æ¶é´") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT) |
| | | // @JsonFormat(pattern = "yyyy-MM-dd") |
| | | // @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private LocalDateTime createTime; |
| | | |
| | | @ApiModelProperty(value = "æåä¿®æ¹è¯¥è®°å½çç¨æ·") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT_UPDATE) |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Integer updateUser; |
| | | |
| | | @ApiModelProperty(value = "è®°å½æåæ´æ°æ¶é´") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT_UPDATE) |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private LocalDateTime updateTime; |
| | | |
| | | @ApiModelProperty(value = "ç§æ·ID") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT) |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long tenantId; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.device.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.device.dto.DeviceAreaTreeDto; |
| | | import com.ruoyi.device.pojo.DeviceArea; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface IDeviceAreaService extends IService<DeviceArea> { |
| | | |
| | | IPage<DeviceArea> queryPage(Page page, DeviceArea deviceArea); |
| | | |
| | | List<DeviceAreaTreeDto> listTree(); |
| | | |
| | | List<DeviceAreaTreeDto> listTreeWithDevices(); |
| | | |
| | | AjaxResult saveDeviceArea(DeviceArea deviceArea); |
| | | |
| | | AjaxResult updateDeviceArea(DeviceArea deviceArea); |
| | | |
| | | AjaxResult removeDeviceAreas(List<Long> ids); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.device.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.device.dto.DeviceAreaTreeDto; |
| | | import com.ruoyi.device.mapper.DeviceAreaMapper; |
| | | import com.ruoyi.device.mapper.DeviceLedgerMapper; |
| | | import com.ruoyi.device.pojo.DeviceArea; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.device.service.IDeviceAreaService; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class DeviceAreaServiceImpl extends ServiceImpl<DeviceAreaMapper, DeviceArea> implements IDeviceAreaService { |
| | | |
| | | @Autowired |
| | | private DeviceAreaMapper deviceAreaMapper; |
| | | |
| | | @Autowired |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | |
| | | @Override |
| | | public IPage<DeviceArea> queryPage(Page page, DeviceArea deviceArea) { |
| | | return deviceAreaMapper.queryPage(page, deviceArea); |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceAreaTreeDto> listTree() { |
| | | return buildTree(Collections.emptyMap()); |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceAreaTreeDto> listTreeWithDevices() { |
| | | LambdaQueryWrapper<DeviceLedger> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.isNotNull(DeviceLedger::getAreaId); |
| | | queryWrapper.orderByAsc(DeviceLedger::getId); |
| | | List<DeviceLedger> deviceLedgers = deviceLedgerMapper.selectList(queryWrapper); |
| | | |
| | | Map<Long, List<DeviceLedger>> deviceMap = new HashMap<>(); |
| | | for (DeviceLedger deviceLedger : deviceLedgers) { |
| | | deviceMap.computeIfAbsent(deviceLedger.getAreaId(), key -> new ArrayList<>()).add(deviceLedger); |
| | | } |
| | | return buildTree(deviceMap); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult saveDeviceArea(DeviceArea deviceArea) { |
| | | if (deviceArea == null || !StringUtils.hasText(deviceArea.getAreaName())) { |
| | | return AjaxResult.error("åºååç§°ä¸è½ä¸ºç©º"); |
| | | } |
| | | normalizeDeviceArea(deviceArea); |
| | | if (existsSameName(deviceArea.getParentId(), deviceArea.getAreaName(), null)) { |
| | | return AjaxResult.error("å级åºååç§°å·²åå¨"); |
| | | } |
| | | if (deviceArea.getParentId() != null && deviceAreaMapper.selectById(deviceArea.getParentId()) == null) { |
| | | return AjaxResult.error("ç¶çº§åºåä¸åå¨"); |
| | | } |
| | | return this.save(deviceArea) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult updateDeviceArea(DeviceArea deviceArea) { |
| | | if (deviceArea == null || deviceArea.getId() == null) { |
| | | return AjaxResult.error("åºåIDä¸è½ä¸ºç©º"); |
| | | } |
| | | if (!StringUtils.hasText(deviceArea.getAreaName())) { |
| | | return AjaxResult.error("åºååç§°ä¸è½ä¸ºç©º"); |
| | | } |
| | | normalizeDeviceArea(deviceArea); |
| | | DeviceArea current = deviceAreaMapper.selectById(deviceArea.getId()); |
| | | if (current == null) { |
| | | return AjaxResult.error("åºåä¸åå¨"); |
| | | } |
| | | if (deviceArea.getParentId() != null && deviceArea.getId().equals(deviceArea.getParentId())) { |
| | | return AjaxResult.error("ç¶çº§åºåä¸è½éæ©èªèº«"); |
| | | } |
| | | if (isDescendant(deviceArea.getId(), deviceArea.getParentId())) { |
| | | return AjaxResult.error("ç¶çº§åºåä¸è½éæ©åèç¹"); |
| | | } |
| | | if (deviceArea.getParentId() != null && deviceAreaMapper.selectById(deviceArea.getParentId()) == null) { |
| | | return AjaxResult.error("ç¶çº§åºåä¸åå¨"); |
| | | } |
| | | if (existsSameName(deviceArea.getParentId(), deviceArea.getAreaName(), deviceArea.getId())) { |
| | | return AjaxResult.error("å级åºååç§°å·²åå¨"); |
| | | } |
| | | return this.updateById(deviceArea) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult removeDeviceAreas(List<Long> ids) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return AjaxResult.error("è¯·éæ©è¦å é¤çåºå"); |
| | | } |
| | | LambdaQueryWrapper<DeviceArea> childWrapper = new LambdaQueryWrapper<>(); |
| | | childWrapper.in(DeviceArea::getParentId, ids); |
| | | if (deviceAreaMapper.selectCount(childWrapper) > 0) { |
| | | return AjaxResult.error("åå¨ååºåï¼ä¸è½ç´æ¥å é¤"); |
| | | } |
| | | return this.removeBatchByIds(ids) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | private List<DeviceAreaTreeDto> buildTree(Map<Long, List<DeviceLedger>> deviceMap) { |
| | | LambdaQueryWrapper<DeviceArea> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.and(wrapper -> wrapper.isNull(DeviceArea::getParentId).or().eq(DeviceArea::getParentId, 0L)); |
| | | queryWrapper.orderByAsc(DeviceArea::getSort).orderByAsc(DeviceArea::getId); |
| | | List<DeviceArea> rootList = deviceAreaMapper.selectList(queryWrapper); |
| | | |
| | | List<DeviceAreaTreeDto> tree = new ArrayList<>(); |
| | | for (DeviceArea deviceArea : rootList) { |
| | | DeviceAreaTreeDto node = toTreeDto(deviceArea, deviceMap); |
| | | node.setChildren(buildChildren(deviceArea.getId(), deviceMap)); |
| | | tree.add(node); |
| | | } |
| | | return tree; |
| | | } |
| | | |
| | | private void normalizeDeviceArea(DeviceArea deviceArea) { |
| | | if (deviceArea.getParentId() != null && deviceArea.getParentId() == 0L) { |
| | | deviceArea.setParentId(null); |
| | | } |
| | | if (deviceArea.getSort() == null) { |
| | | deviceArea.setSort(0L); |
| | | } |
| | | } |
| | | |
| | | private boolean existsSameName(Long parentId, String areaName, Long excludeId) { |
| | | LambdaQueryWrapper<DeviceArea> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(DeviceArea::getAreaName, areaName); |
| | | if (parentId == null) { |
| | | queryWrapper.and(wrapper -> wrapper.isNull(DeviceArea::getParentId).or().eq(DeviceArea::getParentId, 0L)); |
| | | } else { |
| | | queryWrapper.eq(DeviceArea::getParentId, parentId); |
| | | } |
| | | if (excludeId != null) { |
| | | queryWrapper.ne(DeviceArea::getId, excludeId); |
| | | } |
| | | return deviceAreaMapper.selectCount(queryWrapper) > 0; |
| | | } |
| | | |
| | | private boolean isDescendant(Long currentId, Long parentId) { |
| | | if (currentId == null || parentId == null) { |
| | | return false; |
| | | } |
| | | Long cursor = parentId; |
| | | while (cursor != null && cursor != 0L) { |
| | | if (currentId.equals(cursor)) { |
| | | return true; |
| | | } |
| | | DeviceArea parent = deviceAreaMapper.selectById(cursor); |
| | | if (parent == null) { |
| | | return false; |
| | | } |
| | | cursor = parent.getParentId(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private List<DeviceAreaTreeDto> buildChildren(Long parentId, Map<Long, List<DeviceLedger>> deviceMap) { |
| | | LambdaQueryWrapper<DeviceArea> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(DeviceArea::getParentId, parentId); |
| | | queryWrapper.orderByAsc(DeviceArea::getSort).orderByAsc(DeviceArea::getId); |
| | | List<DeviceArea> children = deviceAreaMapper.selectList(queryWrapper); |
| | | |
| | | List<DeviceAreaTreeDto> result = new ArrayList<>(); |
| | | for (DeviceArea child : children) { |
| | | DeviceAreaTreeDto node = toTreeDto(child, deviceMap); |
| | | node.setChildren(buildChildren(child.getId(), deviceMap)); |
| | | result.add(node); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private DeviceAreaTreeDto toTreeDto(DeviceArea deviceArea, Map<Long, List<DeviceLedger>> deviceMap) { |
| | | DeviceAreaTreeDto dto = new DeviceAreaTreeDto(); |
| | | BeanUtils.copyProperties(deviceArea, dto); |
| | | dto.setLabel(deviceArea.getAreaName()); |
| | | dto.setDeviceList(new ArrayList<>(deviceMap.getOrDefault(deviceArea.getId(), Collections.emptyList()))); |
| | | dto.setChildren(new ArrayList<>()); |
| | | return dto; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.device.service.impl; |
| | | |
| | | |
| | | 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.ruoyi.device.dto.DeviceMaintenanceDto; |
| | | import com.ruoyi.device.execl.DeviceMaintenanceExeclDto; |
| | | import com.ruoyi.device.mapper.DeviceMaintenanceMapper; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.device.pojo.DeviceMaintenance; |
| | | import com.ruoyi.device.service.IDeviceLedgerService; |
| | | import com.ruoyi.device.service.IDeviceMaintenanceService; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | |
| | | @Service |
| | | public class DeviceMaintenanceServiceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements IDeviceMaintenanceService { |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | private DeviceMaintenanceMapper deviceMaintenanceMapper; |
| | |
| | | private SparePartsMapper sparePartsMapper; |
| | | @Autowired |
| | | private SparePartsRequisitionRecordService sparePartsRequisitionRecordService; |
| | | @Autowired |
| | | private IDeviceLedgerService deviceLedgerService; |
| | | |
| | | @Override |
| | | public IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto) { |
| | | |
| | | return deviceMaintenanceMapper.queryPage(page, deviceMaintenanceDto); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult saveDeviceRepair(DeviceMaintenance deviceMaintenance) { |
| | | boolean save = this.save(deviceMaintenance); |
| | | if (save){ |
| | | return AjaxResult.success(); |
| | | List<DeviceMaintenance> records = buildMaintenanceRecords(deviceMaintenance); |
| | | if (records.isEmpty()) { |
| | | return AjaxResult.error("è¯·éæ©è®¾å¤"); |
| | | } |
| | | return AjaxResult.error(); |
| | | return this.saveBatch(records) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenance deviceMaintenance) { |
| | | DeviceMaintenance oldDeviceMaintenance = this.getById(deviceMaintenance.getId()); |
| | | // å¤çå¤ä»¶ä½¿ç¨æ
åµ |
| | | if (oldDeviceMaintenance == null) { |
| | | return AjaxResult.error("ä¿å
»è®°å½ä¸åå¨"); |
| | | } |
| | | if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(deviceMaintenance.getSparePartsUseList())) { |
| | | List<Long> sparePartIds = new ArrayList<>(); |
| | | for (DeviceMaintenance.SparePartUse sparePartUse : deviceMaintenance.getSparePartsUseList()) { |
| | | // è·åå¤ä»¶ä¿¡æ¯ |
| | | SpareParts spareParts = sparePartsMapper.selectById(sparePartUse.getId()); |
| | | if (spareParts != null) { |
| | | // æ£æ¥æ°éæ¯å¦è¶³å¤ |
| | | if (spareParts.getQuantity().compareTo(new BigDecimal(sparePartUse.getQuantity())) >= 0) { |
| | | // æ´æ°æ°é |
| | | spareParts.setQuantity(spareParts.getQuantity().subtract(new BigDecimal(sparePartUse.getQuantity()))); |
| | | sparePartsMapper.updateById(spareParts); |
| | | sparePartIds.add(sparePartUse.getId()); |
| | | |
| | | // å建å¤ä»¶é¢ç¨è®°å½ |
| | | SparePartsRequisitionRecord record = new SparePartsRequisitionRecord(); |
| | | record.setSourceType(1); // 1 ä¿å
» |
| | | record.setSourceType(1); |
| | | record.setSourceId(deviceMaintenance.getId()); |
| | | record.setDeviceLedgerId(oldDeviceMaintenance.getDeviceLedgerId()); |
| | | record.setSparePartsId(sparePartUse.getId()); |
| | |
| | | } |
| | | } |
| | | } |
| | | // æ´æ°å¤ä»¶IDsåæ®µ |
| | | if (!sparePartIds.isEmpty()) { |
| | | deviceMaintenance.setSparePartsIds(StringUtils.join(sparePartIds, ",")); |
| | | } |
| | | } |
| | | |
| | | if (this.updateById(deviceMaintenance)) { |
| | | return AjaxResult.success(); |
| | | } |
| | | return AjaxResult.error(); |
| | | return this.updateById(deviceMaintenance) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @Override |
| | | public void export(HttpServletResponse response, Long[] ids) { |
| | | List<DeviceMaintenance> supplierManageList = deviceMaintenanceMapper.selectList(null); |
| | | ArrayList<DeviceMaintenanceExeclDto> deviceLedgerExeclDtos = new ArrayList<>(); |
| | | ArrayList<DeviceMaintenanceExeclDto> result = new ArrayList<>(); |
| | | supplierManageList.forEach(deviceMaintenance -> { |
| | | DeviceMaintenanceExeclDto deviceRepairExeclDto = new DeviceMaintenanceExeclDto(); |
| | | BeanUtils.copyProperties(deviceMaintenance,deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatus(deviceMaintenance.getStatus() == 0 ? "å¾
ç»´ä¿®" : deviceMaintenance.getStatus() == 1 ? "å®ç»" : "失败"); |
| | | // deviceRepairExeclDto.setMaintenanceResult(deviceMaintenance.getMaintenanceResult() != null && deviceMaintenance.getMaintenanceResult() == 0 ? "ç»´ä¿®" : "å®å¥½"); |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |
| | | DeviceMaintenanceExeclDto dto = new DeviceMaintenanceExeclDto(); |
| | | BeanUtils.copyProperties(deviceMaintenance, dto); |
| | | dto.setStatus(deviceMaintenance.getStatus() == 0 ? "å¾
ç»´ä¿®" : deviceMaintenance.getStatus() == 1 ? "å®ç»" : "失败"); |
| | | result.add(dto); |
| | | }); |
| | | ExcelUtil<DeviceMaintenanceExeclDto> util = new ExcelUtil<DeviceMaintenanceExeclDto>(DeviceMaintenanceExeclDto.class); |
| | | util.exportExcel(response, deviceLedgerExeclDtos, "è®¾å¤æ¥ä¿®å¯¼åº"); |
| | | ExcelUtil<DeviceMaintenanceExeclDto> util = new ExcelUtil<>(DeviceMaintenanceExeclDto.class); |
| | | util.exportExcel(response, result, "设å¤ä¿å
»å¯¼åº"); |
| | | } |
| | | |
| | | @Override |
| | | public DeviceMaintenanceDto detailById(Long id) { |
| | | |
| | | return deviceMaintenanceMapper.detailById(id); |
| | | } |
| | | |
| | | private List<DeviceMaintenance> buildMaintenanceRecords(DeviceMaintenance source) { |
| | | Long[] deviceIds = source.getDeviceLedgerIds(); |
| | | if (deviceIds == null || deviceIds.length == 0) { |
| | | deviceIds = source.getDeviceLedgerId() == null ? new Long[0] : new Long[]{source.getDeviceLedgerId()}; |
| | | } |
| | | List<DeviceMaintenance> records = new ArrayList<>(); |
| | | Arrays.stream(deviceIds).distinct().forEach(deviceId -> { |
| | | DeviceLedger deviceLedger = deviceLedgerService.getById(deviceId); |
| | | if (deviceLedger == null) { |
| | | return; |
| | | } |
| | | int quantity = resolveQuantity(deviceLedger); |
| | | for (int i = 0; i < quantity; i++) { |
| | | DeviceMaintenance record = new DeviceMaintenance(); |
| | | BeanUtils.copyProperties(source, record); |
| | | record.setId(null); |
| | | record.setDeviceLedgerIds(null); |
| | | record.setDeviceLedgerId(deviceLedger.getId()); |
| | | record.setAreaId(deviceLedger.getAreaId()); |
| | | record.setDeviceName(deviceLedger.getDeviceName()); |
| | | record.setDeviceModel(deviceLedger.getDeviceModel()); |
| | | records.add(record); |
| | | } |
| | | }); |
| | | return records; |
| | | } |
| | | |
| | | private int resolveQuantity(DeviceLedger deviceLedger) { |
| | | if (deviceLedger == null || deviceLedger.getNumber() == null || deviceLedger.getNumber().compareTo(BigDecimal.ONE) < 0) { |
| | | return 1; |
| | | } |
| | | return Math.max(1, deviceLedger.getNumber().intValue()); |
| | | } |
| | | } |
| | |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SpareParts; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SparePartsRequisitionRecord; |
| | | import com.ruoyi.measuringinstrumentledger.service.SparePartsRequisitionRecordService; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Slf4j |
| | | public class DeviceRepairServiceImpl extends ServiceImpl<DeviceRepairMapper, DeviceRepair> implements IDeviceRepairService { |
| | | |
| | |
| | | |
| | | @Override |
| | | public IPage<DeviceRepairDto> queryPage(Page page, DeviceRepairDto deviceRepairDto) { |
| | | |
| | | return deviceRepairMapper.queryPage(page, deviceRepairDto); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult saveDeviceRepair(DeviceRepair deviceRepair) { |
| | | DeviceLedger byId = deviceLedgerService.getById(deviceRepair.getDeviceLedgerId()); |
| | | deviceRepair.setDeviceName(byId.getDeviceName()); |
| | | deviceRepair.setDeviceModel(byId.getDeviceModel()); |
| | | boolean save = this.save(deviceRepair); |
| | | if (save){ |
| | | return AjaxResult.success(); |
| | | List<DeviceRepair> records = buildRepairRecords(deviceRepair); |
| | | if (records.isEmpty()) { |
| | | return AjaxResult.error("è¯·éæ©è®¾å¤"); |
| | | } |
| | | return AjaxResult.error(); |
| | | return this.saveBatch(records) ? AjaxResult.success() : AjaxResult.error(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult updateDeviceRepair(DeviceRepair deviceRepair) { |
| | | DeviceRepair oldDeviceRepair = this.getById(deviceRepair.getId()); |
| | | // å¤çå¤ä»¶ä½¿ç¨æ
åµ |
| | | if (oldDeviceRepair == null) { |
| | | return AjaxResult.error("æ¥ä¿®è®°å½ä¸åå¨"); |
| | | } |
| | | if (CollectionUtils.isNotEmpty(deviceRepair.getSparePartsUseList())) { |
| | | List<Long> sparePartIds = new ArrayList<>(); |
| | | for (DeviceRepair.SparePartUse sparePartUse : deviceRepair.getSparePartsUseList()) { |
| | | // è·åå¤ä»¶ä¿¡æ¯ |
| | | SpareParts spareParts = sparePartsMapper.selectById(sparePartUse.getId()); |
| | | if (spareParts != null) { |
| | | // æ£æ¥æ°éæ¯å¦è¶³å¤ |
| | | if (spareParts.getQuantity().compareTo(new BigDecimal(sparePartUse.getQuantity())) >= 0) { |
| | | // æ´æ°æ°é |
| | | spareParts.setQuantity(spareParts.getQuantity().subtract(new BigDecimal(sparePartUse.getQuantity()))); |
| | | sparePartsMapper.updateById(spareParts); |
| | | sparePartIds.add(sparePartUse.getId()); |
| | | |
| | | // å建å¤ä»¶é¢ç¨è®°å½ |
| | | SparePartsRequisitionRecord record = new SparePartsRequisitionRecord(); |
| | | record.setSourceType(0); // 0 ç»´ä¿® |
| | | record.setSourceType(0); |
| | | record.setSourceId(deviceRepair.getId()); |
| | | record.setDeviceLedgerId(oldDeviceRepair.getDeviceLedgerId()); |
| | | record.setSparePartsId(sparePartUse.getId()); |
| | |
| | | } |
| | | } |
| | | } |
| | | // æ´æ°å¤ä»¶IDsåæ®µ |
| | | if (!sparePartIds.isEmpty()) { |
| | | deviceRepair.setSparePartsIds(StringUtils.join(sparePartIds, ",")); |
| | | } |
| | |
| | | |
| | | if (this.updateById(deviceRepair)) { |
| | | Long id = deviceRepair.getId(); |
| | | // |
| | | DeviceDefectRecordDto deviceDefectRecordDto = new DeviceDefectRecordDto(); |
| | | deviceDefectRecordDto.setDeviceLedgerId(id); |
| | | deviceDefectRecordDto.setStatus("严é缺é·"); |
| | | List<DeviceDefectRecordDto> records = deviceDefectRecordService.listPage(new Page<>(1, -1), deviceDefectRecordDto).getRecords(); |
| | | if (!records.isEmpty()){ |
| | | if (!records.isEmpty()) { |
| | | records.forEach(deviceDefectRecord -> { |
| | | deviceDefectRecord.setStatus("æ£å¸¸"); |
| | | deviceDefectRecordService.updateByDDR(deviceDefectRecord); |
| | |
| | | |
| | | @Override |
| | | public void export(HttpServletResponse response, Long[] ids) { |
| | | List<DeviceRepair> supplierManageList; |
| | | if (ids == null || ids.length == 0) { |
| | | List<DeviceRepair> supplierManageList = this.list(); |
| | | ArrayList<DeviceRepairExeclDto> deviceLedgerExeclDtos = new ArrayList<>(); |
| | | supplierManageList.stream().forEach(deviceRepair -> { |
| | | DeviceRepairExeclDto deviceRepairExeclDto = new DeviceRepairExeclDto(); |
| | | BeanUtils.copyProperties(deviceRepair,deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatusStr(deviceRepair.getStatus() == 0 ? "å¾
ç»´ä¿®" : deviceRepair.getStatus() == 1 ? "å®ç»" : "失败"); |
| | | |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |
| | | }); |
| | | ExcelUtil<DeviceRepairExeclDto> util = new ExcelUtil<DeviceRepairExeclDto>(DeviceRepairExeclDto.class); |
| | | util.exportExcel(response, deviceLedgerExeclDtos, "è®¾å¤æ¥ä¿®å¯¼åº"); |
| | | }else { |
| | | ArrayList<Long> arrayList = new ArrayList<>(); |
| | | Arrays.stream(ids).map(id -> { |
| | | return arrayList.add( id); |
| | | }); |
| | | List<DeviceRepair> supplierManageList = deviceRepairMapper.selectBatchIds(arrayList); |
| | | ArrayList<DeviceRepairExeclDto> deviceLedgerExeclDtos = new ArrayList<>(); |
| | | supplierManageList.stream().forEach(deviceRepair -> { |
| | | DeviceRepairExeclDto deviceRepairExeclDto = new DeviceRepairExeclDto(); |
| | | BeanUtils.copyProperties(deviceRepair,deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatusStr(deviceRepair.getStatus() == 0 ? "å¾
ç»´ä¿®" : deviceRepair.getStatus() == 1 ? "å®ç»" : "失败"); |
| | | |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |
| | | }); |
| | | ExcelUtil<DeviceRepairExeclDto> util = new ExcelUtil<DeviceRepairExeclDto>(DeviceRepairExeclDto.class); |
| | | util.exportExcel(response, deviceLedgerExeclDtos, "è®¾å¤æ¥ä¿®å¯¼åº"); |
| | | supplierManageList = this.list(); |
| | | } else { |
| | | supplierManageList = deviceRepairMapper.selectBatchIds(Arrays.asList(ids)); |
| | | } |
| | | |
| | | ArrayList<DeviceRepairExeclDto> result = new ArrayList<>(); |
| | | supplierManageList.forEach(deviceRepair -> { |
| | | DeviceRepairExeclDto dto = new DeviceRepairExeclDto(); |
| | | BeanUtils.copyProperties(deviceRepair, dto); |
| | | dto.setStatusStr(deviceRepair.getStatus() == 0 ? "å¾
ç»´ä¿®" : deviceRepair.getStatus() == 1 ? "å®ç»" : "失败"); |
| | | result.add(dto); |
| | | }); |
| | | ExcelUtil<DeviceRepairExeclDto> util = new ExcelUtil<>(DeviceRepairExeclDto.class); |
| | | util.exportExcel(response, result, "è®¾å¤æ¥ä¿®å¯¼åº"); |
| | | } |
| | | |
| | | @Override |
| | | public DeviceRepairDto detailById(Long id) { |
| | | |
| | | return deviceRepairMapper.detailById(id); |
| | | } |
| | | |
| | | private List<DeviceRepair> buildRepairRecords(DeviceRepair source) { |
| | | Long[] deviceIds = source.getDeviceLedgerIds(); |
| | | if (deviceIds == null || deviceIds.length == 0) { |
| | | deviceIds = source.getDeviceLedgerId() == null ? new Long[0] : new Long[]{source.getDeviceLedgerId()}; |
| | | } |
| | | List<DeviceRepair> records = new ArrayList<>(); |
| | | Arrays.stream(deviceIds).distinct().forEach(deviceId -> { |
| | | DeviceLedger deviceLedger = deviceLedgerService.getById(deviceId); |
| | | if (deviceLedger == null) { |
| | | return; |
| | | } |
| | | int quantity = resolveQuantity(deviceLedger); |
| | | for (int i = 0; i < quantity; i++) { |
| | | DeviceRepair record = new DeviceRepair(); |
| | | BeanUtils.copyProperties(source, record); |
| | | record.setId(null); |
| | | record.setDeviceLedgerIds(null); |
| | | record.setDeviceLedgerId(deviceLedger.getId()); |
| | | record.setAreaId(deviceLedger.getAreaId()); |
| | | record.setDeviceName(deviceLedger.getDeviceName()); |
| | | record.setDeviceModel(deviceLedger.getDeviceModel()); |
| | | records.add(record); |
| | | } |
| | | }); |
| | | return records; |
| | | } |
| | | |
| | | private int resolveQuantity(DeviceLedger deviceLedger) { |
| | | if (deviceLedger == null || deviceLedger.getNumber() == null || deviceLedger.getNumber().compareTo(BigDecimal.ONE) < 0) { |
| | | return 1; |
| | | } |
| | | return Math.max(1, deviceLedger.getNumber().intValue()); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.device.service.impl; |
| | | |
| | | import com.ruoyi.device.mapper.DeviceLedgerMapper; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.device.pojo.DeviceMaintenance; |
| | | import com.ruoyi.device.pojo.MaintenanceTask; |
| | | import org.quartz.*; |
| | | import org.quartz.DisallowConcurrentExecution; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.BeanPropertyRowMapper; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.YearMonth; |
| | | import java.util.Arrays; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | @Component |
| | | @DisallowConcurrentExecution // ç¦æ¢å¹¶åæ§è¡åä¸ä¸ªJob |
| | | @DisallowConcurrentExecution |
| | | public class MaintenanceTaskJob implements Job, Serializable { |
| | | private static final long serialVersionUID = 1L; // å¿
é¡»å®ä¹åºååID |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Autowired |
| | | private DeviceMaintenanceServiceImpl deviceMaintenanceService; |
| | |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | @Autowired |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext context) throws JobExecutionException { |
| | | JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); |
| | | // ä¿®å¤ç±»å转æ¢éè¯¯ï¼æ£ç¡®è·åtaskId |
| | | Long taskId = jobDataMap.getLong("maintenanceTaskId"); |
| | | |
| | | try { |
| | | // 3. å°è¯æ¥è¯¢ä½ çä¸å¡æ°æ® |
| | | // éè¿JDBCæ¨¡æ¿æ¥è¯¢å®æ¶ä»»å¡ä¿¡æ¯ï¼ä½¿ç¨åæ°åæ¥è¯¢é²æ¢SQL注å
¥ |
| | | String yourSql = "SELECT * FROM maintenance_task where id = ?"; |
| | | List<MaintenanceTask> tasks = jdbcTemplate.query( |
| | | yourSql, |
| | |
| | | ); |
| | | MaintenanceTask timingTask = tasks.isEmpty() ? null : tasks.get(0); |
| | | if (timingTask == null) { |
| | | throw new JobExecutionException("MaintenanceTaskJobæ¾ä¸å°å®æ¶ä»»å¡: " + taskId); |
| | | throw new JobExecutionException("MaintenanceTaskJobæ¾ä¸å°å®æ¶ä»»å¡ " + taskId); |
| | | } |
| | | |
| | | // 2. å建并ä¿åå·¡æ£ä»»å¡è®°å½ - è¿å°±æ¯æ¨æä¾ç代ç åºè¯¥æ¾çä½ç½® |
| | | DeviceMaintenance deviceMaintenance = createInspectionTask(timingTask); |
| | | deviceMaintenanceService.save(deviceMaintenance); |
| | | List<Long> deviceIds = resolveDeviceIds(timingTask); |
| | | List<DeviceMaintenance> maintenanceList = new ArrayList<>(); |
| | | for (Long deviceId : deviceIds) { |
| | | int quantity = resolveQuantity(deviceId); |
| | | for (int i = 0; i < quantity; i++) { |
| | | maintenanceList.add(createInspectionTask(timingTask, deviceId)); |
| | | } |
| | | } |
| | | deviceMaintenanceService.saveBatch(maintenanceList); |
| | | |
| | | // 3. æ´æ°å®æ¶ä»»å¡çæ§è¡æ¶é´ |
| | | if (!tasks.isEmpty()) { |
| | | MaintenanceTask task = tasks.get(0); |
| | | |
| | | // æ´æ°æåæ§è¡æ¶é´ä¸ºå½åæ¶é´ |
| | | LocalDateTime lastExecutionTime = LocalDateTime.now(); |
| | | |
| | | // 计ç®ä¸æ¬¡æ§è¡æ¶é´ |
| | | LocalDateTime nextExecutionTime = calculateNextExecutionTime( |
| | | task.getFrequencyType(), |
| | | task.getFrequencyDetail(), |
| | | lastExecutionTime |
| | | ); |
| | | |
| | | // æ§è¡æ´æ°æä½ |
| | | String updateSql = "UPDATE maintenance_task " + |
| | | "SET last_execution_time = ?, next_execution_time = ? " + |
| | | "WHERE id = ?"; |
| | | |
| | | jdbcTemplate.update( |
| | | updateSql, |
| | | lastExecutionTime, |
| | | nextExecutionTime, |
| | | taskId |
| | | ); |
| | | String updateSql = "UPDATE maintenance_task SET last_execution_time = ?, next_execution_time = ? WHERE id = ?"; |
| | | jdbcTemplate.update(updateSql, lastExecutionTime, nextExecutionTime, taskId); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new JobExecutionException(e); |
| | | } |
| | | } |
| | | |
| | | // è¿å°±æ¯æ¨æä¾ç代ç å°è£
æçæ¹æ³ |
| | | private DeviceMaintenance createInspectionTask(MaintenanceTask timingTask) { |
| | | private DeviceMaintenance createInspectionTask(MaintenanceTask timingTask, Long deviceLedgerId) { |
| | | DeviceMaintenance inspectionTask = new DeviceMaintenance(); |
| | | |
| | | // å¤å¶åºæ¬å±æ§ |
| | | inspectionTask.setDeviceName(timingTask.getTaskName()); |
| | | DeviceLedger deviceLedger = deviceLedgerMapper.selectById(deviceLedgerId); |
| | | inspectionTask.setDeviceName(deviceLedger != null ? deviceLedger.getDeviceName() : timingTask.getTaskName()); |
| | | inspectionTask.setMaintenanceTaskId(timingTask.getId()); |
| | | inspectionTask.setDeviceLedgerId(timingTask.getTaskId()); |
| | | inspectionTask.setDeviceLedgerId(deviceLedgerId); |
| | | inspectionTask.setAreaId(timingTask.getAreaId() != null ? timingTask.getAreaId() : (deviceLedger != null ? deviceLedger.getAreaId() : null)); |
| | | inspectionTask.setMaintenancePlanTime(LocalDateTime.now()); |
| | | inspectionTask.setFrequencyType(timingTask.getFrequencyType()); |
| | | inspectionTask.setFrequencyDetail(timingTask.getFrequencyDetail()); |
| | | inspectionTask.setTenantId(timingTask.getTenantId()); |
| | | inspectionTask.setStatus(0); |
| | | inspectionTask.setDeviceModel(timingTask.getDeviceModel()); |
| | | inspectionTask.setDeviceModel(deviceLedger != null ? deviceLedger.getDeviceModel() : timingTask.getDeviceModel()); |
| | | inspectionTask.setCreateUser(Integer.parseInt(timingTask.getRegistrantId().toString())); |
| | | inspectionTask.setUpdateTime(LocalDateTime.now()); |
| | | inspectionTask.setCreateTime(LocalDateTime.now()); |
| | |
| | | return inspectionTask; |
| | | } |
| | | |
| | | private List<Long> resolveDeviceIds(MaintenanceTask timingTask) { |
| | | if (timingTask.getDeviceLedgerIdsStr() != null && !timingTask.getDeviceLedgerIdsStr().trim().isEmpty()) { |
| | | return Arrays.stream(timingTask.getDeviceLedgerIdsStr().split(",")) |
| | | .map(String::trim) |
| | | .filter(item -> !item.isEmpty()) |
| | | .map(Long::valueOf) |
| | | .distinct() |
| | | .collect(java.util.stream.Collectors.toList()); |
| | | } |
| | | List<Long> ids = new ArrayList<>(); |
| | | if (timingTask.getTaskId() != null) { |
| | | ids.add(timingTask.getTaskId()); |
| | | } |
| | | return ids; |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ä¸æ¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateNextExecutionTime(String frequencyType, |
| | | String frequencyDetail, |
| | | LocalDateTime currentTime) { |
| | | private int resolveQuantity(Long deviceLedgerId) { |
| | | try { |
| | | String sql = "SELECT number FROM device_ledger WHERE id = ?"; |
| | | Number quantity = jdbcTemplate.queryForObject(sql, Number.class, deviceLedgerId); |
| | | return quantity == null || quantity.intValue() < 1 ? 1 : quantity.intValue(); |
| | | } catch (Exception ignored) { |
| | | return 1; |
| | | } |
| | | } |
| | | |
| | | private LocalDateTime calculateNextExecutionTime(String frequencyType, String frequencyDetail, LocalDateTime currentTime) { |
| | | try { |
| | | switch (frequencyType) { |
| | | case "DAILY": |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯æ¥ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateDailyNextTime(String timeStr, LocalDateTime current) { |
| | | LocalTime executionTime = LocalTime.parse(timeStr); // è§£ææ ¼å¼ "HH:mm" |
| | | LocalTime executionTime = LocalTime.parse(timeStr); |
| | | LocalDateTime nextTime = LocalDateTime.of(current.toLocalDate(), executionTime); |
| | | |
| | | // 妿ä»å¤©çæ¶é´å·²è¿ï¼å宿æå¤© |
| | | return current.isBefore(nextTime) ? nextTime : nextTime.plusDays(1); |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯å¨ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateWeeklyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | String dayOfWeekStr = parts[0]; // å¦ "MON" æ "MON|WED|FRI" |
| | | LocalTime time = LocalTime.parse(parts[1]); // æ¶é´é¨å |
| | | |
| | | // è§£æææå (æ¯æå¤ä¸ªææ) |
| | | String dayOfWeekStr = parts[0]; |
| | | LocalTime time = LocalTime.parse(parts[1]); |
| | | Set<DayOfWeek> targetDays = parseDayOfWeeks(dayOfWeekStr); |
| | | |
| | | // ä»å½åæ¶é´å¼å§æ¾ä¸ä¸ä¸ªç¬¦åæ¡ä»¶çææå |
| | | LocalDateTime nextTime = current; |
| | | while (true) { |
| | | nextTime = nextTime.plusDays(1); |
| | | if (targetDays.contains(nextTime.getDayOfWeek())) { |
| | | return LocalDateTime.of(nextTime.toLocalDate(), time); |
| | | } |
| | | |
| | | // 鲿¢æ é循ç¯(ç论ä¸ä¸ä¼åç) |
| | | if (nextTime.isAfter(current.plusYears(1))) { |
| | | throw new RuntimeException("æ æ³æ¾å°ä¸æ¬¡æ§è¡æ¶é´"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯æä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateMonthlyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | int dayOfMonth = Integer.parseInt(parts[0]); |
| | | LocalTime time = LocalTime.parse(parts[1]); |
| | | |
| | | // ä»ä¸ä¸ªæå¼å§è®¡ç® |
| | | LocalDateTime nextTime = current.plusMonths(1) |
| | | return current.plusMonths(1) |
| | | .withDayOfMonth(Math.min(dayOfMonth, current.plusMonths(1).toLocalDate().lengthOfMonth())) |
| | | .with(time); |
| | | |
| | | return nextTime; |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯å£åº¦ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateQuarterlyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | int quarterMonth = Integer.parseInt(parts[0]); // 1=第1个æï¼2=第2个æï¼3=第3个æ |
| | | int quarterMonth = Integer.parseInt(parts[0]); |
| | | int dayOfMonth = Integer.parseInt(parts[1]); |
| | | LocalTime time = LocalTime.parse(parts[2]); |
| | | |
| | | // 计ç®å½åå£åº¦ |
| | | int currentQuarter = (current.getMonthValue() - 1) / 3 + 1; |
| | | int currentMonthInQuarter = (current.getMonthValue() - 1) % 3 + 1; |
| | | |
| | | YearMonth targetYearMonth; |
| | | if (currentMonthInQuarter < quarterMonth) { |
| | | // æ¬å£åº¦å
è¿ææ§è¡æºä¼ |
| | | targetYearMonth = YearMonth.from(current) |
| | | .plusMonths(quarterMonth - currentMonthInQuarter); |
| | | targetYearMonth = YearMonth.from(current).plusMonths(quarterMonth - currentMonthInQuarter); |
| | | } else { |
| | | // éè¦å°ä¸ä¸ªå£åº¦ |
| | | targetYearMonth = YearMonth.from(current) |
| | | .plusMonths(3 - currentMonthInQuarter + quarterMonth); |
| | | targetYearMonth = YearMonth.from(current).plusMonths(3 - currentMonthInQuarter + quarterMonth); |
| | | } |
| | | |
| | | // å¤çææ«æ¥æ |
| | | int adjustedDay = Math.min(dayOfMonth, targetYearMonth.lengthOfMonth()); |
| | | |
| | | return LocalDateTime.of( |
| | |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * è§£æææå å符串 |
| | | */ |
| | | private Set<DayOfWeek> parseDayOfWeeks(String dayOfWeekStr) { |
| | | Set<DayOfWeek> days = new HashSet<>(); |
| | | String[] dayStrs = dayOfWeekStr.split("\\|"); |
| | | |
| | | for (String dayStr : dayStrs) { |
| | | switch (dayStr) { |
| | | case "MON": days.add(DayOfWeek.MONDAY); break; |
| | | case "TUE": days.add(DayOfWeek.TUESDAY); break; |
| | | case "WED": days.add(DayOfWeek.WEDNESDAY); break; |
| | | case "THU": days.add(DayOfWeek.THURSDAY); break; |
| | | case "FRI": days.add(DayOfWeek.FRIDAY); break; |
| | | case "SAT": days.add(DayOfWeek.SATURDAY); break; |
| | | case "SUN": days.add(DayOfWeek.SUNDAY); break; |
| | | default: throw new IllegalArgumentException("æ æçææå : " + dayStr); |
| | | case "MON": |
| | | days.add(DayOfWeek.MONDAY); |
| | | break; |
| | | case "TUE": |
| | | days.add(DayOfWeek.TUESDAY); |
| | | break; |
| | | case "WED": |
| | | days.add(DayOfWeek.WEDNESDAY); |
| | | break; |
| | | case "THU": |
| | | days.add(DayOfWeek.THURSDAY); |
| | | break; |
| | | case "FRI": |
| | | days.add(DayOfWeek.FRIDAY); |
| | | break; |
| | | case "SAT": |
| | | days.add(DayOfWeek.SATURDAY); |
| | | break; |
| | | case "SUN": |
| | | days.add(DayOfWeek.SUNDAY); |
| | | break; |
| | | default: |
| | | throw new IllegalArgumentException("æ æçææå : " + dayStr); |
| | | } |
| | | } |
| | | |
| | | return days; |
| | | } |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.device.mapper.DeviceAreaMapper; |
| | | import com.ruoyi.device.mapper.MaintenanceTaskMapper; |
| | | import com.ruoyi.device.pojo.DeviceArea; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.device.pojo.MaintenanceTask; |
| | | import com.ruoyi.device.service.IDeviceLedgerService; |
| | | import com.ruoyi.device.service.MaintenanceTaskService; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.inspectiontask.pojo.TimingTask; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author :yys |
| | | * @date : 2025/12/22 14:57 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class MaintenanceTaskServiceImpl extends ServiceImpl<MaintenanceTaskMapper, MaintenanceTask> implements MaintenanceTaskService { |
| | | |
| | | @Autowired |
| | | private MaintenanceTaskMapper maintenanceTaskMapper; |
| | | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | private TimingTaskServiceImpl timingTaskService; |
| | | |
| | | @Autowired |
| | | private MaintenanceTaskScheduler maintenanceTaskScheduler; |
| | | @Autowired |
| | | private IDeviceLedgerService deviceLedgerService; |
| | | @Autowired |
| | | private DeviceAreaMapper deviceAreaMapper; |
| | | |
| | | @Override |
| | | public AjaxResult listPage(Page page, MaintenanceTask maintenanceTask) { |
| | | Page<MaintenanceTask> taskPage = maintenanceTaskMapper.selectPage(page, null); |
| | | // 2. å¦ææ²¡ææ°æ®ï¼ç´æ¥è¿å空å页 |
| | | com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MaintenanceTask> queryWrapper = |
| | | new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); |
| | | if (StringUtils.isNotEmpty(maintenanceTask.getTaskName())) { |
| | | queryWrapper.like(MaintenanceTask::getTaskName, maintenanceTask.getTaskName()); |
| | | } |
| | | if (maintenanceTask.getAreaId() != null) { |
| | | queryWrapper.eq(MaintenanceTask::getAreaId, maintenanceTask.getAreaId()); |
| | | } |
| | | Page<MaintenanceTask> taskPage = maintenanceTaskMapper.selectPage(page, queryWrapper); |
| | | if (taskPage.getRecords().isEmpty()) { |
| | | return AjaxResult.success(taskPage); |
| | | } |
| | | |
| | | // 3. æ¶éææéè¦æ¥è¯¢çç¨æ·ID |
| | | Set<Long> userIds = new HashSet<>(); |
| | | |
| | | // æ¶éç»è®°äººID |
| | | taskPage.getRecords().forEach(task -> { |
| | | if (task.getRegistrantId() != null) { |
| | | userIds.add(task.getRegistrantId()); |
| | | } |
| | | }); |
| | | |
| | | // 4. æ¹éæ¥è¯¢ç¨æ·ä¿¡æ¯ |
| | | Map<Long, String> userNickNameMap = new HashMap<>(); |
| | | if (!userIds.isEmpty()) { |
| | | List<SysUser> users = sysUserMapper.selectUserByIds((new ArrayList<>(userIds))); |
| | | List<SysUser> users = sysUserMapper.selectUserByIds(new ArrayList<>(userIds)); |
| | | users.forEach(user -> userNickNameMap.put(user.getUserId(), user.getNickName())); |
| | | } |
| | | Map<Long, String> areaNameMap = deviceAreaMapper.selectBatchIds(taskPage.getRecords().stream() |
| | | .map(MaintenanceTask::getAreaId) |
| | | .filter(java.util.Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList())) |
| | | .stream() |
| | | .collect(Collectors.toMap(DeviceArea::getId, DeviceArea::getAreaName, (left, right) -> left, HashMap::new)); |
| | | taskPage.getRecords().forEach(task -> { |
| | | // 设置ç»è®°äººæµç§° |
| | | if (task.getRegistrantId() != null) { |
| | | task.setRegistrant(userNickNameMap.getOrDefault(task.getRegistrantId(), "æªç¥ç¨æ·")); |
| | | } |
| | | task.setAreaName(areaNameMap.get(task.getAreaId())); |
| | | }); |
| | | return AjaxResult.success(taskPage); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult add(MaintenanceTask maintenanceTask) { |
| | | if (!prepareMaintenanceTask(maintenanceTask)) { |
| | | return AjaxResult.error("è¯·éæ©è®¾å¤"); |
| | | } |
| | | maintenanceTask.setActive(true); |
| | | // 计ç®é¦æ¬¡æ§è¡æ¶é´ |
| | | TimingTask task = new TimingTask(); |
| | | task.setFrequencyType(maintenanceTask.getFrequencyType()); |
| | | task.setFrequencyDetail(maintenanceTask.getFrequencyDetail()); |
| | |
| | | return AjaxResult.warn("æ²¡ææ¤æ°æ®"); |
| | | } |
| | | BeanUtils.copyProperties(maintenanceTask, maintenanceTask1); |
| | | if (!prepareMaintenanceTask(maintenanceTask1)) { |
| | | return AjaxResult.error("è¯·éæ©è®¾å¤"); |
| | | } |
| | | maintenanceTask1.setDeviceLedgerIds(null); |
| | | int update = maintenanceTaskMapper.updateById(maintenanceTask1); |
| | | if (update > 0) { |
| | | maintenanceTaskScheduler.rescheduleMaintenanceTask(maintenanceTask1); |
| | |
| | | public AjaxResult delete(List<Long> ids) { |
| | | int delete = maintenanceTaskMapper.deleteBatchIds(ids); |
| | | if (delete > 0) { |
| | | ids.forEach(id -> { |
| | | maintenanceTaskScheduler.unscheduleMaintenanceTask(id); |
| | | }); |
| | | ids.forEach(id -> maintenanceTaskScheduler.unscheduleMaintenanceTask(id)); |
| | | } |
| | | return AjaxResult.success("å 餿å"); |
| | | } |
| | | |
| | | private boolean prepareMaintenanceTask(MaintenanceTask task) { |
| | | Long[] deviceIds = task.getDeviceLedgerIds(); |
| | | if ((deviceIds == null || deviceIds.length == 0) && StringUtils.isNotEmpty(task.getDeviceLedgerIdsStr())) { |
| | | deviceIds = Arrays.stream(task.getDeviceLedgerIdsStr().split(",")) |
| | | .filter(StringUtils::isNotEmpty) |
| | | .map(Long::valueOf) |
| | | .toArray(Long[]::new); |
| | | } |
| | | if (deviceIds == null || deviceIds.length == 0) { |
| | | deviceIds = task.getTaskId() == null ? new Long[0] : new Long[]{task.getTaskId()}; |
| | | } |
| | | List<Long> validIds = Arrays.stream(deviceIds).distinct().collect(Collectors.toList()); |
| | | if (validIds.isEmpty()) { |
| | | return false; |
| | | } |
| | | List<DeviceLedger> devices = validIds.stream() |
| | | .map(deviceLedgerService::getById) |
| | | .filter(device -> device != null) |
| | | .collect(Collectors.toList()); |
| | | if (devices.isEmpty()) { |
| | | return false; |
| | | } |
| | | task.setTaskId(devices.get(0).getId()); |
| | | if (task.getAreaId() == null) { |
| | | task.setAreaId(devices.get(0).getAreaId()); |
| | | } |
| | | task.setDeviceLedgerIdsStr(devices.stream().map(item -> String.valueOf(item.getId())).collect(Collectors.joining(","))); |
| | | task.setTaskName(devices.stream().map(DeviceLedger::getDeviceName).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.joining(","))); |
| | | task.setDeviceModel(devices.stream().map(DeviceLedger::getDeviceModel).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.joining(","))); |
| | | return true; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.http.service.controller; |
| | | |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.http.service.impl.RealTimeEnergyConsumptionServiceImpl; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.naming.ldap.PagedResultsControl; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | @RequestMapping("/iot") |
| | | @Api(tags = "æ°éæ¥å£") |
| | | public class JclyController extends BaseController { |
| | | |
| | | @Autowired |
| | | private RealTimeEnergyConsumptionServiceImpl realTimeEnergyConsumptionService; |
| | | |
| | | private final String DEVICE_GUID = "90444196515214284663"; |
| | | |
| | | private final String DEVICE_GUID_2 = "90187099059463151919"; |
| | | |
| | | private final String DEVICE_GUID_3 = "90299548548536240693"; |
| | | |
| | | private final String DEVICE_GUID_4 = "90558670647417764794"; |
| | | |
| | | private final String DEVICE_GUID_5 = "90802100373808917949"; |
| | | |
| | | private final String DEVICE_GUID_6 = "90878497978270816672"; |
| | | |
| | | /** |
| | | * 宿¶è·å温湿度ï¼äºæ°§åç¢³æ°æ® |
| | | */ |
| | | @GetMapping("/getRealData") |
| | | public AjaxResult getRealData() { |
| | | List<Map<String,String>> maps = realTimeEnergyConsumptionService |
| | | .getRealData(Arrays. |
| | | asList(DEVICE_GUID, |
| | | DEVICE_GUID_2, |
| | | DEVICE_GUID_3, |
| | | DEVICE_GUID_4, |
| | | DEVICE_GUID_5, |
| | | DEVICE_GUID_6)); |
| | | return AjaxResult.success(maps); |
| | | } |
| | | |
| | | } |
| | |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.http.service.RealTimeEnergyConsumptionService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | private static final String TOKEN_URL = "/elitechAccess/getToken"; |
| | | |
| | | private static final String REAL_TIME_URL = "/elitechAccess/v2/getRealTimeData"; //è·å设å¤å®æ¶æ°æ® |
| | | private static final String REAL_TIME_URL = "/elitechAccess/v2/getRealTimeData"; |
| | | |
| | | private static final String KET_ID = "75804708"; |
| | | |
| | |
| | | |
| | | private static final String PASS_WORD = "y17775163675"; |
| | | |
| | | private static final String DEVICE_GUID = "90444196515214284663"; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, String> redisTemplate; |
| | | |
| | | /** |
| | | * æ ¹æ®paramCodeæåæ¢å¤´åæ° |
| | | * @param paramList 设å¤åæ°æ°ç» |
| | | * @param targetCode ç®æ æ¢å¤´ç¼ç |
| | | * @return æ¢å¤´åæ°å¯¹è±¡ï¼å
å«name/value/unitï¼ |
| | | * æ ¹æ® paramCode æåæ¢å¤´åæ°ã |
| | | */ |
| | | private static JSONObject getProbeParam(JSONArray paramList, String targetCode) { |
| | | if (paramList == null) { |
| | | return new JSONObject(); |
| | | } |
| | | for (int i = 0; i < paramList.size(); i++) { |
| | | JSONObject paramObj = paramList.getJSONObject(i); |
| | | if (targetCode.equals(paramObj.getString("paramCode"))) { |
| | | return paramObj; |
| | | } |
| | | } |
| | | return new JSONObject(); // æªå¹é
å°è¿å空对象ï¼é¿å
空æé |
| | | return new JSONObject(); |
| | | } |
| | | |
| | | /** |
| | | * 宿¶è·å温湿度ï¼äºæ°§åç¢³æ°æ® |
| | | * 宿¶è·å温湿度ãå
ç
§ãäºæ°§åç¢³æ°æ®ã |
| | | */ |
| | | public static void main(String[] args) { |
| | | String realTimeData = getRealTimeData(getToken()); |
| | | public List<Map<String, String>> getRealData(List<String> guidList) { |
| | | log.info("å¼å§è·å宿¶æ°æ®"); |
| | | List<Map<String, String>> listMaps = new ArrayList<>(); |
| | | String realTimeData = getRealTimeData(getToken(), guidList); |
| | | Map<String, Object> map = JSON.parseObject(realTimeData, Map.class); |
| | | if(map.get("code").equals(0)){ |
| | | // 1. è§£æå¤å±data为JSONæ°ç»ï¼æ¥å£è¿åç设å¤åè¡¨ï¼ |
| | | JSONArray deviceList = JSON.parseArray(map.get("data").toString()); |
| | | // 2. éå设å¤åè¡¨ï¼æ¤å¤ä»
å第ä¸ä¸ªè®¾å¤ï¼è¥æå¤ä¸ªè®¾å¤å¯å¾ªç¯å¤çï¼ |
| | | if (!deviceList.isEmpty()) { |
| | | JSONObject deviceObj = deviceList.getJSONObject(0); |
| | | // 3. è§£æè®¾å¤å
çåæ°æ°ç»ï¼ææparamCode对åºçåæ°ï¼ |
| | | JSONArray paramList = deviceObj.getJSONArray("data"); |
| | | if (!Integer.valueOf(0).equals(map.get("code"))) { |
| | | return listMaps; |
| | | } |
| | | |
| | | // 4. å®ä¹ç®æ æ¢å¤´çparamCodeï¼æéæ©å± |
| | | String[] targetCodes = {"0100", "0110", "0120", "0130"}; |
| | | for (String code : targetCodes) { |
| | | // 5. éååæ°æ°ç»ï¼å¹é
ç®æ paramCode |
| | | for (int i = 0; i < paramList.size(); i++) { |
| | | JSONObject paramObj = paramList.getJSONObject(i); |
| | | String currentCode = paramObj.getString("paramCode"); |
| | | if (code.equals(currentCode)) { |
| | | // 6. æåæ ¸å¿å段ï¼å¼ãåä½ãæ¢å¤´åç§°ï¼ |
| | | String paramName = paramObj.getString("paramName"); // æ¢å¤´1/æ¢å¤´2... |
| | | String value = paramObj.getString("value"); // æ°å¼ï¼345.80/24.90...ï¼ |
| | | String unitCode = paramObj.getString("unitCode"); // åä½ï¼Lux/â/%RH/ppmï¼ |
| | | JSONArray deviceList = JSON.parseArray(String.valueOf(map.get("data"))); |
| | | if (deviceList == null || deviceList.isEmpty()) { |
| | | return listMaps; |
| | | } |
| | | |
| | | // 7. ä¸å¡å¤çï¼æå°/èµå¼/åå¨çï¼æéä¿®æ¹ï¼ |
| | | System.out.println(paramName + "ï¼" + value + " " + unitCode); |
| | | // å¹é
å°åç´æ¥è·³åºå
å±å¾ªç¯ï¼æåæç |
| | | break; |
| | | } |
| | | } |
| | | String[] targetCodes = {"0100", "0110", "0120", "0130"}; |
| | | for (int deviceIndex = 0; deviceIndex < deviceList.size(); deviceIndex++) { |
| | | JSONObject deviceObj = deviceList.getJSONObject(deviceIndex); |
| | | JSONArray paramList = deviceObj.getJSONArray("data"); |
| | | Map<String, String> deviceData = new HashMap<>(); |
| | | for (String code : targetCodes) { |
| | | JSONObject paramObj = getProbeParam(paramList, code); |
| | | if (paramObj.isEmpty()) { |
| | | continue; |
| | | } |
| | | String paramName = paramObj.getString("paramName"); |
| | | String value = paramObj.getString("value"); |
| | | String unitCode = paramObj.getString("unitCode"); |
| | | log.info("{}: {} {}", paramName, value, unitCode); |
| | | switch (paramName) { |
| | | case "æ¢å¤´1": |
| | | deviceData.put("light", value + unitCode); |
| | | break; |
| | | case "æ¢å¤´2": |
| | | deviceData.put("temperature", value + unitCode); |
| | | break; |
| | | case "æ¢å¤´3": |
| | | deviceData.put("humidity", value + unitCode); |
| | | break; |
| | | case "æ¢å¤´4": |
| | | deviceData.put("co2", value + unitCode); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | listMaps.add(deviceData); |
| | | } |
| | | return listMaps; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(); |
| | | } |
| | | |
| | | public static String getToken(){ |
| | | public String getToken() { |
| | | String cachedToken = sanitizeToken(redisTemplate.opsForValue().get("JCLY_TOKEN:")); |
| | | if (cachedToken != null) { |
| | | return cachedToken; |
| | | } |
| | | Map<String, String> param = new HashMap<>(); |
| | | param.put("keyId", KET_ID); |
| | | param.put("keySecret", KEY_SECRET); |
| | | param.put("userName", USER_NAME); |
| | | param.put("password", PASS_WORD); |
| | | log.info("请æ±åæ°ï¼{}", JSON.toJSONString( param)); |
| | | log.info("请æ±åæ°ï¼{}", JSON.toJSONString(param)); |
| | | String result = HttpUtils.sendPostJson(URL + TOKEN_URL, JSON.toJSONString(param)); |
| | | log.info("è¿åç»æï¼{}", result); |
| | | Map<String, Object> map = JSON.parseObject(result, Map.class); |
| | | if (map.get("code").equals(0)) { |
| | | if (Integer.valueOf(0).equals(map.get("code"))) { |
| | | Object token = map.get("data"); |
| | | log.info("token:{}", token); |
| | | redisTemplate.opsForValue().set("JCLY_TOKEN:", token.toString(), 60 * 60 * 24); |
| | | return token.toString(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static String getRealTimeData(String token){ |
| | | private String sanitizeToken(String token) { |
| | | if (token == null) { |
| | | return null; |
| | | } |
| | | String cleanedToken = token.replace("\0", "").trim(); |
| | | return cleanedToken.isEmpty() ? null : cleanedToken; |
| | | } |
| | | |
| | | public static String getRealTimeData(String token, List<String> guidList) { |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("keyId", KET_ID); |
| | | param.put("keySecret", KEY_SECRET); |
| | | param.put("deviceGuids", Collections.singletonList(DEVICE_GUID)); |
| | | log.info("请æ±åæ°ï¼{}", JSON.toJSONString( param)); |
| | | String result = HttpUtils.sendPostJson(URL + REAL_TIME_URL, JSON.toJSONString(param),token); |
| | | param.put("deviceGuids", guidList); |
| | | log.info("请æ±åæ°ï¼{}", JSON.toJSONString(param)); |
| | | String result = HttpUtils.sendPostJson(URL + REAL_TIME_URL, JSON.toJSONString(param), token); |
| | | log.info("è¿åç»æï¼{}", result); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | package com.ruoyi.inspectiontask.pojo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | 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.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Excel; |
| | | import io.swagger.annotations.ApiModel; |
| | |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * å·¡æ£ä»»å¡å¯ä¸æ è¯ |
| | | */ |
| | | @TableId(type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | |
| | | |
| | | @ApiModelProperty(value = "设å¤id") |
| | | private Integer taskId; |
| | | |
| | | @ApiModelProperty(value = "设å¤åºåid") |
| | | private Long areaId; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "设å¤åºååç§°") |
| | | private String areaName; |
| | | |
| | | @ApiModelProperty(value = "å·¡æ£äººID") |
| | | private String inspectorId; |
| | |
| | | @ApiModelProperty(value = "å·¡æ£å°ç¹è¯¦ç»æè¿°") |
| | | private String inspectionLocation; |
| | | |
| | | @ApiModelProperty(value = "软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤") |
| | | @ApiModelProperty(value = "软å 餿 è®°ï¼0=æªå é¤ï¼1=å·²å é¤") |
| | | private Integer deleted; |
| | | |
| | | @ApiModelProperty(value = "å建该记å½çç¨æ·") |
| | |
| | | package com.ruoyi.inspectiontask.pojo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主é®ID |
| | | */ |
| | | @TableId(type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | |
| | | |
| | | @ApiModelProperty(value = "设å¤id") |
| | | private Integer taskId; |
| | | |
| | | @ApiModelProperty(value = "设å¤åºåid") |
| | | private Long areaId; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "设å¤åºååç§°") |
| | | private String areaName; |
| | | |
| | | @ApiModelProperty(value = "设å¤IDéå") |
| | | private String taskIdsStr; |
| | | |
| | | @ApiModelProperty(value = "å·¡æ£äºº") |
| | | @Excel(name = "æ§è¡å·¡æ£äºº") |
| | |
| | | @ApiModelProperty(value = "ç¶æ") |
| | | private String status; |
| | | |
| | | @ApiModelProperty(value = "软å 餿 å¿ï¼0=æªå é¤ï¼1=å·²å é¤") |
| | | @ApiModelProperty(value = "软å 餿 è®°ï¼0=æªå é¤ï¼1=å·²å é¤") |
| | | private Integer deleted; |
| | | |
| | | @TableField(exist = false) |
| | | private String dateStr; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "å¤é设å¤ID") |
| | | private Long[] taskIds; |
| | | |
| | | @ApiModelProperty(value = "å建该记å½çç¨æ·") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT) |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Integer createUser; |
| | | |
| | | @ApiModelProperty(value = "è®°å½å建æ¶é´") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT) |
| | | // @JsonFormat(pattern = "yyyy-MM-dd") |
| | | // @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private LocalDateTime createTime; |
| | | |
| | | @ApiModelProperty(value = "æåä¿®æ¹è¯¥è®°å½çç¨æ·") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT_UPDATE) |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Integer updateUser; |
| | | |
| | | @ApiModelProperty(value = "è®°å½æåæ´æ°æ¶é´") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT_UPDATE) |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private LocalDateTime updateTime; |
| | | |
| | | @ApiModelProperty(value = "ç§æ·ID") |
| | | @TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT) |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long tenantId; |
| | | |
| | | } |
| | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.device.mapper.DeviceAreaMapper; |
| | | import com.ruoyi.device.mapper.DeviceLedgerMapper; |
| | | import com.ruoyi.device.pojo.DeviceArea; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.inspectiontask.dto.InspectionTaskDto; |
| | | import com.ruoyi.inspectiontask.mapper.InspectionTaskMapper; |
| | | import com.ruoyi.inspectiontask.pojo.InspectionTask; |
| | |
| | | @Autowired |
| | | private CommonFileServiceImpl commonFileService; |
| | | |
| | | @Autowired |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | |
| | | @Autowired |
| | | private DeviceAreaMapper deviceAreaMapper; |
| | | |
| | | @Override |
| | | public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) { |
| | | LambdaQueryWrapper<InspectionTask> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.orderByDesc(InspectionTask::getCreateTime); |
| | | if (StringUtils.isNotBlank(inspectionTaskDto.getTaskName())) { |
| | | queryWrapper.like(InspectionTask::getTaskName, inspectionTaskDto.getTaskName()); |
| | | } |
| | | if (inspectionTaskDto.getAreaId() != null) { |
| | | queryWrapper.eq(InspectionTask::getAreaId, inspectionTaskDto.getAreaId()); |
| | | } |
| | | IPage<InspectionTask> entityPage = inspectionTaskMapper.selectPage(page, queryWrapper); |
| | | |
| | |
| | | } |
| | | // è·åidéå |
| | | List<Long> ids = entityPage.getRecords().stream().map(InspectionTask::getId).collect(Collectors.toList()); |
| | | Map<Long, String> areaNameMap = buildAreaNameMap(entityPage.getRecords().stream() |
| | | .map(InspectionTask::getAreaId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet())); |
| | | //ç»è®°äººids |
| | | List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).collect(Collectors.toList()); |
| | | // æ¹éæ¥è¯¢ç»è®°äºº |
| | |
| | | if (sysUser != null) { |
| | | dto.setRegistrant(sysUser.getNickName()); |
| | | } |
| | | dto.setAreaName(areaNameMap.get(inspectionTask.getAreaId())); |
| | | // å¤çå·¡æ£äººåç§° |
| | | if (StringUtils.isNotBlank(inspectionTask.getInspectorId())) { |
| | | String inspectorNames = Arrays.stream(inspectionTask.getInspectorId().split(",")) |
| | |
| | | return resultPage; |
| | | } |
| | | |
| | | private Map<Long, String> buildAreaNameMap(Set<Long> areaIds) { |
| | | if (areaIds == null || areaIds.isEmpty()) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | return deviceAreaMapper.selectBatchIds(new ArrayList<>(areaIds)).stream() |
| | | .collect(Collectors.toMap(DeviceArea::getId, DeviceArea::getAreaName, (left, right) -> left)); |
| | | } |
| | | |
| | | // æåå建BlobDTOçå
Œ
±æ¹æ³ |
| | | private StorageBlobDTO createBlobDto(StorageBlob blob) { |
| | | StorageBlobDTO dto = new StorageBlobDTO(); |
| | |
| | | public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) throws IOException { |
| | | InspectionTask inspectionTask = new InspectionTask(); |
| | | BeanUtils.copyProperties(inspectionTaskDto, inspectionTask); |
| | | if (inspectionTask.getAreaId() == null && inspectionTask.getTaskId() != null) { |
| | | DeviceLedger deviceLedger = deviceLedgerMapper.selectById(Long.valueOf(inspectionTask.getTaskId())); |
| | | if (deviceLedger != null) { |
| | | inspectionTask.setAreaId(deviceLedger.getAreaId()); |
| | | } |
| | | } |
| | | inspectionTask.setRegistrantId(SecurityUtils.getLoginUser().getUserId()); |
| | | inspectionTask.setRegistrant(SecurityUtils.getLoginUser().getUsername()); |
| | | int i; |
| | |
| | | package com.ruoyi.inspectiontask.service.impl; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.device.mapper.DeviceLedgerMapper; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.inspectiontask.mapper.InspectionTaskMapper; |
| | | import com.ruoyi.inspectiontask.mapper.TimingTaskMapper; |
| | | import com.ruoyi.inspectiontask.pojo.InspectionTask; |
| | | import com.ruoyi.inspectiontask.pojo.TimingTask; |
| | | import com.ruoyi.inspectiontask.service.TimingTaskService; |
| | | import org.quartz.*; |
| | | import org.quartz.DisallowConcurrentExecution; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.BeanPropertyRowMapper; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.YearMonth; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | @DisallowConcurrentExecution // ç¦æ¢å¹¶åæ§è¡åä¸ä¸ªJob |
| | | @DisallowConcurrentExecution |
| | | public class TimingTaskJob implements Job, Serializable { |
| | | private static final long serialVersionUID = 1L; // å¿
é¡»å®ä¹åºååID |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Autowired |
| | | private TimingTaskMapper timingTaskMapper; |
| | |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | @Autowired |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext context) throws JobExecutionException { |
| | | JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); |
| | | // ä¿®å¤ç±»å转æ¢éè¯¯ï¼æ£ç¡®è·åtaskId |
| | | Long taskId = jobDataMap.getLong("taskId"); |
| | | |
| | | try { |
| | | // 3. å°è¯æ¥è¯¢ä½ çä¸å¡æ°æ® |
| | | // éè¿JDBCæ¨¡æ¿æ¥è¯¢å®æ¶ä»»å¡ä¿¡æ¯ï¼ä½¿ç¨åæ°åæ¥è¯¢é²æ¢SQL注å
¥ |
| | | String yourSql = "SELECT * FROM timing_task where id = ?"; |
| | | String sql = "SELECT * FROM timing_task WHERE id = ?"; |
| | | List<TimingTask> tasks = jdbcTemplate.query( |
| | | yourSql, |
| | | sql, |
| | | new BeanPropertyRowMapper<>(TimingTask.class), |
| | | taskId |
| | | ); |
| | |
| | | if (timingTask == null) { |
| | | throw new JobExecutionException("æ¾ä¸å°å®æ¶ä»»å¡: " + taskId); |
| | | } |
| | | |
| | | // if (!timingTask.isActive()) { |
| | | // throw new JobExecutionException("宿¶ä»»å¡å·²ç¦ç¨: " + taskId); |
| | | // } |
| | | |
| | | // 2. å建并ä¿åå·¡æ£ä»»å¡è®°å½ - è¿å°±æ¯æ¨æä¾ç代ç åºè¯¥æ¾çä½ç½® |
| | | InspectionTask inspectionTask = createInspectionTask(timingTask); |
| | | inspectionTaskMapper.insert(inspectionTask); |
| | | List<Long> deviceIds = resolveTaskIds(timingTask); |
| | | if (deviceIds.isEmpty()) { |
| | | throw new JobExecutionException("宿¶ä»»å¡æªé
置设å¤: " + taskId); |
| | | } |
| | | |
| | | // 3. æ´æ°å®æ¶ä»»å¡çæ§è¡æ¶é´ |
| | | for (Long deviceId : deviceIds) { |
| | | DeviceLedger deviceLedger = deviceLedgerMapper.selectById(deviceId); |
| | | if (deviceLedger == null) { |
| | | continue; |
| | | } |
| | | int count = getDeviceCount(deviceLedger.getNumber()); |
| | | for (int i = 0; i < count; i++) { |
| | | inspectionTaskMapper.insert(createInspectionTask(timingTask, deviceLedger)); |
| | | } |
| | | } |
| | | |
| | | if (!tasks.isEmpty()) { |
| | | TimingTask task = tasks.get(0); |
| | | |
| | | // æ´æ°æåæ§è¡æ¶é´ä¸ºå½åæ¶é´ |
| | | LocalDateTime lastExecutionTime = LocalDateTime.now(); |
| | | |
| | | // 计ç®ä¸æ¬¡æ§è¡æ¶é´ |
| | | LocalDateTime nextExecutionTime = calculateNextExecutionTime( |
| | | task.getFrequencyType(), |
| | | task.getFrequencyDetail(), |
| | | timingTask.getFrequencyType(), |
| | | timingTask.getFrequencyDetail(), |
| | | lastExecutionTime |
| | | ); |
| | | |
| | | // æ§è¡æ´æ°æä½ |
| | | String updateSql = "UPDATE timing_task " + |
| | | "SET last_execution_time = ?, next_execution_time = ? " + |
| | | "WHERE id = ?"; |
| | | |
| | | jdbcTemplate.update( |
| | | updateSql, |
| | | lastExecutionTime, |
| | | nextExecutionTime, |
| | | taskId |
| | | ); |
| | | String updateSql = "UPDATE timing_task SET last_execution_time = ?, next_execution_time = ? WHERE id = ?"; |
| | | jdbcTemplate.update(updateSql, lastExecutionTime, nextExecutionTime, taskId); |
| | | } |
| | | // timingTaskService.updateTaskExecutionTime(taskId); |
| | | |
| | | // 4. è®°å½æ§è¡æ¥å¿ |
| | | // timingTaskService.recordExecutionLog(taskId, true, "任塿§è¡æåï¼çæå·¡æ£ä»»å¡ID: " + inspectionTask.getId()); |
| | | |
| | | } catch (Exception e) { |
| | | // timingTaskService.recordExecutionLog(taskId, false, "任塿§è¡å¤±è´¥: " + e.getMessage()); |
| | | throw new JobExecutionException(e); |
| | | } |
| | | } |
| | | |
| | | // è¿å°±æ¯æ¨æä¾ç代ç å°è£
æçæ¹æ³ |
| | | private InspectionTask createInspectionTask(TimingTask timingTask) { |
| | | InspectionTask inspectionTask = new InspectionTask(); |
| | | private List<Long> resolveTaskIds(TimingTask timingTask) { |
| | | if (StringUtils.isNotBlank(timingTask.getTaskIdsStr())) { |
| | | return Arrays.stream(timingTask.getTaskIdsStr().split(",")) |
| | | .filter(StringUtils::isNotBlank) |
| | | .map(String::trim) |
| | | .map(Long::valueOf) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | if (timingTask.getTaskId() != null) { |
| | | return new ArrayList<>(Arrays.asList(timingTask.getTaskId().longValue())); |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | // å¤å¶åºæ¬å±æ§ |
| | | inspectionTask.setTaskName(timingTask.getTaskName()); |
| | | inspectionTask.setTaskId(timingTask.getTaskId()); |
| | | private int getDeviceCount(BigDecimal number) { |
| | | if (number == null) { |
| | | return 1; |
| | | } |
| | | int count = number.intValue(); |
| | | return count > 0 ? count : 1; |
| | | } |
| | | |
| | | private InspectionTask createInspectionTask(TimingTask timingTask, DeviceLedger deviceLedger) { |
| | | InspectionTask inspectionTask = new InspectionTask(); |
| | | inspectionTask.setTaskName(deviceLedger.getDeviceName()); |
| | | inspectionTask.setTaskId(deviceLedger.getId().intValue()); |
| | | inspectionTask.setAreaId(deviceLedger.getAreaId()); |
| | | inspectionTask.setInspectorId(timingTask.getInspectorIds()); |
| | | inspectionTask.setInspectionLocation(timingTask.getInspectionLocation()); |
| | | inspectionTask.setRemarks("èªå¨çæèªå®æ¶ä»»å¡ID: " + timingTask.getId()); |
| | | inspectionTask.setRegistrantId(timingTask.getRegistrantId()); |
| | | inspectionTask.setRegistrant(timingTask.getRegistrant()); |
| | | inspectionTask.setFrequencyType(timingTask.getFrequencyType()); |
| | | inspectionTask.setFrequencyDetail(timingTask.getFrequencyDetail()); |
| | | inspectionTask.setTenantId(timingTask.getTenantId()); |
| | | |
| | | return inspectionTask; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计ç®ä¸æ¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateNextExecutionTime(String frequencyType, |
| | | String frequencyDetail, |
| | | LocalDateTime currentTime) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯æ¥ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateDailyNextTime(String timeStr, LocalDateTime current) { |
| | | LocalTime executionTime = LocalTime.parse(timeStr); // è§£ææ ¼å¼ "HH:mm" |
| | | LocalTime executionTime = LocalTime.parse(timeStr); |
| | | LocalDateTime nextTime = LocalDateTime.of(current.toLocalDate(), executionTime); |
| | | |
| | | // 妿ä»å¤©çæ¶é´å·²è¿ï¼å宿æå¤© |
| | | return current.isBefore(nextTime) ? nextTime : nextTime.plusDays(1); |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯å¨ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateWeeklyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | String dayOfWeekStr = parts[0]; // å¦ "MON" æ "MON|WED|FRI" |
| | | LocalTime time = LocalTime.parse(parts[1]); // æ¶é´é¨å |
| | | |
| | | // è§£æææå (æ¯æå¤ä¸ªææ) |
| | | String dayOfWeekStr = parts[0]; |
| | | LocalTime time = LocalTime.parse(parts[1]); |
| | | Set<DayOfWeek> targetDays = parseDayOfWeeks(dayOfWeekStr); |
| | | |
| | | // ä»å½åæ¶é´å¼å§æ¾ä¸ä¸ä¸ªç¬¦åæ¡ä»¶çææå |
| | | LocalDateTime nextTime = current; |
| | | while (true) { |
| | | nextTime = nextTime.plusDays(1); |
| | | if (targetDays.contains(nextTime.getDayOfWeek())) { |
| | | return LocalDateTime.of(nextTime.toLocalDate(), time); |
| | | } |
| | | |
| | | // 鲿¢æ é循ç¯(ç论ä¸ä¸ä¼åç) |
| | | if (nextTime.isAfter(current.plusYears(1))) { |
| | | throw new RuntimeException("æ æ³æ¾å°ä¸æ¬¡æ§è¡æ¶é´"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯æä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateMonthlyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | int dayOfMonth = Integer.parseInt(parts[0]); |
| | | LocalTime time = LocalTime.parse(parts[1]); |
| | | |
| | | // ä»ä¸ä¸ªæå¼å§è®¡ç® |
| | | LocalDateTime nextTime = current.plusMonths(1) |
| | | return current.plusMonths(1) |
| | | .withDayOfMonth(Math.min(dayOfMonth, current.plusMonths(1).toLocalDate().lengthOfMonth())) |
| | | .with(time); |
| | | |
| | | return nextTime; |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯å£åº¦ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateQuarterlyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | int quarterMonth = Integer.parseInt(parts[0]); // 1=第1个æï¼2=第2个æï¼3=第3个æ |
| | | int quarterMonth = Integer.parseInt(parts[0]); |
| | | int dayOfMonth = Integer.parseInt(parts[1]); |
| | | LocalTime time = LocalTime.parse(parts[2]); |
| | | |
| | | // 计ç®å½åå£åº¦ |
| | | int currentQuarter = (current.getMonthValue() - 1) / 3 + 1; |
| | | int currentMonthInQuarter = (current.getMonthValue() - 1) % 3 + 1; |
| | | |
| | | YearMonth targetYearMonth; |
| | | if (currentMonthInQuarter < quarterMonth) { |
| | | // æ¬å£åº¦å
è¿ææ§è¡æºä¼ |
| | | targetYearMonth = YearMonth.from(current) |
| | | .plusMonths(quarterMonth - currentMonthInQuarter); |
| | | targetYearMonth = YearMonth.from(current).plusMonths(quarterMonth - currentMonthInQuarter); |
| | | } else { |
| | | // éè¦å°ä¸ä¸ªå£åº¦ |
| | | targetYearMonth = YearMonth.from(current) |
| | | .plusMonths(3 - currentMonthInQuarter + quarterMonth); |
| | | targetYearMonth = YearMonth.from(current).plusMonths(3 - currentMonthInQuarter + quarterMonth); |
| | | } |
| | | |
| | | // å¤çææ«æ¥æ |
| | | int adjustedDay = Math.min(dayOfMonth, targetYearMonth.lengthOfMonth()); |
| | | |
| | | return LocalDateTime.of( |
| | | targetYearMonth.getYear(), |
| | | targetYearMonth.getMonthValue(), |
| | |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * è§£æææå å符串 |
| | | */ |
| | | private Set<DayOfWeek> parseDayOfWeeks(String dayOfWeekStr) { |
| | | Set<DayOfWeek> days = new HashSet<>(); |
| | | String[] dayStrs = dayOfWeekStr.split("\\|"); |
| | | |
| | | for (String dayStr : dayStrs) { |
| | | switch (dayStr) { |
| | | case "MON": days.add(DayOfWeek.MONDAY); break; |
| | | case "TUE": days.add(DayOfWeek.TUESDAY); break; |
| | | case "WED": days.add(DayOfWeek.WEDNESDAY); break; |
| | | case "THU": days.add(DayOfWeek.THURSDAY); break; |
| | | case "FRI": days.add(DayOfWeek.FRIDAY); break; |
| | | case "SAT": days.add(DayOfWeek.SATURDAY); break; |
| | | case "SUN": days.add(DayOfWeek.SUNDAY); break; |
| | | default: throw new IllegalArgumentException("æ æçææå : " + dayStr); |
| | | case "MON": |
| | | days.add(DayOfWeek.MONDAY); |
| | | break; |
| | | case "TUE": |
| | | days.add(DayOfWeek.TUESDAY); |
| | | break; |
| | | case "WED": |
| | | days.add(DayOfWeek.WEDNESDAY); |
| | | break; |
| | | case "THU": |
| | | days.add(DayOfWeek.THURSDAY); |
| | | break; |
| | | case "FRI": |
| | | days.add(DayOfWeek.FRIDAY); |
| | | break; |
| | | case "SAT": |
| | | days.add(DayOfWeek.SATURDAY); |
| | | break; |
| | | case "SUN": |
| | | days.add(DayOfWeek.SUNDAY); |
| | | break; |
| | | default: |
| | | throw new IllegalArgumentException("æ æçææ: " + dayStr); |
| | | } |
| | | } |
| | | |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.device.mapper.DeviceAreaMapper; |
| | | import com.ruoyi.device.mapper.DeviceLedgerMapper; |
| | | import com.ruoyi.device.pojo.DeviceArea; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.inspectiontask.dto.TimingTaskDto; |
| | | import com.ruoyi.inspectiontask.mapper.InspectionTaskMapper; |
| | | import com.ruoyi.inspectiontask.mapper.TimingTaskMapper; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.*; |
| | | import java.time.DayOfWeek; |
| | | import java.time.DateTimeException; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.Year; |
| | | import java.time.YearMonth; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | |
| | | @Autowired |
| | | private DeviceAreaMapper deviceAreaMapper; |
| | | |
| | | @Override |
| | | public IPage<TimingTaskDto> selectTimingTaskList(Page<TimingTask> page, TimingTask timingTask) { |
| | | // 1. å
å页æ¥è¯¢å®æ¶ä»»å¡æ°æ® |
| | | // æå»ºæ¥è¯¢æ¡ä»¶ |
| | | LambdaQueryWrapper<TimingTask> queryWrapper = new LambdaQueryWrapper<>(); |
| | | if (StringUtils.isNotBlank(timingTask.getTaskName())) { |
| | | queryWrapper.like(TimingTask::getTaskName, timingTask.getTaskName()); |
| | | } |
| | | if (timingTask.getAreaId() != null) { |
| | | queryWrapper.eq(TimingTask::getAreaId, timingTask.getAreaId()); |
| | | } |
| | | IPage<TimingTask> taskPage = timingTaskMapper.selectPage(page, queryWrapper); |
| | | |
| | | // 2. å¦ææ²¡ææ°æ®ï¼ç´æ¥è¿å空å页 |
| | | if (taskPage.getRecords().isEmpty()) { |
| | | return new Page<>(taskPage.getCurrent(), taskPage.getSize(), taskPage.getTotal()); |
| | | } |
| | | |
| | | // 3. æ¶éææéè¦æ¥è¯¢çç¨æ·ID |
| | | Set<Long> userIds = new HashSet<>(); |
| | | |
| | | // æ¶éç»è®°äººID |
| | | taskPage.getRecords().forEach(task -> { |
| | | if (task.getRegistrantId() != null) { |
| | | userIds.add(task.getRegistrantId()); |
| | | } |
| | | }); |
| | | |
| | | // æ¶éå·¡æ£äººIDï¼å¤ä¸ªID以éå·åéï¼ |
| | | taskPage.getRecords().forEach(task -> { |
| | | task.setDateStr(task.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | if (task.getCreateTime() != null) { |
| | | task.setDateStr(task.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | } |
| | | if (StringUtils.isNotBlank(task.getInspectorIds())) { |
| | | Arrays.stream(task.getInspectorIds().split(",")) |
| | | .filter(StringUtils::isNotBlank) |
| | |
| | | } |
| | | }); |
| | | |
| | | // 4. æ¹éæ¥è¯¢ç¨æ·ä¿¡æ¯ |
| | | Map<Long, String> userNickNameMap = new HashMap<>(); |
| | | if (!userIds.isEmpty()) { |
| | | List<SysUser> users = sysUserMapper.selectUserByIds((new ArrayList<>(userIds))); |
| | | List<SysUser> users = sysUserMapper.selectUserByIds(new ArrayList<>(userIds)); |
| | | users.forEach(user -> userNickNameMap.put(user.getUserId(), user.getNickName())); |
| | | } |
| | | |
| | | // 5. 转æ¢ä¸ºDTO |
| | | Map<Long, String> areaNameMap = deviceAreaMapper.selectBatchIds(taskPage.getRecords().stream() |
| | | .map(TimingTask::getAreaId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList())) |
| | | .stream() |
| | | .collect(Collectors.toMap(DeviceArea::getId, DeviceArea::getAreaName, (left, right) -> left, HashMap::new)); |
| | | |
| | | List<TimingTaskDto> dtoList = taskPage.getRecords().stream().map(task -> { |
| | | TimingTaskDto dto = new TimingTaskDto(); |
| | | // å¤å¶åºæ¬å±æ§ |
| | | BeanUtils.copyProperties(task, dto); |
| | | |
| | | // 设置ç»è®°äººæµç§° |
| | | if (task.getRegistrantId() != null) { |
| | | dto.setRegistrant(userNickNameMap.getOrDefault(task.getRegistrantId(), "æªç¥ç¨æ·")); |
| | | } |
| | | |
| | | // 设置巡æ£äººæµç§°å表 |
| | | dto.setAreaName(areaNameMap.get(task.getAreaId())); |
| | | if (StringUtils.isNotBlank(task.getInspectorIds())) { |
| | | List<String> inspectorNickNames = new ArrayList<>(); |
| | | for (String idStr : task.getInspectorIds().split(",")) { |
| | |
| | | } |
| | | dto.setInspector(inspectorNickNames); |
| | | } |
| | | |
| | | return dto; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | // 6. æå»ºè¿åçå页对象 |
| | | Page<TimingTaskDto> resultPage = new Page<>(taskPage.getCurrent(), taskPage.getSize(), taskPage.getTotal()); |
| | | resultPage.setRecords(dtoList); |
| | | return resultPage; |
| | |
| | | public int addOrEditTimingTask(TimingTaskDto timingTaskDto) throws SchedulerException { |
| | | TimingTask timingTask = new TimingTask(); |
| | | BeanUtils.copyProperties(timingTaskDto, timingTask); |
| | | // 1. è§£æå符串为 LocalDateï¼åªå
å«å¹´ææ¥ï¼ |
| | | prepareTimingTask(timingTask); |
| | | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | LocalDate localDate = LocalDate.now(); |
| | | if(StringUtils.isNotEmpty(timingTaskDto.getDateStr())){ |
| | | if (StringUtils.isNotEmpty(timingTaskDto.getDateStr())) { |
| | | localDate = LocalDate.parse(timingTaskDto.getDateStr(), formatter); |
| | | } |
| | | // 2. è·åå½åç³»ç»ç LocalTimeï¼å
嫿¶åç§ï¼ |
| | | LocalTime currentTime = LocalTime.now(); |
| | | timingTask.setCreateTime(LocalDateTime.of(localDate, currentTime)); |
| | | |
| | | // 3. åå¹¶ LocalDate åå½å LocalTime 为 LocalDateTime |
| | | LocalDateTime localDateTime = LocalDateTime.of(localDate, currentTime); |
| | | timingTask.setCreateTime(localDateTime); |
| | | // 设置å建人信æ¯åé»è®¤å¼ |
| | | if (Objects.isNull(timingTaskDto.getId())) { |
| | | timingTask.setRegistrationDate(LocalDate.now()); |
| | | timingTask.setActive(true); |
| | | |
| | | // 计ç®é¦æ¬¡æ§è¡æ¶é´ |
| | | LocalDateTime firstExecutionTime = calculateFirstExecutionTime(timingTask); |
| | | timingTask.setNextExecutionTime(firstExecutionTime); |
| | | timingTask.setNextExecutionTime(calculateFirstExecutionTime(timingTask)); |
| | | int result = timingTaskMapper.insert(timingTask); |
| | | if (result > 0) { |
| | | // æ°å¢æååæ·»å å°è°åº¦å¨ |
| | | timingTaskScheduler.scheduleTimingTask(timingTask); |
| | | } |
| | | return result; |
| | | } else { |
| | | |
| | | |
| | | int result = timingTaskMapper.updateById(timingTask); |
| | | if (result > 0) { |
| | | // æ´æ°æååéæ°è°åº¦ä»»å¡ |
| | | timingTaskScheduler.rescheduleTimingTask(timingTask); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | int result = timingTaskMapper.updateById(timingTask); |
| | | if (result > 0) { |
| | | timingTaskScheduler.rescheduleTimingTask(timingTask); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private void prepareTimingTask(TimingTask timingTask) { |
| | | Long[] selectedTaskIds = timingTask.getTaskIds(); |
| | | if ((selectedTaskIds == null || selectedTaskIds.length == 0) && timingTask.getTaskId() != null) { |
| | | selectedTaskIds = new Long[]{timingTask.getTaskId().longValue()}; |
| | | } |
| | | if (selectedTaskIds == null || selectedTaskIds.length == 0) { |
| | | timingTask.setTaskIdsStr(null); |
| | | return; |
| | | } |
| | | |
| | | List<Long> deviceIds = Arrays.stream(selectedTaskIds) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (deviceIds.isEmpty()) { |
| | | timingTask.setTaskIdsStr(null); |
| | | return; |
| | | } |
| | | |
| | | List<DeviceLedger> devices = deviceLedgerMapper.selectBatchIds(deviceIds); |
| | | Map<Long, DeviceLedger> deviceMap = devices.stream() |
| | | .collect(Collectors.toMap(DeviceLedger::getId, device -> device, (left, right) -> left, LinkedHashMap::new)); |
| | | |
| | | List<Long> validDeviceIds = deviceIds.stream() |
| | | .filter(deviceMap::containsKey) |
| | | .collect(Collectors.toList()); |
| | | if (validDeviceIds.isEmpty()) { |
| | | throw new IllegalArgumentException("æé设å¤ä¸åå¨"); |
| | | } |
| | | |
| | | timingTask.setTaskIds(validDeviceIds.toArray(new Long[0])); |
| | | timingTask.setTaskIdsStr(validDeviceIds.stream().map(String::valueOf).collect(Collectors.joining(","))); |
| | | timingTask.setTaskId(validDeviceIds.get(0).intValue()); |
| | | if (timingTask.getAreaId() == null) { |
| | | DeviceLedger firstDevice = deviceMap.get(validDeviceIds.get(0)); |
| | | if (firstDevice != null) { |
| | | timingTask.setAreaId(firstDevice.getAreaId()); |
| | | } |
| | | } |
| | | timingTask.setTaskName(validDeviceIds.stream() |
| | | .map(deviceMap::get) |
| | | .filter(Objects::nonNull) |
| | | .map(DeviceLedger::getDeviceName) |
| | | .filter(StringUtils::isNotBlank) |
| | | .collect(Collectors.joining(","))); |
| | | } |
| | | |
| | | public LocalDateTime calculateFirstExecutionTime(TimingTask task) { |
| | | // æ ¹æ®é¢çç±»åå详æ
计ç®é¦æ¬¡æ§è¡æ¶é´ |
| | | String frequencyType = task.getFrequencyType(); |
| | | if ("DAILY".equals(frequencyType)) { |
| | | // å¦ææ¯æ¯å¤©æ§è¡ï¼è®¡ç®ä»å¤©ææå¤©çå
·ä½æ¶é´ |
| | | return calculateDailyFirstExecution(task.getFrequencyDetail()); |
| | | } else if ("WEEKLY".equals(frequencyType)) { |
| | | // å¦ææ¯æ¯å¨æ§è¡ï¼è®¡ç®ä¸å¨çå
·ä½ææå |
| | | return calculateWeeklyFirstExecution(task.getFrequencyDetail()); |
| | | } else if ("MONTHLY".equals(frequencyType)) { |
| | | // å¦ææ¯æ¯ææ§è¡ï¼è®¡ç®ä¸ä¸ªæçå
·ä½æ¥æ |
| | | return calculateMonthlyFirstExecution(task.getFrequencyDetail()); |
| | | } else if ("QUARTERLY".equals(frequencyType)) { |
| | | // èªå®ä¹é¢çï¼å¦æ¯å°æ¶ãæ¯30åéç |
| | | return calculateCustomFirstExecution(task.getFrequencyDetail()); |
| | | } else { |
| | | throw new IllegalArgumentException("䏿¯æçé¢çç±»å: " + task.getFrequencyType()); |
| | |
| | | } |
| | | |
| | | private LocalDateTime calculateDailyFirstExecution(String frequencyDetail) { |
| | | // frequencyDetailå¯è½æ¯å
·ä½æ¶é´ï¼å¦ "14:30" |
| | | LocalTime executionTime = LocalTime.parse(frequencyDetail); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime todayExecution = LocalDateTime.of(now.toLocalDate(), executionTime); |
| | | |
| | | // 妿ä»å¤©çæ¶é´å·²è¿ï¼å宿æå¤©æ§è¡ |
| | | return now.isBefore(todayExecution) ? todayExecution : todayExecution.plusDays(1); |
| | | } |
| | | |
| | | // æ å°ææç®åä¸DayOfWeek |
| | | private static final Map<String, DayOfWeek> WEEK_DAY_MAP = new HashMap<>(); |
| | | |
| | | static { |
| | | WEEK_DAY_MAP.put("MON", DayOfWeek.MONDAY); |
| | | WEEK_DAY_MAP.put("TUE", DayOfWeek.TUESDAY); |
| | |
| | | } |
| | | |
| | | private LocalDateTime calculateWeeklyFirstExecution(String frequencyDetail) { |
| | | // è§£æè¾å
¥åæ° |
| | | String[] parts = frequencyDetail.split(","); |
| | | if (parts.length != 2) { |
| | | throw new IllegalArgumentException("åæ°æ ¼å¼é误ï¼åºä¸º'MON,13:43'æ ¼å¼"); |
| | | throw new IllegalArgumentException("åæ°æ ¼å¼é误ï¼åºä¸º MON,13:43"); |
| | | } |
| | | |
| | | String weekDayStr = parts[0].trim(); |
| | | String timeStr = parts[1].trim(); |
| | | |
| | | // è·å对åºçææå |
| | | DayOfWeek targetDay = WEEK_DAY_MAP.get(weekDayStr); |
| | | if (targetDay == null) { |
| | | throw new IllegalArgumentException("æ æçææç®å: " + weekDayStr); |
| | | throw new IllegalArgumentException("æ æçææ: " + weekDayStr); |
| | | } |
| | | |
| | | // è§£ææ¶é´ |
| | | LocalTime targetTime = LocalTime.parse(timeStr, DateTimeFormatter.ofPattern("HH:mm")); |
| | | |
| | | // è·åå½åæ¶é´ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime targetDateTime = now.with(targetDay).with(targetTime); |
| | | |
| | | // å¦æè®¡ç®åºçæ¶é´å¨å½åæ¶é´ä¹åï¼åå ä¸å¨ |
| | | if (targetDateTime.isBefore(now)) { |
| | | targetDateTime = targetDateTime.plusWeeks(1); |
| | | } |
| | | |
| | | return targetDateTime; |
| | | } |
| | | |
| | | private LocalDateTime calculateMonthlyFirstExecution(String frequencyDetail) { |
| | | // è§£æè¾å
¥åæ° |
| | | String[] parts = frequencyDetail.split(","); |
| | | if (parts.length != 2) { |
| | | throw new IllegalArgumentException("åæ°æ ¼å¼é误ï¼åºä¸º'03,17:00'æ ¼å¼"); |
| | | throw new IllegalArgumentException("åæ°æ ¼å¼é误ï¼åºä¸º 03,17:00"); |
| | | } |
| | | |
| | | String dayStr = parts[0].trim(); |
| | | String timeStr = parts[1].trim(); |
| | | |
| | | // è§£ææ¥æ |
| | | int dayOfMonth; |
| | | try { |
| | | dayOfMonth = Integer.parseInt(dayStr); |
| | |
| | | throw new IllegalArgumentException("æ æçæ¥ææ ¼å¼: " + dayStr, e); |
| | | } |
| | | |
| | | // éªè¯æ¥ææææ§ï¼1-31ä¹é´ï¼ |
| | | if (dayOfMonth < 1 || dayOfMonth > 31) { |
| | | throw new IllegalArgumentException("æ¥æå¿
é¡»å¨1-31ä¹é´: " + dayOfMonth); |
| | | throw new IllegalArgumentException("æ¥æå¿
é¡»å¨ 1-31 ä¹é´: " + dayOfMonth); |
| | | } |
| | | |
| | | // è§£ææ¶é´ |
| | | LocalTime targetTime; |
| | | try { |
| | | targetTime = LocalTime.parse(timeStr, DateTimeFormatter.ofPattern("HH:mm")); |
| | |
| | | throw new IllegalArgumentException("æ æçæ¶é´æ ¼å¼: " + timeStr, e); |
| | | } |
| | | |
| | | // è·åå½åæ¶é´ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime targetDateTime = now.withDayOfMonth(dayOfMonth).with(targetTime); |
| | | |
| | | // æ£æ¥æ¥ææ¯å¦è¢«èªå¨è°æ´ï¼å¦31æ¥å¨å°æä¼è¢«è°æ´ï¼ |
| | | boolean isDateAdjusted = targetDateTime.getDayOfMonth() != dayOfMonth; |
| | | |
| | | // å¦æç®æ æ¶é´å¨å½åæ¶é´ä¹åï¼æè
æ¥æè¢«ç³»ç»èªå¨è°æ´äº |
| | | if (targetDateTime.isBefore(now) || isDateAdjusted) { |
| | | // 计ç®ä¸ä¸ªæçæ¥æ |
| | | LocalDateTime nextMonth = now.plusMonths(1); |
| | | // å°è¯è®¾ç½®ä¸ä¸ªæçç®æ æ¥æ |
| | | LocalDateTime nextMonthTarget = nextMonth.withDayOfMonth(dayOfMonth).with(targetTime); |
| | | |
| | | // 妿ä¸ä¸ªæçæ¥æä¹è¢«è°æ´äºï¼å°±ç¨ä¸ä¸ªæçæåä¸å¤© |
| | | if (nextMonthTarget.getDayOfMonth() != dayOfMonth) { |
| | | // æ£ç¡®è·åä¸ä¸ªæçæåä¸å¤©ï¼ä¿®å¤isLeapYearè°ç¨é®é¢ï¼ |
| | | int lastDayOfMonth = nextMonth.getMonth().length( |
| | | Year.of(nextMonth.getYear()).isLeap() |
| | | ); |
| | | int lastDayOfMonth = nextMonth.getMonth().length(Year.of(nextMonth.getYear()).isLeap()); |
| | | nextMonthTarget = nextMonth.withDayOfMonth(lastDayOfMonth).with(targetTime); |
| | | } |
| | | |
| | | targetDateTime = nextMonthTarget; |
| | | } |
| | | |
| | | return targetDateTime; |
| | | } |
| | | |
| | |
| | | throw new RuntimeException("宿¶ä»»å¡ä¸åå¨ï¼ID: " + taskId); |
| | | } |
| | | |
| | | // æ´æ°æåæ§è¡æ¶é´ä¸ºå½åæ¶é´ |
| | | task.setLastExecutionTime(LocalDateTime.now()); |
| | | |
| | | // 计ç®ä¸æ¬¡æ§è¡æ¶é´ |
| | | LocalDateTime nextExecutionTime = calculateNextExecutionTime( |
| | | task.getFrequencyType(), |
| | | task.getFrequencyDetail(), |
| | | LocalDateTime.now() |
| | | ); |
| | | task.setNextExecutionTime(nextExecutionTime); |
| | | |
| | | // æ´æ°æ°æ®åº |
| | | timingTaskMapper.updateById(task); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ä¸æ¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateNextExecutionTime(String frequencyType, |
| | | String frequencyDetail, |
| | | LocalDateTime currentTime) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯æ¥ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateDailyNextTime(String timeStr, LocalDateTime current) { |
| | | LocalTime executionTime = LocalTime.parse(timeStr); // è§£ææ ¼å¼ "HH:mm" |
| | | LocalTime executionTime = LocalTime.parse(timeStr); |
| | | LocalDateTime nextTime = LocalDateTime.of(current.toLocalDate(), executionTime); |
| | | |
| | | // 妿ä»å¤©çæ¶é´å·²è¿ï¼å宿æå¤© |
| | | return current.isBefore(nextTime) ? nextTime : nextTime.plusDays(1); |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯å¨ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateWeeklyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | String dayOfWeekStr = parts[0]; // å¦ "MON" æ "MON|WED|FRI" |
| | | LocalTime time = LocalTime.parse(parts[1]); // æ¶é´é¨å |
| | | |
| | | // è§£æææå (æ¯æå¤ä¸ªææ) |
| | | String dayOfWeekStr = parts[0]; |
| | | LocalTime time = LocalTime.parse(parts[1]); |
| | | Set<DayOfWeek> targetDays = parseDayOfWeeks(dayOfWeekStr); |
| | | |
| | | // ä»å½åæ¶é´å¼å§æ¾ä¸ä¸ä¸ªç¬¦åæ¡ä»¶çææå |
| | | LocalDateTime nextTime = current; |
| | | while (true) { |
| | | nextTime = nextTime.plusDays(1); |
| | | if (targetDays.contains(nextTime.getDayOfWeek())) { |
| | | return LocalDateTime.of(nextTime.toLocalDate(), time); |
| | | } |
| | | |
| | | // 鲿¢æ é循ç¯(ç论ä¸ä¸ä¼åç) |
| | | if (nextTime.isAfter(current.plusYears(1))) { |
| | | throw new RuntimeException("æ æ³æ¾å°ä¸æ¬¡æ§è¡æ¶é´"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯æä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateMonthlyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | int dayOfMonth = Integer.parseInt(parts[0]); |
| | | LocalTime time = LocalTime.parse(parts[1]); |
| | | |
| | | // ä»ä¸ä¸ªæå¼å§è®¡ç® |
| | | LocalDateTime nextTime = current.plusMonths(1) |
| | | return current.plusMonths(1) |
| | | .withDayOfMonth(Math.min(dayOfMonth, current.plusMonths(1).toLocalDate().lengthOfMonth())) |
| | | .with(time); |
| | | |
| | | return nextTime; |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç®æ¯å£åº¦ä»»å¡ç䏿¬¡æ§è¡æ¶é´ |
| | | */ |
| | | private LocalDateTime calculateQuarterlyNextTime(String detail, LocalDateTime current) { |
| | | String[] parts = detail.split(","); |
| | | int quarterMonth = Integer.parseInt(parts[0]); // 1=第1个æï¼2=第2个æï¼3=第3个æ |
| | | int quarterMonth = Integer.parseInt(parts[0]); |
| | | int dayOfMonth = Integer.parseInt(parts[1]); |
| | | LocalTime time = LocalTime.parse(parts[2]); |
| | | |
| | | // 计ç®å½åå£åº¦ |
| | | int currentQuarter = (current.getMonthValue() - 1) / 3 + 1; |
| | | int currentMonthInQuarter = (current.getMonthValue() - 1) % 3 + 1; |
| | | |
| | | YearMonth targetYearMonth; |
| | | if (currentMonthInQuarter < quarterMonth) { |
| | | // æ¬å£åº¦å
è¿ææ§è¡æºä¼ |
| | | targetYearMonth = YearMonth.from(current) |
| | | .plusMonths(quarterMonth - currentMonthInQuarter); |
| | | targetYearMonth = YearMonth.from(current).plusMonths(quarterMonth - currentMonthInQuarter); |
| | | } else { |
| | | // éè¦å°ä¸ä¸ªå£åº¦ |
| | | targetYearMonth = YearMonth.from(current) |
| | | .plusMonths(3 - currentMonthInQuarter + quarterMonth); |
| | | targetYearMonth = YearMonth.from(current).plusMonths(3 - currentMonthInQuarter + quarterMonth); |
| | | } |
| | | |
| | | // å¤çææ«æ¥æ |
| | | int adjustedDay = Math.min(dayOfMonth, targetYearMonth.lengthOfMonth()); |
| | | |
| | | return LocalDateTime.of( |
| | | targetYearMonth.getYear(), |
| | | targetYearMonth.getMonthValue(), |
| | |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * è§£æææå å符串 |
| | | */ |
| | | private Set<DayOfWeek> parseDayOfWeeks(String dayOfWeekStr) { |
| | | Set<DayOfWeek> days = new HashSet<>(); |
| | | String[] dayStrs = dayOfWeekStr.split("\\|"); |
| | | |
| | | for (String dayStr : dayStrs) { |
| | | switch (dayStr) { |
| | | case "MON": days.add(DayOfWeek.MONDAY); break; |
| | | case "TUE": days.add(DayOfWeek.TUESDAY); break; |
| | | case "WED": days.add(DayOfWeek.WEDNESDAY); break; |
| | | case "THU": days.add(DayOfWeek.THURSDAY); break; |
| | | case "FRI": days.add(DayOfWeek.FRIDAY); break; |
| | | case "SAT": days.add(DayOfWeek.SATURDAY); break; |
| | | case "SUN": days.add(DayOfWeek.SUNDAY); break; |
| | | default: throw new IllegalArgumentException("æ æçææå : " + dayStr); |
| | | case "MON": |
| | | days.add(DayOfWeek.MONDAY); |
| | | break; |
| | | case "TUE": |
| | | days.add(DayOfWeek.TUESDAY); |
| | | break; |
| | | case "WED": |
| | | days.add(DayOfWeek.WEDNESDAY); |
| | | break; |
| | | case "THU": |
| | | days.add(DayOfWeek.THURSDAY); |
| | | break; |
| | | case "FRI": |
| | | days.add(DayOfWeek.FRIDAY); |
| | | break; |
| | | case "SAT": |
| | | days.add(DayOfWeek.SATURDAY); |
| | | break; |
| | | case "SUN": |
| | | days.add(DayOfWeek.SUNDAY); |
| | | break; |
| | | default: |
| | | throw new IllegalArgumentException("æ æçææ: " + dayStr); |
| | | } |
| | | } |
| | | |
| | | return days; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public int delByIds(Long[] ids) { |
| | | int i = timingTaskMapper.deleteBatchIds(Arrays.asList(ids)); |
| | | if(i > 0){ |
| | | if (i > 0) { |
| | | for (Long id : ids) { |
| | | timingTaskScheduler.unscheduleTimingTask(id); |
| | | } |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.ruoyi.device.mapper.DeviceAreaMapper"> |
| | | |
| | | <select id="queryPage" resultType="com.ruoyi.device.pojo.DeviceArea"> |
| | | select |
| | | da.*, |
| | | parent.area_name as parentName |
| | | from device_area da |
| | | left join device_area parent on da.parent_id = parent.id |
| | | <where> |
| | | <if test="deviceArea.areaName != null and deviceArea.areaName != ''"> |
| | | and da.area_name like concat('%', #{deviceArea.areaName}, '%') |
| | | </if> |
| | | <if test="deviceArea.parentId != null"> |
| | | and da.parent_id = #{deviceArea.parentId} |
| | | </if> |
| | | </where> |
| | | order by da.parent_id asc, da.sort asc, da.id asc |
| | | </select> |
| | | </mapper> |
| | |
| | | |
| | | <select id="queryPage" resultType="com.ruoyi.device.dto.DeviceLedgerDto"> |
| | | SELECT |
| | | dl.id, |
| | | dl.device_name, |
| | | dl.device_model, |
| | | dl.supplier_name, |
| | | dl.device_brand, |
| | | dl.storage_location, |
| | | dl.unit, |
| | | dl.number, |
| | | dl.status, |
| | | dl.plan_runtime_time, |
| | | dl.start_runtime_time, |
| | | dl.end_runtime_time, |
| | | dl.runtime_duration, |
| | | dl.tax_including_price_unit, |
| | | dl.tax_including_price_total, |
| | | dl.tax_rate, |
| | | dl.un_tax_including_price_total, |
| | | dl.create_time, |
| | | dl.update_time , |
| | | su.nick_name AS createUser, |
| | | dl.update_user, |
| | | dl.tenant_id, |
| | | dl.is_depr, |
| | | dl.annual_depreciation_amount, |
| | | dl.type |
| | | dl.id, |
| | | dl.device_name, |
| | | dl.device_model, |
| | | dl.device_brand, |
| | | dl.storage_location, |
| | | dl.area_id, |
| | | da.area_name, |
| | | dl.supplier_name, |
| | | dl.unit, |
| | | dl.number, |
| | | dl.status, |
| | | dl.plan_runtime_time, |
| | | dl.start_runtime_time, |
| | | dl.end_runtime_time, |
| | | dl.runtime_duration, |
| | | dl.tax_including_price_unit, |
| | | dl.tax_including_price_total, |
| | | dl.tax_rate, |
| | | dl.un_tax_including_price_total, |
| | | dl.create_time, |
| | | dl.update_time, |
| | | su.nick_name AS createUser, |
| | | dl.update_user, |
| | | dl.tenant_id, |
| | | dl.is_depr, |
| | | dl.annual_depreciation_amount, |
| | | dl.type |
| | | FROM device_ledger dl |
| | | left join sys_user su on dl.create_user = su.user_id |
| | | LEFT JOIN sys_user su ON dl.create_user = su.user_id |
| | | LEFT JOIN device_area da ON dl.area_id = da.id |
| | | <where> |
| | | <!-- 设å¤åç§° --> |
| | | <if test="deviceLedger.deviceName != null and deviceLedger.deviceName != ''"> |
| | | AND device_name LIKE CONCAT('%', #{deviceLedger.deviceName}, '%') |
| | | AND dl.device_name LIKE CONCAT('%', #{deviceLedger.deviceName}, '%') |
| | | </if> |
| | | |
| | | <!-- è§æ ¼åå· --> |
| | | <if test="deviceLedger.deviceModel != null and deviceLedger.deviceModel != ''"> |
| | | AND device_model LIKE CONCAT('%', #{deviceLedger.deviceModel}, '%') |
| | | AND dl.device_model LIKE CONCAT('%', #{deviceLedger.deviceModel}, '%') |
| | | </if> |
| | | |
| | | <!-- ä¾åºååç§° --> |
| | | <if test="deviceLedger.supplierName != null and deviceLedger.supplierName != ''"> |
| | | AND supplier_name LIKE CONCAT('%', #{deviceLedger.supplierName}, '%') |
| | | AND dl.supplier_name LIKE CONCAT('%', #{deviceLedger.supplierName}, '%') |
| | | </if> |
| | | |
| | | <!-- åä½ --> |
| | | <if test="deviceLedger.areaId != null"> |
| | | AND dl.area_id = #{deviceLedger.areaId} |
| | | </if> |
| | | <if test="deviceLedger.areaName != null and deviceLedger.areaName != ''"> |
| | | AND da.area_name LIKE CONCAT('%', #{deviceLedger.areaName}, '%') |
| | | </if> |
| | | <if test="deviceLedger.unit != null and deviceLedger.unit != ''"> |
| | | AND unit = #{deviceLedger.unit} |
| | | AND dl.unit = #{deviceLedger.unit} |
| | | </if> |
| | | |
| | | <!-- å½å
¥äºº --> |
| | | <if test="deviceLedger.createUser != null and deviceLedger.createUser != ''"> |
| | | AND create_user LIKE CONCAT('%', #{deviceLedger.createUser}, '%') |
| | | AND dl.create_user LIKE CONCAT('%', #{deviceLedger.createUser}, '%') |
| | | </if> |
| | | |
| | | <!-- æ´æ°äºº --> |
| | | <if test="deviceLedger.updateUser != null and deviceLedger.updateUser != ''"> |
| | | AND update_user LIKE CONCAT('%', #{deviceLedger.updateUser}, '%') |
| | | AND dl.update_user LIKE CONCAT('%', #{deviceLedger.updateUser}, '%') |
| | | </if> |
| | | |
| | | <if test="deviceLedger.entryDateStart != null and deviceLedger.entryDateStart != '' "> |
| | | AND dl.create_time >= DATE_FORMAT(#{deviceLedger.entryDateStart},'%Y-%m-%d') |
| | | </if> |
| | | <if test="deviceLedger.entryDateEnd != null and deviceLedger.entryDateEnd != '' "> |
| | | AND dl.create_time <= DATE_FORMAT(#{deviceLedger.entryDateEnd},'%Y-%m-%d') |
| | | </if> |
| | | |
| | | <!-- ç§æ·ID --> |
| | | <if test="deviceLedger.tenantId != null"> |
| | | AND tenant_id = #{deviceLedger.tenantId} |
| | | AND dl.tenant_id = #{deviceLedger.tenantId} |
| | | </if> |
| | | </where> |
| | | ORDER BY create_time DESC |
| | | ORDER BY dl.create_time DESC |
| | | </select> |
| | | |
| | | <select id="deviceLedgerExportList" resultType="com.ruoyi.device.execl.DeviceLedgerExeclDto"> |
| | | |
| | | </select> |
| | | |
| | | <select id="selectById1" resultType="com.ruoyi.device.pojo.DeviceLedger"> |
| | | select * |
| | | from device_ledger |
| | | where id = #{id} |
| | | </select> |
| | | |
| | | <select id="getDeviceTypeDistributionByYear" |
| | | resultType="com.ruoyi.account.dto.DeviceTypeDetail" |
| | | parameterType="java.lang.Integer"> |
| | |
| | | AND type IS NOT NULL |
| | | GROUP BY type |
| | | </select> |
| | | |
| | | |
| | | </mapper> |
| | |
| | | <select id="queryPage" resultType="com.ruoyi.device.dto.DeviceMaintenanceDto"> |
| | | select dm.id, |
| | | dm.device_ledger_id, |
| | | dm.area_id, |
| | | dm.maintenance_plan_time, |
| | | dm.maintenance_actually_time, |
| | | dm.maintenance_result, |
| | |
| | | dm.maintenance_actually_name, |
| | | dl.device_name, |
| | | dl.device_model, |
| | | da.area_name, |
| | | su.nick_name as create_user_name |
| | | from device_maintenance dm |
| | | left join device_ledger dl on dm.device_ledger_id = dl.id |
| | | left join device_area da on dm.area_id = da.id |
| | | left join sys_user su on dm.create_user = su.user_id |
| | | <where> |
| | | 1 = 1 |
| | |
| | | <select id="detailById" resultType="com.ruoyi.device.dto.DeviceMaintenanceDto"> |
| | | select dm.id, |
| | | dm.device_ledger_id, |
| | | dm.area_id, |
| | | dm.maintenance_plan_time, |
| | | dm.maintenance_actually_time, |
| | | dm.maintenance_result, |
| | |
| | | dm.maintenance_actually_name, |
| | | dl.device_name, |
| | | dl.device_model, |
| | | da.area_name, |
| | | su.user_name as create_user_name |
| | | from device_maintenance dm |
| | | left join device_ledger dl on dm.device_ledger_id = dl.id |
| | | left join device_area da on dm.area_id = da.id |
| | | left join sys_user su on dm.create_user = su.user_id |
| | | where dm.id = #{id} |
| | | </select> |
| | |
| | | <select id="queryPage" resultType="com.ruoyi.device.dto.DeviceRepairDto"> |
| | | select dr.id, |
| | | dr.device_ledger_id, |
| | | dr.area_id, |
| | | dr.repair_time, |
| | | dr.repair_name, |
| | | dr.remark, |
| | |
| | | dr.update_user, |
| | | dr.tenant_id, |
| | | dl.device_name, |
| | | dl.device_model |
| | | dl.device_model, |
| | | da.area_name |
| | | from device_repair dr |
| | | left join device_ledger dl on dr.device_ledger_id = dl.id |
| | | left join device_area da on dr.area_id = da.id |
| | | <where> |
| | | 1 = 1 |
| | | <if test="deviceRepairDto.deviceName != null"> |
| | |
| | | <select id="detailById" resultType="com.ruoyi.device.dto.DeviceRepairDto"> |
| | | select dr.id, |
| | | dr.device_ledger_id, |
| | | dr.area_id, |
| | | dr.repair_time, |
| | | dr.repair_name, |
| | | dr.remark, |
| | |
| | | dr.update_user, |
| | | dr.tenant_id, |
| | | dl.device_name, |
| | | dl.device_model |
| | | dl.device_model, |
| | | da.area_name |
| | | from device_repair dr |
| | | left join device_ledger dl on dr.device_ledger_id = dl.id |
| | | left join device_area da on dr.area_id = da.id |
| | | where dr.id = #{id} |
| | | </select> |
| | | |
| | |
| | | next_date, |
| | | record_date, |
| | | CASE |
| | | WHEN most_date >= DATE_FORMAT(now(),'%Y-%m-%d') THEN 1 |
| | | WHEN DATE_ADD(most_date, INTERVAL IFNULL(cycle, 0) DAY) >= CURDATE() THEN 1 |
| | | ELSE 2 |
| | | END AS status, |
| | | create_user, |
| | |
| | | <if test="req.status != null"> |
| | | <choose> |
| | | <when test="req.status == 1"> |
| | | AND most_date >= DATE_FORMAT(now(),'%Y-%m-%d') |
| | | AND DATE_ADD(most_date, INTERVAL IFNULL(cycle, 0) DAY) >= CURDATE() |
| | | </when> |
| | | <when test="req.status == 2"> |
| | | AND most_date < DATE_FORMAT(now(),'%Y-%m-%d') |
| | | AND DATE_ADD(most_date, INTERVAL IFNULL(cycle, 0) DAY) < CURDATE() |
| | | </when> |
| | | </choose> |
| | | </if> |