Commit cda33f76 authored by 曹盼盼's avatar 曹盼盼

修改设备列表接口性能慢

parent eb653700
......@@ -87,11 +87,12 @@ public class ControllerAop {
,"/tzs/flc-unit-info/region/tree"
// ,"/tzs/reg-unit-info/management-unit/tree",
//"/tzs/reg-unit-info/unit-type/list"
//+ ",/tzs/reg-unit-info/management-unit/tree","/tzs/flc-unit-info/region/tree", "/tzs/reg-unit-info/unit-type/list"
+ "/tzs/reg-unit-info/management-unit/tree","/tzs/flc-unit-info/region/tree", "/tzs/reg-unit-info/unit-type/list"
,"/tzs/reg-unit-info/"+"^[A-Za-z0-9]+$"+"/check","/tzs/flc-unit-info/hasExistPhone","/tzs/flc-unit-info/sendTelCode"
};
if (request.getRequestURI().contains("/tzs/reg-unit-info") || request.getRequestURI().contains("/tzs/flc-unit-info")) {
return;
}
// if (request.getRequestURI().contains("/tzs/reg-unit-info") || request.getRequestURI().contains("/tzs/flc-unit-info")) {
// return;
// }
// 获取请求路径
for (String uri : url) {
if (request.getRequestURI().indexOf(uri) != -1) {
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.module.tzs.api.common.MobileLoginParam;
......@@ -207,5 +208,13 @@ public class TzsAppController {
return ResponseHelper.buildResponse(appService.equipmentCount(unitCode));
}
//设备列表
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "设备列表", notes = "设备列表")
@GetMapping(value = "/getTable")
public ResponseModel<Page<Map<String,Object>>> getTable(@RequestParam Map<String,Object> map) {
return ResponseHelper.buildResponse(appService.getTable(map));
}
}
......@@ -28,7 +28,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
......@@ -55,6 +57,9 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
private Resource equipCategory;
@Autowired
private JdbcTemplate bizJdbcTemplate;
@Autowired
CategoryOtherInfoMapper categoryOtherInfoMapper;
@Autowired
......@@ -65,6 +70,9 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
@Autowired
IdxFeignService idxFeignService;
@Autowired
private static final String TABLENAME="tableName";
@Value("${regulator.unit.code}")
private String code;
......@@ -529,7 +537,10 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
public List<JSONObject> getCompanyType() {
ResponseModel<AgencyUserModel> me = privilegeFeginService.getMe();
List<CompanyModel> companys = me.getResult().getCompanys();
ReginParams reginParams = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
List<CompanyModel> companys = reginParams.getUserModel().getCompanys();
List<JSONObject> objectList = new ArrayList<>();
for (CompanyModel company : companys) {
JSONObject object = new JSONObject();
......@@ -554,6 +565,57 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
return result;
}
/**
* 分页查询数据
*/
public Page<Map<String, Object>> getPage(Map<String, Object> map) {
String tableName = map.get(TABLENAME).toString();
Object sort = map.get("sort");
Integer number = ValidationUtil.isEmpty(map.get("number")) ? 0 : Integer.valueOf(map.get("number").toString());
Integer size = ValidationUtil.isEmpty(map.get("size")) ? 0 : Integer.valueOf(map.get("size").toString());
Page<Map<String, Object>> page = new Page<>(number, size);
Assert.hasText(tableName, "表名不能为空");
String selectSql = "SELECT * FROM " + tableName;
String countSql = " SELECT COUNT(*) count FROM " + tableName;
StringJoiner andJoiner = new StringJoiner(" AND ");
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (!(entry.getKey().equals("tableName") || entry.getKey().equals("number") || entry.getKey().equals("size") || entry.getKey().equals("sort")) && !ValidationUtil.isEmpty(entry.getValue())) {
if (!ValidationUtil.isEmpty(entry.getValue()) && entry.getValue().toString().contains("[") && entry.getValue().toString().contains("]")) {
String jsonValue = entry.getValue().toString().replace("[", "[\"").replace("]", "\"]").replaceAll(" ", "").replaceAll(",", "\",\"");
StringJoiner orJoiner = new StringJoiner(" or ");
// 兼容数据库存储String和list格式
JSON.parseArray(jsonValue).stream().forEach(x -> {
orJoiner.add(entry.getKey() + " like '%" + x + "%'");
});
andJoiner.add("(" + orJoiner + ")");
} else {
andJoiner.add(entry.getKey() + " like '%" + entry.getValue().toString() + "%'");
}
}
}
if (!ValidationUtil.isEmpty(andJoiner.toString())) {
selectSql = selectSql + " WHERE " + andJoiner;
countSql = countSql + " WHERE " + andJoiner;
}
if (!ValidationUtil.isEmpty(sort)) {
String[] split = sort.toString().split(",");
selectSql = selectSql + " ORDER BY " + split[0] + (split[1].equals("descend") ? " DESC " : " ASC ");
}
int begin = (number - 1) * size;
if (size > 0) {
selectSql += " LIMIT " + begin + "," + size;
}
Long count = bizJdbcTemplate.queryForObject(countSql, Long.class);
String finalSelectSql = selectSql;
List<Map<String, Object>> mapList = bizJdbcTemplate.queryForList(finalSelectSql);
page.setTotal(count);
page.setRecords(mapList);
return page;
}
/**
* levlel=company,是企业,如果不是都是监管单位,
......@@ -578,21 +640,21 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
String code = object.getString("orgCode");
String companyCode = object.getString("companyCode");
if (!ValidationUtil.isEmpty(level)) {
ResponseModel<Page<Map<String, Object>>> m = new ResponseModel<>();
Page<Map<String, Object>> m = new Page<>();
if (LEVEL.equals(level)) {
//企业
map.put("USE_UNIT_CREDIT_CODE", companyCode);
m = idxFeignService.getPage(map);
m = this.getPage(map);
map.remove("USE_UNIT_CREDIT_CODE");
} else {
//监管单位
map.put("ORG_BRANCH_CODE", code);
m = idxFeignService.getPage(map);
m = this.getPage(map);
map.remove("ORG_BRANCH_CODE");
}
total += m.getResult().getTotal();
if (!ValidationUtil.isEmpty(m) && !ValidationUtil.isEmpty(m.getResult()) && !ValidationUtil.isEmpty(m.getResult().getRecords())) {
res.addAll(m.getResult().getRecords());
total += m.getTotal();
if (!ValidationUtil.isEmpty(m) && !ValidationUtil.isEmpty(m.getRecords())) {
res.addAll(m.getRecords());
}
}
}
......@@ -618,7 +680,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
return mapPage;
}
private static final String TABLENAME = "tableName";
public List<Map<String, Object>> scalp(Map<String, Object> map) {
List<Map<String, Object>> list = new ArrayList<>();
......
......@@ -71,9 +71,14 @@ public class TzsAppService {
DesignInfoService designInfoService;
@Autowired
IdxFeignService idxFeignService;
@Autowired
EquipmentCategoryMapper equipmentCategoryMapper;
@Autowired
EquipmentCategoryServiceImpl equipmentCategoryServiceImpl;
@Autowired
ProduceInfoService produceInfoService;
@Autowired
......@@ -127,11 +132,6 @@ public class TzsAppService {
@Autowired
OtherInfoService otherInfoService;
@Autowired
IdxFeignService idxFeignService;
@Autowired
EquipmentCategoryServiceImpl equipmentCategoryServiceImpl;
@Autowired
CategoryOtherInfoMapper categoryOtherInfoMapper;
......@@ -513,4 +513,16 @@ public class TzsAppService {
page.setRecords(list);
return page;
}
public Page<Map<String,Object>> getTable(Map<String, Object> map) {
Page<Map<String, Object>> table=null;
String teqy = (String)map.get("teqy");
if (ValidationUtil.isEmpty(teqy) ) {
table = equipmentCategoryServiceImpl.getTable(map);
}else {
map.remove("teqy");
table = idxFeignService.getPage(map).getResult();
}
return table;
}
}
......@@ -294,7 +294,7 @@
<repository>
<id>Releases</id>
<name>Releases</name>
<url>http://36.46.149.14:8081/nexus/content/repositories/releases/</url>
<url>http://113.142.68.105:8081/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>com.e-iceblue</id>
......@@ -305,13 +305,13 @@
<repository>
<id>Snapshots</id>
<name>Snapshots</name>
<url>http://36.46.149.14:8081/nexus/content/repositories/snapshots/</url>
<url>http://113.142.68.105:8081/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>thirdparty</id>
<name>thirdparty</name>
<url>http://36.46.149.14:8081/nexus/content/repositories/thirdparty/</url>
<url>http://113.142.68.105:8081/nexus/content/repositories/thirdparty/</url>
</repository>
</repositories>
......
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