gov 加入springsecurity

企业端,岗位总体信息接口
This commit is contained in:
79493 2022-10-10 15:57:14 +08:00
parent 44aa7338fa
commit a109fec720
26 changed files with 710 additions and 102 deletions

View File

@ -23,8 +23,10 @@ public interface EntPostDutyMapper extends BaseMapper<EntPostDuty> {
* 企业用户岗位职责
* @param enterpriseId 企业id
* @param postId 岗位id
* @param page 页码
* @param pageSize 条数
* @return EntPostTask 企业用户岗位职责
* */
List<EntPostDuty>selectEntUserPostDuty(@Param("enterpriseId") String enterpriseId, @Param("postId")String postId);
List<EntPostDuty>selectEntUserPostDuty(@Param("enterpriseId") String enterpriseId, @Param("postId")String postId,@Param("page") Integer page,@Param("pageSize")Integer pageSize);
}

View File

@ -23,8 +23,10 @@ public interface EntPostListMapper extends BaseMapper<EntPostList> {
* @param enterpriseId 企业id
* @param entUserId 企业用户id
* @param postId 岗位id
* @param page 页码
* @param pageSize 条数
* @return EntPostList 企业用户工作要务
* */
List<EntPostList>selectEntPostList(@Param("enterpriseId") String enterpriseId,@Param("entUserId") String entUserId,@Param("postId")String postId);
List<EntPostList>selectEntPostList(@Param("enterpriseId") String enterpriseId,@Param("entUserId") String entUserId,@Param("postId")String postId,Integer page,Integer pageSize);
}

View File

@ -27,10 +27,13 @@ public interface EntPostTaskMapper extends BaseMapper<EntPostTask> {
* @param listId 清单id
* @param content 内容模糊搜索
* @param taskState 任务状态
* @param page 页码
* @param pageSize 条数
* @return EntPostTask 企业用户清单任务
* */
List<EntPostTask>selectEntUserPostTask(@Param("enterpriseId") String enterpriseId, @Param("entUserId")String entUserId,
@Param("postId")String postId, @Param("listId")String listId,
@Param("content")String content,@Param("taskState") Integer taskState);
@Param("content")String content,@Param("taskState") Integer taskState,
@Param("page") Integer page,@Param("pageSize") Integer pageSize);
}

View File

@ -24,25 +24,27 @@ public interface EntUserCredentialMapper extends BaseMapper<EntUserCredential> {
* 企业用户岗位职责
* @param enterpriseId 企业id
* @param entUserId 企业用户id
* @param page 页码
* @param pageSize 条数
* @return EntUserCredential 企业用户证照
* */
List<EntUserCredential>selectEntUserCredential(@Param("enterpriseId") String enterpriseId, @Param("entUserId")String entUserId);
List<EntUserCredential>selectEntUserCredential(@Param("enterpriseId") String enterpriseId, @Param("entUserId")String entUserId,@Param("page") Integer page,@Param("pageSize")Integer pageSize);
/**
* 企业用户证件照修改
* @param entUserCredentialUpdateDto 企业用户证件照对象
* @param entUserCredential 企业用户证件照对象
* @return int
* */
int updateEntUserCredential(@Param("data") EntUserCredentialUpdateDto entUserCredentialUpdateDto);
int updateEntUserCredential(@Param("data") EntUserCredential entUserCredential);
/**
* 企业用户证件照新增
* @param entUserCredentialUpdateDto 企业用户证件照对象
* @param entUserCredential 企业用户证件照对象
* @return int
* */
int insertEntUserCredential(@Param("data") EntUserCredentialUpdateDto entUserCredentialUpdateDto);
int insertEntUserCredential(@Param("data") EntUserCredential entUserCredential);
/**

View File

@ -1,6 +1,5 @@
package com.rzyc.mapper.ent;
import com.rzyc.model.ent.EntPost;
import com.rzyc.model.ent.EntUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
@ -27,6 +26,14 @@ public interface EntUserMapper extends BaseMapper<EntUser> {
EntUser selectByName(@Param("name") String name);
/**
* 查询企业用户表
* @param keyContent 关键字
* @param page 页码
* @param pageSize 条数
* @return EntUser 企业用户实体
* */
List<EntUser>selectEntUserList(@Param("keyContent") String keyContent,@Param("page")Integer page,@Param("pageSize")Integer pageSize);
}

View File

