chengf
2026-01-29 abefef70ee144169527e878513636578742f40bc
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/demo/contract/controller/ContractController.java
@@ -13,10 +13,14 @@
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.message.util.ChinesePinyinUtils;
import org.jeecg.modules.system.controller.SysUserController;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
@@ -267,7 +271,7 @@
   public Result<String> add(@RequestBody ContractPage contractPage) {
      Contract contract = new Contract();
      BeanUtils.copyProperties(contractPage, contract);
        contract.setContractCode(ChinesePinyinUtils.getFirstLetter(contract.getContractName()));
        contract.setContractCode(getFirstLetter(contract.getContractName()));
      contractService.saveMain(contract, contractPage.getContractFileList(),contractPage.getSemanticWordList());
        addContract(contract,contractPage.getSemanticWordList());
@@ -275,7 +279,39 @@
        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();
     }
   /**
    *  编辑
    *
@@ -622,13 +658,15 @@
             String sType = contract.getAgentsName() == null || contract.getAgentsName().equals("") ? "客户" : "代理商";
             String sTarget = semanticWord.getOutWord();
             String checkSql = "SELECT COUNT(1) FROM d_Contract WHERE sBookMarkName = ?";
             String contractId = 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("-", "");
@@ -644,13 +682,13 @@
                         ")";
                 // 执行插入,仅传入动态参数
                 jdbcTemplate.update(
                         insertSql,
                         uuid,               // 动态UUID
                         sBookMarkName, // 动态sBookMarkName
                         contractId,
                         semanticWord.getWord()  // 动态semantic_word
                 );
//                 jdbcTemplate.update(
//                         insertSql,
//                         uuid,               // 动态UUID
//                         sBookMarkName, // 动态sBookMarkName
//                         contractId,
//                         semanticWord.getWord()  // 动态semantic_word
//                 );
             }
         }