|
|
|
@ -1,10 +1,15 @@ |
|
|
|
|
package common; |
|
|
|
|
|
|
|
|
|
import com.BWebApplication; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.hai.common.Base64Util; |
|
|
|
|
import com.hai.common.security.AESEncodeUtil; |
|
|
|
|
import com.hai.entity.HighDiscountAgentCode; |
|
|
|
|
import com.hai.entity.SecRegion; |
|
|
|
|
import com.hai.service.CommonService; |
|
|
|
|
|
|
|
|
|
import com.hai.service.HighDiscountAgentCodeService; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
@ -33,6 +38,9 @@ public class RegionTest { |
|
|
|
|
@Resource |
|
|
|
|
private CommonService commonService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighDiscountAgentCodeService highDiscountAgentCodeService; |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void addLogs(){ |
|
|
|
|
try { |
|
|
|
@ -67,4 +75,32 @@ public class RegionTest { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void simpleWrite() throws Exception { |
|
|
|
|
// 写法1
|
|
|
|
|
String fileName = "D:\\simpleWrite.xlsx"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String,Object> paramMap = new HashMap<>(); |
|
|
|
|
paramMap.put("discountAgentId", ""); |
|
|
|
|
List<HighDiscountAgentCode> codeList = highDiscountAgentCodeService.getDiscountCode(paramMap); |
|
|
|
|
|
|
|
|
|
List<ExcelModel> list = new ArrayList<>(); |
|
|
|
|
ExcelModel excelModel; |
|
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
|
map.put("type", "DISCOUNT"); |
|
|
|
|
|
|
|
|
|
for (HighDiscountAgentCode code : codeList) { |
|
|
|
|
excelModel = new ExcelModel(); |
|
|
|
|
map.put("id", code.getId()); |
|
|
|
|
String param = "https://hsg.dctpay.com/wx/?action=gogogo&id=" + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(map))); |
|
|
|
|
excelModel.setCodeUrl(param); |
|
|
|
|
list.add(excelModel); |
|
|
|
|
} |
|
|
|
|
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
|
|
|
|
// 如果这里想使用03 则 传入excelType参数即可
|
|
|
|
|
EasyExcel.write(fileName, ExcelModel.class).sheet("模板").doWrite(list); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|