package org.jeecg.modules.demo.semanticword.controller;
|
|
import java.util.*;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
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.Contract;
|
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.jeecg.modules.system.entity.SysUser;
|
import org.jeecg.modules.system.service.ISysUserService;
|
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;
|
|
@Autowired
|
private ISysUserService sysUserService;
|
/**
|
* 分页列表查询
|
*
|
* @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) {
|
|
// 自定义查询规则
|
Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
|
// 自定义多选的查询规则为:LIKE_WITH_OR
|
customeRuleMap.put("status", QueryRuleEnum.LIKE_WITH_OR);
|
QueryWrapper<SemanticWord> queryWrapper;
|
if (semanticWord.getCreateBy() != null && semanticWord.getCreateBy().equals("admin")) {
|
semanticWord.setCreateBy(null);
|
queryWrapper = QueryGenerator.initQueryWrapper(semanticWord, req.getParameterMap(),customeRuleMap);
|
}else if (semanticWord.getCreateBy() != null) {
|
QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
String user = semanticWord.getCreateBy();
|
semanticWord.setCreateBy(null);
|
queryWrapper = QueryGenerator.initQueryWrapper(semanticWord, req.getParameterMap(), customeRuleMap);
|
sysUserQueryWrapper.eq("agent_sales", user);
|
List<SysUser> iPageResult = sysUserService.list(sysUserQueryWrapper);
|
List<String> name = new ArrayList<>();
|
for (SysUser sysUser : iPageResult) {
|
name.add(sysUser.getUsername());
|
}
|
name.add(user);
|
queryWrapper.in("create_by", name);
|
}else {
|
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 isDropService = semanticWord.getIsDropService();
|
if (customerName != null && !customerName.isEmpty()) {
|
// 拼接关联条件:semantic_word关联contract,contract关联customer,通过客户名称过滤
|
queryWrapper.inSql(
|
"contract_id", // semantic_word表中关联contract的字段
|
"SELECT id FROM contract WHERE is_drop_service = '" + isDropService + "'"
|
);
|
}
|
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);
|
}
|
|
|
//@AutoLog(value = "语义词-查询语义总量")
|
@Operation(summary="语义词-查询语义总量")
|
@GetMapping(value = "/count")
|
public Result<IPage<SemanticWord>> queryPageList(Contract contract,
|
SemanticWord semanticWord,
|
@RequestParam(name="role", defaultValue="无") String role,
|
@RequestParam(name="user", defaultValue="无") String user,
|
HttpServletRequest req) {
|
|
// 自定义查询规则
|
Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
|
if (contract.getCreateBy() != null) {
|
user = contract.getCreateBy();
|
}
|
// 自定义多选的查询规则为:LIKE_WITH_OR
|
customeRuleMap.put("reviewStatus", QueryRuleEnum.LIKE_WITH_OR);
|
QueryWrapper<Contract> queryWrapper = QueryGenerator.initQueryWrapper(contract, req.getParameterMap(),customeRuleMap,true);
|
if (contract.getAgentAuditorIsNull() != null) {
|
if (contract.getAgentAuditorIsNull().equals("false")) {
|
queryWrapper.isNotNull("agents_name");
|
} else{
|
queryWrapper.and(wrapper -> wrapper.isNull("agents_name").or().eq("agents_name", ""));
|
|
}
|
}
|
if (!user.equals("无")){
|
QueryWrapper qw = new QueryWrapper<SysUser>();
|
qw.eq("id", user);
|
String userName = ((SysUser)((Page) sysUserService.queryPageList(req, qw, 1, 1).getResult()).getRecords().get(0)).getUsername();
|
queryWrapper.eq("create_by", userName);
|
}
|
if (role.equals("无"));
|
else if (role.equals("1972228581703651330")){//销售
|
// else{
|
// if (user.equals("无")){
|
// return Result.error("请输入销售名称");//销售根据用户筛选
|
// }
|
QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
sysUserQueryWrapper.eq("agent_sales", user);
|
Result<IPage<SysUser>> iPageResult = sysUserService.queryPageList(req, sysUserQueryWrapper, 100, 1);
|
List<String> name = new ArrayList<>();
|
for (SysUser sysUser : iPageResult.getResult().getRecords()){
|
name.add(sysUser.getUsername());
|
}
|
name.add(user);
|
queryWrapper.nested(wrapper -> {
|
// 内层第一个条件:(create_by IN (name) AND review_status != 2)
|
wrapper.nested(w1 -> w1.in("create_by", name).ne("review_status", 2));
|
// 内层 OR 条件:(create_by = 最后一个name AND review_status = 2)
|
wrapper.or(w2 -> w2.eq("create_by", name.get(name.size()-1)).eq("review_status", 2));
|
});
|
}
|
if (role.equals("1972228688033452034")){//财务
|
queryWrapper.ne("review_status", "8");
|
}
|
queryWrapper.orderBy(
|
true, // condition:是否启用该排序(true=启用)
|
false, // isAsc:是否升序(false=降序,让 1 在前、0 在后)
|
"CASE WHEN review_status = 1 THEN 1 ELSE 0 END" // R column:虚拟排序列(直接传 SQL 片段)
|
);
|
|
queryWrapper.orderBy(
|
true, // condition:是否启用该排序(true=启用)
|
false, // isAsc:是否升序(false=降序,让 1 在前、0 在后)
|
"CASE WHEN review_status = 2 THEN 1 ELSE 0 END" // R column:虚拟排序列(直接传 SQL 片段)
|
);
|
|
queryWrapper.orderBy(
|
true, // condition:是否启用该排序(true=启用)
|
true, // isAsc:是否升序(false=降序,让 1 在前、0 在后)
|
"emergency_status" // R column:虚拟排序列(直接传 SQL 片段)
|
);
|
|
queryWrapper.orderBy(
|
true, // condition:是否启用该排序(true=启用)
|
false, // isAsc:是否升序(false=降序,让 1 在前、0 在后)
|
"create_time" // R column:虚拟排序列(直接传 SQL 片段)
|
);
|
|
// ========== 核心修改部分 ==========
|
// 1. 只查询符合条件的合同ID(优化性能,避免查询全量字段)
|
queryWrapper.select("id"); // 只选择合同ID字段
|
List<Contract> contractList = contractService.list(queryWrapper);
|
|
// 2. 统计semantic_word表的记录数
|
long semanticWordCount = 0L;
|
if (!CollectionUtils.isEmpty(contractList)) {
|
// 提取所有符合条件的合同ID
|
List<String> contractIds = new ArrayList<>();
|
for (Contract c : contractList) {
|
contractIds.add(c.getId()); // 假设合同ID字段是id,类型为Long
|
}
|
|
// 构建semantic_word表的查询条件
|
QueryWrapper<SemanticWord> swQueryWrapper = new QueryWrapper<>();
|
// 假设semantic_word表中关联合同的字段是contract_id,请根据实际表结构调整
|
swQueryWrapper.in("contract_id", contractIds);
|
|
// 统计记录数(需要注入SemanticWord对应的Service)
|
semanticWordCount = semanticWordService.count(swQueryWrapper);
|
}
|
|
// 最终结果:semanticWordCount 就是你需要的总记录数
|
System.out.println("semantic_word表总记录数:" + semanticWordCount);
|
return Result.OK(semanticWordCount+"");
|
}
|
|
@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()) {
|
if (semanticWord1.getAcceptindicator() == null) {
|
return Result.error("语义词:"+semanticWord1.getWord()+"已达指标未填写!");
|
}
|
semanticWord1.setContractId(semanticWord.getContractId());
|
}
|
}
|
semanticWordService.saveBatch(semanticWord.getSemanticWordList());
|
return Result.OK("批量添加成功!");
|
}
|
if (semanticWord.getAcceptindicator() == null){
|
return Result.error("语义词:"+semanticWord.getWord()+"已达指标未填写!");
|
}
|
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) {
|
if (semanticWord.getStatus().equals("7")){
|
semanticWord.setDistributionTime(new Date());
|
}
|
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());
|
}
|
}
|
|
}
|