package org.jeecg.modules.demo.contract.controller; import java.io.UnsupportedEncodingException; import java.io.IOException; import java.net.URLDecoder; import java.util.*; import java.util.stream.Collectors; import cn.hutool.extra.pinyin.PinyinUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.websocket.server.PathParam; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; import org.jeecg.common.aspect.DictAspect; import org.jeecg.modules.demo.customer.entity.Customer; import org.jeecg.modules.demo.customer.service.ICustomerService; import org.jeecg.modules.system.controller.SysUserController; import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.service.ISysUserService; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.common.system.vo.LoginUser; import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryRuleEnum; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.demo.contract.entity.ContractFile; import org.jeecg.modules.demo.contract.entity.SemanticWord; import org.jeecg.modules.demo.contract.entity.Contract; import org.jeecg.modules.demo.contract.vo.ContractPage; import org.jeecg.modules.demo.contract.service.IContractService; import org.jeecg.modules.demo.contract.service.IContractFileService; import org.jeecg.modules.demo.contract.service.ISemanticWordService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; 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 com.alibaba.fastjson.JSON; 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-11 * @Version: V1.0 */ @Tag(name="合同") @RestController @RequestMapping("/contract/contract") @Slf4j public class ContractController { @Autowired private IContractService contractService; @Autowired private IContractFileService contractFileService; @Autowired private ISemanticWordService semanticWordService; @Autowired private ICustomerService customerService; @Autowired private ISysUserService sysUserService; /** * 分页列表查询 * * @param contract * @param pageNo * @param pageSize * @param req * @return */ //@AutoLog(value = "合同-分页列表查询") @Operation(summary="合同-分页列表查询") @GetMapping(value = "/list") public Result> queryPageList(Contract contract, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, @RequestParam(name="role", defaultValue="无") String role, @RequestParam(name="user", defaultValue="无") String user, HttpServletRequest req) { // 自定义查询规则 Map customeRuleMap = new HashMap<>(); if (contract.getCreateBy() != null) { user = contract.getCreateBy(); } // 自定义多选的查询规则为:LIKE_WITH_OR customeRuleMap.put("reviewStatus", QueryRuleEnum.LIKE_WITH_OR); QueryWrapper 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("无")); else if (role.equals("1972228581703651330")){//销售 // else{ // if (user.equals("无")){ // return Result.error("请输入销售名称");//销售根据用户筛选 // } QueryWrapper sysUserQueryWrapper = new QueryWrapper<>(); sysUserQueryWrapper.eq("agent_sales", user); Result> iPageResult = sysUserService.queryPageList(req, sysUserQueryWrapper, pageSize, pageNo); List 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"); } Page page = new Page(pageNo, pageSize); 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 片段) ); IPage pageList = contractService.page(page, queryWrapper); List semanticWordList = null; for (Contract contract1 : pageList.getRecords()){ semanticWordList = semanticWordService.selectByMainId(contract1.getId()); for (SemanticWord semanticWord : semanticWordList){ if (semanticWord.getPrice() != null){ contract1.setCountSum(contract1.getCountSum() + semanticWord.getPrice()); } contract1.setSemanticWordList(contract1.getSemanticWordList() == null ? semanticWord.getWord() : contract1.getSemanticWordList() + ", " + semanticWord.getWord()); } QueryWrapper qw = new QueryWrapper<>(); qw.eq("enterprise_name",contract1.getCustomerName()); contract1.setCustomer(customerService.getOne(qw)); } return Result.OK(pageList); } @Operation(summary="合同-查询该角色合同个数") @GetMapping(value = "/count") public Result> queryPageList(Contract contract, @RequestParam(name="role", defaultValue="无") String role, @RequestParam(name="user", defaultValue="无") String user, HttpServletRequest req) { // 自定义查询规则 Map customeRuleMap = new HashMap<>(); if (contract.getCreateBy() != null) { user = contract.getCreateBy(); } // 自定义多选的查询规则为:LIKE_WITH_OR customeRuleMap.put("reviewStatus", QueryRuleEnum.LIKE_WITH_OR); QueryWrapper 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(); 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 sysUserQueryWrapper = new QueryWrapper<>(); sysUserQueryWrapper.eq("agent_sales", user); Result> iPageResult = sysUserService.queryPageList(req, sysUserQueryWrapper, 100, 1); List 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)); }); } 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 片段) ); long count = contractService.count(queryWrapper); return Result.OK(count+""); } /** * 添加 * * @param contractPage * @return */ @AutoLog(value = "合同-添加") @Operation(summary="合同-添加") @RequiresPermissions("contract:contract:add") @PostMapping(value = "/add") public Result add(@RequestBody ContractPage contractPage) { Contract contract = new Contract(); BeanUtils.copyProperties(contractPage, contract); contract.setContractCode(getFirstLetter(contract.getContractName())); contractService.saveMain(contract, contractPage.getContractFileList(),contractPage.getSemanticWordList()); addContract(contract,contractPage.getSemanticWordList()); return Result.OK("添加成功!"); } public static String getFirstLetter(String chinese) { if (chinese == null || chinese.isEmpty()) { return ""; } HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); format.setCaseType(HanyuPinyinCaseType.UPPERCASE); // 大写 format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); // 忽略声调 StringBuilder firstLetters = new StringBuilder(); char[] chars = chinese.toCharArray(); for (char c : chars) { // 如果是中文,提取首字母 if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) { try { String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format); if (pinyinArray != null && pinyinArray.length > 0) { firstLetters.append(pinyinArray[0].charAt(0)); // 取第一个拼音的首字母 } } catch (BadHanyuPinyinOutputFormatCombination e) { e.printStackTrace(); } } else { // 非中文不处理(或根据需求保留/过滤) // firstLetters.append(c); // 如需保留非中文字符,解开此注释 } } return firstLetters.toString(); } /** * 编辑 * * @param contractPage * @return */ @AutoLog(value = "合同-编辑") @Operation(summary="合同-编辑") @RequiresPermissions("contract:contract:edit") @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) public Result edit(@RequestBody ContractPage contractPage) { Contract contract = new Contract(); if (contract.getCustomer() == null ||contract.getCustomer().getEnterpriseName() == null || !contract.getCustomer().getEnterpriseName().equals("")) { BeanUtils.copyProperties(contractPage, contract); Contract contractEntity = contractService.getById(contract.getId()); if (contractEntity.getReviewStatus() != null && contract.getReviewStatus() != null && !contractEntity.getReviewStatus().equals(contract.getReviewStatus())) { contractEntity.setChangerTime(new Date()); contract.setChangerTime(new Date()); } if(contractEntity==null) { return Result.error("未找到对应数据"); } contractService.updateMain(contract, contractPage.getContractFileList(),contractPage.getSemanticWordList()); return Result.OK("编辑成功!"); } BeanUtils.copyProperties(contractPage, contract); Contract contractEntity = contractService.getById(contract.getId()); if (contractEntity.getReviewStatus() != null && contract.getReviewStatus() != null && !contractEntity.getReviewStatus().equals(contract.getReviewStatus())) { contractEntity.setChangerTime(new Date()); contract.setChangerTime(new Date()); } contractEntity.setCustomer(contract.getCustomer()); contract.setCustomerName(contract.getCustomer().getEnterpriseName()); contractEntity.setCustomerName(contract.getCustomer().getEnterpriseName()); QueryWrapper qw = new QueryWrapper<>(); qw.eq("enterprise_name",contract.getCustomer().getEnterpriseName()); if (customerService.count(qw) > 0 && !contractPage.getCustomerName().equals(contract.getCustomerName())) { return Result.error("重复的公司名称"); } if(contractEntity==null) { return Result.error("未找到对应数据"); } contractService.updateMain(contract, contractPage.getContractFileList(),contractPage.getSemanticWordList()); customerService.updateById(contractEntity.getCustomer()); if (contractPage.getStatus() != null) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.set("status", contractPage.getStatus()); // 替换为实际要修改的字段名(如semantic_id) updateWrapper.eq("contract_id", contract.getId()); // 复用查询条件 boolean update = semanticWordService.update(updateWrapper); } return Result.OK("编辑成功!"); } /** * 通过id删除 * * @param id * @return */ @AutoLog(value = "合同-通过id删除") @Operation(summary="合同-通过id删除") @RequiresPermissions("contract:contract:delete") @DeleteMapping(value = "/delete") public Result delete(@RequestParam(name="id",required=true) String id) { QueryWrapper objectQueryWrapper = new QueryWrapper<>(); objectQueryWrapper.eq("id",id); List list = contractService.list(objectQueryWrapper); String customerName = list.get(0).getCustomerName(); contractService.delMain(id); objectQueryWrapper = new QueryWrapper<>(); objectQueryWrapper.eq("customer_name",customerName); if (contractService.count(objectQueryWrapper) == 0) { QueryWrapper customerQueryWrapper = new QueryWrapper<>(); customerQueryWrapper.eq("enterprise_name",customerName); Customer one = customerService.getOne(customerQueryWrapper); customerService.removeById(one); QueryWrapper qw = new QueryWrapper<>(); qw.eq("username", customerName); qw.eq("realname", customerName); sysUserService.remove(qw); } return Result.OK("删除成功!"); } /** * 批量删除 * * @param ids * @return */ @AutoLog(value = "合同-批量删除") @Operation(summary="合同-批量删除") @RequiresPermissions("contract:contract:deleteBatch") @DeleteMapping(value = "/deleteBatch") public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) { this.contractService.delBatchMain(Arrays.asList(ids.split(","))); return Result.OK("批量删除成功!"); } @Autowired DictAspect dictAspect; /** * 通过id查询 * * @param id * @return */ //@AutoLog(value = "合同-通过id查询") @Operation(summary="合同-通过id查询") @GetMapping(value = "/queryById") public Result queryById(@RequestParam(name="id",required=true) String id) { Page page = new Page(1, 1); QueryWrapper contractQueryWrapper = new QueryWrapper<>(); contractQueryWrapper.eq("id", id); IPage pageList = contractService.page(page, contractQueryWrapper); Result result = (Result) dictAspect.parseDictText(Result.ok(pageList)); Contract contract = ((JSONObject)(((IPage)(result.getResult())).getRecords().get(0))).toJavaObject(Contract.class); if(contract==null) { return Result.error("未找到对应数据"); } QueryWrapper qw = new QueryWrapper<>(); qw.eq("enterprise_name",contract.getCustomerName()); contract.setCustomer(customerService.getOne(qw)); List semanticWordList = null; semanticWordList = semanticWordService.selectByMainId(contract.getId()); for (SemanticWord semanticWord : semanticWordList){ if (semanticWord.getPrice() != null){ contract.setCountSum(contract.getCountSum() + semanticWord.getPrice()); } contract.setSemanticWordList(contract.getSemanticWordList() == null ? semanticWord.getWord() : contract.getSemanticWordList() + ", " + semanticWord.getWord()); } return Result.OK(contract); } /** * 通过id查询 * * @param id * @return */ //@AutoLog(value = "合同附件通过主表ID查询") @Operation(summary="合同附件主表ID查询") @GetMapping(value = "/queryContractFileByMainId") public Result> queryContractFileListByMainId(@RequestParam(name="id",required=true) String id) { List contractFileList = contractFileService.selectByMainId(id); return Result.OK(contractFileList); } /** * 通过id查询 * * @param id * @return */ //@AutoLog(value = "语义词通过主表ID查询") @Operation(summary="语义词主表ID查询") @GetMapping(value = "/querySemanticWordByMainId") public Result> querySemanticWordListByMainId(@RequestParam(name="id",required=true) String id) { List semanticWordList = semanticWordService.selectByMainId(id); return Result.OK(semanticWordList); } /** * 导出excel * * @param request * @param contract */ @RequiresPermissions("contract:contract:exportXls") @RequestMapping(value = "/exportXls") public ModelAndView exportXls(HttpServletRequest request, Contract contract) { // Step.1 组装查询条件查询数据 QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(contract, request.getParameterMap()); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); //配置选中数据查询条件 String selections = request.getParameter("selections"); if(oConvertUtils.isNotEmpty(selections)) { List selectionList = Arrays.asList(selections.split(",")); queryWrapper.in("id",selectionList); } //Step.2 获取导出数据 List contractList = contractService.list(queryWrapper); // Step.3 组装pageList List pageList = new ArrayList(); for (Contract main : contractList) { ContractPage vo = new ContractPage(); BeanUtils.copyProperties(main, vo); List contractFileList = contractFileService.selectByMainId(main.getId()); vo.setContractFileList(contractFileList); List semanticWordList = semanticWordService.selectByMainId(main.getId()); vo.setSemanticWordList(semanticWordList); pageList.add(vo); } // Step.4 AutoPoi 导出Excel ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); mv.addObject(NormalExcelConstants.FILE_NAME, "合同列表"); mv.addObject(NormalExcelConstants.CLASS, ContractPage.class); mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("合同数据", "导出人:"+sysUser.getRealname(), "合同")); mv.addObject(NormalExcelConstants.DATA_LIST, pageList); return mv; } /** * 通过excel导入数据 * * @param request * @param response * @return */ @RequiresPermissions("contract:contract:importExcel") @RequestMapping(value = "/importExcel", method = RequestMethod.POST) public Result importExcel(HttpServletRequest request, HttpServletResponse response) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { // 获取上传文件对象 MultipartFile file = entity.getValue(); ImportParams params = new ImportParams(); params.setTitleRows(2); params.setHeadRows(1); params.setNeedSave(true); try { List list = ExcelImportUtil.importExcel(file.getInputStream(), ContractPage.class, params); for (ContractPage page : list) { Contract po = new Contract(); BeanUtils.copyProperties(page, po); contractService.saveMain(po, page.getContractFileList(),page.getSemanticWordList()); } return Result.OK("文件导入成功!数据行数:" + list.size()); } catch (Exception e) { log.error(e.getMessage(),e); return Result.error("文件导入失败:"+e.getMessage()); } finally { try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return Result.OK("文件导入失败!"); } /** * 查询快过期的合同 * * @param days 过期天数阈值(默认30天) * @return */ @AutoLog(value = "合同-查询快过期合同") @Operation(summary = "合同-查询快过期合同") @GetMapping(value = "/expiring") public Result>> queryExpiringContracts( @RequestParam(name = "days", defaultValue = "30") Integer days) { try { // 计算日期范围 java.time.LocalDate today = java.time.LocalDate.now(); java.util.Date startDate = java.sql.Date.valueOf(today); java.util.Date endDateLimit = java.sql.Date.valueOf(today.minusDays(days)); // 构建查询条件 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.isNotNull("month") // 替换为 MySQL 正确的 DATE_ADD 语法:DATE_ADD(日期, INTERVAL 数值 单位) .apply("DATE_ADD(create_time, INTERVAL month MONTH) >= {0}", endDateLimit) .apply("DATE_ADD(create_time, INTERVAL month MONTH) <= {0}", startDate) // 排序也同步替换为 MySQL 语法 .orderByAsc("DATE_ADD(create_time, INTERVAL month MONTH)"); // 执行查询 List contractList = contractService.list(queryWrapper); // 构建返回结果,包含过期天数信息 List> resultList = new ArrayList<>(); for (Contract contract : contractList) { Map contractMap = new HashMap<>(); // 复制合同基本信息 contractMap.put("id", contract.getId()); contractMap.put("contractName", contract.getContractName()); contractMap.put("customerName", contract.getCustomerName()); contractMap.put("endDate", contract.getEndDate()); contractMap.put("reviewStatus", contract.getReviewStatus()); // 计算距离过期的天数 if (contract.getEndDate() != null) { // 将java.util.Date转换为LocalDate java.time.LocalDate endDate = contract.getEndDate().toInstant() .atZone(java.time.ZoneId.systemDefault()) .toLocalDate(); long daysRemaining = java.time.temporal.ChronoUnit.DAYS.between(today, endDate); contractMap.put("daysRemaining", daysRemaining); } else { contractMap.put("daysRemaining", null); } // 设置客户信息 if (contract.getCustomerName() != null) { QueryWrapper customerQueryWrapper = new QueryWrapper<>(); customerQueryWrapper.eq("enterprise_name", contract.getCustomerName()); Customer customer = customerService.getOne(customerQueryWrapper); contractMap.put("customer", customer); } // 设置语义词列表 List semanticWordList = semanticWordService.selectByMainId(contract.getId()); if (semanticWordList != null && !semanticWordList.isEmpty()) { String semanticWords = semanticWordList.stream() .map(SemanticWord::getWord) .collect(Collectors.joining(", ")); contractMap.put("semanticWordList", semanticWords); } resultList.add(contractMap); } return Result.OK(resultList); } catch (Exception e) { log.error("查询快过期合同失败", e); return Result.error("查询失败: " + e.getMessage()); } } @Autowired @Qualifier("robinJdbcTemplate") // 指定特定的JdbcTemplate private JdbcTemplate jdbcTemplate; public void addContract(Contract contract, List semanticWordList) { for (SemanticWord semanticWord : semanticWordList){ String uuid = UUID.randomUUID().toString().replaceAll("-", ""); String sBookMarkName = PinyinUtil.getPinyin(contract.getContractName(), "") + "_" + PinyinUtil.getPinyin(semanticWord.getOutWord()); String sCreator = contract.getCreateBy(); String sType = contract.getAgentsName() == null || contract.getAgentsName().equals("") ? "客户" : "代理商"; String sTarget = semanticWord.getOutWord(); String checkSql = "SELECT COUNT(1) FROM d_Contract WHERE sBookMarkName = ?"; String contractId = PinyinUtil.getPinyin(contract.getContractName(), ""); Integer count = jdbcTemplate.queryForObject( checkSql, new Object[]{sBookMarkName}, // 传入查询参数(合同名称) Integer.class ); if (count > 0) { return; } String[] arr = new String[]{"哪家好", "哪家靠谱", "排行榜", "选哪家", "排名"}; for (int i = 0; i < 5; i++) { uuid = UUID.randomUUID().toString().replaceAll("-", ""); sBookMarkName = semanticWord.getWord() + arr[i]; String semantic_word = semanticWord.getOutWord(); // 插入SQL,固定值直接写在SQL中,动态值用?占位 String insertSql = "INSERT INTO d_keyword_list (" + // 表名修正为 d_keyword_list "UUID, sBookMarkName, ContractId, semantic_word, sCreator, sType, sDomain, " + "apply_name, is_active, priority_num, interval_minute, is_proxy, proxy_mode, scan_min" + // 补充表中存在的 is_proxy 字段 ") VALUES (" + "?, ?, ?, ?, 'admin', 'manual', '客户', " + "'deepseek', 1, 8, 240, 0, 'random', 5" + // 补充 is_proxy 的默认值(int类型,这里用0) ")"; // 执行插入,仅传入动态参数 // jdbcTemplate.update( // insertSql, // uuid, // 动态UUID // sBookMarkName, // 动态sBookMarkName // contractId, // semanticWord.getWord() // 动态semantic_word // ); } } } @RequiresPermissions("contract:contract:importAgentContractWord") @RequestMapping(value = "/importAgentContractWord", method = RequestMethod.POST) public Result importAgentContractWord(@RequestBody Contract contract) { if (contract.getReviewStatus() == null) { contract.setReviewStatus("8"); } QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("contract_name",contract.getContractName()); long count = contractService.count(queryWrapper); if (count > 0) { return Result.error("合同名称已存在"); } contractService.save(contract); QueryWrapper queryWrapper1 = new QueryWrapper<>(); queryWrapper1.eq("contract_name",contract.getContractName()); Contract one1 = contractService.getOne(queryWrapper1); for (SemanticWord semanticWord : contract.getSemanticWordObjs()){ semanticWord.setContractId(one1.getId()); } semanticWordService.saveBatch(contract.getSemanticWordObjs()); for (ContractFile contractFile : contract.getContractFileList()){ contractFile.setContractId(one1.getId()); contractFileService.save(contractFile); } addContract(contract,contract.getSemanticWordObjs()); return Result.OK("添加成功!"); } @Autowired private SysUserController sysUserController; @RequiresPermissions("contract:contract:assignCustomers") @RequestMapping(value = "/assignCustomers/{contractId}", method = RequestMethod.POST) public Result assignCustomers(@RequestBody Customer customer, @PathVariable("contractId") String contractId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("enterprise_name",customer.getEnterpriseName()); QueryWrapper querySysUser = new QueryWrapper<>(); querySysUser.eq("username",customer.getEnterpriseName()); if (customerService.count(queryWrapper) == 0) { customerService.save(customer); } if (sysUserController.getSysUserService().count(querySysUser) == 0) { JSONObject jsonObject = new JSONObject(); String filteredName = customer.getEnterpriseName().replaceAll("[\u4e00-\u9fa5]", "").replaceAll("\\s+", ""); jsonObject.put("workNo", "KH" + filteredName + customer.getCustomerPhone()); jsonObject.put("password", "123456"); jsonObject.put("confirmPassword", "123456"); jsonObject.put("selectedroles", "1972228625018228737"); jsonObject.put("activitiSync", "1"); jsonObject.put("departIds", ""); jsonObject.put("userIdentity", "1"); String phone = customer.getCustomerPhone(); ; // 校验电话号码:非空且为数字,且长度≤20 if (phone != null && phone.matches("\\d{1,20}")) { // 校验通过,放入JSONObject jsonObject.put("phone", phone); } else if(phone == null) { }else { return Result.error("请输入正确的电话号码"); } jsonObject.put("email" , customer.getCustomerEmail()); jsonObject.put("username" , customer.getEnterpriseName()); jsonObject.put("realname" , customer.getEnterpriseName()); try { Result add = sysUserController.add(jsonObject); if (add.getCode() != 200) { return Result.error("电话号码或邮箱重复"); } }catch (Exception e) { if (e.getMessage().equals("Subject does not have permission [system:user:add]")){ return Result.error("未分配权限:创建客户用户"); } return Result.error("电话号码或邮箱重复"); } } Contract contract = new Contract(); contract.setId(contractId); contract.setCustomerName(customer.getEnterpriseName()); contractService.updateById(contract); return Result.OK("添加成功!可通过" + customer.getEnterpriseName() + "/123456访问客户视图"); } }