白蚁-计划管理
parent
01558a76ae
commit
d101457b38
|
|
@ -0,0 +1,124 @@
|
||||||
|
package com.gunshi.project.hsz.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
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.ByPlanPageSo;
|
||||||
|
import com.gunshi.project.hsz.entity.so.OsmoticQueryPageSo;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlan;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlanDetail;
|
||||||
|
import com.gunshi.project.hsz.model.OsmoticPressDevice;
|
||||||
|
import com.gunshi.project.hsz.model.OsmoticPressR;
|
||||||
|
import com.gunshi.project.hsz.service.ByPlanDetailService;
|
||||||
|
import com.gunshi.project.hsz.service.ByPlanService;
|
||||||
|
import com.gunshi.project.hsz.service.FileAssociationsService;
|
||||||
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
||||||
|
import com.gunshi.project.hsz.validate.markers.Update;
|
||||||
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
|
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.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Tag(name = "白蚁-计划管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value="/byPlan")
|
||||||
|
public class ByPlanController extends AbstractCommonFileController{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileAssociationsService fileService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ByPlanService byPlanService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ByPlanDetailService byPlanDetailService;
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "新增")
|
||||||
|
@PostMapping("/insert")
|
||||||
|
public R<ByPlan> insert(@Validated(Insert.class) @RequestBody ByPlan dto) {
|
||||||
|
LambdaQueryWrapper<ByPlan> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(ByPlan::getPlanId, dto.getPlanId());
|
||||||
|
ByPlan one = byPlanService.getOne(queryWrapper);
|
||||||
|
if(Objects.nonNull(one)){
|
||||||
|
throw new RuntimeException("该计划编号已存在");
|
||||||
|
}
|
||||||
|
dto.setId(IdWorker.getId());
|
||||||
|
List<ByPlanDetail> byPlanDetail = dto.getByPlanDetail();
|
||||||
|
byPlanDetail.forEach(detail -> {
|
||||||
|
detail.setId(IdWorker.getId());
|
||||||
|
});
|
||||||
|
boolean save = byPlanService.save(dto);
|
||||||
|
boolean flag2 = byPlanDetailService.saveBatch(byPlanDetail);
|
||||||
|
if (save && flag2) {
|
||||||
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
||||||
|
}
|
||||||
|
return R.ok(save && flag2 ? dto : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "修改")
|
||||||
|
@PostMapping("/update")
|
||||||
|
public R<ByPlan> update(@Validated(Update.class) @RequestBody ByPlan dto) {
|
||||||
|
|
||||||
|
boolean flag = byPlanService.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) {
|
||||||
|
LambdaQueryWrapper<ByPlan> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(ByPlan::getId, id);
|
||||||
|
ByPlan one = byPlanService.getOne(queryWrapper);
|
||||||
|
if(Objects.isNull(one)){
|
||||||
|
throw new RuntimeException("该计划不存在");
|
||||||
|
}
|
||||||
|
String planId = one.getPlanId();
|
||||||
|
LambdaQueryWrapper<ByPlanDetail> queryWrapperDetail = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapperDetail.eq(ByPlanDetail::getPlanId, planId);
|
||||||
|
//先删细节
|
||||||
|
boolean remove = byPlanDetailService.remove(queryWrapperDetail);
|
||||||
|
if(remove){
|
||||||
|
//再删主体
|
||||||
|
byPlanService.remove(queryWrapper);
|
||||||
|
}
|
||||||
|
return R.ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "分页")
|
||||||
|
@PostMapping("/page")
|
||||||
|
public R<Page<ByPlan>> page(@RequestBody ByPlanPageSo byPlanPageSo) {
|
||||||
|
Page<ByPlan> byPlanPage = byPlanService.pageQuery(byPlanPageSo);
|
||||||
|
if(!CollectionUtils.isEmpty(byPlanPage.getRecords())){
|
||||||
|
byPlanPage.getRecords().forEach(o -> o.setFiles(
|
||||||
|
fileService.getFiles(getGroupId(),o.getId().toString())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return R.ok(byPlanPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroupId() {
|
||||||
|
return "byPlan";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.gunshi.project.hsz.entity.so;
|
||||||
|
|
||||||
|
import com.gunshi.db.dto.PageSo;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ByPlanPageSo {
|
||||||
|
|
||||||
|
@NotNull(message = "分页参数不能为空")
|
||||||
|
@Schema(description = "分页参数")
|
||||||
|
private PageSo pageSo;
|
||||||
|
|
||||||
|
|
||||||
|
@Schema(description = "计划名称")
|
||||||
|
private String planName;
|
||||||
|
|
||||||
|
@Schema(description = "防治部位")
|
||||||
|
private String preDetailName;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.gunshi.project.hsz.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.gunshi.project.hsz.entity.so.ByPlanPageSo;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlanDetail;
|
||||||
|
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.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ByPlanDetailMapper extends BaseMapper<ByPlanDetail> {
|
||||||
|
@Select("""
|
||||||
|
<script>
|
||||||
|
select t1.id,t1.plan_id,t1.pre_place_detail_id as ppdi,t1.pre_method,
|
||||||
|
t2.detail_name as ppdn,t3.id as ppi,t3.pre_name as ppn from
|
||||||
|
by_plan_detail t1
|
||||||
|
join pre_place_detail t2 on t1.pre_place_detail_id = t2.id and t2.is_enable = 0
|
||||||
|
join pre_place t3 on t2.pre_id = t3.id
|
||||||
|
where 1=1 and t1.plan_id = #{planId}
|
||||||
|
<if test= "dto.dto.preDetailName !=null and dto.dto.preDetailName !=''">
|
||||||
|
and t2.detail_name LIKE '%'|| #{dto.preDetailName}||'%'
|
||||||
|
</if>
|
||||||
|
</script>
|
||||||
|
""")
|
||||||
|
List<ByPlanDetail> selectList(@Param("planId")String planId, @Param("dto") ByPlanPageSo dto);
|
||||||
|
|
||||||
|
|
||||||
|
@Select("""
|
||||||
|
select count(*)
|
||||||
|
from by_plan_detail t
|
||||||
|
where t.pre_place_detail_id = #{id}
|
||||||
|
""")
|
||||||
|
int selectByPPDI(@Param("id") Serializable id);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.gunshi.project.hsz.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.gunshi.core.result.R;
|
||||||
|
import com.gunshi.project.hsz.entity.so.ByPlanPageSo;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlan;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ByPlanMapper extends BaseMapper<ByPlan> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
package com.gunshi.project.hsz.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.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 org.checkerframework.checker.units.qual.N;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Schema(description="白蚁-计划管理")
|
||||||
|
@Data
|
||||||
|
@TableName("by_plan")
|
||||||
|
public class ByPlan {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
@NotNull(message = "id不能为空",groups = Update.class)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField(value = "plan_id")
|
||||||
|
@Schema(description = "计划编号")
|
||||||
|
@NotNull(message = "计划编号不能为空",groups = {Insert.class, Update.class})
|
||||||
|
private String planId;
|
||||||
|
|
||||||
|
@TableField(value = "plan_name")
|
||||||
|
@Schema(description = "计划名称")
|
||||||
|
private String planName;
|
||||||
|
|
||||||
|
@TableField(value = "plan_date_start")
|
||||||
|
@Schema(description = "计划开始时间")
|
||||||
|
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD, timezone = "GMT+8")
|
||||||
|
private Date planDateStart;
|
||||||
|
|
||||||
|
@TableField(value = "plan_date_end")
|
||||||
|
@Schema(description = "计划结束时间")
|
||||||
|
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD, timezone = "GMT+8")
|
||||||
|
private Date planDateEnd;
|
||||||
|
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
@Schema(description = "用户id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
@TableField(value = "predict_cost")
|
||||||
|
@Schema(description = "预算花费")
|
||||||
|
private BigDecimal predictCost;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
List<ByPlanDetail> byPlanDetail;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Schema(description = "文件集合")
|
||||||
|
private List<FileAssociations> files;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Schema(description="白蚁-计划管理细节")
|
||||||
|
@Data
|
||||||
|
@TableName("by_plan_detail")
|
||||||
|
public class ByPlanDetail {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
@NotNull(message = "id不能为空",groups = Update.class)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField(value = "plan_id")
|
||||||
|
@Schema(description = "计划编号")
|
||||||
|
@NotNull(message = "计划编号不能为空",groups = {Insert.class, Update.class})
|
||||||
|
private String planId;
|
||||||
|
|
||||||
|
@TableField(value = "pre_place_detail_id")
|
||||||
|
@Schema(description = "防治部位编号")
|
||||||
|
@NotNull(message = "防治部位编号",groups = {Insert.class, Update.class})
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
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_method")
|
||||||
|
@Schema(description = "防治方法")
|
||||||
|
private String preMethod;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.gunshi.project.hsz.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByPlanDetailMapper;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByPlanMapper;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlan;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlanDetail;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ByPlanDetailService extends ServiceImpl<ByPlanDetailMapper, ByPlanDetail> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
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.core.result.R;
|
||||||
|
import com.gunshi.project.hsz.entity.so.ByPlanPageSo;
|
||||||
|
import com.gunshi.project.hsz.mapper.AlarmSetMapper;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByPlanDetailMapper;
|
||||||
|
import com.gunshi.project.hsz.mapper.ByPlanMapper;
|
||||||
|
import com.gunshi.project.hsz.model.AlarmSet;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlan;
|
||||||
|
import com.gunshi.project.hsz.model.ByPlanDetail;
|
||||||
|
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.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ByPlanService extends ServiceImpl<ByPlanMapper, ByPlan> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ByPlanDetailMapper byPlanDetailMapper;
|
||||||
|
|
||||||
|
public boolean update(ByPlan dto) {
|
||||||
|
LambdaQueryWrapper<ByPlan> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(ByPlan::getPlanId, dto.getPlanId());
|
||||||
|
ByPlan one = getOne(queryWrapper);
|
||||||
|
if(Objects.isNull(one)){
|
||||||
|
throw new RuntimeException("该计划不存在,请检查");
|
||||||
|
}
|
||||||
|
boolean save = updateById(dto);
|
||||||
|
List<ByPlanDetail> byPlanDetail = dto.getByPlanDetail();
|
||||||
|
byPlanDetail.forEach(detail -> {
|
||||||
|
detail.setId(IdWorker.getId());
|
||||||
|
});
|
||||||
|
LambdaQueryWrapper<ByPlanDetail> queryWrapper2 = new LambdaQueryWrapper<>();
|
||||||
|
//先删除,再新增
|
||||||
|
queryWrapper2.eq(ByPlanDetail::getPlanId, dto.getPlanId());
|
||||||
|
int delete = byPlanDetailMapper.delete(queryWrapper2);
|
||||||
|
List<BatchResult> insert = byPlanDetailMapper.insert(byPlanDetail);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<ByPlan> pageQuery(ByPlanPageSo dto) {
|
||||||
|
LambdaQueryWrapper<ByPlan> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if(!StringUtils.isBlank(dto.getPlanName())){
|
||||||
|
queryWrapper.like(ByPlan::getPlanName,dto.getPlanName());
|
||||||
|
}
|
||||||
|
queryWrapper.orderByDesc(ByPlan::getPlanDateStart);
|
||||||
|
Page<ByPlan> byPlanPage = baseMapper.selectPage(dto.getPageSo().toPage(), queryWrapper);
|
||||||
|
List<ByPlan> records = byPlanPage.getRecords();
|
||||||
|
Iterator<ByPlan> iterator = records.iterator();
|
||||||
|
while(iterator.hasNext()){
|
||||||
|
ByPlan entity = iterator.next();
|
||||||
|
List<ByPlanDetail> details = byPlanDetailMapper.selectList(entity.getPlanId(),dto);
|
||||||
|
if(details.isEmpty()){
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
entity.setByPlanDetail(details);
|
||||||
|
}
|
||||||
|
return byPlanPage;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue