首页 > 其他分享 >easypoi导出带动态下拉框

easypoi导出带动态下拉框

时间:2023-12-05 15:25:49浏览次数:32  
标签:name Excel 导出 private dictMap import easypoi 下拉框 String

涉及无限极分类实现

  • ProductExcel.java
package io.renren.modules.product.excel;

import cn.afterturn.easypoi.excel.annotation.Excel;
import io.renren.modules.product.dto.ProductBarDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.poi.hpsf.Decimal;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
public class ProductExcel {


    // 动态下拉框字段:dict,addressList = true
//    @Excel(name = "学生类型",dict = "level",addressList = true,width = 20)
//    private String type;

    @Excel(name="商品名称",width = 20)
    private String name;

    public String getName(){//过滤空格--因为可能读取excel下面的空行,null必须处理;
        if (name != null){
            return name.trim();
        }
        return null;
    }

    @Excel(name = "商品简称",width = 20)
    private String shortName;

    @Excel(name = "商品规格",width = 20)
    private String spec;

    @Excel(name = "商品重量",width = 20)
    private String weight;

    @Excel(name = "商品主条码",width = 20)
    private String barCode;

    public String getBarCode(){// 过滤空格;
        if (barCode != null){
            return barCode.trim();
        }
        return null;
    }

    @Excel(name = "分类",width = 20,dict = "categoryName",addressList = true)
    private String categoryName;
    private Long categoryId;

    public String getCategoryName(){//过滤空格,过滤开头的一个或多个"|--"
        if (categoryName != null){
            String cateName = categoryName.trim();
            String lastStr = cateName.replaceFirst("^(\\|--)*", "");
            return lastStr;
        }
        return null;
    }

    @Excel(name = "商品单位",width = 20,dict = "unitName",addressList = true)
    private String unitName;
    private Long unitId;

    @Excel(name = "经营方式",width = 20,dict = "manageName",addressList = true)
    private String manageName;
    private Long manageType;

    @Excel(name="销项税率",width = 20)
    private Integer saleTaxRate;

    @Excel(name = "可负库存销售",width = 20,replace = { "是_1", "否_0"}, addressList = true)// 是,否
    private Integer negativeStockSale;

    @Excel(name = "销售价",width = 20)
    private BigDecimal price;

    @Excel(name="进货价",width = 20)
    private BigDecimal purchasePrice;

    @Excel(name="进项税率",width = 20)
    private Integer purchaseTaxRate;

    @Excel(name = "会员价",width = 20)
    private BigDecimal memberPrice;

    @Excel(name = "是否会员折扣",width = 20,replace = { "是_1", "否_0"}, addressList = true)//0:否 1:是
    private Integer isMemberDiscount;

    @Excel(name = "是否微信端售卖",width = 20,replace = { "是_1", "否_0"}, addressList = true)// 0:否 1:是
    private Integer isWxSale;

    @Excel(name = "微信端价",width = 20)
    private BigDecimal wxPrice;

    @Excel(name = "导游提成",width = 20)
    private BigDecimal guideCommission;

    @Excel(name="商品多条码",width = 60)
    private String moreBarCode;

    public String getMoreBarCode(){//过滤空格
        if (moreBarCode != null){
            return moreBarCode.trim();
        }
        return null;
    }

    @Excel(name="多条码对应规格",width = 60)
    private String moreSpec;
    public String getMoreSpec(){//过滤空格
        if (moreSpec != null){
            return moreSpec.trim();
        }
        return null;
    }

    private Integer isMultiBar;
    private String pinyinCode;
    private Integer status;

    @ApiModelProperty(value = "产品多条码")
    private List<ProductBarDTO> productBarList;

}

  • productExcelHandler.java
package io.renren.modules.product.handler;

