package com.yuchen.saas.park.service.controller.basic;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.park.PmgBatPeopleTypeDTO;
import com.yuchen.saas.park.api.entity.park.PmgBatPeopleType;
import com.yuchen.saas.park.api.vo.park.PmgBatPeopleTypeDataVO;
import com.yuchen.saas.park.api.vo.park.PmgBatPeopleTypeVO;
import com.yuchen.saas.park.service.service.PmgBatPeopleTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author 刘通
 * @date 2020/12/14 15:19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/peopleType")
@Api(value = "人员类型", tags = "人员类型接口")
public class PmgBatPeopleTypeController {

    /**
     * 注入人员类型操作接口
     */
    @Resource
    private PmgBatPeopleTypeService pmgBatPeopleTypeService;

    /**
     * 人员类型 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入人员类型信息")
    public R<PmgBatPeopleType> detail(PmgBatPeopleType pmgBatPeopleType) {
        PmgBatPeopleType detail = pmgBatPeopleTypeService.getOne(Condition.getQueryWrapper(pmgBatPeopleType));
        return R.data(detail);
    }

    /**
     * 人员类型 分页
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "人员类型 分页", notes = "人员类型 分页")
    public R<IPage<PmgBatPeopleType>> list(PmgBatPeopleType pmgBatPeopleType, Query query) {
        IPage<PmgBatPeopleType> pages = pmgBatPeopleTypeService.page(Condition.getPage(query),Condition.getQueryWrapper(pmgBatPeopleType));
        return  R.data(pages);
    }


    /**
     * 根据园区id获取人员类型
     */
    @PostMapping("/getPeopleTypeByParkId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据园区id获取人员类型", notes = "根据园区id获取人员类型")
    public R<List<PmgBatPeopleTypeVO>> getPeopleTypeByParkId(@RequestBody PmgBatPeopleType pmgBatPeopleType) {
        List<PmgBatPeopleTypeVO> peopleTypeByParkId = pmgBatPeopleTypeService.getPeopleTypeByParkId(pmgBatPeopleType.getParkId());
        return R.data(peopleTypeByParkId);
    }

    /**
     * 人员中心+ -人员登记-设置 保存人员类型
     */
    @PostMapping("/submitPeopleType")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "人员中心+ -人员登记-设置 保存人员类型", notes = "人员中心+ -人员登记-设置 保存人员类型")
    public R submitPeopleType(@Valid @RequestBody PmgBatPeopleTypeDataVO pmgBatPeopleTypeDataVO) {
        return pmgBatPeopleTypeService.submitPeopleType(pmgBatPeopleTypeDataVO);
    }





    /**
     * 根据园区id和大类获取人员类型
     */
    @PostMapping("/getPeopleTypeByParkIdAndBigType")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "根据园区id和大类获取人员类型", notes = "根据园区id和大类获取人员类型")
    public R<List<PmgBatPeopleType>> getPeopleTypeByParkIdAndBigType(@Validated @RequestBody  PmgBatPeopleTypeDTO pmgBatPeopleType) {
        List<PmgBatPeopleType> peopleTypeByParkId = pmgBatPeopleTypeService.getPeopleTypeByParkIdAndBigType(pmgBatPeopleType);
        return R.data(peopleTypeByParkId);
    }



    /**
     * 人员类型:下拉框选择
     * @return
     */
    @GetMapping("/select")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "人员类型 下拉框", notes = "人员类型 下拉框")
    public R select() {
        List<PmgBatPeopleType> list = pmgBatPeopleTypeService.list();
        return  R.data(list);
    }

    /**
     * 人员类型 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "人员类型 新增或修改", notes = "人员类型 新增或修改")
    public R submit(@Valid @RequestBody PmgBatPeopleType pmgBatPeopleType) {
        return pmgBatPeopleTypeService.submit(pmgBatPeopleType);
    }

    /**
     * 人员类型 删除
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "人员类型 删除", notes = "人员类型 删除")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
        return pmgBatPeopleTypeService.del(id);
    }

    /**
     * 人员类型手动入库
     * @param pmgBatPeopleType
     * @return
     */
    @PostMapping("/add")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "人员类型 新增或修改", notes = "人员类型 新增或修改")
    public R add(@Valid @RequestBody PmgBatPeopleType pmgBatPeopleType) {
        return R.data(pmgBatPeopleTypeService.save(pmgBatPeopleType));
    }
}