表格导出

This commit is contained in:
xiaofajia 2024-12-02 17:57:26 +08:00
parent ec33bcd1ce
commit 3b2a63352c
10 changed files with 434 additions and 5 deletions

View File

@ -1,12 +1,16 @@
package cn.iocoder.yudao.module.supplier.controller.admin; package cn.iocoder.yudao.module.supplier.controller.admin;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.supplier.entity.BaseSupplier; import cn.iocoder.yudao.module.supplier.entity.BaseSupplier;
import cn.iocoder.yudao.module.supplier.service.BaseSupplierService; import cn.iocoder.yudao.module.supplier.service.BaseSupplierService;
import cn.iocoder.yudao.module.supplier.vo.BaseSupplierPageReqVO; import cn.iocoder.yudao.module.supplier.vo.BaseSupplierPageReqVO;
import cn.iocoder.yudao.module.supplier.vo.BaseSupplierRespVO; import cn.iocoder.yudao.module.supplier.vo.BaseSupplierRespVO;
import cn.iocoder.yudao.module.supplier.vo.BaseSupplierSaveReqVO; import cn.iocoder.yudao.module.supplier.vo.BaseSupplierSaveReqVO;
import cn.iocoder.yudao.module.supplier.vo.SupplierExportVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -18,8 +22,15 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 供应商") @Tag(name = "管理后台 - 供应商")
@ -137,4 +148,40 @@ public class BaseSupplierController {
.like(BaseSupplier::getName,name); .like(BaseSupplier::getName,name);
return success(baseSupplierService.list(queryWrapper)); return success(baseSupplierService.list(queryWrapper));
} }
/**
* 导出数据
*
* @author 小李
* @date 17:30 2024/12/2
* @param pageReqVO 请求对象
**/
@GetMapping("/export")
@Operation(summary = "导出数据")
public void exportData(BaseSupplierPageReqVO pageReqVO, HttpServletResponse response)throws IOException {
int pageNo = 1, pageSize = 1000;
List<SupplierExportVO> list = new ArrayList<>();
Page<BaseSupplierRespVO> page = new Page<>(pageNo, pageSize);
do {
IPage<BaseSupplierRespVO> baseSupplierRespVOIPage = baseSupplierService.queryListPage(pageReqVO, page);
List<BaseSupplierRespVO> records = baseSupplierRespVOIPage.getRecords();
if (CollUtil.isEmpty(records)){
break;
}
List<SupplierExportVO> convertedRecords = records.stream().map(item -> BeanUtils.toBean(item, SupplierExportVO.class)).collect(Collectors.toList());
list.addAll(convertedRecords);
pageNo++;
page.setCurrent(pageNo);
}while (true);
if (CollUtil.isEmpty(list)){
throw exception0(500, "没有数据可以导出");
}
list.forEach(item -> {
if (ObjectUtil.isNotEmpty(item.getStatus())){
item.setStatus(item.getStatus().equals("01") ? "启用" : "禁用");
}
item.setCorpId(ObjectUtil.isEmpty(item.getCorpId()) ? "未绑定": "已绑定");
});
ExcelUtils.write(response, "供应商数据.xls", "数据", SupplierExportVO.class, list);
}
} }

View File

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.supplier.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 用于导出供应商VO
*
* @author 小李
* @date 17:30 2024/12/2
**/
@Data
@ExcelIgnoreUnannotated
public class SupplierExportVO {
@ExcelProperty("供应商名称")
private String name;
@ExcelProperty("联系人")
private String linkName;
@ExcelProperty("联系电话")
private String linkPhone;
@ExcelProperty("手机号码")
private String phone;
@ExcelProperty("传真")
private String fax;
@ExcelProperty("地址")
private String address;
@ExcelProperty("状态")
private String status;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("绑定状态")
private String corpId;
}

View File

@ -19,4 +19,7 @@ public interface RepairDictConstants {
/** 配件相关提醒配置 */ /** 配件相关提醒配置 */
String REPAIR_WARES_NOTICE = "repair_wares_notice"; String REPAIR_WARES_NOTICE = "repair_wares_notice";
/** 维修工人工种 */
String REPAIR_WORK_TYPE = "repair_work_type";
} }

View File

