优化不联网
This commit is contained in:
@@ -1,39 +1,15 @@
|
||||
package top.wms.admin.auth.handler;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.xkcoding.justauth.AuthRequestFactory;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.wms.admin.auth.AbstractLoginHandler;
|
||||
import top.wms.admin.auth.enums.AuthTypeEnum;
|
||||
import top.wms.admin.auth.model.req.SocialLoginReq;
|
||||
import top.wms.admin.auth.model.resp.LoginResp;
|
||||
import top.wms.admin.common.constant.RegexConstants;
|
||||
import top.wms.admin.common.constant.SysConstants;
|
||||
import top.wms.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.wms.admin.common.enums.GenderEnum;
|
||||
import top.wms.admin.system.model.entity.RoleDO;
|
||||
import top.wms.admin.system.model.entity.UserDO;
|
||||
import top.wms.admin.system.model.entity.UserSocialDO;
|
||||
import top.wms.admin.system.model.resp.ClientResp;
|
||||
import top.wms.admin.system.service.UserRoleService;
|
||||
import top.wms.admin.system.service.UserSocialService;
|
||||
import top.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
import top.continew.starter.core.exception.BadRequestException;
|
||||
import top.continew.starter.core.validation.ValidationUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* 第三方账号登录处理器
|
||||
@@ -46,57 +22,10 @@ import java.util.Collections;
|
||||
@RequiredArgsConstructor
|
||||
public class SocialLoginHandler extends AbstractLoginHandler<SocialLoginReq> {
|
||||
|
||||
private final AuthRequestFactory authRequestFactory;
|
||||
private final UserSocialService userSocialService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final ProjectProperties projectProperties;
|
||||
|
||||
@Override
|
||||
public LoginResp login(SocialLoginReq req, ClientResp client, HttpServletRequest request) {
|
||||
// 获取第三方登录信息
|
||||
AuthRequest authRequest = this.getAuthRequest(req.getSource());
|
||||
AuthCallback callback = new AuthCallback();
|
||||
callback.setCode(req.getCode());
|
||||
callback.setState(req.getState());
|
||||
AuthResponse<AuthUser> response = authRequest.login(callback);
|
||||
ValidationUtils.throwIf(!response.ok(), response.getMsg());
|
||||
AuthUser authUser = response.getData();
|
||||
// 如未绑定则自动注册新用户,保存或更新关联信息
|
||||
String source = authUser.getSource();
|
||||
String openId = authUser.getUuid();
|
||||
UserSocialDO userSocial = userSocialService.getBySourceAndOpenId(source, openId);
|
||||
UserDO user;
|
||||
if (null == userSocial) {
|
||||
String username = authUser.getUsername();
|
||||
UserDO existsUser = userService.getByUsername(username);
|
||||
String randomStr = RandomUtil.randomString(RandomUtil.BASE_CHAR, 5);
|
||||
if (null != existsUser || !ReUtil.isMatch(RegexConstants.USERNAME, username)) {
|
||||
username = randomStr + IdUtil.fastSimpleUUID();
|
||||
}
|
||||
user = new UserDO();
|
||||
user.setUsername(username);
|
||||
user.setGender(GenderEnum.valueOf(authUser.getGender().name()));
|
||||
user.setAvatar(authUser.getAvatar());
|
||||
user.setStatus(DisEnableStatusEnum.ENABLE);
|
||||
userService.save(user);
|
||||
Long userId = user.getId();
|
||||
RoleDO role = roleService.getByCode(SysConstants.SUPER_ROLE_CODE);
|
||||
userRoleService.assignRolesToUser(Collections.singletonList(role.getId()), userId);
|
||||
userSocial = new UserSocialDO();
|
||||
userSocial.setUserId(userId);
|
||||
userSocial.setSource(source);
|
||||
userSocial.setOpenId(openId);
|
||||
} else {
|
||||
user = BeanUtil.copyProperties(userService.getById(userSocial.getUserId()), UserDO.class);
|
||||
}
|
||||
// 检查用户状态
|
||||
super.checkUserStatus(user);
|
||||
userSocial.setMetaJson(JSONUtil.toJsonStr(authUser));
|
||||
userSocial.setLastLoginTime(LocalDateTime.now());
|
||||
userSocialService.saveOrUpdate(userSocial);
|
||||
// 执行认证
|
||||
String token = super.authenticate(user, client);
|
||||
return LoginResp.builder().token(token).build();
|
||||
// 第三方登录已禁用
|
||||
throw new BadRequestException("第三方登录功能已禁用");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,18 +41,4 @@ public class SocialLoginHandler extends AbstractLoginHandler<SocialLoginReq> {
|
||||
return AuthTypeEnum.SOCIAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 AuthRequest
|
||||
*
|
||||
* @param source 平台名称
|
||||
* @return AuthRequest
|
||||
*/
|
||||
private AuthRequest getAuthRequest(String source) {
|
||||
try {
|
||||
return authRequestFactory.get(source);
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException("暂不支持 [%s] 平台账号登录".formatted(source));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,5 +24,6 @@ public interface MaterialInfoMapper extends BaseMapper<MaterialInfoDO> {
|
||||
|
||||
public int updateByCode(List<MaterialInfoDO> list);
|
||||
|
||||
IPage<MaterialInfoResp> selectMaterialInfoPage(@Param("page") Page<Object> objectPage, @Param(Constants.WRAPPER) QueryWrapper<MaterialInfoDO> queryWrapper);
|
||||
IPage<MaterialInfoResp> selectMaterialInfoPage(@Param("page") Page<Object> objectPage,
|
||||
@Param(Constants.WRAPPER) QueryWrapper<MaterialInfoDO> queryWrapper);
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ public class MaterialInfoDO extends BaseDO {
|
||||
*/
|
||||
private String photoUrl;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 物料类型ID
|
||||
*/
|
||||
private Long materialTypeId;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 流程ID
|
||||
*/
|
||||
private Long materialProcessId;
|
||||
|
||||
@@ -59,14 +59,14 @@ public class MaterialInfoReq implements Serializable {
|
||||
@Length(max = 255, message = "物料照片地址长度不能超过 {max} 个字符")
|
||||
private String photoUrl;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 物料类型ID
|
||||
*/
|
||||
@Schema(description = "物料类型ID")
|
||||
@NotNull(message = "物料类型ID不能为空")
|
||||
private Long materialTypeId;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 流程ID
|
||||
*/
|
||||
@Schema(description = "流程ID")
|
||||
|
||||
@@ -48,9 +48,6 @@ import top.wms.admin.material.model.resp.MaterialInfoImportResp;
|
||||
import top.wms.admin.material.model.resp.MaterialInfoResp;
|
||||
import top.wms.admin.material.service.MaterialInfoService;
|
||||
import top.wms.admin.system.service.FileService;
|
||||
import top.wms.admin.weighManage.model.entity.WorkOrderDO;
|
||||
import top.wms.admin.weighManage.model.query.WorkOrderQuery;
|
||||
import top.wms.admin.weighManage.model.resp.WorkOrderResp;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -90,12 +87,11 @@ public class MaterialInfoServiceImpl extends BaseServiceImpl<MaterialInfoMapper,
|
||||
this.sort(queryWrapper, pageQuery);
|
||||
|
||||
IPage<MaterialInfoResp> page = baseMapper.selectMaterialInfoPage(new Page<>(pageQuery.getPage(), pageQuery
|
||||
.getSize()), queryWrapper);
|
||||
.getSize()), queryWrapper);
|
||||
|
||||
return PageResp.build(page);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MaterialInfoDO getMaterialInfoByCode(String code) {
|
||||
if (StrUtil.isNotBlank(code)) {
|
||||
|
||||
@@ -5,11 +5,11 @@ import top.wms.admin.materialProcess.model.entity.MaterialProcessDO;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 海康物料流程 Mapper
|
||||
*
|
||||
* @author zc
|
||||
* @since 2026/03/16 17:22
|
||||
*/
|
||||
* 海康物料流程 Mapper
|
||||
*
|
||||
* @author zc
|
||||
* @since 2026/03/16 17:22
|
||||
*/
|
||||
@Repository
|
||||
public interface MaterialProcessMapper extends BaseMapper<MaterialProcessDO> {
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import top.continew.starter.extension.crud.model.resp.LabelValueResp;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
import top.wms.admin.materialProcess.model.query.MaterialProcessQuery;
|
||||
import top.wms.admin.materialProcess.model.req.MaterialProcessReq;
|
||||
import top.wms.admin.materialProcess.model.resp.MaterialProcessDetailResp;
|
||||
import top.wms.admin.materialProcess.model.resp.MaterialProcessResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -5,11 +5,11 @@ import top.wms.admin.materialType.model.entity.MaterialTypeDO;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 物料品类 Mapper
|
||||
*
|
||||
* @author zc
|
||||
* @since 2026/03/16 11:18
|
||||
*/
|
||||
* 物料品类 Mapper
|
||||
*
|
||||
* @author zc
|
||||
* @since 2026/03/16 11:18
|
||||
*/
|
||||
@Repository
|
||||
public interface MaterialTypeMapper extends BaseMapper<MaterialTypeDO> {
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import top.continew.starter.extension.crud.model.resp.LabelValueResp;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
import top.wms.admin.materialType.model.query.MaterialTypeQuery;
|
||||
import top.wms.admin.materialType.model.req.MaterialTypeReq;
|
||||
import top.wms.admin.materialType.model.resp.MaterialTypeDetailResp;
|
||||
import top.wms.admin.materialType.model.resp.MaterialTypeResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,7 +12,6 @@ import top.wms.admin.materialType.mapstruct.MaterialTypeConvert;
|
||||
import top.wms.admin.materialType.model.entity.MaterialTypeDO;
|
||||
import top.wms.admin.materialType.model.query.MaterialTypeQuery;
|
||||
import top.wms.admin.materialType.model.req.MaterialTypeReq;
|
||||
import top.wms.admin.materialType.model.resp.MaterialTypeDetailResp;
|
||||
import top.wms.admin.materialType.model.resp.MaterialTypeResp;
|
||||
import top.wms.admin.materialType.service.MaterialTypeService;
|
||||
|
||||
@@ -30,7 +29,6 @@ public class MaterialTypeServiceImpl extends BaseServiceImpl<MaterialTypeMapper,
|
||||
|
||||
private final MaterialTypeConvert materialTypeConvert;
|
||||
|
||||
|
||||
@Override
|
||||
public List<LabelValueResp> getSelectList() {
|
||||
List<MaterialTypeDO> materialTypeDOS = baseMapper.selectList(new QueryWrapper<>());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package top.wms.admin.weighManage.model.entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
Reference in New Issue
Block a user