package com.huiju.estateagents.property.controller;


import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.center.taUser.entity.TaUser;
import com.huiju.estateagents.property.common.UserElement;
import com.huiju.estateagents.property.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.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 物业web端二手交易表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2018-12-29
 */
@RestController

@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当前页"
					)
	})

	@RequestMapping(value = "/transactions",method = RequestMethod.POST)
	public ResponseBean getList(@RequestBody String parameter, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean responseBean = transactionService.getTransactionList(parameter,userElement.getOrgId() );
		return responseBean;
	}
	
	// @ApiOperation(value = "获取二手租赁详情", notes = "获取二手租赁详情")
	@ApiImplicitParams({
			@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, HttpServletRequest request){
		ResponseBean responseBean = new ResponseBean();
		TaUser userElement = getTaUser(request);
		responseBean = transactionService.getTransactionInfo(id);
		return responseBean;
	}
	
	// @ApiOperation(value = "作废二手租赁", notes = "作废二手租赁")
	@ApiImplicitParams({
			@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, HttpServletRequest request){
		ResponseBean responseBean = new ResponseBean();
		TaUser userElement = getTaUser(request);
		responseBean = transactionService.updateTransactionById(id,userElement.getUserId());
		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 是草稿 ")})

	@RequestMapping(value="/transactions/add",method = RequestMethod.POST)
	public ResponseBean transactionsAdd(@RequestBody String paramets, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean  addAnnouncement= transactionService.transactionsAdd(paramets,userElement);
		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 是草稿 ")})

	@RequestMapping(value="/transactions/updata",method = RequestMethod.POST)
	public ResponseBean transactionsUpdata(@RequestBody String paramets, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean  transactionsUpdata= transactionService.transactionsUpdata(paramets,userElement.getOrgId(),userElement.getUserId());
		return transactionsUpdata;
	}
	// @ApiOperation(value = "删除二手租赁",nickname ="删除二手租赁")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:帖子id(多个)" )})

	@RequestMapping(value="/transactions/delete",method = RequestMethod.POST)
	public ResponseBean transactionsDelete(@RequestBody String paramets, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean  transactionsUpdata= transactionService.transactionsDelete(paramets,userElement.getOrgId(),userElement.getUserId());
		return transactionsUpdata;
	}

	// @ApiOperation(value = "二手评论列表",nickname ="二手评论列表")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:帖子id，replyTaUserName：被回复人，taUserName：回复人，" +
					"status:（0回复我的,1回复全部物业人员的,2全部物业人员回复的,3话题发起人回复的）,createDate:时间" )})

	@RequestMapping(value="/transactionReplyList",method = RequestMethod.POST)
	public ResponseBean transactionReplyList(@RequestBody String paramets, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean  transactionReplyList= transactionService.transactionReplyList(paramets,userElement);
		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, HttpServletRequest request){
		ResponseBean  transactionsUpdata= transactionService.deleteReply(paramets);
		return transactionsUpdata;
	}

	// @ApiOperation(value = "添加二手帖子评论",nickname ="添加二手帖子评论")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:帖子id，contentImg:评论所带图片,replyContent:评论内容" )})

	@RequestMapping(value="/transactionReply/add",method = RequestMethod.POST)
	public ResponseBean transactionReplyAdd(@RequestBody String paramets, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean  transactionReplyAdd= transactionService.transactionReplyAdd(paramets,userElement);
		return transactionReplyAdd;
	}

	// @ApiOperation(value = "二手帖子举报列表",nickname ="二手帖子举报列表")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value =":举报人姓名，reportPhone：举报人电话,transactionId:帖子ID" )})

	@RequestMapping(value="/transactionReportList",method = RequestMethod.POST)
	public ResponseBean transactionReportList(@RequestBody String paramets, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean  transactionReplyList= transactionService.transactionReportList(paramets,userElement);
		return transactionReplyList;
	}
}
