|
@@ -25,6 +25,7 @@ import org.sky.scientific.excel.SubjectEnterpriseExcel;
|
|
|
import org.sky.scientific.mapper.SubjectEnterpriseMapper;
|
|
import org.sky.scientific.mapper.SubjectEnterpriseMapper;
|
|
|
import org.sky.scientific.mapper.SubjectMapper;
|
|
import org.sky.scientific.mapper.SubjectMapper;
|
|
|
import org.sky.scientific.mapper.XmCostDetailsMapper;
|
|
import org.sky.scientific.mapper.XmCostDetailsMapper;
|
|
|
|
|
+import org.sky.scientific.pojo.dto.SubjectQueryDto;
|
|
|
import org.sky.scientific.pojo.entity.Subject;
|
|
import org.sky.scientific.pojo.entity.Subject;
|
|
|
import org.sky.scientific.pojo.entity.SubjectEnterprise;
|
|
import org.sky.scientific.pojo.entity.SubjectEnterprise;
|
|
|
import org.sky.scientific.pojo.entity.XmCostDetailsEntity;
|
|
import org.sky.scientific.pojo.entity.XmCostDetailsEntity;
|
|
@@ -37,7 +38,6 @@ import java.io.InputStream;
|
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
@@ -54,11 +54,8 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
|
|
|
private final XmCostDetailsMapper xmCostDetailsMapper;
|
|
private final XmCostDetailsMapper xmCostDetailsMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<SubjectVO> lazyList(Long parentId, Map<String, Object> subject) {
|
|
|
|
|
- if (Func.isEmpty(Func.toStr(subject.get(PARENT_ID)))) {
|
|
|
|
|
- parentId = null;
|
|
|
|
|
- }
|
|
|
|
|
- List<SubjectVO> list = baseMapper.lazyList(SecureUtil.getTenantId(), parentId, subject);
|
|
|
|
|
|
|
+ public List<SubjectVO> lazyList(SubjectQueryDto subject) {
|
|
|
|
|
+ List<SubjectVO> list = baseMapper.lazyList(SecureUtil.getTenantId(), subject);
|
|
|
return ForestNodeMerger.merge(list);
|
|
return ForestNodeMerger.merge(list);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -72,7 +69,7 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
|
|
|
public boolean submitSubject(Subject subject) {
|
|
public boolean submitSubject(Subject subject) {
|
|
|
subject.setTenantId(SecureUtil.getTenantId());
|
|
subject.setTenantId(SecureUtil.getTenantId());
|
|
|
Subject dbByName = baseMapper.getByName(subject.getName(), subject.getParentId(), SecureUtil.getTenantId());
|
|
Subject dbByName = baseMapper.getByName(subject.getName(), subject.getParentId(), SecureUtil.getTenantId());
|
|
|
- if (Func.isEmpty(subject.getId())) {
|
|
|
|
|
|
|
+ if (Func.isEmpty(subject.getId())) {
|
|
|
//新增
|
|
//新增
|
|
|
if (dbByName != null) {
|
|
if (dbByName != null) {
|
|
|
throw new ServiceException("科目名称已存在");
|
|
throw new ServiceException("科目名称已存在");
|
|
@@ -138,12 +135,92 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean deleteSubjectEnterprise(Long id) {
|
|
public boolean deleteSubjectEnterprise(Long id) {
|
|
|
- if(xmCostDetailsMapper.selectCount(Wrappers.<XmCostDetailsEntity>lambdaQuery().eq(XmCostDetailsEntity::getESubjectId, id)) > 0){
|
|
|
|
|
|
|
+ if (xmCostDetailsMapper.selectCount(Wrappers.<XmCostDetailsEntity>lambdaQuery().eq(XmCostDetailsEntity::getESubjectId, id)) > 0) {
|
|
|
throw new ServiceException("企业研发支出明细账中引用了该科目,无法删除");
|
|
throw new ServiceException("企业研发支出明细账中引用了该科目,无法删除");
|
|
|
}
|
|
}
|
|
|
return subjectEnterpriseMapper.deleteById(id) > 0;
|
|
return subjectEnterpriseMapper.deleteById(id) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @SneakyThrows
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void exportSubject(HttpServletResponse response, SubjectQueryDto dto) {
|
|
|
|
|
+
|
|
|
|
|
+ List<SubjectVO> list = this.lazyList(dto);
|
|
|
|
|
+ List<JSONObject> resultList = new ArrayList<>();
|
|
|
|
|
+ traverseSubjectTree(list.get(0), null, null, null, null, 1, resultList);
|
|
|
|
|
+
|
|
|
|
|
+ AtomicInteger index = new AtomicInteger(1);
|
|
|
|
|
+ for (JSONObject obj : resultList) {
|
|
|
|
|
+ obj.put("xh", index.getAndIncrement() + "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/基础资源管理/系统预设会计科目.xls");
|
|
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("系统预设会计科目.xls", Charsets.UTF_8));
|
|
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream())
|
|
|
|
|
+ .withTemplate((templateFileName))
|
|
|
|
|
+ .excelType(ExcelTypeEnum.XLS)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
|
|
+ //设置list集合数据
|
|
|
|
|
+ excelWriter.fill(resultList, writeSheet);
|
|
|
|
|
+ excelWriter.finish();
|
|
|
|
|
+ if (templateFileName != null) {
|
|
|
|
|
+ templateFileName.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void traverseSubjectTree(SubjectVO currentNode,
|
|
|
|
|
+ String l1, String l2,
|
|
|
|
|
+ String l3, String l4,int currentLevel,
|
|
|
|
|
+ List<JSONObject> result) {
|
|
|
|
|
+ if (currentNode == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新各级名称
|
|
|
|
|
+ String newL1 = l1;
|
|
|
|
|
+ String newL2 = l2;
|
|
|
|
|
+ String newL3 = l3;
|
|
|
|
|
+ String newL4 = l4;
|
|
|
|
|
+
|
|
|
|
|
+ switch (currentLevel) {
|
|
|
|
|
+ case 1: // 一级科目
|
|
|
|
|
+ newL1 = currentNode.getName();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2: // 二级科目
|
|
|
|
|
+ newL2 = currentNode.getName();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3: // 三级科目
|
|
|
|
|
+ newL3 = currentNode.getName();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4: // 四级科目
|
|
|
|
|
+ newL4 = currentNode.getName();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将当前节点信息添加到结果集
|
|
|
|
|
+ JSONObject node = new JSONObject();
|
|
|
|
|
+ node.put("l1", newL1);
|
|
|
|
|
+ node.put("l2", newL2);
|
|
|
|
|
+ node.put("l3", newL3);
|
|
|
|
|
+ node.put("l4", newL4);
|
|
|
|
|
+
|
|
|
|
|
+ node.put("code", currentNode.getCode());
|
|
|
|
|
+ node.put("name", currentNode.getName());
|
|
|
|
|
+ result.add(node);
|
|
|
|
|
+
|
|
|
|
|
+ // 递归处理子节点
|
|
|
|
|
+ if (currentNode.getChildren() != null && !currentNode.getChildren().isEmpty()) {
|
|
|
|
|
+ for (SubjectVO child : currentNode.getChildren()) {
|
|
|
|
|
+ traverseSubjectTree(child, newL1, newL2, newL3, newL4, currentLevel+1, result);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
|
@Override
|
|
@Override
|
|
|
public void exportSubjectEnterprise(HttpServletResponse response, SubjectEnterprise dto) {
|
|
public void exportSubjectEnterprise(HttpServletResponse response, SubjectEnterprise dto) {
|
|
@@ -183,27 +260,17 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> impl
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean submitSubjectEnterprise(SubjectEnterprise subjectEnterprise) {
|
|
public boolean submitSubjectEnterprise(SubjectEnterprise subjectEnterprise) {
|
|
|
-// SubjectEnterprise dbEntityByName = subjectEnterpriseMapper.selectOne(Wrappers.<SubjectEnterprise>lambdaQuery()
|
|
|
|
|
-// .eq(SubjectEnterprise::getName, subjectEnterprise.getName()));
|
|
|
|
|
-
|
|
|
|
|
List<SubjectEnterprise> dbListByCode = subjectEnterpriseMapper.selectList(Wrappers.<SubjectEnterprise>lambdaQuery()
|
|
List<SubjectEnterprise> dbListByCode = subjectEnterpriseMapper.selectList(Wrappers.<SubjectEnterprise>lambdaQuery()
|
|
|
.eq(SubjectEnterprise::getCode, subjectEnterprise.getCode()));
|
|
.eq(SubjectEnterprise::getCode, subjectEnterprise.getCode()));
|
|
|
|
|
|
|
|
if (Func.isNull(subjectEnterprise.getId())) {
|
|
if (Func.isNull(subjectEnterprise.getId())) {
|
|
|
//新增
|
|
//新增
|
|
|
-// if (dbEntityByName != null && Func.equals(dbEntityByName.getName(), subjectEnterprise.getName())) {
|
|
|
|
|
-// throw new ServiceException("科目名称已存在");
|
|
|
|
|
-// }
|
|
|
|
|
if (Func.isNotEmpty(dbListByCode) && Func.equals(dbListByCode.get(0).getCode(), subjectEnterprise.getCode())) {
|
|
if (Func.isNotEmpty(dbListByCode) && Func.equals(dbListByCode.get(0).getCode(), subjectEnterprise.getCode())) {
|
|
|
throw new ServiceException("科目代码已存在");
|
|
throw new ServiceException("科目代码已存在");
|
|
|
}
|
|
}
|
|
|
subjectEnterprise.setTenantId(SecureUtil.getTenantId());
|
|
subjectEnterprise.setTenantId(SecureUtil.getTenantId());
|
|
|
return subjectEnterpriseMapper.insert(subjectEnterprise) == 1;
|
|
return subjectEnterpriseMapper.insert(subjectEnterprise) == 1;
|
|
|
} else {
|
|
} else {
|
|
|
- //修改
|
|
|
|
|
-// if (dbEntityByName != null && Func.equals(dbEntityByName.getName(), subjectEnterprise.getName()) && !Func.equals(dbEntityByName.getId(), subjectEnterprise.getId())) {
|
|
|
|
|
-// throw new ServiceException("科目名称已存在");
|
|
|
|
|
-// }
|
|
|
|
|
if (Func.isNotEmpty(dbListByCode) && Func.equals(dbListByCode.get(0).getCode(), subjectEnterprise.getCode()) && !Func.equals(dbListByCode.get(0).getId(), subjectEnterprise.getId())) {
|
|
if (Func.isNotEmpty(dbListByCode) && Func.equals(dbListByCode.get(0).getCode(), subjectEnterprise.getCode()) && !Func.equals(dbListByCode.get(0).getId(), subjectEnterprise.getId())) {
|
|
|
throw new ServiceException("科目代码已存在");
|
|
throw new ServiceException("科目代码已存在");
|
|
|
}
|
|
}
|