package com.yida.data.device.studentCard.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.card.EduStudentCardPhone;
import com.yida.data.common.core.entity.system.enums.OperationLogTypeEnum;
import com.yida.data.device.studentCard.service.EduStudentCardPhoneService;
import com.yida.data.log.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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;


/**
 * 电子学生证关联电话 Controller
 *
 * @author zhanghaijun
 * @date 2021-08-05 09:52:38
 */
@Slf4j
@Api(tags = "学生证-电话管理")
@Validated
@RestController
@RequestMapping("/studentCard/cardPhone")
@RequiredArgsConstructor
public class EduStudentCardPhoneController {

    private final EduStudentCardPhoneService eduStudentCardPhoneService;


    @ApiOperation("查询学生证电话")
    @GetMapping("/getFamilyPhone")
    public ResultBean getFamilyPhone(@ApiParam("iMei号") @RequestParam String imei,
        @ApiParam("1是亲情电话，2是sos电话，3是通话白名单") @RequestParam Integer type) {
        List<EduStudentCardPhone> list = eduStudentCardPhoneService.list(Wrappers.lambdaQuery(new EduStudentCardPhone())
            .eq(EduStudentCardPhone::getImei, imei).eq(EduStudentCardPhone::getType, type));
        return ResultBean.buildSuccess(list);
    }


    @ApiOperation("保存电话")
    @PostMapping("/savePhone")
    @OperationLog(module = ModuleName.TELEPHONE, methods = "保存电话", type = OperationLogTypeEnum.SAVE)
    public ResultBean savePhone(@RequestBody EduStudentCardPhone phone) {
        eduStudentCardPhoneService.savePhone(phone);
        return ResultBean.buildSuccess();
    }


    @ApiOperation("通用删除电话")
    @GetMapping("/delPhone")
    @OperationLog(module = ModuleName.TELEPHONE, methods = "通用删除电话", type = OperationLogTypeEnum.DELETE)
    public ResultBean delPhone(@RequestParam Long id) {
        eduStudentCardPhoneService.delPhone(id);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("批量修改电话")
    @PostMapping("/updateFamilyPhoneBatch")
    @OperationLog(module = ModuleName.TELEPHONE, methods = "批量修改电话", type = OperationLogTypeEnum.UPDATE)
    public ResultBean updateFamilyPhoneBatch(@RequestBody List<EduStudentCardPhone> phones,
        @ApiParam("1-亲情电话，2-sos，3-白名单") Integer type, String imei) {
        eduStudentCardPhoneService.updatePhoneBatch(phones, type, imei);
        return ResultBean.buildSuccess();
    }

}
