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;
/**
*
* 专利关键词高亮 服务类
*
*
* @author 王岩
* @since 2022-03-18
*/
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PatentKeywordsHighlightService extends ServiceImpl {
private final LoginUtils loginUtils;
public PatentKeywordsHighlight initPatentKeywordsHighlight(Integer projectId, Integer userId, Boolean _default, String name) {
List configs = new ArrayList<>();
List colors = new ArrayList() {{
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 getPatentKeywordsHighlight(PatentKeywordsHighlightVO params) {
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PatentKeywordsHighlight::getProjectId, params.getProjectId());
queryWrapper.eq(PatentKeywordsHighlight::getUserId, loginUtils.getId());
List 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);
}
}