wms-serve-mule/src/main/java/com/wms/controller/DisplayController.java
2024-07-04 07:43:04 +08:00

105 lines
4.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.wms.controller;
import com.alibaba.fastjson2.JSON;
import com.wms.constants.WmsConstants;
import com.wms.constants.enums.ResponseCode;
import com.wms.entity.app.ResponseEntity;
import com.wms.entity.app.display.LocationData;
import com.wms.entity.app.display.LocationInfo;
import com.wms.entity.table.Location;
import com.wms.entity.table.Stock;
import com.wms.service.LocationService;
import com.wms.service.StockService;
import com.wms.utils.HttpUtils;
import com.wms.utils.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.LinkedList;
import java.util.List;
@Controller
@CrossOrigin
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping(value = "/api/query")
public class DisplayController extends BaseController{
private final StockService stockService;
private final LocationService locationService;
private final HttpServletRequest servletRequest;
/**
* 大屏查询库位信息
* @param location 参数---库位
* @return 结果
*/
@GetMapping("/queryLocationInfo")
@ResponseBody
public String queryLocationInfo(@RequestParam String location) {
logger.info("接收到查询大屏库位信息请求ip地址{},参数:{}", HttpUtils.getIpAddr(servletRequest), location);
ResponseEntity response = new ResponseEntity();
if (StringUtils.isEmpty(location)) {
logger.error("查询失败,参数中库位号为空");
response.setCode(ResponseCode.ERROR.getCode());
response.setMessage("查询失败,参数中库位号为空");
return JSON.toJSONString(response);
}
Location locationQuery = new Location();
locationQuery.setLocationId(location);
List<Location> locations = locationService.selLocations(locationQuery);
if (locations.size() == 0) {
logger.error("查询失败,该库位立体库中不存在");
response.setCode(ResponseCode.ERROR.getCode());
response.setMessage("查询失败,请检查库位号正确性");
return JSON.toJSONString(response);
}
Location currentLocation = locations.get(0);
String vehicleNo = currentLocation.getVehicleId();
if (StringUtils.isEmpty(vehicleNo)) {
// 设定
LocationInfo returnData = new LocationInfo();
returnData.setLocationId(location);
returnData.setVehicleNo(WmsConstants.EMPTY_STRING);
response.setCode(ResponseCode.OK.getCode());
response.setMessage("查询成功");
response.setReturnData(returnData);
return JSON.toJSONString(response);
}
// 查询库存
Stock stockQuery = new Stock();
stockQuery.setLocationId(location);
stockQuery.setVehicleId(vehicleNo);
List<Stock> stocks = stockService.selStocks(stockQuery);
List<LocationData> locationData = new LinkedList<>();
for (Stock tempStock : stocks) {
LocationData tempData = new LocationData();
tempData.setGoodsId(tempStock.getGoodsId());
tempData.setGoodsName(tempStock.getGoodsName());
tempData.setGoodsNum(tempStock.getRealNum());
locationData.add(tempData);
}
// 设定
LocationInfo returnData = new LocationInfo();
returnData.setLocationId(location);
returnData.setVehicleNo(WmsConstants.EMPTY_STRING);
returnData.setLocationData(locationData);
response.setCode(ResponseCode.OK.getCode());
response.setMessage("查询成功");
response.setReturnData(returnData);
return JSON.toJSONString(response);
}
/**
* 查询所有库位
* @return 结果
*/
@GetMapping("/getAllLocations")
@ResponseBody
public String queryLocationInfo() {
logger.info("接收到查询大屏所有库位信息请求ip地址{}", HttpUtils.getIpAddr(servletRequest));
return JSON.toJSONString(locationService.selLocations(new Location()));
}
}