Commit 59aca9d8 authored by liaoanyuan's avatar liaoanyuan

管理端登录实现

parent fe19ab49
......@@ -75,7 +75,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.22</version>
<version>1.2.1</version>
</dependency>
<!-- Redis -->
<dependency>
......
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.AccountInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.Map;
public interface AccountMapper extends BaseMapper<AccountInfo> {
/**
* 查询管理员信息
* @param map 查询参数
* @return
*/
AccountInfo getAccountInfo(Map<String,Object> map);
}
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.UserInfo;
import cn.wisenergy.model.vo.UserQueryVo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
*@ Description:
*@ Author : 86187
......@@ -34,4 +39,11 @@ public interface UsersMapper extends BaseMapper<UserInfo> {
int delById(@Param("id") Integer id);
int countByPhoneAnsUserId(@Param("phone") String phone,@Param("userId") Integer userId);
/**
* 查询用户信息
* @param map 查询参数
* @return
*/
List<UserInfo> getList(Map<String,Object> map);
}
<?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="cn.wisenergy.mapper.AccountMapper">
<resultMap id="AccountMap" type="cn.wisenergy.model.app.AccountInfo">
<id column="id" property="id"/>
<result column="user_name" property="userName"/>
<result column="password" property="password"/>
<result column="head_image" property="headImage"/>
<result column="is_delete" property="isDelete"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
account
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
user_name,password,head_image,is_delete,create_time,update_time
</sql>
<sql id="vals">
#{userName},#{password},#{headImage},
#{isDelete},now(),now()
</sql>
<sql id="updateCondition">
<if test="userName != null">user_name = #{userName},</if>
<if test="password != null">password =#{password},</if>
<if test="headImage != null">head_image =#{headImage},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="id != null">id = #{id}</if>
<if test="userName != null">and user_name = #{userName}</if>
<if test="password != null">and password =#{password}</if>
<if test="headImage != null">and head_image =#{headImage}</if>
<if test="isDelete != null">and is_delete = #{isDelete}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
<select id="getAccountInfo" resultMap="AccountMap" parameterType="map">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_name = #{userName}
and
is_delete=0;
</where>
</select>
</mapper>
\ No newline at end of file
package cn.wisenergy.model.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ApiModel(value = "AccountInfo")
public class AccountInfo implements Serializable {
private static final long serialVersionUID = 3050641578536493424L;
/**
* 管理员主键id
*/
@ApiModelProperty(name ="id",value = "管理员主键id")
private Integer id;
/**
* 管理员账号
*/
@ApiModelProperty(name = "name",value = "管理员账号")
private String userName;
/**
* 管理员密码
*/
@ApiModelProperty(name="password",value = "管理员密码")
private String password;
/**
* 头像
*/
@ApiModelProperty(name = "headImage",value = "头像")
private String headImage;
/**
* 是否删除
*/
@ApiModelProperty(name = "isDelete",value = "是否删除 0:正常 1:删除")
private Integer isDelete;
/**
* 创建时间
*/
@ApiModelProperty(name = "createTime",value = "创建时间")
private Date createTime;
/**
* 修改时间
*/
@ApiModelProperty(name = "updateTime",value = "修改时间")
private Date updateTime;
}
......@@ -10,6 +10,7 @@ import java.util.Date;
@Data
@ApiModel(value = "CardInfo")
public class CardInfo implements Serializable {
private static final long serialVersionUID = -5934833963262442092L;
/**
* 子卡id
*/
......
......@@ -10,6 +10,7 @@ import java.util.Date;
@Data
@ApiModel(value = "PayRecord")
public class PayRecord implements Serializable {
private static final long serialVersionUID = -1133836167538757507L;
/**
* 充值记录id
*/
......
......@@ -4,11 +4,13 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ApiModel(value = "RefillCard")
public class RefillCard {
public class RefillCard implements Serializable {
private static final long serialVersionUID = 4018232893584885138L;
/**
* 充值卡id
*/
......
......@@ -4,11 +4,13 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ApiModel(value = "SchemeInnfo")
public class SchemeInnfo {
public class SchemeInnfo implements Serializable {
private static final long serialVersionUID = 7020644673356401949L;
/**
* 方案id
*/
......
......@@ -4,11 +4,13 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ApiModel(value = "UserLimit")
public class UserLimit {
public class UserLimit implements Serializable {
private static final long serialVersionUID = 3956830394491346594L;
/**
* 用户卡点id
*/
......
......@@ -4,9 +4,12 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel(value = "UserVolunteer")
public class UserVolunteer {
public class UserVolunteer implements Serializable {
private static final long serialVersionUID = 8617194272686159825L;
/**
* 用户方案id
*/
......
......@@ -30,6 +30,6 @@ public abstract class BaseEntity implements Serializable {
* 删除标记
*/
@ApiModelProperty("是否删除 1,删除;0,未删除")
private String isDelete;
private Integer isDelete;
}
package cn.wisenergy.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel(value = "AccountDto")
public class AccountDto implements Serializable {
private static final long serialVersionUID = -6722696621467423127L;
/**
* 管理员账号
*/
@ApiModelProperty(name = "name",value = "管理员账号")
private String userName;
/**
* 头像
*/
@ApiModelProperty(name = "headImage",value = "头像")
private String headImage;
}
package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.dto.AccountDto;
import java.util.Map;
public interface AccountSerivce {
/**
* 查询管理员信息
* @param userName,password 查询参数
* @return
*/
R<AccountDto> getAccountInfo(String userName, String password);
}
package cn.wisenergy.service.app.impl;
import cn.hutool.crypto.digest.MD5;
import cn.wisenergy.common.utils.Md5Util;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.dto.AccountDto;
import cn.wisenergy.service.app.AccountSerivce;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Service
public class AccountSerivceImpl implements AccountSerivce {
@Autowired
private AccountMapper accountMapper;
@Override
public R<AccountDto> getAccountInfo(String userName, String password) {
log.info("AccountSerivceImpl[].getAccountInfo[].input.param:userName,password"+userName,password);
//创建参数容器map
HashMap<String, Object> map = new HashMap<>(4);
//将参数放入容器中
map.put("userName",userName);
//查询管理者信息
AccountInfo accountInfo = accountMapper.getAccountInfo(map);
//判断信息是否查询成功
if (null==accountInfo) {
//查询失败抛出异常
return R.error("用户不存在");
}
//将加密过后的密码与传输数据进行比较
String s = Md5Util.digestMD5(accountInfo.getPassword());
if (!password.equals(s)) {
return R.error("密码或者用户名错误");
}
//查询超过则进行数据copy
AccountDto accountDto = new AccountDto();
BeanUtils.copyProperties(accountInfo,accountDto);
//返回数据
return R.ok(accountDto);
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.dto.AccountDto;
import cn.wisenergy.service.app.AccountSerivce;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "管理员登录")
@RestController
@RequestMapping("/account")
@Slf4j
public class AccountController {
@Autowired
private AccountSerivce accountSerivce;
@ApiOperation(value = "管理员登录",notes = "管理员登录",httpMethod = "POST")
@ApiImplicitParams({
@ApiImplicitParam(name = "userName",value = "账号",required = true),
@ApiImplicitParam(name = "password",value = "密码",required = true)
})
@PostMapping("/login")
public R<AccountDto> getAccountInfo(String userName, String password){
log.info("AccountController[].getAccountInfo[].input.param:userName,password"+userName,password);
//判断参数是否为空
if (StringUtils.isEmpty(userName)||StringUtils.isEmpty(password)) {
return R.error("账号或密码为空");
}
//查询管理员信息
R<AccountDto> accountInfo1 = accountSerivce.getAccountInfo(userName, password);
//返回数据
return accountInfo1;
}
}
......@@ -5,7 +5,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/exam?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
username: root
password: root
password:
initial-size: 10
max-active: 100
min-idle: 10
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment