# GuestComplaintServiceImpl.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.cons.endofshift.EndOfShiftCons;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftComplaintRequest;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftReportInfo;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftGuestComplaintDTO;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftInfoDTO;
    import cloud.wconnect.frontoffice.pojo.query.ShiftQuery;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftComplaintRequestService;
    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;

    /**
     * Guest complaint 区域service
     *
     * @author lichen
     * @date 2025/6/19
     */
    @Service
    @DS("ratelog_manage")
    public class GuestComplaintServiceImpl implements IEosSave, IEosDelete, IEosSearch {

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

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

        /**
         * 删除排班信息（指定资产指定日期指定排班配置）指定区域数据
         *
         * @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) {
            //校验Guest Complaint是否存在且属于资产
            shiftComplaintRequestService.checkIsExistAndAffiliation(id, propertyId);
            //根据主键删除Digital Check In 数据
            shiftComplaintRequestService.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) {
            ShiftGuestComplaintDTO shiftGuestComplaintDTO = (ShiftGuestComplaintDTO) object;
            if (Objects.nonNull(shiftGuestComplaintDTO.getId())) {
                //校验Guest Complaint是否存在且属于资产
                shiftComplaintRequestService.checkIsExistAndAffiliation(shiftGuestComplaintDTO.getId(), propertyId);
            }

            //更新为可发送
            shiftReportInfoService.updateCanSend(shiftReportInfo.getId(), true);
            //操作时间
            long operatorTime = DateTimeUtils.nowTimestamp();

            // 组装更新数据
            ShiftComplaintRequest shiftComplaintRequest = beanMapper.map(shiftGuestComplaintDTO, ShiftComplaintRequest.class);
            shiftComplaintRequest.setType(EndOfShiftCons.SHIFT_COMPLAINT_TYPE);
            shiftComplaintRequest.setOperateUid(loginUserId);
            shiftComplaintRequest.setOperateTime(operatorTime);
            if (Objects.nonNull(shiftGuestComplaintDTO.getId())) {
                //修改
                shiftComplaintRequestService.updateById(shiftComplaintRequest);
            } else {
                //新增
                shiftComplaintRequest.setPropertyId(propertyId);
                shiftComplaintRequest.setShiftId(shiftReportInfo.getId());
                shiftComplaintRequestService.save(shiftComplaintRequest);
            }
        }

        /**
         * 条件查询排班信息
         *
         * @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) {
            //根据关键字查询Guest complaint数据
            List<ShiftComplaintRequest> shiftComplaintRequestList = shiftComplaintRequestService.list(new LambdaQueryWrapper<ShiftComplaintRequest>()
                    .select(ShiftComplaintRequest::getShiftId)
                    .eq(ShiftComplaintRequest::getPropertyId, propertyId)
                    .like(ShiftComplaintRequest::getCustomer, shiftQuery.getKeyword()));
            if (CollectionUtils.isEmpty(shiftComplaintRequestList)) {
                return new ListPagedDTO<>();
            }

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

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