|
@@ -0,0 +1,163 @@
|
|
|
|
+package com.szwl.controller;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.szwl.constant.ResponseCodesEnum;
|
|
|
|
+import com.szwl.feign.SzwlFeign;
|
|
|
|
+import com.szwl.model.bean.EsOrder;
|
|
|
|
+import com.szwl.model.bean.EsOrderList;
|
|
|
|
+import com.szwl.model.bean.good;
|
|
|
|
+import com.szwl.model.bo.R;
|
|
|
|
+import com.szwl.model.bo.ResponseModel;
|
|
|
|
+import com.szwl.model.entity.TAdmin;
|
|
|
|
+import com.szwl.model.entity.TOrder;
|
|
|
|
+import com.szwl.model.query.TOrderParam;
|
|
|
|
+import com.szwl.service.TOrderService;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.Period;
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@Api(value = "/api", tags = {"第三方接口"})
|
|
|
|
+@RestController("ApiInterfaceController")
|
|
|
|
+@RequestMapping("/orderApi")
|
|
|
|
+public class ApiInterContriller {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SzwlFeign szwlFeign;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TOrderService orderService;
|
|
|
|
+
|
|
|
|
+ @ApiOperation("获取订单数据")
|
|
|
|
+ @PostMapping("/getOrder")
|
|
|
|
+ public ResponseModel<?> remoteProduction(@RequestHeader("x-api-key") String apiKey, @RequestBody TOrderParam orderParam) throws ParseException {
|
|
|
|
+ // 校验apiKey是否为空
|
|
|
|
+ if (StringUtils.isEmpty(apiKey)) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "apiKey is null");
|
|
|
|
+ }
|
|
|
|
+ // 校验参数是否为空
|
|
|
|
+ Long adminId = orderParam.getAdminId();
|
|
|
|
+ Integer current = orderParam.getCurrent();
|
|
|
|
+ Integer size = orderParam.getSize();
|
|
|
|
+ Integer status = orderParam.getStatus();
|
|
|
|
+ String startTime = orderParam.getStartTime();
|
|
|
|
+ String endTime = orderParam.getEndTime();
|
|
|
|
+ String clientId = orderParam.getClientId();
|
|
|
|
+ if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "startTime or endTime is null");
|
|
|
|
+ }
|
|
|
|
+ if (status == null) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "status is null");
|
|
|
|
+ }
|
|
|
|
+ if (current == null || size == null) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "current or size is null");
|
|
|
|
+ }
|
|
|
|
+ if (adminId == null) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "adminId is null");
|
|
|
|
+ }
|
|
|
|
+ TAdmin admin = R.getDataIfSuccess(szwlFeign.validateApiKey(apiKey, adminId));
|
|
|
|
+ if (admin == null) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "Invalid apiKey or adminId is not exist");
|
|
|
|
+ }
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ Date startDate = simpleDateFormat.parse(startTime);
|
|
|
|
+ Date endDate = simpleDateFormat.parse(endTime);
|
|
|
|
+ // 检验时间是否超过一个月
|
|
|
|
+ if (dayTime(startDate, endDate)) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "时间跨度超过一个月");
|
|
|
|
+ }
|
|
|
|
+ // 单页大小不能超过2000
|
|
|
|
+ if (size > 1000) {
|
|
|
|
+ return R.fail(ResponseCodesEnum.A0001, "size大小不能超过1000");
|
|
|
|
+ }
|
|
|
|
+ // 查询
|
|
|
|
+ LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
|
|
|
|
+ query.eq(TOrder::getAdminId, adminId);
|
|
|
|
+ query.eq(TOrder::getStatus, status);
|
|
|
|
+ if (StringUtils.isNotEmpty(clientId)) {
|
|
|
|
+ query.eq(TOrder::getClientId, clientId);
|
|
|
|
+ }
|
|
|
|
+ query.between(TOrder::getCreateDate, startDate, endDate);
|
|
|
|
+ query.orderByDesc(TOrder::getCreateDate);
|
|
|
|
+ Page<TOrder> page = new Page<>(current, size, true);
|
|
|
|
+ IPage<TOrder> iPage = orderService.page(page, query);
|
|
|
|
+ List<TOrder> orderList = iPage.getRecords();
|
|
|
|
+ // 封装数据
|
|
|
|
+ EsOrderList esOrderList = new EsOrderList();
|
|
|
|
+ long total = 0;
|
|
|
|
+ List<EsOrder> orders = new ArrayList<>();
|
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ if (!orderList.isEmpty()) {
|
|
|
|
+ total = iPage.getTotal();
|
|
|
|
+ for (TOrder order : orderList) {
|
|
|
|
+ EsOrder esOrder = new EsOrder();
|
|
|
|
+ esOrder.setChannel(order.getFrpCode());
|
|
|
|
+ esOrder.setClientId(order.getClientId());
|
|
|
|
+ esOrder.setPrice(order.getPrice());
|
|
|
|
+ esOrder.setRefundAmount(order.getRefundAmount());
|
|
|
|
+ esOrder.setSn(order.getSn());
|
|
|
|
+ if(status == 3){
|
|
|
|
+ esOrder.setTime(formatter.format(order.getRefundDate()));
|
|
|
|
+ esOrder.setTime(formatter.format(order.getRefundDate()));
|
|
|
|
+ }else {
|
|
|
|
+ //时间要转变
|
|
|
|
+ esOrder.setTime(formatter.format(order.getCreateDate()));
|
|
|
|
+ esOrder.setTime(formatter.format(order.getCreateDate()));
|
|
|
|
+ }
|
|
|
|
+ esOrder.setStatus(String.valueOf(order.getStatus()));
|
|
|
|
+ esOrder.setTrxNo(order.getTrxNo());
|
|
|
|
+ List<good> goods = new ArrayList<>();
|
|
|
|
+ good goo = new good();
|
|
|
|
+ goo.setGoodsName(order.getProductName());
|
|
|
|
+ goo.setPrice(order.getPrice());
|
|
|
|
+ goo.setSuccess(true);
|
|
|
|
+ goods.add(goo);
|
|
|
|
+ esOrder.setGoods(goods);
|
|
|
|
+ orders.add(esOrder);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ esOrderList.setTotal(total);
|
|
|
|
+ esOrderList.setOrders(orders);
|
|
|
|
+ return R.ok(esOrderList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断时间是否超过一个月
|
|
|
|
+ * @param startDate
|
|
|
|
+ * @param endDate
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private boolean dayTime(Date startDate, Date endDate) {
|
|
|
|
+ // 将 Date 转换为 LocalDate
|
|
|
|
+ LocalDate startLocalDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
+ LocalDate endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
+
|
|
|
|
+ // 使用 Period 类来计算日期差异
|
|
|
|
+ Period period = Period.between(startLocalDate, endLocalDate);
|
|
|
|
+
|
|
|
|
+ // 如果年差异大于 0 或月差异大于 1,则认为超过一个月
|
|
|
|
+ if (period.getYears() > 0 || period.getMonths() > 1) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果月差异是 1,检查天数是否足够达到一个月
|
|
|
|
+ if (period.getMonths() == 1 && period.getDays() >= 0) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+}
|