package com.sptg.gateway.controller.estate;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.common.core.constant.SysLogConstant;
import com.sptg.common.core.util.WebUtils;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.common.security.service.SecurityServiceInterface;
import com.sptg.estate.api.constant.EstateSecurityToken;
import com.sptg.estate.api.dto.AccessCardDto;
import com.sptg.estate.api.dto.SimpleUserDto;
import com.sptg.estate.api.dto.UserDto;
import com.sptg.estate.api.entity.*;
import com.sptg.estate.api.feigns.*;
import com.sptg.estate.api.vo.DevicesAccessPushVO;
import com.sptg.permissions.api.entity.Account;
import com.sptg.permissions.api.entity.Organization;
import com.sptg.permissions.api.feigns.ConfFeign;
import com.sptg.permissions.api.feigns.OrgFeign;
import com.sptg.statistics.api.constant.SysLogMenuConstant;
import com.sptg.statistics.api.entity.SysOperationLog;
import com.sptg.statistics.api.feigns.SysOperationLogFeign;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * title: AccessControlController
 * package: com.sptg.gateway.controller.estate
 * description: 出入管理 控制器
 *              含住户 住户人脸 住户卡
 *
 *
 *
 */
@RestController
@RequestMapping("/estate/access")
@RequiredArgsConstructor
public class AccessController {

    private final ConfFeign confFeign;
    private final AccessCardFeign userCardFeign;
    private final UserFeign userFeign;
    private final OrgFeign orgFeign;
    private final UnitFeign unitFeign;
    private final ResidentialFeign residentialFeign;
    private final RoomFeign roomFeign;
    private final SecurityServiceInterface<Account> securityServiceInterface;
    private final SysOperationLogFeign sysOperationLogFeign;
    private final FaceChargeProjectFeign faceChargeProjectFeign;

