package com.pj.tb_purchaser;

import com.pj.api.dto.PurchaserDto;
import com.pj.tb_purchaser.param.PurchaserParam;
import com.pj.utils.sg.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;


/**
 * Controller: tb_purchaser -- 收购商(app接口)
 * @author lbl
 */
@RestController
@RequestMapping("/app/TbPurchaser/")
public class TbPurchaserAppController {

	/** 底层 Service 对象 */
	@Autowired
	TbPurchaserService tbPurchaserService;

	/** 查个人信息 - 根据id */
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		TbPurchaser t = tbPurchaserService.getById(id);
		return AjaxJson.getSuccessData(t);
	}

	/** 修改认证信息 */
	@RequestMapping("update")
	public AjaxJson update(TbPurchaser t){
		tbPurchaserService.update(t);
		return AjaxJson.getSuccess();
	}

	/** 收购商认证 */
	@RequestMapping("identification")
	public AjaxJson identification(@RequestBody @Validated PurchaserParam purchaser) throws ParseException {
		boolean identification = tbPurchaserService.identification(purchaser);
		if(!identification) return AjaxJson.getError("收购商认证信息提交失败!!!");

		return AjaxJson.getSuccess("收购商认证信息已提交,管理员审核中,请耐心等待!");
	}

	/** 收购商认证状态查询 */
	@RequestMapping("auditStatus")
	public AjaxJson auditStatus(Long appUserId) {
		return AjaxJson.getSuccessData(tbPurchaserService.auditStatus(appUserId));
	}

	/*------            正常业务👆👆    rpc远程调用👇👇                         -----------*/

	/**
	 * 根据ID查商户
	 * @param id
	 * @return
	 */
	@RequestMapping("rpc/getByPurchaserId")
	public PurchaserDto getByPurchaserId(@RequestParam("id") Long id){
		PurchaserDto byPurchaserId = tbPurchaserService.getByPurchaserId(id);
		return byPurchaserId;
	}


}
