|
|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
package com.xjrsoft.module.contract.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
|
|
import com.pictc.enums.BusinessCode;
|
|
|
|
|
import com.xjrsoft.common.exception.BusinessException;
|
|
|
|
|
import com.xjrsoft.module.contract.entity.LngContractApproRel;
|
|
|
|
|
import com.xjrsoft.module.contract.entity.LngContractFact;
|
|
|
|
|
import com.xjrsoft.module.contract.entity.LngContractFactCp;
|
|
|
|
|
@ -9,13 +12,16 @@ import com.xjrsoft.module.contract.mapper.LngContractApproRelMapper;
|
|
|
|
|
import com.xjrsoft.module.contract.mapper.LngContractFactCpMapper;
|
|
|
|
|
import com.xjrsoft.module.contract.mapper.LngContractFactMapper;
|
|
|
|
|
import com.xjrsoft.module.contract.service.IContractFactService;
|
|
|
|
|
import com.xjrsoft.module.contract.vo.LngContractApproRelVo;
|
|
|
|
|
import com.xjrsoft.module.contract.vo.LngContractFactCpVo;
|
|
|
|
|
import com.xjrsoft.module.contract.vo.LngContractFactVo;
|
|
|
|
|
import com.xjrsoft.module.system.client.IFileClient;
|
|
|
|
|
import com.xjrsoft.module.system.vo.LngFileUploadVo;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @title: service
|
|
|
|
|
@ -26,100 +32,34 @@ import java.util.stream.Collectors;
|
|
|
|
|
@Service
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
public class ContractFactServiceImpl extends MPJBaseServiceImpl<LngContractFactMapper, LngContractFact> implements IContractFactService {
|
|
|
|
|
private final LngContractFactMapper contractFactLngContractFactMapper;
|
|
|
|
|
|
|
|
|
|
private final LngContractFactCpMapper contractFactLngContractFactCpMapper;
|
|
|
|
|
private final LngContractApproRelMapper contractFactLngContractApproRelMapper;
|
|
|
|
|
|
|
|
|
|
private final LngContractFactCpMapper lngContractFactCpMapper;
|
|
|
|
|
private final LngContractApproRelMapper lngContractApproRelMapper;
|
|
|
|
|
private final IFileClient fileClient;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean add(LngContractFact lngContractFact) {
|
|
|
|
|
contractFactLngContractFactMapper.insert(lngContractFact);
|
|
|
|
|
for (LngContractFactCp lngContractFactCp : lngContractFact.getLngContractFactCpList()) {
|
|
|
|
|
lngContractFactCp.setKFactId(lngContractFact.getId());
|
|
|
|
|
contractFactLngContractFactCpMapper.insert(lngContractFactCp);
|
|
|
|
|
public LngContractFactVo getInfoById(Long id) {
|
|
|
|
|
LngContractFact lngContractFact = this.getById(id);
|
|
|
|
|
if(lngContractFact == null) {
|
|
|
|
|
new BusinessException(BusinessCode.of(10500,"找不到此数据"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
for (LngContractApproRel lngContractApproRel : lngContractFact.getLngContractApproRelList()) {
|
|
|
|
|
lngContractApproRel.setTableId(lngContractFact.getId());
|
|
|
|
|
contractFactLngContractApproRelMapper.insert(lngContractApproRel);
|
|
|
|
|
LngContractFactVo vo = BeanUtil.toBean(lngContractFact, LngContractFactVo.class);
|
|
|
|
|
List<LngContractFactCp> lngContractFactCpList = lngContractFactCpMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<LngContractFactCp>()
|
|
|
|
|
.eq(LngContractFactCp::getKFactId, lngContractFact.getId()));
|
|
|
|
|
if (CollectionUtils.isNotEmpty(lngContractFactCpList)) {
|
|
|
|
|
vo.setLngContractFactCpList(BeanUtil.copyToList(lngContractFactCpList, LngContractFactCpVo.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean update(LngContractFact lngContractFact) {
|
|
|
|
|
contractFactLngContractFactMapper.updateById(lngContractFact);
|
|
|
|
|
//********************************* LngContractFactCp 增删改 开始 *******************************************/
|
|
|
|
|
{
|
|
|
|
|
// 查出所有子级的id
|
|
|
|
|
List<LngContractFactCp> lngContractFactCpList = contractFactLngContractFactCpMapper.selectList(Wrappers.lambdaQuery(LngContractFactCp.class).eq(LngContractFactCp::getKFactId, lngContractFact.getId()).select(LngContractFactCp::getId));
|
|
|
|
|
List<Long> lngContractFactCpIds = lngContractFactCpList.stream().map(LngContractFactCp::getId).collect(Collectors.toList());
|
|
|
|
|
//原有子表单 没有被删除的主键
|
|
|
|
|
List<Long> lngContractFactCpOldIds = lngContractFact.getLngContractFactCpList().stream().map(LngContractFactCp::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
//找到需要删除的id
|
|
|
|
|
List<Long> lngContractFactCpRemoveIds = lngContractFactCpIds.stream().filter(item -> !lngContractFactCpOldIds.contains(item)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
for (LngContractFactCp lngContractFactCp : lngContractFact.getLngContractFactCpList()) {
|
|
|
|
|
//如果不等于空则修改
|
|
|
|
|
if (lngContractFactCp.getId() != null) {
|
|
|
|
|
contractFactLngContractFactCpMapper.updateById(lngContractFactCp);
|
|
|
|
|
}
|
|
|
|
|
//如果等于空 则新增
|
|
|
|
|
else {
|
|
|
|
|
//已经不存在的id 删除
|
|
|
|
|
lngContractFactCp.setKFactId(lngContractFact.getId());
|
|
|
|
|
contractFactLngContractFactCpMapper.insert(lngContractFactCp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//已经不存在的id 删除
|
|
|
|
|
if(lngContractFactCpRemoveIds.size() > 0){
|
|
|
|
|
contractFactLngContractFactCpMapper.deleteBatchIds(lngContractFactCpRemoveIds);
|
|
|
|
|
}
|
|
|
|
|
List<LngContractApproRel> lngContractApproRelList = lngContractApproRelMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<LngContractApproRel>()
|
|
|
|
|
.eq(LngContractApproRel::getTableId, lngContractFact.getId()));
|
|
|
|
|
if (CollectionUtils.isNotEmpty(lngContractApproRelList)) {
|
|
|
|
|
vo.setLngContractApproRelList(BeanUtil.copyToList(lngContractApproRelList, LngContractApproRelVo.class));
|
|
|
|
|
}
|
|
|
|
|
//********************************* LngContractFactCp 增删改 结束 *******************************************/
|
|
|
|
|
|
|
|
|
|
//********************************* LngContractApproRel 增删改 开始 *******************************************/
|
|
|
|
|
{
|
|
|
|
|
// 查出所有子级的id
|
|
|
|
|
List<LngContractApproRel> lngContractApproRelList = contractFactLngContractApproRelMapper.selectList(Wrappers.lambdaQuery(LngContractApproRel.class).eq(LngContractApproRel::getTableId, lngContractFact.getId()).select(LngContractApproRel::getId));
|
|
|
|
|
List<Long> lngContractApproRelIds = lngContractApproRelList.stream().map(LngContractApproRel::getId).collect(Collectors.toList());
|
|
|
|
|
//原有子表单 没有被删除的主键
|
|
|
|
|
List<Long> lngContractApproRelOldIds = lngContractFact.getLngContractApproRelList().stream().map(LngContractApproRel::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
//找到需要删除的id
|
|
|
|
|
List<Long> lngContractApproRelRemoveIds = lngContractApproRelIds.stream().filter(item -> !lngContractApproRelOldIds.contains(item)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
for (LngContractApproRel lngContractApproRel : lngContractFact.getLngContractApproRelList()) {
|
|
|
|
|
//如果不等于空则修改
|
|
|
|
|
if (lngContractApproRel.getId() != null) {
|
|
|
|
|
contractFactLngContractApproRelMapper.updateById(lngContractApproRel);
|
|
|
|
|
}
|
|
|
|
|
//如果等于空 则新增
|
|
|
|
|
else {
|
|
|
|
|
//已经不存在的id 删除
|
|
|
|
|
lngContractApproRel.setTableId(lngContractFact.getId());
|
|
|
|
|
contractFactLngContractApproRelMapper.insert(lngContractApproRel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//已经不存在的id 删除
|
|
|
|
|
if(lngContractApproRelRemoveIds.size() > 0){
|
|
|
|
|
contractFactLngContractApproRelMapper.deleteBatchIds(lngContractApproRelRemoveIds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//********************************* LngContractApproRel 增删改 结束 *******************************************/
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean delete(List<Long> ids) {
|
|
|
|
|
contractFactLngContractFactMapper.deleteBatchIds(ids);
|
|
|
|
|
contractFactLngContractFactCpMapper.delete(Wrappers.lambdaQuery(LngContractFactCp.class).in(LngContractFactCp::getKFactId, ids));
|
|
|
|
|
contractFactLngContractApproRelMapper.delete(Wrappers.lambdaQuery(LngContractApproRel.class).in(LngContractApproRel::getTableId, ids));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
List<LngFileUploadVo> fileList = fileClient.getTableFiles("lng_contract_fact",
|
|
|
|
|
"lngFileUploadList", vo.getId());
|
|
|
|
|
vo.setLngFileUploadList(fileList);
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|