Commit f48d5628 by whl

调整返回结果数据格式

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