From 82f1b9b696892e6b57b2202bd4e51a0b03bcac96 Mon Sep 17 00:00:00 2001 From: liyunfengfengfeng <2305743208@qq.com> Date: Sun, 25 Mar 2018 21:49:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=A8=A1=E5=9D=97...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yingjun/ssm/aop/BindingResultAop.java | 2 +- .../com/yingjun/ssm/dao/TOpreatorUserDao.java | 74 +++++++ .../com/yingjun/ssm/entity/TOpreatorUser.java | 144 ++++++++++++++ .../ssm/service/TOpreatorUserService.java | 73 +++++++ .../impl/TOpreatorUserServiceImpl.java | 93 +++++++++ .../java/com/yingjun/ssm/util/CodeUtil.java | 4 +- .../yingjun/ssm/web/AdminLoginController.java | 73 +++++++ .../resources/mapper/TOpreatorUserMapper.xml | 180 ++++++++++++++++++ .../webapp/WEB-INF/jsp/admin/adminLogin.jsp | 105 ++++++++++ src/main/webapp/WEB-INF/jsp/admin/success.jsp | 24 +++ 10 files changed, 768 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/yingjun/ssm/dao/TOpreatorUserDao.java create mode 100644 src/main/java/com/yingjun/ssm/entity/TOpreatorUser.java create mode 100644 src/main/java/com/yingjun/ssm/service/TOpreatorUserService.java create mode 100644 src/main/java/com/yingjun/ssm/service/impl/TOpreatorUserServiceImpl.java create mode 100644 src/main/java/com/yingjun/ssm/web/AdminLoginController.java create mode 100644 src/main/resources/mapper/TOpreatorUserMapper.xml create mode 100644 src/main/webapp/WEB-INF/jsp/admin/adminLogin.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/admin/success.jsp diff --git a/src/main/java/com/yingjun/ssm/aop/BindingResultAop.java b/src/main/java/com/yingjun/ssm/aop/BindingResultAop.java index 07cd302..c404e46 100644 --- a/src/main/java/com/yingjun/ssm/aop/BindingResultAop.java +++ b/src/main/java/com/yingjun/ssm/aop/BindingResultAop.java @@ -25,7 +25,7 @@ public class BindingResultAop { @Around("aopMethod()") public Object around(ProceedingJoinPoint joinPoint) throws Throwable{ - LOG.info("采用AOP的方式检查用户是否登录"); + //LOG.info("采用AOP的方式检查用户是否登录"); return joinPoint.proceed(); } diff --git a/src/main/java/com/yingjun/ssm/dao/TOpreatorUserDao.java b/src/main/java/com/yingjun/ssm/dao/TOpreatorUserDao.java new file mode 100644 index 0000000..ff1e783 --- /dev/null +++ b/src/main/java/com/yingjun/ssm/dao/TOpreatorUserDao.java @@ -0,0 +1,74 @@ +package com.yingjun.ssm.dao; +import com.yingjun.ssm.entity.TOpreatorUser; +import java.util.List; +/** + * 管理员 + * @author liyunfeng + */ +public interface TOpreatorUserDao{ + /** + * 获得TOpreatorUser数据的总行数 + * @return + */ + public long getTOpreatorUserRowCount(); + /** + * 获得TOpreatorUser数据集合 + * @return + */ + public List selectTOpreatorUser(); + /** + * 获得一个TOpreatorUser对象,以参数TOpreatorUser对象中不为空的属性作为条件进行查询 + * @param obj + * @return + */ + public TOpreatorUser selectTOpreatorUserByObj(TOpreatorUser obj); + /** + * 通过TOpreatorUser的id获得TOpreatorUser对象 + * @param id + * @return + */ + public TOpreatorUser selectTOpreatorUserById(Long id); + /** + * 插入TOpreatorUser到数据库,包括null值 + * @param value + * @return + */ + public int insertTOpreatorUser(TOpreatorUser value); + /** + * 插入TOpreatorUser中属性值不为null的数据到数据库 + * @param value + * @return + */ + public int insertNonEmptyTOpreatorUser(TOpreatorUser value); + /** + * 批量插入TOpreatorUser到数据库,包括null值 + * @param value + * @return + */ + public int insertTOpreatorUserByBatch(List value); + /** + * 通过TOpreatorUser的id删除TOpreatorUser + * @param id + * @return + */ + public int deleteTOpreatorUserById(Long id); + /** + * 通过TOpreatorUser的id更新TOpreatorUser中的数据,包括null值 + * @param enti + * @return + */ + public int updateTOpreatorUserById(TOpreatorUser enti); + /** + * 通过TOpreatorUser的id更新TOpreatorUser中属性不为null的数据 + * @param enti + * @return + */ + public int updateNonEmptyTOpreatorUserById(TOpreatorUser enti); + + /** + * 根据邮箱以及密码查询管理员信息 + * @param opreatorUser + * @return + */ + public TOpreatorUser queryAdminInfo(TOpreatorUser opreatorUser); +} \ No newline at end of file diff --git a/src/main/java/com/yingjun/ssm/entity/TOpreatorUser.java b/src/main/java/com/yingjun/ssm/entity/TOpreatorUser.java new file mode 100644 index 0000000..a51de5d --- /dev/null +++ b/src/main/java/com/yingjun/ssm/entity/TOpreatorUser.java @@ -0,0 +1,144 @@ +package com.yingjun.ssm.entity; +/** + * @author liyunfeng + */ +public class TOpreatorUser { + /** + * id + */ + private Long id; + /** + * 有效性 + */ + private Integer valid; + /** + * 运维名称 + */ + private String operatorName; + /** + * 手机号 + */ + private String phoneNo; + /** + * 更新时间 + */ + private java.util.Date updateTime; + /** + * 创建时间 + */ + private java.util.Date createTime; + /** + * 角色(1:管理员;2:运维) + */ + private Integer roleId; + /** + * 运维密码 + */ + private String operatorPassword; + /** + * 运维Id + */ + private String operatorAccount; + + /** + * 邮件 + */ + private String email; + + public TOpreatorUser() { + super(); + } + public TOpreatorUser(Long id,Integer valid,String operatorName,String phoneNo,java.util.Date updateTime,java.util.Date createTime,Integer roleId,String operatorPassword,String operatorAccount,String email) { + super(); + this.id = id; + this.valid = valid; + this.operatorName = operatorName; + this.phoneNo = phoneNo; + this.updateTime = updateTime; + this.createTime = createTime; + this.roleId = roleId; + this.operatorPassword = operatorPassword; + this.operatorAccount = operatorAccount; + this.email = email; + } + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getValid() { + return this.valid; + } + + public void setValid(Integer valid) { + this.valid = valid; + } + + public String getOperatorName() { + return this.operatorName; + } + + public void setOperatorName(String operatorName) { + this.operatorName = operatorName; + } + + public String getPhoneNo() { + return this.phoneNo; + } + + public void setPhoneNo(String phoneNo) { + this.phoneNo = phoneNo; + } + + public java.util.Date getUpdateTime() { + return this.updateTime; + } + + public void setUpdateTime(java.util.Date updateTime) { + this.updateTime = updateTime; + } + + public java.util.Date getCreateTime() { + return this.createTime; + } + + public void setCreateTime(java.util.Date createTime) { + this.createTime = createTime; + } + + public Integer getRoleId() { + return this.roleId; + } + + public void setRoleId(Integer roleId) { + this.roleId = roleId; + } + + public String getOperatorPassword() { + return this.operatorPassword; + } + + public void setOperatorPassword(String operatorPassword) { + this.operatorPassword = operatorPassword; + } + + public String getOperatorAccount() { + return this.operatorAccount; + } + + public void setOperatorAccount(String operatorAccount) { + this.operatorAccount = operatorAccount; + } + + public String getEmail() { + return this.email; + } + + public void setEmail(String email) { + this.email = email; + } + +} diff --git a/src/main/java/com/yingjun/ssm/service/TOpreatorUserService.java b/src/main/java/com/yingjun/ssm/service/TOpreatorUserService.java new file mode 100644 index 0000000..670c040 --- /dev/null +++ b/src/main/java/com/yingjun/ssm/service/TOpreatorUserService.java @@ -0,0 +1,73 @@ +package com.yingjun.ssm.service; +import java.util.List; +import com.yingjun.ssm.entity.TOpreatorUser; +/** + * 管理员 + * @author liyunfeng + */ +public interface TOpreatorUserService{ + /** + * 获得TOpreatorUser数据的总行数 + * @return + */ + public long getTOpreatorUserRowCount(); + /** + * 获得TOpreatorUser数据集合 + * @return + */ + public List selectTOpreatorUser(); + /** + * 获得一个TOpreatorUser对象,以参数TOpreatorUser对象中不为空的属性作为条件进行查询 + * @param obj + * @return + */ + public TOpreatorUser selectTOpreatorUserByObj(TOpreatorUser obj); + /** + * 通过TOpreatorUser的id获得TOpreatorUser对象 + * @param id + * @return + */ + public TOpreatorUser selectTOpreatorUserById(Long id); + /** + * 插入TOpreatorUser到数据库,包括null值 + * @param value + * @return + */ + public int insertTOpreatorUser(TOpreatorUser value); + /** + * 插入TOpreatorUser中属性值不为null的数据到数据库 + * @param value + * @return + */ + public int insertNonEmptyTOpreatorUser(TOpreatorUser value); + /** + * 批量插入TOpreatorUser到数据库 + * @param value + * @return + */ + public int insertTOpreatorUserByBatch(List value); + /** + * 通过TOpreatorUser的id删除TOpreatorUser + * @param id + * @return + */ + public int deleteTOpreatorUserById(Long id); + /** + * 通过TOpreatorUser的id更新TOpreatorUser中的数据,包括null值 + * @param enti + * @return + */ + public int updateTOpreatorUserById(TOpreatorUser enti); + /** + * 通过TOpreatorUser的id更新TOpreatorUser中属性不为null的数据 + * @param enti + * @return + */ + public int updateNonEmptyTOpreatorUserById(TOpreatorUser enti); + + /** + * 处理管理员登录 + * @param opreatorUser + */ + public TOpreatorUser checkAdminLogin(TOpreatorUser opreatorUser); +} \ No newline at end of file diff --git a/src/main/java/com/yingjun/ssm/service/impl/TOpreatorUserServiceImpl.java b/src/main/java/com/yingjun/ssm/service/impl/TOpreatorUserServiceImpl.java new file mode 100644 index 0000000..86af0d8 --- /dev/null +++ b/src/main/java/com/yingjun/ssm/service/impl/TOpreatorUserServiceImpl.java @@ -0,0 +1,93 @@ +package com.yingjun.ssm.service.impl; +import java.util.List; +import com.yingjun.ssm.dao.TOpreatorUserDao; +import com.yingjun.ssm.entity.TOpreatorUser; +import com.yingjun.ssm.entity.User; +import com.yingjun.ssm.exception.BizException; +import com.yingjun.ssm.service.TOpreatorUserService; +import com.yingjun.ssm.util.Md5Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * 管理员 + * @author liyunfeng + */ +@Service +public class TOpreatorUserServiceImpl implements TOpreatorUserService{ + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); + @Autowired + private TOpreatorUserDao tOpreatorUserDao; + @Override + public long getTOpreatorUserRowCount(){ + return tOpreatorUserDao.getTOpreatorUserRowCount(); + } + @Override + public List selectTOpreatorUser(){ + return tOpreatorUserDao.selectTOpreatorUser(); + } + @Override + public TOpreatorUser selectTOpreatorUserByObj(TOpreatorUser obj){ + return tOpreatorUserDao.selectTOpreatorUserByObj(obj); + } + @Override + public TOpreatorUser selectTOpreatorUserById(Long id){ + return tOpreatorUserDao.selectTOpreatorUserById(id); + } + @Override + public int insertTOpreatorUser(TOpreatorUser value){ + return tOpreatorUserDao.insertTOpreatorUser(value); + } + @Override + public int insertNonEmptyTOpreatorUser(TOpreatorUser value){ + return tOpreatorUserDao.insertNonEmptyTOpreatorUser(value); + } + @Override + public int insertTOpreatorUserByBatch(List value){ + return tOpreatorUserDao.insertTOpreatorUserByBatch(value); + } + @Override + public int deleteTOpreatorUserById(Long id){ + return tOpreatorUserDao.deleteTOpreatorUserById(id); + } + @Override + public int updateTOpreatorUserById(TOpreatorUser enti){ + return tOpreatorUserDao.updateTOpreatorUserById(enti); + } + @Override + public int updateNonEmptyTOpreatorUserById(TOpreatorUser enti){ + return tOpreatorUserDao.updateNonEmptyTOpreatorUserById(enti); + } + + /** + * 处理管理员登录 + * @param opreatorUser 管理员登录相关信息 + */ + @Override + public TOpreatorUser checkAdminLogin(TOpreatorUser opreatorUser) { + try{ + //加密密码 + opreatorUser.setOperatorPassword(Md5Util.md5Password(opreatorUser.getOperatorPassword())); + TOpreatorUser tOpreatorUser = tOpreatorUserDao.queryAdminInfo(opreatorUser); + if(tOpreatorUser == null){ + throw new BizException("邮箱或密码错误"); + } + return tOpreatorUser; + }catch (BizException biz){ + throw new BizException("邮箱或密码错误",biz); + }catch (Exception e){ + throw new RuntimeException("登录出现异常",e); + } + } + + public TOpreatorUserDao getTOpreatorUserDao() { + return this.tOpreatorUserDao; + } + + public void setTOpreatorUserDao(TOpreatorUserDao tOpreatorUserDao) { + this.tOpreatorUserDao = tOpreatorUserDao; + } + +} \ No newline at end of file diff --git a/src/main/java/com/yingjun/ssm/util/CodeUtil.java b/src/main/java/com/yingjun/ssm/util/CodeUtil.java index 60ae3ed..ce94b9f 100644 --- a/src/main/java/com/yingjun/ssm/util/CodeUtil.java +++ b/src/main/java/com/yingjun/ssm/util/CodeUtil.java @@ -14,7 +14,5 @@ public class CodeUtil { public static String rand(){ return getRandNum(100000,999999).toString().trim(); } - public static void main(String[]args){ - rand(); - } + public static void main(String[]args){rand();} } diff --git a/src/main/java/com/yingjun/ssm/web/AdminLoginController.java b/src/main/java/com/yingjun/ssm/web/AdminLoginController.java new file mode 100644 index 0000000..e0518a7 --- /dev/null +++ b/src/main/java/com/yingjun/ssm/web/AdminLoginController.java @@ -0,0 +1,73 @@ +package com.yingjun.ssm.web; + + +import com.google.gson.Gson; +import com.yingjun.ssm.dto.BaseResult; +import com.yingjun.ssm.entity.TOpreatorUser; +import com.yingjun.ssm.entity.User; +import com.yingjun.ssm.enums.ResultEnum; +import com.yingjun.ssm.exception.BizException; +import com.yingjun.ssm.service.TOpreatorUserService; +import com.yingjun.ssm.service.UserService; +import com.yingjun.ssm.util.CodeUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpSession; + + +/** + * 管理员 + * @author liyunfeng + */ +@Controller +@RequestMapping("/admin") +public class AdminLoginController { + + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); + @Autowired + private TOpreatorUserService tOpreatorUserService; + /** + * 到达管理员登录页面 + * @return + */ + @RequestMapping(value = "/login") + public String login() { + return "/admin/adminLogin"; + } + /** + * 用户登录 + * @return + */ + @ResponseBody + @RequestMapping(value = "/adminLogin",produces = {"application/json;charset=UTF-8"}) + public BaseResult adminLogin(TOpreatorUser opreatorUser, + HttpSession session) { + try { + tOpreatorUserService.checkAdminLogin(opreatorUser); + session.setAttribute("email",opreatorUser.getEmail()); + } catch (BizException e) { + return new BaseResult<>(false, e.getMessage()); + } catch (Exception e) { + return new BaseResult<>(false, ResultEnum.INVALID_USER.getMsg()); + } + return new BaseResult<>(true, "登陆成功"); + } + + /** + * 管理员登录成功 + * @return + */ + @RequestMapping(value = "/adminLoginSuccess") + public String adminLoginSuccess() { + return "/admin/success"; + } + +} diff --git a/src/main/resources/mapper/TOpreatorUserMapper.xml b/src/main/resources/mapper/TOpreatorUserMapper.xml new file mode 100644 index 0000000..b70afb4 --- /dev/null +++ b/src/main/resources/mapper/TOpreatorUserMapper.xml @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + t_opreator_user.id as id + ,t_opreator_user.valid as valid + ,t_opreator_user.operator_name as operator_name + ,t_opreator_user.phone_no as phone_no + ,t_opreator_user.update_time as update_time + ,t_opreator_user.create_time as create_time + ,t_opreator_user.role_id as role_id + ,t_opreator_user.operator_password as operator_password + ,t_opreator_user.operator_account as operator_account + ,t_opreator_user.email as email + + + + + + + + + + + + + + + + + insert into t_opreator_user(id,valid,operator_name,phone_no,update_time,create_time,role_id,operator_password,operator_account,email) + values(#{id},#{valid},#{operatorName},#{phoneNo},#{updateTime},#{createTime},#{roleId},#{operatorPassword},#{operatorAccount},#{email}) + + + + + insert into t_opreator_user + + id, + valid, + operator_name, + phone_no, + update_time, + create_time, + role_id, + operator_password, + operator_account, + email, + + + #{id}, + #{valid}, + #{operatorName}, + #{phoneNo}, + #{updateTime}, + #{createTime}, + #{roleId}, + #{operatorPassword}, + #{operatorAccount}, + #{email}, + + + + + + insert into t_opreator_user(id,valid,operator_name,phone_no,update_time,create_time,role_id,operator_password,operator_account,email) values + + (#{item.id},#{item.valid},#{item.operatorName},#{item.phoneNo},#{item.updateTime},#{item.createTime},#{item.roleId},#{item.operatorPassword},#{item.operatorAccount},#{item.email}) + + + + + + delete from t_opreator_user + where id = #{id} + + + + + update t_opreator_user set + valid=#{valid} + ,operator_name=#{operatorName} + ,phone_no=#{phoneNo} + ,update_time=#{updateTime} + ,create_time=#{createTime} + ,role_id=#{roleId} + ,operator_password=#{operatorPassword} + ,operator_account=#{operatorAccount} + ,email=#{email} + where id=#{id} + + + + + update t_opreator_user + + + valid=#{valid}, + + + operator_name=#{operatorName}, + + + phone_no=#{phoneNo}, + + + update_time=#{updateTime}, + + + create_time=#{createTime}, + + + role_id=#{roleId}, + + + operator_password=#{operatorPassword}, + + + operator_account=#{operatorAccount}, + + + email=#{email}, + + + where id=#{id} + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/admin/adminLogin.jsp b/src/main/webapp/WEB-INF/jsp/admin/adminLogin.jsp new file mode 100644 index 0000000..8e55b3d --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/admin/adminLogin.jsp @@ -0,0 +1,105 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java"%> + + + + + 用户登录 + + + + + + + + + + + + + + + +
+
+ + +
+
+ +
+ +
+
+

管理员登录

+
+
+
+
    +
  • + +
  • +
  • + +
  • +
+
+ + +
+ +
+
+
+
+ + + + + diff --git a/src/main/webapp/WEB-INF/jsp/admin/success.jsp b/src/main/webapp/WEB-INF/jsp/admin/success.jsp new file mode 100644 index 0000000..c69e47c --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/admin/success.jsp @@ -0,0 +1,24 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java"%> + + + + + 用户登录 + + + + + + + + + + + + + + + + 管理员登录成功 + + -- GitLab