|
|
@@ -4,13 +4,20 @@ package org.sky.scientific.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.sky.core.log.exception.ServiceException;
|
|
|
import org.sky.core.mp.base.BaseServiceImpl;
|
|
|
+import org.sky.core.mp.support.Condition;
|
|
|
+import org.sky.core.mp.support.Query;
|
|
|
+import org.sky.core.tool.utils.Func;
|
|
|
import org.sky.scientific.mapper.XmFinanceMapper;
|
|
|
import org.sky.scientific.mapper.XmMapper;
|
|
|
+import org.sky.scientific.pojo.entity.XmEntity;
|
|
|
import org.sky.scientific.pojo.entity.XmFinanceEntity;
|
|
|
import org.sky.scientific.service.IXmFinanceService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -28,7 +35,101 @@ public class XmFinanceServiceImpl extends BaseServiceImpl<XmFinanceMapper, XmFin
|
|
|
|
|
|
@Override
|
|
|
public IPage<XmFinanceEntity> selectXmFinancePage(IPage<XmFinanceEntity> page, XmFinanceEntity dto) {
|
|
|
+ if (Func.isBlank(dto.getYearAndMonth())) {
|
|
|
+ throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getType() == null || !Arrays.asList(1, 2, 3).contains(dto.getType())) {
|
|
|
+ throw new ServiceException("参数type为空或者错误");
|
|
|
+ }
|
|
|
List<XmFinanceEntity> list = baseMapper.selectXmFinancePage(page, dto);
|
|
|
return page.setRecords(list);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean saveFinance(XmFinanceEntity entity) {
|
|
|
+ if (Func.isBlank(entity.getYearAndMonth())) {
|
|
|
+ throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
+ }
|
|
|
+ if (entity.getType() == null || !Arrays.asList(1, 2, 3).contains(entity.getType())) {
|
|
|
+ throw new ServiceException("参数type为空或者错误");
|
|
|
+ }
|
|
|
+ //根据yearAndMonth查询年度项目
|
|
|
+ List<XmEntity> xmListByYear = xmMapper.selectXmListByYear(entity.getYearAndMonth());
|
|
|
+ if (Func.isEmpty(xmListByYear)) {
|
|
|
+ throw new ServiceException(entity.getYearAndMonth() + "年度内无研发项目可新增");
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据yearAndMonth和type查询已有项目
|
|
|
+ Query query = new Query().setCurrent(1).setSize(Integer.MAX_VALUE);
|
|
|
+ List<XmFinanceEntity> dbXmFinanceList = baseMapper.selectXmFinancePage(Condition.getPage(query), entity);
|
|
|
+
|
|
|
+ //年度研发项目
|
|
|
+ List<Long> xmIdList = xmListByYear.stream().map(XmEntity::getId).toList();
|
|
|
+
|
|
|
+ //已添加的研发项目
|
|
|
+ List<Long> XmIdFinances = dbXmFinanceList.stream().map(XmFinanceEntity::getXmId).toList();
|
|
|
+ //去重,差集
|
|
|
+ List<Long> collect = xmIdList.stream().filter(item -> !XmIdFinances.contains(item)).toList();
|
|
|
+
|
|
|
+ if (Func.isEmpty(collect)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<XmFinanceEntity> list = new ArrayList<>();
|
|
|
+ for (Long xmId :collect) {
|
|
|
+ XmFinanceEntity finance = new XmFinanceEntity();
|
|
|
+ finance.setYearAndMonth(entity.getYearAndMonth());
|
|
|
+ finance.setXmId(xmId);
|
|
|
+ finance.setType(entity.getType());
|
|
|
+ list.add(finance);
|
|
|
+ }
|
|
|
+ return this.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean physicalDeleteByIds(List<Long> ids) {
|
|
|
+ return baseMapper.physicalDeleteByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean fetchFinance(XmFinanceEntity entity) {
|
|
|
+ if (Func.isBlank(entity.getYearAndMonth())) {
|
|
|
+ throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
+ }
|
|
|
+ if (entity.getType() == null || !Arrays.asList(1, 2, 3).contains(entity.getType())) {
|
|
|
+ throw new ServiceException("参数type为空或者错误");
|
|
|
+ }
|
|
|
+ //根据yearAndMonth查询年度项目
|
|
|
+ List<XmEntity> xmListByYear = xmMapper.selectXmListByYear(entity.getYearAndMonth());
|
|
|
+ if (Func.isEmpty(xmListByYear)) {
|
|
|
+ throw new ServiceException(entity.getYearAndMonth() + "年度内无研发项目可引入");
|
|
|
+ }
|
|
|
+ //根据yearAndMonth和type查询已有项目
|
|
|
+ Query query = new Query().setCurrent(1).setSize(Integer.MAX_VALUE);
|
|
|
+ List<XmFinanceEntity> dbXmFinanceList = baseMapper.selectXmFinancePage(Condition.getPage(query), entity);
|
|
|
+ if (Func.isEmpty(dbXmFinanceList)) {
|
|
|
+ //本年度无会计/加计扣除/高新-研发项目清单,直接保存
|
|
|
+
|
|
|
+ }
|
|
|
+ //年度研发项目
|
|
|
+ List<Long> xmIdList = xmListByYear.stream().map(XmEntity::getId).toList();
|
|
|
+
|
|
|
+ //已添加的研发项目
|
|
|
+ List<Long> XmIdFinances = dbXmFinanceList.stream().map(XmFinanceEntity::getXmId).toList();
|
|
|
+ //去重,差集
|
|
|
+ List<Long> collect = xmIdList.stream().filter(item -> !XmIdFinances.contains(item)).toList();
|
|
|
+ //保存
|
|
|
+ if (Func.isEmpty(collect)) {
|
|
|
+ throw new ServiceException("无研发项目可引入");
|
|
|
+ }
|
|
|
+ List<XmFinanceEntity> insertList = new ArrayList<>();
|
|
|
+ for (Long xmId : collect) {
|
|
|
+ XmFinanceEntity dto = new XmFinanceEntity();
|
|
|
+ dto.setYearAndMonth(entity.getYearAndMonth());
|
|
|
+ dto.setType(entity.getType());
|
|
|
+ dto.setXmId(xmId);
|
|
|
+ insertList.add(dto);
|
|
|
+ }
|
|
|
+ return this.saveBatch(insertList);
|
|
|
+ }
|
|
|
}
|