import cn.afterturn.easypoi.handler.inter.IExcelDictHandler;
import io.renren.modules.product.dto.ProductCategoryDTO;
import io.renren.modules.product.dto.ProductCategoryExportModelDTO;
import io.renren.modules.product.dto.ProductUnitDTO;
import io.renren.modules.product.service.ProductCategoryService;
import io.renren.modules.product.service.ProductUnitService;
import io.renren.modules.settings.dto.SettingManageTypeDTO;
import io.renren.modules.settings.service.SettingManageTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class productExcelHandler implements IExcelDictHandler {

    @Autowired
    private ProductUnitService productUnitService;

    @Autowired
    private SettingManageTypeService settingManageTypeService;

    @Autowired
    private ProductCategoryService productCategoryService;

    public static productExcelHandler productExcelHandler;

    public productExcelHandler(){}

    @PostConstruct
    public void init(){
        productExcelHandler = this;
        productExcelHandler.productUnitService = this.productUnitService;
        productExcelHandler.settingManageTypeService = this.settingManageTypeService;
        productExcelHandler.productCategoryService = this.productCategoryService;
    }

    @Override
    public List<Map> getList(String dict) {
        System.out.println("-----" + dict);
        List<Map> list = new ArrayList<>();
        Map<String, String> dictMap = new HashMap<>();

        if ("level".equals(dict)){
            dictMap.put("dictKey", "0");
            dictMap.put("dictValue", "严重瞌睡");
            list.add(dictMap);

            dictMap = new HashMap<>();
            dictMap.put("dictKey", "1");
            dictMap.put("dictValue", "小B");
            list.add(dictMap);

            dictMap = new HashMap<>();
            dictMap.put("dictKey", "2");
            dictMap.put("dictValue", "深度富有");
            list.add(dictMap);
        } else if ("unitName".equals(dict)){
            List<ProductUnitDTO> proUnitList = productExcelHandler.productUnitService.list(null);
            System.out.println("------lists-----" + proUnitList);
            for (ProductUnitDTO i : proUnitList){
                dictMap = new HashMap<>();
                dictMap.put("dictKey", i.getId().toString());
                dictMap.put("dictValue", i.getName());
                list.add(dictMap);
            }
        } else if ("manageName".equals(dict)){
            List<SettingManageTypeDTO> manageTypeList = productExcelHandler.settingManageTypeService.list(null);
            for (SettingManageTypeDTO i : manageTypeList){
                dictMap = new HashMap<>();
                dictMap.put("dictKey", i.getId().toString());
                dictMap.put("dictValue", i.getName());
                list.add(dictMap);
            }
        } else if ("categoryName".equals(dict)){
            Map<String, Object> params = new HashMap<>();
            List<ProductCategoryExportModelDTO> cateList = productExcelHandler.productCategoryService.plainTreeList(params);

            for (ProductCategoryExportModelDTO i : cateList){
                dictMap = new HashMap<>();
                dictMap.put("dictKey", i.getId().toString());
                int level = i.getLevel();
                String name = fullStr( level,i.getName());
                dictMap.put("dictValue", name);
                list.add(dictMap);
            }
        }

        return list;
    }


    /*****
     * original,左边扩充n个"-"
     * @param n
     * @param original
     * @return
     */
    private String fullStr(int n,String original){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append("|--");
        }
        sb.append(original);
        return sb.toString();
    }

    // 导出用到--没发现怎么用到的呢?????
    @Override
    public String toName(String dict, Object obj, String name, Object value) {
        if ("level".equals(dict)) {
            int level = Integer.parseInt(value.toString());
            switch (level) {
                case 0:
                    return "严重瞌睡";
                case 1:
                    return "小B";
                case 2:
                    return "深度富有";
            }
        }

//        if ("unitName".equals(dict)){
//
//        }

        return null;
    }

    // 导入用到
    @Override
    public String toValue(String dict, Object obj, String name, Object value) {
        if ("level".equals(dict)) {
            String valueStr = String.valueOf(value);
            switch (valueStr) {
                case "严重瞌睡":
                    return "0";
                case "小B":
                    return "1";
                case "深度富有":
                    return "2";
            }
        }
        return null;
    }

}

