Merge remote-tracking branch 'origin/main'

main
weitingdong 1 year ago
commit 99a0284588
  1. 4
      src/main/java/org/energy/core/secure/AuthInfo.java
  2. 19
      src/main/java/org/energy/modules/auth/controller/AuthController.java
  3. 78
      src/main/java/org/energy/modules/auth/granter/ScadaTokenGranter.java
  4. 1
      src/main/java/org/energy/modules/auth/granter/TokenGranterBuilder.java
  5. 25
      src/main/java/org/energy/modules/auth/properties/ScadaAuthProperties.java
  6. 38
      src/main/java/org/energy/modules/auth/response/ShareAuthResponse.java
  7. 31
      src/main/java/org/energy/modules/auth/utils/AesUtil.java
  8. 1
      src/main/java/org/energy/modules/auth/utils/TokenUtil.java
  9. 6
      src/main/java/org/energy/modules/smart/entity/WorkOrder.java
  10. 10
      src/main/java/org/energy/modules/smart/mapper/WorkOrderMapper.xml
  11. 7
      src/main/java/org/energy/modules/system/entity/UserInfo.java
  12. 2
      src/main/java/org/energy/modules/system/service/IUserService.java
  13. 26
      src/main/java/org/energy/modules/system/service/impl/UserServiceImpl.java
  14. 15
      src/main/resources/application-dev.yml

@ -20,6 +20,9 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.energy.modules.system.vo.MenuVO;
import java.util.List;
/** /**
* AuthInfo * AuthInfo
@ -54,4 +57,5 @@ public class AuthInfo {
private long expiresIn; private long expiresIn;
@ApiModelProperty(value = "许可证") @ApiModelProperty(value = "许可证")
private String license = "powered by daf"; private String license = "powered by daf";
private List<MenuVO> roleMenus;
} }

@ -34,6 +34,7 @@ import org.energy.modules.auth.granter.TokenParameter;
import org.energy.modules.auth.utils.TokenUtil; import org.energy.modules.auth.utils.TokenUtil;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -50,6 +51,7 @@ public class AuthController {
private RedisUtil redisUtil; private RedisUtil redisUtil;
@PostMapping("token") @PostMapping("token")
@ApiOperation(value = "获取认证token", notes = "传入租户ID:tenantId,账号:account,密码:password") @ApiOperation(value = "获取认证token", notes = "传入租户ID:tenantId,账号:account,密码:password")
public R<AuthInfo> token(@ApiParam(value = "授权类型", required = true) @RequestParam(defaultValue = "password", required = false) String grantType, public R<AuthInfo> token(@ApiParam(value = "授权类型", required = true) @RequestParam(defaultValue = "password", required = false) String grantType,
@ -90,4 +92,21 @@ public class AuthController {
return R.data(Kv.init().set("key", key).set("image", specCaptcha.toBase64())); return R.data(Kv.init().set("key", key).set("image", specCaptcha.toBase64()));
} }
@PostMapping("scada-token")
@ApiOperation(value = "获取认证scada-token", notes = "传入")
public R<AuthInfo> token2(@ApiParam(value = "租户ID", required = true) @RequestParam(defaultValue = "000000", required = false) String tenantId,
@ApiParam(value = "token") @RequestParam(required = false) String token) {
String grantType = "scada";
TokenParameter tokenParameter = new TokenParameter();
tokenParameter.getArgs().set("tenantId", tenantId).set("grantType", grantType).set("token", token);
ITokenGranter granter = TokenGranterBuilder.getGranter(grantType);
UserInfo userInfo = granter.grant(tokenParameter);
if (userInfo == null || userInfo.getUser() == null) {
return R.fail(TokenUtil.USER_NOT_FOUND);
}
// success
return R.data(TokenUtil.createAuthInfo(userInfo));
}
} }

@ -0,0 +1,78 @@
/**
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.energy.modules.auth.granter;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONUtil;
import com.dayu.daf.core.launch.constant.TokenConstant;
import com.dayu.daf.core.log.exception.ServiceException;
import com.dayu.daf.core.tool.utils.Func;
import lombok.AllArgsConstructor;
import org.energy.modules.auth.properties.ScadaAuthProperties;
import org.energy.modules.auth.response.ShareAuthResponse;
import org.energy.modules.auth.utils.AesUtil;
import org.energy.modules.auth.utils.TokenUtil;
import org.energy.modules.system.entity.UserInfo;
import org.energy.modules.system.service.IUserService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
/**
* ScadaTokenGranter
*
* @author Chill
*/
@Component
@AllArgsConstructor
public class ScadaTokenGranter implements ITokenGranter {
public static final String GRANT_TYPE = "scada";
private IUserService userService;
@Resource
private ScadaAuthProperties properties;
@Override
public UserInfo grant(TokenParameter tokenParameter) {
String token = tokenParameter.getArgs().getStr("token");
String tenantId = tokenParameter.getArgs().getStr("tenantId");
UserInfo userInfo = null;
if (Func.isNoneBlank(token)) {
byte[] tokenByte = Base64.decode(token);
String decrypt = AesUtil.decrypt(tokenByte, properties.getScadaKey(), properties.getScadaIv());
if (StrUtil.isBlank(decrypt)) {
throw new ServiceException("授权错误");
}
ShareAuthResponse response = BeanUtil.toBean(JSONUtil.parse(decrypt), ShareAuthResponse.class);
if (DateUtil.compare(new Date(), DateUtil.parseDate(response.getExpires())) > 0) {
throw new ServiceException("token过期,请重新登录。");
}
String account = response.getUserName();
userInfo = userService.userInfo(tenantId, account);
} else {
throw new ServiceException("token错误");
}
return userInfo;
}
}