@ -1,15 +1,19 @@
package cn.iocoder.yudao.module.base.controller.admin; package cn.iocoder.yudao.module.base.controller.admin;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.MessageSend; import cn.iocoder.yudao.common.MessageSend;
import cn.iocoder.yudao.common.dto.MessageDTO; import cn.iocoder.yudao.common.dto.MessageDTO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.app.controller.admin.NotifyMessageSocket; import cn.iocoder.yudao.module.app.controller.admin.NotifyMessageSocket;
import cn.iocoder.yudao.module.base.entity.RepairWorker; import cn.iocoder.yudao.module.base.entity.RepairWorker;
import cn.iocoder.yudao.module.base.service.RepairWorkerService; import cn.iocoder.yudao.module.base.service.RepairWorkerService;
import cn.iocoder.yudao.module.base.vo.RepairWorkerPageReqVO; import cn.iocoder.yudao.module.base.vo.RepairWorkerPageReqVO;
import cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO; import cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO;
import cn.iocoder.yudao.module.base.vo.RepairWorkerSaveReqVO; import cn.iocoder.yudao.module.base.vo.RepairWorkerSaveReqVO;
import cn.iocoder.yudao.module.base.vo.WorkerExportVO;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO; import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -21,11 +25,14 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.common.BaseConstants.QUALS_INTERIM_PERIOD; import static cn.iocoder.yudao.common.BaseConstants.QUALS_INTERIM_PERIOD;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.ok; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.ok;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -168,4 +175,41 @@ public class RepairWorkerController {
} }
return ok(); return ok();
} }
/**
* 导出数据
*
* @author 小李
* @date 17:50 2024/12/2
* @param pageReqVO 请求对象
**/
@GetMapping("/export")
@Operation(summary = "导出数据")
public void exportData(RepairWorkerPageReqVO pageReqVO, HttpServletResponse response)throws IOException{
int pageNo = 1, pageSize = 1000;
List<WorkerExportVO> list = new ArrayList<>();
Page<RepairWorkerRespVO> page = new Page<>(pageNo,pageSize);
do {
IPage<RepairWorkerRespVO> repairWorkerRespVOIPage = workerService.queryListPage(pageReqVO, page);
List<RepairWorkerRespVO> records = repairWorkerRespVOIPage.getRecords();
if (CollUtil.isEmpty(records)){
break;
}
List<WorkerExportVO> convertedRecords = records.stream().map(item -> BeanUtils.toBean(item, WorkerExportVO.class)).collect(Collectors.toList());
list.addAll(convertedRecords);
pageNo++;
page.setCurrent(pageNo);
}while (true);
if (CollUtil.isEmpty(list)){
throw exception0(500, "没有数据可以导出");
}
list.forEach(item -> {
if (ObjectUtil.isNotEmpty(item.getIsLeads())){
item.setIsLeads(item.getIsLeads().equals("1") ? "班组长" : "维修工");
}
});
ExcelUtils.write(response, "维修工人数据.xls", "数据", WorkerExportVO.class, list);
}
} }

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.base.vo;
import cn.iocoder.yudao.common.RepairDictConstants;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 用于导出维修工人VO
*
* @author 小李
* @date 17:45 2024/12/2
**/
@Data
@ExcelIgnoreUnannotated
public class WorkerExportVO {
@ExcelProperty("姓名")
private String userName;
@ExcelProperty(value = "工种", converter = DictConvert.class)
@DictFormat(RepairDictConstants.REPAIR_WORK_TYPE)
private String workType;
@ExcelProperty("角色")
private String isLeads;
@ExcelProperty("备注")
private String remark;
}

View File

