更新监测断面接口
parent
9aa0fddccc
commit
4ddc901281
|
|
@ -208,4 +208,5 @@ public class BasicDataController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.gunshi.project.xyt.entity.basedata;
|
|||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
@ -11,6 +12,7 @@ import lombok.Data;
|
|||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Schema(description = "表单参数校验对象")
|
||||
public class CheckStringSearch {
|
||||
@Schema(description="编码/名称/关键词")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.gunshi.project.xyt.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gunshi.project.xyt.entity.basedata.GeneralSearch;
|
||||
import com.gunshi.project.xyt.model.StMoncrB;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
|
@ -9,4 +11,6 @@ import org.apache.ibatis.annotations.Param;
|
|||
@Mapper
|
||||
public interface StMoncrBMapper extends BaseMapper<StMoncrB> {
|
||||
int batchInsert(@Param("list") List<StMoncrB> list);
|
||||
|
||||
Page<StMoncrB> queryBySearch(Page<StMoncrB> page, @Param("obj") GeneralSearch search);
|
||||
}
|
||||
|
|
@ -7,10 +7,14 @@ 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.project.xyt.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
@ -26,6 +30,7 @@ public class StMoncrB implements Serializable {
|
|||
@TableId(value = "CR_ID", type = IdType.INPUT)
|
||||
@Schema(description="断面ID")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
@NotNull(message = "断面ID不能为空", groups = {Update.class})
|
||||
private Long crId;
|
||||
|
||||
/**
|
||||
|
|
@ -33,6 +38,8 @@ public class StMoncrB implements Serializable {
|
|||
*/
|
||||
@TableField(value = "CR_CD")
|
||||
@Schema(description="断面编号")
|
||||
@Size(max = 50,message = "断面编号长度不能超过50")
|
||||
@NotNull
|
||||
private String crCd;
|
||||
|
||||
/**
|
||||
|
|
@ -40,6 +47,8 @@ public class StMoncrB implements Serializable {
|
|||
*/
|
||||
@TableField(value = "CR_NM")
|
||||
@Schema(description="断面名称")
|
||||
@Size(max = 200,message = "断面名称长度不能超过200")
|
||||
@NotNull
|
||||
private String crNm;
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +57,7 @@ public class StMoncrB implements Serializable {
|
|||
@TableField(value = "CR_IMG_ID")
|
||||
@Schema(description="断面平面图 文件ID")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
@NotNull
|
||||
private Long crImgId;
|
||||
|
||||
/**
|
||||
|
|
@ -62,6 +72,7 @@ public class StMoncrB implements Serializable {
|
|||
*/
|
||||
@TableField(value = "[STATUS]")
|
||||
@Schema(description="状态 1:启用 0:禁用")
|
||||
@NotNull
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
package com.gunshi.project.xyt.service;
|
||||
|
||||
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.project.xyt.entity.basedata.CheckStringSearch;
|
||||
import com.gunshi.project.xyt.entity.basedata.GeneralSearch;
|
||||
import com.gunshi.project.xyt.mapper.StMoncrBMapper;
|
||||
import com.gunshi.project.xyt.model.StMoncrB;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Sun Lejun
|
||||
* @version 1.0
|
||||
* @date 2024/1/26
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Data
|
||||
public class StMoncrService {
|
||||
private final StMoncrBMapper stMoncrBMapper;
|
||||
|
||||
|
||||
public Page<StMoncrB> queryBySearch(Page<StMoncrB> page, GeneralSearch search){
|
||||
return stMoncrBMapper.queryBySearch(page, search);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增监测断面
|
||||
* @param stMoncrB 监测断面对象
|
||||
*/
|
||||
public void insert(StMoncrB stMoncrB) {
|
||||
CheckStringSearch checkStringSearch = CheckStringSearch.builder()
|
||||
.keyword(stMoncrB.getCrCd()).build();
|
||||
checkCode(checkStringSearch);
|
||||
stMoncrB.setCrId(IdWorker.getId());
|
||||
stMoncrB.setSortOn(getMaxSortOn());
|
||||
stMoncrB.setTm(new Date());
|
||||
stMoncrBMapper.insert(stMoncrB);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新监测断面
|
||||
* @param stMoncrB 监测断面对象
|
||||
*/
|
||||
public void update(StMoncrB stMoncrB) {
|
||||
CheckStringSearch checkStringSearch = CheckStringSearch.builder()
|
||||
.keyword(stMoncrB.getCrCd()).id(stMoncrB.getCrId()).build();
|
||||
checkCode(checkStringSearch);
|
||||
stMoncrB.setTm(new Date());
|
||||
stMoncrBMapper.updateById(stMoncrB);
|
||||
}
|
||||
|
||||
public int getMaxSortOn(){
|
||||
QueryWrapper<StMoncrB> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(StMoncrB.COL_STATUS, 1);
|
||||
queryWrapper.orderByDesc(StMoncrB.COL_SORT_ON);
|
||||
StMoncrB stMoncrB = stMoncrBMapper.selectOne(queryWrapper, false);
|
||||
if(stMoncrB == null){
|
||||
return 1;
|
||||
}else {
|
||||
return stMoncrB.getSortOn() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查断面编码是否存在
|
||||
* @param search 查询对象
|
||||
*/
|
||||
public void checkCode(CheckStringSearch search){
|
||||
QueryWrapper<StMoncrB> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(StMoncrB.COL_STATUS, 1);
|
||||
queryWrapper.eq(StMoncrB.COL_CR_CD, search.getKeyword());
|
||||
if(search.getId() != null){
|
||||
queryWrapper.ne(StMoncrB.COL_CR_ID, search.getId());
|
||||
}
|
||||
StMoncrB stMoncrB = stMoncrBMapper.selectOne(queryWrapper, false);
|
||||
if(stMoncrB != null){
|
||||
throw new IllegalArgumentException("断面编码已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,4 +27,16 @@
|
|||
#{item.tm,jdbcType=TIMESTAMP})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="queryBySearch" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from ST_MONCR_B
|
||||
<where>
|
||||
<if test="obj.keyword != null and obj.keyword != ''">
|
||||
and (CR_CD like concat('%', #{obj.keyword}, '%') or CR_NM like concat('%', #{obj.keyword}, '%'))
|
||||
</if>
|
||||
and STATUS = 1
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue