123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package cn.cslg.pas.service;
- import cn.cslg.pas.common.model.vo.PatentKeywordsHighlightVO;
- import cn.cslg.pas.common.utils.JsonUtils;
- import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
- import cn.cslg.pas.mapper.PatentKeywordsHighlightMapper;
- import cn.cslg.pas.domain.PatentKeywordsHighlight;
- import cn.dev33.satoken.stp.StpUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import lombok.RequiredArgsConstructor;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * <p>
- * 专利关键词高亮 服务类
- * </p>
- *
- * @author 王岩
- * @since 2022-03-18
- */
- @Service
- @RequiredArgsConstructor(onConstructor_ = {@Lazy})
- public class PatentKeywordsHighlightService extends ServiceImpl<PatentKeywordsHighlightMapper, PatentKeywordsHighlight> {
- private final LoginUtils loginUtils;
- public PatentKeywordsHighlight initPatentKeywordsHighlight(Integer projectId, Integer userId, Boolean _default, String name) {
- List<PatentKeywordsHighlight.Config> configs = new ArrayList<>();
- List<String> colors = new ArrayList<String>() {{
- add("#5470c6");
- add("#91cc75");
- add("#fac858");
- add("#ee6666");
- add("#73c0de");
- }};
- for (String color : colors) {
- PatentKeywordsHighlight.Config config = new PatentKeywordsHighlight.Config();
- config.setKeywords("");
- config.setColor(color);
- configs.add(config);
- }
- PatentKeywordsHighlight patentKeywordsHighlight = new PatentKeywordsHighlight();
- patentKeywordsHighlight.setEnable(false);
- patentKeywordsHighlight.setName(name);
- patentKeywordsHighlight.setUserId(userId);
- patentKeywordsHighlight.setProjectId(projectId);
- patentKeywordsHighlight.setConfig(JsonUtils.objectToJson(configs));
- patentKeywordsHighlight.setConfigs(configs);
- patentKeywordsHighlight.setDefault(_default);
- patentKeywordsHighlight.insert();
- return patentKeywordsHighlight;
- }
- public List<PatentKeywordsHighlight> getPatentKeywordsHighlight(PatentKeywordsHighlightVO params) {
- LambdaQueryWrapper<PatentKeywordsHighlight> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(PatentKeywordsHighlight::getProjectId, params.getProjectId());
- queryWrapper.eq(PatentKeywordsHighlight::getUserId, loginUtils.getId());
- List<PatentKeywordsHighlight> dataList = this.list(queryWrapper);
- if (dataList.size() == 0) {
- dataList.add(this.initPatentKeywordsHighlight(params.getProjectId(), loginUtils.getId(), true, "默认模板"));
- }
- dataList.forEach(item -> {
- item.setConfigs(JsonUtils.jsonToList(item.getConfig(), PatentKeywordsHighlight.Config.class));
- item.setConfig(null);
- });
- return dataList;
- }
- public void updatePatentKeywordsHighlight(PatentKeywordsHighlight patentKeywordsHighlight) {
- patentKeywordsHighlight.setConfig(JsonUtils.objectToJson(patentKeywordsHighlight.getConfigs()));
- patentKeywordsHighlight.setUserId(loginUtils.getId());
- patentKeywordsHighlight.insertOrUpdate();
- }
- public void deletePatentKeywordsHighById(Integer id) {
- this.removeById(id);
- }
- }
|