ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TBigGiftPackageController.java
@@ -1,21 +1,45 @@ package com.ruoyi.web.controller.api; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.ExcelImportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.WebUtils; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.export.BigGiftPackageImport; import com.ruoyi.system.model.TBigGiftPackage; import com.ruoyi.system.query.BigGiftPackageQuery; import com.ruoyi.system.service.TBigGiftPackageService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Objects; /** @@ -101,5 +125,190 @@ } return R.fail("删除失败"); } @ApiOperation(value = "大礼包导入模板下载") @GetMapping("/import-template") public void importTemplate() { List<BigGiftPackageImport> bigGiftPackageImports = new ArrayList<>(); BigGiftPackageImport bigGiftPackageImport = new BigGiftPackageImport(); bigGiftPackageImports.add(bigGiftPackageImport); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), BigGiftPackageImport.class, bigGiftPackageImports); HttpServletResponse response = WebUtils.response(); ServletOutputStream outputStream = null; try { String fileName = URLEncoder.encode("大礼包商品导入模板.xls", "utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName); response.setHeader("content-Type", "application/vnd.ms-excel"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); outputStream = response.getOutputStream(); workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); System.out.println("大礼包商品导入模板下载失败!"); } finally { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } @Log(title = "大礼包商品-导入", businessType = BusinessType.INSERT) @ApiOperation(value = "大礼包商品-导入") @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @PostMapping("/import") public R<String> importInfo(@RequestPart("file") MultipartFile file) { List<BigGiftPackageImport> bigGiftPackageImports = new ArrayList<>(); ImportParams params = new ImportParams(); params.setHeadRows(1); //表头行数 InputStream inputStream = null; List<TBigGiftPackage> bigGiftPackages = new ArrayList<>(); try { inputStream = file.getInputStream(); bigGiftPackageImports = ExcelImportUtil.importExcel(inputStream, BigGiftPackageImport.class, params); } catch (Exception e) { e.printStackTrace(); throw new ServiceException("大礼包商品导入失败!"); } finally { try { inputStream.close(); } catch (IOException e) { throw new ServiceException(e.getMessage()); } } if (CollectionUtils.isEmpty(bigGiftPackageImports)) { throw new ServiceException("大礼包商品数据为空!"); } JSONObject result = new JSONObject(); int i = 1; for (BigGiftPackageImport bigGiftPackageImport : bigGiftPackageImports) { if (!StringUtils.hasLength(bigGiftPackageImport.getCode())){ result.append("第"+i+"行:[", "商品ID"+"]不能为空"); continue; } if (!StringUtils.hasLength(bigGiftPackageImport.getName())){ result.append("第"+i+"行:[", "商品名称"+"]不能为空"); continue; } if (!StringUtils.hasLength(bigGiftPackageImport.getTotalPrice())){ result.append("第"+i+"行:[", "商品总价"+"]不能为空"); continue; } if (!StringUtils.hasLength(bigGiftPackageImport.getDeposit())){ result.append("第"+i+"行:[", "定金"+"]不能为空"); continue; } if (!StringUtils.hasLength(bigGiftPackageImport.getPointsSettlementPrice())){ result.append("第"+i+"行:[", "积分结算价格"+"]不能为空"); continue; } if (!StringUtils.hasLength(bigGiftPackageImport.getIntroduction())){ result.append("第"+i+"行:[", "商品简介"+"]不能为空"); continue; } if (!StringUtils.hasLength(bigGiftPackageImport.getInventory())){ result.append("第"+i+"行:[", "库存"+"]不能为空"); continue; } TBigGiftPackage bigGiftPackage = new TBigGiftPackage(); bigGiftPackage.setCode(bigGiftPackageImport.getCode()); bigGiftPackage.setName(bigGiftPackageImport.getName()); bigGiftPackage.setIntroduction(bigGiftPackageImport.getIntroduction()); try { BigDecimal totalPrice = new BigDecimal(bigGiftPackageImport.getTotalPrice()); bigGiftPackage.setTotalPrice(totalPrice); } catch (Exception e) { result.append("第"+i+"行:[", "商品总价"+"]格式错误"); continue; } try { BigDecimal deposit = new BigDecimal(bigGiftPackageImport.getDeposit()); bigGiftPackage.setDeposit(deposit); } catch (Exception e) { result.append("第"+i+"行:[", "商品定金"+"]格式错误"); continue; } try { BigDecimal pointsSettlementPrice = new BigDecimal(bigGiftPackageImport.getPointsSettlementPrice()); bigGiftPackage.setPointsSettlementPrice(pointsSettlementPrice); } catch (Exception e) { result.append("第"+i+"行:[", "积分结算价格"+"]格式错误"); continue; } try { Integer inventory = Integer.parseInt(bigGiftPackageImport.getInventory()); bigGiftPackage.setInventory(inventory); } catch (Exception e) { result.append("第"+i+"行:[", "库存"+"]格式错误"); continue; } bigGiftPackages.add(bigGiftPackage); i++; } tBigGiftPackageService.saveBatch(bigGiftPackages); if(!result.isEmpty()){ return R.fail(result.toString()); } return R.ok(); } @ApiOperation(value = "大礼包导出") @PostMapping(value = "/export") @Log(title = "大礼包-导出", businessType = BusinessType.EXPORT) public void exportRegistration(@RequestBody BigGiftPackageQuery query){ LambdaQueryWrapper<TBigGiftPackage> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(TBigGiftPackage::getStatus,1); wrapper.like(Objects.nonNull(query.getName()), TBigGiftPackage::getName, query.getName()); wrapper.orderByDesc(TBigGiftPackage::getCreateTime); List<TBigGiftPackage> list = tBigGiftPackageService.list(wrapper); ArrayList<BigGiftPackageImport> bigGiftPackageImports = new ArrayList<>(); for (TBigGiftPackage tBigGiftPackage : list) { BigGiftPackageImport bigGiftPackageImport = new BigGiftPackageImport(); bigGiftPackageImport.setCode(tBigGiftPackage.getCode()); bigGiftPackageImport.setName(tBigGiftPackage.getName()); bigGiftPackageImport.setTotalPrice(tBigGiftPackage.getTotalPrice().toString()); bigGiftPackageImport.setDeposit(tBigGiftPackage.getDeposit().toString()); bigGiftPackageImport.setPointsSettlementPrice(tBigGiftPackage.getPointsSettlementPrice().toString()); bigGiftPackageImport.setIntroduction(tBigGiftPackage.getIntroduction()); bigGiftPackageImport.setInventory(tBigGiftPackage.getInventory().toString()); bigGiftPackageImports.add(bigGiftPackageImport); } Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), BigGiftPackageImport.class, bigGiftPackageImports); HttpServletResponse response = WebUtils.response(); assert response != null; response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); ServletOutputStream outputStream = null; try { String fileName = URLEncoder.encode("大礼包导出信息.xls", "utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName); response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); outputStream = response.getOutputStream(); workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); } finally { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } } ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TPhysicalGoodsController.java
@@ -1,13 +1,23 @@ package com.ruoyi.web.controller.api; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.ExcelImportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.WebUtils; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.export.BigGiftPackageImport; import com.ruoyi.system.export.TPhysicalGoodsImport; import com.ruoyi.system.model.TBigGiftPackage; import com.ruoyi.system.model.THtmlConfig; import com.ruoyi.system.model.TPhysicalGoods; import com.ruoyi.system.query.BigGiftPackageQuery; @@ -15,8 +25,22 @@ import com.ruoyi.system.service.TPhysicalGoodsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Objects; import static net.sf.jsqlparser.parser.feature.Feature.update; @@ -106,5 +130,159 @@ } @ApiOperation(value = "实物商品导入模板下载") @GetMapping("/import-template") public void importTemplate() { List<TPhysicalGoodsImport> physicalGoodsImports = new ArrayList<>(); TPhysicalGoodsImport physicalGoodsImport = new TPhysicalGoodsImport(); physicalGoodsImports.add(physicalGoodsImport); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TPhysicalGoodsImport.class, physicalGoodsImports); HttpServletResponse response = WebUtils.response(); ServletOutputStream outputStream = null; try { String fileName = URLEncoder.encode("实物商品导入模板.xls", "utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName); response.setHeader("content-Type", "application/vnd.ms-excel"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); outputStream = response.getOutputStream(); workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); System.out.println("实物商品导入模板下载失败!"); } finally { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } @Log(title = "实物商品-导入", businessType = BusinessType.INSERT) @ApiOperation(value = "实物商品-导入") @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @PostMapping("/import") public R<String> importInfo(@RequestPart("file") MultipartFile file) { List<TPhysicalGoodsImport> physicalGoodsImports = new ArrayList<>(); ImportParams params = new ImportParams(); params.setHeadRows(1); //表头行数 InputStream inputStream = null; List<TPhysicalGoods> physicalGoods = new ArrayList<>(); try { inputStream = file.getInputStream(); physicalGoodsImports = ExcelImportUtil.importExcel(inputStream, TPhysicalGoodsImport.class, params); } catch (Exception e) { e.printStackTrace(); throw new ServiceException("实物商品导入失败!"); } finally { try { inputStream.close(); } catch (IOException e) { throw new ServiceException(e.getMessage()); } } if (CollectionUtils.isEmpty(physicalGoodsImports)) { throw new ServiceException("实物商品数据为空!"); } JSONObject result = new JSONObject(); int i = 1; for (TPhysicalGoodsImport physicalGoodsImport : physicalGoodsImports) { if (!StringUtils.hasLength(physicalGoodsImport.getName())){ result.append("第"+i+"行:[", "商品名称"+"]不能为空"); continue; } if (!StringUtils.hasLength(physicalGoodsImport.getTotalPrice())){ result.append("第"+i+"行:[", "商品价格"+"]不能为空"); continue; } if (!StringUtils.hasLength(physicalGoodsImport.getIntroduction())){ result.append("第"+i+"行:[", "商品简介"+"]不能为空"); continue; } if (!StringUtils.hasLength(physicalGoodsImport.getSales())){ result.append("第"+i+"行:[", "销量"+"]不能为空"); continue; } TPhysicalGoods goods = new TPhysicalGoods(); goods.setName(physicalGoodsImport.getName()); goods.setIntroduction(physicalGoodsImport.getIntroduction()); try { BigDecimal totalPrice = new BigDecimal(physicalGoodsImport.getTotalPrice()); goods.setTotalPrice(totalPrice); } catch (Exception e) { result.append("第"+i+"行:[", "商品价格"+"]格式错误"); continue; } try { Integer sales = Integer.parseInt(physicalGoodsImport.getSales()); goods.setSales(sales); } catch (Exception e) { result.append("第"+i+"行:[", "销量"+"]格式错误"); continue; } physicalGoods.add(goods); i++; } tPhysicalGoodsService.saveBatch(physicalGoods); if(!result.isEmpty()){ return R.fail(result.toString()); } return R.ok(); } @ApiOperation(value = "实物导出") @PostMapping(value = "/export") @Log(title = "实物-导出", businessType = BusinessType.EXPORT) public void exportRegistration(@RequestBody BigGiftPackageQuery query){ LambdaQueryWrapper<TPhysicalGoods> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(TPhysicalGoods::getStatus,1); wrapper.like(Objects.nonNull(query.getName()), TPhysicalGoods::getName, query.getName()); wrapper.orderByDesc(TPhysicalGoods::getCreateTime); List<TPhysicalGoods> list = tPhysicalGoodsService.list(wrapper); ArrayList<TPhysicalGoodsImport> physicalGoodsImports = new ArrayList<>(); for (TPhysicalGoods goods : list) { TPhysicalGoodsImport physicalGoodsImport = new TPhysicalGoodsImport(); physicalGoodsImport.setName(goods.getName()); physicalGoodsImport.setTotalPrice(goods.getTotalPrice().toString()); physicalGoodsImport.setIntroduction(goods.getIntroduction()); physicalGoodsImport.setSales(goods.getSales().toString()); physicalGoodsImports.add(physicalGoodsImport); } Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TPhysicalGoodsImport.class, physicalGoodsImports); HttpServletResponse response = WebUtils.response(); assert response != null; response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); ServletOutputStream outputStream = null; try { String fileName = URLEncoder.encode("实物导出信息.xls", "utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName); response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); outputStream = response.getOutputStream(); workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); } finally { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } } ruoyi-system/src/main/java/com/ruoyi/system/export/BigGiftPackageImport.java
New file @@ -0,0 +1,33 @@ package com.ruoyi.system.export; import cn.afterturn.easypoi.excel.annotation.Excel; import io.swagger.annotations.ApiModel; import lombok.Data; @Data @ApiModel(value = "大礼包商品导入") public class BigGiftPackageImport { @Excel(name = "商品ID", width = 20) private String code; @Excel(name = "商品名称", width = 20) private String name; @Excel(name = "商品总价", width = 20) private String totalPrice; @Excel(name = "商品订金", width = 20) private String deposit; @Excel(name = "积分结算价", width = 20) private String pointsSettlementPrice; @Excel(name = "商品简介", width = 20) private String introduction; @Excel(name = "库存", width = 20) private String inventory; } ruoyi-system/src/main/java/com/ruoyi/system/export/ContractExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/LargeOrganizationImport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/LargeResourceImport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/LargeSocialWorkerImport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/LargeVolunteerImport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/MerchantImport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/OldsterImport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/TAppealServicesExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/TChildcareServicesExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/TCourseOrderExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/THelpNeedsExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/TMicroWishExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/TOldsterWarningExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/TPhysicalGoodsImport.java
New file @@ -0,0 +1,27 @@ package com.ruoyi.system.export; import cn.afterturn.easypoi.excel.annotation.Excel; import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; @Data @ApiModel(value = "实物商品导入") public class TPhysicalGoodsImport { @Excel(name = "商品名称", width = 20) private String name; @Excel(name = "商品价格", width = 20) private String totalPrice; @Excel(name = "商品简介", width = 20) private String introduction; @Excel(name = "销量", width = 20) private String sales; } ruoyi-system/src/main/java/com/ruoyi/system/export/TRefundOrderExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/export/TRegistrationExport.java
File was deleted ruoyi-system/src/main/java/com/ruoyi/system/model/TPhysicalGoods.java
@@ -76,5 +76,9 @@ @TableField("status") private Integer status; @ApiModelProperty(value = "销量") @TableField("sales") private Integer sales; }