kongzy
2023-11-27 59ae9759fd50568059fa44f43832f5a414edb3e9
assess-system/src/main/java/com/gkhy/assess/system/service/impl/SysUserServiceImpl.java
@@ -1,11 +1,13 @@
package com.gkhy.assess.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.assess.common.api.CommonPage;
import com.gkhy.assess.common.constant.CacheConstant;
import com.gkhy.assess.common.domain.vo.AccountVO;
import com.gkhy.assess.common.domain.vo.LoginBody;
import com.gkhy.assess.common.enums.AttachTypeEnum;
import com.gkhy.assess.common.enums.UserIdentityEnum;
import com.gkhy.assess.common.enums.UserTypeEnum;
import com.gkhy.assess.common.exception.ApiException;
@@ -16,6 +18,7 @@
import com.gkhy.assess.system.domain.*;
import com.gkhy.assess.system.mapper.SysAgencyMapper;
import com.gkhy.assess.system.mapper.SysUserMapper;
import com.gkhy.assess.system.service.SysAttachService;
import com.gkhy.assess.system.service.SysConfigService;
import com.gkhy.assess.system.utils.ShiroUtils;
import com.gkhy.assess.system.service.SysUserService;
@@ -29,6 +32,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.validation.Validator;
import java.util.ArrayList;
import java.util.List;
@@ -54,9 +58,14 @@
    @Autowired
    private SysAgencyMapper agencyMapper;
    @Autowired
    private SysAttachService attachService;
    @Override
    public AccountVO login(LoginBody loginBody) {
        // 验证码校验
       // validateCaptcha(loginBody.getUsername(), loginBody.getCode(), loginBody.getUuid());
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(loginBody.getUsername(), loginBody.getPassword(), false);
        Subject subject= SecurityUtils.getSubject();
        String msg ;
@@ -82,6 +91,32 @@
            msg = "用户认证失败";
            throw new ApiException(msg);
        }
    }
    /**
     * 校验验证码
     *
     * @param username 用户名
     * @param code 验证码
     * @param uuid 唯一标识
     * @return 结果
     */
    public void validateCaptcha(String username, String code, String uuid)
    {
            if(StrUtil.isBlank(code)||StrUtil.isBlank(uuid)){
                throw new ApiException("验证码或验证码标识为空");
            }
            String verifyKey = CacheConstant.CAPTCHA_CODE_KEY +uuid;
            String captcha = (String) redisUtils.get(verifyKey);
            redisUtils.del(verifyKey);
            if (StrUtil.isBlank(captcha))
            {
                throw new ApiException("验证码已失效");
            }
            if (!code.equalsIgnoreCase(captcha))
            {
                throw new ApiException("验证码不正确");
            }
    }
    @Override
@@ -173,6 +208,7 @@
    }
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int addExpert(SysUser user) {
        //校验用户信息
        if(!checkUsernameUnique(new SysUser().setUsername(user.getUsername()))){
@@ -187,6 +223,26 @@
        if(!b){
            throw new ApiException("创建专家信息失败");
        }
        List<SysAttach> socialAttach=user.getSocialAttach();
        List<SysAttach> medicalAttach=user.getMedicalAttach();
        List<SysAttach> salaryAttach=user.getSalaryAttach();
        List<SysAttach> attaches=new ArrayList<>();
        for(SysAttach attach:socialAttach){
            attach.setType(AttachTypeEnum.SOCIAL.getCode());
            attach.setUserId(user.getId());
            attaches.add(attach);
        }
        for(SysAttach attach:medicalAttach){
            attach.setType(AttachTypeEnum.MEDICAL.getCode());
            attach.setUserId(user.getId());
            attaches.add(attach);
        }
        for(SysAttach attach:salaryAttach){
            attach.setType(AttachTypeEnum.SALARY.getCode());
            attach.setUserId(user.getId());
            attaches.add(attach);
        }
        attachService.saveBatch(attaches);
        return 1;
    }
@@ -252,6 +308,30 @@
        if(!b){
            throw new ApiException("更新专家信息失败");
        }
        //刪除旧数据
        attachService.deleteAttachsByUserId(user.getId(),null);
        List<SysAttach> socialAttach=user.getSocialAttach();
        List<SysAttach> medicalAttach=user.getMedicalAttach();
        List<SysAttach> salaryAttach=user.getSalaryAttach();
        List<SysAttach> attaches=new ArrayList<>();
        for(SysAttach attach:socialAttach){
            attach.setType(AttachTypeEnum.SOCIAL.getCode());
            attach.setUserId(user.getId());
            attaches.add(attach);
        }
        for(SysAttach attach:medicalAttach){
            attach.setType(AttachTypeEnum.MEDICAL.getCode());
            attach.setUserId(user.getId());
            attaches.add(attach);
        }
        for(SysAttach attach:salaryAttach){
            attach.setType(AttachTypeEnum.SALARY.getCode());
            attach.setUserId(user.getId());
            attaches.add(attach);
        }
        attachService.saveBatch(attaches);
        return 1;
    }