package com.zcloud.primeport.web;


import com.zcloud.primeport.api.MkmjSwipeCardRecordServiceI;
import com.zcloud.primeport.dto.MkmjSwipeCardRecordAddCmd;
import com.zcloud.primeport.dto.MkmjSwipeCardRecordPageQry;
import com.zcloud.primeport.dto.MkmjSwipeCardRecordUpdateCmd;
import com.zcloud.primeport.dto.clientobject.MkmjSwipeCardRecordCO;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.primeport.dto.mjDock.SwipeRecordPushExtend;
import com.zcloud.primeport.dto.mjDock.SwipeRecordPushInfo;
import com.zcloud.primeport.dto.mjDock.SwipeRecordPushVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * web-adapter
 *
 * @Author dearLin
 * @Date 2026-04-22 17:04:00
 */
@Api(tags = "")
@RequestMapping("/${application.gateway}/mkmjSwipeCardRecord")
@RestController
@AllArgsConstructor
public class MkmjSwipeCardRecordController {
    private final MkmjSwipeCardRecordServiceI mkmjSwipeCardRecordService;

    @ApiOperation("新增")
    @PostMapping("/dockSave")
    public SingleResponse dockSave(@Validated @RequestBody SwipeRecordPushVo cmd) {
        SwipeRecordPushInfo info = cmd.getInfo();
        SwipeRecordPushExtend extend = info.getExtend();
        MkmjSwipeCardRecordAddCmd cardRecordEntity = new MkmjSwipeCardRecordAddCmd();
        cardRecordEntity
                .setNodeCode(info.getNodeCode()).setAlarmCode(info.getAlarmCode()).setAlarmPicture(info.getAlarmPicture())
                .setNodeType(info.getNodeType()).setAlarmDate(info.getAlarmDate()).setAlarmGrade(info.getAlarmGrade())
                .setUnitType(info.getUnitType()).setAlarmType(info.getAlarmType()).setChannelSeq(info.getChannelSeq())
                .setChannelName(info.getChannelName()).setAlarmStat(info.getAlarmStat()).setDeptName(extend.getDeptName())
                .setAcsChannelCode(extend.getAcsChannelCode()).setMaskState(extend.getMaskState()).setEnterOrExit(extend.getEnterOrExit())
                .setOpenTypeStr(extend.getOpenTypeStr()).setSwingTime(extend.getSwingTime()).setDeviceName(extend.getDeviceName())
                .setPersonCode(extend.getPersonCode()).setOpenType(extend.getOpenType()).setOrgCode(extend.getOrgCode())
                .setPaperType(extend.getPaperType()).setPaperNumber(extend.getPaperNumber()).setErrorDetail(extend.getErrorDetail())
                .setOpenFailedCod(extend.getOpenFailedCode()).setExtendId(extend.getId()).setBeginTime(extend.getBeginTime())
                .setAcsChannelName(extend.getAcsChannelName()).setCardStatus(extend.getCardStatus()).setOrgName(extend.getOrgName())
                .setSex(extend.getSex()).setDeptId(extend.getDeptId()).setCardType(extend.getCardType()).setDeviceCode(extend.getDeviceCode())
                .setPersonName(extend.getPersonName()).setPersonImg(extend.getPersonImg()).setOpenResult(extend.getOpenResult())
                .setPersonId(extend.getPersonId()).setRecordImage1(extend.getRecordImage1()).setCategory(extend.getCategory())
                .setCardNumber(extend.getCardNumber()).setRfidType(extend.getRfidType()).setAge(extend.getAge()).setVRecordFlag(extend.getVRecordFlag());

        return mkmjSwipeCardRecordService.add(cardRecordEntity);
//        return SingleResponse.buildSuccess();
    }


    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<MkmjSwipeCardRecordCO> add(@Validated @RequestBody MkmjSwipeCardRecordAddCmd cmd) {
        return mkmjSwipeCardRecordService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<MkmjSwipeCardRecordCO> page(@RequestBody MkmjSwipeCardRecordPageQry qry) {
        return mkmjSwipeCardRecordService.listPage(qry);
    }


    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<MkmjSwipeCardRecordCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(mkmjSwipeCardRecordService.queryById(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Response remove(@PathVariable("id") Long id) {
        mkmjSwipeCardRecordService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam("ids") String ids) {
        List<Long> idsList = Arrays.stream(ids.split(","))
                .map(Long::valueOf)
                .collect(Collectors.toList());
        mkmjSwipeCardRecordService.removeBatch(idsList);
        return SingleResponse.buildSuccess();
    }
//
//    @ApiOperation("修改")
//    @PutMapping("/edit")
//    public SingleResponse edit(@Validated @RequestBody MkmjSwipeCardRecordUpdateCmd mkmjSwipeCardRecordUpdateCmd) {
//        mkmjSwipeCardRecordService.edit(mkmjSwipeCardRecordUpdateCmd);
//        return SingleResponse.buildSuccess();
//    }
}

