From 83a667d7ec77536ed0739be8d2dd64bc54723c03 Mon Sep 17 00:00:00 2001 From: wany <13995595726@qq.com> Date: Tue, 27 Aug 2024 16:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E4=BF=AE=E5=85=BB=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MaintainServiceController.java | 67 +++++++++++ .../project/xyt/entity/so/MaintainPageSo.java | 30 +++++ .../xyt/mapper/MaintainServiceMapper.java | 15 +++ .../project/xyt/model/MaintainService.java | 90 +++++++++++++++ .../xyt/service/MaintainServiceService.java | 108 ++++++++++++++++++ 5 files changed, 310 insertions(+) create mode 100644 src/main/java/com/gunshi/project/xyt/controller/MaintainServiceController.java create mode 100644 src/main/java/com/gunshi/project/xyt/entity/so/MaintainPageSo.java create mode 100644 src/main/java/com/gunshi/project/xyt/mapper/MaintainServiceMapper.java create mode 100644 src/main/java/com/gunshi/project/xyt/model/MaintainService.java create mode 100644 src/main/java/com/gunshi/project/xyt/service/MaintainServiceService.java diff --git a/src/main/java/com/gunshi/project/xyt/controller/MaintainServiceController.java b/src/main/java/com/gunshi/project/xyt/controller/MaintainServiceController.java new file mode 100644 index 0000000..91b49f7 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/controller/MaintainServiceController.java @@ -0,0 +1,67 @@ +package com.gunshi.project.xyt.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.so.MaintainPageSo; +import com.gunshi.project.xyt.model.MaintainService; +import com.gunshi.project.xyt.service.MaintainServiceService; +import com.gunshi.project.xyt.validate.markers.Insert; +import com.gunshi.project.xyt.validate.markers.Update; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.io.Serializable; +import java.util.List; +/** + * 描述: 维修养护 + * author: xusan + * date: 2024-08-27 15:15:14 + */ +@Tag(name = "维修养护") +@RestController +@RequestMapping(value="/maintain/service") +public class MaintainServiceController extends AbstractCommonFileController{ + + @Autowired + private MaintainServiceService service; + + + @Operation(summary = "新增") + @PostMapping("/insert") + public R insert(@Validated(Insert.class) @RequestBody MaintainService dto) { + return R.ok(service.saveData(dto)); + } + + @Operation(summary = "修改") + @PostMapping("/update") + public R update(@Validated(Update.class) @RequestBody MaintainService dto) { + return R.ok(service.updateData(dto)); + } + + @Operation(summary = "删除") + @GetMapping("/del/{id}") + public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { + return R.ok(service.delData(id)); + } + + @Operation(summary = "列表") + @PostMapping("/list") + public R> list() { + return R.ok(service.lambdaQuery().list()); + } + + @Operation(summary = "分页") + @PostMapping("/page") + public R> page(@RequestBody MaintainPageSo page) { + return R.ok(service.pageQuery(page)); + } + + @Override + public String getGroupId() { + return "maintainService"; + } +} \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/entity/so/MaintainPageSo.java b/src/main/java/com/gunshi/project/xyt/entity/so/MaintainPageSo.java new file mode 100644 index 0000000..19fa1f9 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/so/MaintainPageSo.java @@ -0,0 +1,30 @@ +package com.gunshi.project.xyt.entity.so; + +import com.gunshi.db.dto.DateTimeRangeSo; +import com.gunshi.db.dto.PageSo; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * Description: + * Created by wanyan on 2024/3/19 + * + * @author wanyan + * @version 1.0 + */ +@Data +@Schema(description = "分页查询对象") +public class MaintainPageSo { + + @NotNull(message = "分页参数不能为空") + @Schema(description = "分页参数") + private PageSo pageSo; + + @Schema(description="管护类型(1溢洪道淸障 2除草除杂 3设备养护 4环境清洁 5危险提示 6其他)") + private Integer maintainType; + + @Schema(description = "时间范围") + private DateTimeRangeSo dateTimeSo; + +} diff --git a/src/main/java/com/gunshi/project/xyt/mapper/MaintainServiceMapper.java b/src/main/java/com/gunshi/project/xyt/mapper/MaintainServiceMapper.java new file mode 100644 index 0000000..9c77fdd --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/mapper/MaintainServiceMapper.java @@ -0,0 +1,15 @@ +package com.gunshi.project.xyt.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.gunshi.project.xyt.model.MaintainService; +import org.apache.ibatis.annotations.Mapper; + +/** + * 描述: 维修养护 + * author: xusan + * date: 2024-08-27 15:15:14 + */ +@Mapper +public interface MaintainServiceMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/MaintainService.java b/src/main/java/com/gunshi/project/xyt/model/MaintainService.java new file mode 100644 index 0000000..03f71c7 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/model/MaintainService.java @@ -0,0 +1,90 @@ +package com.gunshi.project.xyt.model; + + +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.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.gunshi.core.dateformat.DateFormatString; +import com.gunshi.project.xyt.validate.markers.Update; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** +* 描述: 维修养护 +* author: xusan +* date: 2024-08-27 15:15:13 +*/ +@Schema(description="维修养护") +@Data +@TableName("public.maintain_service") +public class MaintainService implements Serializable { + + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value="id", type= IdType.AUTO) + @Schema(description="主键") + @NotNull(message = "主键不能为空",groups = {Update.class}) + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 上报时间 + */ + @TableField(value="report_time") + @Schema(description="上报时间") + @JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8") + private Date reportTime; + + /** + * 管护类型(1溢洪道淸障 2除草除杂 3设备养护 4环境清洁 5危险提示 6其他) + */ + @TableField(value="maintain_type") + @Schema(description="管护类型(1溢洪道淸障 2除草除杂 3设备养护 4环境清洁 5危险提示 6其他)") + private Integer maintainType; + + /** + * 内容 + */ + @TableField(value="maintain_content") + @Schema(description="内容") + @Size(max = 500,message = "内容最大长度要小于 500") + private String maintainContent; + + /** + * 上报人id + */ + @TableField(value="report_user_id") + @Schema(description="上报人id") + private Long reportUserId; + + /** + * 上报人 + */ + @TableField(value="report_user_name") + @Schema(description="上报人") + @Size(max = 50,message = "上报人最大长度要小于 50") + private String reportUserName; + + @TableField(exist = false) + @Schema(description = "现场图片") + private List pics; + + @TableField(exist = false) + @Schema(description = "现场视频") + private List videos; + +} \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/service/MaintainServiceService.java b/src/main/java/com/gunshi/project/xyt/service/MaintainServiceService.java new file mode 100644 index 0000000..518d525 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/service/MaintainServiceService.java @@ -0,0 +1,108 @@ +package com.gunshi.project.xyt.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gunshi.project.xyt.entity.so.MaintainPageSo; +import com.gunshi.project.xyt.mapper.MaintainServiceMapper; +import com.gunshi.project.xyt.model.MaintainService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.Serializable; +import java.util.List; +import java.util.Objects; + +/** + * 描述: 维修养护 + * author: xusan + * date: 2024-08-27 15:15:14 + */ +@Service +@Slf4j +@Transactional(rollbackFor = Exception.class) +public class MaintainServiceService extends ServiceImpl +{ + @Autowired + private FileAssociationsService fileService; + + public MaintainService saveData(MaintainService dto) { + dto.setId(IdWorker.getId()); + boolean result = this.save(dto); + if (result) { + fileService.save(dto.getPics(), dto.getId().toString(), getGroupId(),getPicType()); + fileService.save(dto.getVideos(), dto.getId().toString(), getGroupId(),getVideoType()); + } + return dto; + } + + private String getVideoType() { + return "mainVideo"; + } + + private String getPicType() { + return "mainPic"; + } + + public MaintainService updateData(MaintainService dto) { + if (Objects.isNull(this.getById(dto.getId()))) { + throw new IllegalArgumentException("当前数据不存在"); + } + boolean result = this.updateById(dto); + if (result) { + fileService.removeByBzIdAndType(dto.getId().toString(),getGroupId(),getPicType()); + fileService.save(dto.getPics(), dto.getId().toString(), getGroupId(),getPicType()); + fileService.removeByBzIdAndType(dto.getId().toString(),getGroupId(),getVideoType()); + fileService.save(dto.getVideos(), dto.getId().toString(), getGroupId(),getVideoType()); + } + return dto; + } + + public Boolean delData(Serializable id) { + if (Objects.isNull(this.getById(id))) { + throw new IllegalArgumentException("当前数据不存在"); + } + boolean data = this.removeById(id); + if (data) { + fileService.deleteFile(getGroupId(), id.toString()); + } + return data; + } + + public String getGroupId() { + return "maintainService"; + } + + public Page pageQuery(MaintainPageSo page) { + LambdaQueryWrapper query = Wrappers.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getMaintainType())) { + query.eq(MaintainService::getMaintainType, page.getMaintainType()); + } + if (page.getDateTimeSo() != null && page.getDateTimeSo().getStart() != null) { + query.ge(MaintainService::getReportTime, page.getDateTimeSo().getStart()); + } + if (page.getDateTimeSo() != null && page.getDateTimeSo().getEnd() != null) { + query.le(MaintainService::getReportTime, page.getDateTimeSo().getEnd()); + } + query.orderByDesc(MaintainService::getReportTime); + Page res = this.page(page.getPageSo().toPage(), query); + if (res.getRecords() != null) { + fillAttach(res.getRecords()); + } + return res; + } + + private void fillAttach(List ret) { + for (MaintainService record : ret) { + record.setPics(fileService.queryFileList(record.getId().toString(),getGroupId(),getPicType())); + record.setVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getVideoType())); + } + } +} + +