交班2
This commit is contained in:
@@ -1,25 +1,31 @@
|
|||||||
package cn.ysk.cashier.cons.rest;
|
package cn.ysk.cashier.cons.rest;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.http.HttpResponse;
|
|
||||||
import cn.hutool.http.HttpUtil;
|
|
||||||
import cn.ysk.cashier.annotation.Log;
|
import cn.ysk.cashier.annotation.Log;
|
||||||
import cn.ysk.cashier.cons.domain.ViewHandover;
|
import cn.ysk.cashier.cons.domain.ViewHandover;
|
||||||
import cn.ysk.cashier.cons.service.ViewHandoverService;
|
import cn.ysk.cashier.cons.service.ViewHandoverService;
|
||||||
import cn.ysk.cashier.cons.service.dto.ViewHandoverQueryCriteria;
|
import cn.ysk.cashier.cons.service.dto.ViewHandoverQueryCriteria;
|
||||||
import cn.ysk.cashier.exception.BadRequestException;
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
|
import cn.ysk.cashier.utils.JSONUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Objects;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author admin
|
* @author admin
|
||||||
@@ -40,18 +46,25 @@ public class ViewHandoverController {
|
|||||||
@PostMapping("handoverData")
|
@PostMapping("handoverData")
|
||||||
@Log("提交交班")
|
@Log("提交交班")
|
||||||
@ApiOperation("提交交班")
|
@ApiOperation("提交交班")
|
||||||
public ResponseEntity<Object> handoverData(@RequestBody ViewHandover resources){
|
public ResponseEntity<Object> handoverData(@RequestBody Map<String, Object> map) throws Exception {
|
||||||
if(Objects.isNull(resources.getShopId())) throw new BadRequestException("店铺信息不可为空");
|
if (CollectionUtils.isEmpty(map) || !map.containsKey("shopId") || !map.containsKey("isprintProduct")) {
|
||||||
HttpResponse response = HttpUtil.createGet(StrUtil.format(wxServiceHostname,"/cashierService/common/handoverData?shopId={}", resources.getShopId())).execute();
|
throw new BadRequestException("参数缺失");
|
||||||
if (response.getStatus() >= 200 && response.getStatus() < 300) {
|
}
|
||||||
String body = response.body();
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
HttpPost post = new HttpPost(wxServiceHostname + "/cashierService/common/handoverData");
|
||||||
} else {
|
String jsonString = JSONUtil.toJSONString(map);
|
||||||
// 请求失败,获取状态码和错误信息
|
StringEntity entity = new StringEntity(jsonString);
|
||||||
int statusCode = response.getStatus();
|
post.setEntity(entity);
|
||||||
String errorMessage = response.body(); // 可以获取错误信息
|
post.setHeader("Content-Type", "application/json");
|
||||||
log.error("交班提交失败:{}",errorMessage);
|
|
||||||
throw new BadRequestException("请求失败,状态码:"+statusCode);
|
try (CloseableHttpResponse response = httpClient.execute(post)) {
|
||||||
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
return new ResponseEntity<>(HttpStatus.valueOf(response.getStatusLine().getStatusCode()));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
httpClient.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user