PatentKeywordsHighlightService.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.model.vo.PatentKeywordsHighlightVO;
  3. import cn.cslg.pas.common.utils.JsonUtils;
  4. import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
  5. import cn.cslg.pas.mapper.PatentKeywordsHighlightMapper;
  6. import cn.cslg.pas.domain.PatentKeywordsHighlight;
  7. import cn.dev33.satoken.stp.StpUtil;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  10. import lombok.RequiredArgsConstructor;
  11. import org.springframework.context.annotation.Lazy;
  12. import org.springframework.stereotype.Service;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. /**
  16. * <p>
  17. * 专利关键词高亮 服务类
  18. * </p>
  19. *
  20. * @author 王岩
  21. * @since 2022-03-18
  22. */
  23. @Service
  24. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  25. public class PatentKeywordsHighlightService extends ServiceImpl<PatentKeywordsHighlightMapper, PatentKeywordsHighlight> {
  26. private final LoginUtils loginUtils;
  27. public PatentKeywordsHighlight initPatentKeywordsHighlight(Integer projectId, Integer userId, Boolean _default, String name) {
  28. List<PatentKeywordsHighlight.Config> configs = new ArrayList<>();
  29. List<String> colors = new ArrayList<String>() {{
  30. add("#5470c6");
  31. add("#91cc75");
  32. add("#fac858");
  33. add("#ee6666");
  34. add("#73c0de");
  35. }};
  36. for (String color : colors) {
  37. PatentKeywordsHighlight.Config config = new PatentKeywordsHighlight.Config();
  38. config.setKeywords("");
  39. config.setColor(color);
  40. configs.add(config);
  41. }
  42. PatentKeywordsHighlight patentKeywordsHighlight = new PatentKeywordsHighlight();
  43. patentKeywordsHighlight.setEnable(false);
  44. patentKeywordsHighlight.setName(name);
  45. patentKeywordsHighlight.setUserId(userId);
  46. patentKeywordsHighlight.setProjectId(projectId);
  47. patentKeywordsHighlight.setConfig(JsonUtils.objectToJson(configs));
  48. patentKeywordsHighlight.setConfigs(configs);
  49. patentKeywordsHighlight.setDefault(_default);
  50. patentKeywordsHighlight.insert();
  51. return patentKeywordsHighlight;
  52. }
  53. public List<PatentKeywordsHighlight> getPatentKeywordsHighlight(PatentKeywordsHighlightVO params) {
  54. LambdaQueryWrapper<PatentKeywordsHighlight> queryWrapper = new LambdaQueryWrapper<>();
  55. queryWrapper.eq(PatentKeywordsHighlight::getProjectId, params.getProjectId());
  56. queryWrapper.eq(PatentKeywordsHighlight::getUserId, loginUtils.getId());
  57. List<PatentKeywordsHighlight> dataList = this.list(queryWrapper);
  58. if (dataList.size() == 0) {
  59. dataList.add(this.initPatentKeywordsHighlight(params.getProjectId(), loginUtils.getId(), true, "默认模板"));
  60. }
  61. dataList.forEach(item -> {
  62. item.setConfigs(JsonUtils.jsonToList(item.getConfig(), PatentKeywordsHighlight.Config.class));
  63. item.setConfig(null);
  64. });
  65. return dataList;
  66. }
  67. public void updatePatentKeywordsHighlight(PatentKeywordsHighlight patentKeywordsHighlight) {
  68. patentKeywordsHighlight.setConfig(JsonUtils.objectToJson(patentKeywordsHighlight.getConfigs()));
  69. patentKeywordsHighlight.setUserId(loginUtils.getId());
  70. patentKeywordsHighlight.insertOrUpdate();
  71. }
  72. public void deletePatentKeywordsHighById(Integer id) {
  73. this.removeById(id);
  74. }
  75. }