MesController.java 10.4 KB
package com.huaheng.api.mes.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.api.mes.domain.InventoryDetailQuery;
import com.huaheng.api.mes.domain.MaterialQuery;
import com.huaheng.api.mes.domain.MesTask;
import com.huaheng.api.mes.domain.TaskHeaderQuery;
import com.huaheng.api.mes.service.MesService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.aspectj.bridge.ISourceLocation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * mes下发任务接口
 * @author xcq
 */
@RestController
@RequestMapping("/api/mes")
@Api(tags = {"MES下发任务接口"}, value = "MES下发任务接口")
public class MesController extends BaseController {
    @Resource
    private MesService mesService;
    @Resource
    private MaterialService materialService;
    @Resource
    private LocationService locationService;
    @Resource
    private ContainerService containerService;


    @ApiOperation(value = "mes任务创建", httpMethod = "POST")
    @PostMapping("/createTask")
    @ResponseBody
    @ApiLogger(apiName = "mes任务创建", from="MES")
    public AjaxResult  createTask(@RequestBody MesTask mesTask){
        return mesService.createTaskService(mesTask);
    }


    @ApiOperation(value = "空料框处理", httpMethod = "POST")
    @PostMapping("/emptyContainerHandle")
    @ResponseBody
    public AjaxResult emptyContainerHandle(@RequestBody MesTask mesTask){
        return mesService.emptyContainerHandleService(mesTask);
    }


    @ApiOperation(value = "初始化货架点位", httpMethod = "POST")
    @PostMapping("/initialLocation")
    @ResponseBody
    public AjaxResult initialLocation(@RequestBody MesTask mesTask){
        return mesService.initialLocationService(mesTask);
    }

    @ApiOperation(value = "机加库获取物料信息", httpMethod = "POST")
    @PostMapping("/getMaterialByMES")
    @ResponseBody
    public AjaxResult getMaterialByMES(@RequestBody MesTask mesTask) {
        return mesService.getMaterialByMES(mesTask);
    }

    @ApiOperation(value = "常规点位初始化", httpMethod = "POST")
    @PostMapping("/routineInitialLocation")
    @ResponseBody
    public AjaxResult routineInitialLocation(@RequestBody MesTask mesTask){
        return mesService.routineInitialLocationService(mesTask);
    }


    @ApiOperation(value = "解绑库位", httpMethod = "POST")
    @PostMapping("/locationUntie")
    @ResponseBody
    public AjaxResult locationUntie(@RequestBody MesTask mesTask){
        return mesService.untieLocationService(mesTask);
    }

    @ApiOperation(value = "取消任务", httpMethod = "POST")
    @PostMapping("/cancelACSTask")
    @ResponseBody
    public AjaxResult cancelACSTask(@RequestBody Integer id){
        return mesService.cancelACSTaskService(id);
    }

    @ApiOperation(value = "任务查看", httpMethod = "POST")
    @PostMapping("/getTaskList")
    @ResponseBody
    public TableDataInfo getTaskList(@RequestBody TaskHeaderQuery taskHeaderQuery){
        return mesService.getTaskListService(taskHeaderQuery);
    }

    @ApiOperation(value = "库存查看", httpMethod = "POST")
    @PostMapping("/getInventoryList")
    @ResponseBody
    @ApiLogger(apiName = "库存查看", from="MES")
    public TableDataInfo getInventoryList(@RequestBody InventoryDetailQuery inventoryDetailQuery){
        return mesService.getInventoryListService(inventoryDetailQuery);
    }

    @ApiOperation(value = "区域同步", httpMethod = "POST")
    @PostMapping("/zoneSync")
    @ResponseBody
    @ApiLogger(apiName = "区域同步", from="MES")
    public AjaxResult zoneSync(@RequestBody List<Zone> zones){
        return mesService.zoneSyncService(zones);
    }

    @ApiOperation(value = "点位到点位任务创建", httpMethod = "POST")
    @PostMapping("/pointToPoint")
    @ResponseBody
    @ApiLogger(apiName = "点位到点位任务创建", from="MES")
    public AjaxResult pointToPoint(@RequestBody MesTask mesTask){
        return mesService.pointToPointService(mesTask);
    }

