package com.yh.saas.plugin.servicer.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.winsea.svc.base.base.util.page.PageUtil;
import com.yh.saas.common.support.plugin.PluginFeature;
import com.yh.saas.plugin.servicer.entity.ServicerBillOperateHis;
import com.yh.saas.plugin.servicer.entity.ServicerMerchantInfo;
import com.yh.saas.plugin.servicer.entity.view.ServicerView;
import com.yh.saas.plugin.servicer.service.IServicerBillOperateHisService;
import com.yh.saas.plugin.servicer.service.IServicerMerchantInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 记录服务商信息表 前端控制器
 * </p>
 *
 * @author yul
 * @since 2019-11-11
 */
@PluginFeature(id = "SupplyServicerMerchantInfo", name = "服务商信息")
@RestController
@RequestMapping("/servicerMerchantInfo")
public class ServicerMerchantInfoController {

	@Autowired
	private IServicerMerchantInfoService merchantInfoService;

	@Autowired
	private IServicerBillOperateHisService servicerBillOperateHisService;

	/**
	 * 新增服务商信息
	 * 
	 * @param merchantInfoView
	 * @return
	 */
	@PostMapping("/api/saveAdd")
	@PluginFeature(id = "ServicerMerchant-Add", name = "服务商信息_新增")
	public String saveAdd(@RequestBody ServicerView<ServicerMerchantInfo> merchantInfoView) {
		return merchantInfoService.saveServicerMerchant(merchantInfoView);
	}

	/**
	 * 编辑服务商信息
	 * 
	 * @param merchantInfoView
	 */
	@PostMapping("/api/saveEdit")
	@PluginFeature(id = "ServicerMerchant-Edit", name = "服务商信息_编辑")
	public void saveEdit(@RequestBody ServicerView<ServicerMerchantInfo> merchantInfoView) {
		merchantInfoService.saveServicerMerchant(merchantInfoView);
	}

	/**
	 * 提交服务商
	 * 
	 * @param merchantInfoView
	 */
	@PluginFeature(id = "ServicerMerchant-Submit", name = "服务商信息_提交")
	@PostMapping("/api/submitServicerMerchant")
	public void submitServicerMerchant(@RequestBody ServicerView<ServicerMerchantInfo> merchantInfoView) {
		merchantInfoView.setOnlySubmit(Boolean.TRUE);
		merchantInfoService.saveServicerMerchant(merchantInfoView);
	}

	/**
	 * 审核服务商
	 * 
	 * @param merchantInfoView
	 */
	@PluginFeature(id = "ServicerMerchant-Approve", name = "服务商信息_审核")
	@PostMapping(value = "/api/approveServicerMerchant")
	public void approveServicerMerchant(@RequestBody ServicerView<ServicerMerchantInfo> merchantInfoView) {
		merchantInfoService.approveServicerMerchant(merchantInfoView);
	}

	/**
	 * 删除服务商信息
	 *
	 * @param merchantInfo
	 */
	@PostMapping("/api/deleteMerchantById")
	@PluginFeature(id = "ServicerMerchant-Remove", name = "服务商信息_删除")
	public void deleteMerchantById(@RequestBody ServicerMerchantInfo merchantInfo) {
		merchantInfoService.deleteMerchantById(merchantInfo);
	}

	/**
	 * 修改是否启用
	 *
	 * @param merchantInfo
	 */
	@PostMapping("/api/updateEnabled")
	@PluginFeature(id = "ServicerMerchant-Edit", name = "服务商信息_编辑")
	public void updateEnabled(@RequestBody ServicerMerchantInfo merchantInfo) {
		merchantInfoService.updateEnabled(merchantInfo.getServicerId());
	}

	/**
	 * 服务商信息分页列表查询
	 * 
	 * @param paramMap
	 * @return
	 */
	@PluginFeature(id = "ServicerMerchant-View", name = "服务商信息_查看")
	@GetMapping("/query/getPageByCondition")
	public Page<ServicerMerchantInfo> getPageByCondition(@RequestParam Map<String, Object> paramMap) {
		return merchantInfoService.selectPageByCondition(PageUtil.convertMap(paramMap));
	}

	/**
	 * 服务商信息列表查询
	 * 
	 * @param paramMap
	 * @return
	 */
	@PluginFeature(id = "ServicerMerchant-View", name = "服务商信息_查看")
	@GetMapping("/query/getListByCondition")
	public List<ServicerMerchantInfo> getListByCondition(@RequestParam Map<String, Object> paramMap) {
		return merchantInfoService.selectListByCondition(paramMap);
	}

	/**
	 * 服务商银行信息列表查询
	 * 
	 * @param paramMap
	 * @return
	 */
	@PluginFeature(id = "ServicerMerchant-View", name = "服务商信息_查看")
	@GetMapping("/query/getBankListByCondition")
	public List<Map<String, Object>> getBankListByCondition(@RequestParam Map<String, Object> paramMap) {
		return merchantInfoService.selectBankListByCondition(paramMap);
	}

	/**
	 * 根据服务商ID查看服务商详情
	 * 
	 * @param servicerId
	 * @return
	 */
	@PluginFeature(id = "ServicerMerchant-View", name = "服务商信息_查看")
	@GetMapping("/query/getServicerMerchantInfoById")
	public ServicerMerchantInfo getServicerMerchantInfoById(
			@RequestParam(name = "servicerId", required = true) String servicerId) {
		return merchantInfoService.selectServicerMerchantInfoById(servicerId);
	}

	/**
	 * 操作历史查询
	 *
	 * @param id
	 * @param workflowId
	 * @return
	 */
	@PluginFeature(id = "ServicerMerchant-View", name = "服务商信息_查看")
	@GetMapping("/query/getBillOperateHis")
	public List<ServicerBillOperateHis> getBillOperateHis(@RequestParam String id, @RequestParam String workflowId) {
		return servicerBillOperateHisService.getBillOperateHis(id, workflowId);
	}

	/**
	 * 获取服务商邮箱地址
	 *
	 * @param servicerId
	 * @return
	 */
	@GetMapping("/query/getServicerMerchantMailInfo")
	public String getServicerMerchantMailInfo(String servicerId) {
		return merchantInfoService.getServicerMerchantMailInfo(servicerId);
	}

}
