package com.zjty.tynotes.job.status.controller;

import com.zjty.tynotes.job.status.entity.RedisListSum;
import com.zjty.tynotes.job.status.service.InternalService;
import com.zjty.tynotes.job.status.service.TestSeeService;
import com.zjty.tynotes.job.status.service.TestService;
import com.zjty.tynotes.misc.config.AutoDocument;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author zjm
 */
@AutoDocument
@RestController
@RequestMapping("/read")
@Api(tags = "查看任务页面", value = "查看任务页面数据")
public class Read1Controller {
    @Autowired
    TestService testService;
    @Autowired
    TestSeeService testSeeService;

    @Autowired
    InternalService internalService;
    /**
     *阅读页面我的代办任务列表
     * @param page              页码 默认1
     * @param size              每页显示条数 默认10
     * @param id                人员id
     */
    @PostMapping("/selectCommission")
    @ApiOperation(value = "获取我的代办任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="string", paramType = "query",required = true),
            @ApiImplicitParam(name="page",value="页码",dataType="int", paramType = "query",example = "1"),
            @ApiImplicitParam(name="size",value="每页显示条数",dataType="int", paramType = "query",example = "10")
    })
    public ResponseEntity<RedisListSum> selectCommission(@RequestParam(value = "id") String id,
                                                      @RequestParam(value = "page", defaultValue = "1") int page,
                                                      @RequestParam(value = "size", defaultValue = "10") int size){

        int pageSize;
        if (page==0){
            pageSize=1;
        }else {
            pageSize=page;
        }

        return ResponseEntity.ok(testSeeService.selectMeCommissionWork(id,pageSize,size));
    }

    /**
     *阅读页面我接收的任务列表
     * @param page              页码 默认1
     * @param size              每页显示条数 默认10
     * @param id                人员id
     */
    @PostMapping("/selectRelated")
    @ApiOperation(value = "获取我的相关任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="string", paramType = "query",required = true),
            @ApiImplicitParam(name="page",value="页码",dataType="int", paramType = "query",example = "1"),
            @ApiImplicitParam(name="size",value="每页显示条数",dataType="int", paramType = "query",example = "10")
    })
    public ResponseEntity<RedisListSum> selectRelated(@RequestParam(value = "id") String id,
                                                @RequestParam(value = "page", defaultValue = "1") int page,
                                                @RequestParam(value = "size", defaultValue = "10") int size){

        int pageSize;
        if (page==0){
            pageSize=1;
        }else {
            pageSize=page;
        }

        return ResponseEntity.ok(testSeeService.selectMeRelatedWork(id,pageSize,size));
    }

    /**
     *阅读页面我的分解任务列表
     * @param page              页码 默认1
     * @param size              每页显示条数 默认10
     * @param id                人员id
     */
    @PostMapping("/selectMeResolve")
    @ApiOperation(value = "阅读页面我的分解任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="string", paramType = "query",required = true),
            @ApiImplicitParam(name="page",value="页码",dataType="int", paramType = "query",example = "1"),
            @ApiImplicitParam(name="size",value="每页显示条数",dataType="int", paramType = "query",example = "10")
    })
    public ResponseEntity<RedisListSum> selectMeResolveWork(@RequestParam(value = "id") String id,
                                                @RequestParam(value = "page", defaultValue = "1") int page,
                                                @RequestParam(value = "size", defaultValue = "10") int size){
        int pageSize;
        if (page==0){
            pageSize=1;
        }else {
            pageSize=page;
        }
        return ResponseEntity.ok(testSeeService.selectMeResolveWork(id,pageSize,size));
    }

    /**
     *阅读页面我发布的任务列表
     * @param page              页码 默认1
     * @param size              每页显示条数 默认10
     * @param id                人员id
     */
    @PostMapping("/selectMeRelease")
    @ApiOperation(value = "阅读页面我发布的任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="string", paramType = "query",required = true),
            @ApiImplicitParam(name="page",value="页码",dataType="int", paramType = "query",example = "1"),
            @ApiImplicitParam(name="size",value="每页显示条数",dataType="int", paramType = "query",example = "10")
    })
    public ResponseEntity<RedisListSum> selectMeReleaseWork(@RequestParam(value = "id") String id,
                                                            @RequestParam(value = "page", defaultValue = "1") int page,
                                                            @RequestParam(value = "size", defaultValue = "10") int size){

        int pageSize;
        if (page==0){
            pageSize=1;
        }else {
            pageSize=page;
        }
        return ResponseEntity.ok(testSeeService.selectMeReleaseWork(id,pageSize,size));
    }

    /**
     *阅读页面标题查询列表
     * @param page              页码 默认1
     * @param size              每页显示条数 默认10
     * @param id                人员id
     */
    @PostMapping("/titleSelect")
    @ApiOperation(value = "获取根据标题查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="string", paramType = "query",required = true),
            @ApiImplicitParam(name="page",value="页码",dataType="int", paramType = "query",example = "1"),
            @ApiImplicitParam(name="size",value="每页显示条数",dataType="int", paramType = "query",example = "10"),
            @ApiImplicitParam(name="title",value="标题",dataType="string", paramType = "query")
    })
    public ResponseEntity<RedisListSum> titleSelect(@RequestParam(value = "id") String id,
                                                 @RequestParam(value = "page", defaultValue = "1") int page,
                                                 @RequestParam(value = "size", defaultValue = "10") int size,
                                                 @RequestParam(value = "title", defaultValue = "10") String title){

        int pageSize;
        if (page==0){
            pageSize=0;
        }else {
            pageSize=page;
        }
        return ResponseEntity.ok(testSeeService.titleSelect(id,pageSize,size,title));
    }




    /**
     * 查看事件的时候
     * @param id 人员id
     * @param eventId 事件id
     * @param readState 是否阅读过  判读是否阅读过  否修改 阅读状态
     * @return
     */
    @ApiOperation(value = "修改事件状态")
    @PostMapping("/readsStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="String", paramType = "query",required = true),
            @ApiImplicitParam(name="eventId",value="事件id",dataType="String", paramType = "query",required = true,example ="1"),
            @ApiImplicitParam(name="readState",value="是否阅读过",dataType="int", paramType = "query",required = true,example="1")
    })

    public ResponseEntity readsStatus(@RequestParam(value = "id") String id,
                                              @RequestParam(value = "eventId")String eventId,
                                              @RequestParam(value = "readState")int readState
    ){
        testService.readsStatus(id,eventId,readState);
        HashMap map=new HashMap(10);
        map.put("msg","事件状态修改成功");
        return ResponseEntity.ok(map);
    }

    @ApiOperation(value = "人员登入第一次的数据触发,之后的数据推送")
    @PostMapping("/push")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="String", paramType = "query",required = true)
    })

    public ResponseEntity loginFirstOneManualPush(@RequestParam(value = "id") String id
    ){

        testService.loginFirstOneManualPush(id);
        return ResponseEntity.ok().build();
    }


    @ApiOperation(value = "测试接口")
    @PostMapping("/test")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="人员id",dataType="String", paramType = "query",required = true)
    })

    public ResponseEntity loginFirstOneManualPush1(@RequestParam(value = "id") String id
    ){

//        internalService.personnelWorkCount(id);
        return ResponseEntity.ok(internalService.personnelWorkCount(id));
    }

}
