白蚁-日志管理
parent
d101457b38
commit
4f8be3e0a6
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.gunshi.project.hsz.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.gunshi.core.result.R;
|
||||||
|
import com.gunshi.project.hsz.entity.so.ByLogPageSo;
|
||||||
|
import com.gunshi.project.hsz.model.ByLog;
|
||||||
|
import com.gunshi.project.hsz.model.ByLogDetail;
|
||||||
|
import com.gunshi.project.hsz.service.ByLogDetailService;
|
||||||
|
import com.gunshi.project.hsz.service.ByLogService;
|
||||||
|
import com.gunshi.project.hsz.service.FileAssociationsService;
|
||||||
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
||||||
|
import com.gunshi.project.hsz.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.apache.commons.collections4.CollectionUtils;
|
||||||
|
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;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Tag(name = "白蚁-日志管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value="/byLog")
|
||||||
|
public class ByLogController extends AbstractCommonFileController {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ByLogService byLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ByLogDetailService byLogDetailService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileAssociationsService fileService;
|
||||||
|
|
||||||
|
@Operation(summary = "新增")
|
||||||
|
@PostMapping("/insert")
|
||||||
|
public R<ByLog> insert(@Validated(Insert.class) @RequestBody ByLog dto) {
|
||||||
|
dto.setId(IdWorker.getId());
|
||||||
|
List<ByLogDetail> byLogDetails = dto.getDetails();
|
||||||
|
byLogDetails.forEach(detail -> {
|
||||||
|
detail.setId(IdWorker.getId());
|
||||||
|
detail.setByLogId(dto.getId());
|
||||||
|
});
|
||||||
|
boolean save = byLogService.save(dto);
|
||||||
|
boolean flag2 = byLogDetailService.saveBatch(byLogDetails);
|
||||||
|
if (save && flag2) {
|
||||||
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
||||||
|
}
|
||||||
|
return R.ok(save && flag2 ? dto : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "修改")
|
||||||
|
@PostMapping("/update")
|
||||||
|
public R<ByLog> update(@Validated(Update.class) @RequestBody ByLog dto) {
|
||||||
|
|
||||||
|
boolean flag = byLogService.update(dto);
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
||||||
|
}
|
||||||
|
return R.ok(flag ? dto : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "删除")
|
||||||
|
@GetMapping("/del/{id}")
|
||||||
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||||
|
ByLog byId = byLogService.getById(id);
|
||||||
|
if(Objects.isNull(byId)){
|
||||||
|
throw new RuntimeException("该日志不存在");
|
||||||
|
}
|
||||||
|
//先删除细节
|
||||||
|
LambdaQueryWrapper<ByLogDetail> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(ByLogDetail::getByLogId,id);
|
||||||
|
boolean remove = byLogDetailService.remove(queryWrapper);
|
||||||
|
//再删除主体
|
||||||
|
if(remove){
|
||||||
|
byLogService.removeById(id);
|
||||||
|
}
|
||||||
|
return R.ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "分页")
|
||||||
|
@PostMapping("/page")
|
||||||
|
public R<Page<ByLog>> page(@RequestBody ByLogPageSo pageSo) {
|
||||||
|
Page<ByLog> res = byLogService.pageQuery(pageSo);
|
||||||
|
if(!CollectionUtils.isEmpty(res.getRecords())){
|
||||||
|
res.getRecords().forEach(o -> o.setFiles(
|
||||||
|
fileService.getFiles(getGroupId(),o.getId().toString())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return R.ok(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroupId() {
|
||||||
|
return "byLog";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.gunshi.project.hsz.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;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "分页查询对象")
|
||||||
|
public class ByLogPageSo {
|
||||||
|
|
||||||
|
@NotNull(message = "分页参数不能为空")
|
||||||
|
@Schema(description = "分页参数")
|
||||||
|
private PageSo pageSo;
|
||||||
|
|
||||||
|
@Schema(description="防治日期时段")
|
||||||
|
private DateTimeRangeSo dateTimeRangeSo;
|
||||||
|
|
||||||
|
@Schema(description = "日志名称")
|
||||||
|
private String logNmae;
|
||||||
|
|
||||||
|
@Schema(description = "防治部位")
|
||||||
|
private String preDetailName;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.gunshi.project.hsz.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.gunshi.project.hsz.entity.so.ByLogPageSo;
|
||||||
|
import com.gunshi.project.hsz.model.ByLogDetail;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ByLogDetailMapper extends BaseMapper<ByLogDetail> {
|
||||||
|
|
||||||
|
@Select("""
|
||||||
|
<script>
|
||||||
|
select t1.id,t1.by_log_id,t1.pre_place_detail_id as ppdi,t1.pre_person,t1.pre_method,t1.pre_effect,
|
||||||
|
t2.detail_name as ppdn,t3.id as ppi,t3.pre_name as ppn
|
||||||
|
from by_log_detail t1
|
||||||
|
join pre_place_detail t2
|
||||||
|
on t1.pre_place_detail_id = t2.id
|
||||||
|
join pre_place t3
|
||||||
|
on t2.pre_id = t3.id
|
||||||
|
where 1=1 and t1.by_log_id = #{logId}
|
||||||
|
<if test= "dto.preDetailName !=null and dto.preDetailName !=''">
|
||||||
|
and t2.detail_name LIKE '%'|| #{dto.preDetailName}||'%'
|
||||||
|
</if>
|
||||||
|
</script>
|
||||||
|
""")
|
||||||
|
List<ByLogDetail> selectDetail(@Param("logId") Long id,@Param("dto") ByLogPageSo pageSo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.gunshi.project.hsz.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.gunshi.project.hsz.model.ByLog;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ByLogMapper extends BaseMapper<ByLog> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.gunshi.project.hsz.model;
|
||||||
|
|
||||||
|
|
||||||
|
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.file.model.FileDescriptor;
|
||||||
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
||||||
|
import com.gunshi.project.hsz.validate.markers.Update;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Schema(description="白蚁-日志记录")
|
||||||
|
@Data
|
||||||
|
@TableName("by_log")
|
||||||
|
public class ByLog {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
@NotNull(message = "id不能为空",groups = Update.class)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField(value = "log_name")
|
||||||
|
@NotNull(message = "日志名称不能为空",groups = {Insert.class, Update.class})
|
||||||
|
@Schema(description = "日志名称")
|
||||||
|
private String logName;
|
||||||
|
|
||||||
|
@TableField(value = "pre_date")
|
||||||
|
@NotNull(message = "防治日期",groups = {Insert.class, Update.class})
|
||||||
|
@Schema(description = "防治日期")
|
||||||
|
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD, timezone = "GMT+8")
|
||||||
|
private Date preDate;
|
||||||
|
|
||||||
|
@TableField(value = "fill_time")
|
||||||
|
@Schema(description = "填报时间 (自动生成)")
|
||||||
|
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||||
|
private Date fillTime;
|
||||||
|
|
||||||
|
@TableField(value = "total_cost")
|
||||||
|
@Schema(description = "总花费")
|
||||||
|
private BigDecimal totalCost;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(value = "remark")
|
||||||
|
@Schema(description = "备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<ByLogDetail> details;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<FileAssociations> files;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.gunshi.project.hsz.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
||||||
|
import com.gunshi.project.hsz.validate.markers.Update;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description="白蚁-日志记录细节")
|
||||||
|
@Data
|
||||||
|
@TableName("by_log_detail")
|
||||||
|
public class ByLogDetail {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
@NotNull(message = "id不能为空",groups = Update.class)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField(value = "by_log_id")
|
||||||
|
@NotNull(message = "日志id不能为空",groups = {Update.class})
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@Schema(description = "日志id")
|
||||||
|
private Long byLogId;
|
||||||
|
|
||||||
|
@TableField(value = "pre_place_detail_id")
|
||||||
|
@NotNull(message = "防治部位id不能为空",groups = {Insert.class, Update.class})
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
@Schema(description = "防治部位id")
|
||||||
|
private Long ppdi;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Schema(description = "防治部位名称")
|
||||||
|
private String ppdn;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Schema(description = "防治点id")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long ppi;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Schema(description = "防治点名称")
|
||||||
|
private String ppn;
|
||||||
|
|
||||||
|
@TableField(value = "pre_person")
|
||||||
|
@Schema(description = "防治人员id")
|
||||||
|
private String prePerson;
|
||||||
|
|
||||||
|
@TableField(value = "pre_method")
|
||||||
|
@Schema(description = "防治方法")
|
||||||
|
private String preMethod;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(value = "pre_effect")
|
||||||
|
@Schema(description = "防治效果")
|
||||||
|
private String preEffect;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.gunshi.project.hsz.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByLogDetailMapper;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByLogMapper;
|
||||||
|
import com.gunshi.project.hsz.model.ByLog;
|
||||||
|
import com.gunshi.project.hsz.model.ByLogDetail;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ByLogDetailService extends ServiceImpl<ByLogDetailMapper, ByLogDetail> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.gunshi.project.hsz.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.gunshi.project.hsz.entity.so.ByLogPageSo;
|
||||||
|
import com.gunshi.project.hsz.mapper.AppVersionRecordMapper;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByLogDetailMapper;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByLogMapper;
|
||||||
|
import com.gunshi.project.hsz.model.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.executor.BatchResult;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ByLogService extends ServiceImpl<ByLogMapper, ByLog> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ByLogDetailMapper byLogDetailMapper;
|
||||||
|
|
||||||
|
public boolean update(ByLog dto) {
|
||||||
|
ByLog byId = getById(dto.getId());
|
||||||
|
if(Objects.isNull(byId)){
|
||||||
|
throw new RuntimeException("该日志不存在,请检查");
|
||||||
|
}
|
||||||
|
boolean save = updateById(dto);
|
||||||
|
List<ByLogDetail> byLogDetails = dto.getDetails();
|
||||||
|
byLogDetails.forEach(detail -> {
|
||||||
|
detail.setId(IdWorker.getId());
|
||||||
|
});
|
||||||
|
LambdaQueryWrapper<ByLogDetail> queryWrapper2 = new LambdaQueryWrapper<>();
|
||||||
|
//先删除,再新增
|
||||||
|
queryWrapper2.eq(ByLogDetail::getByLogId, dto.getId());
|
||||||
|
int delete = byLogDetailMapper.delete(queryWrapper2);
|
||||||
|
List<BatchResult> insert = byLogDetailMapper.insert(byLogDetails);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<ByLog> pageQuery(ByLogPageSo pageSo) {
|
||||||
|
LambdaQueryWrapper<ByLog> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if(!StringUtils.isBlank(pageSo.getLogNmae())){
|
||||||
|
queryWrapper.like(ByLog::getLogName, pageSo.getLogNmae());
|
||||||
|
}
|
||||||
|
Page<ByLog> byLogPage = this.baseMapper.selectPage(pageSo.getPageSo().toPage(), queryWrapper);
|
||||||
|
List<ByLog> records = byLogPage.getRecords();
|
||||||
|
Iterator<ByLog> iterator = records.iterator();
|
||||||
|
while(iterator.hasNext()){
|
||||||
|
ByLog record = iterator.next();
|
||||||
|
List<ByLogDetail> details = byLogDetailMapper.selectDetail(record.getId(),pageSo);
|
||||||
|
if(details.isEmpty()){
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
record.setDetails(details);
|
||||||
|
}
|
||||||
|
return byLogPage;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue