|
@@ -13,7 +13,10 @@ import cn.iocoder.byzs.module.system.convert.user.UserConvert;
|
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.dept.DeptDO;
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.user.AdminUserDO;
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.iocoder.byzs.module.system.enums.common.SexEnum;
|
|
import cn.iocoder.byzs.module.system.enums.common.SexEnum;
|
|
|
|
|
+import cn.iocoder.byzs.module.system.enums.sms.SmsSceneEnum;
|
|
|
import cn.iocoder.byzs.module.system.service.dept.DeptService;
|
|
import cn.iocoder.byzs.module.system.service.dept.DeptService;
|
|
|
|
|
+import cn.iocoder.byzs.module.system.service.permission.PermissionService;
|
|
|
|
|
+import cn.iocoder.byzs.module.system.service.sms.SmsSendService;
|
|
|
import cn.iocoder.byzs.module.system.service.user.AdminUserService;
|
|
import cn.iocoder.byzs.module.system.service.user.AdminUserService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
@@ -23,12 +26,14 @@ import jakarta.annotation.Resource;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.Valid;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -46,6 +51,10 @@ public class UserController {
|
|
|
private AdminUserService userService;
|
|
private AdminUserService userService;
|
|
|
@Resource
|
|
@Resource
|
|
|
private DeptService deptService;
|
|
private DeptService deptService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private SmsSendService smsSendService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private PermissionService permissionService;
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
|
@PostMapping("/create")
|
|
|
@Operation(summary = "新增用户")
|
|
@Operation(summary = "新增用户")
|
|
@@ -170,4 +179,58 @@ public class UserController {
|
|
|
return success(userService.importUserList(list, updateSupport));
|
|
return success(userService.importUserList(list, updateSupport));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ @PostMapping("/parent-class-register")
|
|
|
|
|
+ @Operation(summary = "家长课堂注册")
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public CommonResult<Long> parentClassRegister(@Valid @RequestBody ParentClassRegisterReqVO reqVO) {
|
|
|
|
|
+ if ("batch".equals(reqVO.getType())) {
|
|
|
|
|
+ List<String> batchMobiles = reqVO.getBatchMobiles();
|
|
|
|
|
+ if (CollUtil.isEmpty(batchMobiles)) {
|
|
|
|
|
+ return success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long firstUserId = null;
|
|
|
|
|
+ for (String mobile : batchMobiles) {
|
|
|
|
|
+ UserSaveReqVO saveReqVO = new UserSaveReqVO();
|
|
|
|
|
+ saveReqVO.setUsername(mobile);
|
|
|
|
|
+ saveReqVO.setPassword(mobile);
|
|
|
|
|
+ saveReqVO.setMobile(mobile);
|
|
|
|
|
+ String nickname = mobile.length() >= 4 ? mobile.substring(mobile.length() - 4) : mobile;
|
|
|
|
|
+ saveReqVO.setNickname(nickname);
|
|
|
|
|
+ saveReqVO.setDeptId(reqVO.getDeptId());
|
|
|
|
|
+ Long userId = userService.createUser(saveReqVO);
|
|
|
|
|
+ if (firstUserId == null) {
|
|
|
|
|
+ firstUserId = userId;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (reqVO.getRoleIds() != null && !reqVO.getRoleIds().isEmpty()) {
|
|
|
|
|
+ permissionService.assignUserRole(userId, reqVO.getRoleIds());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Boolean.TRUE.equals(reqVO.getSendSms())) {
|
|
|
|
|
+ sendRegisterSms(mobile);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return success(firstUserId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ UserSaveReqVO saveReqVO = new UserSaveReqVO();
|
|
|
|
|
+ saveReqVO.setUsername(reqVO.getUsername());
|
|
|
|
|
+ saveReqVO.setPassword(reqVO.getPassword());
|
|
|
|
|
+ saveReqVO.setMobile(reqVO.getMobile());
|
|
|
|
|
+ saveReqVO.setNickname(reqVO.getNickname());
|
|
|
|
|
+ saveReqVO.setDeptId(reqVO.getDeptId());
|
|
|
|
|
+ Long userId = userService.createUser(saveReqVO);
|
|
|
|
|
+ if (reqVO.getRoleIds() != null && !reqVO.getRoleIds().isEmpty()) {
|
|
|
|
|
+ permissionService.assignUserRole(userId, reqVO.getRoleIds());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Boolean.TRUE.equals(reqVO.getSendSms())) {
|
|
|
|
|
+ sendRegisterSms(reqVO.getMobile());
|
|
|
|
|
+ }
|
|
|
|
|
+ return success(userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void sendRegisterSms(String mobile) {
|
|
|
|
|
+ Map<String, Object> templateParams = new HashMap<>();
|
|
|
|
|
+ smsSendService.sendSingleSmsToAdmin(mobile, null,
|
|
|
|
|
+ SmsSceneEnum.TXY_MEMBER_REGISTER_NOTICE.getTemplateCode(), templateParams);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|