package thyyxxk.webserver.controller.inpatient.charge;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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 thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.inpatient.charge.MisPosVo;
import thyyxxk.webserver.service.inpatient.charge.TransactionService;
import thyyxxk.webserver.utils.IpAddressUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 智能银行接口
 * @Author:lihong
 * @Date: 2024/9/14
 */
@RestController
@RequestMapping("/transaction")
public class TransactionController {
    @Resource
    private TransactionService transactionService;
    /**
     * @description: pos 签到
     * @author: lihong
     * @date: 2024/9/18 16:42
     * @param: httpServletRequest
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @GetMapping("/sign")
    @PassToken
    public ResultVo sign(HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        return transactionService.posGet("sign","ip="+ipAddress);
    }

    /**
     * @description: pos 查余
     * @author: lihong
     * @date: 2024/9/18 16:42
     * @param: httpServletRequest
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @GetMapping("/balance")
    @PassToken
    public ResultVo balance(HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        return transactionService.posGet("balance","ip="+ipAddress);
    }

    /**
     * @description: pos 刷卡 /扫码 消费  必传参数 amt  chequeType type  非必传 inputRemarkInfo
     * @author: lihong
     * @date: 2024/9/18 16:53
     * @param: httpServletRequest
     * @param: misPosVo
     * @return: thyyxxk.webserver.entity.ResultVo
     **/
    @PostMapping("/consume")
    @PassToken
    public ResultVo consume( @RequestBody MisPosVo misPosVo,HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        misPosVo.setIp(ipAddress);
        return transactionService.posPost(misPosVo,"consume");
    }
    /**
     * @description: 财务工具刷卡/扫码  必传 chequeType   amt  非必传 inputRemarkInfo
     * @author: lihong 
     * @date: 2024/9/18 17:16
     * @param: misPosVo
     * @param: httpServletRequest 
     * @return: thyyxxk.webserver.entity.ResultVo
     **/
    @PostMapping("/consumeCommon")
    @PassToken
    public ResultVo consumeCommon( @RequestBody MisPosVo misPosVo,HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        misPosVo.setIp(ipAddress);
        return transactionService.posPost(misPosVo,"consumeCommon");
    }

    /**
     * @description: 财务工具退货
     * 必传 chequeType   amt 只能退 银联卡(3) 或聚合支付(O)
     * 银联卡还需传 psordnum  transDate
     * 或聚合支付还需传   parChannel
     * @author: lihong
     * @date: 2024/9/18 17:17
     * @param: misPosVo
     * @param: httpServletRequest
     * @return: thyyxxk.webserver.entity.ResultVo
     **/
    @PostMapping("/refund")
    @PassToken
    public ResultVo refund( @RequestBody MisPosVo misPosVo,HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        misPosVo.setIp(ipAddress);
        return transactionService.posPost(misPosVo,"refund");
    }

    /**
     * @description: 重印
     * @param traceNo  交易凭证号，为空则重印上一笔，不为空则重印指定
     * @author: lihong 
     * @date: 2024/9/18 17:18
     * @param: httpServletRequest 
     * @return: thyyxxk.webserver.entity.ResultVo
     **/
    @GetMapping("/reprint")
    @PassToken
    public ResultVo reprint(@RequestParam("traceNo") String traceNo,HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        return transactionService.posGet("reprint","ip="+ipAddress+"&traceNo="+traceNo);
    }

    /**
     * @description: 结算
     * @author: lihong
     * @date: 2024/9/18 17:24
     * @param: httpServletRequest
     * @return: thyyxxk.webserver.entity.ResultVo
     **/
    @GetMapping("/settle")
    @PassToken
    public ResultVo settle(HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        return transactionService.posGet("settle","ip="+ipAddress);
    }

    /**
     * 交易查询
     * @param plId  订单号
     * @param httpServletRequest
     * @return
     */
    @GetMapping("/query")
    @PassToken
    public ResultVo query(@RequestParam("plId") String plId,HttpServletRequest httpServletRequest){
        String ipAddress = IpAddressUtil.getIPAddress(httpServletRequest);
        return transactionService.posGet("query","ip="+ipAddress+"&plId="+plId);
    }

}
