Commit ef3b2855 by whl

修改数据接口逻辑,部分已使用拦截器拦截的接口去除Token注解防止重复校验token,异步查询数据接口

parent b4a2604d
......@@ -80,6 +80,10 @@
相当于compile,但是打包阶段做了exclude操作-->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -4,7 +4,9 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync
@SpringBootApplication
@MapperScan("com.bsoft.api.mapper")
@ComponentScan(basePackages = {"com.bsoft.common.config","com.bsoft.api"})
......
package com.bsoft.api.common;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 请求统一返回结果
*/
@ApiModel(description = "接口结果")
public class Result<T> {
@ApiModelProperty("code")
@ApiModelProperty("错误编码")
private int code;
@ApiModelProperty("错误信息")
private String msg;
@ApiModelProperty("返回的数据")
@ApiModelProperty(value = "返回的数据")
private T data;
private Result(int code, String msg, T data) {
......@@ -52,7 +54,7 @@ public class Result<T> {
this.data = data;
}
public static Result success(Object data){
public static <T> Result<T> success(T data){
return new Result(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getEnMessage(), data);
}
......
package com.bsoft.api.common.exceptions;
public class DBConfigurationError extends ExceptionBase {
public DBConfigurationError(String message){
super(message);
}
}
package com.bsoft.api.common.handlers;
import com.bsoft.api.common.Result;
import com.bsoft.api.common.exceptions.DBConfigurationError;
import com.bsoft.api.common.exceptions.ExceptionBase;
import com.bsoft.api.common.exceptions.InvalidTokenException;
import com.bsoft.common.utils.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
......@@ -25,9 +29,44 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseBody
public Object defaultErrorHandler(HttpServletRequest request, Exception e){
log.error("未知异常:" + e.getMessage(), e.getStackTrace());
String url = HttpUtil.getIP(request);
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error();
}
/**
* 其他内部异常
* @param request
* @param e
* @return
*/
@ExceptionHandler(ExceptionBase.class)
@ResponseBody
public Object BaseErrorHandler(HttpServletRequest request, Exception e){
String url = HttpUtil.getIP(request);
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error();
}
@ExceptionHandler(DBConfigurationError.class)
@ResponseBody
public Object DBConfigurationErrorHandler(HttpServletRequest request, Exception e){
String url = HttpUtil.getIP(request);
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error(400, e.getMessage());
}
/**
* 无效token
* @param request
* @param e
* @return
*/
@ExceptionHandler(InvalidTokenException.class)
@ResponseBody
public Object InvalidTokenExceptionHandler(HttpServletRequest request, Exception e){
String url = HttpUtil.getIP(request);
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error(Result.ErrorCode.INVALID_TOKEN);
}
}
......@@ -2,19 +2,14 @@ package com.bsoft.api.controller;
import com.bsoft.api.common.Result;
import com.bsoft.api.common.annotations.Token;
import com.bsoft.api.common.base.RequestResult;
import com.bsoft.api.mapper.BlockValuesMapper;
import com.bsoft.api.model.requmodel.BlockValues;
import com.bsoft.api.model.reqmodel.BlockValues;
import com.bsoft.api.service.BlockValuesService;
import com.bsoft.api.service.Impl.BlockValuesServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;
......@@ -35,10 +30,10 @@ public class BlockValuesController {
@GetMapping("blockValues")
@Token
@ApiOperation("根据Page查询板块数值")
public Object getBlockValuesByPageID(@RequestBody BlockValues blockValues){
public Object getBlockValuesByPageID(@RequestBody BlockValues blockValues) throws InterruptedException {
List<Map<String,Object>> list= blockValuesService.getBlockValuesByPageID(blockValues.getPageId(),blockValues.getDisease(),
blockValues.getDoctor(),blockValues.getDepartment(),blockValues.getTime());
List<Map<String,Object>> list= blockValuesService.getBlockValuesByPageCode(blockValues.getPageCode(),
blockValues.getDisease(), blockValues.getDoctor(),blockValues.getDepartment(),blockValues.getTime());
return Result.success(list);
}
}
\ No newline at end of file
......@@ -19,8 +19,14 @@ public class LoginController {
@Autowired
private LoginService loginServiceImpl;
/**
*
* @param codeAndPwd
* @param request
* @return
*/
@PostMapping("login")
@ApiOperation("登录")
@ApiOperation(value="Result«LoginService.LoginInfo»登录")
public Result<LoginService.LoginInfo> login(@RequestBody CodeAndPwd codeAndPwd,HttpServletRequest request){
String ip = HttpUtil.getIP(request);
LoginService.LoginInfo loginInfo = loginServiceImpl.login(
......
......@@ -39,7 +39,7 @@ public class UserController {
* @return
*/
@GetMapping("roles")
@Token
// @Token
@ApiOperation("查询用户角色")
public Object getRoleListByUser(@ApiIgnore@CurrentUser Long userId)throws Exception{
return Result.success(sysUserRoleRsService.getRoleListByUser(userId));
......@@ -51,7 +51,7 @@ public class UserController {
* @return
*/
@GetMapping("menus")
@Token
// @Token
@ApiOperation("查询用户菜单")
public Object getMenuByUser(@ApiIgnore@CurrentUser Long userId)throws Exception{
return Result.success(sysMenuService.getMenu(userId));
......
......@@ -16,5 +16,5 @@ public interface SerPageBlockRsMapper {
int updateByPrimaryKey(SerPageBlockRs record);
List<SerPageBlockRs> selectByPageId(Integer pageID);
List<SerPageBlockRs> selectByPageId(Long pageID);
}
\ No newline at end of file
package com.bsoft.api.mapper;
import com.bsoft.api.model.SerPage;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SerPageMapper {
......@@ -13,4 +15,6 @@ public interface SerPageMapper {
List<SerPage> selectAll();
int updateByPrimaryKey(SerPage record);
List<SerPage> selectByCodeAndDim(@Param("pageCode") Integer pageCode, @Param("inField") String inField, @Param("dimCount") int dimCount);
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
@ApiModel("用户信息")
@ApiModel(description = "用户信息")
public class SysUser {
/**
*
......
package com.bsoft.api.model.requmodel;
package com.bsoft.api.model.reqmodel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
@ApiModel("调用blockValues请求的数据")
@ApiModel(description = "调用blockValues请求的数据")
public class BlockValues {
public Integer getPageId() {
return pageId;
public Integer getPageCode() {
return pageCode;
}
public void setPageId(Integer pageId) {
this.pageId = pageId;
public void setPageCode(Integer pageCode) {
this.pageCode = pageCode;
}
public Integer getDisease() {
......@@ -49,10 +47,8 @@ public class BlockValues {
this.time = time;
}
@ApiModelProperty(value = "pageID",required = true)
private Integer pageId;
@ApiModelProperty(value = "pageCode",required = true)
private Integer pageCode;
@ApiModelProperty("病组")
private Integer disease;
@ApiModelProperty("科室")
......
package com.bsoft.api.service;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
public interface AsynBlockValuesService {
void getBlockValues(List<Map<String, Object>> list, String blockId, String tableName,
String whereClause, CountDownLatch latch);
}
......@@ -4,5 +4,5 @@ import java.util.List;
import java.util.Map;
public interface BlockValuesService {
List<Map<String,Object>> getBlockValuesByPageID(Integer pageId, Integer disease, Integer doctor, Integer department, Integer time);
List<Map<String,Object>> getBlockValuesByPageCode(Integer pageId, Integer disease, Integer doctor, Integer department, Integer time) throws InterruptedException;
}
package com.bsoft.api.service.Impl;
import com.bsoft.api.mapper.BlockValuesMapper;
import com.bsoft.api.service.AsynBlockValuesService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
@Service
public class AsynBlockValuesServiceImpl implements AsynBlockValuesService {
private final static Object obj = new Object();
@Resource
private BlockValuesMapper blockValuesMapper;
@Async
@Override
public void getBlockValues(List<Map<String, Object>> list, String blockId, String tableName,
String whereClause, CountDownLatch latch) {
System.out.println("开始"+tableName);
List<Map<String, Object>> dataList = blockValuesMapper.selectByWhere(tableName, whereClause);
Map<String, Object> map = new HashMap<String,Object>(){
{
put(blockId, dataList);
}
};
synchronized (obj){
list.add(map);
}
System.out.println("结束"+tableName);
latch.countDown();
}
}
package com.bsoft.api.service.Impl;
import com.bsoft.api.common.exceptions.DBConfigurationError;
import com.bsoft.api.mapper.BlockValuesMapper;
import com.bsoft.api.mapper.DicDimMapper;
import com.bsoft.api.mapper.SerPageBlockRsMapper;
import com.bsoft.api.mapper.SerPageMapper;
import com.bsoft.api.model.DicDim;
import com.bsoft.api.model.SerPage;
import com.bsoft.api.model.SerPageBlockRs;
import com.bsoft.api.service.AsynBlockValuesService;
import com.bsoft.api.service.BlockValuesService;
import org.apache.ibatis.binding.MapperMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -15,72 +21,79 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@Service
public class BlockValuesServiceImpl implements BlockValuesService {
@Resource
private SerPageBlockRsMapper serPageBlockRsMapper;
@Resource
private DicDimMapper dicDimMapper;
private SerPageMapper serPageMapper;
@Resource
private BlockValuesMapper blockValuesMapper;
private AsynBlockValuesService asynBlockValuesServiceImpl;
@Override
public List<Map<String,Object>> getBlockValuesByPageID(Integer pageId,Integer disease,Integer doctor,Integer department,Integer time){
Boolean isDisease = false;
Boolean isDoctor = false;
Boolean isDepartment = false;
Boolean isTime = false;
List<Map<String,Object>> list = new ArrayList<>();
//根据pageId查询所有板块
List<SerPageBlockRs> pageBlocklist =serPageBlockRsMapper.selectByPageId(pageId);
//根据pageId查询所有维度
List<DicDim> dimList = dicDimMapper.selectByPageid(pageId);
//循环获取需要添加的维度查询条件
for (DicDim data : dimList) {
if(data.getDimField().equalsIgnoreCase("disease")){
isDisease=true;
}
if(data.getDimField().equalsIgnoreCase("doctor")){
isDoctor=true;
}
if(data.getDimField().equalsIgnoreCase("department")){
isDepartment=true;
}
if(data.getDimField().equalsIgnoreCase("time")){
isTime=true;
}
}
//循环获取数据
for (SerPageBlockRs data : pageBlocklist) {
//获取表名
String tableName = "VAL_BLOCK_VALUES_"+data.getBlockId();
@Override
public List<Map<String, Object>> getBlockValuesByPageCode(Integer pageCode, Integer disease, Integer doctor, Integer department, Integer time) throws InterruptedException {
/**
* 1.根据pageCode,disease,doctor,department,time查询所有对应的pageId
* 查询要求为pageCode为当前pageCode,相同pageId的所有数据有且仅有DIM_ID为
* disease,doctor,department,time中不为null的对应id
* 2.根据pageId获取所有block
* 3.根据block拼接表名及where语句
*/
List<Map<String, Object>> list = new ArrayList<>();
String whereSql = "where 1=1";
int count = 0;
String inField = "";
String whereClause = "where 1=1";
if(disease != null){
whereClause += String.format(" and disease='%s'", disease);
inField += "'disease',";
count++;
}
if (doctor != null) {
whereClause += String.format(" and doctor='%s'", doctor);
inField += "'doctor',";
count++;
}
if (department != null) {
whereClause += String.format(" and department='%s'", department);
inField += "'department',";
count++;
}
if (time != null) {
whereClause += String.format(" and time='%s'", time);
inField += "'time',";
count++;
}
if(count > 0){
inField = inField.substring(0, inField.length()-1);
}
//添加查询条件
if(disease!=null&&isDisease){
whereSql+=String.format(" and disease='%s'",disease);
}
if(doctor!=null&&isDoctor){
whereSql+=String.format(" and doctor='%s'",doctor);
}
if(department!=null&&isDepartment){
whereSql+=String.format(" and department='%s'",department);
}
if(time!=null&&isTime){
whereSql+=String.format(" and time='%s'",time);
}
List<Map<String,Object>> dataList =blockValuesMapper.selectByWhere(tableName,whereSql);
list.add(new HashMap<String,Object>(){
{
put(data.getBlockId().toString(),dataList);
}
});
}
return list;
List<SerPage> pageList = serPageMapper.selectByCodeAndDim(pageCode, inField, count);
if(pageList.size() == 0){
throw new DBConfigurationError("页面维度配置表错误,请联系管理员");
}
SerPage page = pageList.get(0);
//根据pageId查询所有板块
List<SerPageBlockRs> pageBlocklist = serPageBlockRsMapper.selectByPageId(page.getId());
//循环获取数据
CountDownLatch latch = new CountDownLatch(pageBlocklist.size());
for (SerPageBlockRs data : pageBlocklist) {
//获取表名
String blockId = data.getBlockId().toString();
String tableName = "VAL_BLOCK_VALUES_" + blockId;
asynBlockValuesServiceImpl.getBlockValues(list, blockId, tableName, whereClause, latch);
}
latch.await();
return list;
}
}
......@@ -11,7 +11,7 @@ public interface LoginService {
String refreshToken(String oldToken);
@ApiModel("登录信息")
@ApiModel(description = "登录信息")
class LoginInfo {
@ApiModelProperty("token")
private String token;
......
......@@ -8,4 +8,9 @@ mybatis.type-aliases-package=com.bsoft.api.model
config.path.include[0]=/token
config.path.include[1]=/user/**
config.path.exclude[0]=/login
\ No newline at end of file
config.path.exclude[0]=/login
# Add @EnableAspectJAutoProxy.
spring.aop.auto=true
# Whether subclass-based (CGLIB) proxies are to be created (true)
spring.aop.proxy-target-class=false
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsoft.api.mapper.SerPageMapper">
<resultMap id="BaseResultMap" type="com.bsoft.api.model.SerPage">
<id column="ID" jdbcType="DECIMAL" property="id" />
<result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate" />
<result column="CREATE_USERID" jdbcType="DECIMAL" property="createUserid" />
<result column="STATE" jdbcType="DECIMAL" property="state" />
<result column="PAGE_CODE" jdbcType="VARCHAR" property="pageCode" />
<result column="PAGE_NAME" jdbcType="VARCHAR" property="pageName" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
<resultMap id="BaseResultMap" type="com.bsoft.api.model.SerPage">
<id column="ID" jdbcType="DECIMAL" property="id"/>
<result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate"/>
<result column="CREATE_USERID" jdbcType="DECIMAL" property="createUserid"/>
<result column="STATE" jdbcType="DECIMAL" property="state"/>
<result column="PAGE_CODE" jdbcType="VARCHAR" property="pageCode"/>
<result column="PAGE_NAME" jdbcType="VARCHAR" property="pageName"/>
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from LL.SER_PAGE
where ID = #{id,jdbcType=DECIMAL}
</delete>
<insert id="insert" parameterType="com.bsoft.api.model.SerPage">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
select SEQ_SER_PAGE_ID.nextval from dual
</selectKey>
insert into LL.SER_PAGE (CREATE_DATE, CREATE_USERID, STATE,
PAGE_CODE, PAGE_NAME)
values (#{createDate,jdbcType=TIMESTAMP}, #{createUserid,jdbcType=DECIMAL}, #{state,jdbcType=DECIMAL},
#{pageCode,jdbcType=VARCHAR}, #{pageName,jdbcType=VARCHAR})
</insert>
<update id="updateByPrimaryKey" parameterType="com.bsoft.api.model.SerPage">
update LL.SER_PAGE
set CREATE_DATE = #{createDate,jdbcType=TIMESTAMP},
CREATE_USERID = #{createUserid,jdbcType=DECIMAL},
STATE = #{state,jdbcType=DECIMAL},
PAGE_CODE = #{pageCode,jdbcType=VARCHAR},
PAGE_NAME = #{pageName,jdbcType=VARCHAR}
where ID = #{id,jdbcType=DECIMAL}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select ID, CREATE_DATE, CREATE_USERID, STATE, PAGE_CODE, PAGE_NAME
from LL.SER_PAGE
where ID = #{id,jdbcType=DECIMAL}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select ID, CREATE_DATE, CREATE_USERID, STATE, PAGE_CODE, PAGE_NAME
from LL.SER_PAGE
</select>
</delete>
<insert id="insert" parameterType="com.bsoft.api.model.SerPage">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
select SEQ_SER_PAGE_ID.nextval from dual
</selectKey>
insert into LL.SER_PAGE (CREATE_DATE, CREATE_USERID, STATE,
PAGE_CODE, PAGE_NAME)
values (#{createDate,jdbcType=TIMESTAMP}, #{createUserid,jdbcType=DECIMAL}, #{state,jdbcType=DECIMAL},
#{pageCode,jdbcType=VARCHAR}, #{pageName,jdbcType=VARCHAR})
</insert>
<update id="updateByPrimaryKey" parameterType="com.bsoft.api.model.SerPage">
update LL.SER_PAGE
set CREATE_DATE = #{createDate,jdbcType=TIMESTAMP},
CREATE_USERID = #{createUserid,jdbcType=DECIMAL},
STATE = #{state,jdbcType=DECIMAL},
PAGE_CODE = #{pageCode,jdbcType=VARCHAR},
PAGE_NAME = #{pageName,jdbcType=VARCHAR}
where ID = #{id,jdbcType=DECIMAL}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select ID, CREATE_DATE, CREATE_USERID, STATE, PAGE_CODE, PAGE_NAME
from LL.SER_PAGE
where ID = #{id,jdbcType=DECIMAL}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select ID, CREATE_DATE, CREATE_USERID, STATE, PAGE_CODE, PAGE_NAME
from LL.SER_PAGE
</select>
<select id="selectByCodeAndDim" resultMap="BaseResultMap">
select d.* from SER_PAGE d,
<if test="dimCount != 0">
(select a.id,COUNT(b.ID) count
from SER_PAGE a
LEFT JOIN ser_page_dim_rs b on a.id = b.PAGE_ID and b.state = 1
LEFT JOIN DIC_DIM c on c.ID = b.DIM_ID
where a.state =1 and a.PAGE_CODE = #{pageCode,jdbcType=VARCHAR}
and c.DIM_FIELD in (${inField})
GROUP BY a.ID) e,
</if>
(select a.id,COUNT(b.ID) count
from SER_PAGE a
LEFT JOIN ser_page_dim_rs b on a.id = b.PAGE_ID and b.state = 1
LEFT JOIN DIC_DIM c on c.ID = b.DIM_ID
where a.state =1 and a.PAGE_CODE = #{pageCode,jdbcType=VARCHAR}
GROUP BY a.ID) f
where d.id = f.id
<if test="dimCount != 0">
and f.count = e.count
and d.Id = e.id
</if>
and f.count =#{dimCount,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment