智慧保安后台管理-外网项目备份
guoshilong
2024-01-04 60a4193a0921393e1b42cef4313e844103681cfd
微信注册新增
6 files modified
6 files added
628 ■■■■■ changed files
src/main/java/org/springblade/modules/auth/endpoint/BladeTokenEndPoint.java 41 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/auth/enums/UserEnum.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/auth/granter/PasswordTokenGranter.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/auth/utils/TokenUtil.java 1 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/controller/UserWxController.java 117 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/entity/UserWx.java 268 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserWxMapper.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserWxMapper.xml 15 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/IUserService.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/IUserWxService.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java 86 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/UserWxServiceImpl.java 56 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/auth/endpoint/BladeTokenEndPoint.java
@@ -188,6 +188,47 @@
    }
    /**
     * 微信小程序账号登录
     * @param tenantId
     * @param username
     * @param password
     * @return
     */
    @ApiLog("登录用户验证")
    @PostMapping("/oauth/token/wxAccount")
    @ApiOperation(value = "获取认证令牌", notes = "传入租户ID:tenantId,账号:account,密码:password,登录类型:loginType")
    public Kv wxAccount(@ApiParam(value = "租户ID", required = true) @RequestParam String tenantId,
                    @ApiParam(value = "账号", required = true) @RequestParam(required = false) String username,
                    @ApiParam(value = "密码", required = true) @RequestParam(required = false) String password) {
        Kv authInfo = Kv.create();
        String grantType = WebUtil.getRequest().getParameter("grant_type");
        String refreshToken = WebUtil.getRequest().getParameter("refresh_token");
        String userType = Func.toStr(WebUtil.getRequest().getHeader(TokenUtil.USER_TYPE_HEADER_KEY), TokenUtil.USER_TYPE_WX);
        TokenParameter tokenParameter = new TokenParameter();
        tokenParameter.getArgs().set("tenantId", tenantId).set("username", username).set("password", password).set("grantType", grantType).set("refreshToken", refreshToken).set("userType", userType);
        ITokenGranter granter = TokenGranterBuilder.getGranter(grantType);
        UserInfo userInfo = granter.grant(tokenParameter);
        if (userInfo == null || userInfo.getUser() == null) {
            return authInfo.set("error_code", HttpServletResponse.SC_BAD_REQUEST).set("error_description", "用户名或密码不正确");
        }
        return TokenUtil.createAuthInfo(userInfo);
    }
    /**
     * 微信小程序授权登录
     * @param username
src/main/java/org/springblade/modules/auth/enums/UserEnum.java
@@ -42,6 +42,11 @@
     * other
     */
    OTHER("other", 3),
    /**
     * app
     */
    WX("wx", 4),
    ;
    final String name;
src/main/java/org/springblade/modules/auth/granter/PasswordTokenGranter.java
@@ -63,6 +63,9 @@
                userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.WEB);
            } else if (userType.equals(UserEnum.APP.getName())) {
                userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.APP);
            }else if (userType.equals(UserEnum.WX.getName())){
                // 微信小程序登录
                userInfo = userService.wxUserInfo(tenantId,username, DigestUtil.hex(password), UserEnum.WEB);
            } else {
                userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.OTHER);
            }
src/main/java/org/springblade/modules/auth/utils/TokenUtil.java
@@ -50,6 +50,7 @@
    public final static String DEFAULT_TENANT_ID = "000000";
    public final static String USER_TYPE_HEADER_KEY = "User-Type";
    public final static String DEFAULT_USER_TYPE = "web";
    public final static String USER_TYPE_WX = "wx";
    public final static String USER_NOT_FOUND = "用户名或密码错误";
    public final static String USER_HAS_NO_ROLE = "未获得用户的角色信息";
    public final static String USER_HAS_NO_TENANT = "未获得用户的租户信息";
