 package com.huimv.management.controller;

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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.huimv.management.entity.TransferPeriodLogEntity;
import com.huimv.management.service.TransferPeriodLogService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;



/**
 * 转栏记录表
 *
 * @author yinhao
 * @version 1.0
 * @date 2021-06-18 18:18:52
 */
@RestController
@RequestMapping("management/transferPeriodLog")
public class TransferPeriodLogController {
    @Autowired
    private TransferPeriodLogService transferPeriodLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = transferPeriodLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		TransferPeriodLogEntity transferPeriodLog = transferPeriodLogService.getById(id);

        return R.ok().put("transferPeriodLog", transferPeriodLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TransferPeriodLogEntity transferPeriodLog){
		transferPeriodLogService.save(transferPeriodLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TransferPeriodLogEntity transferPeriodLog){
		transferPeriodLogService.updateById(transferPeriodLog);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		transferPeriodLogService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/findAll")
    public R findAll(@RequestParam("formFarmId") Integer formFarmId) {
        LambdaQueryWrapper<TransferPeriodLogEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(TransferPeriodLogEntity::getFarmId, formFarmId);
        List<TransferPeriodLogEntity> list = transferPeriodLogService.list(lambdaQueryWrapper);

        return R.ok().put("data", list);

    }

}
