package com.community.huiju.controller;


import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.common.base.BaseController;
import com.community.huiju.model.TpTransaction;
import com.community.huiju.service.ITransactionService;
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.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 物业web端二手交易表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2018-12-29
 */
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "二手租赁相关信息", description = "二手租赁相关信息Api")
public class TransactionController extends BaseController {
	
	@Autowired
	private ITransactionService transactionService;
	
	@ApiOperation(value = "根据搜索条件获取二手租赁列表", notes = "根据搜索条件获取二手租赁列表")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "id:话题编号，transactionTitle：标题" +
					"userName：发布人，status：状态，pageNum：总数，pageSize当前页"
					)
	})
	@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
	@RequestMapping(value = "/transactions",method = RequestMethod.POST)
	public ResponseBean getList(@RequestBody String parameter, HttpSession session){
		UserElement userElement = getUserElement(session);
		ResponseBean responseBean = transactionService.getTransactionList(parameter,userElement.getCommunityId() );
		return responseBean;
	}
	
	@ApiOperation(value = "获取二手租赁详情", notes = "获取二手租赁详情")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
			@ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "交易id")
	})
	@RequestMapping(value = "/transaction/{id}",method = RequestMethod.GET)
	public ResponseBean getList(@PathVariable(value = "id") Integer id, HttpSession session){
		ResponseBean responseBean = new ResponseBean();
		UserElement userElement = getUserElement(session);
		responseBean = transactionService.getTransactionInfo(id);
		return responseBean;
	}
	
	@ApiOperation(value = "作废二手租赁", notes = "作废二手租赁")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
			@ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "交易id")
	})
	@RequestMapping(value = "/transaction/update/{id}",method = RequestMethod.POST)
	public ResponseBean updateTransaction(@PathVariable(value = "id") Integer id, HttpSession session){
		ResponseBean responseBean = new ResponseBean();
		UserElement userElement = getUserElement(session);
		responseBean = transactionService.updateTransactionById(id,userElement.getId());
		return responseBean;
	}

	@ApiOperation(value = "添加二手租赁",nickname ="添加二手租赁")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="transactionTitle:话题标题，" +
					"type:0 代表 二手（卖二手物品）  1 是代表 求购 （买二手物品） 2 是代表 租赁（租二手物品）3其他话题，contentImg：图片，sort:权重值,status:'0 是已作废 1 是已发布  2 是草稿 ")})
	@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
	@RequestMapping(value="/transactions/add",method = RequestMethod.POST)
	public ResponseBean transactionsAdd(@RequestBody String paramets, HttpSession session){
		UserElement userElement = getUserElement(session);
		ResponseBean  addAnnouncement= transactionService.transactionsAdd(paramets,userElement.getCommunityId(),userElement.getId());
		return addAnnouncement;
	}

	@ApiOperation(value = "修改二手租赁",nickname ="修改二手租赁")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="transactionTitle:话题标题，" +
					"type:0 代表 二手（卖二手物品）  1 是代表 求购 （买二手物品） 2 是代表 租赁（租二手物品）3其他话题，contentImg：图片，sort:权重值,status:'0 是已作废 1 是已发布  2 是草稿 ")})
	@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
	@RequestMapping(value="/transactions/updata",method = RequestMethod.POST)
	public ResponseBean transactionsUpdata(@RequestBody String paramets, HttpSession session){
		UserElement userElement = getUserElement(session);
		ResponseBean  transactionsUpdata= transactionService.transactionsUpdata(paramets,userElement.getCommunityId(),userElement.getId());
		return transactionsUpdata;
	}
	@ApiOperation(value = "删除二手租赁",nickname ="删除二手租赁")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:帖子id(多个)" )})
	@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
	@RequestMapping(value="/transactions/delete",method = RequestMethod.POST)
	public ResponseBean transactionsDelete(@RequestBody String paramets, HttpSession session){
		UserElement userElement = getUserElement(session);
		ResponseBean  transactionsUpdata= transactionService.transactionsDelete(paramets,userElement.getCommunityId(),userElement.getId());
		return transactionsUpdata;
	}

	@ApiOperation(value = "二手评论列表",nickname ="二手评论列表")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:帖子id，replyTaUserName：被回复人，taUserName：回复人，" +
					"status:（0回复我的,1回复全部物业人员的,2全部物业人员回复的,3话题发起人回复的）,createDate:时间" )})
	@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
	@RequestMapping(value="/transactionReplyList",method = RequestMethod.POST)
	public ResponseBean transactionReplyList(@RequestBody String paramets, HttpSession session){
		UserElement userElement = getUserElement(session);
		ResponseBean  transactionReplyList= transactionService.transactionReplyList(paramets,userElement.getCommunityId(),userElement.getId());
		return transactionReplyList;
	}

	@ApiOperation(value = "删除二手帖子评论",nickname ="删除二手帖子评论")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:帖子id(多个)" )})
	@RequestMapping(value="/deleteReply",method = RequestMethod.POST)
	public ResponseBean deleteReply(@RequestBody String paramets, HttpSession session){
		ResponseBean  transactionsUpdata= transactionService.deleteReply(paramets);
		return transactionsUpdata;
	}

	@ApiOperation(value = "添加二手帖子评论",nickname ="添加二手帖子评论")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:帖子id，contentImg:评论所带图片,replyContent:评论内容" )})
	@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
	@RequestMapping(value="/transactionReply/add",method = RequestMethod.POST)
	public ResponseBean transactionReplyAdd(@RequestBody String paramets, HttpSession session){
		UserElement userElement = getUserElement(session);
		ResponseBean  transactionReplyAdd= transactionService.transactionReplyAdd(paramets,userElement);
		return transactionReplyAdd;
	}

	@ApiOperation(value = "二手帖子举报列表",nickname ="二手帖子举报列表")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value =":举报人姓名，reportPhone：举报人电话,transactionId:帖子ID" )})
	@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
	@RequestMapping(value="/transactionReportList",method = RequestMethod.POST)
	public ResponseBean transactionReportList(@RequestBody String paramets, HttpSession session){
		UserElement userElement = getUserElement(session);
		ResponseBean  transactionReplyList= transactionService.transactionReportList(paramets,userElement);
		return transactionReplyList;
	}
}
