|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.supervision.common.domain.R;
|
|
|
|
|
import com.supervision.common.enums.ResultStatusEnum;
|
|
|
|
|
import com.supervision.common.exception.CustomException;
|
|
|
|
|
import com.supervision.common.utils.ExcelReader;
|
|
|
|
|
import com.supervision.common.utils.IPages;
|
|
|
|
|
import com.supervision.common.utils.StringUtils;
|
|
|
|
|
import com.supervision.police.domain.CasePerson;
|
|
|
|
|
import com.supervision.police.domain.ComDictionary;
|
|
|
|
|
import com.supervision.police.domain.ModelAtomicIndex;
|
|
|
|
|
import com.supervision.police.dto.AtomicIndexDTO;
|
|
|
|
|
import com.supervision.police.dto.IndexDetail;
|
|
|
|
|
import com.supervision.police.mapper.CasePersonMapper;
|
|
|
|
|
import com.supervision.police.mapper.ModelCaseMapper;
|
|
|
|
|
import com.supervision.police.domain.ModelCase;
|
|
|
|
|
import com.supervision.police.service.ComDictionaryService;
|
|
|
|
|
import com.supervision.police.service.ModelCaseService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.script.ScriptEngine;
|
|
|
|
|
import javax.script.ScriptEngineManager;
|
|
|
|
|
import javax.script.ScriptException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 案件表(ModelCase)表服务实现类
|
|
|
|
|
*
|
|
|
|
|
* @author qmy
|
|
|
|
|
* @since 2024-07-02 14:51:27
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class ModelCaseServiceImpl extends ServiceImpl<ModelCaseMapper, ModelCase> implements ModelCaseService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ComDictionaryService comDictionaryService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelCaseMapper modelCaseMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CasePersonMapper casePersonMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询列表
|
|
|
|
|
* @param modelCase
|
|
|
|
|
* @param page
|
|
|
|
|
* @param size
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> queryList(ModelCase modelCase, Integer page, Integer size) {
|
|
|
|
|
IPage<ModelCase> iPage = new Page<>(page, size);
|
|
|
|
|
iPage = modelCaseMapper.selectAll(iPage, modelCase);
|
|
|
|
|
List<ModelCase> records = iPage.getRecords();
|
|
|
|
|
List<ComDictionary> dicts = comDictionaryService.list();
|
|
|
|
|
for (ModelCase mc : records) {
|
|
|
|
|
String[] caseTypes = mc.getCaseType().split(",");
|
|
|
|
|
List<String> caseType = new ArrayList<>();
|
|
|
|
|
for (String type : caseTypes) {
|
|
|
|
|
caseType.add(comDictionaryService.getName(dicts, "case_type", type));
|
|
|
|
|
}
|
|
|
|
|
mc.setCaseTypeName(StringUtils.join(caseType, ","));
|
|
|
|
|
mc.setCaseStatusName(comDictionaryService.getName(dicts, "case_status", mc.getCaseStatus()));
|
|
|
|
|
mc.setCrimeModeName(comDictionaryService.getName(dicts, "crime_mode", mc.getCrimeMode()));
|
|
|
|
|
mc.setIdentifyResultName(comDictionaryService.getName(dicts, "identify_result", mc.getIdentifyResult()));
|
|
|
|
|
}
|
|
|
|
|
iPage.setRecords(records);
|
|
|
|
|
return R.ok(IPages.buildDataMap(iPage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> checkCaseNo(String caseNo) {
|
|
|
|
|
LambdaQueryWrapper<ModelCase> wrapper = Wrappers.lambdaQuery();
|
|
|
|
|
wrapper.eq(ModelCase::getCaseNo, caseNo)
|
|
|
|
|
.eq(ModelCase::getDataStatus, "1");
|
|
|
|
|
ModelCase modelCase = modelCaseMapper.selectOne(wrapper);
|
|
|
|
|
if (modelCase == null) {
|
|
|
|
|
return R.ok(caseNo);
|
|
|
|
|
} else {
|
|
|
|
|
return R.okMsg("案件编号已存在,请勿重复添加");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> addOrUpd(ModelCase modelCase) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
if (modelCase.getId() != null) {
|
|
|
|
|
i = modelCaseMapper.updateById(modelCase);
|
|
|
|
|
} else {
|
|
|
|
|
Long num = modelCaseMapper.selectCount(null);
|
|
|
|
|
modelCase.setIndexNum(Integer.parseInt(num.toString()) + 1);
|
|
|
|
|
i = modelCaseMapper.insert(modelCase);
|
|
|
|
|
}
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
return R.okMsg("保存成功");
|
|
|
|
|
} else {
|
|
|
|
|
return R.fail("保存失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> del(String id) {
|
|
|
|
|
ModelCase modelCase = modelCaseMapper.selectById(id);
|
|
|
|
|
modelCase.setDataStatus(StringUtils.getUUID());
|
|
|
|
|
int i = modelCaseMapper.updateById(modelCase);
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
return R.okMsg("删除成功");
|
|
|
|
|
} else {
|
|
|
|
|
return R.fail("删除失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> getPerson(String caseId, String name) {
|
|
|
|
|
LambdaQueryWrapper<CasePerson> wrapper = Wrappers.lambdaQuery();
|
|
|
|
|
wrapper.like(CasePerson::getCaseId, caseId)
|
|
|
|
|
.like(CasePerson::getName, name);
|
|
|
|
|
List<CasePerson> casePeople = casePersonMapper.selectList(wrapper);
|
|
|
|
|
List<ComDictionary> dicts = comDictionaryService.list();
|
|
|
|
|
for (CasePerson cp : casePeople) {
|
|
|
|
|
cp.setRoleName(comDictionaryService.getName(dicts, "case_role", cp.getRoleCode()));
|
|
|
|
|
}
|
|
|
|
|
return R.ok(casePeople);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> addPersion(CasePerson person) {
|
|
|
|
|
int i = casePersonMapper.insert(person);
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
return R.okMsg("新增成功");
|
|
|
|
|
} else {
|
|
|
|
|
return R.fail("新增失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> uploadCase(MultipartFile file) {
|
|
|
|
|
/**
|
|
|
|
|
* 检查文件格式
|
|
|
|
|
*/
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
assert fileName != null;
|
|
|
|
|
// 截取文件的类型符
|
|
|
|
|
String substring = fileName.substring(fileName.lastIndexOf(".") + 1);
|
|
|
|
|
if (!("xls".equals(substring) || "xlsx".equals(substring))) {
|
|
|
|
|
throw new CustomException(ResultStatusEnum.INCORRECT_FILE_FORMAT);// 响应“文件格式不正确”异常
|
|
|
|
|
}
|
|
|
|
|
List<ModelCase> putList = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
putList = ExcelReader.getCaseList(file.getInputStream(), substring, null);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new CustomException(ResultStatusEnum.UPLOAD_EXCEPTION);// 响应“文件上传异常”错误
|
|
|
|
|
}
|
|
|
|
|
List<ComDictionary> dicts = comDictionaryService.list();
|
|
|
|
|
/**
|
|
|
|
|
* 读取bean列表,导入到数据库中
|
|
|
|
|
*/
|
|
|
|
|
List<Map<String, Object>> errorList = new ArrayList<>();
|
|
|
|
|
int index = modelCaseMapper.selectMaxIndex() + 1;
|
|
|
|
|
int add = 0;
|
|
|
|
|
for (ModelCase modelCase : putList) {
|
|
|
|
|
if (StringUtils.isEmpty(modelCase.getCaseNo()) || StringUtils.isEmpty(modelCase.getCaseName())
|
|
|
|
|
|| StringUtils.isEmpty(modelCase.getCaseTypeName()) || StringUtils.isEmpty(modelCase.getCaseStatusName())
|
|
|
|
|
|| StringUtils.isEmpty(modelCase.getCrimeModeName())) {
|
|
|
|
|
errorList.add(errorMapBuilder(modelCase, "必填项为空"));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//替换字典项
|
|
|
|
|
String[] split = modelCase.getCaseTypeName().split(",");
|
|
|
|
|
List<String> caseTypes = new ArrayList<>();
|
|
|
|
|
for (String type : split) {
|
|
|
|
|
caseTypes.add(comDictionaryService.getValue(dicts, "case_type", type));
|
|
|
|
|
}
|
|
|
|
|
modelCase.setCaseType(StringUtils.join(caseTypes, ","));
|
|
|
|
|
modelCase.setCaseStatus(comDictionaryService.getValue(dicts, "case_status", modelCase.getCaseStatusName()));
|
|
|
|
|
modelCase.setCrimeMode(comDictionaryService.getValue(dicts, "crime_mode", modelCase.getCrimeModeName()));
|
|
|
|
|
modelCase.setIndexNum(index);
|
|
|
|
|
modelCaseMapper.insert(modelCase);
|
|
|
|
|
add++;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
|
|
returnMap.put("errorList", errorList);
|
|
|
|
|
returnMap.put("add", add);
|
|
|
|
|
return R.ok(returnMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> errorMapBuilder(ModelCase modelCase, String errorText) {
|
|
|
|
|
return new HashMap<String, Object>(2) {{
|
|
|
|
|
put("caseNo", modelCase.getCaseNo());
|
|
|
|
|
put("caseName", modelCase.getCaseName());
|
|
|
|
|
put("errorText", errorText);
|
|
|
|
|
}};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public R<?> getIndexDetail(String caseId, String indexType, Integer page, Integer size) {
|
|
|
|
|
IPage<IndexDetail> iPage = new Page<>(page, size);
|
|
|
|
|
iPage = modelCaseMapper.getIndexDetail(iPage, caseId, indexType);
|
|
|
|
|
List<IndexDetail> records = iPage.getRecords();
|
|
|
|
|
for (IndexDetail record : records) {
|
|
|
|
|
String[] array = record.getAtomicIds().split(",");
|
|
|
|
|
List<String> atomicIds = Arrays.asList(array);
|
|
|
|
|
List<AtomicIndexDTO> atomics = modelCaseMapper.getAtomicDetail(caseId, atomicIds);
|
|
|
|
|
record.setChildren(atomics);
|
|
|
|
|
}
|
|
|
|
|
iPage.setRecords(records);
|
|
|
|
|
return R.ok(IPages.buildDataMap(iPage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|