src/main/java/org/springblade/modules/system/controller/UserWxController.java
New file
@@ -0,0 +1,117 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.aliyun.oss.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.minio.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.apache.commons.codec.Charsets;
import org.springblade.common.config.FileConfig;
import org.springblade.common.config.FtpConfig;
import org.springblade.common.excel.RowWriteHandler;
import org.springblade.common.utils.ImageUtils;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.*;
import org.springblade.modules.accreditation.entity.AccreditationRecords;
import org.springblade.modules.accreditation.service.AccreditationRecordsService;
import org.springblade.modules.dispatcher.entity.Dispatcher;
import org.springblade.modules.dispatcher.service.IDispatcherService;
import org.springblade.modules.experience.entity.Experience;
import org.springblade.modules.experience.service.IExperienceService;
import org.springblade.modules.jurisdiction.entity.Jurisdiction;
import org.springblade.modules.jurisdiction.service.JurisdictionService;
import org.springblade.modules.securitypaper.entity.SecurityPaper;
import org.springblade.modules.securitypaper.service.SecurityPaperService;
import org.springblade.modules.signinrecords.entity.SignInRecords;
import org.springblade.modules.signinrecords.service.SignInRecordsService;
import org.springblade.modules.system.entity.*;
import org.springblade.modules.system.excel.*;
import org.springblade.modules.system.node.TreeNode;
import org.springblade.modules.system.service.*;
import org.springblade.modules.system.vo.UserInfoDetail;
import org.springblade.modules.system.vo.UserVO;
import org.springblade.modules.system.wrapper.UserWrapper;
import org.springblade.modules.training.entity.TrainingRegistration;
import org.springblade.modules.training.service.TrainingRegistrationService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
import sun.misc.BASE64Decoder;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
/**
 * 控制器
 *
 * @author Chill
 */
@NonDS
@ApiIgnore
@RestController
@RequestMapping("/userWx")
@AllArgsConstructor
public class UserWxController {
    private final IUserWxService userWxService;
    /**
     * 微信注册
     * @param user
     * @return
     */
    @PostMapping("/wxRegister")
    public R wxRegister(UserWx user){
        Boolean result = userWxService.wxRegister(user);
        return R.status(result);
    }
}
src/main/java/org/springblade/modules/system/entity/UserWx.java
New file
@@ -0,0 +1,268 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
 * 实体类
 *
 * @author Chill
 */
@Data
@TableName("blade_user_wx")
@EqualsAndHashCode(callSuper = true)
public class UserWx extends TenantEntity {
    private static final long serialVersionUID = 1L;
    /**
     * 用户编号
     */
    private String code;
    /**
     * 用户平台
     */
    private Integer userType;
    /**
     * 账号
     */
    private String account;
    /**
     * 密码
     */
    private String password;
    /**
     * 昵称
     */
    private String name;
    /**
     * 真名
     */
    private String realName;
    /**
     * 头像
     */
    private String avatar;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 手机
     */
    private String phone;
    /**
     * 生日
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;
    /**
     * 性别
     */
    private Integer sex;
    /**
     * 角色id
     */
    private String roleId;
    /**
     * 部门id
     */
    private String deptId;
    /**
     * 岗位id
     */
    private String postId;
    /**
     * 身份证
     */
    private String cardid;
    /**
     * 籍贯
     */
    @ApiModelProperty(value = "籍贯")
    @TableField("nativePlace")
    private String nativeplace;
    /**
     * 民族
     */
    @ApiModelProperty(value = "民族")
    private String nation;
    /**
     * 学历
     */
    @ApiModelProperty(value = "学历")
    private String education;
    /**
     * 政治面貌
     */
    @ApiModelProperty(value = "政治面貌")
    private String politicaloutlook;
    /**
     * 身高
     */
    @ApiModelProperty(value = "身高")
    private String height;
    /**
     * 联系电话
     */
    @ApiModelProperty(value = "联系电话")
    private String cell;
    /**
     * 邮箱
     */
    @ApiModelProperty(value = "邮箱")
    private String emails;
    private String hold;
    private Integer status;
    /**
     * 行政区域id
     */
    private String jurisdiction;
    /**
     * 保安员证编码
     */
    private String securitynumber;
    /**
     * 审查状态
     */
    @TableField("examination_type")
    private String examinationType;
    /**
     * 审查明细
     */
    @TableField("examination_mx")
    private String examinationMx;
    /**
     * 指纹url
     */
    private String fingerprint;
    /**
     * 是否采集照片
     */
    private String photo;
    /**
     * 是否派遣
     */
    private String dispatch;
    /**
     * 指纹特征
     */
    @TableField("my_picture")
    private String myPicture;
    /**
     * 是否报名考试   1:是   2:否
     */
    @TableField("is_apply")
    private Integer isApply;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthtime;
    /**
     * 是否报名培训  1:是   2:否
     */
    @TableField("is_train")
    private Integer isTrain;
    /**
     * 健康状态  0:健康 1:良好 2:一般 3:较差
     */
    private  String healstats;
    private  String soil;
    /**
     * 发证日期(保安证)
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @TableField("paper_time")
    private Date paperTime;
    /**
     * 离职原因
     */
    @TableField("reason_for_leav")
    private String reasonForLeav;
    /**
     * 离职图片
     */
    @TableField("img_for_leav")
    private String imgForLeav;
    private String holdv;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date holdvtime;
    /**
     * 是否缴纳保险 0:是   1:否
     */
    private Integer insurance;
    /**
     * 审查时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("audit_time")
    private Date auditTime;
    /**
     * 持枪编码
     */
    private String guncode;
    /**
     * 押运人员设备编号
     */
    @TableField("equipment_code")
    private String equipmentCode;
    /**
     * 是否冻结 0:否  1:是
     */
    private Integer isFreeze;
    /**
     * 审核状态:1、审核通过;2、审核不通过 10、待审核
     */
    private Integer auditStatus;
}
src/main/java/org/springblade/modules/system/mapper/UserWxMapper.java
New file
@@ -0,0 +1,8 @@
package org.springblade.modules.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springblade.modules.system.entity.UserWx;
public interface UserWxMapper extends BaseMapper<UserWx> {
    UserWx getUserWx(String tenantId, String account, String password);
}
src/main/java/org/springblade/modules/system/mapper/UserWxMapper.xml
New file
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.system.mapper.UserWxMapper">
    <select id="getUserWx" resultType="org.springblade.modules.system.entity.UserWx">
        SELECT *
        FROM blade_user_wx
        WHERE tenant_id = #{param1}
          and account = #{param2}
          and password = #{param3}
          and is_deleted = 0
          and status = 1
    </select>