@ -41,6 +41,7 @@ public class TokenGranterBuilder {
GRANTER_POOL.put(CaptchaTokenGranter.GRANT_TYPE, SpringUtil.getBean(CaptchaTokenGranter.class)); GRANTER_POOL.put(CaptchaTokenGranter.GRANT_TYPE, SpringUtil.getBean(CaptchaTokenGranter.class));
GRANTER_POOL.put(RefreshTokenGranter.GRANT_TYPE, SpringUtil.getBean(RefreshTokenGranter.class)); GRANTER_POOL.put(RefreshTokenGranter.GRANT_TYPE, SpringUtil.getBean(RefreshTokenGranter.class));
GRANTER_POOL.put(SocialTokenGranter.GRANT_TYPE, SpringUtil.getBean(SocialTokenGranter.class)); GRANTER_POOL.put(SocialTokenGranter.GRANT_TYPE, SpringUtil.getBean(SocialTokenGranter.class));
GRANTER_POOL.put(ScadaTokenGranter.GRANT_TYPE, SpringUtil.getBean(ScadaTokenGranter.class));
} }
/** /**

@ -0,0 +1,25 @@
package org.energy.modules.auth.properties;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
/**
* 配置类
*
* @author dayu
*/
@Component
@Data
public class ScadaAuthProperties {
@Value("${sso.scada.key}")
private String scadaKey;
@Value("${sso.scada.iv}")
private String scadaIv;
}

@ -0,0 +1,38 @@
package org.energy.modules.auth.response;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* 分享链接鉴权返回值
*
* @author dayu
* @since 2024/7/2 16:54
*/
@Getter
@Setter
@ToString
public class ShareAuthResponse {
/**
* 用户唯一凭证
*/
private String uid;
/**
* 用户名称
*/
private String userName;
/**
* 角色名称
*/
private String roleName;
/**
* 有效期
*/
private String expires;
}

@ -0,0 +1,31 @@
package org.energy.modules.auth.utils;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import lombok.extern.slf4j.Slf4j;
/**
* Aes 加解密工具类
*
* @author dayu
**/
@Slf4j
public class AesUtil {
/**
* 解密
*/
public static String decrypt(byte[] content, String key, String iv) {
AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, key.getBytes());
aes.setIv(iv.getBytes());
try {
byte[] decryptedBytes = aes.decrypt(content);
return new String(decryptedBytes);
} catch (Exception e) {
log.warn("解密失败", e);
return null;
}
}
}

@ -79,6 +79,7 @@ public class TokenUtil {
authInfo.setRefreshToken(createRefreshToken(userInfo).getToken()); authInfo.setRefreshToken(createRefreshToken(userInfo).getToken());
authInfo.setTokenType(TokenConstant.BEARER); authInfo.setTokenType(TokenConstant.BEARER);
authInfo.setLicense(TokenConstant.LICENSE_NAME); authInfo.setLicense(TokenConstant.LICENSE_NAME);
authInfo.setRoleMenus(userInfo.getRoleMenus());
return authInfo; return authInfo;
} }

