package com.prolog.cs.biz.outbound.controller;

import cn.hutool.core.collection.CollUtil;
import com.prolog.cs.biz.outbound.model.entity.MoveTaskDO;
import com.prolog.cs.biz.outbound.service.RFPickTaskService;
import com.prolog.framework.common.message.RestMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

@Api(tags = "RF拣货确认")
@RestController
@RequestMapping("/rf/picktask")
@Validated
public class RFPickTaskController {

    @Resource
    private RFPickTaskService service;

    @ApiOperation(value = "根据补货任务明细ID更新补货状态")
    @PostMapping("/ask/updateTasksUnshelveByReplenish")
    public RestMessage<Object> updateTasksUnshelveByReplenish(@RequestBody Map<String, Object> params) {
        List<String> ids = (List<String>) params.get("ids");
        if (CollUtil.isEmpty(ids)){
            return RestMessage.success("操作成功", "");
        }
        String status = (String) params.get("status");
        return RestMessage.success("操作成功", service.updateTasksUnshelveByReplenish(ids.toArray(new String[]{}), status));
    }

    @ApiOperation(value = "根据拣选任务明细ID查询补货信息")
    @GetMapping("/ask/getReplenishListByPickTaskId")
    public RestMessage<List<MoveTaskDO>> getReplenishListByPickTaskId(@RequestParam(value = "pickTaskId") @Valid @NotNull(message = "拣选任务明细ID不能为空") String pickTaskId, @RequestParam(value = "status") String status) {
        return RestMessage.success("查询成功", service.getReplenishListByPickTaskId(pickTaskId, status));
    }
}
