parent
ae6f643fd1
commit
65b83500f1
44 changed files with 2483 additions and 11 deletions
@ -0,0 +1,155 @@ |
||||
package org.springblade.lims.entry; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springframework.data.annotation.Id; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@Data |
||||
@TableName("t_maintain_plan") |
||||
public class MaintainPlan extends BaseEntity implements Serializable { |
||||
|
||||
/** |
||||
* 业务主键 |
||||
*/ |
||||
@Id |
||||
private Long id; |
||||
|
||||
/** |
||||
* 计划单据 |
||||
*/ |
||||
private String code; |
||||
|
||||
/** |
||||
* 计划名称 |
||||
*/ |
||||
private String name; |
||||
|
||||
|
||||
/** |
||||
* 保养设备id |
||||
*/ |
||||
private String assetId; |
||||
|
||||
/** |
||||
* 保养设备 |
||||
*/ |
||||
private String assetCode; |
||||
|
||||
/** |
||||
* 设备名称 |
||||
*/ |
||||
private String assetName; |
||||
|
||||
/** |
||||
* 设备型号 |
||||
*/ |
||||
private String assetModel; |
||||
|
||||
/** |
||||
* 设备序列 |
||||
*/ |
||||
private String assetSn; |
||||
|
||||
/** |
||||
* 保养班组 |
||||
*/ |
||||
private String groupId; |
||||
|
||||
/** |
||||
* 保养类型 |
||||
*/ |
||||
private String maintainType; |
||||
|
||||
/** |
||||
* 循环方式 |
||||
*/ |
||||
private String cycleMethod; |
||||
|
||||
/** |
||||
* 保养周期 |
||||
*/ |
||||
private String actionCycleType; |
||||
|
||||
/** |
||||
* 保养周期间隔 |
||||
*/ |
||||
private String actionCycleTime; |
||||
|
||||
/** |
||||
* 开始时间 |
||||
*/ |
||||
private String startTime; |
||||
|
||||
|
||||
/** |
||||
* 结束时间 |
||||
*/ |
||||
private String endTime; |
||||
|
||||
/** |
||||
* 预计工时 |
||||
*/ |
||||
private Double totalCost; |
||||
|
||||
/** |
||||
* 超时时间 |
||||
*/ |
||||
private Double timeout; |
||||
|
||||
/** |
||||
* 方案说明 |
||||
*/ |
||||
private String info; |
||||
|
||||
/** |
||||
* 备注 |
||||
*/ |
||||
private String notes; |
||||
|
||||
/** |
||||
* 制单人 |
||||
*/ |
||||
private String originatorId; |
||||
|
||||
/** |
||||
* 租户 |
||||
*/ |
||||
private String tenantId; |
||||
|
||||
/** |
||||
* 上次执行 |
||||
*/ |
||||
private String lastTime; |
||||
|
||||
/** |
||||
* 下次执行 |
||||
*/ |
||||
private String nextTime; |
||||
|
||||
/** |
||||
* 保养项目列表 |
||||
*/ |
||||
@TableField(exist = false) |
||||
private List<MaintainProject> projectList; |
||||
|
||||
|
||||
/** |
||||
* 保养项目数 |
||||
*/ |
||||
@TableField(exist = false) |
||||
private Integer projectCount; |
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
package org.springblade.lims.entry; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springframework.data.annotation.Id; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@Data |
||||
@TableName("t_maintain_plan_project") |
||||
public class MaintainPlanProject extends BaseEntity implements Serializable { |
||||
|
||||
/** |
||||
* 业务主键 |
||||
*/ |
||||
@Id |
||||
private Long id; |
||||
|
||||
/** |
||||
* 计划id |
||||
*/ |
||||
private String planId; |
||||
|
||||
/** |
||||
* 项目id |
||||
*/ |
||||
private String projectId; |
||||
|
||||
/** |
||||
* 租户 |
||||
*/ |
||||
private String tenantId; |
||||
|
||||
} |
||||
@ -0,0 +1,76 @@ |
||||
package org.springblade.lims.entry; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springframework.data.annotation.Id; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@Data |
||||
@TableName("t_maintain_project") |
||||
public class MaintainProject extends BaseEntity implements Serializable { |
||||
|
||||
/** |
||||
* 业务主键 |
||||
*/ |
||||
@Id |
||||
private Long id; |
||||
|
||||
/** |
||||
* 计划单据 |
||||
*/ |
||||
private String code; |
||||
|
||||
/** |
||||
* 计划名称 |
||||
*/ |
||||
private String name; |
||||
|
||||
|
||||
/** |
||||
* 保养内容 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 保养类型 |
||||
*/ |
||||
private String maintainType; |
||||
|
||||
/** |
||||
* 标准工时 |
||||
*/ |
||||
private Double baseCost; |
||||
|
||||
/** |
||||
* 保养周期 |
||||
*/ |
||||
private String actionCycleId; |
||||
|
||||
/** |
||||
* 保养手册 |
||||
*/ |
||||
private String attach; |
||||
|
||||
/** |
||||
* 保养手册名称 |
||||
*/ |
||||
private String attachName; |
||||
|
||||
/** |
||||
* 备注 |
||||
*/ |
||||
private String notes; |
||||
|
||||
/** |
||||
* 租户 |
||||
*/ |
||||
private String tenantId; |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,64 @@ |
||||
package org.springblade.lims.entry; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springframework.data.annotation.Id; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@Data |
||||
@TableName("t_maintain_record") |
||||
public class MaintainRecord extends BaseEntity implements Serializable { |
||||
|
||||
/** |
||||
* 业务主键 |
||||
*/ |
||||
@Id |
||||
private Long id; |
||||
|
||||
/** |
||||
* 单据 |
||||
*/ |
||||
private String businessCode; |
||||
|
||||
/** |
||||
* 设备 |
||||
*/ |
||||
private String assetId; |
||||
|
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 操作日期 |
||||
*/ |
||||
@DateTimeFormat( |
||||
pattern = "yyyy-MM-dd hh:mm:ss" |
||||
) |
||||
@JsonFormat( |
||||
pattern = "yyyy-MM-dd hh:mm:ss" |
||||
) |
||||
private Date rcdTime; |
||||
|
||||
/** |
||||
* 操作人员 |
||||
*/ |
||||
private String operUserId; |
||||
|
||||
/** |
||||
* 操作人员 |
||||
*/ |
||||
private String operUserName; |
||||
|
||||
} |
||||
@ -0,0 +1,192 @@ |
||||
package org.springblade.lims.entry; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springframework.data.annotation.Id; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@Data |
||||
@TableName("t_maintain_task") |
||||
public class MaintainTask extends BaseEntity implements Serializable { |
||||
|
||||
/** |
||||
* 业务主键 |
||||
*/ |
||||
@Id |
||||
private Long id; |
||||
|
||||
/** |
||||
* 任务单据 |
||||
*/ |
||||
private String businessCode; |
||||
|
||||
/** |
||||
* 计划名称 |
||||
*/ |
||||
private String name; |
||||
|
||||
/** |
||||
* 方案 |
||||
*/ |
||||
private String planId; |
||||
|
||||
/** |
||||
* 保养班组 |
||||
*/ |
||||
private String groupId; |
||||
|
||||
/** |
||||
* 保养类型 |
||||
*/ |
||||
private String maintainType; |
||||
|
||||
/** |
||||
* 保养设备id |
||||
*/ |
||||
private String assetId; |
||||
|
||||
/** |
||||
* 保养设备 |
||||
*/ |
||||
private String assetCode; |
||||
|
||||
/** |
||||
* 设备名称 |
||||
*/ |
||||
private String assetName; |
||||
|
||||
/** |
||||
* 设备型号 |
||||
*/ |
||||
private String assetModel; |
||||
|
||||
/** |
||||
* 设备状态 |
||||
*/ |
||||
private String assetStatus; |
||||
|
||||
/** |
||||
* 设备序列 |
||||
*/ |
||||
private String assetSn; |
||||
|
||||
/** |
||||
* 设备位置 |
||||
*/ |
||||
private String assetPos; |
||||
|
||||
|
||||
/** |
||||
* 保养结果 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 执行人 |
||||
*/ |
||||
private String executorId; |
||||
|
||||
/** |
||||
* 应开始时间 |
||||
*/ |
||||
@DateTimeFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
@JsonFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
private Date planStartTime; |
||||
|
||||
/** |
||||
* 实际开始 |
||||
*/ |
||||
@DateTimeFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
@JsonFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
private Date actStartTime; |
||||
|
||||
/** |
||||
* 实际完成 |
||||
*/ |
||||
@DateTimeFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
@JsonFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
private Date actFinishTime; |
||||
|
||||
/** |
||||
* 超时时间 |
||||
*/ |
||||
private Double timeout; |
||||
|
||||
/** |
||||
* 预计工时 |
||||
*/ |
||||
private Double totalCost; |
||||
|
||||
/** |
||||
* 实际工时 |
||||
*/ |
||||
private Double actTotalCost; |
||||
|
||||
/** |
||||
* 费用 |
||||
*/ |
||||
private Double cost; |
||||
|
||||
/** |
||||
* 逾期 |
||||
*/ |
||||
private String overdue; |
||||
|
||||
/** |
||||
* 结果 |
||||
*/ |
||||
private String result; |
||||
|
||||
/** |
||||
* 备注 |
||||
*/ |
||||
private String notes; |
||||
|
||||
/** |
||||
* 制单人 |
||||
*/ |
||||
private String originatorId; |
||||
|
||||
/** |
||||
* 租户 |
||||
*/ |
||||
private String tenantId; |
||||
|
||||
@TableField(exist = false) |
||||
private String actStartTimeBegin; |
||||
|
||||
@TableField(exist = false) |
||||
private String actStartTimeEnd; |
||||
|
||||
@TableField(exist = false) |
||||
private Integer projectCount; |
||||
|
||||
@TableField(exist = false) |
||||
private Integer unProjectCount; |
||||
|
||||
@TableField(exist = false) |
||||
private List<MaintainProject> projectList; |
||||
} |
||||
@ -0,0 +1,126 @@ |
||||
package org.springblade.lims.entry; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springframework.data.annotation.Id; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@Data |
||||
@TableName("t_maintain_task_project") |
||||
public class MaintainTaskProject extends BaseEntity implements Serializable { |
||||
|
||||
/** |
||||
* 业务主键 |
||||
*/ |
||||
@Id |
||||
private Long id; |
||||
|
||||
/** |
||||
* 项目 |
||||
*/ |
||||
private String projectId; |
||||
|
||||
/** |
||||
* 任务 |
||||
*/ |
||||
private String taskId; |
||||
|
||||
/** |
||||
* 保养结果 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 标准工时 |
||||
*/ |
||||
private Double baseCost; |
||||
|
||||
/** |
||||
* 开始时间 |
||||
*/ |
||||
@DateTimeFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
@JsonFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
private Date startTime; |
||||
|
||||
/** |
||||
* 结束时间 |
||||
*/ |
||||
@DateTimeFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
@JsonFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
private Date endTime; |
||||
|
||||
/** |
||||
* 操作人 |
||||
*/ |
||||
private String operUserId; |
||||
|
||||
/** |
||||
* 操作时间 |
||||
*/ |
||||
@DateTimeFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
@JsonFormat( |
||||
pattern = "yyyy-MM-dd" |
||||
) |
||||
private Date operTime; |
||||
|
||||
|
||||
/** |
||||
* 项目编号 |
||||
*/ |
||||
private String projectCode; |
||||
|
||||
/** |
||||
* 项目名称 |
||||
*/ |
||||
private String projectName; |
||||
|
||||
/** |
||||
* 保养类型 |
||||
*/ |
||||
private String projectMaintainType; |
||||
|
||||
/** |
||||
* 标准工时 |
||||
*/ |
||||
private Double projectBaseCost; |
||||
|
||||
/** |
||||
* 保养手册 |
||||
*/ |
||||
private String projectAttach; |
||||
|
||||
/** |
||||
* 保养手册名称 |
||||
*/ |
||||
private String projectAttachName; |
||||
|
||||
/** |
||||
* 项目备注 |
||||
*/ |
||||
private String projectNotes; |
||||
|
||||
/** |
||||
* 租户 |
||||
*/ |
||||
private String tenantId; |
||||
|
||||
} |
||||
@ -0,0 +1,86 @@ |
||||
|
||||
package org.springblade.lims.controller; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.lims.entry.MaintainPlan; |
||||
import org.springblade.lims.service.IMaintainPlanService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Date; |
||||
|
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/maintainPlan") |
||||
@Api(value = "", tags = "") |
||||
public class MaintainPlanController extends BladeController { |
||||
|
||||
private final IMaintainPlanService service; |
||||
|
||||
@GetMapping("/page") |
||||
public R<Object> page(MaintainPlan entry, Query query) { |
||||
return R.data(service.findPage(entry, query)); |
||||
} |
||||
|
||||
/** |
||||
* 保存申请单 |
||||
*/ |
||||
@PostMapping("/savePlan") |
||||
@ApiOperation(value = "保存申请单", notes = "保存申请单") |
||||
public R savePlan(@RequestBody MaintainPlan entry) { |
||||
return R.data(service.savePlan(entry)); |
||||
} |
||||
|
||||
/** |
||||
* 根据id查询信息 |
||||
*/ |
||||
@GetMapping("/getById") |
||||
@ApiOperation(value = "根据id查询信息", notes = "根据id查询信息") |
||||
public R getById(String id) { |
||||
return R.data(service.findById(id)); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 删除 |
||||
*/ |
||||
@GetMapping("/deleteById") |
||||
@ApiOperation(value = "逻辑删除", notes = "传入id") |
||||
public R deleteById(@ApiParam(value = "主键集合", required = true) @RequestParam String id) { |
||||
return R.status(service.deleteLogic(Func.toLongList(id))); |
||||
} |
||||
|
||||
/** |
||||
* 启动、停用 |
||||
*/ |
||||
@PostMapping("/update") |
||||
@ApiOperation(value = "更新", notes = "更新") |
||||
public R update(@RequestBody MaintainPlan entry) { |
||||
entry.setUpdateTime(new Date()); |
||||
entry.setUpdateUser(AuthUtil.getUserId()); |
||||
return R.status(service.updateById(entry)); |
||||
} |
||||
|
||||
/** |
||||
* 根据id查询信息 |
||||
*/ |
||||
@GetMapping("/createTask") |
||||
@ApiOperation(value = "创建任务", notes = "创建任务") |
||||
public R createTask(String id) { |
||||
return service.createTask(id); |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,105 @@ |
||||
|
||||
package org.springblade.lims.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.SneakyThrows; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Charsets; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.IoUtil; |
||||
import org.springblade.lims.entry.MaintainProject; |
||||
import org.springblade.lims.service.IMaintainProjectService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.servlet.ServletOutputStream; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.validation.Valid; |
||||
import javax.validation.constraints.NotNull; |
||||
import java.io.InputStream; |
||||
import java.net.URLEncoder; |
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/maintainProject") |
||||
@Api(value = "", tags = "") |
||||
public class MaintainProjectController extends BladeController { |
||||
|
||||
private final IMaintainProjectService service; |
||||
private final HttpServletResponse response; |
||||
|
||||
@GetMapping("/page") |
||||
public R<Object> page(MaintainProject entry, Query query) { |
||||
return R.data(service.findPage(entry, query)); |
||||
} |
||||
|
||||
/** |
||||
* 保存申请单 |
||||
*/ |
||||
@PostMapping("/saveProject") |
||||
@ApiOperation(value = "保存申请单", notes = "保存申请单") |
||||
public R saveProject(@RequestBody MaintainProject entry) { |
||||
return R.data(service.saveProject(entry)); |
||||
} |
||||
|
||||
/** |
||||
* 根据id查询信息 |
||||
*/ |
||||
@GetMapping("/getById") |
||||
@ApiOperation(value = "根据id查询信息", notes = "根据id查询信息") |
||||
public R getById(String id) { |
||||
return R.data(service.findById(id)); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 删除 |
||||
*/ |
||||
@GetMapping("/deleteById") |
||||
@ApiOperation(value = "逻辑删除", notes = "传入id") |
||||
public R deleteById(@ApiParam(value = "主键集合", required = true) @RequestParam String id) { |
||||
return R.status(service.deleteLogic(Func.toLongList(id))); |
||||
} |
||||
|
||||
/** |
||||
* 上传文件 |
||||
*/ |
||||
@PostMapping("/uploadFile") |
||||
public R<Map<String,String>> uploadFile(@RequestParam MultipartFile file) { |
||||
return R.data(service.uploadFile(file)); |
||||
} |
||||
|
||||
@SneakyThrows |
||||
@GetMapping("/download/{id}") |
||||
@ApiOperationSupport(order = 0) |
||||
@ApiOperation(value = "下载文件", notes = "下载文件") |
||||
public void download(@ApiParam(value = "下载的文件id", required = true) @Valid @NotNull @PathVariable("id") Long id) { |
||||
MaintainProject entry = service.getById(id); |
||||
String fileName = entry.getAttachName(); |
||||
// 查询
|
||||
InputStream inputStream = service.getInputStreamById(id); |
||||
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
||||
response.setCharacterEncoding(Charsets.UTF_8.name()); |
||||
if (fileName != null) { |
||||
fileName = URLEncoder.encode(fileName, Charsets.UTF_8.name()); |
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName); |
||||
} |
||||
ServletOutputStream outputStream = response.getOutputStream(); |
||||
IoUtil.copy(inputStream, outputStream); |
||||
IoUtil.closeQuietly(inputStream); |
||||
IoUtil.closeQuietly(outputStream); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,35 @@ |
||||
|
||||
package org.springblade.lims.controller; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.lims.entry.MaintainRecord; |
||||
import org.springblade.lims.service.IMaintainRecordService; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/maintainRecord") |
||||
@Api(value = "", tags = "") |
||||
public class MaintainRecordController extends BladeController { |
||||
|
||||
private final IMaintainRecordService service; |
||||
|
||||
@GetMapping("/page") |
||||
public R<Object> page(MaintainRecord entry, Query query) { |
||||
return R.data(service.findPage(entry, query)); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,84 @@ |
||||
|
||||
package org.springblade.lims.controller; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.annotations.ApiParam; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.lims.entry.MaintainTask; |
||||
import org.springblade.lims.service.IMaintainTaskService; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/maintainTask") |
||||
@Api(value = "", tags = "") |
||||
public class MaintainTaskController extends BladeController { |
||||
|
||||
private final IMaintainTaskService service; |
||||
|
||||
@GetMapping("/page") |
||||
public R<Object> page(MaintainTask entry, Query query) { |
||||
return R.data(service.findPage(entry, query)); |
||||
} |
||||
|
||||
/** |
||||
* 保存申请单 |
||||
*/ |
||||
@PostMapping("/saveTask") |
||||
@ApiOperation(value = "保存申请单", notes = "保存申请单") |
||||
public R saveTask(@RequestBody MaintainTask entry) { |
||||
return R.data(service.saveTask(entry)); |
||||
} |
||||
|
||||
/** |
||||
* 根据id查询信息 |
||||
*/ |
||||
@GetMapping("/getById") |
||||
@ApiOperation(value = "根据id查询信息", notes = "根据id查询信息") |
||||
public R getById(String id) { |
||||
return R.data(service.findById(id)); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 删除 |
||||
*/ |
||||
@GetMapping("/deleteById") |
||||
@ApiOperation(value = "逻辑删除", notes = "传入id") |
||||
public R deleteById(@ApiParam(value = "主键集合", required = true) @RequestParam String id) { |
||||
return R.status(service.deleteById(id)); |
||||
} |
||||
|
||||
/** |
||||
* 完成保养任务 |
||||
*/ |
||||
@GetMapping("/finish") |
||||
@ApiOperation(value = "完成保养任务", notes = "完成保养任务") |
||||
public R finish(String id) { |
||||
return service.finish(id); |
||||
} |
||||
|
||||
/** |
||||
* 取消保养任务 |
||||
*/ |
||||
@GetMapping("/cancel") |
||||
@ApiOperation(value = "完成保养任务", notes = "完成保养任务") |
||||
public R cancel(String id) { |
||||
MaintainTask task = service.getById(id); |
||||
task.setStatus(3); |
||||
return R.data(service.updateById(task)); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
|
||||
package org.springblade.lims.controller; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.lims.entry.MaintainTask; |
||||
import org.springblade.lims.entry.MaintainTaskProject; |
||||
import org.springblade.lims.service.IMaintainTaskProjectService; |
||||
import org.springblade.lims.service.IMaintainTaskService; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.Date; |
||||
|
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/maintainTaskProject") |
||||
@Api(value = "", tags = "") |
||||
public class MaintainTaskProjectController extends BladeController { |
||||
|
||||
private final IMaintainTaskProjectService service; |
||||
private final IMaintainTaskService maintainTaskService; |
||||
|
||||
|
||||
/** |
||||
* 更新 |
||||
*/ |
||||
@GetMapping("/updateStatus") |
||||
@ApiOperation(value = "更新", notes = "更新") |
||||
public R updateStatus(String id) { |
||||
MaintainTaskProject entry = service.getById(id); |
||||
//更新保养任务为保养中
|
||||
MaintainTask task = maintainTaskService.getById(entry.getTaskId()); |
||||
task.setStatus(1); |
||||
task.setUpdateTime(new Date()); |
||||
task.setUpdateUser(AuthUtil.getUserId()); |
||||
maintainTaskService.updateById(task); |
||||
//更新保养项目状态
|
||||
entry.setStatus(1); |
||||
entry.setUpdateTime(new Date()); |
||||
entry.setUpdateUser(AuthUtil.getUserId()); |
||||
service.updateById(entry); |
||||
return R.data(service.updateById(entry)); |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
package org.springblade.lims.job; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.lims.service.IMaintainPlanService; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
@AllArgsConstructor |
||||
public class CreateMaintainTaskJob { |
||||
private final IMaintainPlanService maintainPlanService; |
||||
|
||||
//@Scheduled(cron ="0 0/2 * * * ? ")
|
||||
@Scheduled(cron ="0 0 0 1/1 * ? ") |
||||
public void createTask(){ |
||||
maintainPlanService.checkAndCreateTask(); |
||||
} |
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
|
||||
package org.springblade.lims.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.springblade.lims.entry.MaintainPlan; |
||||
|
||||
/** |
||||
* |
||||
* |
||||
* @author sjx |
||||
* @since 2023年11月27日15:47:39 |
||||
*/ |
||||
public interface MaintainPlanMapper extends BaseMapper<MaintainPlan> { |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
|
||||
package org.springblade.lims.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.springblade.lims.entry.MaintainPlanProject; |
||||
|
||||
/** |
||||
* |
||||
* |
||||
* @author sjx |
||||
* @since 2023年11月27日15:47:39 |
||||
*/ |
||||
public interface MaintainPlanProjectMapper extends BaseMapper<MaintainPlanProject> { |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
|
||||
package org.springblade.lims.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.springblade.lims.entry.MaintainProject; |
||||
|
||||
/** |
||||
* |
||||
* |
||||
* @author sjx |
||||
* @since 2023年11月27日15:47:39 |
||||
*/ |
||||
public interface MaintainProjectMapper extends BaseMapper<MaintainProject> { |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
|
||||
package org.springblade.lims.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.springblade.lims.entry.MaintainRecord; |
||||
|
||||
/** |
||||
* |
||||
* |
||||
* @author sjx |
||||
* @since 2023年11月27日15:47:39 |
||||
*/ |
||||
public interface MaintainRecordMapper extends BaseMapper<MaintainRecord> { |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
|
||||
package org.springblade.lims.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.springblade.lims.entry.MaintainTask; |
||||
|
||||
/** |
||||
* |
||||
* |
||||
* @author sjx |
||||
* @since 2023年11月27日15:47:39 |
||||
*/ |
||||
public interface MaintainTaskMapper extends BaseMapper<MaintainTask> { |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
|
||||
package org.springblade.lims.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.springblade.lims.entry.MaintainTaskProject; |
||||
|
||||
/** |
||||
* |
||||
* |
||||
* @author sjx |
||||
* @since 2023年11月27日15:47:39 |
||||
*/ |
||||
public interface MaintainTaskProjectMapper extends BaseMapper<MaintainTaskProject> { |
||||
|
||||
} |
||||
@ -0,0 +1,123 @@ |
||||
package org.springblade.lims.mqtt.callback; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; |
||||
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; |
||||
import org.eclipse.paho.client.mqttv3.MqttException; |
||||
import org.eclipse.paho.client.mqttv3.MqttMessage; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springblade.core.tool.utils.Charsets; |
||||
import org.springblade.core.tool.utils.SpringUtil; |
||||
import org.springblade.lims.mqtt.client.MyMQTTClient; |
||||
import org.springblade.lims.mqtt.config.MqttConfiguration; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author WXY |
||||
* @date 2022/6/29 20:43 |
||||
*/ |
||||
public class MyMQTTCallback implements MqttCallbackExtended { |
||||
|
||||
//手动注入
|
||||
//private MqttConfiguration mqttConfiguration = SpringUtil.getBean(MqttConfiguration.class);
|
||||
|
||||
private static MqttConfiguration mqttConfiguration; |
||||
|
||||
private static MqttConfiguration getMqttConfiguration() { |
||||
if (mqttConfiguration == null) { |
||||
mqttConfiguration = SpringUtil.getBean(MqttConfiguration.class); |
||||
} |
||||
return mqttConfiguration; |
||||
} |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MyMQTTCallback.class); |
||||
|
||||
private MyMQTTClient mqttClient; |
||||
|
||||
public MyMQTTCallback(MyMQTTClient mqttClient) { |
||||
this.mqttClient = mqttClient; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 丢失连接,可在这里做重连 |
||||
* 只会调用一次 |
||||
* |
||||
* @param throwable |
||||
*/ |
||||
@Override |
||||
public void connectionLost(Throwable throwable) { |
||||
log.error("mqtt connectionLost 连接断开,5S之后尝试重连: {}", throwable.getMessage()); |
||||
long reconnectTimes = 1; |
||||
while (true) { |
||||
try { |
||||
if (MyMQTTClient.getClient().isConnected()) { |
||||
//判断已经重新连接成功 需要重新订阅主题 可以在这个if里面订阅主题 或者 connectComplete(方法里面) 看你们自己选择
|
||||
log.warn("mqtt reconnect success end 重新连接 重新订阅成功"); |
||||
return; |
||||
} |
||||
reconnectTimes+=1; |
||||
log.warn("mqtt reconnect times = {} try again... mqtt重新连接时间 {}", reconnectTimes, reconnectTimes); |
||||
MyMQTTClient.getClient().reconnect(); |
||||
} catch (MqttException e) { |
||||
log.error("mqtt断连异常", e); |
||||
} |
||||
try { |
||||
Thread.sleep(5000); |
||||
} catch (InterruptedException e1) { |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param topic |
||||
* @param mqttMessage |
||||
* @throws Exception |
||||
* subscribe后得到的消息会执行到这里面 |
||||
*/ |
||||
@Override |
||||
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception { |
||||
log.info("接收消息主题 : {},接收消息内容 : {}", topic, new String(mqttMessage.getPayload())); |
||||
//接收消息主题
|
||||
if (topic.equals("instrument/updateStatus")){ |
||||
Map maps = (Map) JSON.parse(new String(mqttMessage.getPayload(), Charsets.UTF_8.name())); |
||||
//你自己的业务接口
|
||||
log.info(maps.toString()); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
*连接成功后的回调 可以在这个方法执行 订阅主题 生成Bean的 MqttConfiguration方法中订阅主题 出现bug |
||||
*重新连接后 主题也需要再次订阅 将重新订阅主题放在连接成功后的回调 比较合理 |
||||
* @param reconnect |
||||
* @param serverURI |
||||
*/ |
||||
@Override |
||||
public void connectComplete(boolean reconnect,String serverURI){ |
||||
log.info("MQTT 连接成功,连接方式:{}",reconnect?"重连":"直连"); |
||||
//订阅主题
|
||||
mqttClient.subscribe(getMqttConfiguration().getTopic(), 1); |
||||
} |
||||
|
||||
/** |
||||
* 消息到达后 |
||||
* subscribe后,执行的回调函数 |
||||
* |
||||
* @param s |
||||
* @param mqttMessage |
||||
* @throws Exception |
||||
*/ |
||||
/** |
||||
* publish后,配送完成后回调的方法 |
||||
* |
||||
* @param iMqttDeliveryToken |
||||
*/ |
||||
@Override |
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { |
||||
log.info("==========deliveryComplete={}==========", iMqttDeliveryToken.isComplete()); |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,151 @@ |
||||
package org.springblade.lims.mqtt.client; |
||||
|
||||
import org.eclipse.paho.client.mqttv3.*; |
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springblade.lims.mqtt.callback.MyMQTTCallback; |
||||
|
||||
/** |
||||
1. @author WXY |
||||
2. @date 2022/6/29 20:43 |
||||
*/ |
||||
public class MyMQTTClient { |
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MyMQTTClient.class); |
||||
|
||||
private static MqttClient client; |
||||
private String host; |
||||
private String username; |
||||
private String password; |
||||
private String clientId; |
||||
private int timeout; |
||||
private int keepalive; |
||||
public MyMQTTClient(String host, String username, String password, String clientId, int timeOut, int keepAlive) { |
||||
this.host = host; |
||||
this.username = username; |
||||
this.password = password; |
||||
this.clientId = clientId; |
||||
this.timeout = timeOut; |
||||
this.keepalive = keepAlive; |
||||
} |
||||
|
||||
public static MqttClient getClient() { |
||||
return client; |
||||
} |
||||
|
||||
public static void setClient(MqttClient client) { |
||||
MyMQTTClient.client = client; |
||||
} |
||||
|
||||
/** |
||||
* 设置mqtt连接参数 |
||||
* |
||||
* @param username |
||||
* @param password |
||||
* @param timeout |
||||
* @param keepalive |
||||
* @return |
||||
*/ |
||||
public MqttConnectOptions setMqttConnectOptions(String username, String password, int timeout, int keepalive) { |
||||
MqttConnectOptions options = new MqttConnectOptions(); |
||||
options.setUserName(username); |
||||
options.setPassword(password.toCharArray()); |
||||
options.setConnectionTimeout(timeout); |
||||
options.setKeepAliveInterval(keepalive); |
||||
options.setCleanSession(true); |
||||
options.setAutomaticReconnect(true); |
||||
return options; |
||||
} |
||||
|
||||
/** |
||||
* 连接mqtt服务端,得到MqttClient连接对象 |
||||
*/ |
||||
public void connect() throws MqttException { |
||||
if (client == null) { |
||||
client = new MqttClient(host, clientId, new MemoryPersistence()); |
||||
client.setCallback(new MyMQTTCallback(MyMQTTClient.this)); |
||||
} |
||||
MqttConnectOptions mqttConnectOptions = setMqttConnectOptions(username, password, timeout, keepalive); |
||||
if (!client.isConnected()) { |
||||
client.connect(mqttConnectOptions); |
||||
} else { |
||||
client.disconnect(); |
||||
client.connect(mqttConnectOptions); |
||||
} |
||||
LOGGER.info("MQTT connect success");//未发生异常,则连接成功
|
||||
} |
||||
|
||||
/** |
||||
* 发布,默认qos为0,非持久化 |
||||
* |
||||
* @param pushMessage |
||||
* @param topic |
||||
*/ |
||||
public void publish(String pushMessage, String topic) { |
||||
publish(pushMessage, topic, 0, false); |
||||
} |
||||
|
||||
/** |
||||
* 发布消息 |
||||
* |
||||
* @param pushMessage |
||||
* @param topic |
||||
* @param qos |
||||
* @param retained:留存 |
||||
*/ |
||||
public void publish(String pushMessage, String topic, int qos, boolean retained) { |
||||
MqttMessage message = new MqttMessage(); |
||||
message.setPayload(pushMessage.getBytes()); |
||||
message.setQos(qos); |
||||
message.setRetained(retained); |
||||
MqttTopic mqttTopic = MyMQTTClient.getClient().getTopic(topic); |
||||
if (null == mqttTopic) { |
||||
LOGGER.error("topic is not exist"); |
||||
} |
||||
MqttDeliveryToken token;//Delivery:配送
|
||||
synchronized (this) {//注意:这里一定要同步,否则,在多线程publish的情况下,线程会发生死锁,分析见文章最后补充
|
||||
try { |
||||
token = mqttTopic.publish(message);//也是发送到执行队列中,等待执行线程执行,将消息发送到消息中间件
|
||||
token.waitForCompletion(1000L); |
||||
} catch (MqttPersistenceException e) { |
||||
e.printStackTrace(); |
||||
} catch (MqttException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 订阅某个主题 |
||||
* |
||||
* @param topic |
||||
* @param qos |
||||
*/ |
||||
public void subscribe(String topic, int qos) { |
||||
try { |
||||
MyMQTTClient.getClient().subscribe(topic, qos); |
||||
} catch (MqttException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 取消订阅主题 |
||||
* |
||||
* @param topic 主题名称 |
||||
*/ |
||||
public void cleanTopic(String topic) { |
||||
if (client != null && client.isConnected()) { |
||||
try { |
||||
client.unsubscribe(topic); |
||||
} catch (MqttException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} else { |
||||
System.out.println("取消订阅失败!"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,54 @@ |
||||
package org.springblade.lims.mqtt.config; |
||||
|
||||
import lombok.Data; |
||||
import org.eclipse.paho.client.mqttv3.MqttException; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springblade.lims.mqtt.client.MyMQTTClient; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Bean; |
||||
|
||||
/** |
||||
1. @author WXY |
||||
2. @date 2022/6/29 20:42 |
||||
*/ |
||||
//@Configuration
|
||||
@Data |
||||
public class MqttConfiguration { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MqttConfiguration.class); |
||||
@Value("${mqtt.host}") |
||||
String host; |
||||
@Value("${mqtt.username}") |
||||
String username; |
||||
@Value("${mqtt.password}") |
||||
String password; |
||||
@Value("${mqtt.clientId}") |
||||
String clientId; |
||||
@Value("${mqtt.timeout}") |
||||
int timeOut; |
||||
@Value("${mqtt.keepalive}") |
||||
int keepAlive; |
||||
@Value("${mqtt.topic}") |
||||
String topic; |
||||
|
||||
|
||||
@Bean//注入spring
|
||||
public MyMQTTClient mqttClient() { |
||||
MyMQTTClient mqttClient = new MyMQTTClient(host, username, password, clientId, timeOut, keepAlive); |
||||
for (int i = 0; i < 10; i++) { |
||||
try { |
||||
mqttClient.connect(); |
||||
return mqttClient; |
||||
} catch (MqttException e) { |
||||
log.error("MQTT connect exception,connect time = " + i); |
||||
try { |
||||
Thread.sleep(2000); |
||||
} catch (InterruptedException e1) { |
||||
e1.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
return mqttClient; |
||||
} |
||||
} |
||||
@ -0,0 +1,23 @@ |
||||
package org.springblade.lims.mqtt.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author WXY |
||||
* @date 2022/6/29 20:44 |
||||
*/ |
||||
@Data |
||||
public class MqttMsg { |
||||
private String name = ""; |
||||
private String content = ""; |
||||
private String time = ""; |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "MqttMsg{" + |
||||
"name='" + name + '\'' + |
||||
", content='" + content + '\'' + |
||||
", time='" + time + '\'' + |
||||
'}'; |
||||
} |
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
|
||||
package org.springblade.lims.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.lims.entry.MaintainPlanProject; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
public interface IMaintainPlanProjectService extends BaseService<MaintainPlanProject> { |
||||
} |
||||
@ -0,0 +1,25 @@ |
||||
|
||||
package org.springblade.lims.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.lims.entry.MaintainPlan; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
public interface IMaintainPlanService extends BaseService<MaintainPlan> { |
||||
IPage<MaintainPlan> findPage(MaintainPlan entry, Query query); |
||||
|
||||
boolean savePlan(MaintainPlan entry); |
||||
|
||||
MaintainPlan findById(String id); |
||||
|
||||
R createTask(String id); |
||||
|
||||
void checkAndCreateTask(); |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
|
||||
package org.springblade.lims.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.lims.entry.MaintainProject; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.InputStream; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
public interface IMaintainProjectService extends BaseService<MaintainProject> { |
||||
IPage<MaintainProject> findPage(MaintainProject entry, Query query); |
||||
|
||||
boolean saveProject(MaintainProject entry); |
||||
|
||||
MaintainProject findById(String id); |
||||
|
||||
Map<String,String> uploadFile(MultipartFile file); |
||||
|
||||
InputStream getInputStreamById(Long id); |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
|
||||
package org.springblade.lims.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.lims.entry.MaintainRecord; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
public interface IMaintainRecordService extends BaseService<MaintainRecord> { |
||||
IPage<MaintainRecord> findPage(MaintainRecord entry, Query query); |
||||
|
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
|
||||
package org.springblade.lims.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.lims.entry.MaintainTaskProject; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
public interface IMaintainTaskProjectService extends BaseService<MaintainTaskProject> { |
||||
IPage<MaintainTaskProject> findPage(MaintainTaskProject entry, Query query); |
||||
|
||||
boolean saveTaskProject(MaintainTaskProject entry); |
||||
|
||||
MaintainTaskProject findById(String id); |
||||
|
||||
} |
||||
@ -0,0 +1,25 @@ |
||||
|
||||
package org.springblade.lims.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.lims.entry.MaintainTask; |
||||
|
||||
/** |
||||
* @author sjx |
||||
* @date 2023年11月27日15:34:17 |
||||
*/ |
||||
public interface IMaintainTaskService extends BaseService<MaintainTask> { |
||||
IPage<MaintainTask> findPage(MaintainTask entry, Query query); |
||||
|
||||
boolean saveTask(MaintainTask entry); |
||||
|
||||
MaintainTask findById(String id); |
||||
|
||||
boolean deleteById(String id); |
||||
|
||||
R finish(String id); |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
|
||||
package org.springblade.lims.service.impl; |
||||
|
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.lims.entry.MaintainPlanProject; |
||||
import org.springblade.lims.mapper.MaintainPlanProjectMapper; |
||||
import org.springblade.lims.service.IMaintainPlanProjectService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
|
||||
/** |
||||
* |
||||
* @author swj |
||||
* @since 2022年6月2日15:53:01 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class MaintainPlanProjectServiceImpl extends BaseServiceImpl<MaintainPlanProjectMapper, MaintainPlanProject> implements IMaintainPlanProjectService { |
||||
|
||||
} |
||||
@ -0,0 +1,290 @@ |
||||
|
||||
package org.springblade.lims.service.impl; |
||||
|
||||
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils; |
||||
import com.alibaba.nacos.common.utils.StringUtils; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import lombok.AllArgsConstructor; |
||||
import org.apache.commons.lang3.time.DateFormatUtils; |
||||
import org.apache.commons.lang3.time.DateUtils; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.CollectionUtil; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springblade.lims.entry.*; |
||||
import org.springblade.lims.mapper.MaintainPlanMapper; |
||||
import org.springblade.lims.service.*; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.text.ParseException; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
/** |
||||
* @author swj |
||||
* @since 2022年6月2日15:53:01 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class MaintainPlanServiceImpl extends BaseServiceImpl<MaintainPlanMapper, MaintainPlan> implements IMaintainPlanService { |
||||
|
||||
private final IMaintainPlanProjectService maintainPlanProjectService; |
||||
private final IMaintainProjectService maintainProjectService; |
||||
private final IMaintainTaskService maintainTaskService; |
||||
private final IMaintainTaskProjectService maintainTaskProjectService; |
||||
private final IInstrumentService instrumentService; |
||||
|
||||
|
||||
@Override |
||||
public IPage<MaintainPlan> findPage(MaintainPlan entry, Query query) { |
||||
LambdaQueryWrapper<MaintainPlan> wrapper = new LambdaQueryWrapper<>(); |
||||
if (entry.getStatus() != null) { |
||||
wrapper.eq(MaintainPlan::getStatus, entry.getStatus()); |
||||
} |
||||
if (StringUtils.isNotBlank(entry.getMaintainType())) { |
||||
wrapper.eq(MaintainPlan::getMaintainType, entry.getMaintainType()); |
||||
} |
||||
|
||||
if (StringUtils.isNotBlank(entry.getCode())) { |
||||
wrapper.eq(MaintainPlan::getCode, entry.getCode()); |
||||
} |
||||
if (StringUtils.isNotBlank(entry.getName())) { |
||||
wrapper.eq(MaintainPlan::getName, entry.getName()); |
||||
} |
||||
if (StringUtils.isNotBlank(entry.getCycleMethod())) { |
||||
wrapper.eq(MaintainPlan::getCycleMethod, entry.getCycleMethod()); |
||||
} |
||||
if (StringUtils.isNotBlank(entry.getGroupId())) { |
||||
wrapper.eq(MaintainPlan::getGroupId, entry.getGroupId()); |
||||
} |
||||
if (StringUtils.isNotBlank(entry.getAssetCode())) { |
||||
wrapper.eq(MaintainPlan::getAssetCode, entry.getAssetCode()); |
||||
} |
||||
if (StringUtils.isNotBlank(entry.getAssetName())) { |
||||
wrapper.eq(MaintainPlan::getAssetName, entry.getAssetName()); |
||||
} |
||||
if (StringUtils.isNotBlank(entry.getAssetModel())) { |
||||
wrapper.eq(MaintainPlan::getAssetModel, entry.getAssetModel()); |
||||
} |
||||
|
||||
if (StringUtils.isNotBlank(entry.getAssetSn())) { |
||||
wrapper.eq(MaintainPlan::getAssetSn, entry.getAssetSn()); |
||||
} |
||||
wrapper.eq(BaseEntity::getIsDeleted, 0); |
||||
wrapper.orderByDesc(MaintainPlan::getCreateTime); |
||||
IPage<MaintainPlan> page = this.page(Condition.getPage(query), wrapper); |
||||
page.getRecords().forEach(plan ->{ |
||||
int projectCount = 0; |
||||
LambdaQueryWrapper<MaintainPlanProject> wrapper1 = new LambdaQueryWrapper<>(); |
||||
wrapper1.eq(MaintainPlanProject::getPlanId,plan.getId()); |
||||
List<MaintainPlanProject> planProjectList = maintainPlanProjectService.list(wrapper1); |
||||
if(CollectionUtils.isNotEmpty(planProjectList)){ |
||||
projectCount = planProjectList.size(); |
||||
} |
||||
plan.setProjectCount(projectCount); |
||||
|
||||
}); |
||||
return page; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean savePlan(MaintainPlan entry) { |
||||
//获取设备信息
|
||||
if(StringUtil.isNotBlank(entry.getAssetId())){ |
||||
Instrument instrument = instrumentService.getById(entry.getAssetId()); |
||||
if(instrument != null){ |
||||
entry.setAssetCode(instrument.getCode()); |
||||
entry.setAssetName(instrument.getName()); |
||||
entry.setAssetModel(instrument.getModel()); |
||||
} |
||||
} |
||||
Date date = new Date(); |
||||
//计算下次开始时间
|
||||
//1-单次 2-周期性
|
||||
if (entry.getCycleMethod().equals("2")) { |
||||
int startYear = Integer.parseInt(DateFormatUtils.format(new Date(), "yyyy-MM-dd").substring(0, 4)); |
||||
int startMonth = Integer.parseInt(DateFormatUtils.format(new Date(), "yyyy-MM-dd").substring(5, 7)); |
||||
int startDate = Integer.parseInt(DateFormatUtils.format(new Date(), "yyyy-MM-dd").substring(8)); |
||||
//1-年 2-月 3-间隔
|
||||
if (entry.getActionCycleType().equals("1")) { |
||||
try { |
||||
Date date1 = DateUtils.parseDate(startYear+"-"+entry.getActionCycleTime(),"yyyy-MM-dd"); |
||||
if(date1.compareTo(DateUtils.parseDate(entry.getStartTime(),"yyyy-MM-dd"))<0){ |
||||
//如果是年,则为每年固定日期;
|
||||
entry.setNextTime((startYear+1)+"-"+entry.getActionCycleTime()); |
||||
}else{ |
||||
entry.setNextTime(startYear + "-" + entry.getActionCycleTime()); |
||||
} |
||||
} catch (ParseException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
|
||||
} else if (entry.getActionCycleType().equals("2")) { |
||||
//如果是月或间隔,则通过开始日期计算;
|
||||
|
||||
|
||||
//如果开始时间小于配置的间隔时间,那么下次执行时间是开始时间当月,否则为开始时间下月
|
||||
if (startDate < Integer.parseInt(entry.getActionCycleTime())) { |
||||
entry.setNextTime(startYear + "-" + startMonth + "-" + entry.getActionCycleTime()); |
||||
} else { |
||||
if (startMonth < 9) { |
||||
entry.setNextTime(startYear + "-0" + (startMonth + 1) + (Integer.parseInt(entry.getActionCycleTime()) < 10 ? "0" +entry.getActionCycleTime() : entry.getActionCycleTime()) ); |
||||
} else if (startMonth >= 9 && startMonth <= 11) { |
||||
entry.setNextTime(startYear + "-" + (startMonth + 1) + (Integer.parseInt(entry.getActionCycleTime()) < 10 ? "0" +entry.getActionCycleTime() : entry.getActionCycleTime())); |
||||
} else { |
||||
entry.setNextTime((startYear + 1) + "-01-" + (Integer.parseInt(entry.getActionCycleTime()) < 10 ? "0" +entry.getActionCycleTime() : entry.getActionCycleTime())); |
||||
} |
||||
} |
||||
} else { |
||||
//如果是固定间隔,则第一次为开始日期
|
||||
entry.setNextTime(entry.getStartTime()); |
||||
} |
||||
} |
||||
if (entry.getId() == null) { |
||||
entry.setCreateUser(AuthUtil.getUserId()); |
||||
entry.setCreateTime(date); |
||||
entry.setCode("BYJH" + DateFormatUtils.format(date, "yyyyMMddhhmmss") + StringUtil.randomUUID().substring(0, 5)); |
||||
entry.setOriginatorId(AuthUtil.getUserId().toString()); |
||||
baseMapper.insert(entry); |
||||
} else { |
||||
entry.setUpdateUser(AuthUtil.getUserId()); |
||||
entry.setUpdateTime(date); |
||||
baseMapper.updateById(entry); |
||||
} |
||||
|
||||
//保养项目全删全增
|
||||
if (CollectionUtil.isNotEmpty(entry.getProjectList())) { |
||||
LambdaUpdateWrapper<MaintainPlanProject> wrapper = new LambdaUpdateWrapper<>(); |
||||
wrapper.eq(MaintainPlanProject::getPlanId, entry.getId()); |
||||
maintainPlanProjectService.remove(wrapper); |
||||
for (MaintainProject project : entry.getProjectList()) { |
||||
MaintainPlanProject planProject = new MaintainPlanProject(); |
||||
planProject.setPlanId(entry.getId().toString()); |
||||
planProject.setProjectId(project.getId().toString()); |
||||
planProject.setCreateTime(date); |
||||
planProject.setCreateUser(AuthUtil.getUserId()); |
||||
maintainPlanProjectService.save(planProject); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public MaintainPlan findById(String id) { |
||||
MaintainPlan entry = this.getById(id); |
||||
//查询保养项目
|
||||
LambdaQueryWrapper<MaintainPlanProject> planProjectWrapper = new LambdaQueryWrapper<>(); |
||||
planProjectWrapper.eq(MaintainPlanProject::getPlanId, id); |
||||
List<MaintainPlanProject> planProjectList = maintainPlanProjectService.list(planProjectWrapper); |
||||
if (CollectionUtils.isNotEmpty(planProjectList)) { |
||||
List<String> projectIds = planProjectList.stream().map(MaintainPlanProject::getProjectId).collect(Collectors.toList()); |
||||
List<MaintainProject> projectList = maintainProjectService.listByIds(projectIds); |
||||
entry.setProjectList(projectList); |
||||
} |
||||
return entry; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public R createTask(String id) { |
||||
MaintainPlan plan = this.getById(id); |
||||
//查询保养项目
|
||||
List<MaintainPlanProject> planProjectList = maintainPlanProjectService.list(new LambdaQueryWrapper<MaintainPlanProject>().eq(MaintainPlanProject::getPlanId,id)); |
||||
if(CollectionUtils.isEmpty(planProjectList)){ |
||||
return R.fail("未查询到保养项目!"); |
||||
} |
||||
List<String> projectIds = planProjectList.stream().map(MaintainPlanProject::getProjectId).collect(Collectors.toList()); |
||||
List<MaintainProject> projectList = maintainProjectService.listByIds(projectIds); |
||||
//生成任务
|
||||
MaintainTask task = new MaintainTask(); |
||||
task.setName(plan.getName()); |
||||
task.setMaintainType(plan.getMaintainType()); |
||||
task.setPlanStartTime(new Date()); |
||||
task.setTimeout(plan.getTimeout()); |
||||
task.setPlanId(id); |
||||
task.setGroupId(plan.getGroupId()); |
||||
task.setAssetId(plan.getAssetId()); |
||||
task.setAssetCode(plan.getAssetCode()); |
||||
task.setAssetName(plan.getAssetName()); |
||||
task.setAssetModel(plan.getAssetModel()); |
||||
task.setAssetSn(plan.getAssetSn()); |
||||
task.setActStartTime(new Date()); |
||||
maintainTaskService.saveTask(task); |
||||
//保养项目
|
||||
for(int j=0;j<projectList.size();j++){ |
||||
MaintainProject project=projectList.get(j); |
||||
MaintainTaskProject taskProject=new MaintainTaskProject(); |
||||
taskProject.setTaskId(task.getId().toString()); |
||||
taskProject.setProjectId(project.getId().toString()); |
||||
taskProject.setStatus(0); |
||||
taskProject.setProjectCode(project.getCode()); |
||||
taskProject.setProjectName(project.getName()); |
||||
taskProject.setProjectMaintainType(project.getMaintainType()); |
||||
taskProject.setProjectNotes(project.getNotes()); |
||||
taskProject.setProjectBaseCost(project.getBaseCost()); |
||||
maintainTaskProjectService.save(taskProject); |
||||
} |
||||
return R.success("创建任务成功!"); |
||||
} |
||||
|
||||
@Override |
||||
public void checkAndCreateTask() { |
||||
String date = DateFormatUtils.format(new Date(),"yyyy-MM-dd"); |
||||
//已结束的计划更新状态
|
||||
LambdaQueryWrapper<MaintainPlan> wrapper1 = new LambdaQueryWrapper<>(); |
||||
wrapper1.eq(MaintainPlan::getEndTime,date); |
||||
List<MaintainPlan> planList1 = this.list(wrapper1); |
||||
if(CollectionUtils.isNotEmpty(planList1)){ |
||||
for(MaintainPlan plan : planList1){ |
||||
plan.setStatus(2); |
||||
this.updateById(plan); |
||||
} |
||||
} |
||||
//查询需要创建任务的计划
|
||||
LambdaQueryWrapper<MaintainPlan> wrapper = new LambdaQueryWrapper<>(); |
||||
wrapper.eq(MaintainPlan::getNextTime,date); |
||||
wrapper.eq(MaintainPlan::getCycleMethod,"2"); |
||||
wrapper.eq(BaseEntity::getStatus,"1"); |
||||
List<MaintainPlan> planList = this.list(wrapper); |
||||
if(CollectionUtils.isNotEmpty(planList)){ |
||||
for(MaintainPlan maintainPlan : planList){ |
||||
//创建任务
|
||||
createTask(maintainPlan.getId().toString()); |
||||
//计算下次执行时间
|
||||
if (maintainPlan.getActionCycleType().equals("1")) { |
||||
//年:当前日期再加一年
|
||||
maintainPlan.setNextTime(DateFormatUtils.format(DateUtils.addYears(new Date(),1),"yyyy-MM-dd")); |
||||
}else if (maintainPlan.getActionCycleType().equals("2")){ |
||||
//月:当前月再加一月
|
||||
maintainPlan.setNextTime(DateFormatUtils.format(DateUtils.addMonths(new Date(),1),"yyyy-MM-dd")); |
||||
}else { |
||||
//间隔:当前日期再加间隔天数
|
||||
maintainPlan.setNextTime(DateFormatUtils.format(DateUtils.addDays(new Date(),Integer.parseInt(maintainPlan.getActionCycleTime())),"yyyy-MM-dd")); |
||||
} |
||||
this.updateById(maintainPlan); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
int startYear = Integer.parseInt(DateFormatUtils.format(new Date(), "yyyy-MM-dd").substring(0, 4)); |
||||
int startMonth = Integer.parseInt(DateFormatUtils.format(new Date(), "yyyy-MM-dd").substring(5, 7)); |
||||
int startDate = Integer.parseInt(DateFormatUtils.format(new Date(), "yyyy-MM-dd").substring(8)); |
||||
System.out.println(startYear); |
||||
System.out.println(startMonth); |
||||
System.out.println(startDate); |
||||
} |
||||
} |
||||
@ -0,0 +1,132 @@ |
||||
|
||||
package org.springblade.lims.service.impl; |
||||
|
||||
|
||||
import com.alibaba.nacos.common.utils.StringUtils; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.SneakyThrows; |
||||
import org.apache.commons.lang3.time.DateFormatUtils; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springblade.lims.entry.MaintainProject; |
||||
import org.springblade.lims.mapper.MaintainProjectMapper; |
||||
import org.springblade.lims.service.IMaintainProjectService; |
||||
import org.springblade.system.feign.ISysClient; |
||||
import org.springframework.core.io.ClassPathResource; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.io.FileOutputStream; |
||||
import java.io.InputStream; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
|
||||
|
||||
/** |
||||
* |
||||
* @author swj |
||||
* @since 2022年6月2日15:53:01 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class MaintainProjectServiceImpl extends BaseServiceImpl<MaintainProjectMapper, MaintainProject> implements IMaintainProjectService { |
||||
|
||||
private final ISysClient sysClient; |
||||
|
||||
@Override |
||||
public IPage<MaintainProject> findPage(MaintainProject entry, Query query) { |
||||
LambdaQueryWrapper<MaintainProject> wrapper = new LambdaQueryWrapper<>(); |
||||
if(entry.getStatus() != null){ |
||||
wrapper.eq(MaintainProject::getStatus,entry.getStatus()); |
||||
} |
||||
if(StringUtils.isNotBlank(entry.getMaintainType())){ |
||||
wrapper.eq(MaintainProject::getMaintainType,entry.getMaintainType()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getCode())){ |
||||
wrapper.eq(MaintainProject::getCode,entry.getCode()); |
||||
} |
||||
if(StringUtils.isNotBlank(entry.getName())){ |
||||
wrapper.eq(MaintainProject::getName,entry.getName()); |
||||
} |
||||
wrapper.eq(BaseEntity::getIsDeleted,0); |
||||
wrapper.orderByDesc(MaintainProject::getCreateTime); |
||||
IPage<MaintainProject> page = this.page(Condition.getPage(query), wrapper); |
||||
return page; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean saveProject(MaintainProject entry) { |
||||
Date date = new Date(); |
||||
if(entry.getId() == null){ |
||||
entry.setCreateUser(AuthUtil.getUserId()); |
||||
entry.setCreateTime(date); |
||||
entry.setCode("BYXM"+ DateFormatUtils.format(date,"yyyyMMddhhmmss")+ StringUtil.randomUUID().substring(0,5)); |
||||
baseMapper.insert(entry); |
||||
}else{ |
||||
entry.setUpdateUser(AuthUtil.getUserId()); |
||||
entry.setUpdateTime(date); |
||||
baseMapper.updateById(entry); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public MaintainProject findById(String id) { |
||||
MaintainProject entry = this.getById(id); |
||||
return entry; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String,String> uploadFile(MultipartFile file) { |
||||
Map<String,String> map = new HashMap<>(); |
||||
String fileName = ""; |
||||
String path = ""; |
||||
String originalFilename = ""; |
||||
if (file != null) { |
||||
originalFilename = file.getOriginalFilename(); |
||||
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); |
||||
fileName = UUID.randomUUID().toString() + fileSuffix; |
||||
path = sysClient.getParamValue("jiahe").getData() + fileName; |
||||
|
||||
FileOutputStream fout; |
||||
try { |
||||
fout = new FileOutputStream(path); |
||||
fout.write(file.getBytes()); |
||||
fout.close(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
map.put("filename",originalFilename); |
||||
map.put("path",path); |
||||
return map; |
||||
} |
||||
|
||||
@Override |
||||
@SneakyThrows |
||||
public InputStream getInputStreamById(Long id) { |
||||
MaintainProject entry = this.getById(id); |
||||
InputStream inputStream; |
||||
File file = new File(entry.getAttach()); |
||||
if (file.exists()) { |
||||
inputStream = new FileInputStream(file); |
||||
} else { |
||||
inputStream = new ClassPathResource("FileNotFound.docx").getInputStream(); |
||||
} |
||||
return inputStream; |
||||
} |
||||
} |
||||
@ -0,0 +1,42 @@ |
||||
|
||||
package org.springblade.lims.service.impl; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springblade.lims.entry.MaintainRecord; |
||||
import org.springblade.lims.mapper.MaintainRecordMapper; |
||||
import org.springblade.lims.service.IMaintainRecordService; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.util.Date; |
||||
|
||||
|
||||
/** |
||||
* |
||||
* @author swj |
||||
* @since 2022年6月2日15:53:01 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class MaintainRecordServiceImpl extends BaseServiceImpl<MaintainRecordMapper, MaintainRecord> implements IMaintainRecordService { |
||||
|
||||
|
||||
@Override |
||||
public IPage<MaintainRecord> findPage(MaintainRecord entry, Query query) { |
||||
LambdaQueryWrapper<MaintainRecord> wrapper = new LambdaQueryWrapper<>(); |
||||
|
||||
wrapper.eq(BaseEntity::getIsDeleted,0); |
||||
wrapper.orderByDesc(MaintainRecord::getCreateTime); |
||||
IPage<MaintainRecord> page = this.page(Condition.getPage(query), wrapper); |
||||
return page; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,64 @@ |
||||
|
||||
package org.springblade.lims.service.impl; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springblade.lims.entry.MaintainTaskProject; |
||||
import org.springblade.lims.mapper.MaintainTaskProjectMapper; |
||||
import org.springblade.lims.service.IMaintainTaskProjectService; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.util.Date; |
||||
|
||||
|
||||
/** |
||||
* |
||||
* @author swj |
||||
* @since 2022年6月2日15:53:01 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class MaintainTaskProjectServiceImpl extends BaseServiceImpl<MaintainTaskProjectMapper, MaintainTaskProject> implements IMaintainTaskProjectService { |
||||
|
||||
@Override |
||||
public IPage<MaintainTaskProject> findPage(MaintainTaskProject entry, Query query) { |
||||
LambdaQueryWrapper<MaintainTaskProject> wrapper = new LambdaQueryWrapper<>(); |
||||
|
||||
wrapper.eq(BaseEntity::getIsDeleted,0); |
||||
wrapper.orderByDesc(MaintainTaskProject::getCreateTime); |
||||
IPage<MaintainTaskProject> page = this.page(Condition.getPage(query), wrapper); |
||||
return page; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean saveTaskProject(MaintainTaskProject entry) { |
||||
Date date = new Date(); |
||||
if(entry.getId() == null){ |
||||
entry.setCreateUser(AuthUtil.getUserId()); |
||||
entry.setCreateTime(date); |
||||
baseMapper.insert(entry); |
||||
}else{ |
||||
entry.setUpdateUser(AuthUtil.getUserId()); |
||||
entry.setUpdateTime(date); |
||||
baseMapper.updateById(entry); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public MaintainTaskProject findById(String id) { |
||||
MaintainTaskProject entry = this.getById(id); |
||||
return entry; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,218 @@ |
||||
|
||||
package org.springblade.lims.service.impl; |
||||
|
||||
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils; |
||||
import com.alibaba.nacos.common.utils.StringUtils; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import lombok.AllArgsConstructor; |
||||
import org.apache.commons.lang3.time.DateFormatUtils; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.mp.support.Query; |
||||
import org.springblade.core.secure.utils.AuthUtil; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.Func; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
import org.springblade.lims.entry.MaintainProject; |
||||
import org.springblade.lims.entry.MaintainRecord; |
||||
import org.springblade.lims.entry.MaintainTask; |
||||
import org.springblade.lims.entry.MaintainTaskProject; |
||||
import org.springblade.lims.mapper.MaintainTaskMapper; |
||||
import org.springblade.lims.service.IMaintainProjectService; |
||||
import org.springblade.lims.service.IMaintainRecordService; |
||||
import org.springblade.lims.service.IMaintainTaskProjectService; |
||||
import org.springblade.lims.service.IMaintainTaskService; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
/** |
||||
* |
||||
* @author swj |
||||
* @since 2022年6月2日15:53:01 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class MaintainTaskServiceImpl extends BaseServiceImpl<MaintainTaskMapper, MaintainTask> implements IMaintainTaskService { |
||||
|
||||
private final IMaintainTaskProjectService maintainTaskProjectService; |
||||
private final IMaintainProjectService maintainProjectService; |
||||
private final IMaintainRecordService recordService; |
||||
|
||||
@Override |
||||
public IPage<MaintainTask> findPage(MaintainTask entry, Query query) { |
||||
LambdaQueryWrapper<MaintainTask> wrapper = new LambdaQueryWrapper<>(); |
||||
if(entry.getStatus() != null){ |
||||
wrapper.eq(MaintainTask::getStatus,entry.getStatus()); |
||||
} |
||||
if(StringUtils.isNotBlank(entry.getMaintainType())){ |
||||
wrapper.eq(MaintainTask::getMaintainType,entry.getMaintainType()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getGroupId())){ |
||||
wrapper.eq(MaintainTask::getGroupId,entry.getGroupId()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getBusinessCode())){ |
||||
wrapper.like(MaintainTask::getBusinessCode,entry.getBusinessCode()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getAssetCode())){ |
||||
wrapper.like(MaintainTask::getAssetCode,entry.getAssetCode()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getAssetName())){ |
||||
wrapper.like(MaintainTask::getAssetName,entry.getAssetName()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getAssetModel())){ |
||||
wrapper.like(MaintainTask::getAssetModel,entry.getAssetModel()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getAssetSn())){ |
||||
wrapper.eq(MaintainTask::getAssetSn,entry.getAssetSn()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getActStartTimeBegin())){ |
||||
wrapper.ge(MaintainTask::getActStartTime,entry.getActStartTimeBegin()); |
||||
} |
||||
|
||||
if(StringUtils.isNotBlank(entry.getActStartTimeEnd())){ |
||||
wrapper.le(MaintainTask::getActStartTime,entry.getActStartTimeEnd()); |
||||
} |
||||
|
||||
wrapper.eq(BaseEntity::getIsDeleted,0); |
||||
wrapper.orderByDesc(MaintainTask::getCreateTime); |
||||
IPage<MaintainTask> page = this.page(Condition.getPage(query), wrapper); |
||||
page.getRecords().forEach(task ->{ |
||||
int projectCount = 0; |
||||
int unProjectCount =0; |
||||
LambdaQueryWrapper<MaintainTaskProject> wrapper1 = new LambdaQueryWrapper<>(); |
||||
wrapper1.eq(MaintainTaskProject::getTaskId,task.getId()); |
||||
List<MaintainTaskProject> taskProjectList = maintainTaskProjectService.list(wrapper1); |
||||
if(CollectionUtils.isNotEmpty(taskProjectList)){ |
||||
projectCount = taskProjectList.size(); |
||||
} |
||||
wrapper1.eq(BaseEntity::getStatus,"0"); |
||||
taskProjectList = maintainTaskProjectService.list(wrapper1); |
||||
if(CollectionUtils.isNotEmpty(taskProjectList)){ |
||||
unProjectCount = taskProjectList.size(); |
||||
} |
||||
task.setProjectCount(projectCount); |
||||
task.setUnProjectCount(unProjectCount); |
||||
|
||||
}); |
||||
|
||||
return page; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean saveTask(MaintainTask entry) { |
||||
Date date = new Date(); |
||||
if(entry.getId() == null){ |
||||
entry.setCreateUser(AuthUtil.getUserId()); |
||||
entry.setCreateTime(date); |
||||
entry.setBusinessCode("BYRW"+ DateFormatUtils.format(date,"yyyyMMddhhmmss")+ StringUtil.randomUUID().substring(0,5)); |
||||
entry.setOriginatorId(AuthUtil.getUserId().toString()); |
||||
baseMapper.insert(entry); |
||||
}else{ |
||||
entry.setUpdateUser(AuthUtil.getUserId()); |
||||
entry.setUpdateTime(date); |
||||
baseMapper.updateById(entry); |
||||
} |
||||
//保养项目
|
||||
if(CollectionUtils.isNotEmpty(entry.getProjectList())){ |
||||
//保养项目全删全增
|
||||
LambdaUpdateWrapper<MaintainTaskProject> wrapper = new LambdaUpdateWrapper<>(); |
||||
wrapper.eq(MaintainTaskProject::getTaskId,entry.getId()); |
||||
maintainTaskProjectService.remove(wrapper); |
||||
List<MaintainProject> projectList = entry.getProjectList(); |
||||
for(int j=0;j<projectList.size();j++){ |
||||
MaintainProject project=projectList.get(j); |
||||
project = maintainProjectService.getById(project.getId()); |
||||
MaintainTaskProject taskProject=new MaintainTaskProject(); |
||||
taskProject.setTaskId(entry.getId().toString()); |
||||
taskProject.setProjectId(project.getId().toString()); |
||||
taskProject.setStatus(0); |
||||
taskProject.setProjectCode(project.getCode()); |
||||
taskProject.setProjectName(project.getName()); |
||||
taskProject.setProjectMaintainType(project.getMaintainType()); |
||||
taskProject.setProjectNotes(project.getNotes()); |
||||
taskProject.setProjectBaseCost(project.getBaseCost()); |
||||
maintainTaskProjectService.save(taskProject); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public MaintainTask findById(String id) { |
||||
MaintainTask entry = this.getById(id); |
||||
//查询保养项目
|
||||
LambdaQueryWrapper<MaintainTaskProject> taskProjectWrapper = new LambdaQueryWrapper<>(); |
||||
taskProjectWrapper.eq(MaintainTaskProject::getTaskId, id); |
||||
List<MaintainTaskProject> taskProjectList = maintainTaskProjectService.list(taskProjectWrapper); |
||||
if (CollectionUtils.isNotEmpty(taskProjectList)) { |
||||
List<String> projectIds = taskProjectList.stream().map(MaintainTaskProject::getProjectId).collect(Collectors.toList()); |
||||
List<MaintainProject> projectList = maintainProjectService.listByIds(projectIds); |
||||
entry.setProjectList(projectList); |
||||
} |
||||
return entry; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean deleteById(String id) { |
||||
//删除对应保养项目
|
||||
LambdaQueryWrapper<MaintainTaskProject> wrapper = new LambdaQueryWrapper<>(); |
||||
wrapper.eq(MaintainTaskProject::getTaskId,id); |
||||
List<MaintainTaskProject> taskProjectList = maintainTaskProjectService.list(wrapper); |
||||
if(CollectionUtils.isNotEmpty(taskProjectList)){ |
||||
List<Long> ids = taskProjectList.stream().map(MaintainTaskProject::getId).collect(Collectors.toList()); |
||||
maintainTaskProjectService.deleteLogic(ids); |
||||
} |
||||
return this.deleteLogic(Func.toLongList(id)); |
||||
} |
||||
|
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public R finish(String id) { |
||||
//校验保养项目是否都保养完成
|
||||
LambdaQueryWrapper<MaintainTaskProject> taskProjectWrapper = new LambdaQueryWrapper<>(); |
||||
taskProjectWrapper.eq(MaintainTaskProject::getTaskId,id); |
||||
List<MaintainTaskProject> taskProjectList = maintainTaskProjectService.list(taskProjectWrapper); |
||||
if(CollectionUtils.isNotEmpty(taskProjectList)){ |
||||
for(MaintainTaskProject taskProject : taskProjectList){ |
||||
if(taskProject.getStatus() == 0){ |
||||
return R.fail("存在未保养的项目!"); |
||||
} |
||||
} |
||||
}else{ |
||||
return R.fail("没有需要的保养项目!"); |
||||
} |
||||
//更新保养状态
|
||||
MaintainTask task = this.getById(id); |
||||
task.setStatus(2); |
||||
task.setUpdateTime(new Date()); |
||||
task.setUpdateUser(AuthUtil.getUserId()); |
||||
this.updateById(task); |
||||
//生成保养记录
|
||||
MaintainRecord record=new MaintainRecord(); |
||||
record.setAssetId(task.getAssetId()); |
||||
record.setBusinessCode(task.getBusinessCode()); |
||||
record.setContent("完成保养"); |
||||
record.setRcdTime(new Date()); |
||||
recordService.save(record); |
||||
return R.success("保养完成!"); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue