فهرست منبع

sso业务系统

xyg 2 سال پیش
والد
کامیت
1885e31a47

+ 88 - 0
spring-cloud/commons/src/main/java/com/jd/entity/basic/SsoSystem.java

@@ -0,0 +1,88 @@
+package com.jd.entity.basic;
+
+import java.util.Date;
+
+/**
+ * sso系统
+ * @author Admin
+ */
+public class SsoSystem {
+
+    /**
+     * sso业务系统id
+     */
+    private Integer id;
+
+    /**
+     * 业务系统名称
+     */
+    private String name;
+
+    /**
+     * 业务系统appid,自动生成
+     */
+    private String appId;
+
+    /**
+     * 登录成功重定向http/https地址
+     */
+    private String redirectUrl;
+
+    /**
+     * 业务系统图片
+     */
+    private String titleImg;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getRedirectUrl() {
+        return redirectUrl;
+    }
+
+    public void setRedirectUrl(String redirectUrl) {
+        this.redirectUrl = redirectUrl;
+    }
+
+    public String getTitleImg() {
+        return titleImg;
+    }
+
+    public void setTitleImg(String titleImg) {
+        this.titleImg = titleImg;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+}

+ 79 - 12
spring-cloud/server-basic/src/main/java/com/jd/controller/SsoSystemController.java

@@ -1,20 +1,19 @@
 package com.jd.controller;
 
-import java.util.HashMap;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.jd.code.ConstString;
+import com.jd.entity.basic.SsoSystem;
 import com.jd.service.SsoSystemService;
 import com.jd.util.Blank;
 import com.jd.util.SendUtil;
-
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * SSO业务系统类
@@ -38,11 +37,79 @@ public class SsoSystemController {
     @GetMapping("/getSsoSystemList")
     @ApiOperation(value = "查询SSO业务系统列表")
     public Map<String, Object> getSsoSystemList(String userId) {
-//        if (Blank.isEmpty(userId)) {
-//            return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
-//        }
         Map<String, Object> map = new HashMap<>(4);
         map.put("userId", userId);
         return SendUtil.send(true, ConstString.RESULT_SUCCESS, ssoSystemService.getSsoSystemList(map));
     }
+
+    /**
+     * 获得sso系统列表页面
+     * @param page       页面
+     * @param limit      限制
+     * @param queryValue 查询值
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    @GetMapping("getSsoSystemListByPage")
+    @ApiOperation(value = "分页查询SSO业务系统列表")
+    public Map<String, Object> getSsoSystemListByPage(Integer page, Integer limit, String queryValue) {
+        if (Blank.isEmpty(page, limit)) {
+            return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
+        }
+        Map<String, Object> param = new HashMap<>(4);
+        param.put("start", (page - 1) * limit);
+        param.put("limit", limit);
+        param.put("queryValue", queryValue);
+        return ssoSystemService.getSsoSystemListByPage(param);
+    }
+
+    /**
+     * 插入sso系统
+     * @param ssoSystem sso系统
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    @PostMapping("insertSsoSystem")
+    @ApiOperation(value = "新增SSO业务系统")
+    public Map<String, Object> insertSsoSystem(SsoSystem ssoSystem) {
+        return ssoSystemService.insertSsoSystem(ssoSystem);
+    }
+
+    /**
+     * 更新sso系统
+     * @param ssoSystem sso系统
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    @PostMapping("updateSsoSystem")
+    @ApiOperation(value = "编辑SSO业务系统")
+    public Map<String, Object> updateSsoSystem(SsoSystem ssoSystem) {
+
+        return ssoSystemService.updateSsoSystem(ssoSystem);
+    }
+
+    /**
+     * 删除sso系统
+     * @param id id
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    @PostMapping("deleteSsoSystem")
+    @ApiOperation(value = "删除SSO业务系统")
+    public Map<String, Object> deleteSsoSystem(Integer id) {
+        if (Blank.isEmpty(id)) {
+            return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
+        }
+        return ssoSystemService.deleteSsoSystem(id);
+    }
+
+    /**
+     * 获得sso系统信息
+     * @param id id
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    @GetMapping("getSsoSystemInfo")
+    @ApiOperation(value = "查询SSO业务系统详情")
+    public Map<String, Object> getSsoSystemInfo(Integer id) {
+        if (Blank.isEmpty(id)) {
+            return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
+        }
+        return ssoSystemService.getSsoSystemInfo(id);
+    }
 }

+ 50 - 0
spring-cloud/server-basic/src/main/java/com/jd/mapper/SsoSystemMapper.java

@@ -3,6 +3,7 @@ package com.jd.mapper;
 import java.util.List;
 import java.util.Map;
 
+import com.jd.entity.basic.SsoSystem;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -27,4 +28,53 @@ public interface SsoSystemMapper {
      */
     Map<String, Object> getSsoSystemByClient(@Param("clientId") String clientId);
 
+    /**
+     * 获得sso系统统计列表
+     * @param param 参数
+     * @return {@link Integer}
+     */
+    Integer getSsoSystemListCount(Map<String, Object> param);
+
+    /**
+     * 获得sso系统列表页面
+     * @param param 参数
+     * @return {@link List}<{@link Map}<{@link String}, {@link Object}>>
+     */
+    List<Map<String, Object>> getSsoSystemListByPage(Map<String, Object> param);
+
+    /**
+     * 得到数名字
+     * @param name 名字
+     * @param id   id
+     * @return {@link Integer}
+     */
+    Integer getCountByName(@Param("name") String name, @Param("id") Integer id);
+
+    /**
+     * 插入sso系统
+     * @param ssoSystem sso系统
+     * @return boolean
+     */
+    boolean insertSsoSystem(SsoSystem ssoSystem);
+
+    /**
+     * 更新sso系统
+     * @param ssoSystem sso系统
+     * @return boolean
+     */
+    boolean updateSsoSystem(SsoSystem ssoSystem);
+
+    /**
+     * 删除sso系统
+     * @param id id
+     * @return boolean
+     */
+    boolean deleteSsoSystem(@Param("id") Integer id);
+
+    /**
+     * 获得sso系统信息
+     * @param id id
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    Map<String, Object> getSsoSystemInfo(Integer id);
 }

+ 7 - 0
spring-cloud/server-basic/src/main/java/com/jd/mapper/SsoUserMapper.java

@@ -67,4 +67,11 @@ public interface SsoUserMapper {
      * @return {@link Map}<{@link String}, {@link Object}>
      */
     Map<String, Object> getSsoUserInfo(@Param("userId") Integer userId);
+
+    /**
+     * 获得sso用户数
+     * @param systemId 系统Id
+     * @return {@link Integer}
+     */
+    Integer getSsoUserCount(@Param("systemId") Integer systemId);
 }

+ 37 - 0
spring-cloud/server-basic/src/main/java/com/jd/service/SsoSystemService.java

@@ -1,5 +1,7 @@
 package com.jd.service;
 
+import com.jd.entity.basic.SsoSystem;
+
 import java.util.List;
 import java.util.Map;
 
@@ -15,4 +17,39 @@ public interface SsoSystemService {
      * @return
      */
     List<Map<String, Object>> getSsoSystemList(Map<String, Object> param);
+
+    /**
+     * 获得sso系统列表页面
+     * @param param 参数
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    Map<String, Object> getSsoSystemListByPage(Map<String, Object> param);
+
+    /**
+     * 插入sso系统
+     * @param ssoSystem sso系统
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    Map<String, Object> insertSsoSystem(SsoSystem ssoSystem);
+
+    /**
+     * 更新sso系统
+     * @param ssoSystem sso系统
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    Map<String, Object> updateSsoSystem(SsoSystem ssoSystem);
+
+    /**
+     * 删除sso系统
+     * @param id id
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    Map<String, Object> deleteSsoSystem(Integer id);
+
+    /**
+     * 获得sso系统信息
+     * @param id id
+     * @return {@link Map}<{@link String}, {@link Object}>
+     */
+    Map<String, Object> getSsoSystemInfo(Integer id);
 }

+ 61 - 0
spring-cloud/server-basic/src/main/java/com/jd/service/impl/SsoSystemServiceImpl.java

@@ -5,6 +5,12 @@ import java.util.Map;
 
 import javax.annotation.Resource;
 
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import com.jd.code.ConstString;
+import com.jd.entity.basic.SsoSystem;
+import com.jd.mapper.SsoUserMapper;
+import com.jd.util.SendUtil;
 import org.springframework.stereotype.Service;
 
 import com.jd.mapper.SsoSystemMapper;
@@ -20,6 +26,9 @@ public class SsoSystemServiceImpl implements SsoSystemService {
     @Resource
     private SsoSystemMapper ssoSystemMapper;
 
+    @Resource
+    private SsoUserMapper ssoUserMapper;
+
     /**
      * 查询SSO业务系统列表
      * @param param
@@ -29,4 +38,56 @@ public class SsoSystemServiceImpl implements SsoSystemService {
     public List<Map<String, Object>> getSsoSystemList(Map<String, Object> param) {
         return ssoSystemMapper.getSsoSystemList(param);
     }
+
+    @Override
+    public Map<String, Object> getSsoSystemListByPage(Map<String, Object> param) {
+        Integer count = ssoSystemMapper.getSsoSystemListCount(param);
+        if (count < 1) {
+            return SendUtil.layuiTable(0, null);
+        }
+        List<Map<String, Object>> list = ssoSystemMapper.getSsoSystemListByPage(param);
+        return SendUtil.layuiTable(count, list);
+    }
+
+    @Override
+    public Map<String, Object> insertSsoSystem(SsoSystem ssoSystem) {
+        // 判断业务系统名称是否重复
+        Integer count = ssoSystemMapper.getCountByName(ssoSystem.getName(), null);
+        if (count > 0) {
+            return SendUtil.send(false, "业务系统名称重复");
+        }
+        // 随机生成appId
+        String appId = RandomUtil.randomStringUpper(10);
+        ssoSystem.setAppId(appId);
+        boolean flag = ssoSystemMapper.insertSsoSystem(ssoSystem);
+        return SendUtil.send(flag);
+    }
+
+    @Override
+    public Map<String, Object> updateSsoSystem(SsoSystem ssoSystem) {
+        // 判断业务系统名称是否重复
+        Integer count = ssoSystemMapper.getCountByName(ssoSystem.getName(), ssoSystem.getId());
+        if (count > 0) {
+            return SendUtil.send(false, "业务系统名称重复");
+        }
+        boolean flag = ssoSystemMapper.updateSsoSystem(ssoSystem);
+        return SendUtil.send(flag);
+    }
+
+    @Override
+    public Map<String, Object> deleteSsoSystem(Integer id) {
+        // 查询业务系统下用户数量
+        Integer count = ssoUserMapper.getSsoUserCount(id);
+        if (count > 0) {
+            return SendUtil.send(false, "SSO用户不为空");
+        }
+        boolean flag = ssoSystemMapper.deleteSsoSystem(id);
+        return SendUtil.send(flag);
+    }
+
+    @Override
+    public Map<String, Object> getSsoSystemInfo(Integer id) {
+        Map<String, Object> map = ssoSystemMapper.getSsoSystemInfo(id);
+        return SendUtil.send(true, ConstString.RESULT_SUCCESS, map);
+    }
 }

+ 64 - 0
spring-cloud/server-basic/src/main/resources/mapper/SsoSystemMapper.xml

@@ -25,4 +25,68 @@
         WHERE appid = #{clientId} LIMIT 1
     </select>
 
+    <select id="getSsoSystemListCount" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM sso_system
+        <where>
+            <if test="queryValue != null and queryValue != ''">
+                AND `name` LIKE concat('%', #{queryValue}, '%')
+            </if>
+        </where>
+    </select>
+
+    <select id="getSsoSystemListByPage" resultType="java.util.Map">
+        SELECT
+        sso_system.id,
+        sso_system.`name`,
+        sso_system.appid,
+        sso_system.redirect_url,
+        sso_system.title_img,
+        sso_system.create_time
+        FROM sso_system
+        <where>
+            <if test="queryValue != null and queryValue != ''">
+                AND `name` LIKE concat('%', #{queryValue}, '%')
+            </if>
+        </where>
+        LIMIT #{start}, #{limit}
+    </select>
+
+    <select id="getCountByName" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM sso_system
+        <where>
+            `name` = #{name}
+            <if test="id != null">
+                AND id != #{id}
+            </if>
+        </where>
+    </select>
+
+    <insert id="insertSsoSystem">
+        INSERT INTO sso_system(`name`, `appid`, `redirect_url`, `title_img`, `create_time`)
+        VALUES (#{name}, #{appId}, #{redirectUrl}, #{titleImg}, NOW())
+    </insert>
+
+    <update id="updateSsoSystem">
+        UPDATE sso_system
+        <set>
+            `name` = #{name},
+            `redirect_url` = #{redirectUrl},
+            `title_img` = #{titleImg}
+        </set>
+        WHERE id = #{id}
+    </update>
+
+    <delete id="deleteSsoSystem">
+        DELETE
+        FROM sso_system
+        WHERE id = #{id}
+    </delete>
+
+    <select id="getSsoSystemInfo" resultType="java.util.Map">
+        SELECT *
+        FROM sso_system
+        WHERE id = #{id}
+    </select>
 </mapper>

+ 6 - 0
spring-cloud/server-basic/src/main/resources/mapper/SsoUserMapper.xml

@@ -125,4 +125,10 @@
         FROM sso_user
         WHERE user_id = #{userId} LIMIT 1
     </select>
+
+    <select id="getSsoUserCount" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM sso_user
+        WHERE system_id = #{systemId}
+    </select>
 </mapper>