chengf
2026-01-29 abefef70ee144169527e878513636578742f40bc
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/demo/contract/controller/ContractController.java
@@ -3,16 +3,27 @@
import java.io.UnsupportedEncodingException;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.HashMap;
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;
@@ -33,6 +44,8 @@
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;
@@ -65,7 +78,11 @@
   private IContractFileService contractFileService;
   @Autowired
   private ISemanticWordService semanticWordService;
     @Autowired
     private ICustomerService customerService;
     @Autowired
     private ISysUserService sysUserService;
   /**
    * 分页列表查询
    *
@@ -80,26 +97,168 @@
   @GetMapping(value = "/list")
   public Result<IPage<Contract>> queryPageList(Contract contract,
                           @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                           @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                 @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);
        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("无"));
        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, pageSize, pageNo);
            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");
        }
      Page<Contract> page = new Page<Contract>(pageNo, pageSize);
      IPage<Contract> pageList = contractService.page(page, queryWrapper);
        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<Contract> pageList = contractService.page(page, queryWrapper);
        List<SemanticWord> 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<Customer> 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<IPage<Contract>> queryPageList(Contract contract,
                                                  @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("无"));
         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 片段)
         );
         long count = contractService.count(queryWrapper);
         return Result.OK(count+"");
     }
     /**
    *   添加
    *
    * @param contractPage
@@ -112,10 +271,47 @@
   public Result<String> add(@RequestBody ContractPage contractPage) {
      Contract contract = new Contract();
      BeanUtils.copyProperties(contractPage, contract);
        contract.setContractCode(getFirstLetter(contract.getContractName()));
      contractService.saveMain(contract, contractPage.getContractFileList(),contractPage.getSemanticWordList());
      return Result.OK("添加成功!");
        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();
     }
   /**
    *  编辑
    *
@@ -128,12 +324,47 @@
   @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
   public Result<String> 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<Customer> 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<SemanticWord> updateWrapper = new UpdateWrapper<>();
            updateWrapper.set("status", contractPage.getStatus()); // 替换为实际要修改的字段名(如semantic_id)
            updateWrapper.eq("contract_id", contract.getId()); // 复用查询条件
            boolean update = semanticWordService.update(updateWrapper);
        }
      return Result.OK("编辑成功!");
   }
   
@@ -148,7 +379,28 @@
    @RequiresPermissions("contract:contract:delete")
   @DeleteMapping(value = "/delete")
   public Result<String> delete(@RequestParam(name="id",required=true) String id) {
      contractService.delMain(id);
        QueryWrapper<Contract> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("id",id);
        List<Contract> 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<Customer> customerQueryWrapper = new QueryWrapper<>();
            customerQueryWrapper.eq("enterprise_name",customerName);
            Customer one = customerService.getOne(customerQueryWrapper);
            customerService.removeById(one);
            QueryWrapper<SysUser> qw = new QueryWrapper<>();
            qw.eq("username", customerName);
            qw.eq("realname", customerName);
            sysUserService.remove(qw);
        }
      return Result.OK("删除成功!");
   }
   
@@ -166,7 +418,9 @@
      this.contractService.delBatchMain(Arrays.asList(ids.split(",")));
      return Result.OK("批量删除成功!");
   }
    @Autowired
    DictAspect dictAspect;
   /**
    * 通过id查询
    *
@@ -177,10 +431,26 @@
   @Operation(summary="合同-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<Contract> queryById(@RequestParam(name="id",required=true) String id) {
      Contract contract = contractService.getById(id);
      if(contract==null) {
        Page<Contract> page = new Page<Contract>(1, 1);
        QueryWrapper<Contract> contractQueryWrapper = new QueryWrapper<>();
        contractQueryWrapper.eq("id", id);
        IPage<Contract> 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<Customer> qw = new QueryWrapper<>();
        qw.eq("enterprise_name",contract.getCustomerName());
        contract.setCustomer(customerService.getOne(qw));
        List<SemanticWord> 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);
   }
@@ -296,6 +566,231 @@
      }
      return Result.OK("文件导入失败!");
    }
     /**
      * 查询快过期的合同
      *
      * @param days 过期天数阈值(默认30天)
      * @return
      */
     @AutoLog(value = "合同-查询快过期合同")
     @Operation(summary = "合同-查询快过期合同")
     @GetMapping(value = "/expiring")
     public Result<List<Map<String, Object>>> 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<Contract> 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<Contract> contractList = contractService.list(queryWrapper);
             // 构建返回结果,包含过期天数信息
             List<Map<String, Object>> resultList = new ArrayList<>();
             for (Contract contract : contractList) {
                 Map<String, Object> 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<Customer> customerQueryWrapper = new QueryWrapper<>();
                     customerQueryWrapper.eq("enterprise_name", contract.getCustomerName());
                     Customer customer = customerService.getOne(customerQueryWrapper);
                     contractMap.put("customer", customer);
                 }
                 // 设置语义词列表
                 List<SemanticWord> 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<SemanticWord> 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<String> 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<Contract> 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<String> assignCustomers(@RequestBody Customer customer, @PathVariable("contractId") String contractId) {
         QueryWrapper<Customer> queryWrapper = new  QueryWrapper<>();
         queryWrapper.eq("enterprise_name",customer.getEnterpriseName());
         QueryWrapper<SysUser> 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<SysUser> 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访问客户视图");
     }
}