修改srms接口

This commit is contained in:
梁琦涛
2024-01-24 14:33:13 +08:00
parent 019cd9bf86
commit 1189670ffd
5 changed files with 106 additions and 43 deletions
@@ -58,10 +58,10 @@
<if test="standard.partCategoryName != '' and standard.partCategoryName != null">
and l1.name = #{standard.partCategoryName}
</if>
<if test="standard.hasSplit == '1'">
<if test="standard.hasSplit == 1">
and s1.split_result = '成功'
</if>
<if test="standard.hasSplit == '2'">
<if test="standard.hasSplit == 2">
and s1.split_result is null
</if>
</where>
@@ -101,20 +101,27 @@
<select id="getByLawsStandardPage" resultType="com.jero.modules.docking.srms.vo.StandardPageVO">
select laws.* from (
SELECT
id,standard_number,standard_name,standard_english_name,standard_state,standard_system,release_date,implementation_date,part_name as partCategoryNum
id,standard_number,standard_name,standard_english_name,standard_state,standard_system,
DATE_FORMAT( release_date, '%Y-%m-%d' ) AS release_date,
DATE_FORMAT( implementation_date, '%Y-%m-%d' ) AS implementation_date,
part_name as partCategoryNum
FROM laws_domestic_standard
union all
SELECT
id,standard_number,standard_name,standard_english_name,standard_state,standard_system,release_date,implementation_date,part_name as partCategoryNum
id,standard_number,standard_name,standard_english_name,standard_state,standard_system,
DATE_FORMAT( release_date, '%Y-%m-%d' ) AS release_date,
DATE_FORMAT( implementation_date, '%Y-%m-%d' ) AS implementation_date,
part_name as partCategoryNum
FROM laws_enterprise_standard
union all
SELECT
id,standard_number,standard_name,standard_english_name,standard_state,standard_system,release_date,implementation_date,part_name as partCategoryNum
id,standard_number,standard_name,standard_english_name,standard_state,standard_system,
DATE_FORMAT( release_date, '%Y-%m-%d' ) AS release_date,
DATE_FORMAT( implementation_date, '%Y-%m-%d' ) AS implementation_date,
part_name as partCategoryNum
FROM laws_overseas_standard
) laws
left join laws_node_relation l on l.unique_relation_flag = laws.id
<where>
${ew.sqlSegment}
</where>
where ${ew.sqlSegment}
</select>
</mapper>
@@ -7,9 +7,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.CaseFormat;
import com.google.common.base.Charsets;
import com.jero.common.api.vo.Result;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.util.JwtUtil;
import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.MD5Util;
import com.jero.common.util.RedisUtil;
import com.jero.common.util.TokenUtils;
import com.jero.modules.docking.srms.dto.ByTokenRequests;
@@ -35,13 +39,16 @@ import com.jero.modules.tag.enums.TableNameEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.regexp.RE;
import org.apache.shiro.SecurityUtils;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -80,6 +87,19 @@ public class SrmsApiServiceImpl implements SrmsApiService {
private String appKey;
@Value("${srms.secret}")
private String secret;
@Value("${srms.font_url_pdf}")
private String fontUrlPdf;
@Value("${srms.back_url_pdf}")
private String backUrlPdf;
@Value("${srms.font_url_other}")
private String fontUrlOther;
@Value("${srms.back_url_other}")
private String backUrlOther;
@Value("${srms.other_md5_mark}")
private String otherMd5Mark;
private static final String SRMS_TOKEN = "srms_token_";
private static final String REQUESTS = "Requests";
@@ -154,7 +174,7 @@ public class SrmsApiServiceImpl implements SrmsApiService {
standardVO.setStandardState(standardState);
// 是否存在拆分信息,默认false; true-是,false-否
setHasSplit(requests, standardVO);
List<ByFileRows> listByFileRows = getByFileRows(partCategoryNum, standardVO);
List<ByFileRows> listByFileRows = getByFileRows(partCategoryNum, standardVO,token);
return Result.OK(listByFileRows);
}catch (Exception e){
log.error("标准法规文档查询异常:",e);
@@ -163,7 +183,7 @@ public class SrmsApiServiceImpl implements SrmsApiService {
}
@Nullable
private List<ByFileRows> getByFileRows(String partCategoryNum, StandardVO standardVO) {
private List<ByFileRows> getByFileRows(String partCategoryNum, StandardVO standardVO,String token) {
List<ByFileRows> listByFileRows = lawsStandardMapper.getStandard(standardVO);
if(CollectionUtils.isEmpty(listByFileRows)) {
return listByFileRows;
@@ -190,7 +210,7 @@ public class SrmsApiServiceImpl implements SrmsApiService {
List<OSSFile> listFile = listOssFile.stream().filter(o-> Objects.equals(o.getStandardId(),byFileRows.getId())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(listFile)){
listFile = listFile.stream().sorted(Comparator.comparing(OSSFile::getCreateTime).reversed()).collect(Collectors.toList());
byFileRows.setStandardUrl(listFile.get(0).getUrl());
byFileRows.setStandardUrl(getUrl(listFile.get(0),token));
}
}
LambdaQueryWrapper<SarFileSplitInfoEO> querySarFileSplitInfoEo = new LambdaQueryWrapper<>();
@@ -318,16 +338,15 @@ public class SrmsApiServiceImpl implements SrmsApiService {
}
try {
List<StandardTree> listStandardTreeAll = new ArrayList<>();
// 企业标准
List<LawsTreeNodeModel> listEnterprise = lawsTreeNodeService.queryTreeNodeList(TableNameEnum.ENTERPRISE_STANDARDS.getValue(), nodeName, "1");
getStandardTree(listStandardTreeAll, listEnterprise);
// 国内标准
List<LawsTreeNodeModel> listDomestic = lawsTreeNodeService.queryTreeNodeList(TableNameEnum.DOMESTIC_REGULATIONS.getValue(), nodeName, "1");
getStandardTree(listStandardTreeAll, listDomestic);
// 海外标准
List<LawsTreeNodeModel> listForeign = lawsTreeNodeService.queryTreeNodeList(TableNameEnum.FOREIGN_REGULATIONS.getValue(), nodeName, "1");
getStandardTree(listStandardTreeAll, listForeign);
// 企业标准
List<LawsTreeNodeModel> listEnterprise = lawsTreeNodeService.queryTreeNodeList(TableNameEnum.ENTERPRISE_STANDARDS.getValue(), nodeName, "1");
getStandardTree(listStandardTreeAll, listEnterprise);
return Result.OK(listStandardTreeAll);
}catch (Exception e){
log.error("获取所有体系数据异常:",e);
@@ -382,6 +401,7 @@ public class SrmsApiServiceImpl implements SrmsApiService {
if(StringUtils.isBlank(token) || !Objects.equals(TokenUtils.getTokenByRequest(req),token)){
return Result.error(SYS_ERR);
}
JSONObject requests = JSON.parseObject(JSON.toJSONString(json.get(REQUESTS)));
if(Objects.isNull(requests)){
return Result.error(ADD_NOT_NULL);
@@ -414,12 +434,13 @@ public class SrmsApiServiceImpl implements SrmsApiService {
}
Page<StandardPageVO> page = new Page<>(Long.parseLong(requests.get(pageNoKey).toString()),
Long.parseLong(requests.get(pageSizeKey).toString()));
IPage<StandardPageVO> pageList =lawsStandardMapper.getByLawsStandardPage(page,queryStandardPageVO);
getListStandardPageVO(pageList);
IPage<StandardPageVO> pageList = lawsStandardMapper.getByLawsStandardPage(page,queryStandardPageVO);
getListStandardPageVO(pageList,token);
return Result.OK(pageList);
}
private void setQuery(JSONObject requests, QueryWrapper<StandardPageVO> queryStandardPageVO) {
queryStandardPageVO.eq("'1'","1");
String nodeCodeKey = "nodeCode";
if(requests.containsKey(nodeCodeKey) && !StringUtils.isEmpty(requests.get(nodeCodeKey).toString())){
String nodeCode = requests.get(nodeCodeKey).toString();
@@ -437,19 +458,20 @@ public class SrmsApiServiceImpl implements SrmsApiService {
private void setOrder(QueryWrapper<StandardPageVO> queryStandardPageVO, String[] column, String[] order) {
for (int i = 0; i < column.length; i++) {
String c = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, column[i]);
if(Objects.isNull(order)){
queryStandardPageVO.orderByDesc(column[i]);
queryStandardPageVO.orderByDesc(c);
}else{
if(Objects.equals(order[i],"asc") || Objects.equals(order[i],"ASC")){
queryStandardPageVO.orderByAsc(column[i]);
queryStandardPageVO.orderByAsc(c);
}else{
queryStandardPageVO.orderByDesc(column[i]);
queryStandardPageVO.orderByDesc(c);
}
}
}
}
private void getListStandardPageVO(IPage<StandardPageVO> pageList) {
private void getListStandardPageVO(IPage<StandardPageVO> pageList,String token) {
List<StandardPageVO> listStandardPageVO = pageList.getRecords();
if(CollectionUtils.isEmpty(listStandardPageVO)){
return;
@@ -463,6 +485,29 @@ public class SrmsApiServiceImpl implements SrmsApiService {
List<OSSFile> listOssFile = ossFileService.list(queryOssFile);
List<StandardPageVO> listStandardPageVOPartName = listStandardPageVO.stream().filter(o->!StringUtils.isBlank(o.getPartCategoryNum())).collect(Collectors.toList());
List<PartName> listPartName = getPartNames(listStandardPageVOPartName);
for (StandardPageVO standardPageVO : listStandardPageVO) {
standardPageVO.setStandardState_dictText(sysBaseAPI.translateDict("standard_state", standardPageVO.getStandardState()));
if(!CollectionUtils.isEmpty(listOssFile)){
List<OSSFile> listOssFileOne = listOssFile.stream().filter(o-> Objects.equals(o.getStandardId(),standardPageVO.getId())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(listOssFileOne)){
listOssFileOne = listOssFileOne.stream().sorted(Comparator.comparing(OSSFile::getCreateTime).reversed()).collect(Collectors.toList());
standardPageVO.setStandardUrl(getUrl(listOssFileOne.get(0),token));
}
}
// 零件号查询
if(!CollectionUtils.isEmpty(listPartName) && !StringUtils.isBlank(standardPageVO.getPartCategoryNum())){
List<PartName> listPartNameNew = listPartName.stream().filter(o->Arrays.asList(standardPageVO.getPartCategoryNum().split(",")).contains(o.getCode())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(listPartNameNew)){
List<String> listName = listPartNameNew.stream().map(PartName::getName).collect(Collectors.toList());
standardPageVO.setPartCategoryName(String.join(",",listName));
}
}
}
}
private List<PartName> getPartNames(List<StandardPageVO> listStandardPageVOPartName) {
List<PartName> listPartName = new ArrayList<>();
if(!CollectionUtils.isEmpty(listStandardPageVOPartName)){
List<String> listPartCategoryNum = listStandardPageVOPartName.stream().map(StandardPageVO::getPartCategoryNum).collect(Collectors.toList());
@@ -473,24 +518,29 @@ public class SrmsApiServiceImpl implements SrmsApiService {
listPartName = partNameService.list(queryPartName);
}
}
return listPartName;
}
for (StandardPageVO standardPageVO : listStandardPageVO) {
standardPageVO.setStandardState_dictText(sysBaseAPI.translateDict("standard_state", standardPageVO.getStandardState()));
if(!CollectionUtils.isEmpty(listOssFile)){
List<OSSFile> listOssFileOne = listOssFile.stream().filter(o-> Objects.equals(o.getStandardId(),standardPageVO.getId())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(listOssFileOne)){
listOssFileOne = listOssFileOne.stream().sorted(Comparator.comparing(OSSFile::getCreateTime).reversed()).collect(Collectors.toList());
standardPageVO.setStandardUrl(listOssFileOne.get(0).getUrl());
}
}
// 零件号查询
if(!CollectionUtils.isEmpty(listPartName)){
List<PartName> listPartNameNew = listPartName.stream().filter(o->Arrays.asList(standardPageVO.getPartCategoryNum().split(",")).contains(o.getCode())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(listPartNameNew)){
List<String> listName = listPartNameNew.stream().map(PartName::getName).collect(Collectors.toList());
standardPageVO.setPartCategoryName(String.join(",",listName));
}
private String getUrl(OSSFile ossFile,String token){
String url = "";
try{
if(ossFile.getFileName().toUpperCase().lastIndexOf(".PDF") > 0){
// 拼接url pdf预览
String back = backUrlPdf.replace("{id}",ossFile.getId()).replace("{token}",token);
url = fontUrlPdf.replace("{back_url_pdf}", URLEncoder.encode(back, StandardCharsets.UTF_8.name()));
}else{
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String mark = loginUser.getUsername() + loginUser.getRealname() + LocalDateTime.now();
String markMd5 = MD5Util.MD5Encode(mark + otherMd5Mark,null);
String backOther = backUrlOther.replace("{id}",ossFile.getId()).replace("{token}",token)
.replace("{file_name}",ossFile.getFileName());
url = fontUrlOther.replace("{back_url_other}",URLEncoder.encode(Base64.getEncoder().encodeToString(backOther.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8.name()))
.replace("{mark}",URLEncoder.encode(mark, StandardCharsets.UTF_8.name()))
.replace("{mark_md5}",markMd5);
}
}catch (Exception e){
log.error("拼接url异常",e);
}
return url;
}
}