</mapper>
src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -135,6 +135,17 @@
    /**
     * 用户信息
     * @param tenantId
     * @param account
     * @param password
     * @param userEnum
     * @return
     */
    UserInfo wxUserInfo(String tenantId, String account, String password, UserEnum userEnum);
    /**
     * 用户信息
     *
     * @param userOauth
     * @return
@@ -437,4 +448,5 @@
    boolean batchAudit(String ids, String auditStatus);
    void importSecurityPaperTime(List<UserCertificateExcel> data, Boolean isCovered, String deptId);
}
src/main/java/org/springblade/modules/system/service/IUserWxService.java
New file
@@ -0,0 +1,16 @@
package org.springblade.modules.system.service;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.entity.UserWx;
public interface IUserWxService extends BaseService<UserWx> {
    /**
     * 微信注册用户存入到微信用户表中
     * @param user
     * @return
     */
    Boolean wxRegister(UserWx user);
    UserWx getUserWx(String tenantId, String account, String password);
}
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -104,6 +104,8 @@
    private final SecurityPaperService securityPaperService;
    private final IUserDetailService userDetailService;
    private final IUserWxService userWxService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submit(User user) {
@@ -322,6 +324,89 @@
        User user = baseMapper.getUser(tenantId, account, password);
        return buildUserInfo(user, userEnum);
    }
    @Override
    public UserInfo wxUserInfo(String tenantId, String account, String password, UserEnum userEnum) {
        //先去blade_user_wx表里查
        UserWx userWx = userWxService.getUserWx(tenantId, account, password);
        if (userWx != null){
            //根据身份证号去user表里查
            User userParam = new User();
            userParam.setCardid(userWx.getCardid());
            userParam.setIsDeleted(0);
            List<User> list = list(Condition.getQueryWrapper(userParam));
            //user表里有数据,就直接返回user表的数据
            if (list.size()>0){
                User user = list.get(0);
                return buildUserInfo(user, userEnum);
            }else{
                //
                User user = BuildUser(userWx);
                return buildUserInfo(user, userEnum);
            }
        }else{
            return null;
        }
    }
    private User BuildUser(UserWx userWx) {
        User user = new User();
        user.setId(userWx.getId());
        user.setCode(userWx.getCode());
        user.setUserType(userWx.getUserType());
        user.setAccount(userWx.getAccount());
        user.setPassword(userWx.getPassword());
        user.setName(userWx.getName());
        user.setRealName(userWx.getRealName());
        user.setAvatar(userWx.getAvatar());
        user.setEmail(userWx.getEmail());
        user.setPhone(userWx.getPhone());
        user.setBirthday(userWx.getBirthday());
        user.setSex(userWx.getSex());
        user.setRoleId(userWx.getRoleId());
        user.setDeptId(userWx.getDeptId());
        user.setPostId(userWx.getPostId());
        user.setCardid(userWx.getCardid());
        user.setNativeplace(userWx.getNativeplace());
        user.setNation(userWx.getNation());
        user.setEducation(userWx.getEducation());
        user.setPoliticaloutlook(userWx.getPoliticaloutlook());
        user.setHeight(userWx.getHeight());
        user.setCell(userWx.getCell());
        user.setEmail(userWx.getEmail());
        user.setHold(userWx.getHold());
        user.setStatus(userWx.getStatus());
        user.setJurisdiction(userWx.getJurisdiction());
        user.setSecuritynumber(userWx.getSecuritynumber());
        user.setExaminationType(userWx.getExaminationType());
        user.setFingerprint(userWx.getFingerprint());
        user.setPhoto(userWx.getPhoto());
        user.setDispatch(userWx.getDispatch());
        user.setMyPicture(userWx.getMyPicture());
        user.setIsApply(userWx.getIsApply());
        user.setBirthtime(userWx.getBirthtime());
        user.setIsTrain(userWx.getIsTrain());
        user.setHealstats(userWx.getHealstats());
        user.setSoil(userWx.getSoil());
        user.setPaperTime(userWx.getPaperTime());
        user.setReasonForLeav(userWx.getReasonForLeav());
        user.setImgForLeav(userWx.getImgForLeav());
        user.setHoldv(userWx.getHoldv());
        user.setHoldvtime(userWx.getHoldvtime());
        user.setInsurance(userWx.getInsurance());
        user.setAuditTime(userWx.getAuditTime());
        user.setGuncode(userWx.getGuncode());
        user.setEquipmentCode(userWx.getEquipmentCode());
        user.setIsFreeze(userWx.getIsFreeze());
        user.setAuditStatus(userWx.getAuditStatus());
        return user;
    }
    private UserInfo buildUserInfo(User user) {
        return buildUserInfo(user, UserEnum.WEB);
@@ -1999,4 +2084,5 @@
            }
        }
    }
}
src/main/java/org/springblade/modules/system/service/impl/UserWxServiceImpl.java
New file
@@ -0,0 +1,56 @@
package org.springblade.modules.system.service.impl;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.DigestUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.entity.UserWx;
import org.springblade.modules.system.mapper.UserWxMapper;
import org.springblade.modules.system.service.IUserWxService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserWxServiceImpl extends BaseServiceImpl<UserWxMapper, UserWx> implements IUserWxService {
    @Override
    public Boolean wxRegister(UserWx user) {
        //密码加密
        if (Func.isNotEmpty(user.getPassword())) {
            user.setPassword(DigestUtil.encrypt(user.getPassword()));
        }
        UserWx params = new UserWx();
        params.setCardid(user.getCardid());
        //查看数据库是否有相同身份证号
        List<UserWx> list = list(Condition.getQueryWrapper(params));
        if (list.size()>0){
            throw new ServiceException("该身份证号已注册");
        }
        //注册新用户
        user.setAccount(user.getPhone());
        //微信注册角色
        user.setRoleId("1734015564173127681");
        //微信注册机构
        user.setDeptId("1734016112398020609");
        user.setTenantId("000000");
        if (StringUtil.isNotBlank(user.getRealName())){
            user.setName(user.getRealName());
        }else{
            user.setName("微信用户"+user.getPhone());
            user.setRealName("微信用户"+user.getPhone());
        }
        boolean save = save(user);
        return save;
    }
    @Override
    public UserWx getUserWx(String tenantId, String account, String password) {
        return baseMapper.getUserWx(tenantId, account, password);
    }
}