@ -1,20 +1,30 @@
package cn.iocoder.yudao.module.other.controller.admin; package cn.iocoder.yudao.module.other.controller.admin;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.other.entity.DlRepairOther; import cn.iocoder.yudao.module.other.entity.DlRepairOther;
import cn.iocoder.yudao.module.other.service.DlRepairOtherService; import cn.iocoder.yudao.module.other.service.DlRepairOtherService;
import cn.iocoder.yudao.module.other.vo.DlRepairOtherReqVO; import cn.iocoder.yudao.module.other.vo.DlRepairOtherReqVO;
import cn.iocoder.yudao.module.other.vo.DlRepairOtherRespVO; import cn.iocoder.yudao.module.other.vo.DlRepairOtherRespVO;
import cn.iocoder.yudao.module.other.vo.OtherExportVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/** /**
@ -84,5 +94,42 @@ public class DlRepairOtherController {
List<DlRepairOther> list = dlRepairOtherService.list(new LambdaQueryWrapper<DlRepairOther>().eq(DlRepairOther::getName, name)); List<DlRepairOther> list = dlRepairOtherService.list(new LambdaQueryWrapper<DlRepairOther>().eq(DlRepairOther::getName, name));
return success(list.stream().max(Comparator.comparing(DlRepairOther::getCreateTime)).orElse(null)); return success(list.stream().max(Comparator.comparing(DlRepairOther::getCreateTime)).orElse(null));
} }
/**
* 导出数据
*
* @author 小李
* @date 16:39 2024/12/2
* @param repairOtherReqVO 请求对象
**/
@GetMapping("/export")
@Operation(summary = "导出数据")
public void exportData(DlRepairOtherReqVO repairOtherReqVO, HttpServletResponse response) throws IOException {
int pageNo = 1, pageSize = 1000;
List<OtherExportVO> list = new ArrayList<>();
Page<DlRepairOther> page = new Page<>(pageNo, pageSize);
do {
IPage<DlRepairOther> otherPage = dlRepairOtherService.getOtherPage(repairOtherReqVO, page);
List<DlRepairOther> records = otherPage.getRecords();
if (CollUtil.isEmpty(records)){
break;
}
List<OtherExportVO> convertedRecords = records.stream()
.map(item -> BeanUtils.toBean(item, OtherExportVO.class))
.collect(Collectors.toList());
list.addAll(convertedRecords);
pageNo++;
page.setCurrent(pageNo);
} while (true);
if (CollUtil.isEmpty(list)){
throw exception0(500, "没有数据可以导出");
}
ExcelUtils.write(response, "附加数据.xls", "数据", OtherExportVO.class, list);
}
} }

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.other.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* 用于导出维修附加内容的VO
*
* @author 小李
* @date 16:20 2024/12/2
**/
@Data
@ExcelIgnoreUnannotated
public class OtherExportVO {
@ExcelProperty("名称")
private String name;
@ExcelProperty("价格")
private BigDecimal price;
}

View File

@ -1,28 +1,38 @@
package cn.iocoder.yudao.module.project.controller.admin; package cn.iocoder.yudao.module.project.controller.admin;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.conf.entity.BaseType;
import cn.iocoder.yudao.module.conf.entity.BaseWarehouse;
import cn.iocoder.yudao.module.conf.service.BaseTypeService;
import cn.iocoder.yudao.module.conf.service.BaseWarehouseService;
import cn.iocoder.yudao.module.project.entity.RepairProject; import cn.iocoder.yudao.module.project.entity.RepairProject;
import cn.iocoder.yudao.module.project.service.RepairProjectService; import cn.iocoder.yudao.module.project.service.RepairProjectService;
import cn.iocoder.yudao.module.project.vo.RepairProjectPageReqVO; import cn.iocoder.yudao.module.project.vo.*;
import cn.iocoder.yudao.module.project.vo.RepairProjectRespVO;
import cn.iocoder.yudao.module.project.vo.RepairProjectSaveReqVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 维修项目") @Tag(name = "管理后台 - 维修项目")
@ -34,6 +44,14 @@ public class RepairProjectController {
@Resource @Resource
private RepairProjectService repairProjectService; private RepairProjectService repairProjectService;
@Resource
@Lazy
private BaseWarehouseService warehouseService;
@Resource
@Lazy
private BaseTypeService typeService;
/** /**
* 创建维修项目 * 创建维修项目
* *
@ -137,4 +155,46 @@ public class RepairProjectController {
public CommonResult getRepairProjectAndCateGory(){ public CommonResult getRepairProjectAndCateGory(){
return success(repairProjectService.getRepairProjectAndCateGory()); return success(repairProjectService.getRepairProjectAndCateGory());
} }
/**
* 导出数据
*
* @author 小李
* @date 17:09 2024/12/2
* @param pageReqVO 请求对象
**/
@GetMapping("/export")
@Operation(summary = "导出数据")
public void exportData(RepairProjectPageReqVO pageReqVO, HttpServletResponse response)throws IOException {
int pageNo = 1, pageSize = 1000;
List<ProjectExportVO> list = new ArrayList<>();
Page<RepairProjectRespVO> page = new Page<>(pageNo, pageSize);
do {
IPage<RepairProjectRespVO> repairProjectRespVOIPage = repairProjectService.queryListPage(pageReqVO, page);
List<RepairProjectRespVO> records = repairProjectRespVOIPage.getRecords();
if (CollUtil.isEmpty(records)){
break;
}
records.forEach(item -> {
if (ObjectUtil.isNotEmpty(item.getTypeName())){
item.setType(item.getTypeName());
}
});
List<ProjectExportVO> convertedRecords = records.stream().map(item -> BeanUtils.toBean(item, ProjectExportVO.class)).collect(Collectors.toList());
list.addAll(convertedRecords);
pageNo++;
page.setCurrent(pageNo);
}while (true);
if (CollUtil.isEmpty(list)){
throw exception0(500, "没有数据可以导出");
}
ExcelUtils.write(response, "维修项目数据.xls", "数据", ProjectExportVO.class, list);
}
} }

View File

