7 changed files with 267 additions and 0 deletions
-
62src/main/java/com/xujie/modules/quickQuery/controller/QuickQueryFieldController.java
-
19src/main/java/com/xujie/modules/quickQuery/data/QuickQueryFieldData.java
-
45src/main/java/com/xujie/modules/quickQuery/entity/QuickQueryField.java
-
21src/main/java/com/xujie/modules/quickQuery/mapper/QuickQueryFieldMapper.java
-
19src/main/java/com/xujie/modules/quickQuery/service/QuickQueryFieldService.java
-
74src/main/java/com/xujie/modules/quickQuery/service/impl/QuickQueryFieldServiceImpl.java
-
27src/main/resources/mapper/quickQuery/QuickQueryFieldMapper.xml
@ -0,0 +1,62 @@ |
|||
package com.xujie.modules.quickQuery.controller; |
|||
|
|||
import com.xujie.common.utils.R; |
|||
import com.xujie.modules.quickQuery.data.QuickQueryFieldData; |
|||
import com.xujie.modules.quickQuery.service.QuickQueryFieldService; |
|||
import com.xujie.modules.sys.controller.AbstractController; |
|||
import com.xujie.modules.sys.entity.SysUserEntity; |
|||
import org.apache.shiro.SecurityUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 快捷查询字段配置接口 - rqrq |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/quickQuery/field") |
|||
public class QuickQueryFieldController extends AbstractController { |
|||
|
|||
@Autowired |
|||
private QuickQueryFieldService quickQueryFieldService; |
|||
|
|||
/** |
|||
* 按 tableId(及可选 site)加载可查询字段,供快捷查询弹窗使用 |
|||
*/ |
|||
@PostMapping("/listByTableId") |
|||
public R listByTableId(@RequestBody QuickQueryFieldData query) { |
|||
List<QuickQueryFieldData> rows = quickQueryFieldService.listByTableId( |
|||
query.getTableId(), query.getSite()); |
|||
return R.ok().put("rows", rows); |
|||
} |
|||
|
|||
/** |
|||
* 维护:新增或修改一条字段配置 |
|||
*/ |
|||
@PostMapping("/save") |
|||
public R save(@RequestBody QuickQueryFieldData data) { |
|||
SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|||
String op = user != null ? user.getUsername() : "system"; |
|||
quickQueryFieldService.saveOrUpdateField(data, op); |
|||
return R.ok(); |
|||
} |
|||
|
|||
/** |
|||
* 维护:删除 |
|||
*/ |
|||
@PostMapping("/delete") |
|||
public R delete(@RequestBody Map<String, Object> body) { |
|||
Object idObj = body == null ? null : body.get("id"); |
|||
if (idObj == null) { |
|||
throw new RuntimeException("id 不能为空"); |
|||
} |
|||
Long id = Long.valueOf(String.valueOf(idObj)); |
|||
quickQueryFieldService.deleteById(id); |
|||
return R.ok(); |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package com.xujie.modules.quickQuery.data; |
|||
|
|||
import com.xujie.modules.quickQuery.entity.QuickQueryField; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.apache.ibatis.type.Alias; |
|||
|
|||
/** |
|||
* 快捷查询字段(请求/展示) - rqrq |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Alias("QuickQueryFieldData") |
|||
public class QuickQueryFieldData extends QuickQueryField { |
|||
|
|||
private Integer page; |
|||
|
|||
private Integer limit; |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
package com.xujie.modules.quickQuery.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 快捷查询字段配置 - rqrq |
|||
*/ |
|||
@Data |
|||
@TableName("srm_quick_query_field") |
|||
public class QuickQueryField { |
|||
|
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
private String tableId; |
|||
|
|||
private String fieldName; |
|||
|
|||
private String fieldLabel; |
|||
|
|||
/** NUMBER / TEXT / DATETIME */ |
|||
private String dataType; |
|||
|
|||
private Integer sortOrder; |
|||
|
|||
private String site; |
|||
|
|||
/** ACTIVE / INACTIVE */ |
|||
private String status; |
|||
|
|||
private String remark; |
|||
|
|||
private String createdBy; |
|||
|
|||
private Date createdDate; |
|||
|
|||
private String updatedBy; |
|||
|
|||
private Date updatedDate; |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.xujie.modules.quickQuery.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.xujie.modules.quickQuery.data.QuickQueryFieldData; |
|||
import com.xujie.modules.quickQuery.entity.QuickQueryField; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 快捷查询字段配置 Mapper - rqrq |
|||
*/ |
|||
@Mapper |
|||
public interface QuickQueryFieldMapper extends BaseMapper<QuickQueryField> { |
|||
|
|||
/** |
|||
* 按表格编码拉取可查询字段(启用、按排序) - rqrq |
|||
*/ |
|||
List<QuickQueryFieldData> listByTableId(@Param("tableId") String tableId, @Param("site") String site); |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package com.xujie.modules.quickQuery.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.xujie.modules.quickQuery.data.QuickQueryFieldData; |
|||
import com.xujie.modules.quickQuery.entity.QuickQueryField; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 快捷查询字段配置 - rqrq |
|||
*/ |
|||
public interface QuickQueryFieldService extends IService<QuickQueryField> { |
|||
|
|||
List<QuickQueryFieldData> listByTableId(String tableId, String site); |
|||
|
|||
void saveOrUpdateField(QuickQueryFieldData data, String operator); |
|||
|
|||
void deleteById(Long id); |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
package com.xujie.modules.quickQuery.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.xujie.modules.quickQuery.data.QuickQueryFieldData; |
|||
import com.xujie.modules.quickQuery.entity.QuickQueryField; |
|||
import com.xujie.modules.quickQuery.mapper.QuickQueryFieldMapper; |
|||
import com.xujie.modules.quickQuery.service.QuickQueryFieldService; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 快捷查询字段配置实现 - rqrq |
|||
*/ |
|||
@Service |
|||
public class QuickQueryFieldServiceImpl extends ServiceImpl<QuickQueryFieldMapper, QuickQueryField> |
|||
implements QuickQueryFieldService { |
|||
|
|||
@Override |
|||
public List<QuickQueryFieldData> listByTableId(String tableId, String site) { |
|||
if (!StringUtils.hasText(tableId)) { |
|||
throw new RuntimeException("tableId 不能为空"); |
|||
} |
|||
String siteParam = StringUtils.hasText(site) ? site.trim() : ""; |
|||
return baseMapper.listByTableId(tableId.trim(), siteParam); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void saveOrUpdateField(QuickQueryFieldData data, String operator) { |
|||
if (!StringUtils.hasText(data.getTableId()) || !StringUtils.hasText(data.getFieldName())) { |
|||
throw new RuntimeException("tableId、fieldName 不能为空"); |
|||
} |
|||
if (!StringUtils.hasText(data.getDataType())) { |
|||
throw new RuntimeException("dataType 不能为空"); |
|||
} |
|||
String dt = data.getDataType().trim().toUpperCase(); |
|||
if (!"NUMBER".equals(dt) && !"TEXT".equals(dt) && !"DATETIME".equals(dt)) { |
|||
throw new RuntimeException("dataType 仅支持 NUMBER、TEXT、DATETIME"); |
|||
} |
|||
data.setDataType(dt); |
|||
if (data.getSortOrder() == null) { |
|||
data.setSortOrder(0); |
|||
} |
|||
if (!StringUtils.hasText(data.getSite())) { |
|||
data.setSite(""); |
|||
} |
|||
if (!StringUtils.hasText(data.getStatus())) { |
|||
data.setStatus("ACTIVE"); |
|||
} |
|||
Date now = new Date(); |
|||
if (data.getId() == null) { |
|||
data.setCreatedBy(operator); |
|||
data.setCreatedDate(now); |
|||
baseMapper.insert(data); |
|||
} else { |
|||
data.setUpdatedBy(operator); |
|||
data.setUpdatedDate(now); |
|||
baseMapper.updateById(data); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void deleteById(Long id) { |
|||
if (id == null) { |
|||
throw new RuntimeException("id 不能为空"); |
|||
} |
|||
baseMapper.deleteById(id); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<?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"> |
|||
<!-- rqrq - 快捷查询字段 --> |
|||
<mapper namespace="com.xujie.modules.quickQuery.mapper.QuickQueryFieldMapper"> |
|||
|
|||
<select id="listByTableId" resultType="QuickQueryFieldData"> |
|||
SELECT |
|||
id, |
|||
table_id AS tableId, |
|||
field_name AS fieldName, |
|||
field_label AS fieldLabel, |
|||
data_type AS dataType, |
|||
sort_order AS sortOrder, |
|||
site, |
|||
status, |
|||
remark, |
|||
created_by AS createdBy, |
|||
created_date AS createdDate, |
|||
updated_by AS updatedBy, |
|||
updated_date AS updatedDate |
|||
FROM srm_quick_query_field |
|||
WHERE table_id = #{tableId} |
|||
AND status = N'ACTIVE' |
|||
AND (site = N'' OR site = #{site}) |
|||
ORDER BY sort_order ASC, id ASC |
|||
</select> |
|||
</mapper> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue