From 0177aa684d935d39e460719ac42914d96910a822 Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期一, 03 七月 2023 17:21:46 +0800 Subject: [PATCH] 增加井号重复判断 --- ard-work/src/main/resources/mapper/alarmpoints/ArdAlarmpointsWellMapper.xml | 18 ++++++-- ard-work/src/main/java/com/ruoyi/alarmpoints/well/mapper/ArdAlarmpointsWellMapper.java | 31 +++++++++++---- ard-work/src/main/java/com/ruoyi/alarmpoints/well/service/impl/ArdAlarmpointsWellServiceImpl.java | 14 +++++++ ard-work/src/main/java/com/ruoyi/alarmpoints/well/controller/ArdAlarmpointsWellController.java | 10 ++-- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/alarmpoints/well/controller/ArdAlarmpointsWellController.java b/ard-work/src/main/java/com/ruoyi/alarmpoints/well/controller/ArdAlarmpointsWellController.java index 3ee4de7..e4ac74d 100644 --- a/ard-work/src/main/java/com/ruoyi/alarmpoints/well/controller/ArdAlarmpointsWellController.java +++ b/ard-work/src/main/java/com/ruoyi/alarmpoints/well/controller/ArdAlarmpointsWellController.java @@ -91,8 +91,8 @@ public AjaxResult add(@RequestBody ArdAlarmpointsWell ardAlarmpointsWell) { try { return toAjax(ardAlarmpointsWellService.insertArdAlarmpointsWell(ardAlarmpointsWell)); - } catch (DuplicateKeyException e) { - return AjaxResult.error("浜曞彿閲嶅"); + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); } } @@ -105,9 +105,9 @@ @ApiOperation("淇敼浜�") public AjaxResult edit(@RequestBody ArdAlarmpointsWell ardAlarmpointsWell) { try { - return toAjax(ardAlarmpointsWellService.updateArdAlarmpointsWell(ardAlarmpointsWell)); - } catch (DuplicateKeyException e) { - return AjaxResult.error("浜曞彿閲嶅"); + return toAjax(ardAlarmpointsWellService.updateArdAlarmpointsWell(ardAlarmpointsWell)); + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); } } diff --git a/ard-work/src/main/java/com/ruoyi/alarmpoints/well/mapper/ArdAlarmpointsWellMapper.java b/ard-work/src/main/java/com/ruoyi/alarmpoints/well/mapper/ArdAlarmpointsWellMapper.java index 2eeb3c9..0cd3df9 100644 --- a/ard-work/src/main/java/com/ruoyi/alarmpoints/well/mapper/ArdAlarmpointsWellMapper.java +++ b/ard-work/src/main/java/com/ruoyi/alarmpoints/well/mapper/ArdAlarmpointsWellMapper.java @@ -1,25 +1,26 @@ package com.ruoyi.alarmpoints.well.mapper; import java.util.List; + import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell; import com.ruoyi.common.annotation.DataScope; /** * 浜曠鐞哅apper鎺ュ彛 - * + * * @author 鍒樿嫃涔� * @date 2023-03-07 */ -public interface ArdAlarmpointsWellMapper -{ +public interface ArdAlarmpointsWellMapper { /** * 鏌ヨ浜曠鐞� - * + * * @param id 浜曠鐞嗕富閿� * @return 浜曠鐞� */ public ArdAlarmpointsWell selectArdAlarmpointsWellById(String id); + /** * 鏌ヨ浜曠鐞� * @@ -27,6 +28,7 @@ * @return 浜曠鐞� */ public ArdAlarmpointsWell selectArdAlarmpointsWellByWellId(String wellId); + /** * 鏌ヨ浜曠鐞� * @@ -34,9 +36,10 @@ * @return */ public List selectArdAlarmpointsWellByWellIdLike(ArdAlarmpointsWell ardAlarmpointsWell); + /** * 鏌ヨ浜曠鐞嗗垪琛� - * + * * @param ardAlarmpointsWell 浜曠鐞� * @return 浜曠鐞嗛泦鍚� */ @@ -44,7 +47,7 @@ /** * 鏂板浜曠鐞� - * + * * @param ardAlarmpointsWell 浜曠鐞� * @return 缁撴灉 */ @@ -52,7 +55,7 @@ /** * 淇敼浜曠鐞� - * + * * @param ardAlarmpointsWell 浜曠鐞� * @return 缁撴灉 */ @@ -60,7 +63,7 @@ /** * 鍒犻櫎浜曠鐞� - * + * * @param id 浜曠鐞嗕富閿� * @return 缁撴灉 */ @@ -68,9 +71,19 @@ /** * 鎵归噺鍒犻櫎浜曠鐞� - * + * * @param ids 闇�瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 * @return 缁撴灉 */ public int deleteArdAlarmpointsWellByIds(String[] ids); + + /** + * 鏍稿浜曞彿鏄惁鍞竴 + * + * @param wellId 闇�瑕佹牳瀵圭殑浜曞彿 + * @return 缁撴灉 + */ + + public boolean checkWellIdExists(String wellId); + } diff --git a/ard-work/src/main/java/com/ruoyi/alarmpoints/well/service/impl/ArdAlarmpointsWellServiceImpl.java b/ard-work/src/main/java/com/ruoyi/alarmpoints/well/service/impl/ArdAlarmpointsWellServiceImpl.java index e0a498f..ea80ad6 100644 --- a/ard-work/src/main/java/com/ruoyi/alarmpoints/well/service/impl/ArdAlarmpointsWellServiceImpl.java +++ b/ard-work/src/main/java/com/ruoyi/alarmpoints/well/service/impl/ArdAlarmpointsWellServiceImpl.java @@ -13,10 +13,12 @@ import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.common.utils.spring.SpringUtils; +import lombok.ToString; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.validation.Validator; @@ -85,7 +87,13 @@ * @return 缁撴灉 */ @Override + @Transactional public int insertArdAlarmpointsWell(ArdAlarmpointsWell ardAlarmpointsWell) { + boolean wellIdExists = ardAlarmpointsWellMapper.checkWellIdExists(ardAlarmpointsWell.getWellId()); + if(wellIdExists) + { + throw new RuntimeException("浜曞彿宸插瓨鍦�"); + } ardAlarmpointsWell.setUserId(SecurityUtils.getUserId()); ardAlarmpointsWell.setCreateBy(SecurityUtils.getUsername()); ardAlarmpointsWell.setCreateTime(DateUtils.getNowDate()); @@ -99,7 +107,13 @@ * @return 缁撴灉 */ @Override + @Transactional public int updateArdAlarmpointsWell(ArdAlarmpointsWell ardAlarmpointsWell) { + boolean wellIdExists = ardAlarmpointsWellMapper.checkWellIdExists(ardAlarmpointsWell.getWellId()); + if(wellIdExists) + { + throw new RuntimeException("浜曞彿宸插瓨鍦�"); + } ardAlarmpointsWell.setUpdateBy(SecurityUtils.getUsername()); ardAlarmpointsWell.setUpdateTime(DateUtils.getNowDate()); return ardAlarmpointsWellMapper.updateArdAlarmpointsWell(ardAlarmpointsWell); diff --git a/ard-work/src/main/resources/mapper/alarmpoints/ArdAlarmpointsWellMapper.xml b/ard-work/src/main/resources/mapper/alarmpoints/ArdAlarmpointsWellMapper.xml index de254e1..8c390a1 100644 --- a/ard-work/src/main/resources/mapper/alarmpoints/ArdAlarmpointsWellMapper.xml +++ b/ard-work/src/main/resources/mapper/alarmpoints/ArdAlarmpointsWellMapper.xml @@ -66,18 +66,21 @@ <where> <if test="wellId != null and wellId != ''">and c.well_id = #{wellId}</if> <if test="wellNumber != null and wellNumber != ''">and c.well_number = #{wellNumber}</if> - <if test="userId != null and userId != ''"> and c.user_id = #{userId}</if> - <if test="deptId != null "> and (c.dept_id = #{deptId} OR c.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE cast(#{deptId} as varchar) = any(string_to_array(ancestors,',')) ))</if> + <if test="userId != null and userId != ''">and c.user_id = #{userId}</if> + <if test="deptId != null ">and (c.dept_id = #{deptId} OR c.dept_id IN ( SELECT t.dept_id FROM sys_dept t + WHERE cast(#{deptId} as varchar) = any(string_to_array(ancestors,',')) )) + </if> <!-- 鏁版嵁鑼冨洿杩囨护 --> ${params.dataScope} </where> </select> - <select id="selectArdAlarmpointsWellByWellIdLike" parameterType="ArdAlarmpointsWell" resultMap="ArdAlarmpointsWellResult"> + <select id="selectArdAlarmpointsWellByWellIdLike" parameterType="ArdAlarmpointsWell" + resultMap="ArdAlarmpointsWellResult"> <include refid="selectArdAlarmpointsWellVo"/> <where> <if test="id != null and id != ''">and c.id = #{id}</if> - <if test="wellId != null and wellId != ''"> and well_id like ('%${wellId}%')</if> + <if test="wellId != null and wellId != ''">and well_id like ('%${wellId}%')</if> <!-- 鏁版嵁鑼冨洿杩囨护 --> ${params.dataScope} </where> @@ -174,7 +177,7 @@ <if test="updateTime != null">update_time = #{updateTime},</if> <if test="cameraId != null">camera_id = #{cameraId},</if> </trim> - where id = #{id} + where id = #{id} </update> <delete id="deleteArdAlarmpointsWellById" parameterType="String"> @@ -189,4 +192,9 @@ #{id} </foreach> </delete> + <select id="checkWellIdExists" resultType="boolean"> + SELECT COUNT(*) + FROM ard_alarmpoints_well + WHERE well_id = #{wellId} + </select> </mapper> \ No newline at end of file -- Gitblit v1.9.3