package com.lz.modules.equipment.controller;

import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.RedisUtils;
import com.lz.modules.app.service.StaffService;
import com.lz.modules.equipment.entity.EquipmentInfo;
import com.lz.modules.equipment.entity.model.FindByNameModel;
import com.lz.modules.equipment.entity.model.FindEmployeeResModel;
import com.lz.modules.equipment.entity.model.FindEquipmentsByNameModel;
import com.lz.modules.equipment.service.IEquipmentInfoService;
import com.lz.modules.equipment.service.SpecialApplyInfoService;
import com.lz.modules.sys.controller.AbstractController;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.ArrayList;
import java.util.List;

/**
 * @Author: djc
 * @Desc:
 * @Date: 2020/7/24 17:21
 */
@Slf4j
@RestController
@RequestMapping("api")
@Api(value = "员工相关接口", tags = { "Employees" })
public class EmployeeController extends AbstractController {

    @Autowired
    private StaffService staffService;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private SpecialApplyInfoService specialApplyInfoService;
    @Autowired
    private IEquipmentInfoService iEquipmentInfoService;

    @PostMapping("findEmployeeByName")
    @RequiresPermissions("user:device:pandian")
    public R findEmployeeByName(@RequestBody @ApiParam FindByNameModel nameModel){
        PageUtils pageUtils = PageUtils.startPage(nameModel.getCurrPage(), nameModel.getPageSize()).doSelect(
                page -> staffService.selectBySearchName(page, nameModel)
        );
        return R.ok().put("data", pageUtils);

    }

    @PostMapping("findSpecialApplyByName")
    @RequiresPermissions("user:device:pandian")
    public R findSpecialApplyByName(@RequestBody @ApiParam FindByNameModel nameModel){
        List<FindEmployeeResModel> data = new ArrayList<>();
        PageUtils pageUtils = PageUtils.startPage(nameModel.getCurrPage(), nameModel.getPageSize()).doSelect(
                page -> specialApplyInfoService.selectBySearchName(page, nameModel)
        );

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

    }


    @PostMapping("findUsersEquipmentsByName")
    @RequiresPermissions("user:device:pandian")
    public R findUsersEquipmentsByName(@RequestBody @ApiParam FindEquipmentsByNameModel nameModel){

        PageUtils pageUtils = PageUtils.startPage(nameModel.getCurrPage(), nameModel.getPageSize()).doSelect(
                page -> iEquipmentInfoService.selectByStaffIdOrDepId(page, nameModel)
        );

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

    }

}
