package com.wms.controller;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wms.annotation.MyLog;
import com.wms.constants.enums.ResponseCode;
import com.wms.entity.app.dto.PageDto;
import com.wms.entity.app.request.ELocationConfigQuery;
import com.wms.entity.app.request.ELocationQuery;
import com.wms.entity.app.request.LocationQuery;
import com.wms.entity.app.request.VehicleQuery;
import com.wms.entity.app.ResponseEntity;
import com.wms.entity.app.vo.ELocationVo;
import com.wms.entity.app.vo.LocationVo;
import com.wms.entity.app.vo.VehicleVO;
import com.wms.entity.app.wcs.WcsETaskFeedbackRequest;
import com.wms.entity.table.ELocationConfig;
import com.wms.entity.table.ETagLocation;
import com.wms.entity.table.Location;
import com.wms.entity.table.Vehicle;
import com.wms.service.ELocationConfigService;
import com.wms.service.ETagLocationService;
import com.wms.service.LocationService;
import com.wms.service.VehicleService;
import com.wms.utils.HttpUtils;
import com.wms.utils.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static com.wms.utils.StringUtils.convertJsonString;

/**
 * WMS库位控制类
 *
 * @author 梁州
 * &#064;date  2023/3/6
 */
@Controller
@CrossOrigin
@RequestMapping(value = "/wms/location")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class LocationController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 库位服务
     */
    private final LocationService locationService;
    /**
     * 料箱服务
     */
    private final VehicleService vehicleService;
    /**
     * 电子标签库位服务
     */
    private final ETagLocationService etagLocationService;
    /**
     * 电子标签库位配置信息
     */
    private final ELocationConfigService eLocationConfigService;
    /**
     * 任务类
     */
    private final TaskController taskController;
    /**
     * 请求头部信息
     */
    private final HttpServletRequest servletRequest;

    /**
     * 查询库位信息
     * @param locationQuery 查询参数
     * @return 结果
     */
    @PostMapping("/getLocationsByPage")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "查询库位信息", logMethod = "getLocationsByPage")
    public String getLocationsByPage(@RequestBody LocationQuery locationQuery) {
        logger.info("接收到查询库位信息请求：{}，请求ip：{}", convertJsonString(locationQuery), HttpUtils.getIpAddr(servletRequest));
        ResponseEntity response = new ResponseEntity();
        try {
            Page<Location> page = locationQuery.toMpPage();
            Page<Location> locationPage = locationService.page(page, new LambdaQueryWrapper<Location>()
                    .like(StringUtils.isNotEmpty(locationQuery.getLocationId()), Location::getLocationId, locationQuery.getLocationId())
                    .like(StringUtils.isNotEmpty(locationQuery.getVehicleId()), Location::getVehicleId, locationQuery.getVehicleId())
                    .eq(locationQuery.getLocationStatus() != null, Location::getLocationStatus, locationQuery.getLocationStatus())
                    .eq(locationQuery.getIsLock() != null, Location::getIsLock, locationQuery.getIsLock()));

            PageDto<LocationVo> pageDto = PageDto.of(locationPage, location -> BeanUtil.copyProperties(location, LocationVo.class));
            response.setCode(ResponseCode.OK.getCode());
            response.setMessage("查询成功");
            response.setReturnData(pageDto);
            return convertJsonString(response);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error("查询库位信息发生异常");
            response.setCode(ResponseCode.ERROR.getCode());
            response.setMessage("查询库位信息发生异常");
            return convertJsonString(response);
        }
    }

    /**
     * 更新库位信息
     *
     * @param locationQuery 库位
     * @return 结果
     */
    @PostMapping("/updateLocation")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "更新库位信息", logMethod = "updateLocation")
    public String updateLocation(@RequestBody LocationQuery locationQuery) {
        logger.info("接收到更新库位信息请求：{}，请求ip地址：{}", convertJsonString(locationQuery), HttpUtils.getIpAddr(servletRequest));
        // 创建响应信息
        ResponseEntity rsp = new ResponseEntity();
        try {
            if (StringUtils.isEmpty(locationQuery.getLocationId())) {
                logger.error("缺少库位编号");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("缺少库位编号！");
                return convertJsonString(rsp);
            }
            if (locationService.update(locationQuery.toLocationPO(), new LambdaQueryWrapper<Location>().eq(Location::getLocationId, locationQuery.getLocationId()))) {
                // 返回成功
                logger.info("更新库位信息成功");
                rsp.setCode(ResponseCode.OK.getCode());
                rsp.setMessage("更新库位信息成功");
            } else {
                // 返回失败
                logger.error("更新库位信息失败");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("更新库位信息失败");
            }

            return convertJsonString(rsp);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.info("更新库位信息发生异常：{}", convertJsonString(e));
            // 返回其他异常
            rsp.setCode(ResponseCode.ERROR.getCode());
            rsp.setMessage("Exception Occurred: 发生异常");
            return convertJsonString(rsp);
        }
    }

    /**
     * 生成库位表数据
     *
     * @param locationQuery 库位
     * @return 结果
     */
    @PostMapping("/genLocations")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "生成库位表", logMethod = "genLocations")
    public String genLocations(@RequestBody LocationQuery locationQuery) {
        // 9*64*22
        logger.info("接收到生成库位表数据请求：{}，请求ip地址：{}", convertJsonString(locationQuery), HttpUtils.getIpAddr(servletRequest));
        // 创建响应信息
        ResponseEntity rsp = new ResponseEntity();
        try {
            if (locationQuery.getWRow() == null || locationQuery.getWCol() == null || locationQuery.getWLayer() == null) {
                logger.error("缺少排列层。");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("缺少排列层。");
                return convertJsonString(rsp);
            }
            if (locationQuery.getWRow() <= 0 || locationQuery.getWCol() <= 0 || locationQuery.getWLayer() <= 0) {
                logger.error("排列层必须为正整数。");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("排列层必须为正整数。");
                return convertJsonString(rsp);
            }
            List<Location> locations = new ArrayList<>();
            for (int i = 1; i <= locationQuery.getWRow(); i++) {
                for (int j = 1; j <= locationQuery.getWCol(); j++) {
                    for (int k = 1; k <= locationQuery.getWLayer(); k++) {
                        Location location = new Location();
                        location.setLocationId(StringUtils.padLeft(String.valueOf(i), 2, "0") + "-" + StringUtils.padLeft(String.valueOf(j), 2, "0") + "-" + StringUtils.padLeft(String.valueOf(k), 2, "0") + "-01");
                        location.setAreaId(1);
                        location.setWRow(i);
                        location.setWCol(j);
                        location.setWLayer(k);
                        location.setWDepth(1);
                        location.setLocationType(1);
                        location.setLocationStatus(0);
                        location.setIsLock(0);
                        // 设置设备号
                        if (i == 2) {
                            // 第二排
                            if (k%2==1) {
                                // 第二排奇数层
                                location.setEquipmentId(1);
                            } else {
                                // 第二排偶数层
                                location.setEquipmentId(2);
                            }
                        } else {
                            location.setEquipmentId(Math.round((float) (i + 1) / 2));
                        }
                        locations.add(location);
                    }
                }
            }
            locationService.saveBatch(locations);

            logger.info("生成库位成功。");
            rsp.setCode(ResponseCode.OK.getCode());
            rsp.setMessage("生成库位成功。");
            return convertJsonString(rsp);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.info("生成库位发生异常：{}", convertJsonString(e));
            // 返回其他异常
            rsp.setCode(ResponseCode.ERROR.getCode());
            rsp.setMessage("生成库位发生异常");
            return convertJsonString(rsp);
        }
    }

    /**
     * 生成电子标签库位表数据
     *
     * @param eLocationQuery 库位
     * @return 结果
     */
    @PostMapping("/genELocations")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "生成电子标签库位表", logMethod = "genELocations")
    public String genELocations(@RequestBody ELocationQuery eLocationQuery) {
        // 9*64*22
        logger.info("接收到生成电子标签库位表数据请求：{}，请求ip地址：{}", convertJsonString(eLocationQuery), HttpUtils.getIpAddr(servletRequest));
        // 创建响应信息
        ResponseEntity rsp = new ResponseEntity();
        try {
            List<ETagLocation> eLocations = new ArrayList<>();
            for (int i = 1; i <= 9; i++) {
                for (int j = 1; j <= 96; j++) {
                    ETagLocation eTagLocation = new ETagLocation();
                    eTagLocation.setELocationId(i + "-" + StringUtils.padLeft(String.valueOf(j), 2, "0"));
                    eTagLocation.setAreaId(String.valueOf(i));
                    eTagLocation.setSequenceId(j);
                    eTagLocation.setELocationStatus(0);
                    eTagLocation.setWorkStation("ASRS-#" + i);
                    eTagLocation.setPickStatus(0);
                    eLocations.add(eTagLocation);
                }
            }
            etagLocationService.remove(new LambdaQueryWrapper<>());
            etagLocationService.saveBatch(eLocations);

            logger.info("生成电子标签库位成功。");
            rsp.setCode(ResponseCode.OK.getCode());
            rsp.setMessage("生成电子标签库位成功。");
            return convertJsonString(rsp);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.info("生成电子标签库位异常：{}", convertJsonString(e));
            // 返回其他异常
            rsp.setCode(ResponseCode.ERROR.getCode());
            rsp.setMessage("生成电子标签库位异常");
            return convertJsonString(rsp);
        }
    }

    /**
     * 查询料箱信息
     * @param vehicleQuery 查询参数
     * @return 结果
     */
    @PostMapping("/getVehiclesByPage")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "查询载具信息", logMethod = "getVehiclesByPage")
    public String getVehiclesByPage(@RequestBody VehicleQuery vehicleQuery) {
        logger.info("接收到查询载具信息请求：{}，请求ip：{}", convertJsonString(vehicleQuery), HttpUtils.getIpAddr(servletRequest));
        ResponseEntity response = new ResponseEntity();
        try {
            Page<Vehicle> page = vehicleQuery.toMpPage();
            Page<Vehicle> vehiclePage = vehicleService.page(page, new LambdaQueryWrapper<Vehicle>()
                    .like(StringUtils.isNotEmpty(vehicleQuery.getVehicleId()), Vehicle::getVehicleId, vehicleQuery.getVehicleId())
                    .like(StringUtils.isNotEmpty(vehicleQuery.getCurrentLocation()), Vehicle::getCurrentLocation, vehicleQuery.getCurrentLocation())
                    .eq(vehicleQuery.getVehicleStatus() != null, Vehicle::getVehicleStatus, vehicleQuery.getVehicleStatus())
                    .eq(vehicleQuery.getIsEmpty() != null, Vehicle::getIsEmpty, vehicleQuery.getIsEmpty())
                    .orderByDesc(Vehicle::getLastInTime));

            PageDto<VehicleVO> pageDto = PageDto.of(vehiclePage, vehicle -> BeanUtil.copyProperties(vehicle, VehicleVO.class));
            response.setCode(ResponseCode.OK.getCode());
            response.setMessage("查询成功");
            response.setReturnData(pageDto);
            return convertJsonString(response);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error("查询载具信息发生异常");
            response.setCode(ResponseCode.ERROR.getCode());
            response.setMessage("查询载具信息发生异常");
            return convertJsonString(response);
        }
    }

    /**
     * 更新料箱信息
     *
     * @param vehicleQuery 料箱
     * @return 结果
     */
    @PostMapping("/updateVehicleInfo")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "更新料箱信息", logMethod = "updateVehicleInfo")
    public String updateVehicleInfo(@RequestBody VehicleQuery vehicleQuery) {
        logger.info("接收到更新料箱信息请求：{}，请求ip：{}", convertJsonString(vehicleQuery), HttpUtils.getIpAddr(servletRequest));
        // 创建响应信息
        ResponseEntity rsp = new ResponseEntity();
        try {
            if (StringUtils.isEmpty(vehicleQuery.getVehicleId())) {// 载具号为空
                logger.error("缺少载具号");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("缺少载具号");
                return convertJsonString(rsp);
            }
            if (vehicleService.update(vehicleQuery.toVehiclePO(), new LambdaQueryWrapper<Vehicle>().eq(Vehicle::getVehicleId, vehicleQuery.getVehicleId()))) {
                // 返回成功
                logger.info("更新载具信息成功");
                rsp.setCode(ResponseCode.OK.getCode());
                rsp.setMessage("更新载具信息成功");
            } else {
                // 返回失败
                logger.error("更新载具信息失败");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("更新载具信息失败");
            }

            return convertJsonString(rsp);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.info("更新载具信息发生异常：{}", convertJsonString(e));
            // 返回其他异常
            rsp.setCode(ResponseCode.ERROR.getCode());
            rsp.setMessage("更新载具信息发生异常");
            return JSON.toJSONString(rsp);
        }
    }

    /**
     * 删除当前料箱信息
     *
     * @param vehicleQuery 料箱
     * @return 结果
     */
    @PostMapping("/deleteVehicle")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "删除载具信息", logMethod = "deleteVehicle")
    public String deleteVehicle(@RequestBody VehicleQuery vehicleQuery) {
        logger.info("接收到删除载具信息信息请求：{}，请求ip：{}", convertJsonString(vehicleQuery), HttpUtils.getIpAddr(servletRequest));
        // 创建响应信息
        ResponseEntity rsp = new ResponseEntity();
        try {
            if (StringUtils.isEmpty(vehicleQuery.getVehicleId())) {// 箱号为空，不执行
                logger.error("缺少载具号");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("缺少载具号");
                return convertJsonString(rsp);
            }
            if (vehicleService.remove(new LambdaQueryWrapper<Vehicle>().eq(Vehicle::getVehicleId, vehicleQuery.getVehicleId()))) {
                // 返回成功
                logger.info("删除载具成功");
                rsp.setCode(ResponseCode.OK.getCode());
                rsp.setMessage("删除载具成功");
            } else {
                // 返回失败
                logger.error("删除载具失败");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("删除载具失败");
            }

            return convertJsonString(rsp);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.info("发生异常：{}", e.getMessage());
            // 返回其他异常
            rsp.setCode(ResponseCode.ERROR.getCode());
            rsp.setMessage(e.getMessage());
            return JSON.toJSONString(rsp);
        }
    }

    /**
     * 查询电子标签库位信息
     * @param eLocationQuery 查询参数
     * @return 结果
     */
    @PostMapping("/getELocationsByPage")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "查询电子标签库位信息", logMethod = "getELocationsByPage")
    public String getELocationsByPage(@RequestBody ELocationQuery eLocationQuery) {
        logger.info("接收到查询电子标签库位信息请求：{}，请求ip：{}", convertJsonString(eLocationQuery), HttpUtils.getIpAddr(servletRequest));
        ResponseEntity response = new ResponseEntity();
        try {
            Page<ETagLocation> page = eLocationQuery.toMpPage();
            Page<ETagLocation> eLocationsPage = etagLocationService.page(page, new LambdaQueryWrapper<ETagLocation>()
                    .like(StringUtils.isNotEmpty(eLocationQuery.getELocationId()), ETagLocation::getELocationId, eLocationQuery.getELocationId())
                    .like(StringUtils.isNotEmpty(eLocationQuery.getWorkStation()), ETagLocation::getWorkStation, eLocationQuery.getWorkStation())
                    .eq(eLocationQuery.getELocationStatus() != null, ETagLocation::getELocationStatus, eLocationQuery.getELocationStatus())
                    .eq(eLocationQuery.getPickStatus() != null, ETagLocation::getPickStatus, eLocationQuery.getPickStatus())
                    .orderByDesc(ETagLocation::getPickStatus));

            PageDto<ELocationVo> pageDto = PageDto.of(eLocationsPage, eLocation -> BeanUtil.copyProperties(eLocation, ELocationVo.class));
            response.setCode(ResponseCode.OK.getCode());
            response.setMessage("查询成功");
            response.setReturnData(pageDto);
            return convertJsonString(response);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error("查询电子标签库位信息发生异常: {}", convertJsonString(e));
            response.setCode(ResponseCode.ERROR.getCode());
            response.setMessage("查询电子标签库位信息发生异常");
            return convertJsonString(response);
        }
    }

    /**
     * 更新电子标签库位信息
     *
     * @param eLocationQuery 料箱
     * @return 结果
     */
    @PostMapping("/updateELocationInfo")
    @ResponseBody
    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    @MyLog(logTitle = "更新电子标签库位信息", logMethod = "updateELocationInfo")
    public String updateELocationInfo(@RequestBody ELocationQuery eLocationQuery) {
        logger.info("接收到更新电子标签库位信息请求：{}，请求ip：{}", convertJsonString(eLocationQuery), HttpUtils.getIpAddr(servletRequest));
        // 创建响应信息
        ResponseEntity rsp = new ResponseEntity();
        try {
            if (StringUtils.isEmpty(eLocationQuery.getELocationId())) {// 电子标签库位号为空
                logger.error("缺少库位号");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("缺少库位号");
                return convertJsonString(rsp);
            }
            LambdaUpdateWrapper<ETagLocation> updateWrapper = new LambdaUpdateWrapper<ETagLocation>()
                    .set(eLocationQuery.getELocationStatus() != null, ETagLocation::getELocationStatus, eLocationQuery.getELocationStatus())
                    .set(eLocationQuery.getPickStatus() != null, ETagLocation::getPickStatus, eLocationQuery.getPickStatus())
                    .eq(ETagLocation::getELocationId, eLocationQuery.getELocationId());
            if (etagLocationService.update(updateWrapper)) {
                // 更新成功
                logger.info("更新电子标签库位信息成功。");
                rsp.setCode(ResponseCode.OK.getCode());
                rsp.setMessage("更新电子标签库位信息成功。");
            } else {
                // 更新失败
                logger.error("更新电子标签库位信息失败。");
                rsp.setCode(ResponseCode.ERROR.getCode());
                rsp.setMessage("更新电子标签库位信息失败。");
            }
            return convertJsonString(rsp);
        } catch (Exception e) {
            // 回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error("更新载具信息发生异常：{}", convertJsonString(e));
            // 返回其他异常
            rsp.setCode(ResponseCode.ERROR.getCode());
            rsp.setMessage("更新载具信息发生异常");
            return JSON.toJSONString(rsp);
        }
    }

