部门和角色接口修改

增加气井接口
This commit is contained in:
qinjie 2024-11-24 15:57:24 +08:00
parent 1731a9b6aa
commit bda4d27def
12 changed files with 104 additions and 105 deletions

View File

@ -59,5 +59,10 @@ public class DepartmentController {
public Response<List<Department>> list(){
return Response.succeed(departmentService.list());
}
@GetMapping("/getDepartment")
public Response<Department> getDepartment(@RequestParam String id){
return Response.succeed(departmentService.getById(id));
}
}

View File

@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/gaswell")
@RequestMapping("/gasWell")
public class GasWellController {
private final GasWellService gasWellService;
@ -43,23 +43,26 @@ public class GasWellController {
/**
* 查询气井列表
*/
@GetMapping
public Response<Page<GasWellVO>> page(GasWellPageQuery query) {
return Response.succeed(gasWellService.pageForQuery(query));
@GetMapping(value = "/page")
public Response<Page<GasWellVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String name,
@RequestParam Long blockId) {
return Response.succeed(gasWellService.pageForQuery(currentPage, pageSize, name,blockId));
}
/**
* 获取气井详细信息
*/
@GetMapping(value = "/{id}")
public Response<GasWellVO> getInfo(@PathVariable("id") Long id) {
@GetMapping(value = "/getGasWell")
public Response<GasWellVO> getGasWell(@RequestParam Long id) {
return Response.succeed(gasWellService.selectGasWellById(id));
}
/**
* 新增气井
*/
@PostMapping
@PostMapping(value = "/add")
@OperationLog(description = "新增气井", type = LogType.ADD)
public Response<String> add(@RequestBody @Valid GasWellCreateRequest gasWellCreateRequest) {
gasWellService.insertGasWell(gasWellCreateRequest);
@ -69,7 +72,7 @@ public class GasWellController {
/**
* 修改气井
*/
@PutMapping
@PostMapping("/edit")
@OperationLog(description = "修改气井", type = LogType.UPDATE)
public Response<String> edit(@RequestBody GasWellEditRequest gasWellEditRequest) {
gasWellService.updateGasWell(gasWellEditRequest);
@ -79,11 +82,12 @@ public class GasWellController {
/**
* 删除气井
*/
@DeleteMapping("/{ids}")
@GetMapping("/delete")
@OperationLog(description = "删除气井", type = LogType.DELETE)
public Response<String> delete(@PathVariable Collection<Long> ids) {
gasWellService.deleteGasWellByIds(ids);
public Response<String> delete(@RequestParam Long id) {
gasWellService.deleteGasWellById(id);
return Response.succeed();
}
}

View File

@ -57,5 +57,10 @@ public class RoleController {
public Response<List<Role>> delete(){
return Response.succeed(roleService.list());
}
@GetMapping("/getRole")
public Response<Role> getRole(@RequestParam Long id){
return Response.succeed(roleService.getById(id));
}
}

View File

@ -4,11 +4,9 @@ import java.util.Collection;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.vo.GasWellPageQuery;
import com.isu.gaswellwatch.entity.GasWell;
/**
@ -26,7 +24,7 @@ public interface GasWellDao extends BaseMapper<GasWell> {
* @param id 气井主键
* @return 气井
*/
GasWell selectGasWellById(Long id);
GasWellVO selectGasWellById(Long id);
/**
* 查询气井列表
@ -39,10 +37,10 @@ public interface GasWellDao extends BaseMapper<GasWell> {
/**
* 分页查询气井列表
*
* @param query 查询条件
* @param blockId
* @return 气井
*/
Page<GasWellVO> pageForQuery(Page<GasWellVO> page, @Param("query") GasWellPageQuery query);
Page<GasWellVO> pageForQuery(Page<GasWellVO> page, String name, Long blockId);
/**
* 新增气井
@ -58,7 +56,7 @@ public interface GasWellDao extends BaseMapper<GasWell> {
* @param gasWell 气井
* @return 结果
*/
int updateGasWell(GasWell gasWell);
int updateGasWell(GasWellVO gasWell);
/**
* 删除气井

View File

@ -1,5 +1,7 @@
package com.isu.gaswellwatch.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -28,13 +30,19 @@ public class GasWellCreateRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/** 关联公司 */
private Long companyId;
/** 气井ID */
private Long id;
/** 气井名称 */
@NotBlank(message = "气井名称不能为空")
private String name;
/** 描述 */
private String details;
/** 所属区块 */
@NotNull(message = "所属区块不能为空")
private Long blockId;
}

View File

@ -31,9 +31,6 @@ public class GasWellEditRequest implements Serializable {
/** 主键 */
private Long id;
/** 关联公司 */
private Long companyId;
/** 气井名称 */
private String name;

View File

@ -26,26 +26,24 @@ public class GasWell extends Model<GasWell> {
/** 主键 */
private Long id;
/** 关联公司 */
private Long companyId;
/** 气井名称 */
private String name;
/** 描述 */
private String details;
/** 创建人 */
private Long createBy;
/** 设备ID */
private Long deviceId;
/** 区块ID */
private Long blockId;
/** 创建时间 */
private LocalDateTime createTime;
/** 更新人 */
private Long updateBy;
private String createTime;
/** 更新时间 */
private LocalDateTime updateTime;
private String updateTime;
}

View File

@ -40,9 +40,7 @@ public interface GasWellMapper {
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession()
.get(UserConstant.TOKEN_SESSION);
if (Objects.nonNull(userLoginInfoVO) && Objects.nonNull(userLoginInfoVO.getUserVO())) {
gasWell.setUpdateBy(gasWell.getCreateBy());
}
gasWell.setUpdateTime(LocalDateTime.now());
copyToEntity(request, gasWell);
}
@ -50,12 +48,6 @@ public interface GasWellMapper {
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession()
.get(UserConstant.TOKEN_SESSION);
GasWell gasWell =new GasWell();
gasWell.setCreateTime(LocalDateTime.now());
gasWell.setUpdateTime(gasWell.getCreateTime());
if (Objects.nonNull(userLoginInfoVO) && Objects.nonNull(userLoginInfoVO.getUserVO())) {
gasWell.setCreateBy(userLoginInfoVO.getUserVO().getId());
gasWell.setUpdateBy(gasWell.getCreateBy());
}
create(request, gasWell);
return gasWell;
}

View File

@ -5,7 +5,6 @@ import java.util.Collection;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.vo.GasWellPageQuery;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.entity.GasWell;
import com.baomidou.mybatisplus.extension.service.IService;
@ -37,10 +36,9 @@ public interface GasWellService extends IService<GasWell> {
/**
* 分页查询气井列表
*
* @param query 查询条件
* @return 气井
*/
Page<GasWellVO> pageForQuery(GasWellPageQuery query);
Page<GasWellVO> pageForQuery(Integer currentPage, Integer pageSize, String name, Long blockId);
/**
* 新增气井

View File

@ -2,13 +2,19 @@ package com.isu.gaswellwatch.service.impl;
import java.util.Collection;
import java.util.List;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.isu.gaswellwatch.config.SnowflakeConfig;
import com.isu.gaswellwatch.exception.BusinessException;
import com.isu.gaswellwatch.utils.ConverterUtil;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.vo.GasWellPageQuery;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.dao.GasWellDao;
import com.isu.gaswellwatch.entity.GasWell;
@ -28,6 +34,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@Transactional(readOnly = true)
public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implements GasWellService {
@Resource
private SnowflakeConfig snowflakeConfig;
private final GasWellDao gasWellDao;
private final GasWellMapper gasWellMapper = Mappers.getMapper(GasWellMapper.class);
@ -39,7 +48,7 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
*/
@Override
public GasWellVO selectGasWellById(Long id) {
return gasWellMapper.toPageVO(gasWellDao.selectGasWellById(id));
return gasWellDao.selectGasWellById(id);
}
/**
@ -56,12 +65,11 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
/**
* 分页查询气井列表
*
* @param query 查询条件
* @return 气井
*/
@Override
public Page<GasWellVO> pageForQuery(GasWellPageQuery query){
return gasWellDao.pageForQuery(new Page<>(query.getCurrentPage(), query.getPageSize()), query);
public Page<GasWellVO> pageForQuery(Integer currentPage, Integer pageSize, String name, Long blockId){
return gasWellDao.pageForQuery(new Page<>(currentPage, pageSize), name,blockId);
}
/**
@ -73,7 +81,15 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
@Override
@Transactional(rollbackFor = Throwable.class)
public int insertGasWell(GasWellCreateRequest gasWellCreateRequest) {
return gasWellDao.insertGasWell(gasWellMapper.create(gasWellCreateRequest));
GasWell gasWell = ConverterUtil.convert(gasWellCreateRequest,GasWell.class);
//查重
List<GasWell> list = list(new LambdaQueryWrapper<GasWell>().eq(GasWell::getName, gasWellCreateRequest.getName()));
if(CollectionUtil.isNotEmpty(list)) {
throw new BusinessException("已有相同名称,请重新输入");
}
gasWell.setId(snowflakeConfig.snowflakeId());
return gasWellDao.insertGasWell(gasWell);
}
/**
@ -85,9 +101,8 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
@Override
@Transactional(rollbackFor = Throwable.class)
public int updateGasWell(GasWellEditRequest gasWellEditRequest) {
GasWell gasWell = gasWellDao.selectGasWellById(gasWellEditRequest.getId());
gasWellMapper.copyToEntity(gasWellEditRequest, gasWell);
return gasWellDao.updateGasWell(gasWell);
GasWellVO gasWellVO = ConverterUtil.convert(gasWellEditRequest,GasWellVO.class);
return gasWellDao.updateGasWell(gasWellVO);
}
/**
@ -99,6 +114,11 @@ public class GasWellServiceImpl extends ServiceImpl<GasWellDao, GasWell> implem
@Override
@Transactional(rollbackFor = Throwable.class)
public int deleteGasWellById(Long id) {
//判断气井是否被关联设备如果已经关联设备则无法删除
GasWellVO gasWellVO = gasWellDao.selectGasWellById(id);
if(gasWellVO.getDeviceId() != null){
throw new BusinessException("该气井已经关联设备,无法删除");
}
return gasWellDao.deleteGasWellById(id);
}

View File

@ -31,25 +31,22 @@ public class GasWellVO implements Serializable {
/** 主键 */
private Long id;
/** 关联公司 */
private Long companyId;
/** 气井名称 */
private String name;
/** 描述 */
private String details;
/** 创建人 */
private Long createBy;
/** 创建时间 */
private LocalDateTime createTime;
/** 更新人 */
private Long updateBy;
private String createTime;
/** 更新时间 */
private LocalDateTime updateTime;
private String updateTime;
/** 设备id */
private Long deviceId;
/** 区块id */
private Long blockId;
}

View File

@ -6,40 +6,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.isu.gaswellwatch.vo.GasWellVO" id="GasWellVO">
<result property="id" column="id" />
<result property="companyId" column="company_id" />
<result property="name" column="name" />
<result property="details" column="details" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" jdbcType="DATE" typeHandler="com.isu.gaswellwatch.utils.LocalDateTimeTypeHandler" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" jdbcType="DATE" typeHandler="com.isu.gaswellwatch.utils.LocalDateTimeTypeHandler" />
</resultMap>
<resultMap type="com.isu.gaswellwatch.entity.GasWell" id="GasWellResult">
<result property="id" column="id" />
<result property="companyId" column="company_id" />
<result property="name" column="name" />
<result property="details" column="details" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" jdbcType="DATE" typeHandler="com.isu.gaswellwatch.utils.LocalDateTimeTypeHandler" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" jdbcType="DATE" typeHandler="com.isu.gaswellwatch.utils.LocalDateTimeTypeHandler" />
<result property="deviceId" column="device_id" />
<result property="blockId" column="block_id" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectGasWellVo">
select t1.id, t1.company_id, t1.name, t1.details, t1.create_by, t1.create_time, t1.update_by, t1.update_time from gas_wells t1
select t1.id, t1.name, t1.details, t1.block_id,t1.device_id, t1.create_time, t1.update_time from gas_well t1
</sql>
<select id="pageForQuery" resultMap="GasWellVO">
<include refid="selectGasWellVo"/>
<where>
<if test="query.companyId != null "> and t1.company_id = #{companyId}</if>
<if test="query.name != null and query.name != ''"> and t1.name like concat('%', #{query.name}, '%')</if>
<if test="name != null and name != ''"> and t1.name like concat('%', #{name}, '%')</if>
and t1.block_id = #{blockId}
</where>
order by t1.id desc
</select>
<select id="selectGasWellList" resultMap="GasWellResult">
<select id="selectGasWellList" resultMap="GasWellVO">
<include refid="selectGasWellVo"/>
<where>
<if test="companyId != null "> and t1.company_id = #{companyId}</if>
@ -47,53 +35,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="selectGasWellById" parameterType="Long" resultMap="GasWellResult">
<select id="selectGasWellById" parameterType="Long" resultMap="GasWellVO">
<include refid="selectGasWellVo"/>
where t1.id = #{id}
</select>
<insert id="insertGasWell" useGeneratedKeys="true" keyProperty="id">
insert into gas_wells
<insert id="insertGasWell">
insert into gas_well
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="companyId != null">company_id,</if>
<if test="id != null">id,</if>
<if test="name != null and name != ''">name,</if>
<if test="details != null">details,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="blockId != null">block_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="companyId != null">#{companyId},</if>
<if test="id != null">#{id},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="details != null">#{details},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="blockId != null">#{blockId},</if>
</trim>
</insert>
<update id="updateGasWell">
update gas_wells
update gas_well
<trim prefix="SET" suffixOverrides=",">
<if test="companyId != null">company_id = #{companyId},</if>
<if test="name != null and name != ''">name = #{name},</if>
<if test="details != null">details = #{details},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteGasWellById" parameterType="Long">
delete from gas_wells where id = #{id}
delete from gas_well where id = #{id}
</delete>
<delete id="deleteGasWellByIds">
delete from gas_wells where id in
delete from gas_well where id in
<foreach item="id" collection="list" open="(" separator="," close=")">
#{id}
</foreach>