Browse Source

企业初始化, 小程序登录

master
DX 2 months ago
parent
commit
f7d9ca60c3
  1. 3
      yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
  2. 7
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
  3. 95
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/EnterpriseController.java
  4. 70
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/vo/EnterprisePageReqVO.java
  5. 85
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/vo/EnterpriseRespVO.java
  6. 65
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/vo/EnterpriseSaveReqVO.java
  7. 93
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/enterprise/EnterpriseDO.java
  8. 41
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterprise/EnterpriseMapper.java
  9. 12
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java
  10. 75
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
  11. 56
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterprise/EnterpriseService.java
  12. 75
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterprise/EnterpriseServiceImpl.java
  13. 2
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java
  14. 9
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
  15. 11
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
  16. 35
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
  17. 6
      yudao-server/src/main/resources/application-local.yaml
  18. 4
      yudao-server/src/main/resources/application.yaml

3
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java

@ -164,4 +164,7 @@ public interface ErrorCodeConstants {
// ========== 站内信发送 1-002-028-000 ==========
ErrorCode NOTIFY_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1_002_028_000, "模板参数({})缺失");
//==========企业信息相关 1-002-029-000
ErrorCode ENTERPRISE_NOT_EXISTS = new ErrorCode(1-003-000-000, "企业不存在");
}

7
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java

@ -69,6 +69,13 @@ public class AuthController {
return success(authService.login(reqVO));
}
@PermitAll
@PostMapping("/app_login")
@Operation(summary = "社交快捷登录,使用 code 授权码")
public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthSocialLoginReqVO reqVO) {
return success(authService.miniAppLogin(reqVO));
}
@PostMapping("/logout")
@PermitAll
@Operation(summary = "登出系统")