标签:name,Excel,导出,private,dictMap,import,easypoi,下拉框,String
From: https://www.cnblogs.com/pansidong/p/17877344.html

相关文章

  • 基础lucksheet实现前端导出excel文件
    文章参考:https://blog.csdn.net/csdn_lsy/article/details/1071797081.引入两个插件,其中exceljs负责将lucksheet的数据格式转化成excel的buffer流,file-saver负责将buffer转成blob文件流导出。npminstallexceljsnpminstallfile-saver2.代码实现constExcel=require('......
  • kubectl获取ConfigMap导出YAML时如何忽略某些字段
    前言:当我们在使用Kubernetes时,常常需要通过kubectl命令行工具来管理资源。有时我们也想将某个资源的配置导出为YAML文件,这样做有助于版本控制和资源的迁移。然而,默认情况下,使用kubectlget命令导出资源配置会包含一些元数据字段:如**annotations****,**creationTimestamp**,**r......
  • openGauss学习笔记-142 openGauss 数据库运维-例行维护-导出并查看wdr诊断报告
    openGauss学习笔记-142openGauss数据库运维-例行维护-导出并查看wdr诊断报告生成快照数据需参数enable_wdr_snapshot=on,访问WDR快照数据需要sysadmin或monadmin权限,因此需要使用root账号或其他拥有权限的账号来生成WDR诊断报告。执行如下命令新建报告文件。touch/home/om/w......
  • Java实现Excel导入和导出
    1.功能测试1.1测试准备在做测试前,我们需要將【2.环境准备】中的四个文件拷贝在工程里(如:我这里均放在了com.zyq.util.excel包下)。1.2数据导入1.2.1导入解析为JSON比如,我们有下面一个表格:Controller代码:@PostMapping("/import")publicJSONArrayimportUser(@Requ......
  • easypoi大批量导出excel数据
    easypoi导出excel数据最近,面临了一个新的需求,需要将表中的几百万数据导出到Excel文件中。为了满足这一需求,我决定采用EasyPoi库来实现该功能,并生成压缩包。<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-spring-boot-starter</artifactId>......
  • 一键导出数据库中表结构定义(数据字典)的工具
    导出数据库中标的定义,即所谓的数据字典一、新建maven工程中加入依赖在maven工程的pom.xml中添加依赖<dependency><groupId>cn.smallbun.screw</groupId><artifactId>screw-core</artifactId><version>1.0.5</version></dependency>......
  • Ant Design Vue2表单验证失效、select下拉框验证失效
    简述AntDesignVue2表单验证失效、表单校验三个下拉框,级联联动,动态赋值,第一项changge之后2,3需要=null或者='',但是发现明明第二个select已经选择了而且this.form.b不是空为啥还是校验不通过前情提示系统:一说部分截图、链接等因过期、更换域名、MD语法等可能不显示,可联系反馈(备注......
  • Ant Design Vue2表单验证失效、select下拉框验证失效
    简述AntDesignVue2表单验证失效、表单校验三个下拉框,级联联动,动态赋值,第一项changge之后2,3需要=null或者='',但是发现明明第二个select已经选择了而且this.form.b不是空为啥还是校验不通过前情提示系统:一说部分截图、链接等因过期、更换域名、MD语法等可能不显示,可联系反馈(备注......
  • vue3使用富文本编辑器wangEditor 5,增加自定义下拉框,并动态改变下拉框内容
    官方资料wangEditor官网效果展示准备工作这里按照wangEditor官网提供的Vue3Demo操作就行,下面的内容可以直接跳过安装yarnadd@wangeditor/editor#或者npminstall@wangeditor/editor--saveyarnadd@wangeditor/editor-for-vue@next#或者npminstall@w......
  • SpringBoot自定义注解导出Excel
    先定义一个注解importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;@Retention(RetentionPolicy.RUNTIME)public@interfaceExcelHander{Stringvalue()default"";StringlinkFiled()default"";Cel......