案件新增,查询

This commit is contained in:
18792927508
2024-01-10 11:34:33 +08:00
parent c0ac1d92e9
commit 164612c08a
21 changed files with 739 additions and 570 deletions
@@ -19,9 +19,9 @@ import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.system.mapper.*;
import com.ruoyi.wisdomarbitrate.domain.dto.dept.DeptIdentify;
import com.ruoyi.wisdomarbitrate.domain.dto.dept.SealManage;
import com.ruoyi.wisdomarbitrate.domain.dto.mscase.CaseAttach;
import com.ruoyi.wisdomarbitrate.domain.dto.template.FatchRule;
import com.ruoyi.wisdomarbitrate.domain.dto.template.TemplateManage;
import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseAttach;
import com.ruoyi.wisdomarbitrate.domain.vo.template.TemplateFatchRule;
import com.ruoyi.wisdomarbitrate.mapper.dept.DeptIdentifyMapper;
import com.ruoyi.wisdomarbitrate.mapper.dept.SealManageMapper;
@@ -247,14 +247,14 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
}
boolean downLoadFile = FileTransformation.downLoadFileByUrl(sealImageDownloadUrl, resultFilePath);
if (downLoadFile) {
CaseAttach caseAttach = new CaseAttach();
MsCaseAttach caseAttach = new MsCaseAttach();
caseAttach.setAnnexType(10); //10代表印章图片
caseAttach.setAnnexPath(savePath);
caseAttach.setAnnexName(saveName);
int i1 = msCaseAttachMapper.save(caseAttach);
if (i1 > 0) {
//将附件id保存到公章管理表里
Integer annexId1 = caseAttach.getAnnexId();
Long annexId1 = caseAttach.getAnnexId();
SealManage sealManage = new SealManage();
sealManage.setSealId(sealId);
List<SealManage> selectSealList = sealManageMapper.selectSealList(sealManage);
@@ -288,10 +288,10 @@ public class DeptIdentifyServiceImpl implements IDeptIdentifyService {
List<SealManage> selectSealList = sealManageMapper.selectSealList(sealManage);
if (selectSealList != null && selectSealList.size() > 0) {
for (SealManage sealManage1 : selectSealList) {
Integer annexId = sealManage1.getAnnexId();
Long annexId = sealManage1.getAnnexId();
if (annexId != null) {
//根据附件id查询路径
CaseAttach caseAttach = msCaseAttachMapper.queryAnnexById(annexId);
MsCaseAttach caseAttach = msCaseAttachMapper.queryAnnexById(annexId);
String annexName = caseAttach.getAnnexName();
String prefix = "/profile";
int startIndex = annexName.indexOf(prefix);
@@ -1,7 +1,7 @@
package com.ruoyi.wisdomarbitrate.service.mscase;
import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseApplication;
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseApplicationReq;
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseApplicationVO;
import java.util.List;
@@ -18,5 +18,7 @@ public interface MsCaseApplicationService {
* @param req
* @return
*/
List<MsCaseApplication> list(MsCaseApplicationReq req);
List<MsCaseApplicationVO> list(MsCaseApplicationReq req);
int insert(MsCaseApplicationVO caseApplication);
}
@@ -1,14 +1,41 @@
package com.ruoyi.wisdomarbitrate.service.mscase.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.IdWorkerUtil;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseApplication;
import com.ruoyi.system.domain.entity.flow.MsCaseFlow;
import com.ruoyi.system.domain.entity.flow.MsCaseFlowRoleRelated;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.SysUserRoleMapper;
import com.ruoyi.system.mapper.flow.MsCaseFlowMapper;
import com.ruoyi.system.mapper.flow.MsCaseFlowRoleRelatedMapper;
import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseAffiliate;
import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseAttach;
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseApplicationReq;
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseApplicationVO;
import com.ruoyi.wisdomarbitrate.mapper.mscase.*;
import com.ruoyi.wisdomarbitrate.service.mscase.MsCaseApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.ruoyi.common.utils.SecurityUtils.getUsername;
/**
* @Classname MsCaseApplicationServiceImpl
@@ -19,18 +46,242 @@ import java.util.List;
*/
@Service
public class MsCaseApplicationServiceImpl implements MsCaseApplicationService {
@Autowired
MsCaseApplicationMapper msCaseApplicationMapper;
@Autowired
MsCaseApplicationLogMapper msCaseApplicationLogMapper;
@Autowired
MsCaseAffiliateMapper msCaseAffiliateMapper;
@Autowired
MsCaseAffiliateLogMapper msCaseAffiliateLogMapper;
@Autowired
MsCaseAttachMapper msCaseAttachMapper;
@Autowired
MsCaseAttachLogMapper msCaseAttachLogMapper;
@Autowired
MsCaseFlowMapper caseFlowMapper;
@Autowired
MsCaseFlowRoleRelatedMapper caseFlowRoleRelatedMapper;
@Autowired
SysDeptMapper sysDeptMapper;
@Autowired
SysRoleMapper roleMapper;
@Autowired
SysUserMapper userMapper;
@Autowired
SysUserRoleMapper userRoleMapper;
/**
* 案件列表查询
* @param req
* @return
*/
@Override
public List<MsCaseApplication> list(MsCaseApplicationReq req) {
public List<MsCaseApplicationVO> list(MsCaseApplicationReq req) {
// 根据用户查询角色
LoginUser loginUser = SecurityUtils.getLoginUser();
Long roleId = loginUser.getUser().getRoleId();
if(roleId==null){
return new ArrayList<>();
List<SysRole> roles = loginUser.getUser().getRoles();
if(CollectionUtil.isEmpty(roles)){
throw new ServiceException("该用户未指定角色");
}
req.setUserName(SecurityUtils.getUsername());
// 根据角色查询关联的案件状态
Example example = new Example(MsCaseFlowRoleRelated.class);
example.createCriteria().andIn("roleid",roles.stream().map(SysRole::getRoleId).collect(Collectors.toList()));
List<MsCaseFlowRoleRelated> caseFlowRoleRelatedList= caseFlowRoleRelatedMapper.selectByExample(example);
if(CollectionUtil.isEmpty(caseFlowRoleRelatedList)){
throw new ServiceException("该角色为绑定案件流程");
}
Example flowExample = new Example(MsCaseFlow.class);
flowExample.createCriteria().andIn("id",caseFlowRoleRelatedList.stream().map(MsCaseFlowRoleRelated::getFlowId).collect(Collectors.toList()));
List<MsCaseFlow> caseFlows = caseFlowMapper.selectByExample(flowExample);
if(CollectionUtil.isEmpty(caseFlows)){
throw new ServiceException("该角色为绑定案件流程");
}
// 查询案件列表
List<MsCaseApplicationVO> caseApplicationList=msCaseApplicationMapper.list(req,caseFlows.stream().map(MsCaseFlow::getCaseStatusName).collect(Collectors.toList()));
return caseApplicationList;
}
/**
* 新增案件
* @param caseApplication
* @return
*/
@Transactional
@Override
public int insert(MsCaseApplicationVO caseApplication) {
caseApplication.setId(IdWorkerUtil.getId());
// 根据用户查询角色
LoginUser loginUser = SecurityUtils.getLoginUser();
List<SysRole> roles = loginUser.getUser().getRoles();
if(CollectionUtil.isEmpty(roles)){
throw new ServiceException("该用户未指定角色");
}
// 根据角色查询关联的案件状态
Example example = new Example(MsCaseFlowRoleRelated.class);
example.createCriteria().andIn("roleid",roles.stream().map(SysRole::getRoleId).collect(Collectors.toList()));
List<MsCaseFlowRoleRelated> caseFlowRoleRelatedList= caseFlowRoleRelatedMapper.selectByExample(example);
if(CollectionUtil.isEmpty(caseFlowRoleRelatedList)){
throw new ServiceException("该角色为绑定案件流程");
}
Example flowExample = new Example(MsCaseFlow.class);
flowExample.setOrderByClause("sort asc");
flowExample.createCriteria().andIn("id",caseFlowRoleRelatedList.stream().map(MsCaseFlowRoleRelated::getFlowId).collect(Collectors.toList()));
List<MsCaseFlow> caseFlows = caseFlowMapper.selectByExample(flowExample);
if(CollectionUtil.isNotEmpty(caseFlows)){
caseApplication.setCaseStatusName(caseFlows.get(0).getCaseStatusName());
caseApplication.setCaseFlowId(caseFlows.get(0).getId());
}
// 计算仲裁费用
if( caseApplication.getCaseSubjectAmount()!=null) {
BigDecimal feeRate = new BigDecimal("0.01");
BigDecimal feePayable = caseApplication.getCaseSubjectAmount().multiply(feeRate).setScale(2, BigDecimal.ROUND_HALF_UP);
caseApplication.setFeePayable(feePayable);
}
// 设置批号
caseApplication.setBatchNumber(getBatchNumber());
// 设置编码
caseApplication.setCaseNum(getCaseNum());
caseApplication.setCreateBy(SecurityUtils.getUsername());
caseApplication.setUpdateBy(SecurityUtils.getUsername());
caseApplication.setVersion(1);
MsCaseAffiliate affiliate = caseApplication.getAffiliate();
// 保存案件基本信息
if(msCaseApplicationMapper.insertSelective(caseApplication)>0){
List<MsCaseAttach> caseAttachList = caseApplication.getCaseAttachList();
// 保存案件相关人员
if(affiliate !=null) {
// 设置申请人
if( StrUtil.isNotEmpty(affiliate.getApplicationOrganName())){
// 组装申请机构
insertDept(affiliate);
// 查询申请人角色id
Long roleId = roleMapper.selectRoleIdByName("申请人");
// 根据代理人手机号去用户表查询,有修改,么有新增
SysUser agentUser = userMapper.selectUserByPhone(affiliate.getContactTelphoneAgent());
// 代理人为空,新增代理人
if(agentUser==null){
agentUser = new SysUser();
agentUser.setUserName(affiliate.getContactTelphoneAgent());
agentUser.setNickName(affiliate.getNameAgent());
agentUser.setPhonenumber(affiliate.getContactTelphoneAgent());
agentUser.setPassword(SecurityUtils.encryptPassword("abc123456"));
agentUser.setDeptId(Long.valueOf(affiliate.getApplicationOrganId()));
userMapper.insertUser(agentUser);
userRoleMapper.insertUserRole(agentUser.getUserId(), roleId);
}else if(null != agentUser.getDeptId() && !String.valueOf(agentUser.getDeptId()).equals(affiliate.getApplicationOrganId())){
if (null != agentUser.getDept() && StrUtil.isNotEmpty(agentUser.getDept().getDeptName())) {
throw new ServiceException( "该申请代理人已在【" + agentUser.getDept().getDeptName() + "】申请机构下存在,请检查填写信息是否正确");
} else {
throw new ServiceException("该申请代理人已存在,与申请机构不匹配,请检查填写信息是否正确");
}
}else if (null != agentUser.getDeptId() && String.valueOf(agentUser.getDeptId()).equals(affiliate.getApplicationOrganId())) {
// 同步用户表和案件关联人表的手机号和名称
affiliate.setContactTelphoneAgent(StrUtil.isNotEmpty(agentUser.getPhonenumber())?agentUser.getPhonenumber():affiliate.getContactTelphoneAgent());
affiliate.setNameAgent(agentUser.getNickName());
affiliate.setAgentEmail(StrUtil.isNotEmpty(agentUser.getEmail())?agentUser.getEmail():affiliate.getAgentEmail());
List<Long> longList = new ArrayList<>();
// 新增角色为申请人
if (CollectionUtil.isNotEmpty(agentUser.getRoles())) {
longList = agentUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList());
if (!longList.contains(roleId)) {
userRoleMapper.insertUserRole(agentUser.getUserId(), roleId);
}
} else {
userRoleMapper.insertUserRole(agentUser.getUserId(), roleId);
}
}
}
affiliate.setCaseAppliId(caseApplication.getId());
msCaseAffiliateMapper.insert(affiliate);
}
// 保存案件附件
if(CollectionUtil.isNotEmpty(caseAttachList)){
for (MsCaseAttach caseAttach : caseAttachList) {
caseAttach.setCaseAppliId(caseApplication.getId());
// 修改案件附件
msCaseAttachMapper.updateCaseAttach(caseAttach);
}
// for(MsCaseAttach caseAttach:caseAttachList){
// caseAttach.setCaseAppliId(caseApplication.getId());
//
// }
// msCaseAttachMapper.batchSave(caseAttachList);
}
return 1;
}
return 0;
}
/**
* 新增部门
* @param affiliate
*/
@Transactional
void insertDept(MsCaseAffiliate affiliate) {
// 查询所有的组织机构,组装成map
List<SysDept> deptList = sysDeptMapper.selectDeptList(new SysDept());
if (CollectionUtil.isEmpty(deptList)) {
deptList = new ArrayList<>();
}
Map<String, Long> deptMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptName, SysDept::getDeptId, (oldV, newV) -> newV));
// 将组织机构id设为申请人名称
if (deptMap.containsKey(affiliate.getApplicationOrganName())) {
affiliate.setApplicationOrganId(String.valueOf(deptMap.get(affiliate.getApplicationOrganName())));
} else {
// 如果不存在则新增
SysDept dept = new SysDept();
dept.setParentId(0L);
dept.setDeptName(affiliate.getApplicationOrganName());
dept.setAncestors("0");
dept.setOrderNum(1);
dept.setStatus("0");
dept.setDelFlag("0");
dept.setCreateBy(getUsername());
dept.setUpdateBy(getUsername());
sysDeptMapper.insertDept(dept);
deptMap.put(dept.getDeptName(), dept.getDeptId());
affiliate.setApplicationOrganId(String.valueOf(dept.getDeptId()));
}
}
/**
* 获取案件编码
* @return
*/
private String getCaseNum() {
// todo 查询编码规则
// 自动编码格式 zc+yyyyMMdd+001
String currentDay = DateUtils.dateTime();
String caseNum = "zc" + currentDay;
//查询出当天的案件编号的最大值
Integer maxCaseNum = msCaseApplicationMapper.selectCaseNumLike(caseNum, caseNum.length());
if (null == maxCaseNum) {
caseNum = caseNum + "00001";
} else {
maxCaseNum=maxCaseNum+1;
caseNum = caseNum + String.format("%05d", maxCaseNum);
}
return caseNum;
}
/**
* 获取批次号
* @return
*/
private String getBatchNumber() {
Integer batchNumber = msCaseApplicationMapper.selectMaxBatchNumber();
if(batchNumber==null){
return "000001";
}else {
return String.format("%06d", batchNumber+1);
}
// 查询案件列表
return null;
}
}