package org.jeecg.modules.demo.semanticword.controller;
|
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import cn.hutool.core.util.StrUtil;
|
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletResponse;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.common.system.query.QueryRuleEnum;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.jeecg.modules.demo.contract.entity.SemanticWord;
|
import org.jeecg.modules.demo.contract.service.IContractService;
|
import org.jeecg.modules.demo.contract.service.ISemanticWordService;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.servlet.ModelAndView;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.Operation;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
/**
|
* @Description: 语义词
|
* @Author: jeecg-boot
|
* @Date: 2025-10-13
|
* @Version: V1.0
|
*/
|
@Tag(name="语义词")
|
@RestController
|
@RequestMapping("/semanticword/semanticWord")
|
@Slf4j
|
public class SemanticWordController extends JeecgController<SemanticWord, ISemanticWordService> {
|
@Autowired
|
private ISemanticWordService semanticWordService;
|
|
/**
|
* 分页列表查询
|
*
|
* @param semanticWord
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
//@AutoLog(value = "语义词-分页列表查询")
|
@Operation(summary="语义词-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<IPage<SemanticWord>> queryPageList(SemanticWord semanticWord,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
HttpServletRequest req) {
|
if (semanticWord.getCreateBy() != null && semanticWord.getCreateBy().equals("admin")) {
|
semanticWord.setCreateBy(null);
|
}
|
|
// 自定义查询规则
|
Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
|
// 自定义多选的查询规则为:LIKE_WITH_OR
|
customeRuleMap.put("status", QueryRuleEnum.LIKE_WITH_OR);
|
QueryWrapper<SemanticWord> queryWrapper = QueryGenerator.initQueryWrapper(semanticWord, req.getParameterMap(),customeRuleMap);
|
if (semanticWord.getUser() != null && !semanticWord.getUser().equals("admin")) {
|
queryWrapper.eq("create_by", semanticWord.getUser());
|
}
|
String customerName = semanticWord.getCustomerName();
|
if (customerName != null && !customerName.isEmpty()) {
|
// 拼接关联条件:semantic_word关联contract,contract关联customer,通过客户名称过滤
|
queryWrapper.inSql(
|
"contract_id", // semantic_word表中关联contract的字段
|
"SELECT id FROM contract WHERE customer_name = '" + customerName + "'"
|
);
|
}
|
String agentName = semanticWord.getAgentName();
|
if (agentName != null && !agentName.isEmpty()) {
|
// 拼接关联条件:semantic_word关联contract,contract关联customer,通过客户名称过滤
|
queryWrapper.inSql(
|
"contract_id", // semantic_word表中关联contract的字段
|
"SELECT id FROM contract WHERE agents_name = '" + agentName + "'"
|
);
|
}
|
if (semanticWord.getReviewStatus() != null) {
|
queryWrapper.inSql("contract_id", // semantic_word表中关联contract的字段
|
"SELECT id FROM contract WHERE review_status in ("+semanticWord.getReviewStatus()+")");
|
}
|
|
// 3. 新增:处理 statusFilter 的 IN 筛选(核心新增逻辑)
|
String statusFilter = semanticWord.getStatusFilter();
|
if (StrUtil.isNotBlank(statusFilter)) {
|
// 校验格式:仅允许数字和逗号(防止 SQL 注入)
|
if (!statusFilter.matches("^\\d+(,\\d+)*$")) {
|
throw new IllegalArgumentException("状态筛选格式错误,应为逗号分隔的数字(如:1,4,7)");
|
}
|
// 拆分字符串为数组,使用 in 条件(参数安全,MyBatis 自动处理)
|
String[] statusArr = statusFilter.split(",");
|
queryWrapper.in("status", Arrays.asList(statusArr));
|
}
|
|
if (semanticWord.getChangerNotEqual() != null) {
|
if (semanticWord.getChangerNotEqual().equals("已分配")) {
|
queryWrapper.isNotNull("changer");
|
}else {
|
queryWrapper.isNull("changer");
|
}
|
}
|
|
Page<SemanticWord> page = new Page<SemanticWord>(pageNo, pageSize);
|
IPage<SemanticWord> pageList = semanticWordService.page(page, queryWrapper);
|
List<SemanticWord> records = pageList.getRecords();
|
for (SemanticWord record : records) {
|
if (record.getContract() == null){
|
continue;
|
}
|
record.setContract(contractService.getById(record.getContractId()));
|
record.setCustomerName(record.getContract().getCustomerName());
|
}
|
return Result.OK(pageList);
|
}
|
|
@Autowired
|
private IContractService contractService;
|
/**
|
* 添加
|
*
|
* @param semanticWord
|
* @return
|
*/
|
@AutoLog(value = "语义词-添加")
|
@Operation(summary="语义词-添加")
|
@RequiresPermissions("semanticword:semantic_word:add")
|
@PostMapping(value = "/add")
|
public Result<String> add(@RequestBody SemanticWord semanticWord) {
|
if (semanticWord.getSemanticWordList().size() > 0) {
|
if (semanticWord.getContractId() != null) {
|
for (SemanticWord semanticWord1 : semanticWord.getSemanticWordList()) {
|
semanticWord1.setContractId(semanticWord.getContractId());
|
}
|
}
|
semanticWordService.saveBatch(semanticWord.getSemanticWordList());
|
return Result.OK("批量添加成功!");
|
}
|
semanticWordService.save(semanticWord);
|
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
*
|
* @param semanticWord
|
* @return
|
*/
|
@AutoLog(value = "语义词-编辑")
|
@Operation(summary="语义词-编辑")
|
@RequiresPermissions("semanticword:semantic_word:edit")
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
public Result<String> edit(@RequestBody SemanticWord semanticWord) {
|
semanticWordService.updateById(semanticWord);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "语义词-通过id删除")
|
@Operation(summary="语义词-通过id删除")
|
@RequiresPermissions("semanticword:semantic_word:delete")
|
@DeleteMapping(value = "/delete")
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
semanticWordService.removeById(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
*
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "语义词-批量删除")
|
@Operation(summary="语义词-批量删除")
|
@RequiresPermissions("semanticword:semantic_word:deleteBatch")
|
@DeleteMapping(value = "/deleteBatch")
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
this.semanticWordService.removeByIds(Arrays.asList(ids.split(",")));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 通过id查询
|
*
|
* @param id
|
* @return
|
*/
|
//@AutoLog(value = "语义词-通过id查询")
|
@Operation(summary="语义词-通过id查询")
|
@GetMapping(value = "/queryById")
|
public Result<SemanticWord> queryById(@RequestParam(name="id",required=true) String id) {
|
SemanticWord semanticWord = semanticWordService.getById(id);
|
if(semanticWord==null) {
|
return Result.error("未找到对应数据");
|
}
|
semanticWord.setContract(contractService.getById(semanticWord.getContractId()));
|
return Result.OK(semanticWord);
|
}
|
|
/**
|
* 导出excel
|
*
|
* @param request
|
* @param semanticWord
|
*/
|
@RequiresPermissions("semanticword:semantic_word:exportXls")
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, SemanticWord semanticWord) {
|
return super.exportXls(request, semanticWord, SemanticWord.class, "语义词");
|
}
|
|
/**
|
* 通过excel导入数据
|
*
|
* @param request
|
* @param response
|
* @return
|
*/
|
@RequiresPermissions("semanticword:semantic_word:importExcel")
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
return super.importExcel(request, response, SemanticWord.class);
|
}
|
|
/**
|
* 根据创建人按日期分组统计语义词数量
|
*
|
* @param createBy 创建人
|
* @param checkStartTime 统计开始时间
|
* @param checkEndTime 统计结束时间
|
* @return
|
*/
|
@AutoLog(value = "语义词-按日期分组统计")
|
@Operation(summary = "语义词-按日期分组统计")
|
@GetMapping(value = "/countByDate")
|
public Result<List<Map<String, Object>>> countByCreateTimeGroupByDate(
|
@RequestParam(name = "createBy", required = false) String createBy,
|
@RequestParam(name = "checkStartTime", required = false) String checkStartTime,
|
@RequestParam(name = "checkEndTime", required = false) String checkEndTime) {
|
|
try {
|
// 构建查询条件
|
QueryWrapper<SemanticWord> queryWrapper = new QueryWrapper<>();
|
if (createBy != null) {
|
queryWrapper.eq("create_by", createBy);
|
}
|
|
// 添加时间区间条件
|
if (checkStartTime != null && !checkStartTime.isEmpty()) {
|
queryWrapper.ge("create_time", checkStartTime);
|
}
|
if (checkEndTime != null && !checkEndTime.isEmpty()) {
|
queryWrapper.le("create_time", checkEndTime);
|
}
|
|
// 按日期分组统计
|
queryWrapper.select(
|
"DATE(create_time) as date",
|
"COUNT(*) as count"
|
);
|
queryWrapper.groupBy("DATE(create_time)");
|
queryWrapper.orderByAsc("DATE(create_time)");
|
|
// 执行查询
|
List<Map<String, Object>> result = semanticWordService.listMaps(queryWrapper);
|
|
return Result.OK(result);
|
} catch (Exception e) {
|
log.error("按日期分组统计语义词数量失败", e);
|
return Result.error("统计失败: " + e.getMessage());
|
}
|
}
|
|
}
|