Commit f48d5628 by whl

调整返回结果数据格式

parent ef3b2855
...@@ -29,7 +29,7 @@ public class GlobalExceptionHandler { ...@@ -29,7 +29,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseBody @ResponseBody
public Object defaultErrorHandler(HttpServletRequest request, Exception e){ public Object defaultErrorHandler(HttpServletRequest request, Exception e){
String url = HttpUtil.getIP(request); String url = request.getRequestURI();
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace()); log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error(); return Result.error();
} }
...@@ -43,7 +43,7 @@ public class GlobalExceptionHandler { ...@@ -43,7 +43,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(ExceptionBase.class) @ExceptionHandler(ExceptionBase.class)
@ResponseBody @ResponseBody
public Object BaseErrorHandler(HttpServletRequest request, Exception e){ public Object BaseErrorHandler(HttpServletRequest request, Exception e){
String url = HttpUtil.getIP(request); String url = request.getRequestURI();
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace()); log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error(); return Result.error();
} }
...@@ -51,7 +51,7 @@ public class GlobalExceptionHandler { ...@@ -51,7 +51,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(DBConfigurationError.class) @ExceptionHandler(DBConfigurationError.class)
@ResponseBody @ResponseBody
public Object DBConfigurationErrorHandler(HttpServletRequest request, Exception e){ public Object DBConfigurationErrorHandler(HttpServletRequest request, Exception e){
String url = HttpUtil.getIP(request); String url = request.getRequestURI();
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace()); log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error(400, e.getMessage()); return Result.error(400, e.getMessage());
} }
...@@ -65,7 +65,7 @@ public class GlobalExceptionHandler { ...@@ -65,7 +65,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(InvalidTokenException.class) @ExceptionHandler(InvalidTokenException.class)
@ResponseBody @ResponseBody
public Object InvalidTokenExceptionHandler(HttpServletRequest request, Exception e){ public Object InvalidTokenExceptionHandler(HttpServletRequest request, Exception e){
String url = HttpUtil.getIP(request); String url = request.getRequestURI();
log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace()); log.error(url + "请求未知异常:" + e.getMessage(), e.getStackTrace());
return Result.error(Result.ErrorCode.INVALID_TOKEN); return Result.error(Result.ErrorCode.INVALID_TOKEN);
} }
......
...@@ -3,6 +3,7 @@ package com.bsoft.api.controller; ...@@ -3,6 +3,7 @@ package com.bsoft.api.controller;
import com.bsoft.api.common.Result; import com.bsoft.api.common.Result;
import com.bsoft.api.common.annotations.Token; import com.bsoft.api.common.annotations.Token;
import com.bsoft.api.model.reqmodel.BlockValues; import com.bsoft.api.model.reqmodel.BlockValues;
import com.bsoft.api.model.respmodel.BlockValue;
import com.bsoft.api.service.BlockValuesService; import com.bsoft.api.service.BlockValuesService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -12,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -12,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import java.util.Map;
@Api(tags = "板块数值Api") @Api(tags = "板块数值Api")
@RestController @RestController
...@@ -32,7 +32,7 @@ public class BlockValuesController { ...@@ -32,7 +32,7 @@ public class BlockValuesController {
@ApiOperation("根据Page查询板块数值") @ApiOperation("根据Page查询板块数值")
public Object getBlockValuesByPageID(@RequestBody BlockValues blockValues) throws InterruptedException { public Object getBlockValuesByPageID(@RequestBody BlockValues blockValues) throws InterruptedException {
List<Map<String,Object>> list= blockValuesService.getBlockValuesByPageCode(blockValues.getPageCode(), List<BlockValue> list= blockValuesService.getBlockValuesByPageCode(blockValues.getPageCode(),
blockValues.getDisease(), blockValues.getDoctor(),blockValues.getDepartment(),blockValues.getTime()); blockValues.getDisease(), blockValues.getDoctor(),blockValues.getDepartment(),blockValues.getTime());
return Result.success(list); return Result.success(list);
} }
......
package com.bsoft.api.model.respmodel;
import java.util.List;
import java.util.Map;
public class BlockValue {
private long blockId;
private List<Map<String,Object>> body;
public BlockValue(){}
public BlockValue(long blockId, List<Map<String, Object>> body) {
this.blockId = blockId;
this.body = body;
}
public long getBlockId() {
return blockId;
}
public void setBlockId(long blockId) {
this.blockId = blockId;
}
public List<Map<String, Object>> getBody() {
return body;
}
public void setBody(List<Map<String, Object>> body) {
this.body = body;
}
}
package com.bsoft.api.service; package com.bsoft.api.service;
import com.bsoft.api.model.respmodel.BlockValue;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
public interface AsynBlockValuesService { public interface AsynBlockValuesService {
void getBlockValues(List<Map<String, Object>> list, String blockId, String tableName, void getBlockValues(List<BlockValue> list, Long blockId, String tableName,
String whereClause, CountDownLatch latch); String whereClause, CountDownLatch latch);
} }
package com.bsoft.api.service; package com.bsoft.api.service;
import com.bsoft.api.model.respmodel.BlockValue;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public interface BlockValuesService { public interface BlockValuesService {
List<Map<String,Object>> getBlockValuesByPageCode(Integer pageId, Integer disease, Integer doctor, Integer department, Integer time) throws InterruptedException; List<BlockValue> getBlockValuesByPageCode(Integer pageId, Integer disease, Integer doctor, Integer department, Integer time) throws InterruptedException;
} }
package com.bsoft.api.service.Impl; package com.bsoft.api.service.Impl;
import com.bsoft.api.mapper.BlockValuesMapper; import com.bsoft.api.mapper.BlockValuesMapper;
import com.bsoft.api.model.respmodel.BlockValue;
import com.bsoft.api.service.AsynBlockValuesService; import com.bsoft.api.service.AsynBlockValuesService;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -21,18 +22,14 @@ public class AsynBlockValuesServiceImpl implements AsynBlockValuesService { ...@@ -21,18 +22,14 @@ public class AsynBlockValuesServiceImpl implements AsynBlockValuesService {
@Async @Async
@Override @Override
public void getBlockValues(List<Map<String, Object>> list, String blockId, String tableName, public void getBlockValues(List<BlockValue> list, Long blockId, String tableName,
String whereClause, CountDownLatch latch) { String whereClause, CountDownLatch latch) {
System.out.println("开始"+tableName); System.out.println("开始"+tableName);
List<Map<String, Object>> dataList = blockValuesMapper.selectByWhere(tableName, whereClause); List<Map<String, Object>> dataList = blockValuesMapper.selectByWhere(tableName, whereClause);
Map<String, Object> map = new HashMap<String,Object>(){ BlockValue blockValue = new BlockValue(blockId, dataList);
{
put(blockId, dataList);
}
};
synchronized (obj){ synchronized (obj){
list.add(map); list.add(blockValue);
} }
System.out.println("结束"+tableName); System.out.println("结束"+tableName);
latch.countDown(); latch.countDown();
......
...@@ -8,6 +8,7 @@ import com.bsoft.api.mapper.SerPageMapper; ...@@ -8,6 +8,7 @@ import com.bsoft.api.mapper.SerPageMapper;
import com.bsoft.api.model.DicDim; import com.bsoft.api.model.DicDim;
import com.bsoft.api.model.SerPage; import com.bsoft.api.model.SerPage;
import com.bsoft.api.model.SerPageBlockRs; import com.bsoft.api.model.SerPageBlockRs;
import com.bsoft.api.model.respmodel.BlockValue;
import com.bsoft.api.service.AsynBlockValuesService; import com.bsoft.api.service.AsynBlockValuesService;
import com.bsoft.api.service.BlockValuesService; import com.bsoft.api.service.BlockValuesService;
import org.apache.ibatis.binding.MapperMethod; import org.apache.ibatis.binding.MapperMethod;
...@@ -37,7 +38,7 @@ public class BlockValuesServiceImpl implements BlockValuesService { ...@@ -37,7 +38,7 @@ public class BlockValuesServiceImpl implements BlockValuesService {
@Override @Override
public List<Map<String, Object>> getBlockValuesByPageCode(Integer pageCode, Integer disease, Integer doctor, Integer department, Integer time) throws InterruptedException { public List<BlockValue> getBlockValuesByPageCode(Integer pageCode, Integer disease, Integer doctor, Integer department, Integer time) throws InterruptedException {
/** /**
* 1.根据pageCode,disease,doctor,department,time查询所有对应的pageId * 1.根据pageCode,disease,doctor,department,time查询所有对应的pageId
* 查询要求为pageCode为当前pageCode,相同pageId的所有数据有且仅有DIM_ID为 * 查询要求为pageCode为当前pageCode,相同pageId的所有数据有且仅有DIM_ID为
...@@ -45,7 +46,7 @@ public class BlockValuesServiceImpl implements BlockValuesService { ...@@ -45,7 +46,7 @@ public class BlockValuesServiceImpl implements BlockValuesService {
* 2.根据pageId获取所有block * 2.根据pageId获取所有block
* 3.根据block拼接表名及where语句 * 3.根据block拼接表名及where语句
*/ */
List<Map<String, Object>> list = new ArrayList<>(); List<BlockValue> list = new ArrayList<>();
int count = 0; int count = 0;
String inField = ""; String inField = "";
...@@ -87,7 +88,7 @@ public class BlockValuesServiceImpl implements BlockValuesService { ...@@ -87,7 +88,7 @@ public class BlockValuesServiceImpl implements BlockValuesService {
CountDownLatch latch = new CountDownLatch(pageBlocklist.size()); CountDownLatch latch = new CountDownLatch(pageBlocklist.size());
for (SerPageBlockRs data : pageBlocklist) { for (SerPageBlockRs data : pageBlocklist) {
//获取表名 //获取表名
String blockId = data.getBlockId().toString(); Long blockId = data.getBlockId();
String tableName = "VAL_BLOCK_VALUES_" + blockId; String tableName = "VAL_BLOCK_VALUES_" + blockId;
asynBlockValuesServiceImpl.getBlockValues(list, blockId, tableName, whereClause, latch); asynBlockValuesServiceImpl.getBlockValues(list, blockId, tableName, whereClause, latch);
......
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