Commit 38d65050 by liyanlin

增加zip批量添加费用计划功能

parent a7af8ba4
......@@ -295,6 +295,19 @@
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!--zip解压-->
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.0</version>
</dependency>
<!-- 导入rar解压包 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
......
package com.blt.other.common.util;
import org.apache.poi.ss.usermodel.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static org.apache.poi.ss.usermodel.CellType.*;
import static org.apache.poi.ss.usermodel.CellType.NUMERIC;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
public class ExcelUtil {
public static List<Map<String,Object>> ExcelData(Workbook wb){
List<Map<String,Object>> list = new ArrayList<>();
Sheet sheet = null;
Row row = null;
Object cellData = null;
if(wb != null){
//用来存放表中数据
list = new ArrayList<>();
//获取第一个sheet
sheet = wb.getSheetAt(0);
//获取最大行数
int rowNum = sheet.getPhysicalNumberOfRows();
//获取第一行
row = sheet.getRow(0);
//获取最大列数
int colNum = row.getPhysicalNumberOfCells();
for (int i = 1; i<rowNum; i++) {
Map<String,Object> map = new LinkedHashMap<>();
row = sheet.getRow(i);
if(row !=null){
for (int j=0;j<colNum;j++){
cellData = getCellFormatValue(row.getCell(j));
//map.put(columns[j], cellData);
}
}else{
break;
}
list.add(map);
}
}
return list;
}
public static Object getCellFormatValue(Cell cell){
Object cellValue = null;
if(cell!=null){
//判断cell类型
switch(cell.getCellTypeEnum()){
case NUMERIC:{
cellValue = String.valueOf(cell.getNumericCellValue());
break;
}
case FORMULA:{
//判断cell是否为日期格式
if(DateUtil.isCellDateFormatted(cell)){
//转换为日期格式YYYY-mm-dd
cellValue = cell.getDateCellValue();
}else{
//数字
cellValue = String.valueOf(cell.getNumericCellValue());
}
break;
}
case STRING:{
cellValue = cell.getRichStringCellValue().getString();
break;
}
default:
cellValue = "";
}
}else{
cellValue = "";
}
return cellValue;
}
}
package com.blt.other.common.wrapper;
import lombok.extern.slf4j.Slf4j;
import java.util.function.Consumer;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
@FunctionalInterface
public interface ThrowingConsumer<T, E extends Exception> {
void accept(T t) throws E;
static <T> Consumer<T> throwingConsumerWrapper(ThrowingConsumer<T, Exception> throwingConsumer) {
return i -> {
try {
throwingConsumer.accept(i);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
};
}
static <T, E extends Exception> Consumer<T> handlingConsumerWrapper(ThrowingConsumer<T, E> throwingConsumer, Class<E> exceptionClass) {
return i -> {
try {
throwingConsumer.accept(i);
} catch (Exception ex) {
try {
E exCast = exceptionClass.cast(ex);
System.err.println(
"Exception occured : " + exCast.getMessage());
} catch (ClassCastException ccEx) {
throw new RuntimeException(ex);
}
}
};
}
}
......@@ -167,6 +167,9 @@ public class CostPlanDomain implements Serializable {
@ApiModelProperty("项目")
private String projectType;
@ApiModelProperty("客户编号")
private String customerNum;
public CostPlanDto castToDto() {
StatusMapper statusMapper = SpringContextUtil.getBean(StatusMapper.class);
......
......@@ -15,17 +15,17 @@ import java.time.LocalDateTime;
public class CostTypeDomain {
/**
* 费用类型 包括付款 借还
* 费用类型 包括付款 借还 9
*/
public static final Integer FEE_TYPE = 0b1001;
/**
* 收入类别 包括收款
* 收入类别 包括收款 4
*/
public static final Integer INCOME_TYPE = 0b0100;
/**
* 借支类别 包括借支
* 借支类别 包括借支 2
*/
public static final Integer BORROW = 0b0010;
......
package com.blt.other.module.cost.controller;
import com.bailuntec.cost.api.response.CostResult;
import com.blt.other.common.annotation.LoginIgnore;
import com.blt.other.common.exception.BizRuntimeException;
import com.blt.other.common.util.CurUtils;
import com.blt.other.common.util.PathUtil;
import com.blt.other.database.model.CostPlanDomain;
import com.blt.other.module.cost.dto.response.RestResp;
import com.blt.other.module.cost.dto.response.SaveResp;
import com.blt.other.module.cost.service.CostPlanService;
import com.blt.other.module.cost.service.impl.costplan.CostPlanServiceFactory;
import com.mchange.v2.uid.UidUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.joining;
@Slf4j
@Api(tags = "费用计划接口")
......@@ -132,4 +146,38 @@ public class CostPlanNewController {
return result;
}
@LoginIgnore
@ApiOperation("rar导入费用计划")
@PostMapping("/upload")
public CostResult<String> upload(MultipartFile file, String userCode) {
/*附件字段*/
if (file != null && file.getOriginalFilename().endsWith(".zip")) {
try {
InputStream is = file.getResource().getInputStream();
File rar = File.createTempFile(UidUtils.VM_ID + "fee-original", ".zip");
file.transferTo(rar);
Map<CostPlanService, List<CostPlanDomain>> costPlanServiceListMap = CostPlanServiceFactory.getCostPlanService(rar, userCode);
costPlanServiceListMap.forEach((x, y) -> {
y.forEach(costPlanDomain -> {
x.save(costPlanDomain);
});
});
String costPlanNos = costPlanServiceListMap.values()
.stream()
.map(x -> x.stream()
.map(y -> y.getCostPlanNo())
.collect(joining(","))
)
.collect(joining(","));
return new CostResult<String>().success("费用计划单号:" + costPlanNos);
} catch (IOException e) {
e.printStackTrace();
return new CostResult<String>().error("无法读取文件");
} catch (Exception exception) {
return new CostResult<String>().error(exception.getMessage());
}
}
return new CostResult<String>().error("文件为空或不是.zip格式");
}
}
......@@ -58,6 +58,13 @@ public interface CostTypeDao extends BaseMapper<CostTypeDomain> {
CostTypeResult queryByNo(String typeNo);
/**
* 获取费用类型详情
* @param typeName
* @return
*/
List<CostTypeResult> queryByTypeName(@Param("typeName") String typeName,@Param("costTemplateType") Integer costTemplateType);
/**
* 根据费用类型名称和类型查询
*
* @param name name
......
......@@ -7,9 +7,11 @@ import com.blt.other.module.cost.dto.request.*;
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;
import org.apache.ibatis.annotations.Param;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
public interface CostTypeService extends IService<CostTypeDomain> {
......@@ -60,6 +62,14 @@ public interface CostTypeService extends IService<CostTypeDomain> {
CostTypeResult queryByNo(String typeNo);
/**
* 根据名称和模板类型获取费用费用详情
* @param typeName
* @param costTemplateType
* @return
*/
List<CostTypeResult> queryByTypeName(String typeName, Integer costTemplateType);
/**
* 获取物流subjectCode
*
* @return rs
......
......@@ -147,6 +147,11 @@ public class CostTypeServiceImpl extends ServiceImpl<CostTypeDao, CostTypeDomain
}
@Override
public List<CostTypeResult> queryByTypeName(String typeName, Integer costTemplateType){
return baseMapper.queryByTypeName(typeName, costTemplateType);
}
@Override
public GetLogisticsCodeResp getLogisticsCode() {
GetLogisticsCodeResp resp = new GetLogisticsCodeResp();
resp.setSuccess(true);
......
......@@ -5,6 +5,7 @@ import com.bailuntec.common.StringUtils;
import com.bailuntec.common.exception.BizException;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.blt.other.common.util.PathUtil;
import com.mchange.v2.uid.UidUtils;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
......@@ -51,6 +52,7 @@ public class CostFileUtil {
return fileName;
}
public static String upload(String netUrl, String filePath) throws IOException {
RestTemplate restTemplate = new RestTemplate();
......@@ -79,7 +81,7 @@ public class CostFileUtil {
}
public String saveImage(MultipartFile multipartFile) throws IOException {
public static String saveImage(MultipartFile multipartFile) throws IOException {
//临时文件地址
String basePath = PathUtil.getBasePath() + PathUtil.getPath("cost/");
//文件名
......@@ -100,27 +102,25 @@ public class CostFileUtil {
return qiniuUpload(localFile);
}
public String qiniuUpload(File localFilePath) {
public static String qiniuUpload(File localFilePath) {
//1、构造一个带指定Zone对象的配置类
// Configuration cfg = new Configuration(Zone.zone2());
Configuration cfg = new Configuration(Region.region2());
//2、其他参数参考类注释
UploadManager uploadManager = new UploadManager(cfg);
//3、生成上传凭证,然后准备上传
String accessKey = "RWQXlbVA7oe3BxnPuFtqkAJocQZkWTwrwYyldklr";
String secretKey = "tS2gxsQO26mGoFZJI-x8WSH9X5aPgYMJcyoJdak5";
String bucket = "begogirls";
String accessKey = "QSvtvN4Ons1CiNzaMGqx8XmDaiM1L0ZqSwJ2YoTn";
String secretKey = "yagRd-cBOVhkRGGT-o_reMqNVjI8_k7YwoTXkhrm";
String bucket = "bailun-data-center";
//默认不指定key的情况下,以文件内容的hash值作为文件名
String key = null;
String key = UidUtils.VM_ID + "-" + localFilePath.getName();
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
try {
Response response = uploadManager.put(localFilePath, key, upToken);
//4、解析上传成功的结果
DefaultPutRet putRet = JsonUtilByFsJson.jsonToBean(response.bodyString(), DefaultPutRet.class);
System.out.println(putRet.key);
System.out.println(putRet.hash);
return putRet.key;
} catch (QiniuException ex) {
Response r = ex.response;
......
package com.blt.other.module.cost.vo;
import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
@Slf4j
public enum CostPlanEnumVo {
companyName(new HashMap<String, String>() {
{
put("付款", "付款主体");
put("收款", "收款主体");
put("借支", "付款主体");
put("借还", "收款主体");
}
}),
bankCompany(new HashMap<String, String>() {
{
put("付款", "收款单位");
put("收款", "付款单位");
put("借支", "收款单位");
}
}),
bankName(new HashMap<String, String>() {
{
put("付款", "收款银行");
put("收款", "付款银行");
put("借支", "收款银行");
}
}),
bankCard(new HashMap<String, String>() {
{
put("付款", "收款账户");
put("收款", "付款账户");
put("借支", "收款账户");
}
}),
bankCardUser(new HashMap<String, String>() {
{
put("付款", "持卡人");
put("收款", "持卡人");
put("借支", "持卡人");
}
}),
costRemark(new HashMap<String, String>() {
{
put("付款", "备注");
put("收款", "备注");
put("借支", "备注");
put("借还", "备注");
}
}),
lendType(new HashMap<String, String>() {
{
put("借支", "借支类别");
put("借还", "借支类别");
}
}),
supCostNo(new HashMap<String, String>() {
{
put("借还", "关联借支单");
}
}),
typeName(new HashMap<String, String>() {
{
put("付款", "费用类别");
put("收款", "收入类别");
put("借支", "费用类别");
put("借还", "费用类别");
}
}),
projectType(new HashMap<String, String>() {
{
put("收款", "项目");
}
}),
payCounteract(new HashMap<String, String>() {
{
put("借还", "冲销金额");
}
}),
payLendBalance(new HashMap<String, String>() {
{
put("借还", "归还金额");
}
}),
customerNum(new HashMap<String, String>() {
{
put("收款", "客户编号");
}
}),
dic(new HashMap<String, String>() {
{
put("付款", "币种");
put("收款", "币种");
put("借支", "币种");
}
}),
payDic(new HashMap<String, String>() {
{
put("借还", "借还币种");
}
}),
planAmount(new HashMap<String, String>() {
{
put("收款", "原币金额");
put("借支", "原币金额");
}
}),
amount(new HashMap<String, String>() {
{
put("付款", "原币金额");
}
}),
costReason(new HashMap<String, String>() {
{
put("付款", "费用用途");
put("收款", "收款理由");
put("借支", "借支理由");
put("借还", "借还理由");
}
}),
filePath(new HashMap<String, String>() {
{
put("付款", "附件名");
put("收款", "附件名");
put("借支", "附件名");
put("借还", "附件名");
}
});
private Map<String, String> typeMap;
private Class clazz;
private String parseMethod;
CostPlanEnumVo(Map<String, String> typeMap) {
this.typeMap = typeMap;
}
public static CostPlanEnumVo match(String name, CostPlanEnumVo defaultItem){
for (CostPlanEnumVo item: CostPlanEnumVo.values()) {
if (item.name().equals(name)) {
return item;
}
}
return defaultItem;
}
public static String getCostPlanField(String type, String fieldName){
try {
for (CostPlanEnumVo item : CostPlanEnumVo.values()) {
if(item.typeMap.get(type) == null){
continue;
}
if (item.typeMap.get(type).equals(fieldName)) {
return item.name();
}
}
}catch (Exception ex){
log.error(ex.toString());
}
return "";
}
}
......@@ -81,6 +81,26 @@
where t1.type_no = #{typeNo}
</select>
<select id="queryByTypeName" resultType="com.blt.other.module.cost.dto.response.CostTypeResult">
select t1.id,
t1.type_no,
t1.type_name,
t1.description,
t1.accounting_subject_no,
t2.name as accounting_subject_name,
t1.create_time,
t1.update_user,
t1.update_user_id,
t1.last_update_time,
t1.create_user_id,
t1.create_user,
t1.is_manage_cost
from cost_type t1
left join accounting_subject t2 on t1.accounting_subject_no = t2.subject_no
where t1.type_name = #{typeName}
and t1.cost_template_type = #{costTemplateType}
</select>
<select id="selectByNameAndType" resultType="com.blt.other.database.model.CostTypeDomain">
select *
from cost_type
......
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