@ -75,9 +75,8 @@ public class WorkOrder extends BaseEntity {
/** /**
* 维护作业类型 * 维护作业类型
*/ */
@JsonSerialize(nullsUsing = NullSerializer.class)
@ApiModelProperty(value = "维护作业类型") @ApiModelProperty(value = "维护作业类型")
private Integer maintenanceTaskType; private String maintenanceTaskType;
/** /**
* 用户状态 * 用户状态
*/ */
@ -117,9 +116,8 @@ public class WorkOrder extends BaseEntity {
/** /**
* 处理结果 * 处理结果
*/ */
@JsonSerialize(nullsUsing = NullSerializer.class)
@ApiModelProperty(value = "处理结果") @ApiModelProperty(value = "处理结果")
private Integer handlingResult; private String handlingResult;
/** /**
* 审核状态 * 审核状态
*/ */

@ -55,10 +55,10 @@
and a.work_order_type = #{vo.workOrderType} and a.work_order_type = #{vo.workOrderType}
</if> </if>
<if test="vo.workOrderNo != null and vo.workOrderNo != ''"> <if test="vo.workOrderNo != null and vo.workOrderNo != ''">
and a.work_order_no = #{vo.workOrderNo} and a.work_order_no LIKE CONCAT('%', #{vo.workOrderNo}, '%')
</if> </if>
<if test="vo.description != null and vo.description != ''"> <if test="vo.description != null and vo.description != ''">
and a.description = #{vo.description} and a.description LIKE CONCAT('%', #{vo.description}, '%')
</if> </if>
<if test="vo.maintenanceTaskType != null and vo.maintenanceTaskType != ''"> <if test="vo.maintenanceTaskType != null and vo.maintenanceTaskType != ''">
and a.maintenance_task_type = #{vo.maintenanceTaskType} and a.maintenance_task_type = #{vo.maintenanceTaskType}
@ -67,7 +67,7 @@
and a.user_status = #{vo.userStatus} and a.user_status = #{vo.userStatus}
</if> </if>
<if test="vo.responsibilityTeam != null and vo.responsibilityTeam != ''"> <if test="vo.responsibilityTeam != null and vo.responsibilityTeam != ''">
and a.responsibility_team = #{vo.responsibilityTeam} and a.responsibility_team LIKE CONCAT('%', #{vo.responsibilityTeam}, '%')
</if> </if>
<if test="vo.station != null and vo.station != ''"> <if test="vo.station != null and vo.station != ''">
and b.station = ${vo.station} and b.station = ${vo.station}
@ -109,7 +109,7 @@
and a.work_order_no LIKE CONCAT('%', #{vo.workOrderNo}, '%') and a.work_order_no LIKE CONCAT('%', #{vo.workOrderNo}, '%')
</if> </if>
<if test="vo.description != null and vo.description != ''"> <if test="vo.description != null and vo.description != ''">
and a.description = LIKE CONCAT('%', #{vo.description}, '%') and a.description LIKE CONCAT('%', #{vo.description}, '%')
</if> </if>
<if test="vo.maintenanceTaskType != null and vo.maintenanceTaskType != ''"> <if test="vo.maintenanceTaskType != null and vo.maintenanceTaskType != ''">
and a.maintenance_task_type = #{vo.maintenanceTaskType} and a.maintenance_task_type = #{vo.maintenanceTaskType}
@ -118,7 +118,7 @@
and a.user_status = #{vo.userStatus} and a.user_status = #{vo.userStatus}
</if> </if>
<if test="vo.responsibilityTeam != null and vo.responsibilityTeam != ''"> <if test="vo.responsibilityTeam != null and vo.responsibilityTeam != ''">
and a.responsibility_team = LIKE CONCAT('%', #{vo.responsibilityTeam}, '%') and a.responsibility_team LIKE CONCAT('%', #{vo.responsibilityTeam}, '%')
</if> </if>
<if test="vo.station != null and vo.station != ''"> <if test="vo.station != null and vo.station != ''">
and b.station = ${vo.station} and b.station = ${vo.station}

@ -18,6 +18,7 @@ package org.energy.modules.system.entity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.energy.modules.system.vo.MenuVO;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -57,4 +58,10 @@ public class UserInfo implements Serializable {
@ApiModelProperty(value = "第三方授权id") @ApiModelProperty(value = "第三方授权id")
private String oauthId; private String oauthId;
/**
* 角色菜单
*/
@ApiModelProperty(value = "角色菜单")
private List<MenuVO> roleMenus;
} }

@ -147,4 +147,6 @@ public interface IUserService extends BaseService<User> {
User selectByIdAndDel(Long createUser); User selectByIdAndDel(Long createUser);
User selectByAccountAndDel(String account); User selectByAccountAndDel(String account);
UserInfo userInfo(String tenantId, String account);
} }

@ -17,10 +17,12 @@ package org.energy.modules.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dayu.daf.core.log.exception.ServiceException; import com.dayu.daf.core.log.exception.ServiceException;
import com.dayu.daf.core.mp.base.BaseServiceImpl; import com.dayu.daf.core.mp.base.BaseServiceImpl;
import com.dayu.daf.core.tool.constant.DafConstant;
import com.dayu.daf.core.tool.utils.*; import com.dayu.daf.core.tool.utils.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.energy.common.constant.CommonConstant; import org.energy.common.constant.CommonConstant;
@ -33,6 +35,9 @@ import org.energy.modules.system.mapper.UserMapper;
import org.energy.modules.system.service.*; import org.energy.modules.system.service.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.energy.modules.system.service.IMenuService;
import org.energy.modules.system.vo.MenuVO;
import com.dayu.daf.core.secure.DafUser;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -54,6 +59,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
private IRoleService roleService; private IRoleService roleService;
private IUserOauthService userOauthService; private IUserOauthService userOauthService;
private ITenantService tenantService; private ITenantService tenantService;
private IMenuService menuService;
@Override @Override
public boolean submit(User user) { public boolean submit(User user) {
@ -93,6 +99,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
List<String> roleAlias = baseMapper.getRoleAlias(Func.toLongList(user.getRoleId())); List<String> roleAlias = baseMapper.getRoleAlias(Func.toLongList(user.getRoleId()));
userInfo.setRoles(roleAlias); userInfo.setRoles(roleAlias);
} }
List<MenuVO> list = menuService.routes(userInfo.getUser().getRoleId());
userInfo.setRoleMenus(list);
return userInfo; return userInfo;
} }
@ -216,4 +224,22 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
public User selectByAccountAndDel(String account) { public User selectByAccountAndDel(String account) {
return baseMapper.selectByAccountAndDel(account); return baseMapper.selectByAccountAndDel(account);
} }
@Override
public UserInfo userInfo(String tenantId, String account) {
UserInfo userInfo = new UserInfo();
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.lambda().eq(User::getTenantId, tenantId);
userQueryWrapper.lambda().eq(User::getAccount, account);
userQueryWrapper.lambda().eq(User::getIsDeleted, DafConstant.DB_NOT_DELETED);
User user = super.getOne(userQueryWrapper);
userInfo.setUser(user);
if (Func.isNotEmpty(user)) {
List<String> roleAlias = baseMapper.getRoleAlias(Func.toLongList(user.getRoleId()));
userInfo.setRoles(roleAlias);
}
List<MenuVO> list = menuService.routes(userInfo.getUser().getRoleId());
userInfo.setRoleMenus(list);
return userInfo;
}
} }

@ -12,10 +12,15 @@ spring:
# nodes: 127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003 # nodes: 127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003
# commandTimeout: 5000 # commandTimeout: 5000
datasource: datasource:
# url: jdbc:postgresql://4s27589o64.vicp.fun:32355/om?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
url: jdbc:postgresql://192.168.10.102:5432/om?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8 url: jdbc:postgresql://192.168.10.102:5432/om?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
username: admin username: admin
password: 123456 password: 123456
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
# url: jdbc:mysql://localhost:3306/sys?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
# username: root
# password: 123456
# driver-class-name: com.mysql.cj.jdbc.Driver
#第三方登陆 #第三方登陆
social: social:
@ -30,3 +35,13 @@ daf:
remote-path: /usr/share/nginx/html remote-path: /usr/share/nginx/html
remote-path-iis: D://iis/html remote-path-iis: D://iis/html
log-mode: true log-mode: true
#存放路径
file:
upload_path: c:\\data\\actual\\ #文件上传目录(不配置的话为java.io.tmpdir目录)
#sso配置
sso:
scada:
key: )O[WH]6,YF}+efcaj{+oESb9d8>Z'e9M
iv: L+\~f4,Wh)b$=pkf

Loading…
Cancel
Save