package com.huimv.admin.controller.secondary;

import com.huimv.admin.dto.MachineControlDTO;
import com.huimv.admin.service.secondary.MachineControlService;
import com.huimv.admin.utils.Result;
import com.huimv.admin.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author yinhao
 * @Date 2021/4/1 17:40
 * @Description 料控管理Controller
 */
@CrossOrigin
@RestController
@RequestMapping("/machineControl")
public class MachineControlController {

    @Autowired
    private MachineControlService machineControlService;

    /**
     * 保存料机信息
     * @param machineControlDTO
     * @return
     */
    @RequestMapping("/save")
    public Result save(MachineControlDTO machineControlDTO) {
        machineControlService.save(machineControlDTO);
        return new Result(10000,"保存料机信息成功",true);
    }

    /**
     * 分页条件查询料机信息
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @RequestMapping("/list")
    public Result list(Integer pageNum,Integer pageSize,String keyword){
        Map<String,Object> map = machineControlService.list(pageNum,pageSize,keyword);
        return new Result(ResultCode.SUCCESS,map);
    }

    /**
     * 根据id删除料机信息
     * @param id
     * @return
     */
    @RequestMapping("/deleteById")
    public Result delete(@RequestParam(name = "id") Integer id){
        machineControlService.deleteById(id);
        return new Result(10000,"删除料机信息成功",true);
    }

    /**
     * 新增时选择猪舍的下拉框
     * @return
     */
    @RequestMapping("/selectBox")
    public Result selectBox4add(){
        List<Map<String,Object>> zsList = machineControlService.selectBox4add();
        return new Result(ResultCode.SUCCESS,zsList);
    }



//    @RequestMapping("/changeMachineStartTime")
//    public Result changeMachineStartTime() {
//        return null;
//    }

    //    /**
//     * 根据机器id查询料机信息
//     * @param zsId
//     * @return
//     */
//    @RequestMapping("/listByZsId")
//    public Result listByZsId(@RequestParam(name = "zsId") Integer zsId){
//       return machineControlService.listByZsId(zsId);
//    }
}
