package com.srs.web.controller.stureg;

import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.StringUtils;
import com.srs.stureg.domain.CheckPhone;
import com.srs.stureg.domain.CheckRoom;
import com.srs.stureg.domain.SrsStuReg;
import com.srs.stureg.service.ICheckPhoneService;
import com.srs.stureg.service.ISrsStuRegService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stureg/checkphone")
public class CheckPhoneController extends BaseController {
    @Autowired
    private ISrsStuRegService srsStuRegService;

    @Autowired
    private ICheckPhoneService checkPhoneService;

    @GetMapping("list")
    public TableDataInfo list(SrsStuReg srsStuReg){
        startPage();
        List<SrsStuReg> list = srsStuRegService.selectSrsStuRegList(srsStuReg);
        return getDataTable(list);
    }

    /**
     * 获取新生报到学生号码确认详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:reg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(checkPhoneService.selectCheckPhoneById(id));
    }

    //新生考生号获取个人信息
    @PostMapping("/getOwnInfo")
    public AjaxResult getOwnInfo(@RequestParam(value="ksh",required=false) String ksh){
        if(!StringUtils.isNotEmpty(ksh)){
            ksh = getUsername();
        }
        CheckPhone stu = checkPhoneService.getOwnInfoByKsh(ksh);
        if(stu != null){
            String sfz = stu.getSFZH().substring(0,8) + "**********";
            stu.setSFZH(sfz);
            ksh = stu.getKSH().substring(0,4)+"**********";
            stu.setKSH(ksh);
        }
        return AjaxResult.success(stu);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody CheckPhone checkPhone)
    {
        return toAjax(checkPhoneService.updateCheckPhone(checkPhone));
    }
}