@ -41,17 +41,6 @@ public class EntUserCredentialUpdateDto {
private Date credentialEndTime;
private Date createTime;
private Date modifyTime;
private String createBy;
private String modifyBy;
public Date getCredentialStartTime() {
return credentialStartTime;
}
@ -96,34 +85,6 @@ public class EntUserCredentialUpdateDto {
public void setCredentialImageAddress(String credentialImageAddress) {
this.credentialImageAddress = credentialImageAddress;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public String getModifyBy() {
return modifyBy;
}
public void setModifyBy(String modifyBy) {
this.modifyBy = modifyBy;
}
public String getEntUserId() {
return entUserId;

View File

@ -82,8 +82,79 @@ public class EntUser implements Serializable {
@TableField("modify_by")
private String modifyBy;
@ApiModelProperty(value = "证件未超时数")
@TableField(exist = false)
private Integer noTimeout;
@ApiModelProperty(value = "证件超时数")
@TableField(exist = false)
private Integer overtime;
@ApiModelProperty(value = "进行中履职任务数")
@TableField(exist = false)
private Integer ongoingTask;
@ApiModelProperty(value = "完成的履职任务数")
@TableField(exist = false)
private Integer finishTask;
@ApiModelProperty(value = "超时的履职任务数")
@TableField(exist = false)
private Integer overTimeTask;
@ApiModelProperty(value = "履职百分比数")
@TableField(exist = false)
private double entUserTaskPercent;
public double getEntUserTaskPercent() {
return entUserTaskPercent;
}
public void setEntUserTaskPercent(double entUserTaskPercent) {
this.entUserTaskPercent = entUserTaskPercent;
}
public Integer getNoTimeout() {
return noTimeout;
}
public void setNoTimeout(Integer noTimeout) {
this.noTimeout = noTimeout;
}
public Integer getOvertime() {
return overtime;
}
public void setOvertime(Integer overtime) {
this.overtime = overtime;
}
public Integer getOngoingTask() {
return ongoingTask;
}
public void setOngoingTask(Integer ongoingTask) {
this.ongoingTask = ongoingTask;
}
public Integer getFinishTask() {
return finishTask;
}
public void setFinishTask(Integer finishTask) {
this.finishTask = finishTask;
}
public Integer getOverTimeTask() {
return overTimeTask;
}
public void setOverTimeTask(Integer overTimeTask) {
this.overTimeTask = overTimeTask;
}
public String getEntUserId() {
return entUserId;
}

View File

@ -21,7 +21,7 @@
</sql>
<select id="selectEntUserPostDuty" resultMap="BaseResultMap">
select * from ent_post_duty where enterprise_id = #{enterpriseId} and post_id = #{postId}
select * from ent_post_duty where enterprise_id = #{enterpriseId} and post_id = #{postId} limit #{page},#{pageSize}
</select>
</mapper>

View File

@ -22,19 +22,19 @@
credential_id, credential_name, credential_state, credential_image_address, create_time, modify_time, create_by, modify_by
</sql>
<select id="selectEntUserCredential">
select * from ent_user_credential where ent_user_id = #{entUserId}
<select id="selectEntUserCredential" resultMap="BaseResultMap">
select * from ent_user_credential where ent_user_id = #{entUserId} limit #{page},#{pageSize}
</select>
<update id="updateEntUserCredential" parameterType="com.rzyc.model.dto.EntUserCredentialUpdateDto">
<update id="updateEntUserCredential" parameterType="com.rzyc.model.EntUserCredential">
update ent_user_credential set credential_name= #{data.credentialName} ,credential_start_time = #{data.credentialStartTime},
credential_end_time = #{data.credentialEndTime},credential_image_address = #{data.credentialImageAddress},
modify_timne = #{data.modifyTime} , modify_by = #{data.modifyBy}
modify_time = #{data.modifyTime} , modify_by = #{data.modifyBy}
where ent_user_id = #{data.entUserId}
</update>
<insert id="insertEntUserCredential" parameterType="com.rzyc.model.dto.EntUserCredentialUpdateDto">
insert into ent_user_credential (credential_name,credential_start_time,credential_end_time,credential_image_address,ent_user_id,create_by,create_time) values(#{data.credentialName},#{data.credentialStartTime},#{data.credentialEndTime},#{data.credentialImageAddress},#{data.entUserId},#{data.createBy},#{data.createTime})
<insert id="insertEntUserCredential" parameterType="com.rzyc.model.EntUserCredential">
insert into ent_user_credential (credential_id,credential_name,credential_start_time,credential_end_time,credential_image_address,ent_user_id,create_by,create_time) values(#{data.credentialId},#{data.credentialName},#{data.credentialStartTime},#{data.credentialEndTime},#{data.credentialImageAddress},#{data.entUserId},#{data.createBy},#{data.createTime})
</insert>
<delete id="entUserCredentialDelete">

View File

@ -29,7 +29,46 @@
<select id="selectByName" resultMap="BaseResultMap">
select * from ent_user where name = #{name}
</select>
<resultMap id="entUserListStatistic" type="com.rzyc.model.ent.EntUser">
<id column="ent_user_id" property="entUserId" />
<result column="post_id" property="postId" />
<result column="enterprise_id" property="enterpriseId" />
<result column="name" property="name" />
<result column="mobile" property="mobile" />
<result column="user_type" property="userType" />
<result column="age" property="age" />
<result column="work_time" property="workTime" />
<result column="passwd" property="passwd" />
<result column="post_path" property="postPath" />
<result column="post_path_name" property="postPathName" />
<result column="create_time" property="createTime" />
<result column="create_by" property="createBy" />
<result column="modify_time" property="modifyTime" />
<result column="modify_by" property="modifyBy" />
<result column="noTimeout" property="noTimeout"/>
<result column="overtime" property="overtime"/>
<result column="ongoingTask" property="ongoingTask"/>
<result column="finishTask" property="finishTask"/>
<result column="overTimeTask" property="overTimeTask"/>
</resultMap>
<select id="selectEntUserList" resultMap="entUserListStatistic">
select eu.*,ep.name postName,sum(case when credential_state = 1 then 1 else 0 end)as noTimeout,sum(case when credential_state = 2 then 1 else 0 end)as overtime ,
sum(case when task_state = 1 then 1 else 0 end) as ongoingTask,sum(case when task_state = 2 then 1 else 0 end) as finishTask,sum(case when task_state = 3 then 1 else 0 end) as overTimeTask
from ent_user eu
left join ent_post ep on eu.post_id = ep.post_id
left join ent_user_credential euc on eu.ent_user_id = euc.ent_user_id
left join ent_post_task ept on eu.ent_user_id = ept.ent_user_id
<if test="null != keyContent and '' != keyContent">
where eu.name like concat('%',#{keyContent},'%')
or eu.job_number like concat('%',#{keyContent},'%')
or ep.name like concat('%',#{keyContent},'%')
</if>
limit #{page},#{pageSize}
</select>
</mapper>

View File

@ -2,7 +2,6 @@ package com.rzyc.config;
import com.common.utils.DateUtils;
import com.common.utils.RandomNumber;
import com.rzyc.config.MethodAnnotation;
import com.rzyc.controller.PersonalController;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
@ -17,7 +16,7 @@ import java.sql.*;
* @date 2022/10/8
*/
public class MethodSignature {
public class EntMethodSignature {
public static void main(String[] args) {
@ -48,13 +47,10 @@ public class MethodSignature {
//创建connection
Connection con = buildingSource().getConnection();
Statement statement = con.createStatement();
PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO `authority_key`(id,parent_resource,auth_key,category,create_time,modify_time) VALUES (?,?,?,?,?,?);");
PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO `authority_key`(id,parent_resource,auth_key,category,create_time,modify_time,`name`) VALUES (?,?,?,?,?,?,?);");
con.setAutoCommit(false);
long startTime = System.currentTimeMillis();
if (methods.length>0){
statement.execute("truncate table authority_key");
}
//遍历所有方法
for (Method m : methods) {
//判断方法是否有MethodAnnotation注解
@ -65,12 +61,11 @@ public class MethodSignature {
for (String name : annotation.authorizations()) {
String str = name.substring(name.indexOf(":")+1,name.length());
/* ResultSet rs = statement.executeQuery("select auth_key from authority_key where auth_key ='"+str+"'");
ResultSet rs = statement.executeQuery("select auth_key from authority_key where auth_key ='"+str+"'");
//取数据
if (rs.next()) {
} else {}*/
} else {
String category = name.substring(0,name.indexOf(":"));
preparedStatement.setString(1, RandomNumber.getUUid());
preparedStatement.setString(2,null);
@ -78,8 +73,9 @@ public class MethodSignature {
preparedStatement.setString(4,category);
preparedStatement.setString(5, DateUtils.getNowDateTimeStr());
preparedStatement.setString(6,DateUtils.getNowDateTimeStr());
preparedStatement.setString(7,annotation.name());
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
}

View File

@ -19,5 +19,7 @@ public @interface MethodAnnotation {
String authorization()default "no authorization";
String name()default "no name";
}

View File

@ -7,6 +7,7 @@ import com.common.utils.StringUtils;
import com.common.utils.encryption.PasswdFactory;
import com.common.utils.jwt.JwtUtil;
import com.common.utils.model.SingleResult;
import com.rzyc.advice.PageOperation;
import com.rzyc.bean.user.dto.LoginDto;
import com.rzyc.model.EntUserCredential;
import com.rzyc.model.dto.EntUserCredentialUpdateDto;
@ -159,7 +160,7 @@ public class PersonalController extends BaseController{
})
@GetMapping(value = "/entUserTree")
@PreAuthorize("hasAnyAuthority('PERSONAL:ENTUSERTREE','PERSONAL:ENTUSERTREE:UPDATE')")
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERTREE","PERSONAL:ENTUSERTREE:UPDATE"})
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERTREE","PERSONAL:ENTUSERTREE:UPDATE"},name = "企业用户组织树")
@ResponseBody
public SingleResult<List<EntUser>> entUserTree(String enterpriseId, String postId)throws Exception{
return pcBusinessService.entUserTree(enterpriseId,postId);
@ -182,10 +183,10 @@ public class PersonalController extends BaseController{
})
@GetMapping(value = "/entUserPostList")
@PreAuthorize("hasAnyAuthority('PERSONAL:ENTUSERPOSTLIST','PERSONAL:ENTUSERPOSTLIST:UPDATE')")
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERPOSTLIST","PERSONAL:ENTUSERPOSTLIST:UPDATE"})
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERPOSTLIST","PERSONAL:ENTUSERPOSTLIST:UPDATE"},name = "企业用户工作要务")
@ResponseBody
public SingleResult entUserPostList(String enterpriseId, String entUserId,String postId)throws Exception{
return pcBusinessService.entUserPostList(enterpriseId,entUserId,postId);
public SingleResult entUserPostList(String enterpriseId, String entUserId,String postId,Integer page,Integer pageSize)throws Exception{
return pcBusinessService.entUserPostList(enterpriseId,entUserId,postId,page,pageSize);
}
@ -210,10 +211,10 @@ public class PersonalController extends BaseController{
@GetMapping(value = "/entUserPostTask")
@PreAuthorize("hasAnyAuthority('PERSONAL:ENTUSERPOSTTASK','PERSONAL:ENTUSERPOSTTASK:UPDATE')")
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERPOSTTASK","PERSONAL:ENTUSERPOSTTASK:UPDATE"})
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERPOSTTASK","PERSONAL:ENTUSERPOSTTASK:UPDATE"},name = "企业用户工作清单")
@ResponseBody
public SingleResult entUserPostTask(String enterpriseId, String entUserId,String postId,String listId,String content,Integer taskState)throws Exception{
return pcBusinessService.entUserPostTask(enterpriseId,entUserId,postId,listId,content,taskState);
public SingleResult entUserPostTask(String enterpriseId, String entUserId,String postId,String listId,String content,Integer taskState,Integer page,Integer pageSize)throws Exception{
return pcBusinessService.entUserPostTask(enterpriseId,entUserId,postId,listId,content,taskState,page,pageSize);
}
@ -232,10 +233,10 @@ public class PersonalController extends BaseController{
@GetMapping(value = "/entUserPostDuty")
@PreAuthorize("hasAnyAuthority('PERSONAL:POSTDUTY','PERSONAL:POSTDUTY:UPDATE')")
@MethodAnnotation(authorizations = {"PERSONAL:POSTDUTY","PERSONAL:POSTDUTY:UPDATE"})
@MethodAnnotation(authorizations = {"PERSONAL:POSTDUTY","PERSONAL:POSTDUTY:UPDATE"},name = "企业用户岗位职责")
@ResponseBody
public SingleResult entUserPostDuty(String enterpriseId, String postId)throws Exception{
return pcBusinessService.entUserPostDuty(enterpriseId,postId);
public SingleResult entUserPostDuty(String enterpriseId, String postId,Integer page,Integer pageSize)throws Exception{
return pcBusinessService.entUserPostDuty(enterpriseId,postId,page,pageSize);
}
/**
@ -250,10 +251,10 @@ public class PersonalController extends BaseController{
})
@GetMapping(value = "/entUserCredential")
@PreAuthorize("hasAnyAuthority('PERSONAL:ENTUSERCREDENTIAL','PERSONAL:ENTUSERCREDENTIAL:UPDATE')")
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERCREDENTIAL","PERSONAL:ENTUSERCREDENTIAL:UPDATE"})
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERCREDENTIAL","PERSONAL:ENTUSERCREDENTIAL:UPDATE"},name = "企业用户证照表")
@ResponseBody
public SingleResult entUserCredential(String entUserId)throws Exception{
return pcBusinessService.entUserCredential(null,entUserId);
public SingleResult entUserCredential(String entUserId,Integer page,Integer pageSize)throws Exception{
return pcBusinessService.entUserCredential(null,entUserId,page,pageSize);
}
/**
@ -268,7 +269,7 @@ public class PersonalController extends BaseController{
})
@PostMapping(value = "/entUserCredentialUpdate")
@PreAuthorize("hasAnyAuthority('PERSONAL:ENTUSERCREDENTIAL:UPDATE')")
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERCREDENTIAL:UPDATE"})
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERCREDENTIAL:UPDATE"},name = "企业用户证照表-新增,修改")
@ResponseBody
public SingleResult entUserCredentialUpdate(@RequestBody EntUserCredentialUpdateDto entUserCredentialUpdateDto)throws Exception{
return pcBusinessService.entUserCredentialUpdate(entUserCredentialUpdateDto);
@ -283,11 +284,11 @@ public class PersonalController extends BaseController{
*/
@ApiOperation(value = "企业用户证照表-删除", notes = "企业用户证照表-删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "entUserId", value = "企业用户id",required = true, dataType = "string"),
@ApiImplicitParam(name = "credentialId", value = "证件照id",required = true, dataType = "string"),
})
@PostMapping(value = "/entUserCredentialDelete")
@PreAuthorize("hasAnyAuthority('PERSONAL:ENTUSERCREDENTIAL:DELETE')")
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERCREDENTIAL:DELETE"})
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERCREDENTIAL:DELETE"},name = "企业用户证照表-删除")
@ResponseBody
public SingleResult entUserCredentialDelete(String credentialId)throws Exception{
return pcBusinessService.entUserCredentialDelete(credentialId);
@ -295,11 +296,22 @@ public class PersonalController extends BaseController{
/**
* 企业岗位总体信息
* 企业岗位总体信息列表
* @param keyContent
* @return list
* @throws Exception
*/
@ApiOperation(value = "企业岗位总体信息列表", notes = "企业岗位总体信息列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "keyContent", value = "搜索关键字",required = false, dataType = "string"),
})
@GetMapping(value = "/entUserList")
@PreAuthorize("hasAnyAuthority('PERSONAL:ENTUSERLIST','PERSONAL:ENTUSERLIST:UPDATE')")
@MethodAnnotation(authorizations = {"PERSONAL:ENTUSERLIST","PERSONAL:ENTUSERLIST:UPDATE"},name ="企业岗位总体信息列表")
@ResponseBody
public SingleResult entUserList(String keyContent,Integer page,Integer pageSize)throws Exception{
return pcBusinessService.entUserList(keyContent,page,pageSize);
}

View File

@ -60,6 +60,7 @@ public class JwtAuthenticationTokenFiler extends OncePerRequestFilter {
for (AuthorityKey s:authorizations) {
stringBuilder.append(s.getCategory() +":"+s.getAuthKey());
authority.add(new SimpleGrantedAuthority(stringBuilder.toString()));
stringBuilder.setLength(0);
}
// 获取权限信息封装到Authentication中

View File

@ -3,9 +3,7 @@ package com.rzyc.service;
import cn.jiguang.common.TimeUnit;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.common.utils.DateUtils;
import com.common.utils.StringUtils;
import com.common.utils.TypeConversion;
import com.common.utils.*;
import com.common.utils.model.Code;
import com.common.utils.model.Message;
import com.common.utils.model.SingleResult;
@ -21,6 +19,7 @@ import com.rzyc.model.ent.EntPost;
import com.rzyc.model.ent.EntUser;
import com.rzyc.model.ent.SysEnterprise;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.*;
@ -80,48 +79,56 @@ public class PcBusinessService extends BaseController {
}
public SingleResult entUserPostList(String enterpriseId,String entUserId,String postId){
public SingleResult entUserPostList(String enterpriseId,String entUserId,String postId,Integer page,Integer pageSize){
SingleResult singleResult = new SingleResult();
List<EntPostList>list = entPostListMapper.selectEntPostList(enterpriseId,entUserId,postId);
page = pageSize * (page - 1);
List<EntPostList>list = entPostListMapper.selectEntPostList(enterpriseId,entUserId,postId,page,pageSize);
singleResult.setData(list);
return singleResult;
}
public SingleResult entUserPostTask(String enterpriseId, String entUserId,String postId,String listId,String content,Integer taskState){
public SingleResult entUserPostTask(String enterpriseId, String entUserId,String postId,String listId,String content,Integer taskState,Integer page,Integer pageSize){
SingleResult singleResult = new SingleResult();
page = pageSize * (page - 1);
//EntPostTask
List<EntPostTask>list = entPostTaskMapper.selectEntUserPostTask(enterpriseId,entUserId,postId,listId,content,taskState);
List<EntPostTask>list = entPostTaskMapper.selectEntUserPostTask(enterpriseId,entUserId,postId,listId,content,taskState,page,pageSize);
singleResult.setData(list);
return singleResult;
}
public SingleResult entUserPostDuty(String enterpriseId, String postId){
public SingleResult entUserPostDuty(String enterpriseId, String postId,Integer page,Integer pageSize){
SingleResult singleResult = new SingleResult();
page = pageSize * (page - 1);
//EntPostDuty
List<EntPostDuty>list = entPostDutyMapper.selectEntUserPostDuty(enterpriseId,postId);
List<EntPostDuty>list = entPostDutyMapper.selectEntUserPostDuty(enterpriseId,postId,page,pageSize);
singleResult.setData(list);
return singleResult;
}
public SingleResult entUserCredential(String enterpriseId, String entUserId){
public SingleResult entUserCredential(String enterpriseId, String entUserId,Integer page,Integer pageSize){
SingleResult singleResult = new SingleResult();
List<EntUserCredential>list = entUserCredentialMapper.selectEntUserCredential(enterpriseId,entUserId);
page = pageSize * (page - 1);
List<EntUserCredential>list = entUserCredentialMapper.selectEntUserCredential(enterpriseId,entUserId,page,pageSize);
singleResult.setData(list);
return singleResult;
}
public SingleResult entUserCredentialUpdate(EntUserCredentialUpdateDto entUserCredentialUpdateDto) throws Exception {
SingleResult singleResult = new SingleResult();
EntUserCredential entUserCredential = new EntUserCredential();
BeanUtils.copyProperties(entUserCredentialUpdateDto,entUserCredential);
Integer result = 0;
if (StringUtils.isNotBlank(entUserCredentialUpdateDto.getCredentialId())) {
entUserCredentialUpdateDto.setModifyBy(getUserId());
entUserCredentialUpdateDto.setModifyTime(new Date());
result = entUserCredentialMapper.updateEntUserCredential(entUserCredentialUpdateDto);
if (StringUtils.isNotBlank(entUserCredential.getCredentialId())) {
entUserCredential.setModifyBy(getUserId());
entUserCredential.setModifyTime(new Date());
result = entUserCredentialMapper.updateEntUserCredential(entUserCredential);
}else {
entUserCredentialUpdateDto.setCreateBy(getUserId());
entUserCredentialUpdateDto.setCreateTime(new Date());
result = entUserCredentialMapper.insertEntUserCredential(entUserCredentialUpdateDto);
entUserCredential.setCredentialId(RandomNumber.getUUid());
entUserCredential.setCreateBy(getUserId());
entUserCredential.setCreateTime(new Date());
result = entUserCredentialMapper.insertEntUserCredential(entUserCredential);
}
if (result==1){
singleResult.setCode(Code.SUCCESS.getCode());
@ -141,6 +148,21 @@ public class PcBusinessService extends BaseController {
}
public SingleResult entUserList(String keyContent,Integer page,Integer pageSize){
SingleResult singleResult = new SingleResult();
page = pageSize * (page - 1);
List<EntUser>users = entUserMapper.selectEntUserList(keyContent,page,pageSize);
//计算履职百分比,后期这里使用redis来读取履职进度
for (EntUser e:users) {
Integer total = e.getFinishTask() + e.getOngoingTask() + e.getOverTimeTask();
double percent = Arith.div(total,e.getFinishTask()) * 100;
e.setEntUserTaskPercent(percent);
}
singleResult.setData(users);
return singleResult;
}
}

View File

@ -1,5 +1,6 @@
package com.rzyc.config;
package com.rzyc.service;
import com.rzyc.config.EntUserDetails;
import com.rzyc.mapper.AuthorityKeyMapper;
import com.rzyc.mapper.ent.EntUserMapper;
import com.rzyc.model.AuthorityKey;

View File

@ -209,6 +209,12 @@
<artifactId>spring-security-web</artifactId>
<version>5.7.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<!-- spring security end -->
</dependencies>

View File

@ -7,6 +7,7 @@ import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ -162,4 +163,19 @@ public class ExceptionAdvice {
result.setMessage(e.getMessage());
return result;
}
/**
* @author Xuwanxin
* 权限不足总捕获异常
* */
@ResponseBody
@ExceptionHandler(value = AccessDeniedException.class)
public SingleResult<String> handleAccessRE(AccessDeniedException e) {
e.printStackTrace();
logger.info("权限不足");
SingleResult<String> result = new SingleResult<>();
result.setCode(Code.AUTHORIZATION_FAILED.getCode());
result.setMessage(Message.AUTHORIZATION_FAILED);
return result;
}
}

View File

@ -0,0 +1,33 @@
package com.rzyc.config;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import java.util.Collection;
/**
* spring security UserDetails Custom Part
* @author Xuwanxin
* @date 2022/9/28
* */
public class EntUserDetails extends User {
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public EntUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities, String id) {
super(username, password, authorities);
setId(id);
}
}

View File

@ -0,0 +1,95 @@
package com.rzyc.config;
import com.common.utils.DateUtils;
import com.common.utils.RandomNumber;
import com.rzyc.controller.EmergencyController;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.lang.reflect.Method;
import java.sql.*;
/**
* 工具
* 获取方法中的注解参数插入数据库
* @author Xuwanxin
* @date 2022/10/8
*/
public class GovMethodSignature {
public static void main(String[] args) {
//反射controller获取所有方法
Method[] methods = EmergencyController.class.getMethods();
insertAnnotation(methods);
}
private static HikariDataSource buildingSource() {
//配置文件
HikariConfig hikariConfig = new HikariConfig();
//mysql
hikariConfig.setJdbcUrl("jdbc:mysql://121.40.106.103:3306/inventory_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&useSSL=false");
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
hikariConfig.setUsername("rzyc");
hikariConfig.setPassword("admin@rzyc2022.com##");
hikariConfig.addDataSourceProperty("minimumIdle", "3");
hikariConfig.addDataSourceProperty("maximumPoolSize", "10");
hikariConfig.addDataSourceProperty("maxLifetime", "30000");
HikariDataSource ds = new HikariDataSource(hikariConfig);
return ds;
}
private static void insertAnnotation(Method[] methods) {
try {
//创建connection
Connection con = buildingSource().getConnection();
Statement statement = con.createStatement();
PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO `authority_key`(id,parent_resource,auth_key,category,create_time,modify_time,`name`) VALUES (?,?,?,?,?,?,?);");
con.setAutoCommit(false);
long startTime = System.currentTimeMillis();
//遍历所有方法
for (Method m : methods) {
//判断方法是否有MethodAnnotation注解
if (m.isAnnotationPresent(MethodAnnotation.class)) {
MethodAnnotation annotation = m.getAnnotation(MethodAnnotation.class);
for (String name : annotation.authorizations()) {
String str = name.substring(name.indexOf(":")+1,name.length());
ResultSet rs = statement.executeQuery("select auth_key from authority_key where auth_key ='"+str+"'");
//取数据
if (rs.next()) {
} else {
String category = name.substring(0,name.indexOf(":"));
preparedStatement.setString(1, RandomNumber.getUUid());
preparedStatement.setString(2,null);
preparedStatement.setString(3,str);
preparedStatement.setString(4,category);
preparedStatement.setString(5, DateUtils.getNowDateTimeStr());
preparedStatement.setString(6,DateUtils.getNowDateTimeStr());
preparedStatement.setString(7,annotation.name());
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
}
}
long endTime = System.currentTimeMillis();
con.commit();
System.out.println("用时:" + (endTime-startTime));
//关闭connection
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,25 @@
package com.rzyc.config;
import java.lang.annotation.*;
/**
* 注解参数插入数据库
* @author Xuwanxin
* @date 2022/10/8
* */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target(ElementType.METHOD)//注解作用于方法
public @interface MethodAnnotation {
String[] authorizations()default {"no authorization"};
String authorization()default "no authorization";
String name()default "no name";
}

View File

@ -0,0 +1,92 @@
package com.rzyc.config;
import com.rzyc.filter.JwtAuthenticationTokenFiler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
/**
* spring security config
* @author Xuwanxin
* @date 2022/9/26
* */
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
/**
* 数据库用户连接
*/
private UserDetailsService userService;
/**
* token jwt 验证拦截器
* */
private JwtAuthenticationTokenFiler jwtAuthenticationTokenFiler;
@Autowired
public void setSecurityConfigFinder(UserDetailsService userService,JwtAuthenticationTokenFiler jwtAuthenticationTokenFiler) {
this.userService = userService;
this.jwtAuthenticationTokenFiler = jwtAuthenticationTokenFiler;
}
@Bean
public PasswordEncoder getPasswordEncoder() {
return new BCryptPasswordEncoder();
}
/**
* 暴露AuthenticationManager存上下文
* */
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception
{
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
// 对于登录接口 允许匿名访问
.antMatchers("/personal/login","/personal/entlogin").anonymous()
//放行swagger
.antMatchers("/swagger-ui.html","/swagger-resources/**","/webjars/**","/v2/**","/api/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证,配置退出路径
.anyRequest().authenticated()
.and()
.logout().logoutUrl( "/logout")
.and()
//关闭security默认登陆框
.formLogin().disable()
//关闭csrf
.csrf().disable()
//不通过Session获取SecurityContext
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().addFilterBefore(jwtAuthenticationTokenFiler, UsernamePasswordAuthenticationFilter.class)
;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// 配置数据库访问认证步骤
auth.userDetailsService(userService);
}
}

View File

@ -16,6 +16,8 @@ import com.rzyc.bean.OthResourceDo;
import com.rzyc.bean.OthTeamDo;
import com.rzyc.bean.house.dto.*;
import com.rzyc.bean.house.vo.*;
import com.rzyc.config.MethodAnnotation;
import com.rzyc.enums.BackType;
import com.rzyc.enums.DelState;
import com.rzyc.enums.RevertType;
@ -28,6 +30,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -620,6 +623,8 @@ public class EmergencyController extends BaseController {
* */
@ApiOperation(value = "事故类型", notes = "事故类型")
@GetMapping("/accidentType")
@PreAuthorize("hasAnyAuthority('PCEMERGENCY:ACCIDENTTYPE','PCEMERGENCY:ACCIDENTTYPE:UPDATE')")
@MethodAnnotation(authorizations = {"PCEMERGENCY:ACCIDENTTYPE","PCEMERGENCY:ACCIDENTTYPE:UPDATE"},name = "事故类型")
@ResponseBody
public SingleResult<AccidentType> accidentType()throws Exception{
SingleResult singleResult = new SingleResult();

View File

@ -0,0 +1,82 @@
package com.rzyc.filter;
import com.common.utils.jwt.JwtUtil;
import com.rzyc.advice.CustomException;
import com.rzyc.mapper.AuthorityKeyMapper;
import com.rzyc.model.AuthorityKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* spring security JWT Filter
* @author Xuwanxin
* @date 2022/9/26
* */
@Component
@Slf4j
public class JwtAuthenticationTokenFiler extends OncePerRequestFilter {
@Autowired
AuthorityKeyMapper authorityKeyMapper;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//获取token
String token = request.getHeader("userToken");
if (!StringUtils.hasText(token)) {
//放行
filterChain.doFilter(request, response);
return;
}
try {
String userId = JwtUtil.getTokenMsg(token);
} catch (Exception e) {
System.out.println("token非法");
throw new RuntimeException("token非法");
}
try {
List<AuthorityKey>authorizations = authorityKeyMapper.allAuthorizations();
List<GrantedAuthority> authority= new ArrayList<GrantedAuthority>();
StringBuilder stringBuilder = new StringBuilder();
for (AuthorityKey s:authorizations) {
stringBuilder.append(s.getCategory() +":"+s.getAuthKey());
authority.add(new SimpleGrantedAuthority(stringBuilder.toString()));
stringBuilder.setLength(0);
}
// 获取权限信息封装到Authentication中
UsernamePasswordAuthenticationToken authenticationToken =
new UsernamePasswordAuthenticationToken(null,null,authority);
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
filterChain.doFilter(request, response);
}catch (AccessDeniedException e){
System.out.println("权限失败");
throw new CustomException("无权限操作");
}catch (Exception e){
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,71 @@
package com.rzyc.service;
import com.rzyc.config.EntUserDetails;
import com.rzyc.mapper.AuthorityKeyMapper;
import com.rzyc.mapper.ent.EntUserMapper;
import com.rzyc.model.AuthorityKey;
import com.rzyc.model.ent.EntUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* spring security 用户认证过程
* @author Xuwanxin
* @author 2022/09/27
* */
@Service("userService")
public class UserDetailsServiceImpl implements UserDetailsService {
/**
* 内存过程密码加密
* */
private PasswordEncoder passwordEncoder;
/**
* 企业端用户
* */
private EntUserMapper entUserMapper;
private AuthorityKeyMapper authorityKeyMapper;
@Autowired
public void UserDetailsServiceImplFinder(PasswordEncoder passwordEncoder,EntUserMapper entUserMapper,AuthorityKeyMapper authorityKeyMapper) {
this.passwordEncoder = passwordEncoder;
this.entUserMapper = entUserMapper;
this.authorityKeyMapper = authorityKeyMapper;
}
@Override
public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
//判断数据库用户
EntUser entUser = entUserMapper.selectByName(name);
if (Objects.isNull(entUser)){
throw new UsernameNotFoundException("用户名或密码错误");
}
List<GrantedAuthority> authority= new ArrayList<GrantedAuthority>();
List<AuthorityKey>authorizations = authorityKeyMapper.allAuthorizations();
StringBuilder stringBuilder = new StringBuilder();
for (AuthorityKey s:authorizations) {
stringBuilder.append(s.getCategory() +":"+s.getAuthKey());
authority.add(new SimpleGrantedAuthority(stringBuilder.toString()));
}
return new EntUserDetails(entUser.getName(), passwordEncoder.encode(entUser.getPasswd()), authority,entUser.getEntUserId());
}
}

View File

@ -0,0 +1,62 @@
package com.rzyc.service;
import com.common.utils.jwt.JwtUtil;
import com.rzyc.config.EntUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* 用户登陆 Service
* @author Xuwanxin
* @date 2022/9/26
* */
@Service
public class UserLoginService {
private UserDetailsService userDetailsService;
private PasswordEncoder passwordEncoder;
@Autowired
public void UserLoginServiceFinder(UserDetailsService userDetailsService,PasswordEncoder passwordEncoder){
this.userDetailsService = userDetailsService;
this.passwordEncoder = passwordEncoder;
}
public String login(String username, String password) {
String token = null;
try {
UserDetails userDetails = userDetailsService.loadUserByUsername(username);
if (Objects.isNull(userDetails)) {
throw new UsernameNotFoundException("账号不存在");
}
//这里可能会不对因为我们是MD5这个是spring security 中的 encoder加密
if (!passwordEncoder.matches(password, userDetails.getPassword())) {
throw new BadCredentialsException("密码不正确");
}
//spring security context insert
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
//企业用户id
String id = ((EntUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId();
token = JwtUtil.createToken(id);
} catch (AuthenticationException e) {
e.printStackTrace();
}
return token;
}
}