package com.bjtdba.userCenter.controller;


import com.bjtdba.entity.userCenter.UserDisabledCertificate;
import com.bjtdba.userCenter.service.UserDisabledCertificateService;
import com.bjtdba.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 残疾认证表(UserDisabledCertificate)表控制层
 *
 * @author 何海强
 * @since 2022-11-17 14:16:42
 */
@RestController
@RequestMapping("userCenter_service/userDisabledCertificate")
public class UserDisabledCertificateController {
    /**
     * 服务对象
     */
    @Resource
    private UserDisabledCertificateService userDisabledCertificateService;

    /**
     * 残疾人报名认证
     */
    @PostMapping("/add")
    public Object addLike(@RequestHeader Map<String,String> Hmap, @RequestBody Map<String,String> map) {

        if (!Hmap.containsKey("uid")) {
            return ResponseUtil.fail("uid 参数错误");
        }

        if (!map.containsKey("user_name")||!map.containsKey("user_card")||!map.containsKey("disabled")) {
            return ResponseUtil.fail("参数错误");
        }
        String username = map.get("user_name");
        String user_card = map.get("user_card");
        String disabled = map.get("disabled");
        Integer uid = Integer.parseInt(Hmap.get("uid"));

        UserDisabledCertificate queryParm=new UserDisabledCertificate();
        queryParm.setUser_name(username);
        queryParm.setDisabled(disabled);
        queryParm.setUser_card(user_card);

        List<UserDisabledCertificate> userDisabledCertificateList=userDisabledCertificateService.queryList(queryParm);
        if(userDisabledCertificateList!=null&&userDisabledCertificateList.size()!=0){
            UserDisabledCertificate resObj=userDisabledCertificateList.get(0);
            UserDisabledCertificate updateObj=new UserDisabledCertificate();
            updateObj.setId(resObj.getId());
            updateObj.setUid(uid);
            userDisabledCertificateService.update(updateObj);
            return ResponseUtil.ok();

        }else {
            return ResponseUtil.fail("填写信息错误，认证失败");
        }

    }


    @GetMapping("/getUserDisabled")
    public  Object getUserDisabled(@RequestHeader Map<String,String> Hmap){
        if (!Hmap.containsKey("uid")) {
            return ResponseUtil.fail("uid 参数错误");
        }

        Integer uid = Integer.parseInt(Hmap.get("uid"));

        UserDisabledCertificate queryParm=new UserDisabledCertificate();
        queryParm.setUid(uid);

        List<UserDisabledCertificate> userDisabledCertificateList=userDisabledCertificateService.queryList(queryParm);
        if(userDisabledCertificateList!=null&&userDisabledCertificateList.size()!=0){
            UserDisabledCertificate resObj=userDisabledCertificateList.get(0);

            return ResponseUtil.ok(resObj);

        }else {
            return ResponseUtil.fail("您暂未认证，请认证！");
        }
    }

}

