package common; import com.BWebApplication; import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hai.entity.SecRegion; import com.hai.service.CommonService; import com.hai.service.HighGasOilPriceOfficialService; import org.apache.commons.lang3.StringUtils; 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.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/20 20:26 */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = BWebApplication.class) @WebAppConfiguration public class ExcelTest { @Resource private HighGasOilPriceOfficialService gasOilPriceOfficialService; @Resource private CommonService commonService; @Test public void test(){ try { gasOilPriceOfficialService.refreshPriceOfficial(); /* String dataStr = "{\"showapi_res_error\":\"\",\"showapi_res_id\":\"62831ba20de376a006cb8421\",\"showapi_res_code\":0,\"showapi_fee_num\":1,\"showapi_res_body\":{\"ret_code\":0,\"list\":[{\"p0\":\"8.38\",\"p89\":\"8.06\",\"ct\":\"2022-05-17 07:00:00.263\",\"p90\":\"\",\"p92\":\"8.67\",\"p93\":\"\",\"prov\":\"山东\",\"p95\":\"9.30\",\"p98\":\"10.02\",\"p97\":\"\"},{\"p0\":\"8.91\",\"p89\":\"9.02\",\"ct\":\"2022-05-17 07:00:00.270\",\"p90\":\"\",\"p92\":\"9.56\",\"p93\":\"\",\"prov\":\"西藏\",\"p95\":\"10.11\",\"p98\":\"11.27\",\"p97\":\"\"},{\"p0\":\"8.36\",\"p89\":\"8.07\",\"ct\":\"2022-05-17 07:00:00.242\",\"p90\":\"\",\"p92\":\"8.65\",\"p93\":\"\",\"prov\":\"上海\",\"p95\":\"9.21\",\"p98\":\"10.21\",\"p97\":\"\"},{\"p0\":\"8.37\",\"p89\":\"8.05\",\"ct\":\"2022-05-17 07:00:00.259\",\"p90\":\"\",\"p92\":\"8.65\",\"p93\":\"\",\"prov\":\"福建\",\"p95\":\"9.23\",\"p98\":\"10.11\",\"p97\":\"\"},{\"p0\":\"8.29\",\"p89\":\"0\",\"ct\":\"2022-05-17 07:00:00.300\",\"p90\":\"\",\"p92\":\"8.65\",\"p93\":\"\",\"prov\":\"吉林\",\"p95\":\"9.33\",\"p98\":\"10.17\",\"p97\":\"\"},{\"p0\":\"8.46\",\"p89\":\"8.08\",\"ct\":\"2022-05-17 07:00:00.265\",\"p90\":\"\",\"p92\":\"8.63\",\"p93\":\"\",\"prov\":\"山西\",\"p95\":\"9.32\",\"p98\":\"10.02\",\"p97\":\"\"},{\"p0\":\"8.27\",\"p89\":\"8.03\",\"ct\":\"2022-05-17 07:00:00.260\",\"p90\":\"\",\"p92\":\"8.69\",\"p93\":\"\",\"prov\":\"甘肃\",\"p95\":\"9.28\",\"p98\":\"9.85\",\"p97\":\"\"},{\"p0\":\"8.25\",\"p89\":\"8.1\",\"ct\":\"2022-05-17 07:00:00.259\",\"p90\":\"\",\"p92\":\"8.58\",\"p93\":\"\",\"prov\":\"宁夏\",\"p95\":\"9.07\",\"p98\":\"10.33\",\"p97\":\"\"},{\"p0\":\"8.41\",\"p89\":\"8.15\",\"ct\":\"2022-05-17 07:00:00.269\",\"p90\":\"\",\"p92\":\"8.78\",\"p93\":\"\",\"prov\":\"四川\",\"p95\":\"9.38\",\"p98\":\"10.20\",\"p97\":\"\"},{\"p0\":\"8.39\",\"p89\":\"8.05\",\"ct\":\"2022-05-17 07:00:00.269\",\"p90\":\"\",\"p92\":\"8.69\",\"p93\":\"\",\"prov\":\"河北\",\"p95\":\"9.18\",\"p98\":\"10.01\",\"p97\":\"\"},{\"p0\":\"8.37\",\"p89\":\"0\",\"ct\":\"2022-05-17 07:00:00.270\",\"p90\":\"\",\"p92\":\"8.70\",\"p93\":\"\",\"prov\":\"河南\",\"p95\":\"9.29\",\"p98\":\"9.94\",\"p97\":\"\"},{\"p0\":\"8.36\",\"p89\":\"8.03\",\"ct\":\"2022-05-17 07:00:00.307\",\"p90\":\"\",\"p92\":\"8.66\",\"p93\":\"\",\"prov\":\"浙江\",\"p95\":\"9.21\",\"p98\":\"10.09\",\"p97\":\"\"},{\"p0\":\"8.43\",\"p89\":\"8.14\",\"ct\":\"2022-05-17 07:00:00.264\",\"p90\":\"\",\"p92\":\"8.75\",\"p93\":\"\",\"prov\":\"广西\",\"p95\":\"9.45\",\"p98\":\"10.50\",\"p97\":\"\"},{\"p0\":\"8.44\",\"p89\":\"8.27\",\"ct\":\"2022-05-17 07:00:00.250\",\"p90\":\"\",\"p92\":\"8.74\",\"p93\":\"\",\"prov\":\"重庆\",\"p95\":\"9.24\",\"p98\":\"10.41\",\"p97\":\"\"},{\"p0\":\"8.37\",\"p89\":\"0\",\"ct\":\"2022-05-17 07:00:00.306\",\"p90\":\"\",\"p92\":\"8.70\",\"p93\":\"\",\"prov\":\"湖北\",\"p95\":\"9.32\",\"p98\":\"10.22\",\"p97\":\"\"},{\"p0\":\"8.45\",\"p89\":\"8.08867362\",\"ct\":\"2022-05-17 07:00:00.308\",\"p90\":\"\",\"p92\":\"8.63\",\"p93\":\"\",\"prov\":\"湖南\",\"p95\":\"9.18\",\"p98\":\"9.98\",\"p97\":\"\"},{\"p0\":\"8.47\",\"p89\":\"9.03\",\"ct\":\"2022-05-17 07:00:00.268\",\"p90\":\"\",\"p92\":\"9.80\",\"p93\":\"\",\"prov\":\"海南\",\"p95\":\"10.42\",\"p98\":\"11.81\",\"p97\":\"\"},{\"p0\":\"8.43\",\"p89\":\"8.04\",\"ct\":\"2022-05-17 07:00:00.250\",\"p90\":\"\",\"p92\":\"8.64\",\"p93\":\"\",\"prov\":\"江西\",\"p95\":\"9.28\",\"p98\":\"10.78\",\"p97\":\"\"},{\"p0\":\"8.44\",\"p89\":\"8.14\",\"ct\":\"2022-05-17 07:00:00.304\",\"p90\":\"\",\"p92\":\"8.84\",\"p93\":\"\",\"prov\":\"云南\",\"p95\":\"9.49\",\"p98\":\"10.17\",\"p97\":\"\"},{\"p0\":\"8.16\",\"p89\":\"5.7\",\"ct\":\"2022-05-17 07:00:00.290\",\"p90\":\"\",\"p92\":\"8.65\",\"p93\":\"\",\"prov\":\"黑龙江\",\"p95\":\"9.27\",\"p98\":\"10.51\",\"p97\":\"\"},{\"p0\":\"8.24\",\"p89\":\"0\",\"ct\":\"2022-05-17 07:00:00.258\",\"p90\":\"\",\"p92\":\"8.62\",\"p93\":\"\",\"prov\":\"内蒙古\",\"p95\":\"9.20\",\"p98\":\"10.09\",\"p97\":\"\"},{\"p0\":\"8.28\",\"p89\":\"0\",\"ct\":\"2022-05-17 07:00:00.257\",\"p90\":\"\",\"p92\":\"8.67\",\"p93\":\"\",\"prov\":\"辽宁\",\"p95\":\"9.25\",\"p98\":\"10.07\",\"p97\":\"\"},{\"p0\":\"8.38\",\"p89\":\"8.09\",\"ct\":\"2022-05-17 07:00:00.263\",\"p90\":\"\",\"p92\":\"8.71\",\"p93\":\"\",\"prov\":\"广东\",\"p95\":\"9.43\",\"p98\":\"10.57\",\"p97\":\"\"},{\"p0\":\"8.29\",\"p89\":\"8.12\",\"ct\":\"2022-05-17 07:00:00.262\",\"p90\":\"\",\"p92\":\"8.65\",\"p93\":\"\",\"prov\":\"青海\",\"p95\":\"9.27\",\"p98\":\"10.10\",\"p97\":\"\"},{\"p0\":\"8.39\",\"p89\":\"8.05\",\"ct\":\"2022-05-17 07:00:00.249\",\"p90\":\"\",\"p92\":\"8.69\",\"p93\":\"\",\"prov\":\"天津\",\"p95\":\"9.18\",\"p98\":\"10.49\",\"p97\":\"\"},{\"p0\":\"8.48\",\"p89\":\"8.32\",\"ct\":\"2022-05-17 07:00:00.266\",\"p90\":\"\",\"p92\":\"8.82\",\"p93\":\"\",\"prov\":\"贵州\",\"p95\":\"9.32\",\"p98\":\"10.22\",\"p97\":\"\"},{\"p0\":\"8.26\",\"p89\":\"8.08\",\"ct\":\"2022-05-17 07:00:00.267\",\"p90\":\"\",\"p92\":\"8.57\",\"p93\":\"\",\"prov\":\"陕西\",\"p95\":\"9.05\",\"p98\":\"10.11\",\"p97\":\"\"},{\"p0\":\"8.17\",\"p89\":\"0\",\"ct\":\"2022-05-17 07:00:00.285\",\"p90\":\"\",\"p92\":\"8.48\",\"p93\":\"\",\"prov\":\"新疆\",\"p95\":\"9.11\",\"p98\":\"10.24\",\"p97\":\"\"},{\"p0\":\"8.34\",\"p89\":\"8.11\",\"ct\":\"2022-05-17 07:00:00.249\",\"p90\":\"\",\"p92\":\"8.66\",\"p93\":\"\",\"prov\":\"江苏\",\"p95\":\"9.21\",\"p98\":\"9.89\",\"p97\":\"\"},{\"p0\":\"8.43\",\"p89\":\"8.14\",\"ct\":\"2022-05-17 07:00:00.235\",\"p90\":\"\",\"p92\":\"8.69\",\"p93\":\"\",\"prov\":\"北京\",\"p95\":\"9.25\",\"p98\":\"10.23\",\"p97\":\"\"},{\"p0\":\"8.42\",\"p89\":\"8.1\",\"ct\":\"2022-05-17 07:00:00.257\",\"p90\":\"\",\"p92\":\"8.63\",\"p93\":\"\",\"prov\":\"安徽\",\"p95\":\"9.23\",\"p98\":\"10.06\",\"p97\":\"\"}]}}"; JSONObject dataObject = JSONObject.parseObject(dataStr); if (dataObject.getInteger("showapi_res_code").equals(0)) { JSONObject resBody = dataObject.getJSONObject("showapi_res_body"); JSONArray oilArray = resBody.getJSONArray("list"); for (Object oil : oilArray) { JSONObject oilObject = (JSONObject) oil; System.out.println(); SecRegion region = commonService.getRegionsByName(oilObject.getString("prov")); if (region != null) { BigDecimal oilNo92 = oilObject.getBigDecimal("p92"); if (oilNo92 != null) { gasOilPriceOfficialService.editPrice(region.getRegionId(), 92, oilNo92); } BigDecimal oilNo95 = oilObject.getBigDecimal("p95"); if (oilNo95 != null) { gasOilPriceOfficialService.editPrice(region.getRegionId(), 95, oilNo95); } BigDecimal oilNo98 = oilObject.getBigDecimal("p98"); if (oilNo98 != null) { gasOilPriceOfficialService.editPrice(region.getRegionId(), 98, oilNo98); } BigDecimal oilNo0 = oilObject.getBigDecimal("p0"); if (oilNo0 != null) { gasOilPriceOfficialService.editPrice(region.getRegionId(), 0, oilNo0); } } } }*/ }catch (Exception e){ e.printStackTrace(); } } }