package com.cirle.scientific.controller.signatrue;



import com.cirle.scientific.pojo.BizCodeEnum;
import com.cirle.scientific.pojo.Result;
import com.cirle.scientific.service.SignatrueService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


/**
 * @author 24901
 */
@Controller
@RequestMapping(value = "/signatrue")
public class SignatrueDetailController {


    private SignatrueService signatrueService;

    @Autowired
    public void setSignatrueService(SignatrueService signatrueService) {
        this.signatrueService = signatrueService;
    }

    @PostMapping(value = "/checkSign")
    @ResponseBody
    @ApiOperation(value = "查询签名信息")
    public Result checkSign(HttpServletRequest request,
                            @ApiParam(name = "memCard", value = "memCard") @RequestAttribute(value = "memCard", required = false) String memCard,
                            @ApiParam(name = "conferenceId", value = "会议id") @RequestParam() String conferenceId){
        if (request.getSession().getAttribute("UserCard") != null) {
            memCard = (String) request.getSession().getAttribute("UserCard");
        }
        if(memCard==null){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return Result.success(signatrueService.selectSignatrue(memCard , conferenceId));
    }

    @GetMapping("/info")
    @ApiOperation("签名页面")
    public String search(@ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/sign/info";
        }else {
            return "";
        }
    }

    @GetMapping("/sign")
    @ApiOperation("签名页面")
    public String sign(@ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/sign/sign";
        } else if (StringUtils.isNotBlank(from) && from.equals("web")){
            return "html5/sign/sign";
        }else {
            return "";
        }
    }



    @PostMapping(value = "/addSign")
    @ResponseBody
    @ApiOperation(value = "用户劳务合同签名")
    public Result addSign(HttpServletRequest request,
                      @ApiParam(name = "memCard", value = "用户唯一标识") @RequestAttribute(value = "memCard", required = false) String memCard,
                      @ApiParam(name = "conferenceId", value = "会议id") @RequestParam() String conferenceId,
                      @ApiParam(name = "formId", value = "模板id") @RequestParam() String formId,
                      @ApiParam(name = "partyB", value = "乙方") @RequestParam String partyB,
                      @ApiParam(name = "identityId", value = "身份证号") @RequestParam String identityId,
                      @ApiParam(name = "courseMatter", value = "讲课内容") @RequestParam String courseMatter,
                      @ApiParam(name = "courseTime", value = "讲课时间") @RequestParam String courseTime,
                      @ApiParam(name = "courseSite", value = "讲课地点") @RequestParam String courseSite,
                      @ApiParam(name = "m", value = "费用") @RequestParam String m,
                      @ApiParam(name = "bankProvince",value = "开户行省市") @RequestParam String bankProvince,
                      @ApiParam(name = "bankOfDepositName",value = "开户行名称") @RequestParam String bankOfDepositName,
                      @ApiParam(name = "bankId",value = "银行卡号") @RequestParam String bankId,
                      @ApiParam(name = "bankName",value = "户名") @RequestParam String bankName,
                      @ApiParam(name = "phone",value = "手机号") @RequestParam String phone,
                      @ApiParam(name = "signImg",value = "签名的图片") @RequestParam String signImg,
                      @ApiParam(name = "isSubmit", value = "用户是否提交") @RequestParam Integer isSubmit){
        if (request.getSession().getAttribute("UserCard") != null) {
            memCard = (String) request.getSession().getAttribute("UserCard");
        }
        if(memCard==null){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        if(request.getParameter("money")!=null){
            m = request.getParameter("money");
        }
        if("a".equalsIgnoreCase(m)){
//                { value: 'a', label: '1000' },
//                { value: 'b', label: '1500' },
//                { value: 'c', label: '2000' },
//                { value: 'd', label: '2500' }
            m = "1000";
        }else if("b".equalsIgnoreCase(m)){
            m = "1500";
        }else if("c".equalsIgnoreCase(m)){
            m = "2000";
        }else if("d".equalsIgnoreCase(m)){
            m = "2500";
        }else if("e".equalsIgnoreCase(m)){
            m = "3000";
        }
        Result result = signatrueService.addSignatrue(memCard, conferenceId, formId, partyB, identityId, courseMatter, courseTime, courseSite, m, bankProvince, bankOfDepositName, bankId, bankName, phone, signImg, isSubmit);
        return result;

    }

}