@ -1,16 +1,25 @@
package cn.iocoder.yudao.module.project.controller.admin; package cn.iocoder.yudao.module.project.controller.admin;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.conf.entity.BaseType;
import cn.iocoder.yudao.module.conf.entity.BaseWarehouse;
import cn.iocoder.yudao.module.conf.service.BaseTypeService;
import cn.iocoder.yudao.module.conf.service.BaseWarehouseService;
import cn.iocoder.yudao.module.project.entity.RepairWares; import cn.iocoder.yudao.module.project.entity.RepairWares;
import cn.iocoder.yudao.module.project.service.RepairWaresService; import cn.iocoder.yudao.module.project.service.RepairWaresService;
import cn.iocoder.yudao.module.project.vo.*; import cn.iocoder.yudao.module.project.vo.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -19,10 +28,15 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 配件库") @Tag(name = "管理后台 - 配件库")
@ -34,6 +48,14 @@ public class RepairWaresController {
@Resource @Resource
private RepairWaresService waresService; private RepairWaresService waresService;
@Resource
@Lazy
private BaseWarehouseService warehouseService;
@Resource
@Lazy
private BaseTypeService typeService;
/** /**
* 创建配件库 * 创建配件库
* *
@ -193,4 +215,54 @@ public class RepairWaresController {
List<RepairWaresExcelVO> list = ExcelUtils.read(file, RepairWaresExcelVO.class); List<RepairWaresExcelVO> list = ExcelUtils.read(file, RepairWaresExcelVO.class);
return success(waresService.importData(list, updateSupport)); return success(waresService.importData(list, updateSupport));
} }
/**
* 导出数据
*
* @author 小李
* @date 17:20 2024/12/2
* @param pageReqVO 请求对象
**/
@GetMapping("/export")
@Operation(summary = "导出数据")
public void exportData(RepairWaresPageReqVO pageReqVO, HttpServletResponse response)throws IOException {
int pageNo = 1, pageSize = 1000;
List<RepairWaresExcelVO> list = new ArrayList<>();
Page<RepairWaresRespVO> page = new Page<>(pageNo, pageSize);
do {
IPage<RepairWaresRespVO> waresPage = waresService.getWaresPage(pageReqVO, page);
List<RepairWaresRespVO> records = waresPage.getRecords();
if (CollUtil.isEmpty(records)){
break;
}
List<RepairWaresExcelVO> convertedRecords = records.stream().map(item -> BeanUtils.toBean(item, RepairWaresExcelVO.class)).collect(Collectors.toList());
list.addAll(convertedRecords);
pageNo++;
page.setCurrent(pageNo);
}while (true);
if (CollUtil.isEmpty(list)){
throw exception0(500, "没有数据可以导出");
}
List<BaseWarehouse> warehouses = warehouseService.list();
Map<String, String> warehousesMap = warehouses.stream().collect(Collectors.toMap(BaseWarehouse::getId, BaseWarehouse::getName));
List<BaseType> types = typeService.list(new LambdaQueryWrapper<BaseType>().eq(BaseType::getType, "02"));
Map<String, String> typesMap = types.stream().collect(Collectors.toMap(BaseType::getId, BaseType::getName));
list.forEach(item -> {
if (ObjectUtil.isNotEmpty(item.getWarehouse()) && ObjectUtil.isNotEmpty(warehousesMap.get(item.getWarehouse()))){
item.setWarehouse(warehousesMap.get(item.getWarehouse()));
}
if (ObjectUtil.isNotEmpty(item.getType()) && ObjectUtil.isNotEmpty(typesMap.get(item.getType()))){
item.setType(typesMap.get(item.getType()));
}
});
ExcelUtils.write(response, "维修配件数据.xls", "数据", RepairWaresExcelVO.class, list);
}
} }

View File

@ -0,0 +1,57 @@
package cn.iocoder.yudao.module.project.vo;
import cn.iocoder.yudao.common.RepairDictConstants;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 用于导出维修项目的VO
*
* @author 小李
* @date 17:03 2024/12/2
**/
@Data
@ExcelIgnoreUnannotated
public class ProjectExportVO {
@ExcelProperty("名称")
private String name;
@ExcelProperty("成本")
private Long cost;
@ExcelProperty("规格")
private String spec;
@ExcelProperty("售价")
private BigDecimal price;
@ExcelProperty("编码")
private String code;
@ExcelProperty(value = "单位", converter = DictConvert.class)
@DictFormat(RepairDictConstants.REPAIR_UNIT)
private String unit;
@ExcelProperty("分类")
private String type;
@ExcelProperty("工时")
private String manHour;
@ExcelProperty("备注")
private String remark;
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}