万能查询业务分离

This commit is contained in:
20932067@zju.edu.cn 2021-02-22 20:59:14 +08:00
parent a254eafa8d
commit b51c75efdc
29 changed files with 749 additions and 207 deletions

View File

@ -0,0 +1,25 @@
import request from "@/utils/request";
// 获取查询基本信息
export function RealInfo(id){
return request({
url: "/data/real/"+id,
method: 'get',
})
}
// 查询数据
export function RealData(data){
return request({
url: "/data/real",
method: 'put',
data:data
})
}
// 查询数据
export function exportReal(data){
return request({
url: "/data/real/export",
method: 'put',
data:data
})
}

View File

@ -77,7 +77,7 @@
</template>
<script>
import {RealInfo, RealData,exportReal} from "@/api/tool/query"
import {RealInfo, RealData,exportReal} from "@/api/system/data"
function listInit(list) {
for (let i = 0; i < list.length; i++) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>hchyun</artifactId>
<groupId>com.hchyun</groupId>
<version>3.2.0</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

View File

@ -0,0 +1,100 @@
package com.hchyun.web.controller.system;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.core.controller.BaseController;
import com.hchyun.common.core.entity.AjaxResult;
import com.hchyun.common.utils.ServerResult;
import com.hchyun.generator.util.MapExcelUtil;
import com.hchyun.system.entity.RealUniQuery;
import com.hchyun.system.service.RealQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* @Author 18209
* @Date 2021/2/22 18:02
* @Version 1.0
*/
@RestController
@RequestMapping("/data")
public class RealQueryController extends BaseController {
private Logger logger = LoggerFactory.getLogger(RealQueryController.class);
@Autowired
private RealQueryService realQueryService;
/**
* 用户导出
* @param realUniQuery
* @return
*/
@PreAuthorize("@hchyun.hasAnyPermi('data:real:export')")
@PutMapping("/real/export")
public AjaxResult exportReal(@Validated @RequestBody RealUniQuery realUniQuery) {
try {
ServerResult<List<Map<String, Object>>> serverResult = realQueryService.RealData(realUniQuery, 1);
if (serverResult.isStart()) {
return new MapExcelUtil().exportExcel(serverResult.getData(), serverResult.getSheetName());
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
/**
* 获取查询基本信息
* @param id
* @return
*/
@PreAuthorize("@hchyun.hasPermi('data:real:data')")
@GetMapping("/real/{id}")
public AjaxResult RealInfo(@PathVariable("id") Long id) {
try {
if (id == null) {
return AjaxResult.error("id不能为空!");
}
ServerResult<List<RealUniQuery>> serverResult = realQueryService.RealInfo(id);
if (serverResult.isStart()) {
return AjaxResult.success(serverResult.getData());
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
/**
* 获取查询数据
* @param realUniQuery
* @return
*/
@PreAuthorize("@hchyun.hasAnyPermi('data:real:list')")
@PutMapping("/real")
public Serializable RealData(@Validated @RequestBody RealUniQuery realUniQuery) {
try {
ServerResult<List<Map<String, Object>>> serverResult = realQueryService.RealData(realUniQuery, 2);
if (serverResult.isStart()) {
return getDataTable(serverResult.getData());
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
}

View File

@ -3,7 +3,7 @@ hchyun:
# 名称
name: HchYun
# 版本
version: 3.2.0
version: 1.0.0
# 版权年份
copyrightYear: 2020
# 实例演示开关

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>hchyun</artifactId>
<groupId>com.hchyun</groupId>
<version>3.2.0</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -100,7 +100,7 @@ public class Menu extends BaseEntity {
menuName = uqName;
orderNum = "0";
path = "data/" + uqId;
component = "tool/query/queryDate";
component = "system/query/queryDate";
isFrame = "1";
isCache = "0";
menuType = "C";

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>hchyun</artifactId>
<groupId>com.hchyun</groupId>
<version>3.2.0</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>hchyun</artifactId>
<groupId>com.hchyun</groupId>
<version>3.2.0</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -41,61 +41,11 @@ public class QueryController extends BaseController {
@Autowired
private QueryService queryService;
@ApiOperation("获取查询基本信息")
@PreAuthorize("@hchyun.hasPermi('query:real:list')")
@GetMapping("/real/{id}")
public AjaxResult RealInfo(@PathVariable("id") Long id) {
try {
if (id == null) {
return AjaxResult.error("id不能为空!");
}
ServerResult<List<UniCon>> serverResult = queryService.RealInfo(id);
if (serverResult.isStart()) {
return AjaxResult.success(serverResult.getData());
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
@PreAuthorize("@hchyun.hasAnyPermi('query:real:export')")
@PutMapping("/real/export")
public AjaxResult exportReal(@Validated @RequestBody UniQuery uniQuery) {
try {
ServerResult<List<Map<String, Object>>> serverResult = queryService.RealData(uniQuery, 1);
if (serverResult.isStart()) {
return new MapExcelUtil().exportExcel(serverResult.getData(), serverResult.getSheetName());
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
@PreAuthorize("@hchyun.hasAnyPermi('query:real:data')")
@PutMapping("/real")
public Serializable RealData(@Validated @RequestBody UniQuery uniQuery) {
try {
ServerResult<List<Map<String, Object>>> serverResult = queryService.RealData(uniQuery, 2);
if (serverResult.isStart()) {
return getDataTable(serverResult.getData());
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
/**
* 获取编辑sql的基本信息
* @param id
* @return
*/
@PreAuthorize("@hchyun.hasPermi('query:list')")
@GetMapping("/{id}")
public AjaxResult Info(@PathVariable("id") Long id) {
@ -118,6 +68,11 @@ public class QueryController extends BaseController {
}
}
/**
* 更新万能查询编辑信息 info 和查询信息
* @param uniQuery
* @return
*/
@PreAuthorize("@hchyun.hasPermi('query:edit')")
@PutMapping
public AjaxResult edit(@Validated @RequestBody UniQuery uniQuery) {
@ -134,6 +89,11 @@ public class QueryController extends BaseController {
}
}
/**
* 导出预览数据
* @param uniQuery
* @return
*/
@PreAuthorize("@hchyun.hasAnyPermi('query:export')")
@PutMapping("export")
public AjaxResult export(@Validated @RequestBody UniQuery uniQuery) {
@ -150,6 +110,11 @@ public class QueryController extends BaseController {
}
}
/**
* 返回预览信息
* @param uniQuery
* @return
*/
@PreAuthorize("@hchyun.hasPermi('query:preview')")
@PutMapping("preview")
public Serializable Preview(@Validated @RequestBody UniQuery uniQuery) {
@ -167,6 +132,12 @@ public class QueryController extends BaseController {
}
}
/**
* 发布上线
* @param uniQuery
* @return
*/
@PreAuthorize("@hchyun.hasPermi('query:release')")
@PutMapping("/release")
public AjaxResult Release(@RequestBody UniQuery uniQuery) {
try {

View File

@ -44,7 +44,6 @@ import com.hchyun.common.enums.BusinessType;
* @author hchyun
* @date 2021-01-30
*/
@Api(value = "万能查询管理", tags = "万能查询管理")
@RestController
@RequestMapping("/tool/query")
public class UniQueryController extends BaseController {
@ -56,7 +55,6 @@ public class UniQueryController extends BaseController {
/**
* 查询万能查询列表
*/
@ApiOperation("查询万能查询列表")
@PreAuthorize("@hchyun.hasPermi('tool:query:list')")
@GetMapping("/list")
public Serializable list(UniQuery uniQuery) {
@ -77,7 +75,6 @@ public class UniQueryController extends BaseController {
/**
* 导出万能查询列表
*/
@ApiOperation("导出万能查询列表")
@PreAuthorize("@hchyun.hasPermi('tool:query:export')")
@Log(title = "万能查询", businessType = BusinessType.EXPORT)
@GetMapping("/export")
@ -99,8 +96,6 @@ public class UniQueryController extends BaseController {
/**
* 获取万能查询详细信息
*/
@ApiOperation("获取万能查询详细信息")
@ApiImplicitParam(name = "id", value = "万能查询id", required = true, dataType = "Long", paramType = "path")
@PreAuthorize("@hchyun.hasPermi('tool:query:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
@ -120,8 +115,6 @@ public class UniQueryController extends BaseController {
/**
* 新增万能查询
*/
@ApiOperation("新增万能查询")
@ApiImplicitParam(name = "uniQuery", value = "新增万能查询信息", dataType = "UniQuery")
@PreAuthorize("@hchyun.hasPermi('tool:query:add')")
@Log(title = "万能查询", businessType = BusinessType.INSERT)
@PostMapping
@ -146,10 +139,8 @@ public class UniQueryController extends BaseController {
}
/**
* 修改万能查询
* 简单修改万能查询
*/
@ApiOperation("修改万能查询")
@ApiImplicitParam(name = "uniQuery", value = "修改万能查询信息", dataType = "UniQuery")
@PreAuthorize("@hchyun.hasPermi('tool:query:edit')")
@Log(title = "万能查询", businessType = BusinessType.UPDATE)
@PutMapping
@ -177,8 +168,6 @@ public class UniQueryController extends BaseController {
/**
* 删除万能查询
*/
@ApiOperation("删除万能查询")
@ApiImplicitParam(name = "ids", value = "万能查询ids", required = true, dataType = "Long", paramType = "path")
@PreAuthorize("@hchyun.hasPermi('tool:query:remove')")
@Log(title = "万能查询", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")

View File

@ -14,24 +14,60 @@ import java.util.Map;
*/
public interface QueryDao {
/**
* 通过id获取到万能查询的基本信息
* @param id
* @return
*/
UniQuery selectQueryInfo(Long id);
Integer updateQueryInfo(UniQuery uniQuery);
/**
* 删除万能查询
* @param uqId
* @return
*/
Integer deleteUniCon(Long uqId);
/**
* 新增万能查询
* @param uniCons
* @return
*/
Integer insertUniCon(List<UniCon> uniCons);
/**
* 获取查询信息
* @param paramSQL
* @return
*/
List<Map<String, Object>> UniQuery(String paramSQL);
List<UniCon> queryRealInfo(Long id);
/**
* 查询是否发布
* @param id
* @return
*/
Integer Release(Long id);
/**
* 改变发布状态
* @param uniQuery
* @return
*/
Integer changeRelease(UniQuery uniQuery);
/**
* 插入到菜单
* @param menu
* @return
*/
Integer insertMenu(Menu menu);
/**
* 删除菜单
* @param path
* @return
*/
Integer deleteMenu(String path);
}

View File

@ -60,5 +60,7 @@ public interface UniQueryDao {
*/
public int deleteUniQueryByIds(Long[] ids);
int deleteUniQueryByUqId(Long id);
}

View File

@ -47,6 +47,7 @@ public class UniQuery extends BaseEntity {
private Integer pageSize;
public Integer getIsRelease() {
return isRelease;
}

View File

@ -37,22 +37,6 @@ public interface QueryService {
*/
ServerResult<List<Map<String, Object>>> previewQuery(UniQuery uniQuery);
/**
* 获取真实查询基本信息
*
* @param id
* @return
*/
ServerResult<List<UniCon>> RealInfo(Long id);
/**
* 获取查询信息
*
* @param uniQuery
* @return
*/
ServerResult<List<Map<String, Object>>> RealData(UniQuery uniQuery, Integer type);
/**
* @param uniQuery
* @return

View File

@ -94,38 +94,6 @@ public class QueryServiceImpl implements QueryService {
}
}
@Override
public ServerResult<List<Map<String, Object>>> RealData(UniQuery uniQuery, Integer type) {
try {
List<UniCon> uniCons = uniQuery.getUniCons();
Integer pageNum = null, pageSize = null;
if (type == 2) {
pageNum = uniQuery.getPageNum();
pageSize = uniQuery.getPageSize();
}
uniQuery = uniQueryDao.selectUniQueryById(uniQuery.getId());
StringBuilder sql = new StringBuilder(uniQuery.getUqSql().toLowerCase());
if (uniQuery.getIsRelease() == 0) {
return new ServerResult<>(false, ReturnConstants.STATE_ERROR);
} else {
if (uniCons.size() > 0) {
sql.append(" where 1 = 1 ");
for (UniCon uniCon : uniCons) {
sql.append(conversionReal(uniCon));
}
}
if (type == 2) {
PageHelper.startPage(pageNum, pageSize, "");
}
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
return new ServerResult<>(true, dataMap, uniQuery.getUqName());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
}
/**
* 更新万能查询基本信息和条件
*/
@ -175,71 +143,11 @@ public class QueryServiceImpl implements QueryService {
}
}
@Override
public ServerResult<List<UniCon>> RealInfo(Long id) {
try {
List<UniCon> uniCons = queryDao.queryRealInfo(id);
return new ServerResult<>(true, uniCons);
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<>(false, ReturnConstants.DB_EX);
}
}
public String conversionReal(UniCon uniCon) {
if (uniCon.getUcReal() == null) {
return "";
} else {
String sql = " and ";
switch (uniCon.getUcCon()) {
case "EQ":
sql += uniCon.getUcKey() + " = '" + uniCon.getUcReal() + "'";
break;
case "NE":
sql += uniCon.getUcKey() + " != '" + uniCon.getUcReal() + "'";
break;
case "GT":
sql += uniCon.getUcKey() + " > '" + uniCon.getUcReal() + "'";
break;
case "GTE":
sql += uniCon.getUcKey() + " >= '" + uniCon.getUcReal() + "'";
break;
case "LT":
sql += uniCon.getUcKey() + " < '" + uniCon.getUcReal() + "'";
break;
case "LTE":
sql += uniCon.getUcKey() + " <= '" + uniCon.getUcReal() + "'";
break;
case "LIKE":
sql += uniCon.getUcKey() + " like '%" + uniCon.getUcReal() + "%'";
break;
case "BETWEEN":
if (uniCon.getUcType().equals("input")) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(uniCon.getUcReal());
Object begin = jsonObject.get("begin");
Object end = jsonObject.get("end");
if (begin != null && end != null) {
sql += uniCon.getUcKey() + " between '" + begin + "' AND '" + end + "'";
} else {
sql = "";
}
} else if (uniCon.getUcType().equals("datetime")) {
List<String> list = (ArrayList<String>) uniCon.getUcReal();
if (list.size() == 2) {
String startTime = list.get(0);
String endTime = list.get(1);
sql += uniCon.getUcKey() + " between '" + startTime + "' AND '" + endTime + "'";
} else {
sql = "";
}
}
break;
}
return sql;
}
}
/**
* 预览模式下拼接sql
* @param uniCon
* @return
*/
public String conversionPreview(UniCon uniCon) {
String sql = " and ";
switch (uniCon.getUcCon()) {

View File

@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
import com.hchyun.generator.dao.UniQueryDao;
import com.hchyun.generator.entity.UniQuery;
import com.hchyun.generator.service.UniQueryService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
/**
* 万能查询Service业务层处理
@ -119,17 +121,23 @@ public class UniQueryServiceImpl implements UniQueryService {
* @return 结果
*/
@Override
@Transactional
public ServerResult<Integer> deleteUniQueryByIds(Long[] ids) {
try {
Integer renewal = uniQueryDao.deleteUniQueryByIds(ids);
for (Long id : ids) {
uniQueryDao.deleteUniQueryByUqId(id);
}
if (renewal > 0) {
return new ServerResult<Integer>(true, renewal);
return new ServerResult<>(true, renewal);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
logger.error(e.getMessage());
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
return new ServerResult<>(false, ReturnConstants.DB_EX);
}
}
@ -140,17 +148,20 @@ public class UniQueryServiceImpl implements UniQueryService {
* @return 结果
*/
@Override
@Transactional
public ServerResult<Integer> deleteUniQueryById(Long id) {
try {
Integer renewal = uniQueryDao.deleteUniQueryById(id);
uniQueryDao.deleteUniQueryByUqId(id);
if (renewal > 0) {
return new ServerResult<Integer>(true, renewal);
return new ServerResult<>(true, renewal);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
logger.error(e.getMessage());
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
return new ServerResult<>(false, ReturnConstants.DB_EX);
}
}
}

View File

@ -73,9 +73,6 @@
<select id="Release" resultType="Integer" parameterType="Long">
select is_release from gen_uni_query where id = #{id}
</select>
<select id="queryRealInfo" parameterType="Long" resultMap="UniConResult">
select * from gen_uni_con where uq_id = #{id}
</select>
<update id="changeRelease" parameterType="com.hchyun.generator.entity.UniQuery">
update gen_uni_query set is_release = #{isRelease} where id = #{id}
</update>

View File

@ -68,6 +68,10 @@
<delete id="deleteUniQueryById" parameterType="Long">
delete from gen_uni_query where id = #{id}
</delete>
<delete id="deleteUniQueryByUqId" parameterType="Long">
delete from gen_uni_con where uq_id = #{id}
</delete>
<delete id="deleteUniQueryByIds" parameterType="String">
delete from gen_uni_query where id in

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>hchyun</artifactId>
<groupId>com.hchyun</groupId>
<version>3.2.0</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>hchyun</artifactId>
<groupId>com.hchyun</groupId>
<version>3.2.0</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -0,0 +1,38 @@
package com.hchyun.system.dao;
import com.hchyun.system.entity.RealUniQuery;
import java.util.List;
import java.util.Map;
/**
* @Author 18209
* @Date 2021/2/22 18:04
* @Version 1.0
*/
public interface RealQueryServiceDao {
/**
* 查询万能查询
*
* @param id 万能查询ID
* @return 万能查询
*/
RealUniQuery selectRealUniQueryById(Long id);
/**
* 查询结果
* @param paramSQL
* @return
*/
List<Map<String, Object>> realUniQuery(String paramSQL);
/**
* 获取页面信息
* @param id
* @return
*/
List<RealUniQuery> queryRealInfo(Long id);
}

View File

@ -0,0 +1,141 @@
package com.hchyun.system.entity;
/**
* 万能查询条件对象 sys_uni_con
*
* @author hchyun
* @date 2021-01-30
*/
public class RealUniCon {
/**
* id
*/
private Long id;
/**
* 万能查询tableid
*/
private Long uqId;
/**
* 名称(lable)
*/
private String ucName;
/**
* 关键字
*/
private String ucKey;
/**
* 查询条件
*/
private String ucCon;
/**
* 模拟数据
*/
private String ucMock;
/**
* 真实数据
*/
private Object ucReal;
/**
* 描述
*/
private String ucDescribe;
/**
* 输入类型
*/
private String ucType;
/**
* 显示类型
*/
private Integer type;
public String getUcType() {
return ucType;
}
public void setUcType(String ucType) {
this.ucType = ucType;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setUqId(Long uqId) {
this.uqId = uqId;
}
public Long getUqId() {
return uqId;
}
public void setUcName(String ucName) {
this.ucName = ucName;
}
public String getUcName() {
return ucName;
}
public void setUcKey(String ucKey) {
this.ucKey = ucKey;
}
public String getUcKey() {
return ucKey;
}
public void setUcCon(String ucCon) {
this.ucCon = ucCon;
}
public String getUcCon() {
return ucCon;
}
public String getUcMock() {
return ucMock;
}
public void setUcMock(String ucMock) {
this.ucMock = ucMock;
}
public String getUcDescribe() {
return ucDescribe;
}
public void setUcDescribe(String ucDescribe) {
this.ucDescribe = ucDescribe;
}
public Object getUcReal() {
return ucReal;
}
public void setUcReal(Object ucReal) {
this.ucReal = ucReal;
}
}

View File

@ -0,0 +1,131 @@
package com.hchyun.system.entity;
import com.hchyun.common.core.entity.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.ArrayList;
import java.util.List;
/**
* 万能查询对象 sys_uni_query
*
* @author hchyun
* @date 2021-01-30
*/
public class RealUniQuery extends BaseEntity {
/**
* id
*/
private Long id;
/**
* 名称
*/
private String uqName;
/**
* sql语句
*/
private String uqSql;
/**
* 描述
*/
private String uqDescribe;
/**
* 是否发布(0:,1:发布)
*/
private Integer isRelease;
private List<RealUniCon> realUniCons;
private Integer pageNum;
private Integer pageSize;
public Integer getIsRelease() {
return isRelease;
}
public void setIsRelease(Integer isRelease) {
this.isRelease = isRelease;
}
public Integer getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public List<RealUniCon> getUniCons() {
if (realUniCons == null) {
return realUniCons = new ArrayList<RealUniCon>();
} else {
return realUniCons;
}
}
public void setUniCons(List<RealUniCon> realUniCons) {
this.realUniCons = realUniCons;
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setUqName(String uqName) {
this.uqName = uqName;
}
public String getUqName() {
return uqName;
}
public void setUqSql(String uqSql) {
this.uqSql = uqSql;
}
public String getUqSql() {
return uqSql;
}
public void setUqDescribe(String uqDescribe) {
this.uqDescribe = uqDescribe;
}
public String getUqDescribe() {
return uqDescribe;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("uqName", getUqName())
.append("uqSql", getUqSql())
.append("uqDescribe", getUqDescribe())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -0,0 +1,31 @@
package com.hchyun.system.service;
import com.hchyun.common.utils.ServerResult;
import com.hchyun.system.entity.RealUniQuery;
import java.util.List;
import java.util.Map;
/**
* @Author 18209
* @Date 2021/2/22 18:03
* @Version 1.0
*/
public interface RealQueryService {
/**
* 获取查询信息
* @param realUniQuery
* @param type
* @return
*/
ServerResult<List<Map<String, Object>>> RealData(RealUniQuery realUniQuery, Integer type);
/**
* 获取真实查询基本信息
*
* @param id
* @return
*/
ServerResult<List<RealUniQuery>> RealInfo(Long id);
}

View File

@ -0,0 +1,128 @@
package com.hchyun.system.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.utils.ServerResult;
import com.hchyun.system.dao.RealQueryServiceDao;
import com.hchyun.system.entity.RealUniCon;
import com.hchyun.system.entity.RealUniQuery;
import com.hchyun.system.service.RealQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @Author 18209
* @Date 2021/2/22 18:04
* @Version 1.0
*/
@Service
public class RealQueryServiceImpl implements RealQueryService {
private Logger logger = LoggerFactory.getLogger(RealQueryServiceImpl.class);
@Autowired
private RealQueryServiceDao realQueryServiceDao;
@Override
public ServerResult<List<RealUniQuery>> RealInfo(Long id) {
try {
List<RealUniQuery> uniCons = realQueryServiceDao.queryRealInfo(id);
return new ServerResult<>(true, uniCons);
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<>(false, ReturnConstants.DB_EX);
}
}
@Override
public ServerResult<List<Map<String, Object>>> RealData(RealUniQuery realUniQuery, Integer type) {
try {
List<RealUniCon> realUniCons = realUniQuery.getUniCons();
Integer pageNum = null, pageSize = null;
if (type == 2) {
pageNum = realUniQuery.getPageNum();
pageSize = realUniQuery.getPageSize();
}
realUniQuery = realQueryServiceDao.selectRealUniQueryById(realUniQuery.getId());
StringBuilder sql = new StringBuilder(realUniQuery.getUqSql().toLowerCase());
if (realUniQuery.getIsRelease() == 0) {
return new ServerResult<>(false, ReturnConstants.STATE_ERROR);
} else {
if (realUniCons.size() > 0) {
sql.append(" where 1 = 1 ");
for (RealUniCon realUniCon : realUniCons) {
sql.append(conversionReal(realUniCon));
}
}
if (type == 2) {
PageHelper.startPage(pageNum, pageSize, "");
}
List<Map<String, Object>> dataMap = realQueryServiceDao.realUniQuery(sql.toString());
return new ServerResult<>(true, dataMap, realUniQuery.getUqName());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<>(false, ReturnConstants.SYS_FAILL);
}
}
public String conversionReal(RealUniCon realUniCon) {
if (realUniCon.getUcReal() == null) {
return "";
} else {
String sql = " and ";
switch (realUniCon.getUcCon()) {
case "EQ":
sql += realUniCon.getUcKey() + " = '" + realUniCon.getUcReal() + "'";
break;
case "NE":
sql += realUniCon.getUcKey() + " != '" + realUniCon.getUcReal() + "'";
break;
case "GT":
sql += realUniCon.getUcKey() + " > '" + realUniCon.getUcReal() + "'";
break;
case "GTE":
sql += realUniCon.getUcKey() + " >= '" + realUniCon.getUcReal() + "'";
break;
case "LT":
sql += realUniCon.getUcKey() + " < '" + realUniCon.getUcReal() + "'";
break;
case "LTE":
sql += realUniCon.getUcKey() + " <= '" + realUniCon.getUcReal() + "'";
break;
case "LIKE":
sql += realUniCon.getUcKey() + " like '%" + realUniCon.getUcReal() + "%'";
break;
case "BETWEEN":
if (realUniCon.getUcType().equals("input")) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(realUniCon.getUcReal());
Object begin = jsonObject.get("begin");
Object end = jsonObject.get("end");
if (begin != null && end != null) {
sql += realUniCon.getUcKey() + " between '" + begin + "' AND '" + end + "'";
} else {
sql = "";
}
} else if (realUniCon.getUcType().equals("datetime")) {
List<String> list = (ArrayList<String>) realUniCon.getUcReal();
if (list.size() == 2) {
String startTime = list.get(0);
String endTime = list.get(1);
sql += realUniCon.getUcKey() + " between '" + startTime + "' AND '" + endTime + "'";
} else {
sql = "";
}
}
break;
}
return sql;
}
}
}

View File

@ -0,0 +1,46 @@
<?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.hchyun.system.dao.RealQueryServiceDao">
<resultMap type="com.hchyun.system.entity.RealUniQuery" id="RealUniQueryResult">
<result property="id" column="id" />
<result property="uqName" column="uq_name" />
<result property="uqSql" column="uq_sql" />
<result property="uqDescribe" column="uq_describe" />
<result property="isRelease" column="is_release" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<resultMap type="com.hchyun.system.entity.RealUniCon" id="RealUniConResult">
<result property="id" column="uc_id" />
<result property="uqId" column="uq_id" />
<result property="ucName" column="uc_name" />
<result property="ucKey" column="uc_key" />
<result property="ucCon" column="uc_con" />
<result property="ucMock" column="uc_mock" />
<result property="ucDescribe" column="uc_describe" />
<result property="ucType" column="uc_type" />
<result property="type" column="type" />
</resultMap>
<select id="queryRealInfo" parameterType="Long" resultMap="RealUniConResult">
select * from gen_uni_con where uq_id = #{id}
</select>
<sql id="selectUniQueryVo">
select id, uq_name, uq_sql, uq_describe, is_release, create_by, create_time, update_by, update_time from gen_uni_query
</sql>
<select id="selectRealUniQueryById" parameterType="Long" resultMap="RealUniQueryResult">
<include refid="selectUniQueryVo"/>
where id = #{id}
</select>
<select id="realUniQuery" resultType="java.util.HashMap">
${paramSQL}
</select>
</mapper>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>hchyun</artifactId>
<groupId>com.hchyun</groupId>
<version>3.2.0</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -6,14 +6,14 @@
<groupId>com.hchyun</groupId>
<artifactId>hchyun</artifactId>
<version>3.2.0</version>
<version>1.0.0</version>
<name>hchyun</name>
<url>http://www.hchyun.com</url>
<description>宏驰云管理系统</description>
<properties>
<hchyun.version>3.2.0</hchyun.version>
<hchyun.version>1.0.0</hchyun.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
@ -177,7 +177,7 @@
<dependency>
<groupId>com.hchyun</groupId>
<artifactId>hchyun-test</artifactId>
<version>3.2.0</version>
<version>${hchyun.version}</version>
</dependency>
<!-- 核心模块-->
@ -200,7 +200,6 @@
<artifactId>hchyun-common</artifactId>
<version>${hchyun.version}</version>
</dependency>
</dependencies>
</dependencyManagement>