    /**
     * 功能描述:出入管理页面初始化
     * @return ModelAndView
     *
     *
     */
    @GetMapping("/index")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_MANAGE,format = DataFormatEnum.VIEW)
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("estate/access-manage");
        modelAndView.addObject("fastDfsServer",this.confFeign.getFileServerHost());
        return modelAndView;
    }

    /**
     * 功能描述:住户列表查询
     * @param userDto 住户业务对象（含查询条件）
     * @param page 分页条件
     * @return ResultBean<Page<User>>
     *
     *
     */
    @GetMapping(value = "/showAccessUserList")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_MANAGE,format = DataFormatEnum.JSON)
    public ResultBean<Page<User>> showAccessUserList(UserDto userDto, Page<User> page) {
        //根据树形选择加载数据；如果没有选中ID，则根据当前账号查询
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        Organization userOrg = this.orgFeign.getOrgById(onLineUser.getOrgId());
        if(userDto.getSelectTreeId() == null ||  null == userDto.getSelectTreeType()){
            if(userOrg.getOrgType() == OperationConstant.THREE){
                //物业
                userDto.setEstatePosition(onLineUser.getOrgPosition());
            }else{
                //机构
                userDto.setOrgPosition(onLineUser.getOrgPosition());
            }
        }else{
            //1 机构 2 小区 3社区机构
            Organization organization = this.orgFeign.getOrgById(userDto.getSelectTreeId());
            if(userDto.getSelectTreeType() <= OperationConstant.THREE){
                if(userDto.getSelectTreeType() == OperationConstant.ONE){
                    if (organization.getOrgType() == OperationConstant.THREE){
                        //物业
                        userDto.setEstatePosition(organization.getPosition());
                    }else{
                        //机构
                        userDto.setOrgPosition(organization.getPosition());
                    }
                }else if(userDto.getSelectTreeType() == OperationConstant.TWO){
                    //小区
                    if (userOrg.getOrgType() == OperationConstant.THREE){
                        //物业账号
                        userDto.setEstatePosition(this.residentialFeign.findResidentialById(organization.getId()).getEstatePosition());
                    }else{
                        //机构账号
                        userDto.setOrgPosition(this.residentialFeign.findResidentialById(organization.getId()).getOrgPosition());
                    }
                }
            }
            //4 单元
            if(userDto.getSelectTreeType() == OperationConstant.FOUR){
                if (userOrg.getOrgType() == OperationConstant.THREE){
                    userDto.setEstatePosition(this.unitFeign.findUnitById(userDto.getSelectTreeId()).getEstatePosition());
                }else{
                    userDto.setOrgPosition(this.unitFeign.findUnitById(userDto.getSelectTreeId()).getOrgPosition());
                }
            }
            //5 房间
            if(userDto.getSelectTreeType() == OperationConstant.FIVE){
                if (userOrg.getOrgType() == OperationConstant.THREE){
                    userDto.setEstatePosition(this.roomFeign.findRoomById(userDto.getSelectTreeId()).getEstatePosition());
                }else{
                    userDto.setOrgPosition(this.roomFeign.findRoomById(userDto.getSelectTreeId()).getOrgPosition());
                }
            }
        }
        userDto.setPage(page);
        ResultBean<Page<User>> pageResultBean;
        //门禁卡
        AccessCardDto accessCardDto = new AccessCardDto();
        //判断是否传入卡号和卡有效期
        if (StringUtils.isNotBlank(userDto.getCardNo()) || (userDto.getCardBeginDate() != null && userDto.getCardEndDate() != null)){
            if (userOrg.getOrgType() == OperationConstant.THREE){
                accessCardDto.setEstatePosition(userDto.getEstatePosition());
            }else {
                accessCardDto.setOrgPosition(userDto.getOrgPosition());
            }
            //卡号
            if (StringUtils.isNotBlank(userDto.getCardNo())){
                accessCardDto.setCardNo(userDto.getCardNo());
            }
            //有效期
            if (userDto.getCardBeginDate() != null && userDto.getCardEndDate() != null) {
                accessCardDto.setBeginDate(userDto.getCardBeginDate());
                accessCardDto.setEndDate(userDto.getCardEndDate());
            }
            accessCardDto.setType(OperationConstant.ZERO);
            //获取卡片列表
            List<AccessCard> accessCardList = this.userCardFeign.getListByCardNoAndDate(accessCardDto);
            if (accessCardList.size() > 0){
                List<String> userIds = new ArrayList<>();
                accessCardList.forEach(accessCard -> userIds.add(accessCard.getUserId()));
                userDto.setIds(userIds);
                pageResultBean = this.userFeign.pagingByUserIds(userDto);
            }else {
                pageResultBean = new ResultBean<>(ResultEnum.SUCCESS,page);
            }
        }else {
            pageResultBean = this.userFeign.showUserList(userDto);
        }
        //查询卡信息和检查是否可以下发人脸
        if(pageResultBean!=null&&pageResultBean.getData()!=null){
            Page<User> resultPage=pageResultBean.getData();
            if(null!=resultPage){
                List<User> records = resultPage.getRecords();
                if(null!=records&&!records.isEmpty()){
                    records.forEach(u->{
                        AccessCardDto dto = new AccessCardDto();
                        dto.setUserId(String.valueOf(u.getId()));
                        dto.setType(OperationConstant.ZERO);
                        List<AccessCard> accessCardList = userCardFeign.getAccessCardByUserIdAndType(dto);
                        if(null != accessCardList && !accessCardList.isEmpty()){
                            u.setAccessCard(accessCardList.get(0));
                        }
                        //检查是否可以下发人脸，小区是否设置了人脸套餐
                        List<FaceChargeProject> faceChargeList = faceChargeProjectFeign.getListByResidentialId(u.getResidentialId());
                        if(faceChargeList == null || faceChargeList.size() <= 0){
                            u.setHasFaceCharge(false);
                        }
                        if(u.getImageUri() == null){
                            u.setHasFace(false);
                        }
                    });
                    /*boolean isDelete = false;
                    List<User> deleteList = new ArrayList<>();
                    for (User record : records) {
                        AccessCardDto dto = new AccessCardDto();
                        dto.setUserId(String.valueOf(record.getId()));
                        dto.setType(OperationConstant.ZERO);
                        //判断是否传入卡号和卡有效期
                        if (StringUtils.isNotBlank(userDto.getCardNo())) {
                            dto.setCardNo(userDto.getCardNo());
                            isDelete = true;
                        }
                        if (userDto.getCardBeginDate() != null && userDto.getCardEndDate() != null) {
                            dto.setBeginDate(userDto.getCardBeginDate());
                            dto.setEndDate(userDto.getCardEndDate());
                            isDelete = true;
                        }
                        List<AccessCard> accessCardList = userCardFeign.findAccessCardByCondition(dto);
                        if (null != accessCardList && !accessCardList.isEmpty()) {
                            record.setAccessCard(accessCardList.get(0));
                        } else if (isDelete) {
                            deleteList.add(record);
                        }
                    }
                    if (isDelete){
                        records.removeAll(deleteList);
                    }*/
                }
            }
        }
        return pageResultBean;
    }


    /**
     * 功能描述:出入管理门禁卡设置页面初始化
     * @param id 住户id(必填)
     * @return ModelAndView
     *
     *
     */
    @GetMapping("/indexUserCardSet/{id}")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_CARD_SET,format = DataFormatEnum.VIEW)
    public ModelAndView indexUserCardSet(@PathVariable(value = "id")Long id){
        User user =  this.userFeign.findUserById(id);
        if (null == id || null == user){
            //  没有找到要绑定的住户
            return new ModelAndView("common/404");
        }
        AccessCardDto accessCardDto = new AccessCardDto();
        accessCardDto.setUserId(user.getId().toString());
        accessCardDto.setType(OperationConstant.ZERO);
        List<AccessCard> accessCardList = userCardFeign.getAccessCardByUserIdAndType(accessCardDto);
        if(null != accessCardList && !accessCardList.isEmpty()){
            user.setAccessCard(accessCardList.get(0));
        }
        ModelAndView modelAndView = new ModelAndView("estate/access-user-card-set");
        modelAndView.addObject("user",user);
        return modelAndView;
    }

    /**
     * 功能描述:门禁卡新增或编辑
     * @param accessCardDto 门禁卡业务对象
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/addOrUpdateUserCard")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_CARD_SET,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> addOrUpdateUserCard(AccessCardDto accessCardDto){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        accessCardDto.setType(OperationConstant.ZERO);
        accessCardDto.setCreateAccountId(onLineUser.getId());
        ResultBean<Boolean> resultBean = this.userCardFeign.addOrUpdateUserCard(accessCardDto);
        if(null !=  resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_CARD,SysLogConstant.ALTER_EVENT,
                    WebUtils.getIp(),accessCardDto,onLineUser,accessCardDto);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:门禁卡新增或编辑(只保存卡设置，不下发到设备)
     * @param accessCardDto 门禁卡业务对象
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/simpleAddOrUpdateUserCard")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_CARD_SAVE,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> simpleAddOrUpdateUserCard(AccessCardDto accessCardDto){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        accessCardDto.setType(OperationConstant.ZERO);
        accessCardDto.setCreateAccountId(onLineUser.getId());
        ResultBean<AccessCardDto> resultBean = this.userCardFeign.simpleAddOrUpdateUserCard(accessCardDto);
        ResultBean<Boolean> resultBean1 = null;
        if(null != resultBean.getData()){
            resultBean1 = new ResultBean<>(ResultEnum.SUCCESS, true);
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_CARD,SysLogConstant.ALTER_EVENT,
                    WebUtils.getIp(),accessCardDto,onLineUser,accessCardDto);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }else{
            resultBean1 = new ResultBean<>(ResultEnum.ERROR, false);
        }
        return resultBean1;
    }

    /**
     * 功能描述:执行下发门禁卡（启用或者禁用）
     * @param devicesAccessPushVO 住户门禁卡下发设备对象
     * @return ResultBean<Boolean>
     */
    @PostMapping("/sendUserCard")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_CARD_SEND,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> sendUserCard(DevicesAccessPushVO devicesAccessPushVO){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        ResultBean<Boolean> resultBean =this.userCardFeign.sendAccessUserCard(devicesAccessPushVO);
        if(null !=  resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_CARD,SysLogConstant.ALTER_EVENT,
                    WebUtils.getIp(),devicesAccessPushVO,onLineUser,devicesAccessPushVO);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:添加或修改(含删除)特殊门禁开门权限
     * @param devicesAccessPushVO
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping(value = "/accessDevicesManualPush")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_SPECIAL_PUSH,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> accessDevicesManualPush(DevicesAccessPushVO devicesAccessPushVO){
        //登陆用户
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        Long userId = devicesAccessPushVO.getUserId();
        Integer pushMaterial = devicesAccessPushVO.getPushMaterial();
        Integer pushType = devicesAccessPushVO.getPushType();
        Integer operType = devicesAccessPushVO.getOperType();
        List<Long> deviceIdList = devicesAccessPushVO.getDeviceIdList();
        //如果是特殊授权下发时，必须传入下发的设备，其他情况，通过获取已下发过的设备即可。
        if(operType.equals(OperationConstant.ONE)){
            if(userId == null || pushMaterial == null || pushType == null || deviceIdList == null || deviceIdList.size() <= 0){
                return new ResultBean<>(ResultEnum.PARAMETER_ANOMALY);
            }
        }else if(userId == null){
            return new ResultBean<>(ResultEnum.PARAMETER_ANOMALY);
        }
        devicesAccessPushVO.setOnLineUser(onLineUser);
        ResultBean<Boolean> resultBean = userFeign.accessDevicesManualPush(devicesAccessPushVO);
        Boolean result=resultBean.getData();
        if(result!=null&&result){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            String message="添加/修改用户特殊开门权限";
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_MANAGE, SysLogConstant.ALTER_EVENT,
                    WebUtils.getIp(),message,devicesAccessPushVO,onLineUser,devicesAccessPushVO);
            sysOperationLogFeign.info(sysOperationLog);
            /*-------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:出入管理住户人脸页面初始化
     * @param id 住户id 必填
     *
     *
     * @return ModelAndView
     */
    @GetMapping("/indexUserFaceSet/{id}")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_FACE_IMAGE_SET,format = DataFormatEnum.VIEW)
    public ModelAndView indexUserFaceSet(@PathVariable(value = "id")Long id){
        User user =  this.userFeign.findUserById(id);
        if (null == id || null == user){
            //  没有找到要绑定的住户
            return new ModelAndView("common/404");
        }
        ModelAndView modelAndView = new ModelAndView("estate/access-user-face-set");
        modelAndView.addObject("user",user);
        modelAndView.addObject("fastDfsServer",this.confFeign.getFileServerHost());
        return modelAndView;
    }

    /**
     * 功能描述:添加或修改（含删除）住户人脸图片（同时下发人脸到全部设备）
     * @param userDto 住户人脸业务对象
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/addOrUpdateUserFaceImage")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_FACE_IMAGE_SET,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> addOrUpdateUserFaceImage(UserDto userDto){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        userDto.setCreateId(onLineUser.getId());
        ResultBean<Boolean> resultBean=this.userFeign.addOrUpdateUserFaceImage(userDto);
        if(null!= resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_USER_FACE,SysLogConstant.ALTER_EVENT,
                    WebUtils.getIp(),"添加/更新住户人脸操作",userDto,onLineUser,userDto);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:仅添加或修改（含删除）住户人脸图片（但不下发人脸）
     * @param userDto 住户人脸业务对象
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/simpleAddOrUpdateUserFaceImage")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_FACE_IMAGE_SAVE,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> simpleAddOrUpdateUserFaceImage(UserDto userDto){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        userDto.setCreateId(onLineUser.getId());
        ResultBean<Boolean> resultBean=this.userFeign.simpleAddOrUpdateUserFaceImage(userDto);
        if(null!= resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_USER_FACE,SysLogConstant.ALTER_EVENT,
                    WebUtils.getIp(),"添加/更新住户人脸图片操作",userDto,onLineUser,userDto);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:执行下发人脸（启用或者禁用）
     * @param devicesAccessPushVO 住户人脸下发设备对象
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/sendUserFaceImage")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_FACE_IMAGE_SEND,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> sendUserFaceImage(DevicesAccessPushVO devicesAccessPushVO){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        UserDto userDto = new UserDto();
        userDto.setId(devicesAccessPushVO.getUserId());
        userDto.setCreateId(onLineUser.getId());
        userDto.setDevicesAccessPushVO(devicesAccessPushVO);
        ResultBean<Boolean> resultBean=this.userFeign.sendUserFaceImage(userDto);
        if(null!= resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_USER_FACE,SysLogConstant.ALTER_EVENT,
                    WebUtils.getIp(),"启用/禁用住户人脸操作",userDto,onLineUser,devicesAccessPushVO);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:批量下发禁用人脸指令
     * @param ids 住户ids
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/deleteUserFaceImageBatch")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_FACE_DELETE_BATCH,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> deleteUserFaceImageBatch(@RequestBody List<String> ids){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        ResultBean<Boolean> resultBean=this.userFeign.deleteUserFaceImageBatch(ids);
        if(null!= resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_USER_FACE,SysLogConstant.DELETE_EVENT,
                    WebUtils.getIp(),"启用/禁用住户人脸操作", ids, onLineUser);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:批量设置并下发人脸
     * @param simpleUserDtoList 住户信息集
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/issueUserFaceImageBatch")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_FACE_ISSUE_BATCH,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> issueUserFaceImageBatch(@RequestBody List<SimpleUserDto> simpleUserDtoList){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        Assert.notEmpty(simpleUserDtoList, "批量住户信息不能为空");
        ResultBean<Boolean> resultBean = this.userFeign.issueUserFaceImageBatch(simpleUserDtoList);
        if(null!= resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog = new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_USER_FACE,SysLogConstant.DELETE_EVENT,
                    WebUtils.getIp(),"批量启用住户人脸操作", simpleUserDtoList, onLineUser);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:批量下发禁用门禁卡指令
     * @param ids 住户ids
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/deleteUserCardBatch")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_CARD_DELETE_BATCH,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> deleteUserCardBatch(@RequestBody List<String> ids){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        ResultBean<Boolean> resultBean = this.userFeign.deleteUserCardBatch(ids);
        if(null!= resultBean.getData() && resultBean.getData()){
            /*---------------------------------------------------记录日志--------------------------------------------------------*/
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_CARD,SysLogConstant.DELETE_EVENT,
                    WebUtils.getIp(),"批量禁用住户门禁卡操作", ids, onLineUser);
            sysOperationLogFeign.info(sysOperationLog);
            /*------------------------------------------------------------------------------------------------------------------*/
        }
        return resultBean;
    }

    /**
     * 功能描述:批量下发启用门禁卡指令
     * @param ids 住户ids
     * @return ResultBean<Boolean>
     *
     *
     */
    @PostMapping("/enableUserCardBatch")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_CARD_ENABLE_BATCH,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> enableUserCardBatch(@RequestBody List<String> ids){
        Account onLineUser = this.securityServiceInterface.getOnLineUser();
        ResultBean<Boolean> resultBean = this.userFeign.enableUserCardBatch(ids);
        if(null!= resultBean.getData() && resultBean.getData()){
            SysOperationLog sysOperationLog=new SysOperationLog(SysLogMenuConstant.ESTATE_ACCESS_CARD,SysLogConstant.ADD_EVENT,
                    WebUtils.getIp(),"批量启用住户门禁卡操作", ids, onLineUser);
            sysOperationLogFeign.info(sysOperationLog);
        }
        return resultBean;
    }
