huanghongfa
2021-05-07 45c8d2b8893397092e495e8a3f92b95e10c69961
Merge remote-tracking branch 'origin/test' into test
1个文件已修改
1个文件已添加
78 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActMessageDAO.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/filter/StoreValidFilter.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComActMessageDAO.java
@@ -31,8 +31,9 @@
    
    @Select("<script>" +
            "select * from com_act_message " +
            " where (sendto_user_id in (select id from com_pb_member_role t1 where t1.phone=#{comActMessageVO.phone})) " +
            " or (sendto_user_id in (select id from com_pb_service_team t2 where t2.phone=#{comActMessageVO.phone}))" +
            " where " +
            " ((sendto_user_id in (select id from com_pb_member_role t1 where t1.phone=#{comActMessageVO.phone})) " +
            " or (sendto_user_id in (select id from com_pb_service_team t2 where t2.phone=#{comActMessageVO.phone})))" +
            "<if test='comActMessageVO.status != null'>" +
            " and status=#{comActMessageVO.status} \n" +
            " </if> " +
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/filter/StoreValidFilter.java
New file
@@ -0,0 +1,73 @@
package com.panzhihua.shop_backstage.filter;
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.common.constants.Constants;
import com.panzhihua.common.constants.TokenConstant;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.shop.ShopStoreVO;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.utlis.AES;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
 * @ClasssName StoreValidFilter
 * @Description 商铺有效性过滤
 * @Author cedoo
 * @Date 2021/5/7
 * @Version 1.0
 **/
@Slf4j
@Component
public class StoreValidFilter implements Filter {
    @Resource
    private CommunityService communityService;
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String uri = request.getRequestURI();
        if(!"/login".equals(uri)) {
            String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO);
            boolean empty = ObjectUtils.isEmpty(userInfo);
            if (empty) {
                log.error("获取登录用户信息失败【{}】", request);
                return;
            }
            byte[] bytes = AES.parseHexStr2Byte(userInfo);
            byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY);
            userInfo = new String(decrypt);
            LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(userInfo, LoginUserInfoVO.class);
            R r = communityService.getUserStoreInfo(loginUserInfoVO.getUserId());
            boolean shopStoreValid = false;
            if (R.isOk(r) && r.getData() != null) {
                ShopStoreVO shopStoreVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), ShopStoreVO.class);
                shopStoreValid = shopStoreVO.getStatus() == 1;
            }
            if (!shopStoreValid) {
                //返回请求被拒绝响应
                response.setContentType("application/json");
                response.setCharacterEncoding("UTF-8");
                response.getWriter().write(JSONObject.toJSONString(R.fail(403)));
                response.flushBuffer();
                return;
            }
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
}