| | |
| | | .securitySchemes(Collections.singletonList(securityScheme())) |
| | | .securityContexts(securityContexts()) |
| | | .globalOperationParameters(setHeaderToken()) |
| | | .groupName("MDC"); |
| | | .groupName("AI"); |
| | | } |
| | | |
| | | /*** |
| | |
| | | private ApiInfo apiInfo() { |
| | | return new ApiInfoBuilder() |
| | | // //大æ é¢ |
| | | .title("JeecgBoot åå°æå¡APIæ¥å£ææ¡£") |
| | | .title(" åå°æå¡APIæ¥å£ææ¡£") |
| | | // çæ¬å· |
| | | .version("1.0") |
| | | // .termsOfServiceUrl("NO terms of service") |
| | | // æè¿° |
| | | .description("åå°APIæ¥å£") |
| | | // ä½è
|
| | | .contact(new Contact("å京å½ç¬ä¿¡æ¯ææ¯æéå
¬å¸","www.jeccg.com","jeecgos@163.com")) |
| | | .contact(new Contact("西å®çµç§","www.xalxzn.com","xalxzn.com")) |
| | | .license("The Apache License, Version 2.0") |
| | | .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") |
| | | .build(); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.common.util.StrUtils; |
| | | import org.jeecg.modules.ai.entity.FileImgInfo; |
| | | import org.jeecg.modules.ai.entity.FilePdfInfo; |
| | | import org.jeecg.modules.ai.service.IFileImgInfoService; |
| | | import org.jeecg.modules.ai.service.IFilePdfInfoService; |
| | | import org.jeecg.modules.ai.vo.FilePdfSelectVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/9 |
| | | */ |
| | | @Slf4j |
| | | @Api(tags = "PDFå¾çæä»¶ç®¡ç") |
| | | @RestController |
| | | @RequestMapping("/ai/fileImg") |
| | | public class FileImgInfoController extends JeecgController<FileImgInfo, IFileImgInfoService> { |
| | | |
| | | @Autowired |
| | | private IFilePdfInfoService filePdfInfoService; |
| | | |
| | | @AutoLog(value = "å页å表æ¥è¯¢") |
| | | @ApiOperation(value = "å页å表æ¥è¯¢", notes = "å页å表æ¥è¯¢") |
| | | @GetMapping(value = "/list") |
| | | public Result<?> queryPageList(FilePdfSelectVo vo, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){ |
| | | Page page = new Page<>(pageNo, pageSize); |
| | | FilePdfInfo info = null; |
| | | if (StrUtils.isNotBlankOrNull(vo.getPdfFileId())) { |
| | | info = filePdfInfoService.getById(vo.getPdfFileId()); |
| | | } else if (StrUtils.isNotBlankOrNull(vo.getPdfName())) { |
| | | info = filePdfInfoService.findNewFilePDF(vo.getPdfName()); |
| | | } |
| | | if (info == null) { |
| | | return Result.error("æ æ¤æä»¶"); |
| | | } |
| | | IPage<FileImgInfo> imgInfos = service.queryPageList(info.getId(), page); |
| | | return Result.OK(imgInfos); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.controller; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.modules.ai.entity.FileImgInfo; |
| | | import org.jeecg.modules.ai.entity.FilePdfInfo; |
| | | import org.jeecg.modules.ai.service.IFilePdfInfoService; |
| | | import org.jeecg.modules.ai.vo.FilePdfSelectVo; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/7 |
| | | */ |
| | | @Slf4j |
| | | @Api(tags = "PDFæä»¶ç®¡ç") |
| | | @RestController |
| | | @RequestMapping("/ai/filePdf") |
| | | public class FilePdfInfoController extends JeecgController<FilePdfInfo, IFilePdfInfoService> { |
| | | |
| | | @AutoLog(value = "PDFæä»¶ç®¡ç-æ£ç´¢æ¥è¯¢") |
| | | @ApiOperation(value = "PDFæä»¶ç®¡ç-æ£ç´¢æ¥è¯¢", notes = "PDFæä»¶ç®¡ç-æ£ç´¢æ¥è¯¢") |
| | | @PutMapping(value = "/findImgList") |
| | | public Result<?> findImgPathList(@RequestBody FilePdfSelectVo vo) { |
| | | List<FileImgInfo> infos = service.findImgPathList(vo); |
| | | /*Thread.sleep();*/ |
| | | return Result.OK(infos); |
| | | } |
| | | |
| | | /* @AutoLog(value = "aiTest") |
| | | @ApiOperation(value = "aiTest", notes = "aiTest")*/ |
| | | @GetMapping(value = "/aiTest") |
| | | public Result<?> aiTest(String nameList) { |
| | | /* String name = "{\"id\":\"683a65fd-8feb-4446-ad32-714c4785f667\",\"messages\":[{\"role\":\"user\",\"content\":\"ç»æè®²ä¸ªæ
äºï¼\"}],\"stream\":true,\"max_tokens\":500}"; // JSONæ°æ® |
| | | String url = "https://836u458t54.vicp.fun/chat/test_chat"; |
| | | String aiPost = AiTestUils.sendJsonToHttpsPost(url, name);*/ |
| | | |
| | | String s = "\"data\": {\"id\": \"683a65fd-8feb-4446-ad32-714c4785f667\", \"created\": 1723105518, \"model\": \"YxCareer0.7\", \"choices\": [{\"index\": 0, \"delta\": {\"role\": \"assistant\", \"content\": \"\"}, \"finish_reason\": null}]}"; |
| | | System.out.println(s.replace("data:" ,"")); |
| | | return Result.OK(""); |
| | | } |
| | | |
| | | |
| | | @AutoLog(value = "PDFæä»¶å表") |
| | | @ApiOperation(value = "PDFæä»¶å表", notes = "PDFæä»¶å表") |
| | | @GetMapping(value = "/filePdfList") |
| | | public Result<?> aiFindFiles() { |
| | | List<FilePdfInfo> infos = service.list(); |
| | | return Result.OK(infos); |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.controller; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.modules.ai.entity.LanguageModel; |
| | | import org.jeecg.modules.ai.service.ILanguageModelService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/19 |
| | | */ |
| | | @Slf4j |
| | | @Api(tags = "é®ç") |
| | | @RestController |
| | | @RequestMapping("/ai/languageModel") |
| | | public class LanguageModelController extends JeecgController<LanguageModel, ILanguageModelService> { |
| | | |
| | | /** |
| | | * æ°å¢ |
| | | * |
| | | * @param languageModel |
| | | * @return |
| | | */ |
| | | @AutoLog("é®ç-æ°å¢") |
| | | @ApiOperation(value = "é®ç-æ°å¢", notes = "é®ç-æ°å¢") |
| | | @PostMapping("/addLanguage") |
| | | public Result<?> addLanguageModel(@RequestBody LanguageModel languageModel) { |
| | | Boolean flag = super.service.addLanguageModel(languageModel); |
| | | return flag ? Result.OK("æ°å¢æå") : Result.error("æ°å¢å¤±è´¥"); |
| | | } |
| | | |
| | | @AutoLog("é®ç-ä¼è¯å表") |
| | | @ApiOperation(value = "é®ç-ä¼è¯å表", notes = "é®ç-ä¼è¯å表") |
| | | @GetMapping("/languageTitles") |
| | | public Result<?> languageModelTitles() { |
| | | List<LanguageModel> languageModels = super.service.findListAiTitles(); |
| | | return Result.OK(languageModels); |
| | | } |
| | | |
| | | |
| | | |
| | | @AutoLog("é®ç-å表") |
| | | @ApiOperation(value = "é®ç-å表", notes = "é®ç-å表") |
| | | @GetMapping("/languageProblems") |
| | | public Result<?> languageProblems(String id) { |
| | | List<LanguageModel> models = super.service.languageProblems(id); |
| | | return Result.OK(models); |
| | | } |
| | | @AutoLog("é®ç-å é¤") |
| | | @ApiOperation(value = "é®ç-å é¤", notes = "é®ç-å é¤") |
| | | @RequestMapping(value = "/deleteLanguage", method = RequestMethod.DELETE) |
| | | public Result deleteLanguage(@RequestParam("id") String id) { |
| | | if (StringUtils.isNotBlank(id)) { |
| | | List<LanguageModel> models = super.service.languageProblems(id); |
| | | if (models == null || models.isEmpty()){ |
| | | super.service.removeById(id); |
| | | } |
| | | List<String> strings = new ArrayList<>(); |
| | | strings.add(id); |
| | | for (LanguageModel model : models) { |
| | | strings.add(model.getId()); |
| | | } |
| | | super.service.removeBatchByIds(strings); |
| | | } |
| | | return Result.ok("å 餿å"); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | | import org.jeecgframework.poi.excel.annotation.Excel; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/1 |
| | | */ |
| | | @Data |
| | | @TableName("ai_file_img_info") |
| | | @EqualsAndHashCode(callSuper = false) |
| | | @Accessors(chain = true) |
| | | public class FileImgInfo implements Serializable { |
| | | private static final long serialVersionUID = 1519876512924700514L; |
| | | @TableId(type = IdType.ASSIGN_ID) |
| | | @ApiModelProperty(value = "主é®") |
| | | private String id; |
| | | private String fileId; |
| | | /*页ç */ |
| | | private Integer pageNumber; |
| | | /*å¾çè·¯å¾*/ |
| | | private String imgPath; |
| | | /*å¾çåç§°*/ |
| | | private String imgName; |
| | | |
| | | private String imgEncodeName; |
| | | |
| | | @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("å建æ¶é´") |
| | | private Date createTime; |
| | | @Excel(name = "å建人",width = 15) |
| | | @ApiModelProperty("å建人") |
| | | private String createBy; |
| | | |
| | | @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("æ´æ°æ¶é´") |
| | | private Date updateTime; |
| | | @Excel(name = "æ´æ°äºº",width = 15) |
| | | @ApiModelProperty("æ´æ°äºº") |
| | | private String updateBy; |
| | | @Excel(name = "å é¤ç¶æ", width = 15, dicCode = "del_flag") |
| | | @ApiModelProperty(value = "å é¤ç¶æï¼0ï¼æ£å¸¸ï¼1å·²å é¤ï¼") |
| | | private String delFlag; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | | import org.jeecgframework.poi.excel.annotation.Excel; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/1 |
| | | */ |
| | | @Data |
| | | @TableName("ai_file_pdf_Info") |
| | | @EqualsAndHashCode(callSuper = false) |
| | | @Accessors(chain = true) |
| | | public class FilePdfInfo implements Serializable { |
| | | private static final long serialVersionUID = 1519876512924700514L; |
| | | @TableId(type = IdType.ASSIGN_ID) |
| | | @ApiModelProperty(value = "主é®") |
| | | private String id; |
| | | private String filePath; |
| | | private String fileName; |
| | | // æä»¶å å¯åçåç§° |
| | | private String fileEncodeName; |
| | | // æä»¶å¤§å°ï¼KBï¼ |
| | | private Long fileSize; |
| | | // æä»¶åç¼ |
| | | private String fileSuffix; |
| | | /*æ°æ§ç³»ç»*/ |
| | | private String controlSystem; |
| | | |
| | | @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("å建æ¶é´") |
| | | private Date createTime; |
| | | @Excel(name = "å建人",width = 15) |
| | | @ApiModelProperty("å建人") |
| | | private String createBy; |
| | | |
| | | @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("æ´æ°æ¶é´") |
| | | private Date updateTime; |
| | | @Excel(name = "æ´æ°äºº",width = 15) |
| | | @ApiModelProperty("æ´æ°äºº") |
| | | private String updateBy; |
| | | @Excel(name = "å é¤ç¶æ", width = 15, dicCode = "del_flag") |
| | | @ApiModelProperty(value = "å é¤ç¶æï¼0ï¼æ£å¸¸ï¼1å·²å é¤ï¼") |
| | | private String delFlag; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | | import org.jeecgframework.poi.excel.annotation.Excel; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/19 |
| | | */ |
| | | @Data |
| | | @TableName("ai_language_model") |
| | | @EqualsAndHashCode(callSuper = false) |
| | | @Accessors(chain = true) |
| | | public class LanguageModel implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1519876512924700514L; |
| | | @TableId(type = IdType.ASSIGN_ID) |
| | | @ApiModelProperty(value = "主é®") |
| | | private String id; |
| | | |
| | | private String aiId; |
| | | |
| | | private String parentId; |
| | | /*é®é¢*/ |
| | | private String problem; |
| | | /*åç*/ |
| | | private String answer; |
| | | /*ç±»å 1 å表 2 é®ç 3 åç*/ |
| | | private Integer aiType; |
| | | |
| | | |
| | | @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("å建æ¶é´") |
| | | private Date createTime; |
| | | @Excel(name = "å建人",width = 15) |
| | | @ApiModelProperty("å建人") |
| | | private String createBy; |
| | | |
| | | @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @ApiModelProperty("æ´æ°æ¶é´") |
| | | private Date updateTime; |
| | | @Excel(name = "æ´æ°äºº",width = 15) |
| | | @ApiModelProperty("æ´æ°äºº") |
| | | private String updateBy; |
| | | @Excel(name = "å é¤ç¶æ", width = 15, dicCode = "del_flag") |
| | | @ApiModelProperty(value = "å é¤ç¶æï¼0ï¼æ£å¸¸ï¼1å·²å é¤ï¼") |
| | | private String delFlag; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.jeecg.modules.ai.entity.FileImgInfo; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/5 |
| | | */ |
| | | public interface FileImgInfoMapper extends BaseMapper<FileImgInfo> { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.jeecg.modules.ai.entity.FilePdfInfo; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/5 |
| | | */ |
| | | public interface FilePdfInfoMapper extends BaseMapper<FilePdfInfo> { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.jeecg.modules.ai.entity.LanguageModel; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/19 |
| | | */ |
| | | public interface LanguageModelMapper extends BaseMapper<LanguageModel> { |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="org.jeecg.modules.ai.mapper.FileImgInfoMapper"> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="org.jeecg.modules.ai.mapper.FilePdfInfoMapper"> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="org.jeecg.modules.ai.mapper.LanguageModelMapper"> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import org.jeecg.modules.ai.entity.FileImgInfo; |
| | | import org.jeecg.modules.ai.vo.FilePdfSelectVo; |
| | | |
| | | import java.io.File; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/5 |
| | | */ |
| | | public interface IFileImgInfoService extends IService<FileImgInfo> { |
| | | |
| | | /** |
| | | * è§£æpdfæä»¶ï¼çæå¾çä¿åè®°å½ |
| | | * @param file |
| | | * @return |
| | | */ |
| | | boolean analysisPDfFromFile(File file); |
| | | |
| | | /** |
| | | * |
| | | * @param fileId |
| | | * @param pageNumbers |
| | | * @return |
| | | */ |
| | | List<FileImgInfo> findFileImgInfos(String fileId,List<Integer> pageNumbers); |
| | | |
| | | |
| | | IPage<FileImgInfo> queryPageList(String fileId, Page page); |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import org.jeecg.modules.ai.entity.FileImgInfo; |
| | | import org.jeecg.modules.ai.entity.FilePdfInfo; |
| | | import org.jeecg.modules.ai.vo.FilePdfSelectVo; |
| | | |
| | | import java.io.File; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/5 |
| | | */ |
| | | public interface IFilePdfInfoService extends IService<FilePdfInfo> { |
| | | |
| | | /** |
| | | * æä»¶ |
| | | * @param file |
| | | * @return |
| | | */ |
| | | boolean uploadFilePdf(File file); |
| | | |
| | | /** |
| | | * |
| | | * @param fileVo |
| | | * @return |
| | | */ |
| | | List<FileImgInfo> findImgPathList(FilePdfSelectVo fileVo); |
| | | |
| | | |
| | | FilePdfInfo findNewFilePDF(String fileName); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import org.jeecg.modules.ai.entity.LanguageModel; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/19 |
| | | */ |
| | | public interface ILanguageModelService extends IService<LanguageModel> { |
| | | |
| | | boolean addLanguageModel(LanguageModel languageModel); |
| | | |
| | | /** |
| | | * æ¥è¯¢åè¡¨æ°æ® |
| | | * @param aiType |
| | | * @param aiId |
| | | * @return |
| | | */ |
| | | LanguageModel selectParentId(Integer aiType,String aiId); |
| | | |
| | | /** |
| | | * |
| | | * @return |
| | | */ |
| | | List<LanguageModel> findListAiTitles(); |
| | | |
| | | /** |
| | | * |
| | | * @return |
| | | */ |
| | | List<LanguageModel> languageProblems(String id); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/8 |
| | | */ |
| | | public interface IWebSocketAiService { |
| | | |
| | | |
| | | /** |
| | | * æ¥è¯¢ |
| | | */ |
| | | void selectChatIA(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service.imp; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator; |
| | | import com.baomidou.mybatisplus.core.incrementer.ImadcnIdentifierGenerator; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.incrementer.KingbaseKeyGenerator; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.hibernate.HibernateException; |
| | | import org.hibernate.engine.spi.SharedSessionContractImplementor; |
| | | import org.hibernate.id.IdentifierGenerator; |
| | | import org.jeecg.modules.ai.entity.FileImgInfo; |
| | | import org.jeecg.modules.ai.entity.FilePdfInfo; |
| | | import org.jeecg.modules.ai.mapper.FileImgInfoMapper; |
| | | import org.jeecg.modules.ai.service.IFileImgInfoService; |
| | | import org.jeecg.modules.ai.service.IFilePdfInfoService; |
| | | import org.jeecg.modules.ai.vo.FilePdfSelectVo; |
| | | import org.jeecg.modules.utils.BeanMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.io.Serializable; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/5 |
| | | */ |
| | | @Service |
| | | public class FileImgInfoServiceImp extends ServiceImpl<FileImgInfoMapper,FileImgInfo> implements IFileImgInfoService { |
| | | |
| | | @Override |
| | | public boolean analysisPDfFromFile(File file) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<FileImgInfo> findFileImgInfos(String fileId,List<Integer> pageNumbers) { |
| | | List<FileImgInfo> mdcPlanCloses = this.getBaseMapper(). |
| | | selectList(new LambdaQueryWrapper<FileImgInfo>(). |
| | | in(FileImgInfo::getPageNumber, pageNumbers). |
| | | eq(FileImgInfo::getFileId,fileId). |
| | | orderByAsc(FileImgInfo::getPageNumber) |
| | | ); |
| | | return mdcPlanCloses; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<FileImgInfo> queryPageList(String fileId, Page page) { |
| | | LambdaQueryWrapper<FileImgInfo> wrapper =new LambdaQueryWrapper<>(); |
| | | wrapper.eq(FileImgInfo::getFileId,fileId); |
| | | return baseMapper.selectPage(page,wrapper); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service.imp; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.api.vo.FileUploadResult; |
| | | import org.jeecg.modules.ai.entity.FileImgInfo; |
| | | import org.jeecg.modules.ai.entity.FilePdfInfo; |
| | | import org.jeecg.modules.ai.mapper.FilePdfInfoMapper; |
| | | import org.jeecg.modules.ai.service.IFileImgInfoService; |
| | | import org.jeecg.modules.ai.service.IFilePdfInfoService; |
| | | import org.jeecg.modules.ai.vo.FilePdfSelectVo; |
| | | import org.jeecg.modules.ai.vo.KeyWordPositionVo; |
| | | import org.jeecg.modules.ai.vo.PhotoListVo; |
| | | import org.jeecg.modules.utils.BeanMapper; |
| | | import org.jeecg.modules.utils.DateUtil; |
| | | import org.jeecg.modules.utils.PdfTurnPngUtils; |
| | | import org.jeecg.modules.utils.PdfUtils; |
| | | import org.jeecg.modules.utils.file.FileUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.crypto.KeyGenerator; |
| | | import java.io.File; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/5 |
| | | */ |
| | | @Service |
| | | public class FilePdfInfoServiceImp extends ServiceImpl<FilePdfInfoMapper,FilePdfInfo> implements IFilePdfInfoService { |
| | | |
| | | @Autowired |
| | | private IFileImgInfoService fileImgInfoService; |
| | | |
| | | @Value("${jeecg.path.upload}") |
| | | public String fileUploadFolder; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public boolean uploadFilePdf(File file) { |
| | | FileUploadResult result = FileUtils.uploadFileInFile(file); |
| | | FilePdfInfo info = new FilePdfInfo(); |
| | | info.setFileName(result.getFileName()); |
| | | info.setFileEncodeName(result.getFileEncodeName()); |
| | | info.setFilePath(result.getFilePath()); |
| | | info.setFileSize(result.getFileSize()); |
| | | info.setFileSuffix(result.getFileSuffix()); |
| | | boolean b = save(info); |
| | | if (!b) { |
| | | return false; |
| | | } |
| | | try { |
| | | List<PhotoListVo> pngList = PdfTurnPngUtils.pdf2pngList(file,"png",info.getId()); |
| | | if (pngList == null || pngList.isEmpty() ) { |
| | | return false; |
| | | } |
| | | List<FileImgInfo> fileImgs = new ArrayList<>(); |
| | | for (PhotoListVo vo : pngList) { |
| | | FileImgInfo img = new FileImgInfo(); |
| | | BeanMapper.copy(vo,img); |
| | | img.setFileId(info.getId()); |
| | | fileImgs.add(img); |
| | | } |
| | | |
| | | boolean c = fileImgInfoService.saveBatch(fileImgs); |
| | | if (c) { |
| | | return true; |
| | | } else { |
| | | removeById(info.getId()); |
| | | return false; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | removeById(info.getId()); |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<FileImgInfo> findImgPathList(FilePdfSelectVo fileVo) { |
| | | FilePdfInfo info = new FilePdfInfo(); |
| | | if (StringUtils.isNotBlank(fileVo.getPdfFileId())) { |
| | | info = super.getById(fileVo.getPdfFileId()); |
| | | } else { |
| | | //å¾
ä¼å |
| | | List<FilePdfInfo> list = super.list(new LambdaQueryWrapper<FilePdfInfo>(). |
| | | eq(FilePdfInfo::getFileName, fileVo.getPdfName()). |
| | | orderByDesc(FilePdfInfo::getCreateTime) |
| | | ); |
| | | if (list == null || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | BeanMapper.copy(list.get(0),info); |
| | | } |
| | | if (info == null ) { |
| | | return null; |
| | | } |
| | | List<KeyWordPositionVo> workVo = PdfUtils.findListWord(fileUploadFolder + "/" + info.getFilePath() + "/" + info.getFileEncodeName(),fileVo.getPdfContent()); |
| | | if (workVo == null || workVo.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<Integer> sb = new ArrayList<>(); |
| | | for (KeyWordPositionVo key : workVo) { |
| | | sb.add(key.getPage()); |
| | | } |
| | | List<FileImgInfo> list = fileImgInfoService.findFileImgInfos(fileVo.getPdfFileId(),sb); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public FilePdfInfo findNewFilePDF(String fileName) { |
| | | FilePdfInfo info = new FilePdfInfo(); |
| | | List<FilePdfInfo> list = super.list(new LambdaQueryWrapper<FilePdfInfo>(). |
| | | eq(FilePdfInfo::getFileName, fileName). |
| | | orderByDesc(FilePdfInfo::getCreateTime) |
| | | ); |
| | | if (list == null || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | BeanMapper.copy(list.get(0),info); |
| | | return info; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service.imp; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.ai.entity.LanguageModel; |
| | | import org.jeecg.modules.ai.mapper.LanguageModelMapper; |
| | | import org.jeecg.modules.ai.service.ILanguageModelService; |
| | | import org.jeecg.modules.system.util.SecurityUtil; |
| | | import org.jeecg.modules.utils.BeanMapper; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/19 |
| | | */ |
| | | @Service |
| | | public class LanguageModelServiceImpl extends ServiceImpl<LanguageModelMapper,LanguageModel> implements ILanguageModelService { |
| | | |
| | | @Override |
| | | public boolean addLanguageModel(LanguageModel languageModel) { |
| | | if (languageModel == null || languageModel.getAiType() == null) { |
| | | return false; |
| | | } |
| | | LanguageModel model = new LanguageModel(); |
| | | if (languageModel.getAiType() == 1) { |
| | | boolean one =super.save(languageModel); |
| | | if (one) { |
| | | model.setProblem(languageModel.getProblem()); |
| | | model.setParentId(languageModel.getId()); |
| | | model.setAiType(2); |
| | | super.save(model); |
| | | return true; |
| | | } |
| | | } |
| | | else if (languageModel.getAiType() == 2 || languageModel.getAiType() == 3) { |
| | | //æ¥è¯¢ç¶ç±»ID |
| | | super.save(languageModel); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public LanguageModel selectParentId(Integer aiType, String aiId) { |
| | | LanguageModel info = new LanguageModel(); |
| | | List<LanguageModel> list = super.list(new LambdaQueryWrapper<LanguageModel>(). |
| | | eq(LanguageModel::getAiType, aiType). |
| | | eq(LanguageModel::getAiId, aiId). |
| | | orderByDesc(LanguageModel::getCreateTime) |
| | | ); |
| | | if (list == null || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | BeanMapper.copy(list.get(0),info); |
| | | return info; |
| | | } |
| | | |
| | | @Override |
| | | public List<LanguageModel> findListAiTitles() { |
| | | LoginUser user = (LoginUser)SecurityUtils.getSubject().getPrincipal(); |
| | | List<LanguageModel> list = super.list(new LambdaQueryWrapper<LanguageModel>(). |
| | | eq(LanguageModel::getAiType, 1). |
| | | eq(LanguageModel::getCreateBy, user.getUsername()). |
| | | orderByDesc(LanguageModel::getCreateTime) |
| | | ); |
| | | if (list == null || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<LanguageModel> languageProblems(String id) { |
| | | LoginUser user = (LoginUser)SecurityUtils.getSubject().getPrincipal(); |
| | | LambdaQueryWrapper<LanguageModel> wrapperL = new LambdaQueryWrapper<>(); |
| | | wrapperL.eq(LanguageModel::getCreateBy, user.getUsername()); |
| | | wrapperL.eq(LanguageModel::getParentId, id); |
| | | wrapperL.and((wrapper)->wrapper.eq(LanguageModel::getAiType, 2). |
| | | or(). |
| | | eq(LanguageModel::getAiType, 3)); |
| | | wrapperL.orderByAsc(LanguageModel::getCreateTime); |
| | | List<LanguageModel> list = super.list(wrapperL); |
| | | if (list == null || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | return list; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.service.imp; |
| | | |
| | | import org.jeecg.modules.ai.service.IWebSocketAiService; |
| | | import org.jeecg.modules.ai.websocket.AiWebSocket; |
| | | import org.jeecg.modules.utils.AiTestUils; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/8 |
| | | */ |
| | | @Service |
| | | public class WebSocketAiService implements IWebSocketAiService { |
| | | |
| | | |
| | | @Override |
| | | /*@Scheduled(cron = "0/10 * * * * ?")*/ |
| | | public void selectChatIA() { |
| | | String name = "{\"id\":\"683a65fd-8feb-4446-ad32-714c4785f667\",\"messages\":[{\"role\":\"user\",\"content\":\"ç»æè®²ä¸ªæ
äºï¼\"}],\"stream\":true,\"max_tokens\":500}"; // JSONæ°æ® |
| | | String url = "https://836u458t54.vicp.fun/chat/test_chat"; |
| | | String aiPost = AiTestUils.sendJsonToHttpsPost(url, name); |
| | | /*System.out.println(aiPost);*/ |
| | | for (String s : AiWebSocket.getSessionPoolAi().keySet()) { |
| | | AiWebSocket.pushMessage(s,aiPost); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/7 |
| | | */ |
| | | @Data |
| | | public class FilePdfSelectVo { |
| | | private String pdfContent; |
| | | private String pdfName; |
| | | private String pdfPath; |
| | | private String pdfFileId; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.vo; |
| | | |
| | | import com.itextpdf.text.Rectangle; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/7/23 |
| | | * åä½çä½ç½®ä¿¡æ¯ |
| | | */ |
| | | @Data |
| | | public class ItemPosition { |
| | | private Integer page; |
| | | private String text; |
| | | //è¿ä¸ªåçç©å½¢åæ |
| | | private Rectangle rectangle; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/7/23 |
| | | * éè¦é«äº®æ¾ç¤ºçå
³é®ååæ ä¿¡æ¯ |
| | | */ |
| | | @Data |
| | | public class KeyWordPosition { |
| | | private String text; |
| | | private List<ItemPosition> listItem; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.vo; |
| | | |
| | | import com.itextpdf.text.Rectangle; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/7 |
| | | */ |
| | | @Data |
| | | public class KeyWordPositionVo { |
| | | private Integer page; |
| | | private String text; |
| | | //è¿ä¸ªåçç©å½¢åæ |
| | | private Rectangle rectangle; |
| | | private String rectangleString; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.vo; |
| | | |
| | | import com.itextpdf.text.Rectangle; |
| | | import com.itextpdf.text.pdf.parser.ImageRenderInfo; |
| | | import com.itextpdf.text.pdf.parser.TextExtractionStrategy; |
| | | import com.itextpdf.text.pdf.parser.TextRenderInfo; |
| | | import com.itextpdf.text.pdf.parser.Vector; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/7/23 |
| | | * è®°å½ææä½ç½®+åä½ä¿¡æ¯ï¼è¿ç§æ¹å¼è·ååæ ä¿¡æ¯ååä½ä¿¡æ¯æ¹ä¾¿ä¸ç¹ |
| | | * |
| | | */ |
| | | public class MyTextExtractionStrategy implements TextExtractionStrategy { |
| | | private List<ItemPosition> positions; |
| | | private Integer page; |
| | | |
| | | public MyTextExtractionStrategy() {} |
| | | |
| | | public MyTextExtractionStrategy(List<ItemPosition> positions, Integer page) { |
| | | this.positions = positions; |
| | | this.page = page; |
| | | } |
| | | @Override |
| | | public void beginTextBlock() { |
| | | // TODO Auto-generated method stub |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void renderText(TextRenderInfo renderInfo) { |
| | | ItemPosition ItemPosition = new ItemPosition(); |
| | | Vector bottomLeftPoint = renderInfo.getDescentLine().getStartPoint(); |
| | | Vector topRightPoint = renderInfo.getAscentLine().getEndPoint(); |
| | | //è®°å½ç©å½¢åæ |
| | | Rectangle rectangle = new Rectangle(bottomLeftPoint.get(Vector.I1), bottomLeftPoint.get(Vector.I2), |
| | | topRightPoint.get(Vector.I1), topRightPoint.get(Vector.I2)); |
| | | ItemPosition.setPage(page); |
| | | ItemPosition.setRectangle(rectangle); |
| | | ItemPosition.setText(renderInfo.getText()); |
| | | positions.add(ItemPosition); |
| | | } |
| | | |
| | | @Override |
| | | public void endTextBlock() { |
| | | // TODO Auto-generated method stub |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void renderImage(ImageRenderInfo renderInfo) { |
| | | // TODO Auto-generated method stub |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public String getResultantText() { |
| | | // TODO Auto-generated method stub |
| | | return null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/6 |
| | | */ |
| | | @Data |
| | | public class PhotoListVo { |
| | | private Integer pageNumber; |
| | | // æä»¶åç§° ä¸å¸¦åç¼ |
| | | private String imgName; |
| | | |
| | | // æä»¶å å¯åçåç§° |
| | | private String imgEncodeName; |
| | | |
| | | // æä»¶ä¿åç¸å¯¹è·¯å¾ |
| | | private String imgPath; |
| | | |
| | | // æä»¶å¤§å°ï¼KBï¼ |
| | | private Long imgSize; |
| | | |
| | | // æä»¶åç¼ |
| | | private String imgSuffix; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai.websocket; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.base.BaseMap; |
| | | import org.jeecg.common.constant.WebsocketConst; |
| | | import org.jeecg.common.modules.redis.client.JeecgRedisClient; |
| | | import org.jeecg.modules.ai.service.IWebSocketAiService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.PathParam; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/8 |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | @ServerEndpoint("/websocket/ai/{userId}") |
| | | public class AiWebSocket { |
| | | /**线ç¨å®å
¨Map*/ |
| | | private static ConcurrentHashMap<String, Session> sessionPoolAi = new ConcurrentHashMap<>(); |
| | | /** |
| | | * Redis触åçå¬åå |
| | | */ |
| | | public static final String REDIS_TOPIC_NAME_AI = "websocketAiHandler"; |
| | | @Resource |
| | | private JeecgRedisClient jeecgRedisClient; |
| | | |
| | | public static Map<String, Session> getSessionPoolAi() { |
| | | return sessionPoolAi; |
| | | } |
| | | //==========ãwebsocketæ¥åãæ¨éæ¶æ¯çæ¹æ³ ââ å
·ä½æå¡èç¹æ¨éwsæ¶æ¯ã======================================================================================== |
| | | @OnOpen |
| | | public void onOpen(Session session, @PathParam(value = "userId") String userId) { |
| | | try { |
| | | sessionPoolAi.put(userId, session); |
| | | log.info("ãç³»ç» WebSocketãææ°çè¿æ¥ï¼æ»æ°ä¸º:" + sessionPoolAi.size()); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(@PathParam("userId") String userId) { |
| | | try { |
| | | sessionPoolAi.remove(userId); |
| | | log.info("ãç³»ç» WebSocketãè¿æ¥æå¼ï¼æ»æ°ä¸º:" + sessionPoolAi.size()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * wsæ¨éæ¶æ¯ |
| | | * |
| | | * @param userId |
| | | * @param message |
| | | */ |
| | | public static void pushMessage(String userId, String message) { |
| | | |
| | | Session session = sessionPoolAi.get(userId); |
| | | if (session != null && session.isOpen()) { |
| | | try { |
| | | //update-begin-author:taoyan date:20211012 for: websocketæ¥é https://gitee.com/jeecg/jeecg-boot/issues/I4C0MU |
| | | synchronized (session){ |
| | | session.getBasicRemote().sendText(message); |
| | | } |
| | | //update-end-author:taoyan date:20211012 for: websocketæ¥é https://gitee.com/jeecg/jeecg-boot/issues/I4C0MU |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /*for (Map.Entry<String, Session> item : sessionPoolAi.entrySet()) { |
| | | //userId keyå¼= {ç¨æ·id + "_"+ ç»å½tokençmd5串} |
| | | //TODO vue2æªæ¹keyæ°è§åï¼ææ¶ä¸å½±åé»è¾ |
| | | if (item.getKey().contains(userId)) { |
| | | Session session = item.getValue(); |
| | | try { |
| | | //update-begin-author:taoyan date:20211012 for: websocketæ¥é https://gitee.com/jeecg/jeecg-boot/issues/I4C0MU |
| | | synchronized (session){ |
| | | log.info("ãç³»ç» WebSocketãæ¨éåäººæ¶æ¯:" + message); |
| | | session.getBasicRemote().sendText(message); |
| | | } |
| | | //update-end-author:taoyan date:20211012 for: websocketæ¥é https://gitee.com/jeecg/jeecg-boot/issues/I4C0MU |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(),e); |
| | | } |
| | | } |
| | | }*/ |
| | | } |
| | | |
| | | /** |
| | | * wséåç¾¤åæ¶æ¯ |
| | | */ |
| | | public void pushMessage(String message) { |
| | | try { |
| | | for (Map.Entry<String, Session> item : sessionPoolAi.entrySet()) { |
| | | try { |
| | | item.getValue().getAsyncRemote().sendText(message); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | log.info("ãç³»ç» WebSocketãç¾¤åæ¶æ¯:" + message); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * wsæ¥å客æ·ç«¯æ¶æ¯ |
| | | */ |
| | | @OnMessage |
| | | public void onMessage(String message, @PathParam(value = "userId") String userId) { |
| | | if(!"ping".equals(message) && !WebsocketConst.CMD_CHECK.equals(message)){ |
| | | log.info("ãç³»ç» WebSocketãæ¶å°å®¢æ·ç«¯æ¶æ¯:" + message); |
| | | }else{ |
| | | log.debug("ãç³»ç» WebSocketãæ¶å°å®¢æ·ç«¯æ¶æ¯:" + message); |
| | | } |
| | | /* JSONObject obj = new JSONObject(); |
| | | //ä¸å¡ç±»å |
| | | obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_CHECK); |
| | | //æ¶æ¯å
容 |
| | | obj.put(WebsocketConst.MSG_TXT, "å¿è·³ååº");*/ |
| | | /*webSocketAiService.selectChatIA(message);*/ |
| | | /*this.pushMessage(userId, obj.toJSONString());*/ |
| | | |
| | | } |
| | | |
| | | /** |
| | | * é
ç½®é误信æ¯å¤ç |
| | | * |
| | | * @param session |
| | | * @param t |
| | | */ |
| | | @OnError |
| | | public void onError(Session session, Throwable t) { |
| | | log.warn("ãç³»ç» WebSocketãæ¶æ¯åºç°é误"); |
| | | //t.printStackTrace(); |
| | | } |
| | | //==========ãç³»ç» WebSocketæ¥åãæ¨éæ¶æ¯çæ¹æ³ ââ å
·ä½æå¡èç¹æ¨éwsæ¶æ¯ã======================================================================================== |
| | | |
| | | |
| | | //==========ãéç¨redisåå¸è®¢é
模å¼ââæ¨éæ¶æ¯ã======================================================================================== |
| | | /** |
| | | * åå°åéæ¶æ¯å°redis |
| | | * |
| | | * @param message |
| | | */ |
| | | public void sendMessage(String message) { |
| | | BaseMap baseMap = new BaseMap(); |
| | | baseMap.put("userId", ""); |
| | | baseMap.put("message", message); |
| | | jeecgRedisClient.sendMessage(REDIS_TOPIC_NAME_AI, baseMap); |
| | | } |
| | | |
| | | /** |
| | | * æ¤ä¸ºåç¹æ¶æ¯ redis |
| | | * |
| | | * @param userId |
| | | * @param message |
| | | */ |
| | | public void sendMessage(String userId, String message) { |
| | | BaseMap baseMap = new BaseMap(); |
| | | jeecgRedisClient.sendMessage(REDIS_TOPIC_NAME_AI, baseMap); |
| | | } |
| | | |
| | | /** |
| | | * æ¤ä¸ºåç¹æ¶æ¯(å¤äºº) redis |
| | | * |
| | | * @param userIds |
| | | * @param message |
| | | */ |
| | | public void sendMessage(String[] userIds, String message) { |
| | | |
| | | } |
| | | |
| | | // æ¤ä¸ºåç¹æ¶æ¯ |
| | | public void sendOneMessage(String userId, String message) { |
| | | |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.utils; |
| | | |
| | | |
| | | import javax.net.ssl.*; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.DataOutputStream; |
| | | import java.io.InputStream; |
| | | import java.net.URL; |
| | | import java.security.cert.CertificateException; |
| | | import java.security.cert.X509Certificate; |
| | | |
| | | public class AiTestUils { |
| | | |
| | | private static class TrustAnyTrustManager implements X509TrustManager { |
| | | /** |
| | | * è¯¥æ¹æ³æ£æ¥å®¢æ·ç«¯çè¯ä¹¦ï¼è¥ä¸ä¿¡ä»»è¯¥è¯ä¹¦åæåºå¼å¸¸ãç±äºæä»¬ä¸éè¦å¯¹å®¢æ·ç«¯è¿è¡è®¤è¯ï¼å æ¤æä»¬åªéè¦æ§è¡é»è®¤ç信任管çå¨çè¿ |
| | | * ä¸ªæ¹æ³ã |
| | | * JSSEä¸ï¼é»è®¤ç信任管çå¨ç±»ä¸ºTrustManagerã |
| | | */ |
| | | @Override |
| | | public void checkClientTrusted(X509Certificate[] chain, String authType) |
| | | throws CertificateException { |
| | | } |
| | | |
| | | /** |
| | | * è¯¥æ¹æ³æ£æ¥æå¡å¨çè¯ä¹¦ï¼è¥ä¸ä¿¡ä»»è¯¥è¯ä¹¦åæ ·æåºå¼å¸¸ãéè¿èªå·±å®ç°è¯¥æ¹æ³ï¼å¯ä»¥ä½¿ä¹ä¿¡ä»»æä»¬æå®çä»»ä½è¯ä¹¦ã |
| | | * å¨å®ç°è¯¥æ¹æ³æ¶ï¼ä¹å¯ä»¥ç®åçä¸åä»»ä½å¤çï¼ å³ä¸ä¸ªç©ºç彿°ä½ï¼ç±äºä¸ä¼æåºå¼å¸¸ï¼å®å°±ä¼ä¿¡ä»»ä»»ä½è¯ä¹¦ã(non-Javadoc) |
| | | */ |
| | | @Override |
| | | public void checkServerTrusted(X509Certificate[] chain, String authType) |
| | | throws CertificateException { |
| | | } |
| | | |
| | | /** |
| | | * @return è¿ååä¿¡ä»»çX509è¯ä¹¦æ°ç»ã |
| | | */ |
| | | @Override |
| | | public X509Certificate[] getAcceptedIssuers() { |
| | | return new X509Certificate[]{}; |
| | | } |
| | | } |
| | | |
| | | private static class TrustAnyHostnameVerifier implements HostnameVerifier { |
| | | @Override |
| | | public boolean verify(String hostname, SSLSession session) { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * postæ¹å¼è¯·æ±æå¡å¨(httpsåè®®) |
| | | * @param url æ±å°å |
| | | * @param content åæ° |
| | | * @return |
| | | */ |
| | | public static String sendJsonToHttpsPost(String url, String content) { |
| | | try { |
| | | /* |
| | | * ç±»HttpsURLConnectionä¼¼ä¹å¹¶æ²¡ææä¾æ¹æ³è®¾ç½®ä¿¡ä»»ç®¡çå¨ãå
¶å®ï¼ |
| | | * HttpsURLConnectionéè¿SSLSocketæ¥å»ºç«ä¸HTTPSçå®å
¨è¿æ¥ |
| | | * ï¼SSLSocket对象æ¯ç±SSLSocketFactoryçæçã |
| | | * HttpsURLConnectionæä¾äºæ¹æ³setSSLSocketFactory |
| | | * (SSLSocketFactory)设置å®ä½¿ç¨çSSLSocketFactory对象ã |
| | | * SSLSocketFactoryéè¿SSLContext对象æ¥è·å¾ï¼å¨åå§åSSLContext对象æ¶ï¼å¯æå®ä¿¡ä»»ç®¡çå¨å¯¹è±¡ã |
| | | */ |
| | | SSLContext sc = SSLContext.getInstance("SSL"); |
| | | sc.init(null, new TrustManager[]{new TrustAnyTrustManager()}, |
| | | new java.security.SecureRandom()); |
| | | |
| | | URL console = new URL(url); |
| | | HttpsURLConnection conn = (HttpsURLConnection) console.openConnection(); |
| | | conn.setSSLSocketFactory(sc.getSocketFactory()); |
| | | conn.setHostnameVerifier(new TrustAnyHostnameVerifier()); |
| | | conn.setDoOutput(true); |
| | | // 设置请æ±å¤´ |
| | | conn.setRequestProperty("Content-Type", "application/json;charset=utf-8"); |
| | | conn.connect(); |
| | | DataOutputStream out = new DataOutputStream(conn.getOutputStream()); |
| | | out.write(content.getBytes()); |
| | | // å·æ°ãå
³é |
| | | out.flush(); |
| | | out.close(); |
| | | InputStream is = conn.getInputStream(); |
| | | if (is != null) { |
| | | ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[1024]; |
| | | int len = 0; |
| | | while ((len = is.read(buffer)) != -1) { |
| | | outStream.write(buffer, 0, len); |
| | | } |
| | | is.close(); |
| | | return outStream.toString(); |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.utils; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * Created by Administrator on 2015/8/28. |
| | | */ |
| | | @Slf4j |
| | | public class DateUtil { |
| | | public static final String STR_DATE = "yyyy-MM-dd"; |
| | | public static final String STR_YEAR_MONTH = "yyyy-MM"; |
| | | public static final String STR_DATE_TIME = "yyyy-MM-dd HH:mm:ss.SSS"; |
| | | public static final String STR_DATE_TIME_SMALL = "yyyy-MM-dd HH:mm:ss"; |
| | | public static final String STR_DATE_TIME_MIN = "yyyy-MM-dd HH:mm"; |
| | | public static final String STR_DATE_TIME_HOUR = "yyyy-MM-dd HH"; |
| | | public static final String STR_DATE_TIME_FULL = "yyyyMMddHHmmssSSS"; |
| | | public static final String STR_YEARMONTH = "yyyyMM"; |
| | | public static final String STR_YEAR = "yyyy"; |
| | | |
| | | /** |
| | | * è·åå½åæ¶é´ |
| | | * @return |
| | | */ |
| | | public static Date getNow() { |
| | | return new Date(System.currentTimeMillis()); |
| | | } |
| | | |
| | | /** |
| | | * <p> |
| | | * Description: å»ææ¥ææ¶é´ä¸çæ¶é´é¨å |
| | | * </p> |
| | | * å¦: 2013-11-11 18:56:33 ---> 2013-11-11 00:00:00 |
| | | * |
| | | * @param date éè¦ä¿®æ¹çæ¶é´ |
| | | * @return ä¿®æ¹åçæ¶é´ |
| | | */ |
| | | public static Date removeTime(Date date) { |
| | | Date result = null; |
| | | try { |
| | | SimpleDateFormat df = new SimpleDateFormat(STR_DATE); |
| | | String dateStr = df.format(date); |
| | | result = df.parse(dateStr); |
| | | } catch (ParseException e) { |
| | | log.error(e.getMessage(), e.getStackTrace()); |
| | | return null; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * <p> |
| | | * Description: ææå®æ ¼å¼è·åæ¶é´å符串 |
| | | * </p> |
| | | * |
| | | * @param date è¦è½¬æ¢çæ¥æ |
| | | * @param format æ ¼å¼,ä¾å¦:yyyy-MM-dd HH:mm:ss.SSS |
| | | * @return 转æ¢åçæ¶é´å符串 |
| | | */ |
| | | public static String format(Date date, String format) { |
| | | SimpleDateFormat df = new SimpleDateFormat(format); |
| | | return df.format(date); |
| | | } |
| | | |
| | | /** |
| | | * è·åæ¥æç天å符串 |
| | | * @param date |
| | | * @return |
| | | */ |
| | | public static String getDayStr(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); // å¾å°æ¥å |
| | | calendar.setTime(date);// æå½åæ¶é´èµç»æ¥å |
| | | int day = calendar.get(Calendar.DATE);//è·åæ¥ |
| | | String dayStr = day < 10 ? "0" + day : day + ""; |
| | | return dayStr; |
| | | } |
| | | |
| | | /** |
| | | * è·åæ¥æç年份å符串 |
| | | * @param date |
| | | * @return |
| | | */ |
| | | public static String getYearStr(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); // å¾å°æ¥å |
| | | calendar.setTime(date);// æå½åæ¶é´èµç»æ¥å |
| | | String yearStr = calendar.get(Calendar.YEAR) + "";//è·åæ¥ |
| | | return yearStr; |
| | | } |
| | | |
| | | /** |
| | | * è·åæ¥æçæä»½å符串 |
| | | * @param date |
| | | * @return |
| | | */ |
| | | public static String getMonthStr(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); // å¾å°æ¥å |
| | | calendar.setTime(date);// æå½åæ¶é´èµç»æ¥å |
| | | int month = calendar.get(Calendar.MONTH);//è·åæ¥ |
| | | String monthStr = month < 10 ? "0" + month : month + ""; |
| | | return monthStr; |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åæ¶é´ ååi天 |
| | | * 精确å°ç§ |
| | | * @param i ä¸ºæ£æ°ä»£è¡¨å i天ï¼ä¸ºè´æ°ä»£è¡¨åi天 |
| | | * @return |
| | | */ |
| | | public static Date addDay(Date date, int i){ |
| | | Calendar calendar = Calendar.getInstance(); // å¾å°æ¥å |
| | | calendar.setTime(date);// æå½åæ¶é´èµç»æ¥å |
| | | calendar.add(Calendar.DAY_OF_MONTH, i); // 设置天æ°å å |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åæ¶é´ ååiç§ |
| | | * 精确å°ç§ |
| | | * @param i ä¸ºæ£æ°ä»£è¡¨å iç§ï¼ä¸ºè´æ°ä»£è¡¨åiç§ |
| | | * @return |
| | | */ |
| | | public static Date addSeconds(Date date, int i){ |
| | | Calendar calendar = Calendar.getInstance(); // å¾å°æ¥å |
| | | calendar.setTime(date);// æå½åæ¶é´èµç»æ¥å |
| | | calendar.add(Calendar.SECOND, i); // è®¾ç½®ç§æ°å å |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | public static Date toDate(String date, String format) { |
| | | SimpleDateFormat df = new SimpleDateFormat(format); |
| | | try { |
| | | return df.parse(date); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.utils; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.pdfbox.pdmodel.PDDocument; |
| | | import org.apache.pdfbox.rendering.PDFRenderer; |
| | | import org.jeecg.common.util.SHA256Util; |
| | | import org.jeecg.modules.ai.vo.PhotoListVo; |
| | | import org.jeecg.modules.utils.file.FileUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/8/1 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class PdfTurnPngUtils { |
| | | |
| | | private static String filePngPath; |
| | | |
| | | @Value("${jeecg.path.upload}") |
| | | public void setFilePngPath(String filePngPath) { |
| | | PdfTurnPngUtils.filePngPath = filePngPath; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 使ç¨pdfboxå°æ´ä¸ªpdfè½¬æ¢æå¾ç |
| | | * |
| | | * @param fileAddress æä»¶å°å å¦:C:\\Users\\user\\Desktop\\test |
| | | * @param filename PDFæä»¶åä¸å¸¦åç¼å |
| | | * @param type å¾çç±»å png åjpg |
| | | */ |
| | | public static void pdf2png(String fileAddress, String filename, String type) { |
| | | long startTime = System.currentTimeMillis(); |
| | | // å°æä»¶å°ååæä»¶åæ¼æ¥æè·¯å¾ 注æï¼çº¿ä¸ç¯å¢ä¸è½ä½¿ç¨\\æ¼æ¥ |
| | | File file = new File(fileAddress + "\\" + filename + ".pdf"); |
| | | try { |
| | | // åå
¥æä»¶ |
| | | PDDocument doc = PDDocument.load(file); |
| | | PDFRenderer renderer = new PDFRenderer(doc); |
| | | int pageCount = doc.getNumberOfPages(); |
| | | for (int i = 0; i < pageCount ; i++) { |
| | | // dpi为144ï¼è¶é«è¶æ¸
æ°ï¼è½¬æ¢è¶æ
¢ |
| | | BufferedImage image = renderer.renderImageWithDPI(i, 144); // Windows native DPI |
| | | // å°å¾çååºå°è¯¥è·¯å¾ä¸ |
| | | ImageIO.write(image, type, |
| | | new File(fileAddress + "\\å¤ä»½\\" + filename + "_" + (i+1) + "." + type)); |
| | | } |
| | | long endTime = System.currentTimeMillis(); |
| | | System.out.println("å
±èæ¶ï¼" + ((endTime - startTime) / 1000.0) + "ç§"); //转åç¨æ¶ |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | public static List<PhotoListVo> pdf2pngList(File filePdf, String type,String pathImg){ |
| | | PDDocument doc = null; |
| | | try { |
| | | List<PhotoListVo> files = new ArrayList<>(); |
| | | doc = PDDocument.load(filePdf); |
| | | String pdfName = FileUtils.getFilenameNonSuffix(filePdf.getName()); |
| | | if (doc == null ) { |
| | | return null; |
| | | } |
| | | PDFRenderer renderer = new PDFRenderer(doc); |
| | | int pageCount = doc.getNumberOfPages(); |
| | | Date currentDate = DateUtil.getNow(); |
| | | String monthStr = DateUtil.format(currentDate, DateUtil.STR_YEAR_MONTH); |
| | | String relativePath = "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/"+ pathImg + "/"; |
| | | //ç»å¯¹è·¯å¾ |
| | | String absolutePath = filePngPath + "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/" + pathImg + "/"; |
| | | for (int i = 0; i < pageCount ; i++) { |
| | | PhotoListVo pVo = new PhotoListVo(); |
| | | // dpi为144ï¼è¶é«è¶æ¸
æ°ï¼è½¬æ¢è¶æ
¢ |
| | | BufferedImage image = renderer.renderImageWithDPI(i, 144); // Windows native DPI 144 |
| | | // å°å¾çååºå°è¯¥è·¯å¾ä¸ |
| | | //æä»¶è·¯å¾ |
| | | //ç¸å¯¹è·¯å¾ |
| | | String encodeFileName = SHA256Util.getSHA256Str(pdfName + "_" + (i+1) + System.currentTimeMillis()); |
| | | String imgPath = absolutePath + "/" + encodeFileName + "." + type; |
| | | File targetFile = new File(imgPath); |
| | | if(!targetFile.getParentFile().exists()){ |
| | | targetFile.getParentFile().mkdirs(); |
| | | } |
| | | ImageIO.write(image, type, targetFile); |
| | | pVo.setImgEncodeName(encodeFileName + "." + type); |
| | | pVo.setImgName(pdfName + "_" + (i+1)); |
| | | pVo.setImgSize(Long.valueOf(new File(imgPath).length())); |
| | | pVo.setImgSuffix(type); |
| | | pVo.setPageNumber(i+1); |
| | | pVo.setImgPath(relativePath); |
| | | files.add(pVo); |
| | | } |
| | | return files; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.utils; |
| | | |
| | | import com.itextpdf.text.BaseColor; |
| | | import com.itextpdf.text.DocumentException; |
| | | import com.itextpdf.text.pdf.PdfContentByte; |
| | | import com.itextpdf.text.pdf.PdfReader; |
| | | import com.itextpdf.text.pdf.PdfStamper; |
| | | import com.itextpdf.text.pdf.parser.PdfTextExtractor; |
| | | import org.jeecg.modules.ai.vo.ItemPosition; |
| | | import org.jeecg.modules.ai.vo.KeyWordPosition; |
| | | import org.jeecg.modules.ai.vo.KeyWordPositionVo; |
| | | import org.jeecg.modules.ai.vo.MyTextExtractionStrategy; |
| | | |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/7/23 |
| | | */ |
| | | public class PdfUtils { |
| | | /** |
| | | * ç¨äºä¾å¤é¨ç±»è°ç¨è·åå
³é®åæå¨PDFæä»¶åæ |
| | | * @param filepath |
| | | * @param keyWords |
| | | * @return |
| | | */ |
| | | public static List<KeyWordPosition> getKeyWordsByPath(String filepath, String keyWords) { |
| | | List<KeyWordPosition> matchItems = null; |
| | | try{ |
| | | PdfReader pdfReader = new PdfReader(filepath); |
| | | matchItems = getKeyWords(pdfReader, keyWords); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return matchItems; |
| | | } |
| | | |
| | | /** |
| | | * è·åå
³é®åæå¨PDFåæ |
| | | * @param pdfReader |
| | | * @param keyWords |
| | | * @return |
| | | */ |
| | | private static List<KeyWordPosition> getKeyWords(PdfReader pdfReader, String keyWords) { |
| | | int page = 0; |
| | | |
| | | List<KeyWordPosition> matchItems = new ArrayList<>(); |
| | | try{ |
| | | int pageNum = pdfReader.getNumberOfPages(); |
| | | StringBuilder allText = null; |
| | | |
| | | //éå页 |
| | | for (page = 1; page <= pageNum; page++) { |
| | | //åªè®°å½å½é¡µçææå
容ï¼éè¦è®°å½å
¨é¨é¡µæ¾å¨å¾ªç¯å¤é¢ |
| | | List<ItemPosition> allItems = new ArrayList<>(); |
| | | //æ«æå
容 |
| | | MyTextExtractionStrategy myTextExtractionStrategy = new MyTextExtractionStrategy(allItems, page); |
| | | PdfTextExtractor.getTextFromPage(pdfReader, page, myTextExtractionStrategy); |
| | | //å½é¡µçæåå
容ï¼ç¨äºå
³é®è¯å¹é
|
| | | allText = new StringBuilder(); |
| | | //ä¸ä¸ªåä¸ä¸ªåçéå |
| | | for (int i=0; i<allItems.size(); i++) { |
| | | ItemPosition item = allItems.get(i); |
| | | allText.append(item.getText()); |
| | | //å
³é®ååå¨è¿ç»å¤ä¸ªåä¸ |
| | | if(allText.indexOf(keyWords) != -1) { |
| | | KeyWordPosition keyWordPosition = new KeyWordPosition(); |
| | | //è®°å½å
³é®è¯æ¯ä¸ªåçä½ç½®ï¼åªè®°å½å¼å§ç»ææ è®°æ¶ä¼æé®é¢ |
| | | List<ItemPosition> listItem = new ArrayList<>(); |
| | | for(int j=i-keyWords.length()+1; j<=i; j++) { |
| | | listItem.add(allItems.get(j)); |
| | | } |
| | | keyWordPosition.setListItem(listItem); |
| | | keyWordPosition.setText(keyWords); |
| | | matchItems.add(keyWordPosition); |
| | | allText.setLength(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return matchItems; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | String keyword = "䏿¦åçæºåºå®å
¨äºæ
"; |
| | | String sourcePdf = "F:\\123.pdf"; |
| | | String watermarkPdf = "F:\\12_bak.pdf"; |
| | | Long start = System.currentTimeMillis(); |
| | | System.out.println("å¼å§æ«æ...."); |
| | | List<KeyWordPosition> matchItems = getKeyWordsByPath(sourcePdf, keyword); |
| | | System.out.println(matchItems); |
| | | System.out.println("æ«æç»æ["+(System.currentTimeMillis()-start)+"ms]ï¼å
±æ¾å°å
³é®å["+keyword+"]åºç°["+matchItems.size()+"]次"); |
| | | start = System.currentTimeMillis(); |
| | | System.out.println("å¼å§æ·»å æ è®°...."); |
| | | andRectangleMark(sourcePdf |
| | | , watermarkPdf |
| | | , matchItems |
| | | , BaseColor.RED |
| | | , 2 |
| | | , 2); |
| | | //æä»¶æ´ç |
| | | System.out.println("æ è®°æ·»å 宿["+(System.currentTimeMillis()-start)+"ms]"); |
| | | |
| | | } |
| | | |
| | | |
| | | public static List<KeyWordPositionVo> findListWord(String sourcePath, String keyWord){ |
| | | System.out.println("å¼å§æ«æ...."); |
| | | try { |
| | | List<KeyWordPositionVo> matchItems = getKeyWordsByPathOne(sourcePath, keyWord); |
| | | return matchItems; |
| | | }catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç¨äºä¾å¤é¨ç±»è°ç¨è·åå
³é®åæå¨PDFæä»¶åæ |
| | | * @param filepath |
| | | * @param keyWords |
| | | * @return |
| | | */ |
| | | public static List<KeyWordPositionVo> getKeyWordsByPathOne(String filepath, String keyWords) { |
| | | List<KeyWordPositionVo> matchItems = null; |
| | | try{ |
| | | PdfReader pdfReader = new PdfReader(filepath); |
| | | matchItems = getKeyWordPage(pdfReader, keyWords); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return matchItems; |
| | | } |
| | | |
| | | /** |
| | | * è·åå
³é®åæå¨PDFåæ ä¸é¡µåªåç¬¬ä¸æ¡ |
| | | * @param pdfReader |
| | | * @param keyWords |
| | | * @return |
| | | */ |
| | | private static List<KeyWordPositionVo> getKeyWordPage(PdfReader pdfReader, String keyWords) { |
| | | int page = 0; |
| | | List<KeyWordPositionVo> matchItems = new ArrayList<>(); |
| | | try{ |
| | | int pageNum = pdfReader.getNumberOfPages(); |
| | | StringBuilder allText = null; |
| | | //éå页 |
| | | for (page = 1; page <= pageNum; page++) { |
| | | //åªè®°å½å½é¡µçææå
容ï¼éè¦è®°å½å
¨é¨é¡µæ¾å¨å¾ªç¯å¤é¢ |
| | | List<ItemPosition> allItems = new ArrayList<>(); |
| | | //æ«æå
容 |
| | | MyTextExtractionStrategy myTextExtractionStrategy = new MyTextExtractionStrategy(allItems, page); |
| | | PdfTextExtractor.getTextFromPage(pdfReader, page, myTextExtractionStrategy); |
| | | //å½é¡µçæåå
容ï¼ç¨äºå
³é®è¯å¹é
|
| | | allText = new StringBuilder(); |
| | | //ä¸ä¸ªåä¸ä¸ªåçéå |
| | | for (int i=0; i<allItems.size(); i++) { |
| | | ItemPosition item = allItems.get(i); |
| | | allText.append(item.getText()); |
| | | //å
³é®ååå¨è¿ç»å¤ä¸ªåä¸ |
| | | if(allText.indexOf(keyWords) != -1) { |
| | | KeyWordPosition keyWordPosition = new KeyWordPosition(); |
| | | //è®°å½å
³é®è¯æ¯ä¸ªåçä½ç½®ï¼åªè®°å½å¼å§ç»ææ è®°æ¶ä¼æé®é¢ |
| | | KeyWordPositionVo vo = new KeyWordPositionVo(); |
| | | for(int j=i-keyWords.length()+1; j<=i; j++) { |
| | | if (allItems.get(j).getText().indexOf(keyWords)!= -1) { |
| | | vo.setPage(allItems.get(j).getPage()); |
| | | vo.setRectangle(allItems.get(j).getRectangle()); |
| | | vo.setText(allItems.get(j).getText()); |
| | | vo.setRectangleString(allItems.get(j).getRectangle().toString()); |
| | | matchItems.add(vo); |
| | | break; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return matchItems; |
| | | } |
| | | |
| | | /** |
| | | * æ·»å ç©å½¢æ è®° |
| | | * @param oldPath |
| | | * @param newPath |
| | | * @param matchItems å
³é®è¯ |
| | | * @param color æ è®°é¢è² |
| | | * @param lineWidth 线æ¡ç²ç» |
| | | * @param padding è¾¹æ¡å
è¾¹è· |
| | | * @throws DocumentException |
| | | * @throws IOException |
| | | */ |
| | | public static void andRectangleMark(String oldPath, String newPath, List<KeyWordPosition> matchItems, BaseColor color, int lineWidth, int padding) throws DocumentException, IOException{ |
| | | // å¾
å æ°´å°çæä»¶ |
| | | PdfReader reader = new PdfReader(oldPath); |
| | | // å 宿°´å°çæä»¶ |
| | | PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newPath)); |
| | | |
| | | PdfContentByte content; |
| | | |
| | | // 设置åä½ |
| | | // 循ç¯å¯¹æ¯é¡µæå
¥æ°´å° |
| | | for (KeyWordPosition keyWordPosition:matchItems) |
| | | { |
| | | //ä¸ä¸ªå
³é®è¯çææååæ |
| | | List<ItemPosition> oneKeywordItems = keyWordPosition.getListItem(); |
| | | for(int i=0; i<oneKeywordItems.size(); i++) { |
| | | ItemPosition item = oneKeywordItems.get(i); |
| | | ItemPosition preItem = i==0?null:oneKeywordItems.get(i-1); |
| | | //å¸¦ç¡®å®æ¯å¦æ°´å° |
| | | |
| | | // æ°´å°çèµ·å§ |
| | | content = stamper.getOverContent(item.getPage()); |
| | | // å¼å§åå
¥æ°´å° |
| | | content.setLineWidth(lineWidth); |
| | | content.setColorStroke(color); |
| | | System.out.println(item.toString()); |
| | | |
| | | //åºçº¿ |
| | | content.moveTo(item.getRectangle().getLeft()-padding, item.getRectangle().getBottom()-padding); |
| | | content.lineTo(item.getRectangle().getRight()+padding, item.getRectangle().getBottom()-padding); |
| | | if(i!=0 && preItem!=null && (preItem.getRectangle().getBottom()-padding)==(item.getRectangle().getBottom()-padding) && (preItem.getRectangle().getRight()+padding)!=(item.getRectangle().getLeft()-padding)) { |
| | | content.moveTo(preItem.getRectangle().getRight()+padding, preItem.getRectangle().getBottom()-padding); |
| | | content.lineTo(item.getRectangle().getLeft()-padding, item.getRectangle().getBottom()-padding); |
| | | } |
| | | //ä¸çº¿ |
| | | content.moveTo(item.getRectangle().getLeft()-padding, item.getRectangle().getTop()+padding); |
| | | content.lineTo(item.getRectangle().getRight()+padding, item.getRectangle().getTop()+padding); |
| | | if(i!=0 && preItem!=null && (preItem.getRectangle().getTop()+padding)==(item.getRectangle().getTop()+padding) && (preItem.getRectangle().getRight()+padding)!=(item.getRectangle().getLeft()-padding)) { |
| | | content.moveTo(preItem.getRectangle().getRight()+padding, preItem.getRectangle().getTop()+padding); |
| | | content.lineTo(item.getRectangle().getLeft()-padding, item.getRectangle().getTop()+padding); |
| | | } |
| | | |
| | | //左线 |
| | | if(i==0) { |
| | | content.moveTo(item.getRectangle().getLeft()-padding, item.getRectangle().getBottom()-padding); |
| | | content.lineTo(item.getRectangle().getLeft()-padding, item.getRectangle().getTop()+padding); |
| | | } |
| | | //å³çº¿ |
| | | if(i==(oneKeywordItems.size()-1)) { |
| | | content.moveTo(item.getRectangle().getRight()+padding, item.getRectangle().getBottom()-padding); |
| | | content.lineTo(item.getRectangle().getRight()+padding, item.getRectangle().getTop()+padding); |
| | | } |
| | | |
| | | content.stroke(); |
| | | } |
| | | } |
| | | stamper.close(); |
| | | } |
| | | } |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.utils.file; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.api.vo.FileUploadResult; |
| | | import org.jeecg.common.util.SHA256Util; |
| | | import org.jeecg.modules.utils.DateUtil; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.util.Date; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class FileUtils { |
| | | |
| | | private static String fileUploadFolder; |
| | | |
| | | @Value("${jeecg.path.upload}") |
| | | public void setFileUploadFolder(String fileUploadFolder) { |
| | | FileUtils.fileUploadFolder = fileUploadFolder; |
| | | } |
| | | |
| | | /** |
| | | * æä»¶è·¯å¾ä¸ä¼ ä¿å |
| | | * @param filePath |
| | | * @return |
| | | */ |
| | | public static FileUploadResult uploadFilePath(String filePath) { |
| | | File file = new File(filePath); |
| | | if(file == null) { |
| | | return null; |
| | | } |
| | | String fileName = file.getName(); |
| | | String suffix = getFileSuffix(fileName); |
| | | Date currentDate = DateUtil.getNow(); |
| | | String monthStr = DateUtil.format(currentDate, DateUtil.STR_YEAR_MONTH); |
| | | //ç¸å¯¹è·¯å¾ |
| | | String relativePath = "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/"; |
| | | //ç»å¯¹è·¯å¾ |
| | | String absolutePath = fileUploadFolder + "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/"; |
| | | String fileNameNonSuffix = getFilenameNonSuffix(fileName); |
| | | if(fileNameNonSuffix == null) |
| | | return null; |
| | | String encodeFileName = SHA256Util.getSHA256Str(fileNameNonSuffix + System.currentTimeMillis()); |
| | | if(StringUtils.isNotBlank(suffix)) { |
| | | encodeFileName = encodeFileName + "." + suffix; |
| | | } |
| | | Long b = uploadFileInput(file, absolutePath, encodeFileName); |
| | | FileUploadResult dto = new FileUploadResult(); |
| | | dto.setFileName(fileNameNonSuffix); |
| | | dto.setFilePath(encodeFileName); |
| | | dto.setFilePath(relativePath); |
| | | dto.setFileSize(b); |
| | | dto.setFileSuffix(suffix); |
| | | return dto; |
| | | } |
| | | |
| | | /** |
| | | * æä»¶Fileä¸ä¼ ä¿å |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public static FileUploadResult uploadFileInFile(File file) { |
| | | if(file == null) { |
| | | return null; |
| | | } |
| | | String fileName = file.getName(); |
| | | String suffix = getFileSuffix(fileName); |
| | | Date currentDate = DateUtil.getNow(); |
| | | String monthStr = DateUtil.format(currentDate, DateUtil.STR_YEAR_MONTH); |
| | | //ç¸å¯¹è·¯å¾ |
| | | String relativePath = "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/"; |
| | | //ç»å¯¹è·¯å¾ |
| | | String absolutePath = fileUploadFolder + "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/"; |
| | | String fileNameNonSuffix = getFilenameNonSuffix(fileName); |
| | | if(fileNameNonSuffix == null) { |
| | | return null; |
| | | } |
| | | String encodeFileName = SHA256Util.getSHA256Str(fileNameNonSuffix + System.currentTimeMillis()); |
| | | if(StringUtils.isNotBlank(suffix)) { |
| | | encodeFileName = encodeFileName + "." + suffix; |
| | | } |
| | | Long b = uploadFileInput(file, absolutePath, encodeFileName); |
| | | FileUploadResult dto = new FileUploadResult(); |
| | | dto.setFileName(fileNameNonSuffix); |
| | | dto.setFileEncodeName(encodeFileName); |
| | | dto.setFilePath(relativePath); |
| | | dto.setFileSize(b); |
| | | dto.setFileSuffix(suffix); |
| | | return dto; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * MultipartFile æ¹å¼ä¿å |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public static FileUploadResult uploadMultipartFile(MultipartFile file) { |
| | | if(file == null || file.isEmpty()) { |
| | | return null; |
| | | } |
| | | String fileName = file.getOriginalFilename(); |
| | | String suffix = getFileSuffix(fileName); |
| | | Date currentDate = DateUtil.getNow(); |
| | | String monthStr = DateUtil.format(currentDate, DateUtil.STR_YEAR_MONTH); |
| | | //ç¸å¯¹è·¯å¾ |
| | | String relativePath = "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/"; |
| | | //ç»å¯¹è·¯å¾ |
| | | String absolutePath = fileUploadFolder + "/" + monthStr + "/" + DateUtil.getDayStr(currentDate) + "/"; |
| | | String fileNameNonSuffix = getFilenameNonSuffix(fileName); |
| | | if(fileNameNonSuffix == null) |
| | | return null; |
| | | String encodeFileName = SHA256Util.getSHA256Str(fileNameNonSuffix + System.currentTimeMillis()); |
| | | Long fileSize = file.getSize(); |
| | | if(StringUtils.isNotBlank(suffix)) { |
| | | encodeFileName = encodeFileName + "." + suffix; |
| | | } |
| | | boolean b = uploadFile(file, absolutePath, encodeFileName); |
| | | if(!b) |
| | | return null; |
| | | FileUploadResult dto = new FileUploadResult(); |
| | | dto.setFileName(fileNameNonSuffix); |
| | | dto.setFilePath(encodeFileName); |
| | | dto.setFilePath(relativePath); |
| | | dto.setFileSize(fileSize); |
| | | dto.setFileSuffix(suffix); |
| | | return dto; |
| | | } |
| | | |
| | | public static void downLoadFile(HttpServletResponse response, String fileName, String filePath, String toFileName) { |
| | | String absolutePath = fileUploadFolder + filePath; |
| | | File file = new File(absolutePath , fileName); |
| | | if(file.exists()) { |
| | | byte[] buffer = new byte[1024]; |
| | | FileInputStream fis = null; |
| | | BufferedInputStream bis = null; |
| | | try { |
| | | response.setHeader("Content-Type", "application/octet-stream;charset=utf-8"); // åè¯æµè§å¨è¾åºå
å®¹ä¸ºæµ |
| | | response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(toFileName, "UTF-8")); |
| | | fis = new FileInputStream(file); |
| | | bis = new BufferedInputStream(fis); |
| | | OutputStream os = response.getOutputStream(); |
| | | int i = bis.read(buffer); |
| | | while (i != -1) { |
| | | os.write(buffer, 0, i); |
| | | i = bis.read(buffer); |
| | | } |
| | | }catch (Exception e) { |
| | | log.error(e.getMessage(), e.getStackTrace()); |
| | | }finally { |
| | | if(bis != null) { |
| | | try { |
| | | bis.close(); |
| | | } catch (IOException e) { |
| | | } |
| | | } |
| | | if(fis != null) { |
| | | try { |
| | | fis.close(); |
| | | } catch (IOException e) { |
| | | } |
| | | } |
| | | } |
| | | }else { |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * ä¸ä¼ æä»¶å·¥å
·ç±» |
| | | * @param file |
| | | * @param path |
| | | * @param fileNewName æ°çæä»¶å |
| | | * @return |
| | | */ |
| | | public static Long uploadFileInput(File file, String path, String fileNewName) { |
| | | File targetFile = new File(path, fileNewName); |
| | | if(!targetFile.getParentFile().exists()){ |
| | | targetFile.getParentFile().mkdirs(); |
| | | } |
| | | try { |
| | | FileInputStream fis = new FileInputStream(file); |
| | | FileOutputStream fos = new FileOutputStream(targetFile); |
| | | //FileInputStream fis = new FileInputStream(file); |
| | | byte[] bytes = new byte[1024 * 4]; |
| | | int index = 0; |
| | | long total = 0; |
| | | while ((index = fis.read(bytes)) != -1) { |
| | | fos.write(bytes, 0, index); |
| | | total =+ index; |
| | | } |
| | | fis.close(); |
| | | fos.flush(); |
| | | fos.close(); |
| | | return total; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e.getStackTrace()); |
| | | return 0L; |
| | | } |
| | | } |
| | | /** |
| | | * ä¸ä¼ æä»¶å·¥å
·ç±» |
| | | * @param multipartFile |
| | | * @param path |
| | | * @param fileNewName æ°çæä»¶å |
| | | * @return |
| | | */ |
| | | public static boolean uploadFile(MultipartFile multipartFile, String path, String fileNewName) { |
| | | File targetFile = new File(path, fileNewName); |
| | | if(!targetFile.getParentFile().exists()){ |
| | | targetFile.getParentFile().mkdirs(); |
| | | } |
| | | try { |
| | | multipartFile.transferTo(targetFile); |
| | | return true; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e.getStackTrace()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åæä»¶åç¼ æ åç¼æä»¶è¿åNULL |
| | | * @param fileName |
| | | * @return |
| | | */ |
| | | public static String getFileSuffix(String fileName) { |
| | | if (fileName.contains(".")) { |
| | | String suffix = fileName.substring(fileName.lastIndexOf('.') + 1); |
| | | return suffix; |
| | | }else { |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * è·åæä»¶å ä¸å¸¦åç¼åç¹å· |
| | | * @param fileName |
| | | * @return |
| | | */ |
| | | public static String getFilenameNonSuffix(String fileName) { |
| | | if (fileName.contains(".")) { |
| | | String filename = fileName.substring(0, fileName.lastIndexOf('.')); |
| | | return filename; |
| | | }else { |
| | | return fileName; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | public static String checkFileEncode(File file) { |
| | | String charset = "GBK"; |
| | | byte[] first3Bytes = new byte[3]; |
| | | BufferedInputStream bis = null; |
| | | try { |
| | | boolean checked = false; |
| | | bis = new BufferedInputStream(new FileInputStream(file)); |
| | | bis.mark(0); |
| | | int read = bis.read(first3Bytes, 0, 3); |
| | | if (read == -1) |
| | | return charset; |
| | | if(first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE ) { |
| | | charset = "UTF-16LE"; |
| | | checked = true; |
| | | }else if ( first3Bytes[0] == (byte) 0xFE && first3Bytes[1] == (byte) 0xFF ) { |
| | | charset = "UTF-16BE"; |
| | | checked = true; |
| | | }else if (first3Bytes[0] == (byte) 0xEF && first3Bytes[1] == (byte) 0xBB && first3Bytes[2] == (byte) 0xBF ) { |
| | | charset = "UTF-8"; |
| | | checked = true; |
| | | } |
| | | bis.reset(); |
| | | if (!checked) { |
| | | while ((read = bis.read()) != -1 ) { |
| | | if ( read >= 0xF0 ) |
| | | break; |
| | | if ( 0x80 <= read && read <= 0xBF ) // åç¬åºç°BF以ä¸çï¼ä¹ç®æ¯GBK |
| | | break; |
| | | if ( 0xC0 <= read && read <= 0xDF ) { |
| | | read = bis.read(); |
| | | if ( 0x80 <= read && read <= 0xBF ) // ååè (0xC0 - 0xDF) (0x80 - 0xBF),ä¹å¯è½å¨GBKç¼ç å
  |
| | | continue; |
| | | else |
| | | break; |
| | | } else if ( 0xE0 <= read && read <= 0xEF ) { |
| | | // 乿å¯è½åºéï¼ä½æ¯å çè¾å° |
| | | read = bis.read(); |
| | | if ( 0x80 <= read && read <= 0xBF ) { |
| | | read = bis.read(); |
| | | if ( 0x80 <= read && read <= 0xBF ) { |
| | | charset = "UTF-8"; |
| | | break; |
| | | } else |
| | | break; |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return charset; |
| | | }catch (Exception e) { |
| | | return null; |
| | | }finally { |
| | | if(bis != null) { |
| | | try { |
| | | bis.close(); |
| | | } catch (IOException e) { |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
| | | import org.springframework.context.ConfigurableApplicationContext; |
| | | import org.springframework.core.env.Environment; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | |
| | | @Slf4j |
| | | @SpringBootApplication |
| | | //@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class}) |
| | | @EnableScheduling |
| | | public class JeecgSystemApplication extends SpringBootServletInitializer { |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) throws UnknownHostException { |
| | | ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemApplication.class, args); |
| | | ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemApplication.class, args); |
| | | Environment env = application.getEnvironment(); |
| | | String ip = InetAddress.getLocalHost().getHostAddress(); |
| | | String port = env.getProperty("server.port"); |
| | |
| | | connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 |
| | | datasource: |
| | | master: |
| | | url: jdbc:postgresql://192.168.253.133:5432/ai_service?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai |
| | | url: jdbc:postgresql://192.168.3.184:5432/ai_service_weiyi?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai |
| | | username: postgres |
| | | password: ABC@13579 |
| | | password: 123456 |
| | | driverClassName: org.postgresql.Driver |
| | | #redis é
ç½® |
| | | redis: |
| | |
| | | pc: http://localhost:3100 |
| | | app: http://localhost:8051 |
| | | path: |
| | | #æä»¶ä¸ä¼ æ ¹ç®å½ 设置 |
| | | #æä»¶ä¸ä¼ æ ¹ç®å½ 设置 /home/weiyi/anaconda3/envs/aiservice |
| | | upload: C://opt//upFiles |
| | | #webappæä»¶è·¯å¾ |
| | | webapp: C://opt//upFiles |
| | |
| | | # appSecret |
| | | client-secret: ?? |
| | | agent-id: ?? |
| | | webservice: |
| | | url: http://localhost:8081/services/EquipmentService?wsdl |
| | | namespace: http://service.server.webservice.example.com |
| | | statusMethod: equipmentStatus |
| | | rateMethod: equipmentRate |
| | |
| | | connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 |
| | | datasource: |
| | | master: |
| | | url: jdbc:sqlserver://195.0.1.10:1433;databasename=SSGX_kns |
| | | username: sa |
| | | password: Sa123456789 |
| | | driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver |
| | | url: jdbc:postgresql://192.168.253.133:5432/ai_service?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai |
| | | username: postgres |
| | | password: ABC@13579 |
| | | driverClassName: org.postgresql.Driver |
| | | #redis é
ç½® |
| | | redis: |
| | | database: 0 |
| | | host: 127.0.0.1 |
| | | port: 6379 |
| | | password: |
| | | password: '' |
| | | #mybatis plus 设置 |
| | | mybatis-plus: |
| | | mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml |
| | |
| | | pc: http://localhost:3100 |
| | | app: http://localhost:8051 |
| | | path: |
| | | #æä»¶ä¸ä¼ æ ¹ç®å½ 设置 |
| | | #æä»¶ä¸ä¼ æ ¹ç®å½è®¾ç½® |
| | | upload: C://opt//upFiles |
| | | #webappæä»¶è·¯å¾ |
| | | webapp: C://opt//upFiles |
| | |
| | | #code_generate_project_path |
| | | project_path=F:\\java_workspace |
| | | #bussi_package[User defined] |
| | | bussi_package=org.jeecg.modules.mdc |
| | | bussi_package=org.jeecg.modules.ai |
| | | |
| | | |
| | | #default code path |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.ai; |
| | | |
| | | import org.jeecg.JeecgSystemApplication; |
| | | import org.jeecg.modules.ai.service.IFilePdfInfoService; |
| | | import org.jeecg.modules.ai.service.IWebSocketAiService; |
| | | import org.jeecg.modules.ai.vo.FilePdfSelectVo; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | |
| | | import java.io.File; |
| | | |
| | | /** |
| | | * @author clown |
| | | * * @date 2024/7/16 |
| | | */ |
| | | |
| | | @RunWith(SpringRunner.class) |
| | | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class) |
| | | public class AiTest { |
| | | |
| | | @Autowired |
| | | private IFilePdfInfoService filePdfInfoService; |
| | | @Autowired |
| | | private IWebSocketAiService webSocketAiService; |
| | | |
| | | @Test |
| | | public void selectChatIA() { |
| | | webSocketAiService.selectChatIA(); |
| | | } |
| | | |
| | | @Test |
| | | public void filePdf() { |
| | | // æå®æä»¶å¤¹è·¯å¾ |
| | | String directoryPath = "F:\\file"; |
| | | // å建File对象表示æä»¶å¤¹ |
| | | File directory = new File(directoryPath); |
| | | // è·åæä»¶å¤¹ä¸æææä»¶åæä»¶å¤¹ |
| | | File[] files = directory.listFiles(); |
| | | // æ£æ¥æä»¶æ°ç»æ¯å¦ä¸ºç©ºä»¥åæ¯å¦å卿件 |
| | | if (files != null && files.length > 0) { |
| | | // éåæä»¶æ°ç»ï¼æå°æ¯ä¸ªæä»¶çåå |
| | | for (File file : files) { |
| | | if (file.isFile()) { // ç¡®ä¿æ¯æä»¶èéæä»¶å¤¹ |
| | | System.out.println(file.getName()); |
| | | filePdfInfoService.uploadFilePdf |
| | | (new File(directoryPath + "\\" + file.getName())); |
| | | } |
| | | } |
| | | } else { |
| | | System.out.println("æä»¶å¤¹ä¸ºç©ºæä¸åå¨ã"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void filePdfImg() { |
| | | FilePdfSelectVo vo = new FilePdfSelectVo(); |
| | | vo.setPdfContent("åé¿"); |
| | | vo.setPdfFileId("1821103772084142082"); |
| | | filePdfInfoService.findImgPathList(vo); |
| | | } |
| | | |
| | | @Test |
| | | public void sendJsonToHttpsPost() { |
| | | /* String name = "{\"id\":\"683a65fd-8feb-4446-ad32-714c4785f667\",\"messages\":[{\"role\":\"user\",\"content\":\"ç»æè®²ä¸ªæ
äºï¼\"}],\"stream\":true,\"max_tokens\":500}"; // JSONæ°æ® |
| | | String url = "https://836u458t54.vicp.fun/chat/test_chat"; |
| | | String aiPost = AiTestUils.sendJsonToHttpsPost(url, name); |
| | | System.out.println(aiPost);*/ |
| | | |
| | | String s = "\"data\": {\"id\": \"683a65fd-8feb-4446-ad32-714c4785f667\", \"created\": 1723105518, \"model\": \"YxCareer0.7\", \"choices\": [{\"index\": 0, \"delta\": {\"role\": \"assistant\", \"content\": \"\"}, \"finish_reason\": null}]}"; |
| | | System.out.println(s); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | <artifactId>pegdown</artifactId> |
| | | <version>${pegdown.version}</version> |
| | | </dependency> |
| | | <!--使ç¨itextpdfï¼æ¯pdfboxç®åäº--> |
| | | <dependency> |
| | | <groupId>com.itextpdf</groupId> |
| | | <artifactId>itextpdf</artifactId> |
| | | <version>5.5.13.2</version> |
| | | </dependency> |
| | | <!--å¿
é¡»å å
¥è¿ä¸ªï¼å¦å䏿ä¼ä¹±ç æä¸ºç©º--> |
| | | <dependency> |
| | | <groupId>com.itextpdf</groupId> |
| | | <artifactId>itext-asian</artifactId> |
| | | <version>5.2.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>net.sourceforge.tess4j</groupId> |
| | | <artifactId>tess4j</artifactId> |
| | | <version>4.5.1</version> |
| | | </dependency> |
| | | |
| | | |
| | | </dependencies> |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | <dependencyManagement> |
| | | <dependencies> |
| | | <!-- spring-cloud--> |