package com.community.huiju.controller;


import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.service.IUserService;
import com.community.huiju.service.TpTicketService;
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.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.community.huiju.common.base.BaseController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 工单表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-02-14
 */
@RestController
@RequestMapping("/")
@Api(value = "工单列表API", description = "工单列表API")
public class TpTicketController extends BaseController {
    @Autowired
    private IUserService userService;

    @Autowired
    private TpTicketService tpTicketService;
    @ApiOperation(value = "工单列表", notes = "工单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "id:工单编号，" +
                    "type:工单类型(1:投诉 2:报修   3:联系物业)," +
                    "ticketTitle:工单标题，createUser:发起人," +
                    "status:流转状态(0:待分配  1:拒绝受理 2:待处理 3:正在处理 4:待评价 5:已评价 6:已终止'）" +
                    "tpUserId:当前处理人" )
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/ticketLiset", method = RequestMethod.POST)
    public ResponseBean ticketLiset(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = tpTicketService.ticketLiset(parameter,userElement.getCommunityId());
        return responseBean;
    }

    @ApiOperation(value = "工单详情", notes = "工单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "id:工单编号")
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/ticketDetails", method = RequestMethod.POST)
    public ResponseBean ticketDetails(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = tpTicketService.ticketDetails(parameter,userElement.getId(),userElement.getCommunityId());
        return responseBean;
    }
    @ApiOperation(value = "添加工单对话", notes = "添加工单对话")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "content:对话内容，imageUrl:[]图片,ticketId:工单id，" +
                    "status:工单状态（0:待分配  1:拒绝受理 2:待处理 3:正在处理 4:待评价 5:已评价 6:已终止）")
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/addRecordComment", method = RequestMethod.POST)
    public ResponseBean addRecordComment(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = tpTicketService.addRecordComment(parameter,userElement.getId(),userElement.getCommunityId(),userElement.getUserName());
        return responseBean;
    }
    @ApiOperation(value = "工单受理分配", notes = "工单受理分配")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "ticketId:工单id，" +
                    "id:当前处理人id")
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/addRecord", method = RequestMethod.POST)
    public ResponseBean addRecord(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = tpTicketService.addRecord(parameter,userElement.getId(),userElement.getCommunityId());
        return responseBean;
    }
    @ApiOperation(value = "修改工单状态为拒绝处理", notes = "修改工单状态为拒绝处理")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "ticketId:工单id,textContent:拒绝的内容" )
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/updateTicketStatus", method = RequestMethod.POST)
    public ResponseBean updateTicketStatus(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = tpTicketService.updateTicketStatus(parameter,userElement.getId(),userElement.getCommunityId(),userElement.getUserName(),userElement.getLoginName());
        return responseBean;
    }

    @ApiOperation(value = "修改当前状态为待评价", notes = "修改当前状态为待评价")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "content:对话内容，imageUrl:[]图片,ticketId:工单id" )
    })
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value = "/updateTicket", method = RequestMethod.POST)
    public ResponseBean updateTicket(@RequestBody String parameter, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  responseBean = tpTicketService.updateTicket(parameter,userElement.getId(),userElement.getCommunityId(),userElement.getUserName(),userElement.getLoginName());
        return responseBean;
    }
}
