();
String username = JwtUtil.getUsername(token);
-
+
//1. 校验用户是否有效
SysUser sysUser = sysUserService.getUserByName(username);
result = sysUserService.checkUserIsEffective(sysUser);
@@ -277,4 +272,118 @@ public class ThirdLoginController {
result.setResult(token);
return result;
}
+
+ /**
+ * 企业微信/钉钉 OAuth2登录
+ *
+ * @param source
+ * @param state
+ * @return
+ */
+ @ResponseBody
+ @GetMapping("/oauth2/{source}/login")
+ public String oauth2LoginCallback(@PathVariable("source") String source, @RequestParam("state") String state, HttpServletResponse response) throws Exception {
+ String url;
+ if (ThirdAppConfig.WECHAT_ENTERPRISE.equalsIgnoreCase(source)) {
+ ThirdAppTypeItemVo config = thirdAppConfig.getWechatEnterprise();
+ StringBuilder builder = new StringBuilder();
+ // 构造企业微信OAuth2登录授权地址
+ builder.append("https://open.weixin.qq.com/connect/oauth2/authorize");
+ // 企业的CorpID
+ builder.append("?appid=").append(config.getClientId());
+ // 授权后重定向的回调链接地址,请使用urlencode对链接进行处理
+ String redirectUri = RestUtil.getBaseUrl() + "/sys/thirdLogin/oauth2/wechat_enterprise/callback";
+ builder.append("&redirect_uri=").append(URLEncoder.encode(redirectUri, "UTF-8"));
+ // 返回类型,此时固定为:code
+ builder.append("&response_type=code");
+ // 应用授权作用域。
+ // snsapi_base:静默授权,可获取成员的的基础信息(UserId与DeviceId);
+ builder.append("&scope=snsapi_base");
+ // 重定向后会带上state参数,长度不可超过128个字节
+ builder.append("&state=").append(state);
+ // 终端使用此参数判断是否需要带上身份信息
+ builder.append("#wechat_redirect");
+ url = builder.toString();
+ } else if (ThirdAppConfig.DINGTALK.equalsIgnoreCase(source)) {
+ ThirdAppTypeItemVo config = thirdAppConfig.getDingtalk();
+ StringBuilder builder = new StringBuilder();
+ // 构造钉钉OAuth2登录授权地址
+ builder.append("https://login.dingtalk.com/oauth2/auth");
+ // 授权通过/拒绝后回调地址。
+ // 注意 需要与注册应用时登记的域名保持一致。
+ String redirectUri = RestUtil.getBaseUrl() + "/sys/thirdLogin/oauth2/dingtalk/callback";
+ builder.append("?redirect_uri=").append(URLEncoder.encode(redirectUri, "UTF-8"));
+ // 固定值为code。
+ // 授权通过后返回authCode。
+ builder.append("&response_type=code");
+ // 步骤一中创建的应用详情中获取。
+ // 企业内部应用:client_id为应用的AppKey。
+ builder.append("&client_id=").append(config.getClientId());
+ // 授权范围,授权页面显示的授权信息以应用注册时配置的为准。
+ // openid:授权后可获得用户userid
+ builder.append("&scope=openid");
+ // 跟随authCode原样返回。
+ builder.append("&state=").append(state);
+ url = builder.toString();
+ } else {
+ return "不支持的source";
+ }
+ log.info("oauth2 login url:" + url);
+ response.sendRedirect(url);
+ return "login…";
+ }
+
+ /**
+ * 企业微信/钉钉 OAuth2登录回调
+ *
+ * @param code
+ * @param state
+ * @param response
+ * @return
+ */
+ @ResponseBody
+ @GetMapping("/oauth2/{source}/callback")
+ public String oauth2LoginCallback(
+ @PathVariable("source") String source,
+ // 企业微信返回的code
+ @RequestParam(value = "code", required = false) String code,
+ // 钉钉返回的code
+ @RequestParam(value = "authCode", required = false) String authCode,
+ @RequestParam("state") String state,
+ HttpServletResponse response
+ ) {
+ SysUser loginUser;
+ if (ThirdAppConfig.WECHAT_ENTERPRISE.equalsIgnoreCase(source)) {
+ log.info("【企业微信】OAuth2登录进入callback:code=" + code + ", state=" + state);
+ loginUser = thirdAppWechatEnterpriseService.oauth2Login(code);
+ if (loginUser == null) {
+ return "登录失败";
+ }
+ } else if (ThirdAppConfig.DINGTALK.equalsIgnoreCase(source)) {
+ log.info("【钉钉】OAuth2登录进入callback:authCode=" + authCode + ", state=" + state);
+ loginUser = thirdAppDingtalkService.oauth2Login(authCode);
+ if (loginUser == null) {
+ return "登录失败";
+ }
+ } else {
+ return "不支持的source";
+ }
+ try {
+ String token = saveToken(loginUser);
+ state += "/oauth2-app/login?oauth2LoginToken=" + URLEncoder.encode(token, "UTF-8");
+ state += "&thirdType=" + "wechat_enterprise";
+ log.info("OAuth2登录重定向地址: " + state);
+ try {
+ response.sendRedirect(state);
+ return "ok";
+ } catch (IOException e) {
+ e.printStackTrace();
+ return "重定向失败";
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return "解码失败";
+ }
+ }
+
}
\ No newline at end of file
diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java
index ab35a5d2..1753b413 100644
--- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java
+++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java
@@ -1,20 +1,20 @@
package org.jeecg.modules.system.mapper;
-import java.util.List;
-import java.util.Map;
-
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.common.system.vo.DictModel;
+import org.jeecg.common.system.vo.DictModelMany;
import org.jeecg.common.system.vo.DictQuery;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.model.DuplicateCheckVo;
import org.jeecg.modules.system.model.TreeSelectModel;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import java.util.List;
+import java.util.Map;
/**
*
@@ -30,11 +30,29 @@ public interface SysDictMapper extends BaseMapper {
* 重复检查SQL
* @return
*/
+ @Deprecated
public Long duplicateCheckCountSql(DuplicateCheckVo duplicateCheckVo);
+ @Deprecated
public Long duplicateCheckCountSqlNoDataId(DuplicateCheckVo duplicateCheckVo);
public List queryDictItemsByCode(@Param("code") String code);
+ /**
+ * 查询有效的数据字典项
+ * @param code
+ * @return
+ */
+ List queryEnableDictItemsByCode(@Param("code") String code);
+
+
+ /**
+ * 通过多个字典code获取字典数据
+ *
+ * @param dictCodeList
+ * @return
+ */
+ public List queryDictItemsByCodeList(@Param("dictCodeList") List dictCodeList);
+
@Deprecated
public List queryTableDictItemsByCode(@Param("table") String table,@Param("text") String text,@Param("code") String code);
@@ -47,9 +65,29 @@ public interface SysDictMapper extends BaseMapper {
public String queryDictTextByKey(@Param("code") String code,@Param("key") String key);
+ /**
+ * 可通过多个字典code查询翻译文本
+ * @param dictCodeList 多个字典code
+ * @param keys 数据列表
+ * @return
+ */
+ List queryManyDictByKeys(@Param("dictCodeList") List dictCodeList, @Param("keys") List keys);
+
@Deprecated
public String queryTableDictTextByKey(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("key") String key);
+ /**
+ * 通过查询指定table的 text code key 获取字典值,可批量查询
+ *
+ * @param table
+ * @param text
+ * @param code
+ * @param keys
+ * @return
+ */
+ @Deprecated
+ List queryTableDictTextByKeys(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("keys") List keys);
+
@Deprecated
public List queryTableDictByKeys(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("keyArray") String[] keyArray);
@@ -142,6 +180,7 @@ public interface SysDictMapper extends BaseMapper {
* @param filterSql
* @return
*/
+ @Deprecated
IPage queryTableDictWithFilter(Page page, @Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("filterSql") String filterSql);
/**
@@ -152,5 +191,6 @@ public interface SysDictMapper extends BaseMapper {
* @param filterSql
* @return
*/
+ @Deprecated
List queryAllTableDictItems(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("filterSql") String filterSql);
}
diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java
index bdaca9b3..5ae50449 100644
--- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java
+++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java
@@ -131,6 +131,7 @@ public interface SysUserMapper extends BaseMapper {
int deleteLogicDeleted(@Param("userIds") String userIds);
/** 更新空字符串为null【此写法有sql注入风险,禁止随便用】 */
+ @Deprecated
int updateNullByEmptyString(@Param("fieldName") String fieldName);
/**
diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml
index 5ec72068..a942b6ba 100644
--- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml
+++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml
@@ -8,7 +8,32 @@
where dict_id = (select id from sys_dict where dict_code = #{code})
order by s.sort_order asc
-
+
+
+
+
+
+
+
+
+
+
+
+