package com.sy.coinage.workshop.controller;

import com.sy.coinage.core.annotation.LoginNotRequired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import javax.validation.Valid;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sy.coinage.core.annotation.ActiveFastJsonProfile;
import com.sy.coinage.core.annotation.CurrentUser;
import com.sy.coinage.core.aop.annotation.Permission;
import com.sy.coinage.core.aop.annotation.Operation;
import com.sy.coinage.core.controller.BaseController;
import com.sy.coinage.core.interceptor.Create;
import com.sy.coinage.core.interceptor.Update;
import com.sy.coinage.core.req.*;
import com.sy.coinage.core.vo.*;

import com.sy.coinage.workshop.model.*;
import com.sy.coinage.workshop.service.IWorkshopTransferService;
import com.sy.coinage.workshop.vo.*;
import com.sy.coinage.workshop.req.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * -车间内部迁移表Controller
 */
@Api(value = "车间内部迁移表接口", tags = {"车间内部迁移表接口"})
@RestController
@RequestMapping(value = "/workshopTransfer")
public class WorkshopTransferController extends BaseController {

    @Autowired
    private IWorkshopTransferService workshopTransferService;

    /**
     * 车间内部迁移表分页列表
     */
    @ApiOperation(value = "车间内部迁移表分页列表")
    @PostMapping("/list")
    @ActiveFastJsonProfile(groups = "list", clazz = WorkshopTransfer.class)
    public IPage<WorkshopTransfer> list(@RequestBody WorkshopTransferListReq req, @CurrentUser CacheUserVO user) {
        LambdaQueryWrapper<WorkshopTransfer> queryWrapper = new LambdaQueryWrapper<>();

        Page<WorkshopTransfer> page = new Page<>(req.getPage(), req.getRows());
        IPage<WorkshopTransfer> data = this.workshopTransferService.page(page, queryWrapper);
        return data;
    }

    /**
     * 车间内部迁移表详情
     */
    @ApiOperation(value = "车间内部迁移表-通过ID查询单条数据")
    @PostMapping("/get")
    @ActiveFastJsonProfile(groups = "get", clazz = WorkshopTransfer.class)
    public WorkshopTransferVO get(@RequestBody @ApiParam(value = "主键请求bean") @Valid IdReq req) {
        WorkshopTransferVO data = null;
        WorkshopTransfer model = this.workshopTransferService.getById(req.getId());
        data = new WorkshopTransferVO();
        BeanUtils.copyProperties(model, data);
        return data;
    }


    @ApiOperation(value = "新增车间内部流转")
    @Operation(value = "新增车间内部流转")
    @PostMapping("/add")
    @LoginNotRequired
//    @Permission("workshopTransfer:add")
    public Object add(@RequestBody @ApiParam(value = "新增请求bean") @Validated({Create.class}) WorkshopTransferReq req) {
        this.workshopTransferService.add(req);
        return "";
    }

}
