From c96306638527b3376d88704ee82fc14fe3f4c541 Mon Sep 17 00:00:00 2001 From: 13405411873 <1994398261@qq.com> Date: Wed, 11 Oct 2023 18:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChainStoreInfoController.java | 26 +-- .../AutoInjectBaseFieldInterceptor.java | 202 ++++++++++++++++++ .../common/config/MybatisPlusConfig.java | 3 + .../service/impl/AccountServiceImpl.java | 2 + .../service/impl/AlipayServiceImpl.java | 2 + .../service/impl/BalanceServiceImpl.java | 2 + .../service/impl/CouponGroupServiceImpl.java | 2 + .../service/impl/CouponServiceImpl.java | 3 + .../service/impl/MemberServiceImpl.java | 5 + .../service/impl/OpenGiftServiceImpl.java | 3 + .../common/service/impl/OrderServiceImpl.java | 8 + .../service/impl/PaymentServiceImpl.java | 2 + .../common/service/impl/PointServiceImpl.java | 3 + .../service/impl/RefundServiceImpl.java | 2 + .../common/service/impl/StaffServiceImpl.java | 2 + .../service/impl/UserCouponServiceImpl.java | 7 + .../service/impl/WeixinServiceImpl.java | 3 + .../controller/BackendLoginController.java | 10 +- .../module/schedule/CouponExpireJob.java | 4 +- .../com/fuint/module/schedule/MessageJob.java | 4 +- .../fuint/module/schedule/OrderCancelJob.java | 4 +- .../com/fuint/system/dept/entity/SysDept.java | 5 + .../system/dept/mapper/SysDeptMapper.java | 15 -- .../system/dept/mapper/xml/SysDeptMapper.xml | 45 +--- .../dept/service/impl/SysDeptServiceImpl.java | 4 +- .../fuint/system/dict/entity/SysDictData.java | 1 + .../src/main/resources/application.properties | 3 +- fuintBackend/fuint-framework/pom.xml | 7 + .../fuint/framework/entity/BaseEntity.java | 62 +----- .../framework/shiroConfig/ShiroConfig.java | 72 +++++++ .../framework/shiroConfig/UserRealm.java | 54 +++++ .../main/resources/mapper/TAccountMapper.xml | 4 +- 32 files changed, 425 insertions(+), 146 deletions(-) create mode 100644 fuintBackend/fuint-application/src/main/java/com/fuint/common/config/AutoInjectBaseFieldInterceptor.java create mode 100644 fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/ShiroConfig.java create mode 100644 fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/UserRealm.java diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/controller/ChainStoreInfoController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/controller/ChainStoreInfoController.java index 7ab800a4c..483b22610 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/controller/ChainStoreInfoController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/store/controller/ChainStoreInfoController.java @@ -3,11 +3,11 @@ package com.fuint.business.store.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.api.ApiController; -import com.baomidou.mybatisplus.extension.api.R; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fuint.business.store.entity.ChainStoreInfo; import com.fuint.business.store.service.ChainStoreInfoService; +import com.fuint.framework.web.BaseController; +import com.fuint.framework.web.ResponseObject; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -22,7 +22,7 @@ import java.util.List; */ @RestController @RequestMapping("chainStoreInfo") -public class ChainStoreInfoController extends ApiController { +public class ChainStoreInfoController extends BaseController { /** * 服务对象 */ @@ -37,8 +37,8 @@ public class ChainStoreInfoController extends ApiController { * @return 所有数据 */ @GetMapping - public R selectAll(Page page, ChainStoreInfo chainStoreInfo) { - return success(this.chainStoreInfoService.page(page, new QueryWrapper<>(chainStoreInfo))); + public ResponseObject selectAll(Page page, ChainStoreInfo chainStoreInfo) { + return getSuccessResult(this.chainStoreInfoService.page(page, new QueryWrapper<>(chainStoreInfo))); } /** @@ -48,8 +48,8 @@ public class ChainStoreInfoController extends ApiController { * @return 单条数据 */ @GetMapping("{id}") - public R selectOne(@PathVariable Serializable id) { - return success(this.chainStoreInfoService.getById(id)); + public ResponseObject selectOne(@PathVariable Serializable id) { + return getSuccessResult(this.chainStoreInfoService.getById(id)); } /** @@ -59,8 +59,8 @@ public class ChainStoreInfoController extends ApiController { * @return 新增结果 */ @PostMapping - public R insert(@RequestBody ChainStoreInfo chainStoreInfo) { - return success(this.chainStoreInfoService.save(chainStoreInfo)); + public ResponseObject insert(@RequestBody ChainStoreInfo chainStoreInfo) { + return getSuccessResult(this.chainStoreInfoService.save(chainStoreInfo)); } /** @@ -70,8 +70,8 @@ public class ChainStoreInfoController extends ApiController { * @return 修改结果 */ @PutMapping - public R update(@RequestBody ChainStoreInfo chainStoreInfo) { - return success(this.chainStoreInfoService.updateById(chainStoreInfo)); + public ResponseObject update(@RequestBody ChainStoreInfo chainStoreInfo) { + return getSuccessResult(this.chainStoreInfoService.updateById(chainStoreInfo)); } /** @@ -81,8 +81,8 @@ public class ChainStoreInfoController extends ApiController { * @return 删除结果 */ @DeleteMapping - public R delete(@RequestParam("idList") List idList) { - return success(this.chainStoreInfoService.removeByIds(idList)); + public ResponseObject delete(@RequestParam("idList") List idList) { + return getSuccessResult(this.chainStoreInfoService.removeByIds(idList)); } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/AutoInjectBaseFieldInterceptor.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/AutoInjectBaseFieldInterceptor.java new file mode 100644 index 000000000..26491471f --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/AutoInjectBaseFieldInterceptor.java @@ -0,0 +1,202 @@ +package com.fuint.common.config; + +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReflectUtil; +import com.fuint.common.dto.AccountInfo; +import com.fuint.common.util.TokenUtil; +import com.fuint.repository.model.TAccount; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.binding.MapperMethod.ParamMap; +import org.apache.ibatis.executor.Executor; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.SqlCommandType; +import org.apache.ibatis.plugin.*; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Field; +import java.util.*; + +/** + * mybatis拦截器,自动注入创建人、创建时间、修改人、修改时间 + * + * @Author wxz + * @Date 2023-5-5 + */ + +@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})}) +@Component +@Slf4j +public class AutoInjectBaseFieldInterceptor implements Interceptor { + /** + * 用户字段,如果有其他命名的字段,就添加进来 + */ + private List createUserFieldList() { + List createUserList = new ArrayList<>(); + createUserList.add("createUser"); + createUserList.add("createBy"); + return createUserList; + } + + private List updateUserFieldList() { + List createUserList = new ArrayList<>(); + createUserList.add("updateUser"); + createUserList.add("updateBy"); + return createUserList; + } + + private List idFieldList() { + return Collections.singletonList("id"); + } + + private List createTimeFieldList() { + List createTimeList = new ArrayList<>(); + createTimeList.add("createTime"); + createTimeList.add("createDate"); + return createTimeList; + } + private List createDepartFieldList() { + List createDepartList = new ArrayList<>(); + createDepartList.add("deptId"); + createDepartList.add("departId"); + return createDepartList; + } + + private List updateTimeFieldList() { + List createTimeList = new ArrayList<>(); + createTimeList.add("updateTime"); + createTimeList.add("updateDate"); + return createTimeList; + } + + @Override + public Object intercept(Invocation invocation) throws Throwable { + + if (invocation.getArgs().length == 1) { + return invocation.proceed(); + } + + MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; + SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType(); + Object parameter = invocation.getArgs()[1]; + if (parameter == null) { + return invocation.proceed(); + } + if (SqlCommandType.INSERT == sqlCommandType) { + Field[] fields = ReflectUtil.getFields(parameter.getClass()); + for (Field field : fields) { + try { + String fieldName = field.getName(); + //获取属性名前,先开启反射可访问,否则,无法获取到字段名,因为字段名是私有属性 + field.setAccessible(true); + Object localCreateBy = field.get(parameter); + // 注入id + if (this.idFieldList().contains(fieldName)) { + if (localCreateBy == null || "".equals(localCreateBy)) { + field.set(parameter, IdUtil.fastSimpleUUID()); + } + } + //注入创建时间 + if (this.createTimeFieldList().contains(fieldName)) { + if (localCreateBy == null || "".equals(localCreateBy)) { + field.set(parameter, new Date()); + } + } + //注入创建人 + if (this.createUserFieldList().contains(fieldName)) { + if (localCreateBy == null || "".equals(localCreateBy)) { + setUserName(field, parameter); + } + } + //注入部门 + if (this.createDepartFieldList().contains(fieldName)) { + if (localCreateBy == null || "".equals(localCreateBy)) { + setDepart(field, parameter); + } + } + field.setAccessible(false); + } + catch (Exception ignored) { + } + } + } + if (SqlCommandType.UPDATE == sqlCommandType) { + Field[] fields = null; + if (parameter instanceof ParamMap) { + ParamMap p = (ParamMap) parameter; + if (p.containsKey("et")) { + parameter = p.get("et"); + } else { + parameter = p.get("param1"); + } + if (parameter == null) { + return invocation.proceed(); + } + } + fields = ReflectUtil.getFields(parameter.getClass()); + for (Field field : fields) { + try { + String fieldName = field.getName(); + field.setAccessible(true); + Object localUpdateBy = field.get(parameter); + if (this.updateUserFieldList().contains(fieldName)) { + if (localUpdateBy == null || "".equals(localUpdateBy)) { + setUserName(field, parameter); + } + } + if (this.updateTimeFieldList().contains(fieldName)) { + if (localUpdateBy == null || "".equals(localUpdateBy)) { + field.set(parameter, new Date()); + } + } + field.setAccessible(false); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + return invocation.proceed(); + } + + @Override + public Object plugin(Object target) { + return Plugin.wrap(target, this); + } + + @Override + public void setProperties(Properties properties) { + } + + private void setUserName(Field field, Object parameter) { + AccountInfo sysUser = null; + //获取登录用户信息 + try { + sysUser = TokenUtil.getNowAccountInfo(); + if (ObjectUtil.isNotEmpty(sysUser)) { + field.setAccessible(true); + field.set(parameter, sysUser.getId() + ""); + field.setAccessible(false); + } + } + catch (Exception ignored) { + } + } + + private void setDepart(Field field, Object parameter) { + AccountInfo sysUser = null; + //获取登录用户信息 + try { + sysUser = TokenUtil.getNowAccountInfo(); + if (ObjectUtil.isNotEmpty(sysUser)) { + field.setAccessible(true); + field.set(parameter, sysUser.getDeptId()); + field.setAccessible(false); + } + } + catch (Exception ignored) { + } + } + +} + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/MybatisPlusConfig.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/MybatisPlusConfig.java index 24cda04b8..0b6c3fcb6 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/MybatisPlusConfig.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/MybatisPlusConfig.java @@ -1,5 +1,6 @@ package com.fuint.common.config; +import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.injector.ISqlInjector; import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector; import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor; @@ -48,4 +49,6 @@ public class MybatisPlusConfig { public OptimisticLockerInterceptor optimisticLockerInterceptor() { return new OptimisticLockerInterceptor(); } + + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AccountServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AccountServiceImpl.java index 35a53abfa..06de3dadb 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AccountServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AccountServiceImpl.java @@ -25,6 +25,7 @@ import com.github.pagehelper.PageHelper; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -61,6 +62,7 @@ public class AccountServiceImpl extends ServiceImpl im * 员工接口 */ @Autowired + @Lazy private StaffService staffService; @Autowired private ISysDeptService deptService; diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AlipayServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AlipayServiceImpl.java index d7472045a..2d8cd13d9 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AlipayServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/AlipayServiceImpl.java @@ -23,6 +23,7 @@ import com.ijpay.alipay.AliPayApiConfigKit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; @@ -40,6 +41,7 @@ public class AlipayServiceImpl implements AlipayService { private static final Logger logger = LoggerFactory.getLogger(WeixinServiceImpl.class); @Autowired + @Lazy private OrderService orderService; @Autowired diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/BalanceServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/BalanceServiceImpl.java index 7eba27186..9a2861633 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/BalanceServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/BalanceServiceImpl.java @@ -23,6 +23,7 @@ import com.fuint.repository.model.MtUser; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.apache.commons.lang.StringUtils; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -48,6 +49,7 @@ public class BalanceServiceImpl extends ServiceImpl private MtUserMapper mtUserMapper; @Resource + @Lazy private WeixinService weixinService; @Resource diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/CouponGroupServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/CouponGroupServiceImpl.java index 8ffb1e2d5..d7899b42a 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/CouponGroupServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/CouponGroupServiceImpl.java @@ -28,6 +28,7 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.core.env.Environment; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; @@ -73,6 +74,7 @@ public class CouponGroupServiceImpl extends ServiceImpl imp private MtCouponGoodsMapper mtCouponGoodsMapper; @Autowired + @Lazy private UserCouponService userCouponService; @Autowired @@ -73,6 +75,7 @@ public class CouponServiceImpl extends ServiceImpl imp private SendSmsService sendSmsService; @Autowired + @Lazy private ConfirmLogService confirmLogService; @Autowired diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java index c84b5d104..8dbe52ff2 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java @@ -27,6 +27,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -64,24 +65,28 @@ public class MemberServiceImpl extends ServiceImpl impleme * 会员等级接口 * */ @Resource + @Lazy private UserGradeService userGradeService; /** * 会员等级接口 * */ @Resource + @Lazy private OpenGiftService openGiftService; /** * 后台账户服务接口 */ @Resource + @Lazy private AccountService accountService; /** * 员工接口 */ @Resource + @Lazy private StaffService staffService; /** diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OpenGiftServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OpenGiftServiceImpl.java index 27c167148..1eb40e018 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OpenGiftServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OpenGiftServiceImpl.java @@ -23,6 +23,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -48,9 +49,11 @@ public class OpenGiftServiceImpl extends ServiceImpl implem private SettingService settingService; @Autowired + @Lazy private CouponService couponService; @Autowired + @Lazy private UserCouponService userCouponService; @Autowired private AddressService addressService; @Autowired + @Lazy private MemberService memberService; @Autowired + @Lazy private PointService pointService; @Autowired @@ -106,12 +111,15 @@ public class OrderServiceImpl extends ServiceImpl implem UserGradeService userGradeService; @Autowired + @Lazy private RefundService refundService; @Autowired + @Lazy private WeixinService weixinService; @Autowired + @Lazy private AlipayService alipayService; @Autowired diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PaymentServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PaymentServiceImpl.java index 7e182a589..ab5c81483 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PaymentServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PaymentServiceImpl.java @@ -13,6 +13,7 @@ import com.fuint.utils.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; @@ -40,6 +41,7 @@ public class PaymentServiceImpl implements PaymentService { * 微信服务接口 * */ @Autowired + @Lazy private WeixinService weixinService; /** diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PointServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PointServiceImpl.java index 6e341cc30..f4e930bfa 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PointServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/PointServiceImpl.java @@ -23,6 +23,7 @@ import com.github.pagehelper.PageHelper; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import com.github.pagehelper.Page; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -47,9 +48,11 @@ public class PointServiceImpl extends ServiceImpl implem private MtUserMapper mtUserMapper; @Autowired + @Lazy private MemberService memberService; @Autowired + @Lazy private WeixinService weixinService; /** diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/RefundServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/RefundServiceImpl.java index 07559eaee..9675a7e28 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/RefundServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/RefundServiceImpl.java @@ -23,6 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -79,6 +80,7 @@ public class RefundServiceImpl extends ServiceImpl imp * 订单服务接口 * */ @Autowired + @Lazy private OrderService orderService; /** diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/StaffServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/StaffServiceImpl.java index 402b2d45a..e2f5fb629 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/StaffServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/StaffServiceImpl.java @@ -20,6 +20,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -43,6 +44,7 @@ public class StaffServiceImpl extends ServiceImpl implem * 会员服务接口 */ @Autowired + @Lazy private MemberService memberService; /** diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/UserCouponServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/UserCouponServiceImpl.java index 888f931ab..985581d99 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/UserCouponServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/UserCouponServiceImpl.java @@ -23,6 +23,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -45,18 +46,23 @@ public class UserCouponServiceImpl extends ServiceImpl children = new ArrayList(); diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/SysDeptMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/SysDeptMapper.java index 3e2dbff8d..4614fb731 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/SysDeptMapper.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/SysDeptMapper.java @@ -79,21 +79,6 @@ public interface SysDeptMapper extends BaseMapper */ public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); - /** - * 新增部门信息 - * - * @param dept 部门信息 - * @return 结果 - */ - public int insertDept(SysDept dept); - - /** - * 修改部门信息 - * - * @param dept 部门信息 - * @return 结果 - */ - public int updateDept(SysDept dept); /** * 修改所在部门正常状态 diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/xml/SysDeptMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/xml/SysDeptMapper.xml index 047ecb40d..7ff431704 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/xml/SysDeptMapper.xml +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/mapper/xml/SysDeptMapper.xml @@ -69,49 +69,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from sys_dept where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1 - - - insert into sys_dept( - parent_id, - dept_name, - ancestors, - order_num, - leader, - phone, - email, - status, - create_by, - create_time - )values( - #{parentId}, - #{deptName}, - #{ancestors}, - #{orderNum}, - #{leader}, - #{phone}, - #{email}, - #{status}, - #{createBy}, - sysdate() - ) - - - - update sys_dept - - parent_id = #{parentId}, - dept_name = #{deptName}, - ancestors = #{ancestors}, - order_num = #{orderNum}, - leader = #{leader}, - phone = #{phone}, - email = #{email}, - status = #{status}, - update_by = #{updateBy}, - update_time = sysdate() - - where dept_id = #{deptId} - + + update sys_dept set ancestors = diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java index 229e6eee9..b41264f72 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dept/service/impl/SysDeptServiceImpl.java @@ -184,7 +184,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple } dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); } - return baseMapper.insertDept(dept); + return baseMapper.insert(dept); } /** @@ -205,7 +205,7 @@ public class SysDeptServiceImpl extends ServiceImpl imple dept.setAncestors(newAncestors); updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); } - int result = baseMapper.updateDept(dept); + int result = baseMapper.updateById(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) && !StringUtils.equals("0", dept.getAncestors())) { diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dict/entity/SysDictData.java b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dict/entity/SysDictData.java index 348e6dee5..638f91e15 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/system/dict/entity/SysDictData.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/system/dict/entity/SysDictData.java @@ -15,6 +15,7 @@ public class SysDictData extends BaseEntity private static final long serialVersionUID = 1L; /** 字典编码 */ + private Long dictCode; /** 字典排序 */ diff --git a/fuintBackend/fuint-application/src/main/resources/application.properties b/fuintBackend/fuint-application/src/main/resources/application.properties index efe8f4798..b92416466 100644 --- a/fuintBackend/fuint-application/src/main/resources/application.properties +++ b/fuintBackend/fuint-application/src/main/resources/application.properties @@ -20,6 +20,7 @@ spring.servlet.multipart.max-request-size=10MB # mybatis\u914D\u7F6E mybatis-plus.mapper-locations = classpath*:/mapper/*Mapper.xml,classpath*:com/fuint/**/xml/*Mapper.xml - +# Զ +mybatis-plus.configuration.intercepts=com.example.MyInterceptor # \u9ED8\u8BA4\u65F6\u95F4\u683C\u5F0F spring.jackson.date-format=yyyy-MM-dd HH:mm:ss diff --git a/fuintBackend/fuint-framework/pom.xml b/fuintBackend/fuint-framework/pom.xml index c3d67cff8..6f320fce1 100644 --- a/fuintBackend/fuint-framework/pom.xml +++ b/fuintBackend/fuint-framework/pom.xml @@ -40,8 +40,15 @@ javassist 3.24.0-GA + + + org.apache.shiro + shiro-spring-boot-starter + 1.7.0 + + diff --git a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/entity/BaseEntity.java b/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/entity/BaseEntity.java index 971850132..42cc9c22a 100644 --- a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/entity/BaseEntity.java +++ b/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/entity/BaseEntity.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; import java.io.Serializable; import java.util.Date; @@ -15,6 +16,7 @@ import java.util.Map; * * @author ruoyi */ +@Data public class BaseEntity implements Serializable { private static final long serialVersionUID = 1L; @@ -47,66 +49,6 @@ public class BaseEntity implements Serializable @TableField(exist = false) private Map params; - public String getSearchValue() - { - return searchValue; - } - - public void setSearchValue(String searchValue) - { - this.searchValue = searchValue; - } - - public String getCreateBy() - { - return createBy; - } - - public void setCreateBy(String createBy) - { - this.createBy = createBy; - } - - public Date getCreateTime() - { - return createTime; - } - - public void setCreateTime(Date createTime) - { - this.createTime = createTime; - } - - public String getUpdateBy() - { - return updateBy; - } - - public void setUpdateBy(String updateBy) - { - this.updateBy = updateBy; - } - - public Date getUpdateTime() - { - return updateTime; - } - - public void setUpdateTime(Date updateTime) - { - this.updateTime = updateTime; - } - - public String getRemark() - { - return remark; - } - - public void setRemark(String remark) - { - this.remark = remark; - } - public Map getParams() { if (params == null) diff --git a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/ShiroConfig.java b/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/ShiroConfig.java new file mode 100644 index 000000000..9bc72f5c6 --- /dev/null +++ b/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/ShiroConfig.java @@ -0,0 +1,72 @@ +package com.fuint.framework.shiroConfig; + +import org.apache.shiro.authc.credential.HashedCredentialsMatcher; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.spring.LifecycleBeanPostProcessor; +import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; +import org.apache.shiro.spring.web.ShiroFilterFactoryBean; +import org.apache.shiro.util.ThreadContext; +import org.apache.shiro.web.mgt.DefaultWebSecurityManager; +import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; + +import java.util.LinkedHashMap; +import java.util.Map; +/** + * 描述: + * + * @author caojing + * @create 2020-4-28 + */ +@Configuration +public class ShiroConfig { + //Filter工厂,设置对应的过滤条件和跳转条件 + @Bean + public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { + ShiroFilterFactoryBean filter=new ShiroFilterFactoryBean(); + filter.setSecurityManager(securityManager); + //设置shiro的拦截规则 + //anon 匿名用户可访问 authc 认证用户可访问 + //user 使用RemeberMe的用户可访问 perms 对应权限可访问 + //role 对应的角色可访问 + LinkedHashMap filterMap=new LinkedHashMap<>(); + filterMap.put("/backendApi/login/doLogin","anon"); + filterMap.put("/clientApi/captcha/getCode","anon"); + filterMap.put("/static/**","anon"); + filterMap.put("/**","authc"); + filter.setFilterChainDefinitionMap(filterMap); + return filter; + + } + @Bean + public UserRealm getRealm(){ + UserRealm userRealm = new UserRealm(); + return userRealm; + } + @Bean + public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(@Qualifier("securityManager") SecurityManager securityManager) { + AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor(); + advisor.setSecurityManager(securityManager); + return advisor; + } + + @Bean(name = "securityManager") + public DefaultWebSecurityManager securityManager(UserRealm userRealm) + { + DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); + // 设置realm. + securityManager.setRealm(userRealm); + ThreadContext.bind(securityManager);//加上这句代码手动绑定 + // session管理器 + //securityManager.setSessionManager(sessionManager()); + // 记住我 + //securityManager.setRememberMeManager(rememberMe ? rememberMeManager() : null); + // 缓存管理器; + //securityManager.setCacheManager(getEhCacheManager()); + + return securityManager; + } +} diff --git a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/UserRealm.java b/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/UserRealm.java new file mode 100644 index 000000000..45bef0e2a --- /dev/null +++ b/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/UserRealm.java @@ -0,0 +1,54 @@ +package com.fuint.framework.shiroConfig; + + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.fuint.repository.mapper.TAccountMapper; +import com.fuint.repository.model.TAccount; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.*; +import org.apache.shiro.authz.AuthorizationInfo; +import org.apache.shiro.authz.SimpleAuthorizationInfo; +import org.apache.shiro.realm.AuthorizingRealm; +import org.apache.shiro.subject.PrincipalCollection; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * 描述: + * + * @author caojing + * @create 2020-04-28 + */ +public class UserRealm extends AuthorizingRealm { + @Autowired + TAccountMapper accountMapper; + //doGetAuthorizationInfo: 权限认证,即登录过后,每个身份不一定,对应的所能看的页面也不一样。 + @Override + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { + //添加角色和权限 + + return null; + } + /** + * 这里可以注入userService,为了方便演示,我就写死了帐号了密码 + * private UserService userService; + *

+ * 获取即将需要认证的信息 + */ + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { + System.out.println("-------身份认证方法--------"); + String accountName= (String) authenticationToken.getPrincipal(); + String password = new String((char[]) authenticationToken.getCredentials()); + //根据用户名去数据库查询用户信息 + LambdaQueryWrapper queryWrapper =new LambdaQueryWrapper<>(); + queryWrapper.eq(TAccount::getAccountName,accountName); + TAccount tAccount = accountMapper.selectOne(queryWrapper); + if (tAccount == null) { + throw new AccountException("用户名不正确"); + } else if (!tAccount.getPassword().equals(password )) { + throw new AccountException("密码不正确"); + } + return new SimpleAuthenticationInfo(accountName, password,getName()); + } +} + diff --git a/fuintBackend/fuint-repository/src/main/resources/mapper/TAccountMapper.xml b/fuintBackend/fuint-repository/src/main/resources/mapper/TAccountMapper.xml index f29179945..725b86174 100644 --- a/fuintBackend/fuint-repository/src/main/resources/mapper/TAccountMapper.xml +++ b/fuintBackend/fuint-repository/src/main/resources/mapper/TAccountMapper.xml @@ -14,8 +14,8 @@ AND ta.dept_id = #{accountInfo.deptId} - - AND sd.ancestors like concat (#{ownDeptStr},'%') + + AND sd.ancestors like concat (#{ancestors},'%') order by create_time desc