package org.jeecg.modules.api.controller2;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.PageBean;
import org.jeecg.modules.apiService.NotebookService;
import org.jeecg.modules.employBillInfo.entity.EmployBillInfo;
import org.jeecg.modules.employFeedback.entity.EmployFeedback;
import org.jeecg.modules.employNotebook.entity.EmployNotebook;
import org.jeecg.modules.employWorkInfo.entity.EmployWorkInfo;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags="记工记账相关接口")
@RestController
@RequestMapping("/employ/notebook")
@Slf4j
public class NotebookController {

    /******************************************************************************************************************/
    //记工记账信息
    @Resource
    private NotebookService notebookService;
    /******************************************************************************************************************/

    //个人记工-新建账本
    @ApiOperation(value="记工记账-新建账本", notes="Type：0-个人 1-班组")
    @RequestMapping(value = "/addNoteBook", method = {RequestMethod.POST})
    public Result<?> addNoteBook(@RequestHeader("X-Access-Token") String token, EmployNotebook employNotebook){
        return notebookService.addNoteBook(token, employNotebook);
    }

    //个人记工-账本信息修改
    @ApiOperation(value="记工记账-账本信息修改", notes="记工记账-账本信息修改")
    @RequestMapping(value = "/updateNoteBook", method = {RequestMethod.POST})
    public Result<?> updateNoteBook(@RequestHeader("X-Access-Token") String token, EmployNotebook employNotebook){
        return notebookService.updateNoteBook(token, employNotebook);
    }

    @ApiOperation(value="记工记账-在建/结束项目", notes="Type：0-个人 1-班组， status: 0-在建项目 1-结束项目")
    @RequestMapping(value = "/queryNotebookList", method = {RequestMethod.GET})
    public Result<?> queryNotebookList(@RequestHeader("X-Access-Token") String token, String type, String status, PageBean pageBean){
        return notebookService.queryNotebookList(token, type, status, pageBean);
    }

    //个人记工-全年收支
    @ApiOperation(value="记工记账-全年收支", notes="记工记账-全年收支")
    @RequestMapping(value = "/queryBill", method = {RequestMethod.GET})
    public Result<?> queryBill(@RequestHeader("X-Access-Token") String token, String employNoteBookId, PageBean pageBean){
        return notebookService.queryBill(token, employNoteBookId, pageBean);
    }

    //个人记工-全年收支金额
    @ApiOperation(value="记工记账-全年收支金额", notes="记工记账-全年收支金额")
    @RequestMapping(value = "/queryBillAmount", method = {RequestMethod.GET})
    public Result<?> queryBillAmount(@RequestHeader("X-Access-Token") String token, String employNoteBookId){
        return notebookService.queryBillAmount(token, employNoteBookId);
    }

    //个人记工-技工问题
    @ApiOperation(value="记工记账-技工问题", notes="记工记账-技工问题")
    @RequestMapping(value = "/addQuestion", method = {RequestMethod.POST})
    public Result<?> addQuestion(@RequestHeader("X-Access-Token") String token, EmployFeedback employFeedback){
        return notebookService.addQuestion(token, employFeedback);
    }

    @ApiOperation(value="记工记账-项目记账", notes="记工记账-项目记账")
    @RequestMapping(value = "/addBillInfo", method = {RequestMethod.POST})
    public Result<?> addBillInfo(@RequestHeader("X-Access-Token") String token, EmployBillInfo employBillInfo){
        String message = null;
        //参数校验
        if(null == employBillInfo.getNotebookId()){
            message = "账本id为空，请输入正确的账本id";
        }else if(null == employBillInfo.getAmount()){
            message = "记账金额为空，请输入金额";
        }else if(null == employBillInfo.getBillDate()){


            message = "记账日期为空，请输入记账日期";
        }else if(null == employBillInfo.getType()){
            message = "记账类型为空，请输入记账类型";
        }
        //参数输入有误，返回错误信息
        if(null != message){
            return Result.OK(message);
        }

        //业务处理
        return notebookService.addBillInfo(token, employBillInfo);
    }

    @ApiOperation(value="记工记账-项目记工", notes="记工记账-项目记工")
    @RequestMapping(value = "/addWorkInfo", method = {RequestMethod.POST})
    public Result<?> addWorkInfo(@RequestHeader("X-Access-Token") String token, EmployWorkInfo employWorkInfo){
        String message = null;
        //参数校验
        if(null == employWorkInfo.getNotebookId()){
            message = "账本id为空，请输入正确的账本id";
        }else if(null == employWorkInfo.getOvertime()){
            message = "加班时长为空，请输入加班时长";
        }else if(null == employWorkInfo.getWorkDate()){
            message = "记工日期为空，请输入记工日期";
        }

        //参数输入有误，返回错误信息
        if(null != message){
            return Result.OK(message);
        }

        //业务处理
        return notebookService.addWorkInfo(token, employWorkInfo);
    }

    @ApiOperation(value="记工记账-查询记工记录", notes="记工记账-查询记工记录")
    @RequestMapping(value = "/queryWork", method = {RequestMethod.GET})
    public Result<?> queryWork(@RequestHeader("X-Access-Token")String token, EmployWorkInfo workInfo, PageBean pageBean){
        //业务处理
        return notebookService.queryWork(token, workInfo, pageBean);
    }

}
