@@ -6,6 +6,8 @@ import com.taauav.admin.service.ISysAdminService; | |||
import com.taauav.admin.service.ISysAuthRuleService; | |||
import com.taauav.common.domain.Entity; | |||
import com.taauav.common.util.ShiroUtils; | |||
import com.taauav.front.entity.UserAdmin; | |||
import com.taauav.front.service.IUserAdminService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.shiro.SecurityUtils; | |||
import org.apache.shiro.authc.*; | |||
@@ -14,6 +16,7 @@ import org.apache.shiro.authz.SimpleAuthorizationInfo; | |||
import org.apache.shiro.realm.AuthorizingRealm; | |||
import org.apache.shiro.subject.PrincipalCollection; | |||
import org.apache.shiro.util.ByteSource; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.util.StringUtils; | |||
import javax.annotation.Resource; | |||
@@ -30,8 +33,11 @@ public class MyShiroRealm extends AuthorizingRealm { | |||
@Resource | |||
private ISysAdminService iSysAdminService; | |||
@Autowired | |||
private IUserAdminService userAdminService; | |||
@Resource | |||
private ISysAuthRuleService iSysAuthRuleService; | |||
/** | |||
* create by: dyg | |||
* description: 授权 | |||
@@ -65,7 +71,7 @@ public class MyShiroRealm extends AuthorizingRealm { | |||
} | |||
} | |||
return authorizationInfo; | |||
}else if(false) { | |||
} else if (false) { | |||
/**前台用户*/ | |||
return authorizationInfo; | |||
@@ -84,36 +90,58 @@ public class MyShiroRealm extends AuthorizingRealm { | |||
@Override | |||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { | |||
log.warn("开始进行身份认证......"); | |||
UsernamePasswordToken token; | |||
if (authenticationToken instanceof AdminUserToken) { //后台用户认证 | |||
token = (UsernamePasswordToken)authenticationToken; | |||
} else if(authenticationToken instanceof FrontUserToken) { //前台用户认证 | |||
token = (UsernamePasswordToken)authenticationToken; | |||
if (authenticationToken instanceof AdminUserToken) { | |||
// 后台用户认证 | |||
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; | |||
//获取用户的输入的账号. | |||
String userName = (String) token.getPrincipal(); | |||
//通过username从数据库中查找 User对象. | |||
//实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法 | |||
SysAdmin user = iSysAdminService.findByUsername(userName); | |||
if (Objects.isNull(user)) { | |||
throw new UnknownAccountException("用户名或密码错误"); | |||
} | |||
String status = "1"; | |||
if (!(status.equals(user.getStatus().toString()))) { | |||
throw new UnknownAccountException("账号已被锁定,请联系管理员!"); | |||
} | |||
return new SimpleAuthenticationInfo( | |||
// 这里传入的是user对象,比对的是用户名,直接传入用户名也没错,但是在授权部分就需要自己重新从数据库里取权限 | |||
user, | |||
// 密码 | |||
user.getPassword(), | |||
// salt = username + salt | |||
ByteSource.Util.bytes(""), | |||
// realm name | |||
getName() | |||
); | |||
} else if (authenticationToken instanceof FrontUserToken) { | |||
// 前台用户认证 | |||
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; | |||
//获取用户的输入的账号. | |||
String userName = (String) token.getPrincipal(); | |||
//通过username从数据库中查找 User对象. | |||
//实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法 | |||
UserAdmin user = userAdminService.findByUsername(userName); | |||
if (Objects.isNull(user)) { | |||
throw new UnknownAccountException("用户名或密码错误"); | |||
} | |||
String status = "1"; | |||
if (!(status.equals(user.getStatus().toString()))) { | |||
throw new UnknownAccountException("账号已被锁定,请联系管理员!"); | |||
} | |||
return new SimpleAuthenticationInfo( | |||
// 这里传入的是user对象,比对的是用户名,直接传入用户名也没错,但是在授权部分就需要自己重新从数据库里取权限 | |||
user, | |||
// 密码 | |||
user.getPassword(), | |||
// salt = username + salt | |||
ByteSource.Util.bytes(""), | |||
// realm name | |||
getName() | |||
); | |||
} else { | |||
throw new UnknownAccountException("用户名或密码错误"); | |||
} | |||
//获取用户的输入的账号. | |||
String userName = (String) token.getPrincipal(); | |||
//通过username从数据库中查找 User对象. | |||
//实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法 | |||
SysAdmin user = iSysAdminService.findByUsername(userName); | |||
if (Objects.isNull(user)) { | |||
throw new UnknownAccountException("用户名或密码错误"); | |||
} | |||
String status = "1"; | |||
if (!(status.equals(user.getStatus().toString()))) { | |||
throw new UnknownAccountException("账号已被锁定,请联系管理员!"); | |||
} | |||
return new SimpleAuthenticationInfo( | |||
// 这里传入的是user对象,比对的是用户名,直接传入用户名也没错,但是在授权部分就需要自己重新从数据库里取权限 | |||
user, | |||
// 密码 | |||
user.getPassword(), | |||
// salt = username + salt | |||
ByteSource.Util.bytes(""), | |||
// realm name | |||
getName() | |||
); | |||
} | |||
} |
@@ -2,6 +2,7 @@ package com.taauav.common.util; | |||
import com.taauav.admin.entity.SysAdmin; | |||
import com.taauav.common.domain.Entity; | |||
import com.taauav.front.entity.UserAdmin; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.shiro.SecurityUtils; | |||
import org.apache.shiro.authc.Authenticator; | |||
@@ -17,19 +18,24 @@ import java.util.Objects; | |||
/** | |||
* shiro工具类 | |||
* | |||
* @author dyg | |||
* @date 2019/11/06 | |||
*/ | |||
@Slf4j | |||
public class ShiroUtils { | |||
/** 私有构造器 **/ | |||
private ShiroUtils(){ } | |||
/** | |||
* 私有构造器 | |||
**/ | |||
private ShiroUtils() { | |||
} | |||
private static RedisSessionDAO redisSessionDAO = SpringUtil.getBean(RedisSessionDAO.class); | |||
/** | |||
* 获取当前用户信息 | |||
* | |||
* @return | |||
*/ | |||
public static SysAdmin getAdminInfo() { | |||
@@ -39,15 +45,25 @@ public class ShiroUtils { | |||
/** | |||
* 获取用户编号 | |||
* | |||
* @return | |||
*/ | |||
public static Integer getAdminId() { | |||
SysAdmin admin = getAdminInfo(); | |||
return admin.getId(); | |||
Object object = getObject(); | |||
if (object instanceof SysAdmin) { | |||
SysAdmin admin = (SysAdmin) SecurityUtils.getSubject().getPrincipal(); | |||
return admin.getId(); | |||
} else if (object instanceof UserAdmin) { | |||
UserAdmin admin = (UserAdmin) SecurityUtils.getSubject().getPrincipal(); | |||
return admin.getId(); | |||
} | |||
// 临时处理(待完善) | |||
return 1; | |||
} | |||
/** | |||
* 获取当前登录实体类 | |||
* | |||
* @return | |||
*/ | |||
public static Object getObject() { | |||
@@ -57,6 +73,7 @@ public class ShiroUtils { | |||
/** | |||
* 删除用户缓存信息 | |||
* | |||
* @param username | |||
* @param isRemoveSession | |||
*/ | |||
@@ -71,7 +88,7 @@ public class ShiroUtils { | |||
if (null == attribute) { | |||
continue; | |||
} | |||
sysAdmin = (SysAdmin)((SimplePrincipalCollection) attribute).getPrimaryPrincipal(); | |||
sysAdmin = (SysAdmin) ((SimplePrincipalCollection) attribute).getPrimaryPrincipal(); | |||
if (null == sysAdmin) { | |||
continue; | |||
} |
@@ -0,0 +1,36 @@ | |||
package com.taauav.front.constant; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* 通知公告 模块常量 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
public class UserNoticeConstant { | |||
/** | |||
* 公告类型:1水务新闻 2政策法规 | |||
*/ | |||
public static Map<Integer, String> USER_NOTICE_TYPE_LIST = new HashMap<Integer, String>() { | |||
{ | |||
put(1, "水务新闻"); | |||
put(2, "政策法规"); | |||
} | |||
}; | |||
/** | |||
* 发布状态 | |||
*/ | |||
public static Map<Integer, String> USER_NOTICE_STATUS_LIST = new HashMap<Integer, String>() { | |||
{ | |||
put(1, "已发布"); | |||
put(2, "待发布"); | |||
} | |||
}; | |||
} |
@@ -18,15 +18,15 @@ public class FrontBaseController { | |||
// */ | |||
// public Integer userId; | |||
/** | |||
* 将前台传递过来的日期格式的字符串,自动转化为Date类型 | |||
*/ | |||
@InitBinder | |||
public void initBinder(HttpServletRequest request, WebDataBinder binder) { | |||
System.out.println("初始化基类"); | |||
String token = request.getHeader("token"); | |||
Claims data = JwtUtil.parseJWT(token); | |||
// this.userId = Integer.valueOf(data.get("id").toString()); | |||
} | |||
// /** | |||
// * 将前台传递过来的日期格式的字符串,自动转化为Date类型 | |||
// */ | |||
// @InitBinder | |||
// public void initBinder(HttpServletRequest request, WebDataBinder binder) { | |||
// System.out.println("初始化基类"); | |||
// String token = request.getHeader("token"); | |||
// Claims data = JwtUtil.parseJWT(token); | |||
//// this.userId = Integer.valueOf(data.get("id").toString()); | |||
// } | |||
} |
@@ -0,0 +1,38 @@ | |||
package com.taauav.front.controller; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.front.service.IUserAdminService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.taauav.front.controller.FrontBaseController; | |||
/** | |||
* <p> | |||
* 外包人员表 前端控制器 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
@RestController | |||
@RequestMapping("/front/useradmin") | |||
public class UserAdminController extends FrontBaseController { | |||
@Autowired | |||
private IUserAdminService userAdminService; | |||
/** | |||
* 获取人员列表 | |||
* | |||
* @return | |||
*/ | |||
@PostMapping("/getUserAdminList") | |||
public Response getUserAdminList() { | |||
return userAdminService.getUserAdminList(); | |||
} | |||
} |
@@ -0,0 +1,83 @@ | |||
package com.taauav.front.controller; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.front.entity.UserNotice; | |||
import com.taauav.front.query.UserNoticeQuery; | |||
import com.taauav.front.service.IUserNoticeService; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import com.taauav.front.controller.FrontBaseController; | |||
/** | |||
* <p> | |||
* 通知公告表 前端控制器 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
@RestController | |||
@RequestMapping("/front/usernotice") | |||
public class UserNoticeController extends FrontBaseController { | |||
@Autowired | |||
private IUserNoticeService noticeService; | |||
/** | |||
* 获取通知公告列表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
@PostMapping("/index") | |||
public Response index(@RequestBody UserNoticeQuery query) { | |||
return noticeService.getNoticeList(query); | |||
} | |||
/** | |||
* 添加通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@PostMapping("/add") | |||
public Response add(@RequestBody UserNotice entity) { | |||
return noticeService.add(entity); | |||
} | |||
/** | |||
* 编辑通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@PostMapping("/edit") | |||
public Response edit(@RequestBody UserNotice entity) { | |||
return noticeService.edit(entity); | |||
} | |||
/** | |||
* 获取详情信息 | |||
* | |||
* @param noticeId 记录ID | |||
* @return | |||
*/ | |||
@GetMapping("/info") | |||
public Response info(Integer noticeId) { | |||
return noticeService.info(noticeId); | |||
} | |||
/** | |||
* 删除通知公告 | |||
* | |||
* @param noticeId 通知公告ID | |||
* @return | |||
*/ | |||
@PostMapping("/delete") | |||
public Response delete(Integer noticeId) { | |||
return noticeService.delete(noticeId); | |||
} | |||
} |
@@ -0,0 +1,112 @@ | |||
package com.taauav.front.entity; | |||
import java.time.LocalDateTime; | |||
import java.util.Date; | |||
import com.taauav.common.domain.Entity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* <p> | |||
* 外包人员表 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
public class UserAdmin extends Entity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 姓名 | |||
*/ | |||
private String realname; | |||
/** | |||
* 用户名 | |||
*/ | |||
private String username; | |||
/** | |||
* 密码 | |||
*/ | |||
private String password; | |||
/** | |||
* 头像 | |||
*/ | |||
private String avatar; | |||
/** | |||
* 性别:1男 2女 3保密 | |||
*/ | |||
private Integer gender; | |||
/** | |||
* 联系方式(手机号码) | |||
*/ | |||
private String mobile; | |||
/** | |||
* 邮箱 | |||
*/ | |||
private String email; | |||
/** | |||
* 河长等级:1一级 2二级 3三级 | |||
*/ | |||
private boolean level; | |||
/** | |||
* 区划ID | |||
*/ | |||
private Long driverArea; | |||
/** | |||
* 职务 | |||
*/ | |||
private String duty; | |||
/** | |||
* 角色编号 | |||
*/ | |||
private String authGroup; | |||
/** | |||
* Session标识 | |||
*/ | |||
private String token; | |||
/** | |||
* 备注 | |||
*/ | |||
private String note; | |||
/** | |||
* 最近登录时间 | |||
*/ | |||
private Date lastTime; | |||
/** | |||
* 登录次数 | |||
*/ | |||
private Integer loginNum; | |||
/** | |||
* 上次登录IP | |||
*/ | |||
private Long lastIp; | |||
/** | |||
* 排序 | |||
*/ | |||
private Integer sort; | |||
} |
@@ -0,0 +1,64 @@ | |||
package com.taauav.front.entity; | |||
import java.time.LocalDateTime; | |||
import java.util.Date; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import com.taauav.common.domain.Entity; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
/** | |||
* <p> | |||
* 通知公告表 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Accessors(chain = true) | |||
public class UserNotice extends Entity { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 公告标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 公告类型:1水务新闻 2政策法规 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 公告内容 | |||
*/ | |||
private String content; | |||
/** | |||
* 附件 | |||
*/ | |||
private String attachment; | |||
/** | |||
* 阅读量 | |||
*/ | |||
private Integer viewNum; | |||
/** | |||
* 发布人 | |||
*/ | |||
private Integer publishUser; | |||
/** | |||
* 发布时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
private Date publishTime; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.taauav.front.mapper; | |||
import com.taauav.front.entity.UserAdmin; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* 外包人员表 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
public interface UserAdminMapper extends BaseMapper<UserAdmin> { | |||
} |
@@ -0,0 +1,5 @@ | |||
<?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="com.taauav.front.mapper.UserAdminMapper"> | |||
</mapper> |
@@ -0,0 +1,16 @@ | |||
package com.taauav.front.mapper; | |||
import com.taauav.front.entity.UserNotice; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* 通知公告表 Mapper 接口 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
public interface UserNoticeMapper extends BaseMapper<UserNotice> { | |||
} |
@@ -0,0 +1,5 @@ | |||
<?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="com.taauav.front.mapper.UserNoticeMapper"> | |||
</mapper> |
@@ -0,0 +1,41 @@ | |||
package com.taauav.front.query; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import com.taauav.common.core.mps.BaseQuery; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.util.Date; | |||
/** | |||
* 通知公告查询条件 | |||
*/ | |||
@Data | |||
public class UserNoticeQuery extends BaseQuery { | |||
/** | |||
* 公告标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 公告类型 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 发布人ID | |||
*/ | |||
private Integer publishUser; | |||
/** | |||
* 发布开始时间 | |||
*/ | |||
private String startTime; | |||
/** | |||
* 发布结束时间 | |||
*/ | |||
private String endTime; | |||
} |
@@ -0,0 +1,32 @@ | |||
package com.taauav.front.service; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.service.IBaseService; | |||
import com.taauav.front.entity.UserAdmin; | |||
/** | |||
* <p> | |||
* 外包人员表 服务类 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
public interface IUserAdminService extends IBaseService<UserAdmin> { | |||
/** | |||
* 根据用户获取数据 | |||
* | |||
* @param username | |||
* @return | |||
*/ | |||
UserAdmin findByUsername(String username); | |||
/** | |||
* 获取人员列表 | |||
* | |||
* @return | |||
*/ | |||
Response getUserAdminList(); | |||
} |
@@ -0,0 +1,59 @@ | |||
package com.taauav.front.service; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.service.IBaseService; | |||
import com.taauav.front.entity.UserNotice; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
import com.taauav.front.query.UserNoticeQuery; | |||
/** | |||
* <p> | |||
* 通知公告表 服务类 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
public interface IUserNoticeService extends IBaseService<UserNotice> { | |||
/** | |||
* 获取通知公告列表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
Response getNoticeList(UserNoticeQuery query); | |||
/** | |||
* 添加通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
Response add(UserNotice entity); | |||
/** | |||
* 编辑通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
Response edit(UserNotice entity); | |||
/** | |||
* 获取通知公告详情 | |||
* | |||
* @param noticeId 通知公告ID | |||
* @return | |||
*/ | |||
Response info(Integer noticeId); | |||
/** | |||
* 删除通知公告 | |||
* | |||
* @param noticeId 通知公告ID | |||
* @return | |||
*/ | |||
Response delete(Integer noticeId); | |||
} |
@@ -2,7 +2,11 @@ package com.taauav.front.service.impl; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import com.taauav.admin.entity.SysAdmin; | |||
import com.taauav.common.bean.CacheUser; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.config.AdminUserToken; | |||
import com.taauav.common.config.FrontUserToken; | |||
import com.taauav.common.util.DateUtil; | |||
import com.taauav.common.util.FunctionUtils; | |||
import com.taauav.common.util.JwtUtil; | |||
@@ -10,7 +14,15 @@ import com.taauav.common.util.StringUtils; | |||
import com.taauav.front.dto.LoginDto; | |||
import com.taauav.admin.entity.LsAdmin; | |||
import com.taauav.admin.mapper.LsAdminMapper; | |||
import com.taauav.front.entity.UserAdmin; | |||
import com.taauav.front.service.ILSLoginService; | |||
import org.apache.shiro.SecurityUtils; | |||
import org.apache.shiro.authc.AuthenticationException; | |||
import org.apache.shiro.authc.IncorrectCredentialsException; | |||
import org.apache.shiro.authc.UnknownAccountException; | |||
import org.apache.shiro.authc.UsernamePasswordToken; | |||
import org.apache.shiro.subject.Subject; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@@ -42,47 +54,37 @@ public class LSLoginServiceImpl extends ServiceImpl<LsAdminMapper, LsAdmin> impl | |||
*/ | |||
@Override | |||
public Response login(LoginDto loginDto) { | |||
// 用户名校验 | |||
if (StringUtils.isEmpty(loginDto.getUsername())) { | |||
return response.failure("登录用户名不能为空"); | |||
} | |||
// 登录密码校验 | |||
if (StringUtils.isEmpty(loginDto.getPassword())) { | |||
return response.failure("登录密码不能为空"); | |||
} | |||
// 根据用户名获取用户信息 | |||
QueryWrapper<LsAdmin> queryWrapper = new QueryWrapper<>(); | |||
queryWrapper.eq("username", loginDto.getUsername()); | |||
queryWrapper.eq("mark", 1); | |||
LsAdmin adminInfo = adminMapper.selectOne(queryWrapper); | |||
if (adminInfo == null) { | |||
return response.failure("用户信息不存在"); | |||
} | |||
// 校验密码是否正确 | |||
if (!adminInfo.getPassword().equals(FunctionUtils.password(loginDto.getPassword()))) { | |||
return response.failure("登录密码不正确"); | |||
} | |||
// 校验用户状态 | |||
if (adminInfo.getStatus() != 1) { | |||
return response.failure("您已被禁用,请联系管理员"); | |||
} | |||
// 更新登录时间 | |||
adminInfo.setLastTime(DateUtil.now()); | |||
adminMapper.updateById(adminInfo); | |||
// 生成token给前端 | |||
String token = JwtUtil.createJWT(adminInfo.getId()); | |||
// System.out.print("token:" + token); | |||
// Claims data = JwtUtil.parseJWT(token); | |||
// System.out.println(data); | |||
// System.out.println("用户ID:" + data.get("id")); | |||
// | |||
// Boolean isOK = JwtUtil.isVerify(token, 1); | |||
// System.out.print(isOK); | |||
// 获取Subject实例对象,用户实例 | |||
Subject currentUser = SecurityUtils.getSubject(); | |||
// 将用户名和密码封装到UsernamePasswordToken | |||
UsernamePasswordToken token = new FrontUserToken(loginDto.getUsername(), loginDto.getPassword()); | |||
CacheUser cacheUser; | |||
// 4、认证 | |||
try { | |||
// 传到 MyShiroRealm 类中的方法进行认证 | |||
currentUser.login(token); | |||
// 构建缓存用户信息返回给前端 | |||
UserAdmin user = (UserAdmin) currentUser.getPrincipals().getPrimaryPrincipal(); | |||
cacheUser = CacheUser.builder() | |||
.token(currentUser.getSession().getId().toString()) | |||
.build(); | |||
BeanUtils.copyProperties(user, cacheUser); | |||
} catch (UnknownAccountException e) { | |||
log.error("账户不存在异常:", e); | |||
return response.failure("账号不存在!"); | |||
// throw new LoginException("账号不存在!", e); | |||
} catch (IncorrectCredentialsException e) { | |||
log.error("凭据错误(密码错误)异常:", e); | |||
return response.failure("密码不正确!"); | |||
// throw new LoginException("密码不正确!", e); | |||
} catch (AuthenticationException e) { | |||
log.error("身份验证异常:", e); | |||
return response.failure("用户验证失败!"); | |||
// throw new LoginException("用户验证失败!", e); | |||
} | |||
Map<String, String> result = new HashMap<>(); | |||
result.put("token", token); | |||
result.put("token", cacheUser.getToken()); | |||
return response.success("登录成功", result); | |||
} | |||
@@ -0,0 +1,80 @@ | |||
package com.taauav.front.service.impl; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.taauav.admin.entity.SysAdmin; | |||
import com.taauav.common.bean.CacheUser; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.config.FrontUserToken; | |||
import com.taauav.common.service.impl.BaseServiceImpl; | |||
import com.taauav.front.dto.LoginDto; | |||
import com.taauav.front.entity.UserAdmin; | |||
import com.taauav.front.mapper.UserAdminMapper; | |||
import com.taauav.front.service.IUserAdminService; | |||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
import org.apache.shiro.SecurityUtils; | |||
import org.apache.shiro.authc.AuthenticationException; | |||
import org.apache.shiro.authc.IncorrectCredentialsException; | |||
import org.apache.shiro.authc.UnknownAccountException; | |||
import org.apache.shiro.authc.UsernamePasswordToken; | |||
import org.apache.shiro.subject.Subject; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.stereotype.Service; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* <p> | |||
* 外包人员表 服务实现类 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
@Service | |||
public class UserAdminServiceImpl extends BaseServiceImpl<UserAdminMapper, UserAdmin> implements IUserAdminService { | |||
@Autowired | |||
private UserAdminMapper userAdminMapper; | |||
@Value("${server.IMAGE_URL}") | |||
private String imageUrl; | |||
@Autowired | |||
private Response response; | |||
/** | |||
* 根据用户名获取人员信息 | |||
* | |||
* @param username 用户名 | |||
* @return | |||
*/ | |||
@Override | |||
public UserAdmin findByUsername(String username) { | |||
QueryWrapper wrapper = new QueryWrapper(); | |||
wrapper.eq("username", username); | |||
wrapper.eq("mark", 1); | |||
UserAdmin admin = userAdminMapper.selectOne(wrapper); | |||
if (admin != null && !"".equals(admin.getAvatar())) { | |||
admin.setAvatar(imageUrl + admin.getAvatar()); | |||
} | |||
return admin; | |||
} | |||
/** | |||
* 获取人员列表 | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public Response getUserAdminList() { | |||
// 查询条件 | |||
QueryWrapper<UserAdmin> queryWrapper = new QueryWrapper<>(); | |||
queryWrapper.eq("status", 1); | |||
queryWrapper.eq("mark", 1); | |||
List<UserAdmin> userAdminList = userAdminMapper.selectList(queryWrapper); | |||
return response.success(userAdminList); | |||
} | |||
} |
@@ -0,0 +1,206 @@ | |||
package com.taauav.front.service.impl; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.service.impl.BaseServiceImpl; | |||
import com.taauav.common.util.DateUtil; | |||
import com.taauav.common.util.ShiroUtils; | |||
import com.taauav.common.util.StringUtils; | |||
import com.taauav.front.constant.UserNoticeConstant; | |||
import com.taauav.front.entity.UserAdmin; | |||
import com.taauav.front.entity.UserNotice; | |||
import com.taauav.front.mapper.UserAdminMapper; | |||
import com.taauav.front.mapper.UserNoticeMapper; | |||
import com.taauav.front.query.UserNoticeQuery; | |||
import com.taauav.front.service.IUserNoticeService; | |||
import com.taauav.front.vo.usernotice.UserNoticeInfoVo; | |||
import com.taauav.front.vo.usernotice.UserNoticeListVo; | |||
import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.*; | |||
/** | |||
* <p> | |||
* 通知公告表 服务实现类 | |||
* </p> | |||
* | |||
* @author 鲲鹏 | |||
* @since 2020-05-14 | |||
*/ | |||
@Service | |||
public class UserNoticeServiceImpl extends BaseServiceImpl<UserNoticeMapper, UserNotice> implements IUserNoticeService { | |||
@Autowired | |||
private UserNoticeMapper noticeMapper; | |||
@Autowired | |||
private Response response; | |||
@Autowired | |||
private UserAdminMapper userAdminMapper; | |||
/** | |||
* 获取通知公告列表 | |||
* | |||
* @param query 查询条件 | |||
* @return | |||
*/ | |||
@Override | |||
public Response getNoticeList(UserNoticeQuery query) { | |||
// 查询条件 | |||
QueryWrapper<UserNotice> queryWrapper = new QueryWrapper<>(); | |||
// 标题 | |||
if (!StringUtils.isEmpty(query.getTitle())) { | |||
queryWrapper.like("title", query.getTitle()); | |||
} | |||
// 公告类型 | |||
if (query.getType() != null && query.getType() > 0) { | |||
queryWrapper.eq("type", query.getType()); | |||
} | |||
// 发布人 | |||
if (query.getPublishUser() != null && query.getPublishUser() > 0) { | |||
queryWrapper.eq("publish_user", query.getPublishUser()); | |||
} | |||
// 发布开始时间 | |||
if (!StringUtils.isEmpty(query.getStartTime())) { | |||
Date startTime = DateUtil.parse(query.getStartTime(), "yyyy-MM-dd HH:mm:ss"); | |||
queryWrapper.ge("publish_time", startTime); | |||
} | |||
// 发布结束时间 | |||
if (!StringUtils.isEmpty(query.getEndTime())) { | |||
Date endTime = DateUtil.parse(query.getEndTime(), "yyyy-MM-dd HH:mm:ss"); | |||
queryWrapper.le("publish_time", endTime); | |||
} | |||
// 查询数据 | |||
IPage<UserNotice> page = new Page<>(query.getPage(), query.getPageSize()); | |||
IPage<UserNotice> data = noticeMapper.selectPage(page, queryWrapper); | |||
List<UserNotice> noticeList = data.getRecords(); | |||
List<UserNoticeListVo> userNoticeListVoList = new ArrayList<>(); | |||
if (!noticeList.isEmpty()) { | |||
noticeList.forEach(item -> { | |||
UserNoticeListVo userNoticeListVo = new UserNoticeListVo(); | |||
// 拷贝属性 | |||
BeanUtils.copyProperties(item, userNoticeListVo); | |||
// 发布人名称 | |||
UserAdmin userAdmin = userAdminMapper.selectById(item.getPublishUser()); | |||
if (userAdmin != null) { | |||
userNoticeListVo.setPublishUserName(userAdmin.getRealname()); | |||
} | |||
// 通知状态 | |||
userNoticeListVo.setStatusName(UserNoticeConstant.USER_NOTICE_STATUS_LIST.get(item.getStatus())); | |||
// 通知类型 | |||
userNoticeListVo.setTypeName(UserNoticeConstant.USER_NOTICE_TYPE_LIST.get(item.getType())); | |||
userNoticeListVoList.add(userNoticeListVo); | |||
}); | |||
} | |||
// 返回结果 | |||
Map<String, Object> result = new HashMap<>(); | |||
result.put("total", data.getTotal()); | |||
result.put("size", data.getSize()); | |||
result.put("current", data.getCurrent()); | |||
result.put("pages", data.getPages()); | |||
result.put("records", userNoticeListVoList); | |||
return response.success(result); | |||
} | |||
/** | |||
* 添加通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Override | |||
public Response add(UserNotice entity) { | |||
if (entity == null) { | |||
return response.failure("实体对象不能为空"); | |||
} | |||
// 设置发布人和发布时间 | |||
if (entity.getStatus() == 1) { | |||
entity.setPublishUser(ShiroUtils.getAdminId()); | |||
entity.setPublishTime(DateUtil.now()); | |||
} | |||
boolean result = this.addData(entity); | |||
if (!result) { | |||
return response.failure("添加失败"); | |||
} | |||
return response.success("添加成功"); | |||
} | |||
/** | |||
* 编辑通知公告 | |||
* | |||
* @param entity 实体对象 | |||
* @return | |||
*/ | |||
@Override | |||
public Response edit(UserNotice entity) { | |||
if (entity == null) { | |||
return response.failure("实体对象不能为空"); | |||
} | |||
if (entity.getId() == null && entity.getId() < 0) { | |||
return response.failure("记录ID不能为空"); | |||
} | |||
// 设置发布人和发布时间 | |||
if (entity.getStatus() == 1) { | |||
entity.setPublishUser(ShiroUtils.getAdminId()); | |||
entity.setPublishTime(DateUtil.now()); | |||
} | |||
boolean result = this.editData(entity); | |||
if (!result) { | |||
return response.failure("编辑失败"); | |||
} | |||
return response.success("编辑成功"); | |||
} | |||
/** | |||
* 获取通知公告详情 | |||
* | |||
* @param noticeId 通知公告ID | |||
* @return | |||
*/ | |||
@Override | |||
public Response info(Integer noticeId) { | |||
if (noticeId == null || noticeId <= 0) { | |||
return response.failure("公告ID不能为空"); | |||
} | |||
UserNotice info = this.getInfo(noticeId); | |||
// 拷贝属性 | |||
UserNoticeInfoVo userNoticeInfoVo = new UserNoticeInfoVo(); | |||
if (info != null) { | |||
BeanUtils.copyProperties(info, userNoticeInfoVo); | |||
// 发布人 | |||
UserAdmin userAdmin = userAdminMapper.selectById(info.getPublishUser()); | |||
if (userAdmin != null) { | |||
userNoticeInfoVo.setPublishUserName(userAdmin.getRealname()); | |||
} | |||
} | |||
return response.success(userNoticeInfoVo); | |||
} | |||
/** | |||
* 删除通知公告 | |||
* | |||
* @param noticeId 通知公告ID | |||
* @return | |||
*/ | |||
@Override | |||
public Response delete(Integer noticeId) { | |||
if (noticeId == null || noticeId <= 0) { | |||
return response.failure("通知公告ID不能为空"); | |||
} | |||
UserNotice info = this.getInfo(noticeId); | |||
if (info == null) { | |||
return response.failure("通知公告信息不存在"); | |||
} | |||
boolean result = this.deleteById(noticeId, info); | |||
if (!result) { | |||
return response.failure("删除失败"); | |||
} | |||
return response.success("删除成功"); | |||
} | |||
} |
@@ -0,0 +1,140 @@ | |||
package com.taauav.front.utils; | |||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; | |||
import com.baomidou.mybatisplus.core.toolkit.StringPool; | |||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; | |||
import com.baomidou.mybatisplus.generator.AutoGenerator; | |||
import com.baomidou.mybatisplus.generator.InjectionConfig; | |||
import com.baomidou.mybatisplus.generator.config.*; | |||
import com.baomidou.mybatisplus.generator.config.po.TableInfo; | |||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; | |||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Scanner; | |||
/** | |||
* 代码生成类 | |||
* | |||
* @author 牧羊人 | |||
* @date 2019/11/28 | |||
*/ | |||
public class CodeGenerator { | |||
/** | |||
* <p> | |||
* 读取控制台内容 | |||
* </p> | |||
*/ | |||
public static String scanner(String tip) { | |||
Scanner scanner = new Scanner(System.in); | |||
StringBuilder help = new StringBuilder(); | |||
help.append("请输入" + tip + ":"); | |||
System.out.println(help.toString()); | |||
if (scanner.hasNext()) { | |||
String ipt = scanner.next(); | |||
if (StringUtils.isNotEmpty(ipt)) { | |||
return ipt; | |||
} | |||
} | |||
throw new MybatisPlusException("请输入正确的" + tip + "!"); | |||
} | |||
public static void main(String[] args) { | |||
// 代码生成器 | |||
AutoGenerator mpg = new AutoGenerator(); | |||
// 全局配置 | |||
GlobalConfig gc = new GlobalConfig(); | |||
String projectPath = System.getProperty("user.dir"); | |||
gc.setOutputDir(projectPath + "/src/main/java"); | |||
gc.setAuthor("鲲鹏"); | |||
gc.setOpen(false); | |||
// gc.setSwagger2(true); 实体属性 Swagger2 注解 | |||
mpg.setGlobalConfig(gc); | |||
// 数据源配置 | |||
DataSourceConfig dsc = new DataSourceConfig(); | |||
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/taauav_nanjing?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC"); | |||
// dsc.setSchemaName("public"); | |||
dsc.setDriverName("com.mysql.cj.jdbc.Driver"); | |||
dsc.setUsername("root"); | |||
dsc.setPassword(""); | |||
mpg.setDataSource(dsc); | |||
// 包配置 | |||
PackageConfig pc = new PackageConfig(); | |||
// pc.setModuleName(scanner("模块名")); | |||
// pc.setModuleName("university"); | |||
// pc.setParent("com.think"); | |||
pc.setParent("com.taauav.front"); | |||
mpg.setPackageInfo(pc); | |||
// 自定义配置 | |||
InjectionConfig cfg = new InjectionConfig() { | |||
@Override | |||
public void initMap() { | |||
// to do nothing | |||
} | |||
}; | |||
// 如果模板引擎是 freemarker | |||
String templatePath = "/templates/mapper.xml.ftl"; | |||
// 如果模板引擎是 velocity | |||
// String templatePath = "/templates/mapper.xml.vm"; | |||
// 自定义输出配置 | |||
List<FileOutConfig> focList = new ArrayList<>(); | |||
// 自定义配置会被优先输出 | |||
focList.add(new FileOutConfig(templatePath) { | |||
@Override | |||
public String outputFile(TableInfo tableInfo) { | |||
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! | |||
return projectPath + "/src/main/java/com/taauav/front/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; | |||
} | |||
}); | |||
/* | |||
cfg.setFileCreate(new IFileCreate() { | |||
@Override | |||
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) { | |||
// 判断自定义文件夹是否需要创建 | |||
checkDir("调用默认方法创建的目录"); | |||
return false; | |||
} | |||
}); | |||
*/ | |||
cfg.setFileOutConfigList(focList); | |||
mpg.setCfg(cfg); | |||
// 配置模板 | |||
TemplateConfig templateConfig = new TemplateConfig(); | |||
// 配置自定义输出模板 | |||
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别 | |||
// templateConfig.setEntity("templates/entity2.java"); | |||
// templateConfig.setService(); | |||
// templateConfig.setController(); | |||
templateConfig.setXml(null); | |||
mpg.setTemplate(templateConfig); | |||
// 策略配置 | |||
StrategyConfig strategy = new StrategyConfig(); | |||
strategy.setNaming(NamingStrategy.underline_to_camel); | |||
strategy.setColumnNaming(NamingStrategy.underline_to_camel); | |||
strategy.setSuperEntityClass("com.taauav.common.domain.Entity"); | |||
strategy.setEntityLombokModel(true); | |||
strategy.setRestControllerStyle(true); | |||
// 公共父类 | |||
strategy.setSuperControllerClass("com.taauav.front.controller.FrontBaseController"); | |||
// 写于父类中的公共字段 | |||
strategy.setSuperEntityColumns("id"); | |||
strategy.setInclude(scanner("表名,多个英文逗号分割").split(",")); | |||
strategy.setControllerMappingHyphenStyle(true); | |||
// strategy.setTablePrefix(pc.getModuleName() + "_"); | |||
// strategy.setTablePrefix("user_"); | |||
mpg.setStrategy(strategy); | |||
mpg.setTemplateEngine(new FreemarkerTemplateEngine()); | |||
mpg.execute(); | |||
} | |||
} |
@@ -0,0 +1,74 @@ | |||
package com.taauav.front.vo.usernotice; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.util.Date; | |||
@Data | |||
public class UserNoticeInfoVo { | |||
/** | |||
* 公告ID | |||
*/ | |||
private Integer id; | |||
/** | |||
* 公告标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 公告类型:1水务新闻 2政策法规 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 公告类型描述 | |||
*/ | |||
private String typeName; | |||
/** | |||
* 公告内容 | |||
*/ | |||
private String content; | |||
/** | |||
* 附件 | |||
*/ | |||
private String attachment; | |||
/** | |||
* 阅读量 | |||
*/ | |||
private Integer viewNum; | |||
/** | |||
* 发布状态:1已发布 2未发布 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 状态描述 | |||
*/ | |||
private String statusName; | |||
/** | |||
* 发布人 | |||
*/ | |||
private Integer publishUser; | |||
/** | |||
* 发布人名称 | |||
*/ | |||
private String publishUserName; | |||
/** | |||
* 发布时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
private Date publishTime; | |||
} |
@@ -0,0 +1,74 @@ | |||
package com.taauav.front.vo.usernotice; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.util.Date; | |||
@Data | |||
public class UserNoticeListVo { | |||
/** | |||
* 公告ID | |||
*/ | |||
private Integer id; | |||
/** | |||
* 公告标题 | |||
*/ | |||
private String title; | |||
/** | |||
* 公告类型:1水务新闻 2政策法规 | |||
*/ | |||
private Integer type; | |||
/** | |||
* 公告类型描述 | |||
*/ | |||
private String typeName; | |||
/** | |||
* 公告内容 | |||
*/ | |||
private String content; | |||
/** | |||
* 附件 | |||
*/ | |||
private String attachment; | |||
/** | |||
* 阅读量 | |||
*/ | |||
private Integer viewNum; | |||
/** | |||
* 发布状态:1已发布 2未发布 | |||
*/ | |||
private Integer status; | |||
/** | |||
* 状态描述 | |||
*/ | |||
private String statusName; | |||
/** | |||
* 发布人 | |||
*/ | |||
private Integer publishUser; | |||
/** | |||
* 发布人名称 | |||
*/ | |||
private String publishUserName; | |||
/** | |||
* 发布时间 | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
private Date publishTime; | |||
} |