# PassOnAreaServiceImpl.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.commonlib.util.JsonUtils;
    import cloud.wconnect.frontoffice.cons.endofshift.EndOfShiftAreaEnum;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftOperationRecord;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftReportInfo;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftInfoDTO;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftPassOnDTO;
    import cloud.wconnect.frontoffice.pojo.query.ShiftQuery;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftOperationRecordService;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftReportInfoService;
    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.core.conditions.update.LambdaUpdateWrapper;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    /**
     * Pass on 区域service
     *
     * @author lichen
     * @date 2025/6/19
     */
    @Service
    @DS("ratelog_manage")
    public class PassOnAreaServiceImpl implements IEosSave, IEosSearch {

        /**
         * 区域类型
         */
        public static final int PASS_ON = EndOfShiftAreaEnum.PASS_ON.getAreaId();
        @Autowired
        private IShiftReportInfoService shiftReportInfoService;
        @Autowired
        private IShiftOperationRecordService shiftOperationRecordService;
        @Autowired
        private ObjectMapper objectMapper;
        @Autowired
        private BeanMapper beanMapper;

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

        /**
         * 保存排班信息（指定资产指定日期指定排班配置）指定区域的数据
         *
         * @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) {
            int shiftReportInfoId = shiftReportInfo.getId();
            //当前时间
            long operatorTime = DateTimeUtils.nowTimestamp();

            //更新的wrapper
            LambdaUpdateWrapper<ShiftReportInfo> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(ShiftReportInfo::getId, shiftReportInfoId);
            updateWrapper.set(ShiftReportInfo::getOperateUid, loginUserId);
            updateWrapper.set(ShiftReportInfo::getOperateTime, operatorTime);
            updateWrapper.set(ShiftReportInfo::getCanSend, true);

            ShiftPassOnDTO shiftPassOnDTO = (ShiftPassOnDTO) object;
            shiftPassOnDTO.setUid(loginUserId);
            shiftPassOnDTO.setUpdateTime(operatorTime);
            updateWrapper.set(ShiftReportInfo::getPassOnJson, JsonUtils.convertObjToString(objectMapper, shiftPassOnDTO));
            shiftReportInfoService.update(updateWrapper);

            //插入操作记录
            ShiftOperationRecord shiftOperationRecord = ShiftOperationRecord.builder()
                    .propertyId(propertyId)
                    .shiftId(shiftReportInfoId)
                    .operationType(PASS_ON)
                    .operationBy(loginUserId)
                    .operationTime(operatorTime)
                    .build();
            shiftOperationRecordService.save(shiftOperationRecord);
        }

        /**
         * 条件查询排班信息
         *
         * @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) {
            Page<ShiftReportInfo> shiftReportInfoPage = shiftReportInfoService.page(new Page<>(shiftQuery.getPage(), shiftQuery.getSize()),
                    new LambdaQueryWrapper<ShiftReportInfo>()
                            .eq(ShiftReportInfo::getPropertyId, propertyId)
                            .like(ShiftReportInfo::getPassOnJson, shiftQuery.getKeyword())
                            .orderByDesc(ShiftReportInfo::getTargetDate)
                            .orderByDesc(ShiftReportInfo::getShift));
            long total = shiftReportInfoPage.getTotal();
            if (total == 0) {
                return new ListPagedDTO<>();
            } else {
                ListPagedDTO<ShiftInfoDTO> result = new ListPagedDTO<>();
                result.setList(beanMapper.mapList(shiftReportInfoPage.getRecords(), ShiftInfoDTO.class));
                result.setTotal(total);
                return result;
            }
        }
    }