Commit 2ce5e2d9 by huluobin

# 费用系统 配置 批量导入导出

parent 01dca74b
......@@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Slf4j
@Api(tags = "类型接口")
......@@ -88,7 +87,7 @@ public class CostTypeController {
@ApiOperation("批量导入数据")
@PostMapping("/importExcel")
public CostResult<Void> importExcel(@RequestBody CostTypeImportExcelReq excel) throws IOException {
public CostResult<Void> importExcel(CostTypeImportExcelReq excel) {
costTypeService.importExcel(excel);
return CostResult.success();
}
......@@ -96,7 +95,7 @@ public class CostTypeController {
@ApiOperation("导出excel")
@PostMapping("/exportExcel")
public CostResult<Void> exportExcel(HttpServletResponse response,
@RequestBody CostTypeExportExcelReq req) throws IOException {
@RequestBody CostTypeExportExcelReq req) {
costTypeService.exportExcel(response, req);
return CostResult.success();
}
......
......@@ -3,14 +3,13 @@ package com.blt.other.module.cost.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blt.other.database.model.CostTypeDomain;
import com.blt.other.module.cost.dto.request.CostTypeQueryPageReq;
import com.blt.other.module.cost.dto.request.CostTypeBaseReq;
import com.blt.other.module.cost.dto.response.CostTypeResult;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
@Mapper
@Repository
......@@ -18,7 +17,10 @@ public interface CostTypeDao extends BaseMapper<CostTypeDomain> {
//分页获取费用类型
IPage<CostTypeResult> queryPage(@Param("page") IPage<CostTypeResult> page,
@Param("req") CostTypeQueryPageReq req);
@Param("req") CostTypeBaseReq req);
//获取全部费用类型
List<CostTypeResult> queryAll(@Param("req") CostTypeBaseReq req);
//根据编号查
CostTypeDomain selectByNo(String typeNo);
......
package com.blt.other.module.cost.dto.request;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
......@@ -10,6 +11,7 @@ import lombok.Data;
* @author robbendev
* @since 2021/1/13 3:04 下午
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class CostTypeExportExcelReq {
public class CostTypeExportExcelReq extends CostTypeBaseReq {
}
package com.blt.other.module.cost.dto.request;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2021/1/13 3:30 下午
*/
@Data
public class CostTypeImportExcelItem {
@ExcelProperty("费用类别")
private String typeName;
@ExcelProperty("费用类别描述")
private String typeDesc;
@ExcelProperty("会计科目")
private String accountingSubjectName;
/**
* 形如0b1001 四位二进制
* 高位到低位分别是 付款 收款 借支 借还
*/
@ExcelIgnore
@ApiModelProperty("费用模版类型作用")
private Integer costTemplateType;
}
package com.blt.other.module.cost.dto.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
/**
* <p>
......@@ -12,4 +14,12 @@ import lombok.Data;
*/
@Data
public class CostTypeImportExcelReq {
@ApiModelProperty("导入excel文件 表头 费用类别-费用类别描述-会计科目 ")
MultipartFile excel;
@ApiModelProperty("1-费用类型 2-收入类型 3-借支类型")
Integer type;
}
package com.blt.other.module.cost.dto.response;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2021/1/13 3:30 下午
*/
@Data
public class CostTypeExportExcelItem {
@ExcelProperty("描述")
@ApiModelProperty("描述")
private String description;
@ExcelProperty("描述")
@ApiModelProperty("费用类型标题")
private String typeName;
@ExcelProperty("描述")
@ApiModelProperty(value = "会计一级类目名称")
private String accountingSubjectName;
}
......@@ -9,6 +9,8 @@ import com.blt.other.module.cost.dto.response.GetLogisticsBankResp;
import com.blt.other.module.cost.dto.response.GetLogisticsCodeResp;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public interface CostTypeService extends IService<CostTypeDomain> {
......@@ -65,8 +67,8 @@ public interface CostTypeService extends IService<CostTypeDomain> {
GetLogisticsBankResp getLogisticsBank(String subSupplierName);
//批量导入
void importExcel(CostTypeImportExcelReq excel);
void importExcel(CostTypeImportExcelReq excel) throws IOException;
//导出
void exportExcel(HttpServletResponse response, CostTypeExportExcelReq req);
void exportExcel(HttpServletResponse response, CostTypeExportExcelReq req) throws IOException;
}
package com.blt.other.module.cost.service.impl;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.blt.other.common.base.SysUser;
import com.blt.other.common.util.SessionUtils;
import com.blt.other.database.model.CostTypeDomain;
import com.blt.other.module.cost.dao.AccountingSubjectMapper;
import com.blt.other.module.cost.dao.CostTypeDao;
import com.blt.other.module.cost.dto.request.CostTypeImportExcelItem;
import com.blt.other.module.cost.model.AccountingSubject;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2021/1/13 3:31 下午
*/
@Slf4j
public class CostTypeImportExcelItemListener extends AnalysisEventListener<CostTypeImportExcelItem> {
private static final int BATCH_COUNT = 1000;
List<CostTypeImportExcelItem> list = new ArrayList<>();
private final Integer costTemplateType;
private final AccountingSubjectMapper accountingSubjectMapper;
private final CostTypeDao costTypeDao;
public CostTypeImportExcelItemListener(Integer costTemplateType, AccountingSubjectMapper accountingSubjectMapper, CostTypeDao costTypeDao) {
this.costTemplateType = costTemplateType;
this.accountingSubjectMapper = accountingSubjectMapper;
this.costTypeDao = costTypeDao;
}
@Override
public void invoke(CostTypeImportExcelItem data, AnalysisContext context) {
log.info("解析到一条数据:{}", JSON.toJSONString(data));
list.add(data);
if (list.size() >= BATCH_COUNT) {
syncData();
list.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
syncData();
log.info("所有数据解析完成!");
}
private void syncData() {
SysUser sysUser = SessionUtils.getSysUser();
log.info("{}条数据,开始存储数据库!", list.size());
list.forEach(item -> {
AccountingSubject accountingSubject = accountingSubjectMapper.selectByName(item.getAccountingSubjectName());
if (accountingSubject == null) {
accountingSubject = new AccountingSubject();
accountingSubject.setSubjectNo(IdWorker.getIdStr());
accountingSubject.setName(item.getAccountingSubjectName());
accountingSubject.setUpdateUserId(sysUser.getOaUserId());
accountingSubject.setUpdateUser(sysUser.getUserName());
accountingSubjectMapper.insert(accountingSubject);
log.info("新增会计科目");
}
CostTypeDomain costTypeDomain = costTypeDao.selectOne(new LambdaQueryWrapper<CostTypeDomain>()
.eq(CostTypeDomain::getTypeName, item.getTypeName())
.eq(CostTypeDomain::getAccountingSubjectNo, accountingSubject.getSubjectNo()));
if (costTypeDomain == null) {
costTypeDomain = new CostTypeDomain();
costTypeDomain.setTypeNo(IdWorker.getIdStr());
costTypeDomain.setTypeName(item.getTypeName());
costTypeDomain.setDescription(item.getTypeDesc());
costTypeDomain.setAccountingSubjectNo(accountingSubject.getSubjectNo());
costTypeDomain.setCostTemplateType(costTemplateType);
costTypeDomain.setUpdateUserId(sysUser.getOaUserId());
costTypeDomain.setUpdateUser(sysUser.getUserName());
costTypeDao.insert(costTypeDomain);
log.info("新增费用科目");
}
});
log.info("存储数据库成功!");
}
}
package com.blt.other.module.cost.service.impl;
import com.alibaba.excel.EasyExcel;
import com.bailuntec.common.BeanUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -12,6 +14,7 @@ import com.blt.other.module.auth.model.OaUser;
import com.blt.other.module.cost.dao.AccountingSubjectMapper;
import com.blt.other.module.cost.dao.CostTypeDao;
import com.blt.other.module.cost.dto.request.*;
import com.blt.other.module.cost.dto.response.CostTypeExportExcelItem;
import com.blt.other.module.cost.dto.response.CostTypeResult;
import com.blt.other.module.cost.dto.response.GetLogisticsBankResp;
import com.blt.other.module.cost.dto.response.GetLogisticsCodeResp;
......@@ -22,7 +25,11 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Slf4j
......@@ -122,20 +129,47 @@ public class CostTypeServiceImpl extends ServiceImpl<CostTypeDao, CostTypeDomain
return resp;
}
@Override
public void importExcel(CostTypeImportExcelReq excel) {
@Override
public void importExcel(CostTypeImportExcelReq req) throws IOException {
CostTypeImportExcelItemListener costTypeImportExcelItemListener = new CostTypeImportExcelItemListener(
this.getCostTemplateType(req.getType()),
accountingSubjectMapper,
baseMapper
);
EasyExcel.read(req.getExcel().getInputStream(), CostTypeImportExcelItem.class, costTypeImportExcelItemListener).sheet().doRead();
}
@Override
public void exportExcel(HttpServletResponse response, CostTypeExportExcelReq req) {
public void exportExcel(HttpServletResponse response, CostTypeExportExcelReq req) throws IOException {
// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(IdWorker.getIdStr(), "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
req.setCostTemplateType(this.getCostTemplateType(req.getType()));
List<CostTypeExportExcelItem> list = baseMapper.queryAll(req)
.stream()
.map(costTypeResult -> {
CostTypeExportExcelItem item = new CostTypeExportExcelItem();
BeanUtils.copyProperties(costTypeResult, item);
return item;
})
.collect(Collectors.toList());
EasyExcel.write(response.getOutputStream(), CostTypeExportExcelItem.class)
.sheet("sheet")
.doWrite(list);
}
/**
* 根据ui类型获取费用类型 对应的费用模版类型
*
* @param type 1-费用类型 2-收入类型
* @param type 1-费用类型 2-收入类型 3-借支类型
* @return res
*/
private Integer getCostTemplateType(Integer type) {
......
......@@ -4,6 +4,7 @@ package com.blt.other.module.sys.controller;
import com.bailuntec.cost.api.response.CostResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blt.other.module.cost.dto.request.*;
import com.blt.other.module.sys.dto.request.*;
import com.blt.other.module.sys.model.SpecDepartmentCheckConfig;
import com.blt.other.module.sys.service.ISpecDepartmentCheckConfigService;
import io.swagger.annotations.Api;
......
package com.blt.other.module.cost.dto.request;
package com.blt.other.module.sys.dto.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......
package com.blt.other.module.cost.dto.request;
package com.blt.other.module.sys.dto.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......
package com.blt.other.module.sys.dto.request;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2021/1/13 3:25 下午
*/
@Data
public class SpecDepartmentCheckConfigImportExcelItem {
@ExcelProperty("付款财务主体")
@ApiModelProperty(value = "付款财务主体")
private String costCompanyName;
@ExcelProperty("申请人oa公司")
@ApiModelProperty(value = "申请人oa公司")
private String oaCompany;
@ExcelProperty(value = "特殊审核部门")
@ApiModelProperty(value = "特殊审核部门")
private String reviewerDepartmentName;
}
package com.blt.other.module.cost.dto.request;
package com.blt.other.module.sys.dto.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......
package com.blt.other.module.cost.dto.request;
package com.blt.other.module.sys.dto.request;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
......
package com.blt.other.module.cost.dto.request;
package com.blt.other.module.sys.dto.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......
package com.blt.other.module.cost.dto.request;
package com.blt.other.module.sys.dto.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* <p>
*
......
package com.blt.other.module.sys.dto.response;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2021/1/13 3:27 下午
*/
@Data
public class SpecDepartmentCheckConfigExportExcelItem {
@ExcelProperty("付款财务主体")
@ApiModelProperty(value = "付款财务主体")
private String costCompanyName;
@ExcelProperty("申请人oa公司")
@ApiModelProperty(value = "申请人oa公司")
private String oaCompany;
@ExcelProperty(value = "特殊审核部门")
@ApiModelProperty(value = "特殊审核部门")
private String reviewerDepartmentName;
}
......@@ -3,6 +3,7 @@ package com.blt.other.module.sys.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.blt.other.module.cost.dto.request.*;
import com.blt.other.module.sys.dto.request.*;
import com.blt.other.module.sys.model.SpecDepartmentCheckConfig;
import javax.servlet.http.HttpServletResponse;
......
package com.blt.other.module.sys.service.impl;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.blt.other.module.auth.dao.OaDepartmentMapper;
import com.blt.other.module.auth.service.IOaCompanyService;
import com.blt.other.module.sys.dto.request.SpecDepartmentCheckConfigImportExcelItem;
import com.blt.other.module.cost.service.CostCompanyService;
import com.blt.other.module.sys.model.SpecDepartmentCheckConfig;
import com.blt.other.module.sys.service.ISpecDepartmentCheckConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2021/1/13 3:27 下午
*/
public class SpecDepartmentCheckConfigExcelItemListener extends AnalysisEventListener<SpecDepartmentCheckConfigImportExcelItem> {
private final ISpecDepartmentCheckConfigService specDepartmentCheckConfigService;
private final CostCompanyService costCompanyService;
private final IOaCompanyService oaCompanyService;
private final OaDepartmentMapper oaDepartmentMapper;
private static final Logger LOGGER = LoggerFactory.getLogger(SpecDepartmentCheckConfigExcelItemListener.class);
SpecDepartmentCheckConfigExcelItemListener(ISpecDepartmentCheckConfigService specDepartmentCheckConfigService,
CostCompanyService costCompanyService,
IOaCompanyService oaCompanyService,
OaDepartmentMapper oaDepartmentMapper) {
this.specDepartmentCheckConfigService = specDepartmentCheckConfigService;
this.costCompanyService = costCompanyService;
this.oaCompanyService = oaCompanyService;
this.oaDepartmentMapper = oaDepartmentMapper;
}
private static final int BATCH_COUNT = 2000;
List<SpecDepartmentCheckConfigImportExcelItem> list = new ArrayList<>();
@Override
public void invoke(SpecDepartmentCheckConfigImportExcelItem data, AnalysisContext context) {
LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data));
list.add(data);
if (list.size() >= BATCH_COUNT) {
syncData();
list.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
syncData();
LOGGER.info("所有数据解析完成!");
}
private void syncData() {
LOGGER.info("{}条数据,开始存储数据库!", list.size());
List<SpecDepartmentCheckConfig> specDepartmentCheckConfigList = list.stream()
.map(specDepartmentCheckConfigImportExcelItem -> {
SpecDepartmentCheckConfig specDepartmentCheckConfig = new SpecDepartmentCheckConfig();
specDepartmentCheckConfig.setCostCompanyName(specDepartmentCheckConfigImportExcelItem.getCostCompanyName());
specDepartmentCheckConfig.setCostCompanyId(costCompanyService.costCompanyMap().get(specDepartmentCheckConfigImportExcelItem.getCostCompanyName()).getId());
specDepartmentCheckConfig.setOaCompany(specDepartmentCheckConfig.getOaCompany());
specDepartmentCheckConfig.setOaCompanyId(oaCompanyService.companyDict().get(specDepartmentCheckConfigImportExcelItem.getOaCompany()).getOaCompanyId());
specDepartmentCheckConfig.setReviewerDepartmentId(oaDepartmentMapper.selectByName(specDepartmentCheckConfigImportExcelItem.getReviewerDepartmentName()).getDepartmentId());
specDepartmentCheckConfig.setReviewerDepartmentName(specDepartmentCheckConfigImportExcelItem.getReviewerDepartmentName());
specDepartmentCheckConfig.setLastUpdateTime(LocalDateTime.now());
return specDepartmentCheckConfig;
})
.filter(specDepartmentCheckConfig -> specDepartmentCheckConfig.getCostCompanyId() != null)
.filter(specDepartmentCheckConfig -> specDepartmentCheckConfig.getOaCompanyId() != null)
.filter(specDepartmentCheckConfig -> specDepartmentCheckConfig.getReviewerDepartmentId() != null)
.collect(Collectors.toList());
specDepartmentCheckConfigService.saveBatch(specDepartmentCheckConfigList);
LOGGER.info("存储数据库成功!");
}
}
package com.blt.other.module.sys.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -16,13 +13,11 @@ import com.blt.other.module.auth.model.OaUser;
import com.blt.other.module.auth.service.IOaCompanyService;
import com.blt.other.module.cost.dao.SpecDepartmentCheckConfigMapper;
import com.blt.other.module.cost.dto.request.*;
import com.blt.other.module.sys.dto.request.*;
import com.blt.other.module.sys.dto.response.SpecDepartmentCheckConfigExportExcelItem;
import com.blt.other.module.cost.service.CostCompanyService;
import com.blt.other.module.sys.model.SpecDepartmentCheckConfig;
import com.blt.other.module.sys.service.ISpecDepartmentCheckConfigService;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -30,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -131,12 +125,13 @@ public class SpecDepartmentCheckConfigServiceImpl extends ServiceImpl<SpecDepart
@Override
public void exportExcel(HttpServletResponse response, SpecDepartmentCheckExportExcelReq req) throws IOException {
// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
//
String fileName = URLEncoder.encode("模版", "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
LongestMatchColumnWidthStyleStrategy longestMatchColumnWidthStyleStrategy = new LongestMatchColumnWidthStyleStrategy();
List<SpecDepartmentCheckConfigExportExcelItem> aiList = baseMapper.selectList(this.buildQueryWrapper(req)).stream()
.map(specDepartmentCheckConfig -> {
SpecDepartmentCheckConfigExportExcelItem item = new SpecDepartmentCheckConfigExportExcelItem();
......@@ -146,7 +141,10 @@ public class SpecDepartmentCheckConfigServiceImpl extends ServiceImpl<SpecDepart
return item;
})
.collect(Collectors.toList());
EasyExcel.write(response.getOutputStream(), SpecDepartmentCheckConfigExportExcelItem.class).sheet("sheet").doWrite(aiList);
EasyExcel.write(response.getOutputStream(), SpecDepartmentCheckConfigExportExcelItem.class)
.sheet("sheet")
.registerWriteHandler(longestMatchColumnWidthStyleStrategy)
.doWrite(aiList);
}
@Override
......@@ -180,106 +178,4 @@ public class SpecDepartmentCheckConfigServiceImpl extends ServiceImpl<SpecDepart
}
@Data
static class SpecDepartmentCheckConfigExportExcelItem {
@ExcelProperty("付款财务主体")
@ApiModelProperty(value = "付款财务主体")
private String costCompanyName;
@ExcelProperty("申请人oa公司")
@ApiModelProperty(value = "申请人oa公司")
private String oaCompany;
@ExcelProperty(value = "特殊审核部门")
@ApiModelProperty(value = "特殊审核部门")
private String reviewerDepartmentName;
}
@Data
static class SpecDepartmentCheckConfigImportExcelItem {
@ExcelProperty("付款财务主体")
@ApiModelProperty(value = "付款财务主体")
private String costCompanyName;
@ExcelProperty("申请人oa公司")
@ApiModelProperty(value = "申请人oa公司")
private String oaCompany;
@ExcelProperty(value = "特殊审核部门")
@ApiModelProperty(value = "特殊审核部门")
private String reviewerDepartmentName;
}
static class SpecDepartmentCheckConfigExcelItemListener extends AnalysisEventListener<SpecDepartmentCheckConfigImportExcelItem> {
private final ISpecDepartmentCheckConfigService specDepartmentCheckConfigService;
private final CostCompanyService costCompanyService;
private final IOaCompanyService oaCompanyService;
private final OaDepartmentMapper oaDepartmentMapper;
private static final Logger LOGGER = LoggerFactory.getLogger(SpecDepartmentCheckConfigExcelItemListener.class);
SpecDepartmentCheckConfigExcelItemListener(ISpecDepartmentCheckConfigService specDepartmentCheckConfigService,
CostCompanyService costCompanyService,
IOaCompanyService oaCompanyService,
OaDepartmentMapper oaDepartmentMapper) {
this.specDepartmentCheckConfigService = specDepartmentCheckConfigService;
this.costCompanyService = costCompanyService;
this.oaCompanyService = oaCompanyService;
this.oaDepartmentMapper = oaDepartmentMapper;
}
private static final int BATCH_COUNT = 2000;
List<SpecDepartmentCheckConfigImportExcelItem> list = new ArrayList<>();
@Override
public void invoke(SpecDepartmentCheckConfigImportExcelItem data, AnalysisContext context) {
LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data));
list.add(data);
if (list.size() >= BATCH_COUNT) {
syncData();
list.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
syncData();
LOGGER.info("所有数据解析完成!");
}
private void syncData() {
LOGGER.info("{}条数据,开始存储数据库!", list.size());
List<SpecDepartmentCheckConfig> specDepartmentCheckConfigList = list.stream()
.map(specDepartmentCheckConfigImportExcelItem -> {
SpecDepartmentCheckConfig specDepartmentCheckConfig = new SpecDepartmentCheckConfig();
specDepartmentCheckConfig.setCostCompanyName(specDepartmentCheckConfigImportExcelItem.getCostCompanyName());
specDepartmentCheckConfig.setCostCompanyId(costCompanyService.costCompanyMap().get(specDepartmentCheckConfigImportExcelItem.getCostCompanyName()).getId());
specDepartmentCheckConfig.setOaCompany(specDepartmentCheckConfig.getOaCompany());
specDepartmentCheckConfig.setOaCompanyId(oaCompanyService.companyDict().get(specDepartmentCheckConfigImportExcelItem.getOaCompany()).getOaCompanyId());
specDepartmentCheckConfig.setReviewerDepartmentId(oaDepartmentMapper.selectByName(specDepartmentCheckConfigImportExcelItem.getReviewerDepartmentName()).getDepartmentId());
specDepartmentCheckConfig.setReviewerDepartmentName(specDepartmentCheckConfigImportExcelItem.getReviewerDepartmentName());
specDepartmentCheckConfig.setLastUpdateTime(LocalDateTime.now());
return specDepartmentCheckConfig;
})
.filter(specDepartmentCheckConfig -> specDepartmentCheckConfig.getCostCompanyId() != null)
.filter(specDepartmentCheckConfig -> specDepartmentCheckConfig.getOaCompanyId() != null)
.filter(specDepartmentCheckConfig -> specDepartmentCheckConfig.getReviewerDepartmentId() != null)
.collect(Collectors.toList());
specDepartmentCheckConfigService.saveBatch(specDepartmentCheckConfigList);
LOGGER.info("存储数据库成功!");
}
}
}
......@@ -4,6 +4,14 @@
<mapper namespace="com.blt.other.module.cost.dao.CostTypeDao">
<select id="queryPage" resultType="com.blt.other.module.cost.dto.response.CostTypeResult">
<include refid="query"/>
</select>
<select id="queryAll" resultType="com.blt.other.module.cost.dto.response.CostTypeResult">
<include refid="query"/>
</select>
<sql id="query">
select t1.id,
t1.type_no,
t1.type_name,
......@@ -22,7 +30,7 @@
<if test="req.accountingSubjectNo !=null">
and t1.accounting_subject_no = #{req.accountingSubjectNo}
</if>
</select>
</sql>
<select id="selectByNo" resultType="com.blt.other.database.model.CostTypeDomain">
select *
......@@ -73,9 +81,11 @@
</select>
<select id="selectTestType" resultType="com.blt.other.database.model.CostTypeDomain">
SELECT t1.* from cost_type t1
LEFT JOIN cost_type t2 on t1.type_name =t2.type_name and t2.cost_template_type = 2
where t1.cost_template_type = 9 and t2.id is null;
SELECT t1.*
from cost_type t1
LEFT JOIN cost_type t2 on t1.type_name = t2.type_name and t2.cost_template_type = 2
where t1.cost_template_type = 9
and t2.id is null;
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment