|
@@ -16,6 +16,7 @@ import com.dragonsoft.duceap.core.search.enums.SearchOperator;
|
|
import com.dragonsoft.smtools.enums.SM3SignStrategy;
|
|
import com.dragonsoft.smtools.enums.SM3SignStrategy;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -54,8 +55,8 @@ public class CodeGmServiceImpl implements ICodeGmService {
|
|
}
|
|
}
|
|
String digest = codeGmSign.getDigest();
|
|
String digest = codeGmSign.getDigest();
|
|
String origin = codeRecord.getLabel() + codeRecord.getValue();
|
|
String origin = codeRecord.getLabel() + codeRecord.getValue();
|
|
- String summary = sm3SignStrategy.summary(origin);
|
|
|
|
- if(!summary.equals(digest)){
|
|
|
|
|
|
+ boolean verify = sm3SignStrategy.verify(origin, digest);
|
|
|
|
+ if(!verify){
|
|
throw new GmIntegrityException();
|
|
throw new GmIntegrityException();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -77,6 +78,7 @@ public class CodeGmServiceImpl implements ICodeGmService {
|
|
return ResponseStatus.success();
|
|
return ResponseStatus.success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional
|
|
@Override
|
|
@Override
|
|
public ResponseStatus codeGmSign(String codeId) {
|
|
public ResponseStatus codeGmSign(String codeId) {
|
|
List<CodeRecord> codeRecords = CodeInfoUtils.getCodeListByCodeDicId(codeId);
|
|
List<CodeRecord> codeRecords = CodeInfoUtils.getCodeListByCodeDicId(codeId);
|
|
@@ -84,13 +86,18 @@ public class CodeGmServiceImpl implements ICodeGmService {
|
|
ArrayList<CodeRecord> collect = codeRecords.stream()
|
|
ArrayList<CodeRecord> collect = codeRecords.stream()
|
|
.collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
|
.collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
|
new TreeSet<>(Comparator.comparing(codeRecord -> codeRecord.getLabel() + StrUtil.COMMA + codeRecord.getValue()))), ArrayList::new));
|
|
new TreeSet<>(Comparator.comparing(codeRecord -> codeRecord.getLabel() + StrUtil.COMMA + codeRecord.getValue()))), ArrayList::new));
|
|
|
|
+ List<CodeGmSign> signs = getCodeGmSignByCodeId(codeId);
|
|
|
|
+ Map<String, CodeGmSign> signMap = signs.stream().collect(Collectors.toMap(item -> item.getCode(), item -> item, (oldOne, lastOne) -> lastOne));
|
|
for (CodeRecord codeRecord : collect) {
|
|
for (CodeRecord codeRecord : collect) {
|
|
- CodeGmSign codeGmSign = new CodeGmSign();
|
|
|
|
- codeGmSign.setCodeId(codeId);
|
|
|
|
- codeGmSign.setCode(codeRecord.getValue());
|
|
|
|
|
|
+ CodeGmSign sign = signMap.get(codeRecord.getValue());
|
|
|
|
+ if(sign == null){
|
|
|
|
+ sign = new CodeGmSign();
|
|
|
|
+ }
|
|
String summary = sm3SignStrategy.summary(codeRecord.getLabel() + codeRecord.getValue());
|
|
String summary = sm3SignStrategy.summary(codeRecord.getLabel() + codeRecord.getValue());
|
|
- codeGmSign.setDigest(summary);
|
|
|
|
- codeGmBPO.save(codeGmSign);
|
|
|
|
|
|
+ sign.setCodeId(codeId);
|
|
|
|
+ sign.setCode(codeRecord.getValue());
|
|
|
|
+ sign.setDigest(summary);
|
|
|
|
+ codeGmBPO.saveOrUpdate(sign);
|
|
}
|
|
}
|
|
return ResponseStatus.success();
|
|
return ResponseStatus.success();
|
|
}
|
|
}
|