嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-bweb/src/test/common/RegionTest.java

107 lines
3.7 KiB

4 years ago
package common;
import com.BWebApplication;
4 years ago
import com.alibaba.excel.EasyExcel;
4 years ago
import com.alibaba.fastjson.JSON;
4 years ago
import com.hai.common.Base64Util;
import com.hai.common.security.AESEncodeUtil;
import com.hai.entity.HighDiscountAgentCode;
4 years ago
import com.hai.entity.SecRegion;
import com.hai.service.CommonService;
4 years ago
import com.hai.service.HighDiscountAgentCodeService;
4 years ago
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @ClassName RegionTest
* @Description: TODO ()
* @Author 胡锐
* @Date 2020/12/29
**/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = BWebApplication.class)
4 years ago
@WebAppConfiguration
public class RegionTest {
@Resource
private CommonService commonService;
4 years ago
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
4 years ago
@Test
public void addLogs(){
try {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("exampleWrite.json"),"UTF-8");
List<Map<String,Object>> jobTypeList = new ArrayList<>();
List<Map<String,Object>> children1;
List<SecRegion> parentRegion = commonService.getCities();
for (SecRegion parent : parentRegion) {
Map<String,Object> map = new HashMap<>();
map.put("value", parent.getRegionId());
map.put("label", parent.getRegionName());
// 查询二级
List<SecRegion> chinRegion = commonService.getRegionsByParentId(parent.getRegionId());
children1 = new ArrayList<>();
for (SecRegion chin : chinRegion) {
Map<String,Object> map1 = new HashMap<>();
map1.put("value", chin.getRegionId());
map1.put("label", chin.getRegionName());
children1.add(map1);
}
map.put("children", children1);
jobTypeList.add(map);
}
osw.write(JSON.toJSONString(jobTypeList));
osw.flush();//清空缓冲区,强制输出数据
osw.close();//关闭输出流
}catch (Exception e){
e.printStackTrace();
}
}
4 years ago
@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);
}
4 years ago
}