diff --git a/src/main/java/com/glxp/api/controller/sup/UserRegisterController.java b/src/main/java/com/glxp/api/controller/sup/UserRegisterController.java new file mode 100644 index 0000000..28afc48 --- /dev/null +++ b/src/main/java/com/glxp/api/controller/sup/UserRegisterController.java @@ -0,0 +1,117 @@ +package com.glxp.api.controller.sup; + +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.servlet.http.HttpSession; +import javax.validation.Valid; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.glxp.api.common.enums.ResultEnum; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; +import com.glxp.api.controller.BaseController; +import com.glxp.api.entity.sup.UserCertEntity; +import com.glxp.api.entity.sup.UserPersonEntity; +import com.glxp.api.entity.sup.UserRegisterEntity; +import com.glxp.api.service.sup.UserCertService; +import com.glxp.api.service.sup.UserPersonService; +import com.glxp.api.service.sup.UserRegisterService; +import com.glxp.api.util.CaptchaUtils; + +import cn.hutool.core.util.ReUtil; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; + +@RestController +@Slf4j +public class UserRegisterController extends BaseController { + private static final Logger logger = LoggerFactory.getLogger(UserRegisterController.class); + @Resource + private UserRegisterService userRegisterService; + @Resource + private UserPersonService userPersonService; + @Resource + private UserCertService userCertService; + @PostMapping("/admin/auth/register/getCheckcode") + public BaseResponse getCheckcode(@RequestBody Map params, HttpSession httpSession) { + return CaptchaUtils.getCheckcode(params,httpSession); + } + + @PostMapping("/admin/auth/register/checkCode") + public BaseResponse checkCode(@RequestBody Map params) { + return CaptchaUtils.checkCode(params); + } + + /** + * 根据手机号获取注册信息 + * + * @param mobile 手机号 + */ + @GetMapping("/admin/auth/register/get/{mobile}") + public BaseResponse getInfo(@PathVariable String mobile) { + UserRegisterEntity userRegisterEntity = userRegisterService.getOne(new QueryWrapper().eq("mobile", mobile)); + if(userRegisterEntity==null) { + userRegisterEntity = new UserRegisterEntity(); + } else { + List userPersons = userPersonService.list(new QueryWrapper().eq("registerId", userRegisterEntity.getId())); + userRegisterEntity.setUserPersons(userPersons); + List userCerts = userCertService.list(new QueryWrapper().eq("registerId", userRegisterEntity.getId())); + userRegisterEntity.setUserCerts(userCerts); + } + return ResultVOUtils.success(userRegisterEntity); + } + + @PostMapping("/admin/auth/register/save") + public BaseResponse saveRegister(@RequestBody @Valid UserRegisterEntity userRegisterEntity, HttpSession httpSession, + BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + + //校验邮箱是否正确 + if (StrUtil.isNotBlank(userRegisterEntity.getEmail())) { + boolean match = ReUtil.isMatch("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", userRegisterEntity.getEmail()); + if (!match) { + return ResultVOUtils.error(500, "邮箱格式错误"); + } + } + UserRegisterEntity userRegisterEntity2 = userRegisterService.getOne(new QueryWrapper().eq("companyName", userRegisterEntity.getCompanyName())); + if (userRegisterEntity2 !=null ) { + if(userRegisterEntity.getId()==null) + return ResultVOUtils.error(500, "该单位已被注册!"); + if(userRegisterEntity2.getId()!=userRegisterEntity.getId()) + return ResultVOUtils.error(500, "该单位已被注册!"); + } + if(StringUtils.isEmpty(userRegisterEntity.getCheckStatus())) + userRegisterEntity.setCheckStatus("0"); + boolean b = false; + b = userRegisterService.saveOrUpdate(userRegisterEntity); + + if (!b) { + return ResultVOUtils.error(ResultEnum.NOT_NETWORK); + } + + return ResultVOUtils.success(); + } + + @GetMapping("/admin/auth/register/list") + public BaseResponse list(@RequestBody Map params, BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + return ResultVOUtils.success(userRegisterService.list(new QueryWrapper().allEq(params))); + } + +} diff --git a/src/main/java/com/glxp/api/entity/sup/UserRegisterEntity.java b/src/main/java/com/glxp/api/entity/sup/UserRegisterEntity.java index 6f95094..ff944bc 100644 --- a/src/main/java/com/glxp/api/entity/sup/UserRegisterEntity.java +++ b/src/main/java/com/glxp/api/entity/sup/UserRegisterEntity.java @@ -1,11 +1,14 @@ package com.glxp.api.entity.sup; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.util.Date; + import lombok.Data; @Data @@ -110,5 +113,9 @@ public class UserRegisterEntity implements Serializable { @TableField(value = "checkTime") private Date checkTime; + //负责人列表 + private List userPersons; + //证书列表 + private List userCerts; private static final long serialVersionUID = 1L; }