'提交代码'

dev-discount
= 3 years ago
parent 949805d235
commit e97ae4783a
  1. 128
      hai-cweb/src/main/java/com/cweb/controller/HighGasController.java
  2. 7
      hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java
  3. 11
      hai-cweb/src/test/common/RegionTest.java
  4. 59
      hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java
  5. 98
      hai-service/src/main/java/com/hai/common/utils/PageUtil.java

@ -1,14 +1,14 @@
package com.cweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.cweb.config.TuanYouConfig;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.security.SessionObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.CoordCommonUtil;
import com.hai.common.utils.PageUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighMerchantStore;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.service.HighGasOilPriceService;
import io.swagger.annotations.Api;
@ -23,13 +23,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Controller
@RequestMapping(value = "/highGas")
@ -40,11 +35,11 @@ public class HighGasController {
@Resource
private HighGasOilPriceService highGasOilPriceService;
@RequestMapping(value="/getGasStoreList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询加油站列表")
public ResponseData getGasStoreList(@RequestParam(name = "storeName", required = false) String storeName,
@RequestParam(name = "distance", required = true) Integer distanceRecent,
@RequestParam(name = "regionId", required = true) Long regionId,
@RequestParam(name = "oilNoName", required = true) String oilNoName,
@RequestParam(name = "longitude", required = true) String longitude,
@ -62,9 +57,13 @@ public class HighGasController {
store.put("distance", Math.round(distance/100d)/10d);
}
List<Map<String, Object>> distance = storeList.stream().sorted(Comparator.comparingDouble(entry -> Double.valueOf(entry.get("distance").toString()))).collect(Collectors.toList());
return ResponseMsgUtil.success(initPageInfoObj(pageNum,distance.size(),pageSize,new PageInfo<>(distance)));
Iterator<Map<String, Object>> iterator = distance.iterator();
while (iterator.hasNext()) {
if ((int)Math.round(Double.valueOf(iterator.next().get("distance").toString())) > distanceRecent.intValue()) {
iterator.remove();
}
}
return ResponseMsgUtil.success(PageUtil.initPageInfoObj(pageNum,distance.size(),pageSize,new PageInfo<>(distance)));
} catch (Exception e) {
log.error("HighGasController -> getGasDetailByStoreKey() error!",e);
@ -72,93 +71,42 @@ public class HighGasController {
}
}
public static <T> PageInfo<T> initPageInfoObj(int currentPage, int total, int pageSize, PageInfo<T> pageInfo) {
List<T> list = pageInfo.getList();
int fromIndex = 0;
int toIndex = 0;
if (total / pageSize == 0 && total % pageSize > 0) {
fromIndex = 0;
toIndex = total;
} else {
if (total / pageSize >= 1 && total % pageSize >= 0) {
fromIndex = pageSize * (currentPage - 1);
if (pageSize * currentPage >= total) {
toIndex = total;
} else {
toIndex = pageSize * currentPage;
}
}
}
@RequestMapping(value="/getGasDetailByStoreKey",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据门店key 查询")
public ResponseData getGasDetailByStoreKey(@RequestParam(name = "storeKey", required = true) String storeKey) {
try {
list = list.subList(fromIndex, toIndex);
} catch (IndexOutOfBoundsException e) {
fromIndex = 0;
toIndex= pageSize;
list = list.subList(fromIndex, toIndex);
}catch(IllegalArgumentException e) {
fromIndex = total-pageSize;
toIndex =total;
list = list.subList(fromIndex, toIndex);
}
pageInfo.setList(list);
pageInfo.setNextPage(currentPage < ((total + pageSize - 1) / pageSize) ? currentPage + 1 : currentPage);
pageInfo.setTotal(total);
pageInfo.setPageNum(currentPage);
pageInfo.setPages((total + pageSize - 1) / pageSize);
pageInfo.setNavigateLastPage((total + pageSize - 1) / pageSize);
pageInfo.setPrePage(currentPage > 1 ? currentPage - 1 : currentPage);
pageInfo.setIsFirstPage(currentPage == 1 ? true : false);
pageInfo.setIsLastPage(currentPage == (total + pageSize - 1) / pageSize ? true : false);
pageInfo.setHasPreviousPage(currentPage == 1 ? false : true);
pageInfo.setHasNextPage(currentPage == (total + pageSize - 1) / pageSize ? false : true);
return calcNavigatepageNums(pageInfo);
}
private static <T> PageInfo<T> calcNavigatepageNums(PageInfo<T> pageInfo) {
// 当总页数小于或等于导航页码数时
if (pageInfo.getPages() <= pageInfo.getNavigatePages()) {
pageInfo.setNavigatepageNums(new int[pageInfo.getPages()]);
for (int i = 0; i < pageInfo.getPages(); i++) {
pageInfo.getNavigatepageNums()[i] = i + 1;
JSONObject jsonObject = TuanYouConfig.queryGasInfoByGasId(storeKey);
if (jsonObject != null && jsonObject.getString("code").equals("200")) {
return ResponseMsgUtil.success(jsonObject.get("result"));
}
} else { // 当总页数大于导航页码数时
pageInfo.setNavigatepageNums(new int[pageInfo.getNavigatePages()]);
int startNum = pageInfo.getPageNum() - pageInfo.getNavigatePages() / 2;
int endNum = pageInfo.getPageNum() + pageInfo.getNavigatePages() / 2;
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未获取到加油站信息");
if (startNum < 1) {
startNum = 1;
// (最前navigatePages页
for (int i = 0; i < pageInfo.getNavigatePages(); i++) {
pageInfo.getNavigatepageNums()[i] = startNum++;
}
} else if (endNum > pageInfo.getPages()) {
endNum = pageInfo.getPages();
// 最后navigatePages页
for (int i = pageInfo.getNavigatePages() - 1; i >= 0; i--) {
pageInfo.getNavigatepageNums()[i] = endNum--;
}
} else {
// 所有中间页
for (int i = 0; i < pageInfo.getNavigatePages(); i++) {
pageInfo.getNavigatepageNums()[i] = startNum++;
}
}
} catch (Exception e) {
log.error("HighGasController -> getGasDetailByStoreKey() error!",e);
return ResponseMsgUtil.exception(e);
}
return pageInfo;
}
@RequestMapping(value="/getGasDetailByStoreKey",method = RequestMethod.GET)
@RequestMapping(value="/getGasPriceDetail",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据门店key 查询")
public ResponseData getGasDetailByStoreKey(@RequestParam(name = "storeKey", required = true) String storeKey) {
@ApiOperation(value = "根据门店key和油号 查询油价")
public ResponseData getGasPriceDetail(@RequestParam(name = "storeKey", required = true) String storeKey,
@RequestParam(name = "oilNo", required = true) String oilNo) {
try {
return ResponseMsgUtil.success(TuanYouConfig.queryGasInfoByGasId(storeKey));
JSONObject jsonObject = TuanYouConfig.queryCompanyPriceDetail(storeKey,oilNo);
if (jsonObject != null && jsonObject.getString("code").equals("200")) {
if(jsonObject.getJSONArray("result").size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未获取到价格信息");
}
return ResponseMsgUtil.success(jsonObject.get("result"));
}
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未获取到价格信息");
} catch (Exception e) {
log.error("HighGasController -> getGasDetailByStoreKey() error!",e);
log.error("HighGasController -> getGasPriceDetail() error!",e);
return ResponseMsgUtil.exception(e);
}
}

@ -38,7 +38,6 @@ import java.util.stream.Collectors;
@RequestMapping(value = "/highOrder")
@Api(value = "订单接口")
public class HighOrderController {
private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class);
@Autowired
@ -67,7 +66,6 @@ public class HighOrderController {
@ApiOperation(value = "增加订单")
public ResponseData addOrder(@RequestBody HighOrder highOrder, HttpServletRequest request) {
try {
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
@ -237,14 +235,15 @@ public class HighOrderController {
}
}
public static void main(String[] args) {
}
@RequestMapping(value = "/getOrderById", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据id查询订单详情")
public ResponseData getOrderById(@RequestParam(name = "orderId", required = true) Long orderId) {
try {
return ResponseMsgUtil.success(highOrderService.getOrderById(orderId));
} catch (Exception e) {
log.error("HighOrderController --> getOrderById() error!", e);
return ResponseMsgUtil.exception(e);

@ -10,11 +10,13 @@ import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.IDGenerator;
import com.hai.entity.HighCouponCode;
import com.hai.entity.HighMerchantStore;
import com.hai.entity.HighOrder;
import com.hai.entity.SecRegion;
import com.hai.service.CommonService;
import com.hai.service.HighCouponCodeService;
import com.hai.service.HighMerchantStoreService;
import com.hai.service.HighOrderService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
@ -87,6 +89,15 @@ public class RegionTest {
}
}
@Test
public void addLogs1(){
try {
highCouponCodeService.cnpcCallbackCouponCode("2021041201",new Date(), "南充");
}catch (Exception e){
e.printStackTrace();
}
}
@Test

@ -147,6 +147,65 @@ public class SynchronizeCNPC {
}
}
/* @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次
public void certification3() {
List<SecSinopecConfig> sinopecConfig = secSinopecConfigService.getListSinopecConfig(new HashMap<>());
for (SecSinopecConfig config : sinopecConfig) {
Map<String, Object> tokenMap = new HashMap<>();
tokenMap.put("appId", config.getAppId());
tokenMap.put("appSecret", config.getAppSecret());
JSONObject jsonObject = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/api/open/merchant/token", JSON.toJSONString(tokenMap));
log.error(jsonObject.toJSONString());
if (jsonObject != null && jsonObject.getBoolean("success") == true) {
JSONObject data = jsonObject.getJSONObject("data");
String token = data.getString("token");
Calendar instance = Calendar.getInstance();
instance.add(Calendar.DAY_OF_MONTH, -1);
instance.set(Calendar.HOUR_OF_DAY, 00);
instance.set(Calendar.MINUTE, 00);
instance.set(Calendar.SECOND, 00);
Map<String,Object> bodyMap = new HashMap<>();
bodyMap.put("appId", config.getAppId());
bodyMap.put("pageNo", 1);
bodyMap.put("pageSize", 5000);
bodyMap.put("startTime", instance.getTime());
bodyMap.put("endTime", new Date());
bodyMap.put("customerCode", config.getCode());
Long date = new Date().getTime();
String sha256 = encodeBySHA256(config.getSignkey() + JSON.toJSONString(bodyMap) + date);
JSONObject object = HttpsUtils.doPost("https://app.zshcqsy.com/api-provider/sapapi/open/coupon/customerRedeemcodeList", JSON.toJSONString(bodyMap), token, sha256, date);
//JSONObject object = JSONObject.parseObject("{\"code\":1000,\"data\":{\"pageNo\":1,\"pageSize\":100,\"rowCount\":\"2\",\"list\":[{\"nodeName\":\"中国石油化工股份有限公司重庆江南石油分公司大学城南二路加油加\",\"totalAmount\":150.00,\"codeId\":\"01DIhbtPzIghPP0mPWaWzO13\",\"nodeNo\":\"50000105\",\"name\":\"重庆惠昕石化有限责任公司11.02日150元券\",\"useTime\":\"2021-04-03 06:11:14\"},{\"nodeName\":\"中国石化销售有限公司重庆三峡分公司忠县经营部三台加油站\",\"totalAmount\":100.00,\"codeId\":\"201126141728001027\",\"nodeNo\":\"50000238\",\"name\":\"重庆惠昕石化有限责任公司11.26日100元券\",\"useTime\":\"2021-04-03 15:16:03\"}]},\"success\":true}");
if(Objects.equals(object.get("success"), true)) {
log.error(JSONObject.toJSONString(object.get("data")));
Object dataJson = JSONObject.parse(JSONObject.toJSONString(object.get("data")));
JSONObject dataObject = JSON.parseObject(JSONObject.toJSONString(dataJson));
JSONArray list = dataObject.getJSONArray("list");
for (Object dataJsonObject : list) {
try {
JSONObject parseObject = JSON.parseObject(JSON.toJSONString(dataJsonObject));
String codeId = parseObject.getString("codeId");
String nodeName = parseObject.getString("nodeName");
Date useTime = DateUtil.format(parseObject.getString("useTime"), "yyyy-MM-dd HH:mm:ss");
highCouponCodeService.cnpcCallbackCouponCode(codeId, useTime, nodeName);
} catch (Exception e) {
log.error("HighCouponSchedule --> expiredCoupon() error!", e);
}
}
}
}
}
}*/
public String encodeBySHA256(String str) {
try{
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");

@ -0,0 +1,98 @@
package com.hai.common.utils;
import com.github.pagehelper.PageInfo;
import java.util.List;
/**
* 分页工具
*/
public class PageUtil {
/**
* 初始化
* @param currentPage
* @param total
* @param pageSize
* @param pageInfo
* @param <T>
* @return
*/
public static <T> PageInfo<T> initPageInfoObj(int currentPage, int total, int pageSize, PageInfo<T> pageInfo) {
List<T> list = pageInfo.getList();
int fromIndex = 0;
int toIndex = 0;
if (total / pageSize == 0 && total % pageSize > 0) {
fromIndex = 0;
toIndex = total;
} else {
if (total / pageSize >= 1 && total % pageSize >= 0) {
fromIndex = pageSize * (currentPage - 1);
if (pageSize * currentPage >= total) {
toIndex = total;
} else {
toIndex = pageSize * currentPage;
}
}
}
try {
list = list.subList(fromIndex, toIndex);
} catch (IndexOutOfBoundsException e) {
fromIndex = 0;
toIndex= pageSize;
list = list.subList(fromIndex, toIndex);
}catch(IllegalArgumentException e) {
fromIndex = total-pageSize;
toIndex =total;
list = list.subList(fromIndex, toIndex);
}
pageInfo.setList(list);
pageInfo.setNextPage(currentPage < ((total + pageSize - 1) / pageSize) ? currentPage + 1 : currentPage);
pageInfo.setTotal(total);
pageInfo.setPageNum(currentPage);
pageInfo.setPages((total + pageSize - 1) / pageSize);
pageInfo.setNavigateLastPage((total + pageSize - 1) / pageSize);
pageInfo.setPrePage(currentPage > 1 ? currentPage - 1 : currentPage);
pageInfo.setIsFirstPage(currentPage == 1 ? true : false);
pageInfo.setIsLastPage(currentPage == (total + pageSize - 1) / pageSize ? true : false);
pageInfo.setHasPreviousPage(currentPage == 1 ? false : true);
pageInfo.setHasNextPage(currentPage == (total + pageSize - 1) / pageSize ? false : true);
return calcNavigatepageNums(pageInfo);
}
private static <T> PageInfo<T> calcNavigatepageNums(PageInfo<T> pageInfo) {
// 当总页数小于或等于导航页码数时
if (pageInfo.getPages() <= pageInfo.getNavigatePages()) {
pageInfo.setNavigatepageNums(new int[pageInfo.getPages()]);
for (int i = 0; i < pageInfo.getPages(); i++) {
pageInfo.getNavigatepageNums()[i] = i + 1;
}
} else { // 当总页数大于导航页码数时
pageInfo.setNavigatepageNums(new int[pageInfo.getNavigatePages()]);
int startNum = pageInfo.getPageNum() - pageInfo.getNavigatePages() / 2;
int endNum = pageInfo.getPageNum() + pageInfo.getNavigatePages() / 2;
if (startNum < 1) {
startNum = 1;
// (最前navigatePages页
for (int i = 0; i < pageInfo.getNavigatePages(); i++) {
pageInfo.getNavigatepageNums()[i] = startNum++;
}
} else if (endNum > pageInfo.getPages()) {
endNum = pageInfo.getPages();
// 最后navigatePages页
for (int i = pageInfo.getNavigatePages() - 1; i >= 0; i--) {
pageInfo.getNavigatepageNums()[i] = endNum--;
}
} else {
// 所有中间页
for (int i = 0; i < pageInfo.getNavigatePages(); i++) {
pageInfo.getNavigatepageNums()[i] = startNum++;
}
}
}
return pageInfo;
}
}
Loading…
Cancel
Save