Commit 84bc1e6f by huluobin

update

parent f6259876
......@@ -15,4 +15,6 @@ public interface AccountingSubjectMapper extends BaseMapper<AccountingSubject> {
//根据编号查
AccountingSubject selectByNo(String accountingSubjectNo);
AccountingSubject selectByName(String accountType);
}
......@@ -7,4 +7,10 @@
from accounting_subject
where subject_no = #{accountingSubjectNo}
</select>
<select id="selectByName" resultType="com.blt.other.module.cost.model.AccountingSubject">
select *
from accounting_subject
where name = #{accountType}
</select>
</mapper>
package com.blt.other;
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.bailuntec.api.bailuntec.oa.OaApi;
import com.bailuntec.api.bailuntec.oa.response.OaDepartmentResp;
import com.bailuntec.api.bailuntec.oa.response.OaUserResp;
import com.bailuntec.common.SpringContextUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.blt.other.database.model.CostTypeDomain;
import com.blt.other.module.auth.dao.OaDepartmentMapper;
import com.blt.other.module.auth.model.OaDepartment;
import com.blt.other.module.auth.model.OaUser;
import com.blt.other.module.auth.service.IOaDepartmentService;
import com.blt.other.module.auth.service.IOaUserService;
import com.blt.other.module.cost.service.impl.costcheck.CostContext;
import com.blt.other.module.cost.service.impl.costcheck.DepartmentCheckState;
import com.blt.other.module.cost.dao.AccountingSubjectMapper;
import com.blt.other.module.cost.dao.CostTypeDao;
import com.blt.other.module.cost.model.AccountingSubject;
import com.blt.other.module.sys.dao.CostReviewerMapper;
import com.blt.other.module.sys.dao.DepartmentReviewerMapper;
import com.blt.other.module.sys.model.CostReviewer;
import com.blt.other.module.sys.model.DepartmentReviewer;
import lombok.Data;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
......@@ -26,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -49,12 +62,12 @@ public class OtherApplicationTests {
@Resource
DepartmentReviewerMapper departmentReviewerMapper;
@Rollback
@Rollback(value = false)
@Test
public void syncDepartmentReviewer() {
departmentReviewerMapper.delete(new LambdaQueryWrapper<>());
costReviewerMapper.delete(new LambdaQueryWrapper<CostReviewer>()
.eq(CostReviewer::getType, CostReviewer.departmentReviewer));
// costReviewerMapper.delete(new LambdaQueryWrapper<CostReviewer>()
// .eq(CostReviewer::getType, CostReviewer.departmentReviewer));
List<CostReviewer> costReviewerList = costReviewerMapper.selectList(new LambdaQueryWrapper<CostReviewer>()
.eq(CostReviewer::getType, 1));
......@@ -155,14 +168,89 @@ public class OtherApplicationTests {
return getPrimaryDepartment(departmentMap, departmentMap.get(oaDepartment.getParentId()));
}
@Resource
DepartmentCheckState departmentCheckState;
@Rollback(value = false)
@Test
public void importMallProduct() {
CostContext costContext = new CostContext("F029432", null);
costContext.setCostState(departmentCheckState);
costContext.handle();
TypeListener typeListener = new TypeListener();
EasyExcel.read("/Users/huluobin/费用类型.xlsx", TypeItem.class, typeListener).sheet().doRead();
}
@Data
public static class TypeItem {
@ExcelProperty("desc")
private String desc;
@ExcelProperty("type")
private String type;
@ExcelProperty(value = "account_type")
private String accountType;
@ExcelProperty(value = "cost_type")
private Integer costType;
}
public static class TypeListener extends AnalysisEventListener<TypeItem> {
private static final Logger LOGGER = LoggerFactory.getLogger(TypeListener.class);
TypeListener() {
}
private static final int BATCH_COUNT = 2000;
List<TypeItem> list = new ArrayList<>();
@Override
public void invoke(TypeItem 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() {
list.forEach(item -> {
AccountingSubjectMapper accountingSubjectMapper = SpringContextUtil.getBean(AccountingSubjectMapper.class);
AccountingSubject accountingSubject = accountingSubjectMapper.selectByName(item.getAccountType());
if (accountingSubject == null) {
accountingSubject = new AccountingSubject();
accountingSubject.setName(item.getAccountType());
accountingSubject.setSubjectNo(IdWorker.getIdStr());
accountingSubjectMapper.insert(accountingSubject);
}
CostTypeDao costTypeDao = SpringContextUtil.getBean(CostTypeDao.class);
CostTypeDomain costTypeDomain = new CostTypeDomain();
if (item.getCostType() == 1) {
costTypeDomain.setCostTemplateType(CostTypeDomain.feeType);
}
if (item.getCostType() == 2) {
costTypeDomain.setCostTemplateType(CostTypeDomain.incomeType);
}
if (item.getCostType() == 3) {
costTypeDomain.setCostTemplateType(CostTypeDomain.borrow);
}
costTypeDomain.setTypeName(item.getType());
costTypeDomain.setTypeNo(IdWorker.getIdStr());
costTypeDomain.setDescription(item.getDesc());
costTypeDomain.setAccountingSubjectNo(accountingSubject.getSubjectNo());
costTypeDao.insert(costTypeDomain);
});
}
}
......
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