提交 9b8c0450 作者: zgz

sql查询问题处理

上级 60dbcea1
...@@ -16,6 +16,7 @@ import com.zzsn.event.vo.SubjectTypeVo; ...@@ -16,6 +16,7 @@ import com.zzsn.event.vo.SubjectTypeVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
/** /**
...@@ -137,12 +138,15 @@ public class SubjectTypeController { ...@@ -137,12 +138,15 @@ public class SubjectTypeController {
*/ */
@GetMapping("/subjectAndTypeTree") @GetMapping("/subjectAndTypeTree")
public Result<?> subjectAndTypeTree(@RequestParam(required = false) Integer facePublic, public Result<?> subjectAndTypeTree(@RequestParam(required = false) Integer facePublic,
@RequestParam(required = false) String environment) { @RequestParam(required = false) String environment,
@RequestParam(required = false) String flagCode,
HttpServletRequest request) {
UserVo loginUser = UserUtil.getLoginUser();
List<SubjectTreeVO> dataList = null; List<SubjectTreeVO> dataList = null;
if (facePublic == null) { if (facePublic == null) {
dataList = subjectTypeService.subjectAndTypeTree(environment); dataList = subjectTypeService.subjectAndTypeTree(environment);
} else if (facePublic == 1) { } else if (facePublic == 1) {
dataList = subjectTypeService.subjectsByFacePublic(facePublic,environment); dataList = subjectTypeService.subjectsByFacePublic(facePublic,environment,loginUser.getUsername(),flagCode,request);
} }
return Result.OK(dataList); return Result.OK(dataList);
} }
......
...@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
* @author zgz * @author zgz
* @date 2025/2/18 * @date 2025/2/18
*/ */
@FeignClient(name = "data-permit",url = "http://1.95.77.159:10089/permission/") @FeignClient(name = "data-permit",url = "http://1.95.14.24:8060/")
public interface DataPermitClientProd { public interface DataPermitClientProd {
/** /**
* 获取数据权限 * 获取数据权限
......
...@@ -78,7 +78,8 @@ public interface SubjectTypeMapper extends BaseMapper<SubjectType> { ...@@ -78,7 +78,8 @@ public interface SubjectTypeMapper extends BaseMapper<SubjectType> {
* @author lkg * @author lkg
* @date 2025/1/7 * @date 2025/1/7
*/ */
List<SubjectTreeVO> subjectsByFacePublic(@Param("facePublic") Integer facePublic,@Param("environment") String environment); List<SubjectTreeVO> subjectsByFacePublic(@Param("facePublic") Integer facePublic,@Param("environment") String environment,@Param("username") String username
,@Param("sql") String sql);
/** /**
* 可用的事件和分类列表 * 可用的事件和分类列表
......
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
LEFT JOIN subject_type_map b ON b.subject_id = d.id LEFT JOIN subject_type_map b ON b.subject_id = d.id
LEFT JOIN subject_type c ON b.type_id = c.id LEFT JOIN subject_type c ON b.type_id = c.id
where where
((d.face_public = 1 and d.create_by = #{username}) or (d.face_public = 1 and #{sql})) ((d.face_public = 1 and d.create_by = #{username}) or (d.face_public = 1 and ${sql}))
<if test="subjectCondition.environment !=null and subjectCondition.environment !=''"> <if test="subjectCondition.environment !=null and subjectCondition.environment !=''">
and d.environment =#{subjectCondition.environment} and d.environment =#{subjectCondition.environment}
</if> </if>
...@@ -216,7 +216,7 @@ ...@@ -216,7 +216,7 @@
and face_public = 1 and face_public = 1
</when> </when>
<otherwise> <otherwise>
and ((create_by = #{username}) or (face_public = 1 and #{sql})) and ((create_by = #{username}) or (face_public = 1 and ${sql}))
</otherwise> </otherwise>
</choose> </choose>
</select> </select>
......
...@@ -52,7 +52,8 @@ ...@@ -52,7 +52,8 @@
s.time_enable as start_time, s.time_enable as start_time,
s.time_disable as end_time s.time_disable as end_time
from subject s from subject s
where s.face_public = #{facePublic} where
((s.face_public = #{facePublic} and s.create_by = #{username}) or (s.face_public = #{facePublic} and ${sql}))
<if test="environment!=null and environment != ''"> <if test="environment!=null and environment != ''">
and s.environment = #{environment} and s.environment = #{environment}
</if> </if>
......
...@@ -7,6 +7,7 @@ import com.zzsn.event.vo.SubjectTreeVO; ...@@ -7,6 +7,7 @@ import com.zzsn.event.vo.SubjectTreeVO;
import com.zzsn.event.vo.SubjectTypeTreeVO; import com.zzsn.event.vo.SubjectTypeTreeVO;
import com.zzsn.event.vo.SubjectTypeVo; import com.zzsn.event.vo.SubjectTypeVo;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
/** /**
...@@ -79,7 +80,8 @@ public interface ISubjectTypeService extends IService<SubjectType> { ...@@ -79,7 +80,8 @@ public interface ISubjectTypeService extends IService<SubjectType> {
* @author lkg * @author lkg
* @date 2025/1/7 * @date 2025/1/7
*/ */
List<SubjectTreeVO> subjectsByFacePublic(Integer facePublic,String environment); List<SubjectTreeVO> subjectsByFacePublic(Integer facePublic,String environment,String username,String flagCode,
HttpServletRequest request);
/** /**
* 专题和分类列表-研究中心 * 专题和分类列表-研究中心
......
...@@ -6,7 +6,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -6,7 +6,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.SubjectType; import com.zzsn.event.entity.SubjectType;
import com.zzsn.event.mapper.SubjectTypeMapper; import com.zzsn.event.mapper.SubjectTypeMapper;
import com.zzsn.event.permit.ParamAop;
import com.zzsn.event.permit.UQueryEntity;
import com.zzsn.event.service.ISubjectTypeService; import com.zzsn.event.service.ISubjectTypeService;
import com.zzsn.event.util.TokenUtil;
import com.zzsn.event.util.tree.Node; import com.zzsn.event.util.tree.Node;
import com.zzsn.event.util.tree.TreeUtil; import com.zzsn.event.util.tree.TreeUtil;
import com.zzsn.event.util.user.UserUtil; import com.zzsn.event.util.user.UserUtil;
...@@ -14,12 +17,15 @@ import com.zzsn.event.vo.SubjectPage; ...@@ -14,12 +17,15 @@ import com.zzsn.event.vo.SubjectPage;
import com.zzsn.event.vo.SubjectTreeVO; import com.zzsn.event.vo.SubjectTreeVO;
import com.zzsn.event.vo.SubjectTypeTreeVO; import com.zzsn.event.vo.SubjectTypeTreeVO;
import com.zzsn.event.vo.SubjectTypeVo; import com.zzsn.event.vo.SubjectTypeVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -29,6 +35,7 @@ import java.util.stream.Collectors; ...@@ -29,6 +35,7 @@ import java.util.stream.Collectors;
* @author lkg * @author lkg
* @date 2024/4/28 * @date 2024/4/28
*/ */
@Slf4j
@Service @Service
public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, SubjectType> implements ISubjectTypeService { public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, SubjectType> implements ISubjectTypeService {
...@@ -41,6 +48,8 @@ public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, Subje ...@@ -41,6 +48,8 @@ public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, Subje
public List<Node> researchCenterEnableList(String username) { public List<Node> researchCenterEnableList(String username) {
return baseMapper.enableList(1, username); return baseMapper.enableList(1, username);
} }
@Autowired
private ParamAop paramAop;
@Override @Override
public List<String> belowIdList(String typeId,Integer category) { public List<String> belowIdList(String typeId,Integer category) {
...@@ -95,8 +104,27 @@ public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, Subje ...@@ -95,8 +104,27 @@ public class SubjectTypeServiceImpl extends ServiceImpl<SubjectTypeMapper, Subje
} }
@Override @Override
public List<SubjectTreeVO> subjectsByFacePublic(Integer facePublic,String environment) { public List<SubjectTreeVO> subjectsByFacePublic(Integer facePublic,String environment,String username,String flagCode,
return baseMapper.subjectsByFacePublic(facePublic,environment); HttpServletRequest request) {
String sql = "";
if(StringUtils.isNotBlank(flagCode)){
String accesstoken = request.getHeader("Accesstoken");
String userId = TokenUtil.verifyToken(accesstoken);
UQueryEntity queryEntity = new UQueryEntity();
queryEntity.setUserId(userId);
queryEntity.setFlagCode(flagCode);
queryEntity = paramAop.startArs(queryEntity,accesstoken,environment);
String sqlStr = queryEntity.getSql();
if(sqlStr.contains("()")){
sqlStr = sqlStr.replace("()","(1=2)");
}
sql = sqlStr;
log.info("subjectsByFacePublic sql:{}",sql);
}
log.info("subjectsByFacePublic username:{},facePublic:{},environment:{},sql:{}",username,facePublic,environment,sql);
List<SubjectTreeVO> list = baseMapper.subjectsByFacePublic(facePublic,environment,username,sql);
log.info("subjectsByFacePublic=======list.size:{}",list.size());
return list;
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论