作者 朱兆平

卡口用户登录验证OK

  1 +package com.tianbo.warehouse.dao;
  2 +
  3 +import com.tianbo.warehouse.model.KakoUser;
  4 +
  5 +import java.util.List;
  6 +
  7 +public interface KakoUserMapper {
  8 + int deleteByPrimaryKey(String id);
  9 +
  10 + int insert(KakoUser record);
  11 +
  12 + int insertSelective(KakoUser record);
  13 +
  14 + KakoUser selectByPrimaryKey(String id);
  15 +
  16 + int updateByPrimaryKeySelective(KakoUser record);
  17 +
  18 + int updateByPrimaryKey(KakoUser record);
  19 +
  20 + List<KakoUser> selectByUsername(String userName);
  21 +
  22 + int lockUser(KakoUser record);
  23 +}
  1 +package com.tianbo.warehouse.model;
  2 +
  3 +import com.alibaba.fastjson.annotation.JSONField;
  4 +import com.alibaba.fastjson.serializer.SerializerFeature;
  5 +import org.springframework.security.core.GrantedAuthority;
  6 +import org.springframework.security.core.authority.SimpleGrantedAuthority;
  7 +import org.springframework.security.core.userdetails.UserDetails;
  8 +
  9 +import java.util.ArrayList;
  10 +import java.util.Collection;
  11 +import java.util.Date;
  12 +import java.util.List;
  13 +
  14 +public class KakoUser implements UserDetails {
  15 + private String id;
  16 +
  17 + private String companyId;
  18 +
  19 + private String officeId;
  20 +
  21 + private String loginName;
  22 +
  23 + private String password;
  24 +
  25 + private String no;
  26 +
  27 + private String name;
  28 +
  29 + private String email;
  30 +
  31 + private String phone;
  32 +
  33 + private String mobile;
  34 +
  35 + private String userType;
  36 +
  37 + private String photo;
  38 +
  39 + private String loginIp;
  40 +
  41 + private Date loginDate;
  42 +
  43 + private String loginFlag;
  44 +
  45 + private String createBy;
  46 +
  47 + private Date createDate;
  48 +
  49 + private String updateBy;
  50 +
  51 + private Date updateDate;
  52 +
  53 + private String remarks;
  54 +
  55 + private String delFlag;
  56 +
  57 + private String token;
  58 +
  59 + @JSONField(serialzeFeatures= {SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullStringAsEmpty})
  60 + private List<ROLE> roles;
  61 +
  62 + @JSONField(serialzeFeatures= {SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullStringAsEmpty})
  63 + private List<PERMISSION> permissions;
  64 +
  65 + public String getId() {
  66 + return id;
  67 + }
  68 +
  69 + public void setId(String id) {
  70 + this.id = id == null ? null : id.trim();
  71 + }
  72 +
  73 + public String getCompanyId() {
  74 + return companyId;
  75 + }
  76 +
  77 + public void setCompanyId(String companyId) {
  78 + this.companyId = companyId == null ? null : companyId.trim();
  79 + }
  80 +
  81 + public String getOfficeId() {
  82 + return officeId;
  83 + }
  84 +
  85 + public void setOfficeId(String officeId) {
  86 + this.officeId = officeId == null ? null : officeId.trim();
  87 + }
  88 +
  89 + public String getLoginName() {
  90 + return loginName;
  91 + }
  92 +
  93 + @Override
  94 + public String getUsername() {
  95 + return loginName;
  96 + }
  97 +
  98 + public void setLoginName(String loginName) {
  99 + this.loginName = loginName == null ? null : loginName.trim();
  100 + }
  101 +
  102 + @Override
  103 + public String getPassword() {
  104 + return password;
  105 + }
  106 +
  107 + public void setPassword(String password) {
  108 + this.password = password == null ? null : password.trim();
  109 + }
  110 +
  111 + public String getNo() {
  112 + return no;
  113 + }
  114 +
  115 + public void setNo(String no) {
  116 + this.no = no == null ? null : no.trim();
  117 + }
  118 +
  119 + public String getName() {
  120 + return name;
  121 + }
  122 +
  123 + public void setName(String name) {
  124 + this.name = name == null ? null : name.trim();
  125 + }
  126 +
  127 + public String getEmail() {
  128 + return email;
  129 + }
  130 +
  131 + public void setEmail(String email) {
  132 + this.email = email == null ? null : email.trim();
  133 + }
  134 +
  135 + public String getPhone() {
  136 + return phone;
  137 + }
  138 +
  139 + public void setPhone(String phone) {
  140 + this.phone = phone == null ? null : phone.trim();
  141 + }
  142 +
  143 + public String getMobile() {
  144 + return mobile;
  145 + }
  146 +
  147 + public void setMobile(String mobile) {
  148 + this.mobile = mobile == null ? null : mobile.trim();
  149 + }
  150 +
  151 + public String getUserType() {
  152 + return userType;
  153 + }
  154 +
  155 + public void setUserType(String userType) {
  156 + this.userType = userType == null ? null : userType.trim();
  157 + }
  158 +
  159 + public String getPhoto() {
  160 + return photo;
  161 + }
  162 +
  163 + public void setPhoto(String photo) {
  164 + this.photo = photo == null ? null : photo.trim();
  165 + }
  166 +
  167 + public String getLoginIp() {
  168 + return loginIp;
  169 + }
  170 +
  171 + public void setLoginIp(String loginIp) {
  172 + this.loginIp = loginIp == null ? null : loginIp.trim();
  173 + }
  174 +
  175 + public Date getLoginDate() {
  176 + return loginDate;
  177 + }
  178 +
  179 + public void setLoginDate(Date loginDate) {
  180 + this.loginDate = loginDate;
  181 + }
  182 +
  183 + public String getLoginFlag() {
  184 + return loginFlag;
  185 + }
  186 +
  187 + public void setLoginFlag(String loginFlag) {
  188 + this.loginFlag = loginFlag == null ? null : loginFlag.trim();
  189 + }
  190 +
  191 + public String getCreateBy() {
  192 + return createBy;
  193 + }
  194 +
  195 + public void setCreateBy(String createBy) {
  196 + this.createBy = createBy == null ? null : createBy.trim();
  197 + }
  198 +
  199 + public Date getCreateDate() {
  200 + return createDate;
  201 + }
  202 +
  203 + public void setCreateDate(Date createDate) {
  204 + this.createDate = createDate;
  205 + }
  206 +
  207 + public String getUpdateBy() {
  208 + return updateBy;
  209 + }
  210 +
  211 + public void setUpdateBy(String updateBy) {
  212 + this.updateBy = updateBy == null ? null : updateBy.trim();
  213 + }
  214 +
  215 + public Date getUpdateDate() {
  216 + return updateDate;
  217 + }
  218 +
  219 + public void setUpdateDate(Date updateDate) {
  220 + this.updateDate = updateDate;
  221 + }
  222 +
  223 + public String getRemarks() {
  224 + return remarks;
  225 + }
  226 +
  227 + public void setRemarks(String remarks) {
  228 + this.remarks = remarks == null ? null : remarks.trim();
  229 + }
  230 +
  231 + public String getDelFlag() {
  232 + return delFlag;
  233 + }
  234 +
  235 + public void setDelFlag(String delFlag) {
  236 + this.delFlag = delFlag == null ? null : delFlag.trim();
  237 + }
  238 + public List<ROLE> getRoles() {
  239 + return roles;
  240 + }
  241 +
  242 + public void setRoles(List<ROLE> roles) {
  243 + this.roles = roles;
  244 + }
  245 +
  246 + public List<PERMISSION> getPermissions() {
  247 + return permissions;
  248 + }
  249 +
  250 + public void setPermissions(List<PERMISSION> permissions) {
  251 + this.permissions = permissions;
  252 + }
  253 + public String getToken() {
  254 + return token;
  255 + }
  256 +
  257 + public void setToken(String token) {
  258 + this.token = token;
  259 + }
  260 +
  261 + /**
  262 + *
  263 + * @return 账户未过期
  264 + */
  265 + @Override
  266 + public boolean isAccountNonExpired(){
  267 + return true;
  268 + }
  269 +
  270 + /**
  271 + *
  272 + * @return 账户未锁定
  273 + */
  274 + @Override
  275 + public boolean isAccountNonLocked(){
  276 + return true;
  277 + }
  278 +
  279 + /**
  280 + *
  281 + * @return 密码未过期
  282 + */
  283 + @Override
  284 + public boolean isCredentialsNonExpired(){
  285 + return true;
  286 + }
  287 +
  288 + /**
  289 + *
  290 + * @return 账户可用
  291 + */
  292 + @Override
  293 + public boolean isEnabled(){
  294 + if(loginFlag!=null && !loginFlag.isEmpty() && loginFlag.equals("1")){
  295 + return true;
  296 + }
  297 + return false;
  298 + }
  299 +
  300 + /**
  301 + *
  302 + * @return user的权限列表
  303 + */
  304 + @Override
  305 + public Collection<? extends GrantedAuthority> getAuthorities(){
  306 + List<GrantedAuthority> auths = new ArrayList<>();
  307 + if(roles!=null && !roles.isEmpty()){
  308 + for (ROLE role : roles) {
  309 + if (null != role){
  310 + auths.add(new SimpleGrantedAuthority(role.getAuthority()));
  311 + }
  312 + }
  313 + }
  314 + return auths;
  315 + }
  316 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.tianbo.warehouse.dao.KakoUserMapper" >
  4 + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.KakoUser" >
  5 + <id column="id" property="id" jdbcType="VARCHAR" />
  6 + <result column="company_id" property="companyId" jdbcType="VARCHAR" />
  7 + <result column="office_id" property="officeId" jdbcType="VARCHAR" />
  8 + <result column="login_name" property="loginName" jdbcType="VARCHAR" />
  9 + <result column="password" property="password" jdbcType="VARCHAR" />
  10 + <result column="no" property="no" jdbcType="VARCHAR" />
  11 + <result column="name" property="name" jdbcType="VARCHAR" />
  12 + <result column="email" property="email" jdbcType="VARCHAR" />
  13 + <result column="phone" property="phone" jdbcType="VARCHAR" />
  14 + <result column="mobile" property="mobile" jdbcType="VARCHAR" />
  15 + <result column="user_type" property="userType" jdbcType="CHAR" />
  16 + <result column="photo" property="photo" jdbcType="VARCHAR" />
  17 + <result column="login_ip" property="loginIp" jdbcType="VARCHAR" />
  18 + <result column="login_date" property="loginDate" jdbcType="TIMESTAMP" />
  19 + <result column="login_flag" property="loginFlag" jdbcType="VARCHAR" />
  20 + <result column="create_by" property="createBy" jdbcType="VARCHAR" />
  21 + <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
  22 + <result column="update_by" property="updateBy" jdbcType="VARCHAR" />
  23 + <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
  24 + <result column="remarks" property="remarks" jdbcType="VARCHAR" />
  25 + <result column="del_flag" property="delFlag" jdbcType="CHAR" />
  26 + </resultMap>
  27 + <sql id="Base_Column_List" >
  28 + id, company_id, office_id, login_name, password, no, name, email, phone, mobile,
  29 + user_type, photo, login_ip, login_date, login_flag, create_by, create_date, update_by,
  30 + update_date, remarks, del_flag
  31 + </sql>
  32 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
  33 + select
  34 + <include refid="Base_Column_List" />
  35 + from sys_user
  36 + where id = #{id,jdbcType=VARCHAR}
  37 + </select>
  38 + <select id="selectByUsername" resultMap="BaseResultMap" parameterType="java.lang.String" >
  39 + select
  40 + <include refid="Base_Column_List" />
  41 + from sys_user
  42 + where login_name = #{login_name,jdbcType=VARCHAR}
  43 + </select>
  44 + <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
  45 + delete from sys_user
  46 + where id = #{id,jdbcType=VARCHAR}
  47 + </delete>
  48 + <insert id="insert" parameterType="com.tianbo.warehouse.model.KakoUser" >
  49 + insert into sys_user (id, company_id, office_id,
  50 + login_name, password, no,
  51 + name, email, phone,
  52 + mobile, user_type, photo,
  53 + login_ip, login_date, login_flag,
  54 + create_by, create_date, update_by,
  55 + update_date, remarks, del_flag
  56 + )
  57 + values (#{id,jdbcType=VARCHAR}, #{companyId,jdbcType=VARCHAR}, #{officeId,jdbcType=VARCHAR},
  58 + #{loginName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{no,jdbcType=VARCHAR},
  59 + #{name,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
  60 + #{mobile,jdbcType=VARCHAR}, #{userType,jdbcType=CHAR}, #{photo,jdbcType=VARCHAR},
  61 + #{loginIp,jdbcType=VARCHAR}, #{loginDate,jdbcType=TIMESTAMP}, #{loginFlag,jdbcType=VARCHAR},
  62 + #{createBy,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR},
  63 + #{updateDate,jdbcType=TIMESTAMP}, #{remarks,jdbcType=VARCHAR}, #{delFlag,jdbcType=CHAR}
  64 + )
  65 + </insert>
  66 + <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.KakoUser" >
  67 + insert into sys_user
  68 + <trim prefix="(" suffix=")" suffixOverrides="," >
  69 + <if test="id != null" >
  70 + id,
  71 + </if>
  72 + <if test="companyId != null" >
  73 + company_id,
  74 + </if>
  75 + <if test="officeId != null" >
  76 + office_id,
  77 + </if>
  78 + <if test="loginName != null" >
  79 + login_name,
  80 + </if>
  81 + <if test="password != null" >
  82 + password,
  83 + </if>
  84 + <if test="no != null" >
  85 + no,
  86 + </if>
  87 + <if test="name != null" >
  88 + name,
  89 + </if>
  90 + <if test="email != null" >
  91 + email,
  92 + </if>
  93 + <if test="phone != null" >
  94 + phone,
  95 + </if>
  96 + <if test="mobile != null" >
  97 + mobile,
  98 + </if>
  99 + <if test="userType != null" >
  100 + user_type,
  101 + </if>
  102 + <if test="photo != null" >
  103 + photo,
  104 + </if>
  105 + <if test="loginIp != null" >
  106 + login_ip,
  107 + </if>
  108 + <if test="loginDate != null" >
  109 + login_date,
  110 + </if>
  111 + <if test="loginFlag != null" >
  112 + login_flag,
  113 + </if>
  114 + <if test="createBy != null" >
  115 + create_by,
  116 + </if>
  117 + <if test="createDate != null" >
  118 + create_date,
  119 + </if>
  120 + <if test="updateBy != null" >
  121 + update_by,
  122 + </if>
  123 + <if test="updateDate != null" >
  124 + update_date,
  125 + </if>
  126 + <if test="remarks != null" >
  127 + remarks,
  128 + </if>
  129 + <if test="delFlag != null" >
  130 + del_flag,
  131 + </if>
  132 + </trim>
  133 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  134 + <if test="id != null" >
  135 + #{id,jdbcType=VARCHAR},
  136 + </if>
  137 + <if test="companyId != null" >
  138 + #{companyId,jdbcType=VARCHAR},
  139 + </if>
  140 + <if test="officeId != null" >
  141 + #{officeId,jdbcType=VARCHAR},
  142 + </if>
  143 + <if test="loginName != null" >
  144 + #{loginName,jdbcType=VARCHAR},
  145 + </if>
  146 + <if test="password != null" >
  147 + #{password,jdbcType=VARCHAR},
  148 + </if>
  149 + <if test="no != null" >
  150 + #{no,jdbcType=VARCHAR},
  151 + </if>
  152 + <if test="name != null" >
  153 + #{name,jdbcType=VARCHAR},
  154 + </if>
  155 + <if test="email != null" >
  156 + #{email,jdbcType=VARCHAR},
  157 + </if>
  158 + <if test="phone != null" >
  159 + #{phone,jdbcType=VARCHAR},
  160 + </if>
  161 + <if test="mobile != null" >
  162 + #{mobile,jdbcType=VARCHAR},
  163 + </if>
  164 + <if test="userType != null" >
  165 + #{userType,jdbcType=CHAR},
  166 + </if>
  167 + <if test="photo != null" >
  168 + #{photo,jdbcType=VARCHAR},
  169 + </if>
  170 + <if test="loginIp != null" >
  171 + #{loginIp,jdbcType=VARCHAR},
  172 + </if>
  173 + <if test="loginDate != null" >
  174 + #{loginDate,jdbcType=TIMESTAMP},
  175 + </if>
  176 + <if test="loginFlag != null" >
  177 + #{loginFlag,jdbcType=VARCHAR},
  178 + </if>
  179 + <if test="createBy != null" >
  180 + #{createBy,jdbcType=VARCHAR},
  181 + </if>
  182 + <if test="createDate != null" >
  183 + #{createDate,jdbcType=TIMESTAMP},
  184 + </if>
  185 + <if test="updateBy != null" >
  186 + #{updateBy,jdbcType=VARCHAR},
  187 + </if>
  188 + <if test="updateDate != null" >
  189 + #{updateDate,jdbcType=TIMESTAMP},
  190 + </if>
  191 + <if test="remarks != null" >
  192 + #{remarks,jdbcType=VARCHAR},
  193 + </if>
  194 + <if test="delFlag != null" >
  195 + #{delFlag,jdbcType=CHAR},
  196 + </if>
  197 + </trim>
  198 + </insert>
  199 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.KakoUser" >
  200 + update sys_user
  201 + <set >
  202 + <if test="companyId != null" >
  203 + company_id = #{companyId,jdbcType=VARCHAR},
  204 + </if>
  205 + <if test="officeId != null" >
  206 + office_id = #{officeId,jdbcType=VARCHAR},
  207 + </if>
  208 + <if test="loginName != null" >
  209 + login_name = #{loginName,jdbcType=VARCHAR},
  210 + </if>
  211 + <if test="password != null" >
  212 + password = #{password,jdbcType=VARCHAR},
  213 + </if>
  214 + <if test="no != null" >
  215 + no = #{no,jdbcType=VARCHAR},
  216 + </if>
  217 + <if test="name != null" >
  218 + name = #{name,jdbcType=VARCHAR},
  219 + </if>
  220 + <if test="email != null" >
  221 + email = #{email,jdbcType=VARCHAR},
  222 + </if>
  223 + <if test="phone != null" >
  224 + phone = #{phone,jdbcType=VARCHAR},
  225 + </if>
  226 + <if test="mobile != null" >
  227 + mobile = #{mobile,jdbcType=VARCHAR},
  228 + </if>
  229 + <if test="userType != null" >
  230 + user_type = #{userType,jdbcType=CHAR},
  231 + </if>
  232 + <if test="photo != null" >
  233 + photo = #{photo,jdbcType=VARCHAR},
  234 + </if>
  235 + <if test="loginIp != null" >
  236 + login_ip = #{loginIp,jdbcType=VARCHAR},
  237 + </if>
  238 + <if test="loginDate != null" >
  239 + login_date = #{loginDate,jdbcType=TIMESTAMP},
  240 + </if>
  241 + <if test="loginFlag != null" >
  242 + login_flag = #{loginFlag,jdbcType=VARCHAR},
  243 + </if>
  244 + <if test="createBy != null" >
  245 + create_by = #{createBy,jdbcType=VARCHAR},
  246 + </if>
  247 + <if test="createDate != null" >
  248 + create_date = #{createDate,jdbcType=TIMESTAMP},
  249 + </if>
  250 + <if test="updateBy != null" >
  251 + update_by = #{updateBy,jdbcType=VARCHAR},
  252 + </if>
  253 + <if test="updateDate != null" >
  254 + update_date = #{updateDate,jdbcType=TIMESTAMP},
  255 + </if>
  256 + <if test="remarks != null" >
  257 + remarks = #{remarks,jdbcType=VARCHAR},
  258 + </if>
  259 + <if test="delFlag != null" >
  260 + del_flag = #{delFlag,jdbcType=CHAR},
  261 + </if>
  262 + </set>
  263 + where id = #{id,jdbcType=VARCHAR}
  264 + </update>
  265 + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.KakoUser" >
  266 + update sys_user
  267 + set company_id = #{companyId,jdbcType=VARCHAR},
  268 + office_id = #{officeId,jdbcType=VARCHAR},
  269 + login_name = #{loginName,jdbcType=VARCHAR},
  270 + password = #{password,jdbcType=VARCHAR},
  271 + no = #{no,jdbcType=VARCHAR},
  272 + name = #{name,jdbcType=VARCHAR},
  273 + email = #{email,jdbcType=VARCHAR},
  274 + phone = #{phone,jdbcType=VARCHAR},
  275 + mobile = #{mobile,jdbcType=VARCHAR},
  276 + user_type = #{userType,jdbcType=CHAR},
  277 + photo = #{photo,jdbcType=VARCHAR},
  278 + login_ip = #{loginIp,jdbcType=VARCHAR},
  279 + login_date = #{loginDate,jdbcType=TIMESTAMP},
  280 + login_flag = #{loginFlag,jdbcType=VARCHAR},
  281 + create_by = #{createBy,jdbcType=VARCHAR},
  282 + create_date = #{createDate,jdbcType=TIMESTAMP},
  283 + update_by = #{updateBy,jdbcType=VARCHAR},
  284 + update_date = #{updateDate,jdbcType=TIMESTAMP},
  285 + remarks = #{remarks,jdbcType=VARCHAR},
  286 + del_flag = #{delFlag,jdbcType=CHAR}
  287 + where id = #{id,jdbcType=VARCHAR}
  288 + </update>
  289 +
  290 + <update id="lockUser" parameterType="com.tianbo.warehouse.model.KakoUser" >
  291 + update sys_user
  292 + set
  293 + login_flag = #{loginFlag,jdbcType=VARCHAR}
  294 + where login_name = #{loginName,jdbcType=VARCHAR}
  295 + </update>
  296 +</mapper>