|
|
|
@ -1,18 +1,30 @@
|
|
|
|
|
package jnpf.controller;
|
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import jnpf.config.ConfigValueUtil;
|
|
|
|
|
import cn.xuyanwu.spring.file.storage.FileInfo;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import jnpf.base.ActionResult;
|
|
|
|
|
import jnpf.base.UserInfo;
|
|
|
|
|
import jnpf.base.model.ColumnDataModel;
|
|
|
|
|
import jnpf.base.util.VisualUtils;
|
|
|
|
|
import jnpf.exception.DataException;
|
|
|
|
|
import jnpf.model.visualJson.config.HeaderModel;
|
|
|
|
|
import jnpf.permission.entity.UserEntity;
|
|
|
|
|
import jnpf.service.*;
|
|
|
|
|
import jnpf.entity.*;
|
|
|
|
|
import jnpf.util.*;
|
|
|
|
|
import jnpf.model.enterpriseaccountbill.*;
|
|
|
|
|
import lombok.Cleanup;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
@ -28,6 +40,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
import jnpf.engine.entity.FlowTaskEntity;
|
|
|
|
|
import jnpf.exception.WorkFlowException;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* EnterpriseAccountBill
|
|
|
|
@ -48,6 +61,9 @@ public class EnterpriseAccountBillController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserProvider userProvider;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ConfigValueUtil configValueUtil;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EnterpriseAccountBillService enterpriseAccountBillService;
|
|
|
|
|
|
|
|
|
@ -101,6 +117,137 @@ public class EnterpriseAccountBillController {
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success("创建成功");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 导出Excel
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Operation(summary = "导出Excel")
|
|
|
|
|
@PostMapping("/Actions/Export")
|
|
|
|
|
public ActionResult Export(@RequestBody EnterpriseAccountBillPagination enterpriseAccountBillPagination) throws IOException {
|
|
|
|
|
if (StringUtil.isEmpty(enterpriseAccountBillPagination.getSelectKey())){
|
|
|
|
|
return ActionResult.fail("请选择导出字段");
|
|
|
|
|
}
|
|
|
|
|
List<EnterpriseAccountBillEntity> list= enterpriseAccountBillService.getList(enterpriseAccountBillPagination);
|
|
|
|
|
List<Map<String, Object>> realList=new ArrayList<>();
|
|
|
|
|
for (EnterpriseAccountBillEntity entity : list) {
|
|
|
|
|
Map<String, Object> enterpriseAccountBillEntityMap=JsonUtil.entityToMap(entity);
|
|
|
|
|
enterpriseAccountBillEntityMap.put("id", enterpriseAccountBillEntityMap.get("id"));
|
|
|
|
|
//副表数据
|
|
|
|
|
//子表数据
|
|
|
|
|
realList.add(enterpriseAccountBillEntityMap);
|
|
|
|
|
}
|
|
|
|
|
//数据转换
|
|
|
|
|
realList = generaterSwapUtil.swapDataList(realList, EnterpriseAccountBillConstant.getFormData(), EnterpriseAccountBillConstant.getColumnData(), enterpriseAccountBillPagination.getModuleId(),false);
|
|
|
|
|
String[]keys=!StringUtil.isEmpty(enterpriseAccountBillPagination.getSelectKey())?enterpriseAccountBillPagination.getSelectKey():new String[0];
|
|
|
|
|
UserInfo userInfo=userProvider.get();
|
|
|
|
|
DownloadVO vo=this.creatModelExcel(configValueUtil.getTemporaryFilePath(),realList,keys,userInfo);
|
|
|
|
|
return ActionResult.success(vo);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 导出表格方法
|
|
|
|
|
*/
|
|
|
|
|
public DownloadVO creatModelExcel(String path,List<Map<String, Object>>list,String[]keys,UserInfo userInfo){
|
|
|
|
|
DownloadVO vo=DownloadVO.builder().build();
|
|
|
|
|
List<ExcelExportEntity> entitys=new ArrayList<>();
|
|
|
|
|
if(keys.length>0){
|
|
|
|
|
for(String key:keys){
|
|
|
|
|
switch(key){
|
|
|
|
|
case "billNumber" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("流水编号" ,"billNumber"));
|
|
|
|
|
break;
|
|
|
|
|
case "orderNumber" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("订单编号" ,"orderNumber"));
|
|
|
|
|
break;
|
|
|
|
|
case "orderTypeId" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("订单类型" ,"orderTypeId"));
|
|
|
|
|
break;
|
|
|
|
|
// case "billStatusId" :
|
|
|
|
|
// entitys.add(new ExcelExportEntity("单据状态" ,"billStatusId"));
|
|
|
|
|
// break;
|
|
|
|
|
case "incomeAmount" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("收入(元)" ,"incomeAmount"));
|
|
|
|
|
break;
|
|
|
|
|
case "payoutAmount" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("支出(元)" ,"payoutAmount"));
|
|
|
|
|
break;
|
|
|
|
|
case "accountBalance" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("余额(元)" ,"accountBalance"));
|
|
|
|
|
break;
|
|
|
|
|
case "creatorUserId" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("创建用户" ,"creatorUserId"));
|
|
|
|
|
break;
|
|
|
|
|
case "creatorTime" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("创建时间" ,"creatorTime"));
|
|
|
|
|
break;
|
|
|
|
|
case "remark" :
|
|
|
|
|
entitys.add(new ExcelExportEntity("备注" ,"remark"));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExportParams exportParams = new ExportParams(null, "表单信息");
|
|
|
|
|
exportParams.setType(ExcelType.XSSF);
|
|
|
|
|
try{
|
|
|
|
|
@Cleanup Workbook workbook = new HSSFWorkbook();
|
|
|
|
|
if (entitys.size()>0){
|
|
|
|
|
if (list.size()==0){
|
|
|
|
|
list.add(new HashMap<>());
|
|
|
|
|
}
|
|
|
|
|
//去除空数据
|
|
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
|
|
for (Map<String, Object> map : list) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (String key : keys) {
|
|
|
|
|
//子表
|
|
|
|
|
if (key.toLowerCase().startsWith("tablefield")) {
|
|
|
|
|
String tableField = key.substring(0, key.indexOf("-" ));
|
|
|
|
|
String field = key.substring(key.indexOf("-" ) + 1);
|
|
|
|
|
Object o = map.get(tableField);
|
|
|
|
|
if (o != null) {
|
|
|
|
|
List<Map<String, Object>> childList = (List<Map<String, Object>>) o;
|
|
|
|
|
for (Map<String, Object> childMap : childList) {
|
|
|
|
|
if (childMap.get(field) != null) {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Object o = map.get(key);
|
|
|
|
|
if (o != null) {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
dataList.add(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//复杂表头-表头和数据处理
|
|
|
|
|
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(EnterpriseAccountBillConstant.getColumnData(), ColumnDataModel.class);
|
|
|
|
|
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
|
|
|
|
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
|
|
|
|
entitys = VisualUtils.complexHeaderHandel(entitys, complexHeaderList);
|
|
|
|
|
dataList = VisualUtils.complexHeaderDataHandel(dataList, complexHeaderList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, dataList);
|
|
|
|
|
}
|
|
|
|
|
String fileName = "表单信息" + DateUtil.dateNow("yyyyMMdd") + "_" + RandomUtil.uuId() + ".xlsx";
|
|
|
|
|
MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
|
|
|
|
|
String temporaryFilePath = configValueUtil.getTemporaryFilePath();
|
|
|
|
|
FileInfo fileInfo = FileUploadUtils.uploadFile(multipartFile, temporaryFilePath, fileName);
|
|
|
|
|
vo.setName(fileInfo.getFilename());
|
|
|
|
|
vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + fileName);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("信息导出Excel错误:{}", e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 编辑
|
|
|
|
|
* @param id
|
|
|
|
|