/**
     * 功能描述:用户特殊门禁权限页面初始化
     * @return ModelAndView
     *
     *
     */


    @GetMapping(value = "/specialOpenPermissionSet/{id}/{residentialId}")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_SPECIAL_PUSH,format = DataFormatEnum.VIEW)
    public ModelAndView specialOpenPermissionSet(@PathVariable(value = "id") long id, @PathVariable Long residentialId){
        User user = this.userFeign.findUserById(id);
        Assert.notNull(user,"用户不存在");
        AccessCardDto dto = new AccessCardDto();
        dto.setUserId(String.valueOf(id));
        dto.setType(OperationConstant.ZERO);
        dto.setCardEnable(OperationConstant.ONE);
        List<AccessCard> accessCards = userCardFeign.getAccessCardByUserIdAndType(dto);
//        Assert.notEmpty(accessCard, "用户门禁卡信息不存在");
        String url = "estate/access-devices-manual-push";
        ModelAndView modelAndView = new ModelAndView(url);
        modelAndView.addObject("user",user);
        modelAndView.addObject("userType", OperationConstant.ZERO); //住户特殊开门权限
        if(accessCards != null && accessCards.size() > 0){
            modelAndView.addObject("card",accessCards.get(0));
        }
        return modelAndView;
    }

    /**
     * 功能描述:导入住户卡
     * @param flag 5 住户卡
     * @return ModelAndView
     *
     *
     */
    @RequestMapping(value = "/indexImportExcel/{flag}")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_IMPORT,format = DataFormatEnum.VIEW)
    public ModelAndView indexImportExcel(@PathVariable(value = "flag")String flag) {
        if (null == flag){
            return new ModelAndView("common/404");
        }
        ModelAndView modelAndView = new ModelAndView("common/import-excel");
        modelAndView.addObject("flag",flag);
        return modelAndView;
    }

    /**
     * 功能描述:导出住户出入管理
     * @param response
     *
     *
     */
    @RequestMapping(value = "/exportUserAccess")
    @Security(token = EstateSecurityToken.ESTATE_ACCESS_EXPORT)
    public void exportUserAccess(HttpServletResponse response) {
        try {
            response.sendRedirect("/common/excel/exportExcel/8");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
