From 0bf75be12bfe218793dbca913e8c120c91492080 Mon Sep 17 00:00:00 2001 From: liuxm <liuxm@fescotech.com> Date: 星期一, 22 四月 2024 17:03:31 +0800 Subject: [PATCH] 角色管理相关 --- pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebFilterConfiguration.java | 45 ++++++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaRole.java | 22 +- pms-parent/pms-global/src/main/resources/mapper/BaRoleMapper.xml | 7 pms-parent/pms-global/src/main/resources/mapper/BaUserMapper.xml | 1 pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleSv.java | 103 ++++++++++++++ pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/QueryVo.java | 14 ++ pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebListenerConfiguration.java | 62 ++++++++ pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleCtrl.java | 119 +++++++++++++++++ 8 files changed, 359 insertions(+), 14 deletions(-) diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaRole.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaRole.java index 7ba2890..eb0a905 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaRole.java +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaRole.java @@ -6,23 +6,16 @@ import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.writer.ObjectWriterImplToString; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import com.dy.common.po.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.validation.constraints.NotEmpty; import lombok.*; import org.hibernate.validator.constraints.Length; +import java.util.Date; import java.util.List; -/** - * 鐢ㄦ埛 - */ -//2024-04-12涓嬮潰TableName涓嶇敤閰嶇疆琛ㄥ悕绉帮紙value="BaUser"鎴栤�渂a_user鈥濓級 -//鍙閫氳繃椹煎嘲鍛藉悕娉曞垯绫诲悕涓庤〃鍚嶅搴旇捣鏉ュ氨鍙互浜嗭紝濡傛灉涓嶈兘瀵瑰簲璧锋潵锛岄渶瑕佹寚瀹氳〃鍚嶇О -//渚嬪@TableName(value="TestUser" autoResultMap = true) @TableName(value="ba_role", autoResultMap = true) @Data @Builder @@ -65,9 +58,16 @@ public Boolean deleted; /** + * 鍒涘缓鏃堕棿 + */ + @TableField(value = "create_dt", fill = FieldFill.INSERT) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + public Date createDt; + + /** * 鍓嶇web鐣岄潰鎻愪氦鐨勮鑹叉墍灞炴潈闄愮殑id锛屽叾鏄竴涓瓧绗︿覆鏁扮粍 */ @TableField(exist = false) - public List<String> priIds ; + public List<Integer> priIds ; } \ No newline at end of file diff --git a/pms-parent/pms-global/src/main/resources/mapper/BaRoleMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/BaRoleMapper.xml index cfc729f..b722404 100644 --- a/pms-parent/pms-global/src/main/resources/mapper/BaRoleMapper.xml +++ b/pms-parent/pms-global/src/main/resources/mapper/BaRoleMapper.xml @@ -8,6 +8,7 @@ <result column="name" property="name" /> <result column="disabled" property="disabled" /> <result column="deleted" property="deleted" /> + <result column="create_dt" property="createDt" /> </resultMap> <resultMap id="partResultMap" type="com.dy.pmsGlobal.pojoBa.BaRole"> <result column="id" property="id" /> @@ -15,17 +16,17 @@ </resultMap> <resultMap id="someResultMap" extends="partResultMap" type="com.dy.pmsGlobal.pojoBa.BaRole"> - <collection property="priIds" ofType="java.lang.String" fetchType="eager" column="{roleId=id}" select="com.dy.pmsGlobal.daoBa.BaPrivilegeMapper.selectPrivilegeByRoleId" /> + <collection property="priIds" ofType="java.lang.Integer" fetchType="eager" column="{roleId=id}" select="com.dy.pmsGlobal.daoBa.BaPrivilegeMapper.selectPrivilegeByRoleId" /> </resultMap> <sql id="Base_Column_List"> <!--@mbg.generated--> - id, `name`, disabled, deleted + id, `name`, disabled, deleted,create_dt </sql> <sql id="Part_Column_List"> <!--@mbg.generated--> - id, `name`, disabled + id, `name`, disabled,create_dt </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="someResultMap"> diff --git a/pms-parent/pms-global/src/main/resources/mapper/BaUserMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/BaUserMapper.xml index a011812..59beadf 100644 --- a/pms-parent/pms-global/src/main/resources/mapper/BaUserMapper.xml +++ b/pms-parent/pms-global/src/main/resources/mapper/BaUserMapper.xml @@ -11,6 +11,7 @@ <result column="supper_admin" property="supperAdmin" /> <result column="disabled" property="disabled" typeHandler="com.dy.common.mybatis.BooleanTypeHandler" /> <result column="deleted" property="deleted" typeHandler="com.dy.common.mybatis.BooleanTypeHandler" /> + <result column="create_dt" property="createDt" /> </resultMap> <resultMap id="partResultMap" type="com.dy.pmsGlobal.pojoBa.BaUser"> <!--@mbg.generated--> diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebFilterConfiguration.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebFilterConfiguration.java new file mode 100644 index 0000000..43ab770 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebFilterConfiguration.java @@ -0,0 +1,45 @@ +package com.dy.pmsBase.config; + +//import com.dy.common.webFilter.DevOfDataSourceNameSetFilter; +import com.dy.common.webFilter.UserTokenFilter; +import jakarta.servlet.Filter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class WebFilterConfiguration { + + @Value("${pms.global.dev}") + public String isDevStage ;//鏄惁涓哄紑鍙戦樁娈� +// @Value("${pipIrr.global.dsName}") +// public String dsName ;//寮�鍙戦樁娈电殑鏁版嵁婧愬悕绉� + + /** + * DevOfDataSourceNameSetFilter涓嶶serTokenFilter鍙兘涓�涓閰嶇疆涓婏紝 + * 鎵�浠ヤ粬浠殑order閮芥槸1 + */ + private static final int order_UserTokenFilter = 1 ;//涓庝笅闈� + private static final int order_DevOfDataSourceNameSetFilter = 1 ; + + + @Bean + public FilterRegistrationBean<? extends Filter> RegFilter() { + FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>(); + if(this.isDevStage != null && !this.isDevStage.trim().equals("") && this.isDevStage.trim().equalsIgnoreCase("true")){ +// filterRegistrationBean.setFilter(new DevOfDataSourceNameSetFilter()); +// filterRegistrationBean.addUrlPatterns("/*");//閰嶇疆杩囨护瑙勫垯 +// filterRegistrationBean.addInitParameter("dataSourceName",dsName);//璁剧疆init鍙傛暟 +// filterRegistrationBean.setName("DevOfDataSourceNameSetFilter");//璁剧疆杩囨护鍣ㄥ悕绉� +// filterRegistrationBean.setOrder(order_DevOfDataSourceNameSetFilter);//鎵ц娆″簭 + }else{ + filterRegistrationBean.setFilter(new UserTokenFilter()); + filterRegistrationBean.addUrlPatterns("/*");//閰嶇疆杩囨护瑙勫垯 + filterRegistrationBean.setName("UserTokenFilter");//璁剧疆杩囨护鍣ㄥ悕绉� + filterRegistrationBean.setOrder(order_UserTokenFilter);//鎵ц娆″簭 + } + return filterRegistrationBean; + } + +} diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebListenerConfiguration.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebListenerConfiguration.java new file mode 100644 index 0000000..eb55338 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/config/WebListenerConfiguration.java @@ -0,0 +1,62 @@ +package com.dy.pmsBase.config; + +import com.dy.common.webListener.GenerateIdSetSuffixListener; +import jakarta.servlet.ServletContextListener; +import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class WebListenerConfiguration { + + /** + * 鍚姩椤哄簭 + */ + //private static final int order_config = 0 ; + private static final int order_idSetSuffix = 1 ; + //private static final int order_init = 2 ; + + /* + * 瑙f瀽鍚勭***.config閰嶇疆鐨凜onfigListener锛屾殏鏃朵笉閲囩敤姝ょ閰嶇疆鏂瑰紡 + * + @Bean + public ConfigListener getGlConfigListener(){ + return new ConfigListener() ; + } + /** + * 澶栭儴鎻愪緵Listener + * @param listener 澶栭儴鎻愪緵Listener + * @return 娉ㄥ唽Bean + @Bean + public ServletListenerRegistrationBean<? extends ServletContextListener> regConfigListener(ConfigListener listener) { + ServletListenerRegistrationBean<ConfigListener> listenerRegistrationBean = new ServletListenerRegistrationBean<>(); + listenerRegistrationBean.setListener(listener); + listenerRegistrationBean.setOrder(order_config); + return listenerRegistrationBean; + } + */ + + /** + * 鍐呴儴鎻愪緵listener锛岃listener鍦ㄧ郴缁熷惎鍔ㄦ椂锛屾牴鎹厤缃� 璁剧疆ID浜х敓鍣ㄧ殑鍚庣紑 + * @return 娉ㄥ唽Bean + */ + @Bean + public ServletListenerRegistrationBean<? extends ServletContextListener> regSsoListener() { + ServletListenerRegistrationBean<GenerateIdSetSuffixListener> listenerRegistrationBean = new ServletListenerRegistrationBean<>(); + listenerRegistrationBean.setListener(new GenerateIdSetSuffixListener()); + listenerRegistrationBean.setOrder(order_idSetSuffix); + return listenerRegistrationBean; + } + +// /** +// * 鍐呴儴鎻愪緵listener锛岃listener鍦ㄧ郴缁熷惎鍔ㄦ椂锛屽垵濮嬪寲鏁版嵁搴撴暟鎹� +// * @return 娉ㄥ唽Bean +// */ +// @Bean +// public ServletListenerRegistrationBean<? extends ServletContextListener> regInitListener() { +// ServletListenerRegistrationBean<InitListener> listenerRegistrationBean = new ServletListenerRegistrationBean<>(); +// listenerRegistrationBean.setListener(new InitListener()); +// listenerRegistrationBean.setOrder(order_init); +// return listenerRegistrationBean; +// } +} diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/QueryVo.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/QueryVo.java new file mode 100644 index 0000000..53d38a0 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/QueryVo.java @@ -0,0 +1,14 @@ +package com.dy.pmsBase.role; + +import com.dy.common.webUtil.QueryConditionVo; +import lombok.*; + +@Data +@EqualsAndHashCode(callSuper = false) +@ToString(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class QueryVo extends QueryConditionVo { + public String name; +} diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleCtrl.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleCtrl.java new file mode 100644 index 0000000..01091c5 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleCtrl.java @@ -0,0 +1,119 @@ +package com.dy.pmsBase.role; + +import com.alibaba.fastjson2.JSON; +import com.dy.common.aop.SsoPowerAop; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; +import com.dy.pmsGlobal.pojoBa.BaRole; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 瑙掕壊绠$悊 + */ +@Slf4j +@RestController +@RequestMapping(path="role") +@SuppressWarnings("unchecked") +public class RoleCtrl { + private RoleSv roleSv; + @Autowired + public RoleCtrl(RoleSv roleSv){ + this.roleSv = roleSv; + } + + /** + * 淇濆瓨瑙掕壊淇℃伅 + * @param role + * @param bindingResult + * @return + */ + @PostMapping(path="save") + @SsoPowerAop(power = "10100011") + public BaseResponse<BaRole> save(@RequestBody @Valid BaRole role,BindingResult bindingResult){ + try { + role.setDeleted(false); + role.setDisabled(false); + return BaseResponseUtils.buildSuccess(roleSv.save(role)); + }catch (Exception e){ + log.error("淇濆瓨瑙掕壊寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + + /** + * 鏇存柊瑙掕壊淇℃伅 + * @param role + * @param bindingResult + * @return + */ + @PostMapping(path="update") + @SsoPowerAop(power = "10100011") + public BaseResponse<BaRole> update(@RequestBody @Valid BaRole role,BindingResult bindingResult){ + try { + return BaseResponseUtils.buildSuccess(roleSv.update(role)); + }catch (Exception e){ + log.error("鏇存柊瑙掕壊寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鍒犻櫎瑙掕壊淇℃伅 + * @param id + * @param bindingResult + * @return + */ + @PostMapping(path="delete") + @SsoPowerAop(power = "10100011") + public BaseResponse<BaRole> delete(String id,BindingResult bindingResult){ + try { + return BaseResponseUtils.buildSuccess(roleSv.delete(Long.parseLong(id))); + }catch (Exception e){ + log.error("鍒犻櫎瑙掕壊寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + + /** + * 鏍规嵁ID鏌ヨ瑙掕壊淇℃伅 + * @return + */ + @GetMapping(path="one") + @SsoPowerAop(power = "10100010") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇� + public BaseResponse<BaRole> one(String id){ + try{ + BaRole role=roleSv.selectById(id); + return BaseResponseUtils.buildSuccess(JSON.toJSON(role)); + }catch (Exception e){ + log.error("鏌ヨ瑙掕壊寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鍒嗛〉鏌ヨ瑙掕壊淇℃伅 + * @param vo + * @return + */ + @PostMapping(path="some") + @SsoPowerAop(power = "10100010") + public BaseResponse<QueryResultVo<List<BaRole>>> some(@RequestBody QueryVo vo){ + try { + return BaseResponseUtils.buildSuccess(roleSv.selectSome(vo)); + }catch (Exception e){ + log.error("鍒嗛〉鏌ヨ瑙掕壊寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + +} + diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleSv.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleSv.java new file mode 100644 index 0000000..e3a95c6 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleSv.java @@ -0,0 +1,103 @@ +package com.dy.pmsBase.role; + +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.dy.common.webUtil.QueryResultVo; +import com.dy.pmsBase.role.QueryVo; +import com.dy.pmsGlobal.daoBa.BaPrivilegeMapper; +import com.dy.pmsGlobal.daoBa.BaRoleMapper; +import com.dy.pmsGlobal.daoBa.BaRolePrivilegeMapper; +import com.dy.pmsGlobal.pojoBa.BaRole; +import com.dy.pmsGlobal.pojoBa.BaRolePrivilege; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.common.utils.PojoUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class RoleSv { + + private BaRoleMapper dao; + private BaRolePrivilegeMapper rpDao; + private BaPrivilegeMapper priDao; + + @Autowired + public RoleSv(BaRoleMapper dao, BaRolePrivilegeMapper rpDao,BaPrivilegeMapper priDao) { + this.dao = dao; + this.rpDao = rpDao; + this.priDao = priDao; + } + + @Transactional + public int save(BaRole role) { + int count = dao.insert(role); + // 娣诲姞瑙掕壊鏉冮檺 + updateRolePrivileges(role.id,role.priIds); + return count; + } + + /** + * 閫昏緫鍒犻櫎瀹炰綋 + * @param id 瀹炰綋ID + * @return 褰卞搷璁板綍鏁伴噺 + */ + @Transactional + public int delete(Long id) { + return this.dao.deleteLogicById(id); + } + + @Transactional + public int update(BaRole role) { + int count = dao.updateByPrimaryKeySelective(role); + // 鏇存柊瑙掕壊鏉冮檺 + updateRolePrivileges(role.id,role.priIds); + return count; + } + + /** + * 娣诲姞鎴栨洿鏂拌鑹叉潈闄� + * @param roleId 瑙掕壊ID + * @param priIds 鏉冮檺id + * @return + */ + private void updateRolePrivileges(Long roleId,List<Integer> priIds) { + if(CollectionUtils.isEmpty(priIds)){ + throw new RuntimeException("鏉冮檺id涓嶈兘涓虹┖"); + } + // 鍒犻櫎瑙掕壊鏉冮檺 + rpDao.deleteByRoleId(roleId); + priIds.stream().forEach(rp -> { + if(priDao.selectByPrimaryKey(rp.longValue()) != null){ + rpDao.insert(new BaRolePrivilege(roleId, rp.longValue())); + } + }); + } + + public BaRole selectById(String roleId) { + return dao.selectByPrimaryKey(Long.valueOf(roleId)); + } + + /** + * 鑾峰彇瑙掕壊鍒楄〃 + */ + public QueryResultVo<List<BaRole>> selectSome(QueryVo queryVo) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); + + //鏌ヨ绗﹀悎鏉′欢鐨勮褰曟�绘暟 + Long itemTotal = this.dao.selectSomeCount(params); + + QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; + //璁$畻鍒嗛〉绛変俊鎭� + rsVo.calculateAndSet(itemTotal, params); + + //鏌ヨ绗﹀悎鏉′欢鐨勮褰� + rsVo.obj = this.dao.selectSome(params) ; + return rsVo ; + } + +} + -- Gitblit v1.8.0