//    /**
//     * 查询电子标签库位分配信息
//     * @param eLocationConfigQuery 查询参数
//     * @return 结果
//     */
//    @PostMapping("/getELocationConfigsByPage")
//    @ResponseBody
//    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
//    @MyLog(logTitle = "查询电子标签库位分配信息", logMethod = "getELocationConfigsByPage")
//    public String getELocationConfigsByPage(@RequestBody ELocationConfigQuery eLocationConfigQuery) {
//        logger.info("接收到查询电子标签库位分配信息请求：{}，请求ip：{}", convertJsonString(eLocationConfigQuery), HttpUtils.getIpAddr(servletRequest));
//        ResponseEntity response = new ResponseEntity();
//        try {
//            Page<ETagLocation> page = eLocationQuery.toMpPage();
//            Page<ETagLocation> eLocationsPage = etagLocationService.page(page, new LambdaQueryWrapper<ETagLocation>()
//                    .like(StringUtils.isNotEmpty(vehicleQuery.getVehicleId()), Vehicle::getVehicleId, vehicleQuery.getVehicleId())
//                    .eq(vehicleQuery.getVehicleStatus() != null, Vehicle::getVehicleStatus, vehicleQuery.getVehicleStatus())
//                    .eq(vehicleQuery.getIsEmpty() != null, Vehicle::getIsEmpty, vehicleQuery.getIsEmpty())
//                    .orderByDesc(Vehicle::getLastInTime));
//
//            PageDto<VehicleVO> pageDto = PageDto.of(vehiclePage, vehicle -> BeanUtil.copyProperties(vehicle, VehicleVO.class));
//            response.setCode(ResponseCode.OK.getCode());
//            response.setMessage("查询成功");
//            response.setReturnData(pageDto);
//            return convertJsonString(response);
//        } catch (Exception e) {
//            // 回滚事务
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            logger.error("查询载具信息发生异常");
//            response.setCode(ResponseCode.ERROR.getCode());
//            response.setMessage("查询载具信息发生异常");
//            return convertJsonString(response);
//        }
//    }
//
//    /**
//     * 更新电子库位分配信息
//     *
//     * @param eLocationConfigQuery 参数
//     * @return 结果
//     */
//    @PostMapping("/updateELocationConfigInfo")
//    @ResponseBody
//    @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
//    @MyLog(logTitle = "更新电子库位分配信息", logMethod = "updateELocationConfigInfo")
//    public String updateELocationConfigInfo(@RequestBody ELocationConfigQuery eLocationConfigQuery) {
//        logger.info("接收到更新电子库位分配信息请求：{}，请求ip：{}", convertJsonString(eLocationConfigQuery), HttpUtils.getIpAddr(servletRequest));
//        // 创建响应信息
//        ResponseEntity rsp = new ResponseEntity();
//        try {
//            if (StringUtils.isEmpty(vehicleQuery.getVehicleId())) {// 载具号为空
//                logger.error("缺少载具号");
//                rsp.setCode(ResponseCode.ERROR.getCode());
//                rsp.setMessage("缺少载具号");
//                return convertJsonString(rsp);
//            }
//            if (vehicleService.update(vehicleQuery.toVehiclePO(), new LambdaQueryWrapper<Vehicle>().eq(Vehicle::getVehicleId, vehicleQuery.getVehicleId()))) {
//                // 返回成功
//                logger.info("更新载具信息成功");
//                rsp.setCode(ResponseCode.OK.getCode());
//                rsp.setMessage("更新载具信息成功");
//            } else {
//                // 返回失败
//                logger.error("更新载具信息失败");
//                rsp.setCode(ResponseCode.ERROR.getCode());
//                rsp.setMessage("更新载具信息失败");
//            }
//
//            return convertJsonString(rsp);
//        } catch (Exception e) {
//            // 回滚事务
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            logger.info("更新载具信息发生异常：{}", convertJsonString(e));
//            // 返回其他异常
//            rsp.setCode(ResponseCode.ERROR.getCode());
//            rsp.setMessage("更新载具信息发生异常");
//            return JSON.toJSONString(rsp);
//        }
//    }
}