# DigitalCheckInAreaServiceImpl.java

    package cloud.wconnect.frontoffice.service.endofshift.area.impl;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.frontoffice.cons.endofshift.EndOfShiftAreaEnum;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftDigitalCheckIn;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftReportInfo;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftDigitalCheckInDTO;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftInfoDTO;
    import cloud.wconnect.frontoffice.pojo.query.ShiftQuery;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftDigitalCheckInService;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftReportInfoService;
    import cloud.wconnect.frontoffice.service.endofshift.area.IEosDelete;
    import cloud.wconnect.frontoffice.service.endofshift.area.IEosSave;
    import cloud.wconnect.frontoffice.service.endofshift.area.IEosSearch;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.List;
    import java.util.Objects;
    import java.util.stream.Collectors;

    /**
     * Digital check-in 区域service
     *
     * @author lichen
     * @date 2025/6/19
     */
    @Service
    @DS("ratelog_manage")
    public class DigitalCheckInAreaServiceImpl implements IEosSave, IEosDelete, IEosSearch {

        /**
         * 区域类型
         */
        public static final int DIGITAL_CHECK_IN = EndOfShiftAreaEnum.DIGITAL_CHECK_IN.getAreaId();
        @Autowired
        private IShiftReportInfoService shiftReportInfoService;
        @Autowired
        private BeanMapper beanMapper;
        @Autowired
        private IShiftDigitalCheckInService shiftDigitalCheckInService;

        /**
         * 用于判断是否支持子类执行方法
         *
         * @param type 类型
         * @return java.lang.Boolean
         * @author lichen
         * @date 2025/6/19
         */
        @Override
        public boolean support(Integer type) {
            return type == DIGITAL_CHECK_IN;
        }

        /**
         * 删除排班信息（指定资产指定日期指定排班配置）指定区域数据
         *
         * @param propertyId      资产id
         * @param shiftReportInfo 排班基础信息
         * @param id              区域的主键id
         * @return void
         * @author lichen
         * @date 2025/6/19
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void delete(Integer propertyId, ShiftReportInfo shiftReportInfo, Integer id) {
            //校验是否存在，是否归属于当前资产
            shiftDigitalCheckInService.checkIsExistAndAffiliation(id, propertyId);
            //根据主键删除Digital Check In数据
            shiftDigitalCheckInService.removeById(id);
            //更新为已发送
            shiftReportInfoService.updateCanSend(shiftReportInfo.getId(), true);
        }

        /**
         * 保存排班信息（指定资产指定日期指定排班配置）指定区域的数据
         *
         * @param propertyId      属性ID
         * @param shiftReportInfo 排班基础信息
         * @param object          保存的区域对象
         * @param loginUserId     登录用户id
         * @return void
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void save(Integer propertyId, ShiftReportInfo shiftReportInfo, Object object, int loginUserId) {
            ShiftDigitalCheckInDTO shiftDigitalCheckInDTO = (ShiftDigitalCheckInDTO) object;
            Integer id = shiftDigitalCheckInDTO.getId();
            if (Objects.nonNull(id)) {
                //校验是否存在，是否归属于当前资产
                shiftDigitalCheckInService.checkIsExistAndAffiliation(id, propertyId);
            }

            //更新为可发送邮件
            shiftReportInfoService.updateCanSend(shiftReportInfo.getId(), true);

            ShiftDigitalCheckIn shiftDigitalCheckIn = beanMapper.map((ShiftDigitalCheckInDTO) object, ShiftDigitalCheckIn.class);
            shiftDigitalCheckIn.setOperateUid(loginUserId);
            shiftDigitalCheckIn.setOperateTime(DateTimeUtils.nowTimestamp());
            if (Objects.nonNull(id)) {
                //修改
                shiftDigitalCheckInService.updateById(shiftDigitalCheckIn);
            } else {
                //新增
                shiftDigitalCheckIn.setPropertyId(propertyId);
                shiftDigitalCheckIn.setShiftId(shiftReportInfo.getId());
                shiftDigitalCheckInService.save(shiftDigitalCheckIn);
            }
        }

        /**
         * 条件查询排班信息
         *
         * @param propertyId 资产id
         * @param shiftQuery 查询条件
         * @return cloud.wconnect.commonlib.pojo.dto.ListPagedDTO<cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftInfoDTO>
         * @author lichen
         * @date 2025/6/19
         */
        @Override
        public ListPagedDTO<ShiftInfoDTO> searchList(Integer propertyId, ShiftQuery shiftQuery) {
            //根据关键字查询Digital check-in
            List<ShiftDigitalCheckIn> shiftDigitalCheckInList = shiftDigitalCheckInService.list(new LambdaQueryWrapper<ShiftDigitalCheckIn>()
                    .select(ShiftDigitalCheckIn::getShiftId)
                    .eq(ShiftDigitalCheckIn::getPropertyId, propertyId)
                    .like(ShiftDigitalCheckIn::getCustomer, shiftQuery.getKeyword()));

            if (CollectionUtils.isEmpty(shiftDigitalCheckInList)) {
                return new ListPagedDTO<>();
            }

            //分页查询排班信息
            Page<ShiftReportInfo> shiftReportInfoPage = shiftReportInfoService.pageByIds(shiftQuery.getPage(), shiftQuery.getSize(),
                    shiftDigitalCheckInList.stream().map(ShiftDigitalCheckIn::getShiftId).collect(Collectors.toSet()));

            ListPagedDTO<ShiftInfoDTO> result = new ListPagedDTO<>();
            result.setList(beanMapper.mapList(shiftReportInfoPage.getRecords(), ShiftInfoDTO.class));
            result.setTotal(shiftReportInfoPage.getTotal());
            return result;
        }
    }