95
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/EnterpriseController.java

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.system.controller.admin.enterprise;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.system.controller.admin.enterprise.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO;
import cn.iocoder.yudao.module.system.service.enterprise.EnterpriseService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@Tag(name = "管理后台 - 企业")
@RestController
@RequestMapping("/system/enterprise")
@Validated
public class EnterpriseController {
@Resource
private EnterpriseService enterpriseService;
@PostMapping("/create")
@Operation(summary = "创建企业")
@PreAuthorize("@ss.hasPermission('system:enterprise:create')")
public CommonResult<Long> createEnterprise(@Valid @RequestBody EnterpriseSaveReqVO createReqVO) {
return success(enterpriseService.createEnterprise(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新企业")
@PreAuthorize("@ss.hasPermission('system:enterprise:update')")
public CommonResult<Boolean> updateEnterprise(@Valid @RequestBody EnterpriseSaveReqVO updateReqVO) {
enterpriseService.updateEnterprise(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除企业")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('system:enterprise:delete')")
public CommonResult<Boolean> deleteEnterprise(@RequestParam("id") Long id) {
enterpriseService.deleteEnterprise(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得企业")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:enterprise:query')")
public CommonResult<EnterpriseRespVO> getEnterprise(@RequestParam("id") Long id) {
EnterpriseDO enterprise = enterpriseService.getEnterprise(id);
return success(BeanUtils.toBean(enterprise, EnterpriseRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得企业分页")
@PreAuthorize("@ss.hasPermission('system:enterprise:query')")
public CommonResult<PageResult<EnterpriseRespVO>> getEnterprisePage(@Valid EnterprisePageReqVO pageReqVO) {
PageResult<EnterpriseDO> pageResult = enterpriseService.getEnterprisePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, EnterpriseRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出企业 Excel")
@PreAuthorize("@ss.hasPermission('system:enterprise:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportEnterpriseExcel(@Valid EnterprisePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<EnterpriseDO> list = enterpriseService.getEnterprisePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "企业.xls", "数据", EnterpriseRespVO.class,
BeanUtils.toBean(list, EnterpriseRespVO.class));
}
}

70
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/vo/EnterprisePageReqVO.java

@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.system.controller.admin.enterprise.vo;
import lombok.*;
import java.time.LocalDate;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 企业分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class EnterprisePageReqVO extends PageParam {
@Schema(description = "所属部门ID", example = "10990")
private Long departmentId;
@Schema(description = "管辖人员ID", example = "30445")
private Long userId;
@Schema(description = "企业类型:1.大型、2.中型、3.小型、4.环保重点", example = "2")
private String type;
@Schema(description = "企业所属区域:1.东区、2.西区、3.北区、4.南区")
private String region;
@Schema(description = "企业名称", example = "张三")
private String enterprisesName;
@Schema(description = "企业地址")
private String address;
@Schema(description = "环保负责人姓名", example = "张三")
private String contactName;
@Schema(description = "企业环保负责人联系电话")
private String environmentalContactPhone;
@Schema(description = "企业注册号")
private String registrationNumber;
@Schema(description = "企业图文介绍")
private String introduction;
@Schema(description = "企业成立时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDate[] establishmentDate;
@Schema(description = "企业经纬度")
private String gpsLocation;
@Schema(description = "创建人")
private String createBy;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "修改人")
private String updateBy;
@Schema(description = "管理部门", example = "26433")
private Long managerDeptId;
}

85
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/vo/EnterpriseRespVO.java

@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.system.controller.admin.enterprise.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDate;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 企业 Response VO")
@Data
@ExcelIgnoreUnannotated
public class EnterpriseRespVO {
@Schema(description = "企业ID,主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "853")
@ExcelProperty("企业ID,主键")
private Long id;
@Schema(description = "所属部门ID", example = "10990")
@ExcelProperty("所属部门ID")
private Long departmentId;
@Schema(description = "管辖人员ID", example = "30445")
@ExcelProperty("管辖人员ID")
private Long userId;
@Schema(description = "企业类型:1.大型、2.中型、3.小型、4.环保重点", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("企业类型:1.大型、2.中型、3.小型、4.环保重点")
private String type;
@Schema(description = "企业所属区域:1.东区、2.西区、3.北区、4.南区", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("企业所属区域:1.东区、2.西区、3.北区、4.南区")
private String region;
@Schema(description = "企业名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@ExcelProperty("企业名称")
private String enterprisesName;
@Schema(description = "企业地址")
@ExcelProperty("企业地址")
private String address;
@Schema(description = "环保负责人姓名", example = "张三")
@ExcelProperty("环保负责人姓名")
private String contactName;
@Schema(description = "企业环保负责人联系电话")
@ExcelProperty("企业环保负责人联系电话")
private String environmentalContactPhone;
@Schema(description = "企业注册号")
@ExcelProperty("企业注册号")
private String registrationNumber;
@Schema(description = "企业图文介绍")
@ExcelProperty("企业图文介绍")
private String introduction;
@Schema(description = "企业成立时间")
@ExcelProperty("企业成立时间")
private LocalDate establishmentDate;
@Schema(description = "企业经纬度")
@ExcelProperty("企业经纬度")
private String gpsLocation;
@Schema(description = "创建人")
@ExcelProperty("创建人")
private String createBy;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "修改人")
@ExcelProperty("修改人")
private String updateBy;
@Schema(description = "管理部门", example = "26433")
@ExcelProperty("管理部门")
private Long managerDeptId;
}

65
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/enterprise/vo/EnterpriseSaveReqVO.java

@ -0,0 +1,65 @@
package cn.iocoder.yudao.module.system.controller.admin.enterprise.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDate;
import java.util.*;
import javax.validation.constraints.NotEmpty;
@Schema(description = "管理后台 - 企业新增/修改 Request VO")
@Data
public class EnterpriseSaveReqVO {
@Schema(description = "企业ID,主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "853")
private Long id;
@Schema(description = "所属部门ID", example = "10990")
private Long departmentId;
@Schema(description = "管辖人员ID", example = "30445")
private Long userId;
@Schema(description = "企业类型:1.大型、2.中型、3.小型、4.环保重点", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String type;
@Schema(description = "企业所属区域:1.东区、2.西区、3.北区、4.南区", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "企业所属区域:1.东区、2.西区、3.北区、4.南区不能为空")
private String region;
@Schema(description = "企业名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@NotEmpty(message = "企业名称不能为空")
private String enterprisesName;
@Schema(description = "企业地址")
private String address;
@Schema(description = "环保负责人姓名", example = "张三")
private String contactName;
@Schema(description = "企业环保负责人联系电话")
private String environmentalContactPhone;
@Schema(description = "企业注册号")
private String registrationNumber;
@Schema(description = "企业图文介绍")
private String introduction;
@Schema(description = "企业成立时间")
private LocalDate establishmentDate;
@Schema(description = "企业经纬度")
private String gpsLocation;
@Schema(description = "创建人")
private String createBy;
@Schema(description = "修改人")
private String updateBy;
@Schema(description = "管理部门", example = "26433")
private Long managerDeptId;
}

93
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/enterprise/EnterpriseDO.java

@ -0,0 +1,93 @@
package cn.iocoder.yudao.module.system.dal.dataobject.enterprise;
import lombok.*;
import java.time.LocalDate;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 企业 DO
*
* @author 芋道源码
*/
@TableName("enterprises")
@KeySequence("enterprises_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EnterpriseDO extends BaseDO {
/**
* 企业ID主键
*/
@TableId
private Long id;
/**
* 所属部门ID
*/
private Long departmentId;
/**
* 管辖人员ID
*/
private Long userId;
/**
* 企业类型1.大型2.中型3.小型4.环保重点
*/
private String type;
/**
* 企业所属区域1.东区2.西区3.北区4.南区
*/
private String region;
/**
* 企业名称
*/
private String enterprisesName;
/**
* 企业地址
*/
private String address;
/**
* 环保负责人姓名
*/
private String contactName;
/**
* 企业环保负责人联系电话
*/
private String environmentalContactPhone;
/**
* 企业注册号
*/
private String registrationNumber;
/**
* 企业图文介绍
*/
private String introduction;
/**
* 企业成立时间
*/
private LocalDate establishmentDate;
/**
* 企业经纬度
*/
private String gpsLocation;
/**
* 创建人
*/
private String createBy;
/**
* 修改人
*/
private String updateBy;
/**
* 管理部门
*/
private Long managerDeptId;
}

41
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/enterprise/EnterpriseMapper.java

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.system.dal.mysql.enterprise;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.enterprise.vo.*;
/**
* 企业 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface EnterpriseMapper extends BaseMapperX<EnterpriseDO> {
default PageResult<EnterpriseDO> selectPage(EnterprisePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<EnterpriseDO>()
.eqIfPresent(EnterpriseDO::getDepartmentId, reqVO.getDepartmentId())
.eqIfPresent(EnterpriseDO::getUserId, reqVO.getUserId())
.eqIfPresent(EnterpriseDO::getType, reqVO.getType())
.eqIfPresent(EnterpriseDO::getRegion, reqVO.getRegion())
.likeIfPresent(EnterpriseDO::getEnterprisesName, reqVO.getEnterprisesName())
.eqIfPresent(EnterpriseDO::getAddress, reqVO.getAddress())
.likeIfPresent(EnterpriseDO::getContactName, reqVO.getContactName())
.eqIfPresent(EnterpriseDO::getEnvironmentalContactPhone, reqVO.getEnvironmentalContactPhone())
.eqIfPresent(EnterpriseDO::getRegistrationNumber, reqVO.getRegistrationNumber())
.eqIfPresent(EnterpriseDO::getIntroduction, reqVO.getIntroduction())
.betweenIfPresent(EnterpriseDO::getEstablishmentDate, reqVO.getEstablishmentDate())
.eqIfPresent(EnterpriseDO::getGpsLocation, reqVO.getGpsLocation())
.eqIfPresent(EnterpriseDO::getCreateBy, reqVO.getCreateBy())
.betweenIfPresent(EnterpriseDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(EnterpriseDO::getUpdateBy, reqVO.getUpdateBy())
.eqIfPresent(EnterpriseDO::getManagerDeptId, reqVO.getManagerDeptId())
.orderByDesc(EnterpriseDO::getId));
}
}

12
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java

@ -78,4 +78,16 @@ public interface AdminAuthService {
*/
AuthLoginRespVO register(AuthRegisterReqVO createReqVO);
/*********************************小程序登录相关****************************************/
/**
* 小程序登录
*
* @param reqVO 登录信息
* @return 登录结果
*/
AuthLoginRespVO miniAppLogin(AuthSocialLoginReqVO reqVO);
}

75
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java

@ -13,23 +13,31 @@ import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*;
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper;
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
import cn.iocoder.yudao.module.system.enums.oauth2.OAuth2ClientConstants;
import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
import cn.iocoder.yudao.module.system.service.member.MemberService;
import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService;
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.google.common.annotations.VisibleForTesting;
import com.xingyuv.captcha.model.common.ResponseModel;
import com.xingyuv.captcha.model.vo.CaptchaVO;
import com.xingyuv.captcha.service.CaptchaService;
import com.xingyuv.jushauth.model.AuthUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.validation.Validator;
@ -64,6 +72,8 @@ public class AdminAuthServiceImpl implements AdminAuthService {
private CaptchaService captchaService;
@Resource
private SmsCodeApi smsCodeApi;
@Resource
private SocialUserMapper socialUserMapper;
/**
* 验证码的开关默认为 true
@ -71,6 +81,9 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Value("${yudao.captcha.enable:true}")
private Boolean captchaEnable;
@Autowired
private SocialClientService socialClientService;
@Override
public AdminUserDO authenticate(String username, String password) {
final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_USERNAME;
@ -259,6 +272,68 @@ public class AdminAuthServiceImpl implements AdminAuthService {
return createTokenAfterLoginSuccess(userId, registerReqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
}
/**
* 小程序登录
*
* @param reqVO 登录信息
* @return 登录结果
*/
@Override
@Transactional
public AuthLoginRespVO miniAppLogin(AuthSocialLoginReqVO reqVO) {
AuthUser authUser = socialClientService.getAuthUser(
SocialTypeEnum.WECHAT_MINI_APP.getType(),
UserTypeEnum.MEMBER.getValue(), // 假设用户类型为会员
reqVO.getCode(),
reqVO.getState()
);
SocialUserRespDTO respDTO = socialUserService.getSocialUserByCode(UserTypeEnum.ADMIN.getValue(), UserTypeEnum.MEMBER.getValue(),
reqVO.getCode(), reqVO.getState());
AdminUserDO user = null;
if (respDTO == null ) {
// 未找到社交用户,插入记录
SocialUserDO socialUser = new SocialUserDO();
socialUser.setType(reqVO.getType());
socialUser.setOpenid(authUser.getUuid());
socialUser.setCode(reqVO.getCode());
socialUser.setAvatar(authUser.getAvatar());
socialUser.setRawTokenInfo(authUser.getToken().getRefreshToken());
socialUser.setNickname(authUser.getNickname());
socialUser.setRawUserInfo(authUser.getRawUserInfo().toJSONString());
final int insert = socialUserMapper.insert(socialUser);
if (insert < 0) {
throw exception(USER_NOT_EXISTS);
}
user = userService.autoRegisterUser(authUser);
//添加绑定
SocialUserBindReqDTO userBindReqDTO = new SocialUserBindReqDTO();
userBindReqDTO.setUserId(user.getId());
userBindReqDTO.setUserType(SocialTypeEnum.WECHAT_MINI_APP.getType());
userBindReqDTO.setCode(reqVO.getCode());
userBindReqDTO.setSocialType(reqVO.getType());
userBindReqDTO.setState(reqVO.getState());
socialUserService.bindSocialUser(userBindReqDTO);
return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL);
} else {
// 获得用户
user = userService.getUser(respDTO.getUserId());
if (user == null) {
throw exception(USER_NOT_EXISTS);
}
}
return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL);
}
@VisibleForTesting
void validateCaptcha(AuthRegisterReqVO reqVO) {
// 如果验证码关闭,则不进行校验

56
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterprise/EnterpriseService.java

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.system.service.enterprise;
import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.enterprise.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import javax.validation.Valid;
/**
* 企业 Service 接口
*
* @author 芋道源码
*/
public interface EnterpriseService {
/**
* 创建企业
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createEnterprise(@Valid EnterpriseSaveReqVO createReqVO);
/**
* 更新企业
*
* @param updateReqVO 更新信息
*/
void updateEnterprise(@Valid EnterpriseSaveReqVO updateReqVO);
/**
* 删除企业
*
* @param id 编号
*/
void deleteEnterprise(Long id);
/**
* 获得企业
*
* @param id 编号
* @return 企业
*/
EnterpriseDO getEnterprise(Long id);
/**
* 获得企业分页
*
* @param pageReqVO 分页查询
* @return 企业分页
*/
PageResult<EnterpriseDO> getEnterprisePage(EnterprisePageReqVO pageReqVO);
}

75
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/enterprise/EnterpriseServiceImpl.java

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.system.service.enterprise;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.enterprise.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.dal.mysql.enterprise.EnterpriseMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
/**
* 企业 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class EnterpriseServiceImpl implements EnterpriseService {
@Resource
private EnterpriseMapper enterpriseMapper;
@Override
public Long createEnterprise(EnterpriseSaveReqVO createReqVO) {
// 插入
EnterpriseDO enterprise = BeanUtils.toBean(createReqVO, EnterpriseDO.class);
enterpriseMapper.insert(enterprise);
// 返回
return enterprise.getId();
}
@Override
public void updateEnterprise(EnterpriseSaveReqVO updateReqVO) {
// 校验存在
validateEnterpriseExists(updateReqVO.getId());
// 更新
EnterpriseDO updateObj = BeanUtils.toBean(updateReqVO, EnterpriseDO.class);
enterpriseMapper.updateById(updateObj);
}
@Override
public void deleteEnterprise(Long id) {
// 校验存在
validateEnterpriseExists(id);
// 删除
enterpriseMapper.deleteById(id);
}
private void validateEnterpriseExists(Long id) {
if (enterpriseMapper.selectById(id) == null) {
throw exception(ENTERPRISE_NOT_EXISTS);
}
}
@Override
public EnterpriseDO getEnterprise(Long id) {
return enterpriseMapper.selectById(id);
}
@Override
public PageResult<EnterpriseDO> getEnterprisePage(EnterprisePageReqVO pageReqVO) {
return enterpriseMapper.selectPage(pageReqVO);
}
}

2
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java

@ -87,4 +87,6 @@ public interface SocialUserService {
*/
PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO);
SocialUserDO selectBySocialTypeAndOpenId(Integer type, String openId);
}

9
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java

@ -13,8 +13,10 @@ import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xingyuv.jushauth.model.AuthUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -171,4 +173,11 @@ public class SocialUserServiceImpl implements SocialUserService {
return socialUserMapper.selectPage(pageReqVO);
}
@Override
public SocialUserDO selectBySocialTypeAndOpenId(Integer type, String openId) {
LambdaQueryWrapper<SocialUserDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SocialUserDO::getType, type).eq(SocialUserDO::getOpenid, openId);
return socialUserMapper.selectOne(wrapper);
}
}

11
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.user;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
@ -11,6 +12,7 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRe
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import com.xingyuv.jushauth.model.AuthUser;
import javax.validation.Valid;
import java.io.InputStream;
@ -216,4 +218,13 @@ public interface AdminUserService {
*/
boolean isPasswordMatch(String rawPassword, String encodedPassword);
/**
* 小程序端自动注册
* @param authUser
* @return java.lang.Long
* @Author djx
* @Date 2025-01-22 上午9:41
**/
AdminUserDO autoRegisterUser(AuthUser authUser);
}

35
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java

@ -13,6 +13,7 @@ import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
@ -22,9 +23,11 @@ import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqV
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.dept.UserPostMapper;
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import cn.iocoder.yudao.module.system.service.dept.DeptService;
import cn.iocoder.yudao.module.system.service.dept.PostService;
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
@ -33,6 +36,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
import com.xingyuv.jushauth.model.AuthUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.crypto.password.PasswordEncoder;
@ -518,6 +522,37 @@ public class AdminUserServiceImpl implements AdminUserService {
return passwordEncoder.matches(rawPassword, encodedPassword);
}
/**
* 小程序端自动注册
*
* @param authUser
* @return java.lang.Long
* @Author djx
* @Date 2025-01-22 上午9:40
**/
@Override
public AdminUserDO autoRegisterUser(AuthUser authUser) {
// 根据微信用户信息生成用户数据
AdminUserDO user = new AdminUserDO();
// openid.substring(openid.length() - 10)
user.setUsername("wx_" + authUser.getUuid().substring(authUser.getUuid().length() - 5)); // 使用微信 openid 作为用户名
user.setNickname(authUser.getNickname());
user.setAvatar(authUser.getAvatar());
user.setStatus(CommonStatusEnum.ENABLE.getStatus());
user.setPassword(encodePassword(authUser.getUuid().substring(authUser.getUuid().length() - 10))); // 随机密码
userMapper.insert(user);
return user;
}
public void bindSocialUser(Long userId, AuthUser authUser) {
// SocialUserDO socialUser = new SocialUserDO();
// socialUser.setUserId(userId);
// socialUser.setType(SocialTypeEnum.WECHAT_MINI_APP.getType());
// socialUser.setOpenId(authUser.getUuid());
// socialUser.setUnionId(authUser.getToken().getUnionId());
// socialUserMapper.insert(socialUser);
}
/**
* 对密码进行加密
*

6
yudao-server/src/main/resources/application-local.yaml

@ -201,8 +201,8 @@ wx:
# secret: 6f270509224a7ae1296bbf1c8cb97aed
# appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的)
# secret: 4a1a04e07f6a4a0751b39c3064a92c8b
appid: wx66186af0759f47c9 # 测试号(puhui 提供的)
secret: 3218bcbd112cbc614c7264ceb20144ac
appid: wx6a07542e99f7fc98 # 测试号(puhui 提供的)
secret: ebce621ebc5afed6d9fad388d08e11ed
config-storage:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
key-prefix: wa # Redis Key 的前缀
@ -272,4 +272,4 @@ iot:
# 保持连接
keepalive: 60
# 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息)
clearSession: true
clearSession: true

4
yudao-server/src/main/resources/application.yaml

@ -248,7 +248,7 @@ yudao:
front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
unit-test-enable: false # 是否生成单元测试
tenant: # 多租户相关配置项
enable: true
enable: false
ignore-urls:
- /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
- /admin-api/system/tenant/get-by-website # 基于域名获取租户,不许带租户编号
@ -329,4 +329,4 @@ yudao:
key: pLXUGAwK5305
customer: E77DF18BE109F454A5CD319E44BF5177
debug: false
debug: false

Loading…
Cancel
Save