package cn.huge.module.knowledge.service;
|
|
import cn.huge.base.common.exception.ServiceException;
|
import cn.huge.base.common.utils.DateUtils;
|
import cn.huge.base.common.utils.IdUtils;
|
import cn.huge.module.client.api.impl.UtilsClientImpl;
|
import cn.huge.module.knowledge.dao.mapper.DyhCaseInfoMapper;
|
import cn.huge.module.knowledge.domain.dto.CaseYearCountDTO;
|
import cn.huge.module.knowledge.domain.dto.CategoryCountDTO;
|
import cn.huge.module.knowledge.domain.dto.DictionaryDTO;
|
import cn.huge.module.knowledge.domain.dto.DyhCaseInfoDTO;
|
import cn.huge.module.knowledge.domain.dto.DyhCaseDetailDTO;
|
import cn.huge.module.knowledge.domain.po.DyhCaseInfo;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.PostConstruct;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.HashMap;
|
|
/**
|
* @title: 调解案件信息表业务逻辑处理
|
* @Description 调解案件信息表业务逻辑处理
|
* @company hugeinfo
|
* @author huangh
|
* @Time 2024-12-20 10:02:00
|
* @version 1.0.0
|
*/
|
@Slf4j
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
public class DyhCaseInfoService extends ServiceImpl<DyhCaseInfoMapper, DyhCaseInfo>{
|
|
@Autowired
|
private DyhCaseInfoMapper mapper;
|
|
@Autowired
|
private UtilsClientImpl utilsClient;
|
|
/**
|
* 更新对象
|
* @param entity 对象
|
*/
|
public void updateDyhCaseInfo(DyhCaseInfo entity){
|
try{
|
mapper.updateDyhCaseInfo(entity);
|
}catch (Exception e){
|
log.error("[DyhCaseInfoService.updateDyhCaseInfo]调用失败,异常信息:"+e, e);
|
throw new ServiceException("DyhCaseInfoService.updateDyhCaseInfo", e);
|
}
|
}
|
|
/**
|
* 条件更新对象
|
* @param entity 对象
|
* @param terms 条件
|
*/
|
public void updateDyhCaseInfoTerms(DyhCaseInfo entity, Map<String, Object> terms){
|
try{
|
mapper.updateDyhCaseInfoTerms(entity, terms);
|
}catch (Exception e){
|
log.error("[DyhCaseInfoService.updateDyhCaseInfoTerms]调用失败,异常信息:"+e, e);
|
throw new ServiceException("DyhCaseInfoService.updateDyhCaseInfoTerms", e);
|
}
|
}
|
|
/**
|
* 根据编号物理删除
|
* @param id 查询条件集合
|
*/
|
public void deleteDyhCaseInfo(String id){
|
try{
|
mapper.deleteDyhCaseInfo(id);
|
}catch (Exception e){
|
log.error("[DyhCaseInfoService.deleteDyhCaseInfo]调用失败,异常信息:"+e, e);
|
throw new ServiceException("DyhCaseInfoService.deleteDyhCaseInfo", e);
|
}
|
}
|
|
/**
|
* 按条件查询
|
* @param terms 条件
|
* @return List
|
*/
|
public List<DyhCaseInfo> listTerms(Map<String, Object> terms){
|
return mapper.listTerms(terms);
|
}
|
|
/**
|
* 按条件统计
|
* @param terms 条件
|
* @return long
|
*/
|
public long countTerms(Map<String, Object> terms){
|
return mapper.countTerms(terms);
|
}
|
|
|
/**
|
* 各类别统计
|
* @return List<CategoryCountDTO>
|
*/
|
public List<DictionaryDTO> categoryCount(Map<String, Object> terms){
|
try{
|
DictionaryDTO yearCountDictionaryDTO = new DictionaryDTO();
|
yearCountDictionaryDTO.setName("发生时间");
|
yearCountDictionaryDTO.setChildren(new ArrayList<>());
|
List<CategoryCountDTO> yearCount = this.yearCount(terms);
|
for (CategoryCountDTO category : yearCount) {
|
DictionaryDTO dictionary = new DictionaryDTO();
|
BeanUtils.copyProperties(category, dictionary);
|
yearCountDictionaryDTO.getChildren().add(dictionary);
|
}
|
|
DictionaryDTO areaCountDictionaryDTO = new DictionaryDTO();
|
areaCountDictionaryDTO.setName("纠纷发生地");
|
areaCountDictionaryDTO.setChildren(new ArrayList<>());
|
List<CategoryCountDTO> areaCount = this.areaCount(terms);
|
for (CategoryCountDTO category : areaCount) {
|
DictionaryDTO dictionary = new DictionaryDTO();
|
BeanUtils.copyProperties(category, dictionary);
|
areaCountDictionaryDTO.getChildren().add(dictionary);
|
}
|
List<DictionaryDTO> categoryCount = new ArrayList<>();
|
categoryCount.add(yearCountDictionaryDTO);
|
categoryCount.add(areaCountDictionaryDTO);
|
return categoryCount;
|
}catch (Exception e){
|
log.error("[CpwsCaseInfoService.categoryCount]调用失败,异常信息:"+e, e);
|
throw new ServiceException("CpwsCaseInfoService.categoryCount", e);
|
}
|
}
|
|
/**
|
* 年份统计
|
* @return List<CategoryCountDTO>
|
*/
|
public List<CategoryCountDTO> yearCount(Map<String, Object> terms){
|
try{
|
return mapper.yearCount(terms);
|
}catch (Exception e){
|
log.error("[CpwsCaseInfoService.yearCount]调用失败,异常信息:"+e, e);
|
throw new ServiceException("CpwsCaseInfoService.yearCount", e);
|
}
|
|
}
|
|
/**
|
* 根据编号查询案件描述和调解协议
|
* @return List<CategoryCountDTO>
|
*/
|
public DyhCaseInfo getDyhCaseById(String id){
|
try{
|
return mapper.getDyhCaseById(id);
|
}catch (Exception e){
|
log.error("[CpwsCaseInfoService.yearCount]调用失败,异常信息:"+e, e);
|
throw new ServiceException("CpwsCaseInfoService.yearCount", e);
|
}
|
}
|
|
/**
|
* 区域统计
|
* @return List<CategoryCountDTO>
|
*/
|
public List<CategoryCountDTO> areaCount(Map<String, Object> terms){
|
try{
|
return mapper.areaCount(terms);
|
}catch (Exception e){
|
log.error("[CpwsCaseInfoService.yearCount]调用失败,异常信息:"+e, e);
|
throw new ServiceException("CpwsCaseInfoService.yearCount", e);
|
}
|
|
}
|
|
/**
|
* 按条件分页查询
|
* @param page 分页对象
|
* @param terms 条件
|
* @return Page
|
*/
|
public Page<DyhCaseInfoDTO> pageQuery(PageRequest page, Map<String, Object> terms){
|
long total = mapper.countTerms(terms);
|
List<DyhCaseInfoDTO> content = mapper.pageTerms(page, terms);
|
return new PageImpl<>(content, page, total);
|
}
|
|
/**
|
* 新增或更新对象
|
* @param dyhCaseInfo 实体对象
|
*/
|
public void saveDyhCaseInfo(DyhCaseInfo dyhCaseInfo){
|
try{
|
Date nowDate = DateUtils.getNowDate();
|
// 判断是否新增
|
if (IdUtils.checkNewId(dyhCaseInfo.getId())){
|
dyhCaseInfo.setId(utilsClient.getNewTimeId());
|
dyhCaseInfo.setCreateTime(nowDate);
|
}
|
dyhCaseInfo.setUpdateTime(nowDate);
|
this.saveOrUpdate(dyhCaseInfo);
|
}catch (Exception e){
|
log.error("[DyhCaseInfoService.saveDyhCaseInfo]调用失败,异常信息:"+e, e);
|
throw new ServiceException("DyhCaseInfoService.saveDyhCaseInfo", e);
|
}
|
}
|
|
/**
|
* 获取案件详情信息(隐私化处理)
|
* @param id 案件ID
|
* @return DyhCaseDetailDTO
|
*/
|
public DyhCaseDetailDTO getCaseDetail(String id) {
|
try {
|
DyhCaseDetailDTO caseDetail = mapper.getCaseDetail(id);
|
if (caseDetail != null) {
|
// 创建DyhCaseInfo对象用于隐私化处理
|
DyhCaseInfo caseInfo = new DyhCaseInfo();
|
BeanUtils.copyProperties(caseDetail, caseInfo);
|
log.info("caseInfo:{}",caseInfo);
|
// 进行隐私化处理
|
DyhCaseInfo processedCase = privacyProcessing(caseInfo);
|
log.info("processedCase:{}",processedCase);
|
// 将处理后的结果复制回DTO
|
BeanUtils.copyProperties(processedCase, caseDetail);
|
|
}
|
return caseDetail;
|
} catch (Exception e) {
|
log.error("[DyhCaseInfoService.getCaseDetail]调用失败,异常信息:"+e, e);
|
throw new ServiceException("DyhCaseInfoService.getCaseDetail", e);
|
}
|
}
|
|
/**
|
* 根据ID查询案件标题(隐私化处理)
|
* @param id 案件ID
|
* @return DyhCaseInfo 仅包含id和caseTitle
|
*/
|
public DyhCaseInfo getCaseTitleById(String id) {
|
try {
|
DyhCaseInfo caseInfo = mapper.getCaseTitleById(id);
|
if (caseInfo != null) {
|
DyhCaseInfo processedCase = privacyProcessing(caseInfo);
|
// 只保留需要的字段
|
caseInfo.setCaseTitle(processedCase.getCaseTitle());
|
|
}
|
return caseInfo;
|
} catch (Exception e) {
|
log.error("[DyhCaseInfoService.getCaseTitleById]调用失败,异常信息:"+e, e);
|
throw new ServiceException("DyhCaseInfoService.getCaseTitleById", e);
|
}
|
}
|
|
/**
|
* 对案件信息中的姓名进行隐私化处理
|
* @param caseInfo 案件信息对象
|
* @return 处理后的案件信息对象
|
*/
|
public DyhCaseInfo privacyProcessing(DyhCaseInfo caseInfo) {
|
try {
|
if (caseInfo == null) {
|
return null;
|
}
|
|
// 处理原告和被告信息
|
String plaintiffs = caseInfo.getPlaintiffs();
|
String defendants = caseInfo.getDefendants();
|
|
if (plaintiffs != null && !plaintiffs.isEmpty()) {
|
String[] plaintiffArray = plaintiffs.split(",");
|
String[] newPlaintiffs = new String[plaintiffArray.length];
|
|
for (int i = 0; i < plaintiffArray.length; i++) {
|
newPlaintiffs[i] = processName(plaintiffArray[i]);
|
}
|
|
// 处理重名情况
|
newPlaintiffs = handleDuplicateNames(newPlaintiffs);
|
|
// 更新原告信息
|
caseInfo.setPlaintiffs(String.join(",", newPlaintiffs));
|
|
// 在案件描述和调解协议中替换姓名
|
for (int i = 0; i < plaintiffArray.length; i++) {
|
String oldName = plaintiffArray[i];
|
String newName = newPlaintiffs[i];
|
|
if (caseInfo.getCaseDes() != null) {
|
caseInfo.setCaseDes(caseInfo.getCaseDes().replace(oldName, newName));
|
}
|
if (caseInfo.getAgreeContent() != null) {
|
caseInfo.setAgreeContent(caseInfo.getAgreeContent().replace(oldName, newName));
|
}
|
if (caseInfo.getCaseTitle() != null) {
|
caseInfo.setCaseTitle(caseInfo.getCaseTitle().replace(oldName, newName));
|
}
|
}
|
}
|
|
if (defendants != null && !defendants.isEmpty()) {
|
String[] defendantArray = defendants.split(",");
|
String[] newDefendants = new String[defendantArray.length];
|
|
for (int i = 0; i < defendantArray.length; i++) {
|
newDefendants[i] = processName(defendantArray[i]);
|
}
|
|
// 处理重名情况
|
newDefendants = handleDuplicateNames(newDefendants);
|
|
// 更新被告信息
|
caseInfo.setDefendants(String.join(",", newDefendants));
|
|
// 在案件描述和调解协议中替换姓名
|
for (int i = 0; i < defendantArray.length; i++) {
|
String oldName = defendantArray[i];
|
String newName = newDefendants[i];
|
|
if (caseInfo.getCaseDes() != null) {
|
caseInfo.setCaseDes(caseInfo.getCaseDes().replace(oldName, newName));
|
}
|
if (caseInfo.getAgreeContent() != null) {
|
caseInfo.setAgreeContent(caseInfo.getAgreeContent().replace(oldName, newName));
|
}
|
if (caseInfo.getCaseTitle() != null) {
|
caseInfo.setCaseTitle(caseInfo.getCaseTitle().replace(oldName, newName));
|
}
|
}
|
}
|
|
return caseInfo;
|
} catch (Exception e) {
|
log.error("[DyhCaseInfoService.privacyProcessing]隐私化处理失败,异常信息:" + e, e);
|
throw new ServiceException("DyhCaseInfoService.privacyProcessing", e);
|
}
|
}
|
|
/**
|
* 处理单个姓名的隐私化
|
* @param name 原始姓名
|
* @return 隐私化后的姓名
|
*/
|
private String processName(String name) {
|
if (name == null || name.isEmpty()) {
|
return name;
|
}
|
|
if (name.length() > 4) {
|
return "某某" + name.substring(name.length() - 2);
|
} else {
|
return name.charAt(0) + "某" + name.charAt(name.length() - 1);
|
}
|
}
|
|
/**
|
* 处理重名情况
|
* @param names 处理后的姓名数组
|
* @return 处理重名后的姓名数组
|
*/
|
private String[] handleDuplicateNames(String[] names) {
|
Map<String, Integer> nameCount = new HashMap<>();
|
String[] result = new String[names.length];
|
|
for (int i = 0; i < names.length; i++) {
|
String name = names[i];
|
nameCount.put(name, nameCount.getOrDefault(name, 0) + 1);
|
|
if (nameCount.get(name) > 1) {
|
result[i] = name + (nameCount.get(name) - 1);
|
} else {
|
result[i] = name;
|
}
|
}
|
|
return result;
|
}
|
|
}
|