sunmingan 4 роки тому
батько
коміт
85ed00c31b

+ 15 - 1
mpwechatApp/src/main/java/com/liangjian11/wx/mp/mapper/ChannelPortMapper.java

@@ -63,7 +63,7 @@ public interface ChannelPortMapper extends BaseMapper<ChannelPort> {
     @Select("SELECT * from (select  row_number() over (  order by u.createTime DESC)  as rownum,u.*" +
         ",case type when '1' then '企业微信' when '0' then '公众号' end 'typeName'" +
         ",case state when '0' then '正常' when '1' then '失效' end'stateName' from channel_port u ${sqlStr} ) A where A.rownum>#{index} AND A.rownum<#{size} ")
-    List<ChannelPort> queryExternalList(@Param("sqlStr")String sqlStr, @Param("index")Integer index, @Param("size")Integer size);
+    List<Map<String,Object>> queryExternalList(@Param("sqlStr")String sqlStr, @Param("index")Integer index, @Param("size")Integer size);
 
     /**
      * 根据条件查询数量
@@ -79,4 +79,18 @@ public interface ChannelPortMapper extends BaseMapper<ChannelPort> {
      */
     @Select("select * from channel_port where type = '0' and state = '0'")
     List<ChannelPort> queryListByAllConfigInfo();
+
+    /**
+     * 根据portName 和 type 查询库中是否存在
+     * @param m
+     * @return
+     */
+    @Select("<script> select count(id) from channel_port" +
+        " <trim prefix='where' prefixOverrides='AND |OR'>" +
+        " <if test='m.portName != null and m.portName.length() > 0'> and portName = #{m.portName} </if>" +
+        " <if test='m.type != null and m.type.length() > 0'> and type = #{m.type} </if>" +
+        " <if test='m.id != null'> and id <![CDATA[ <> ]]> #{m.id} </if>" +
+        " </trim>" +
+        " </script>")
+    int selectByPortName(@Param("m")Map<String,Object> m);
 }

+ 15 - 5
mpwechatApp/src/main/java/com/liangjian11/wx/mp/service/impl/ChannelPortServiceImpl.java

@@ -42,15 +42,15 @@ public class ChannelPortServiceImpl implements ChannelPortService {
         String sqlStr=data.getFilterString();
         Integer totalCount=this.portMapper.queryExternalCount(sqlStr);
 
-        List<ChannelPort> list = new ArrayList<>();
+        List<Map<String,Object>> listMap = new ArrayList<>();
         if(totalCount != null && totalCount > 0){
-            list = this.portMapper.queryExternalList(sqlStr,start,end);
-            for (ChannelPort p: list) {
-                p.setHeadImg(webUrl + p.getHeadImg());
+            listMap = this.portMapper.queryExternalList(sqlStr,start,end);
+            for (Map m: listMap) {
+                m.put("headImg",webUrl + m.get("headImg"));
             }
         }
         ResultInfo result = new ResultInfo(ResultInfo.TYPE_RESULT_SUCCESS,100,"操作成功!");
-        result.setItems(list);
+        result.setItems(listMap);
         result.setTotalCount(totalCount);
         return result;
     }
@@ -72,6 +72,16 @@ public class ChannelPortServiceImpl implements ChannelPortService {
                 port.setHeadImg(newPath);
             }
         }
+        //重名检测
+        Map<String,Object> paramMap = new HashMap<String,Object>();
+        paramMap.put("id",port.getId());
+        paramMap.put("portName",port.getPortName());
+        paramMap.put("type",port.getType());
+        int count = portMapper.selectByPortName(paramMap);
+        if(count > 0){
+            return new ResultInfo(ResultInfo.TYPE_RESULT_INFO,200,"端口名称重复,请重新输入!");
+        }
+
         if(port.getId() == null){
             //新增
             port.setCreateTime(DateUtil.getNowDateTimeStr());