    /**
     * 获取光腾物料
     * @return
     */
    @PostMapping("/getGTMaterial")
    @ResponseBody
    public TableDataInfo getGTMaterial(@RequestBody MaterialQuery materialQuery){
        LambdaQueryWrapper<Material> queryWrapper = Wrappers.lambdaQueryNoWarehouse();
        queryWrapper.eq(Material::getWarehouseCode, QuantityConstant.WAREHOUSE_KS)
                .eq(Material::getCompanyCode, QuantityConstant.COMPANY_GT)
                .like(StringUtils.isNotEmpty(materialQuery.getCode()),Material::getCode, materialQuery.getCode())
                .like(StringUtils.isNotEmpty(materialQuery.getName()),Material::getName, materialQuery.getName())
                .select(Material::getCode, Material::getName,Material::getSpec, Material::getUnit);
        if (StringUtils.isNotNull(materialQuery.getPageNum()) && StringUtils.isNotNull(materialQuery.getPageSize())){
            // 分页查询
            Page<Material> page = new Page<>(materialQuery.getPageNum(), materialQuery.getPageSize());
            IPage<Material> iPage = materialService.page(page, queryWrapper);
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
        }else {
            List<Material> list = materialService.list(queryWrapper);
            return getDataTable(list);
        }
    }

    /**
     * 区域移动
     * @return
     */
    @PostMapping("/regionalMove")
    @ResponseBody
    @ApiLogger(apiName = "区域移动", from="MES")
    public AjaxResult regionalMove(@RequestBody MesTask mesTask){
        return mesService.regionalMoveService(mesTask);
    }


    /**
     * PDA修改光腾点位状态
     * @param location
     * @return
     */
    @PostMapping("/updateLocationStatus")
    @ResponseBody
    @ApiLogger(apiName = "修改光腾点位状态", from="PDA")
    public AjaxResult updateLocationStatus(@RequestBody Location location){
        return mesService.updateLocationStatusService(location);
    }


    /**
     * PDA点位转换成空料框
     * @param location
     * @return
     */
    @PostMapping("/locationConvert")
    @ResponseBody
    @ApiLogger(apiName = "PDA点位转换", from="PDA")
    public AjaxResult locationConvert(@RequestBody Location location){
        return mesService.locationConvertService(location);
    }

    /**
     * PDA获取点位信息
     * @param location
     * @return
     */
    @PostMapping("/getLocation")
    @ResponseBody
    @ApiLogger(apiName = "PDA获取点位信息", from="PDA")
    public AjaxResult getLocation(@RequestBody Location location){
        LambdaQueryWrapper<Location> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper
                .eq(Location::getZoneCode, QuantityConstant.GT_RECEIPT_TYPE)
                .eq(StringUtils.isNotEmpty(location.getCode()), Location::getCode, location.getCode())
                .eq(StringUtils.isNotEmpty(location.getName()), Location::getName, location.getName())
                .eq(StringUtils.isNotEmpty(location.getContainerCode()), Location::getContainerCode, location.getContainerCode())
                .eq(StringUtils.isNotNull(location.getSystemCreated()), Location::getStatus, location.getStatus())
                .eq(StringUtils.isNotNull(location.getIRow()), Location::getIRow, location.getIRow())
                .eq(StringUtils.isNotNull(location.getIColumn()), Location::getIColumn, location.getIColumn())
                .eq(StringUtils.isNotNull(location.getIGrid()), Location::getIGrid, location.getIGrid())
                .eq(StringUtils.isNotNull(location.getILayer()), Location::getILayer, location.getILayer())
                .eq(StringUtils.isNotEmpty(location.getStatus()), Location::getStatus, location.getStatus())
                .eq(StringUtils.isNotEmpty(location.getLocationType()), Location::getLocationType, location.getLocationType())
                .eq(Location::getDeleted, false)
                .orderByDesc(Location::getId);
        List<Location> locations = locationService.list(lambdaQueryWrapper);
        if (locations == null ||locations.size() == 0){
            return AjaxResult.success("点位信息为空!");
        }
        // 根据容器编码查询容器数据
        List<String> containerCodes = locations.stream().map(Location::getContainerCode).collect(Collectors.toList());
        LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerLambdaQueryWrapper.in(Container::getCode, containerCodes);
        List<Container> containers = containerService.list(containerLambdaQueryWrapper);
        // 将containers转换成map
        Map<String, Container> containerMap = containers.stream().collect(Collectors.toMap(Container::getCode, container -> container));
        locations.forEach(location1 -> {
            if (containerMap.containsKey(location1.getContainerCode()) && containerMap.get(location1.getContainerCode()).getStatus() == QuantityConstant.STATUS_CONTAINER_SOME){
                location1.setStatus(QuantityConstant.STATUS_CONTAINER_SOME);
            }
        });
        AjaxResult result = AjaxResult.success("点位信息获取成功!");
        result.setData(locations);
        return result;
    }


}