package com.unis.base.app.controller;

import com.unis.base.app.service.PersonnelService;
import com.unis.base.client.PersonnelFegin;
import com.unis.base.common.vo.DRyxxsjyVO;
import com.unis.common.utils.CurrentUtil;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author WangZL
 * @version 1.0
 * @Title PersonnelController
 * @ProjectName 人员信息 Controller
 * @Description
 * @date 2019/07/22 17点26分
 */
@RestController
@Api(value = "人员信息", tags = "人员信息维护")
@Slf4j
public class PersonnelController {

	@Autowired
	private PersonnelFegin personnelFegin;

	@Autowired
	private PersonnelService personnelService;

	@ApiOperation(value = "获取人员信息列表", notes = "参数：人员编号，人员名称，库点编号，库点名称，岗位代码")
	@PostMapping(value = "/personnelList")
	public ResponseWrapper getDRyxxsjyList(@RequestBody DRyxxsjyVO dRyxxsjyVO){
		return personnelFegin.getDRyxxsjyList(dRyxxsjyVO);
	}

	@ApiOperation(value = "分页获取人员信息列表", notes = "参数：人员编号，人员名称，库点编号，库点名称，岗位代码")
	@PostMapping(value = "/personnelPage/{pageNum}/{pageSize}")
	public ResponseWrapper getDRyxxsjyPage(@RequestBody DRyxxsjyVO dRyxxsjyVO,@PathVariable("pageNum")Integer pageNum,@PathVariable("pageSize") Integer pageSize) {
		return personnelFegin.getDRyxxsjyPage(dRyxxsjyVO,pageNum,pageSize);
	}

	@ApiOperation(value = "根据人员编码获取人员信息", notes = "参数：库点编号")
	@GetMapping(value = "/personnel/{rybh}")
	public ResponseWrapper getDRyxxsjyInfoByrybh(@PathVariable("rybh")String rybh) {
        return personnelFegin.getDRyxxsjyInfoByrybh(rybh);
	}

	@ApiOperation(value = "更新人员信息", notes = "参数：人员姓名，所属库点代码")
	@PutMapping(value = "/personnel")
	public ResponseWrapper update(@RequestBody DRyxxsjyVO dRyxxsjyVO) {
		dRyxxsjyVO.setRefresher(CurrentUtil.getUserName());
		dRyxxsjyVO.setRefreshTime(new Date());
        return personnelFegin.update(dRyxxsjyVO);
	}

	@DeleteMapping(value="/personnel/{rybh}")
	@ApiOperation(value = "根据人员编号删除人员信息", notes = "参数：人员编号")
	public ResponseWrapper delete(@PathVariable("rybh")String rybh) {
        return personnelFegin.delete(rybh);
    }

	@PostMapping(value = "/personnel")
	@ApiOperation(value = "新增人员信息", notes = "参数：人员编号")
    public ResponseWrapper insert(@RequestBody DRyxxsjyVO dRyxxsjyVO) {
		dRyxxsjyVO.setStatus(1);
		dRyxxsjyVO.setCreator(CurrentUtil.getUserName());
		dRyxxsjyVO.setCreateDate(new Date());
        return personnelFegin.insert(dRyxxsjyVO);
    }

	@PostMapping(value = "/personnelInsertList")
	@ApiOperation(value = "人员信息-新增列表", notes = "参数：人员信息列表")
	public ResponseWrapper insertList(@RequestBody List<DRyxxsjyVO> dRyxxsjyVOList) {
		return personnelService.insertList(dRyxxsjyVOList);
	}

	@ApiOperation(value = "人员信息-根据库点代码获取人员列表", notes = "参数：库点代码")
	@PostMapping(value = "/personnelListByKddm/{kddm}")
	public ResponseWrapper getPersonnelListByKddm(@PathVariable("kddm")String kddm){
		return personnelFegin.getPersonnelListByKddm(kddm);
	}

	@PostMapping(value = "/personnelEnabled")
	@ApiOperation(value = "人员信息-更改启用状态", notes = "参数：人员编号，启用状态")
	public ResponseWrapper updateEnabled(@RequestBody DRyxxsjyVO dRyxxsjyVO) {
		return personnelFegin.updateEnabled(dRyxxsjyVO);
	}
}
