# HKEfficiencyWidgetController.java

    package cloud.wconnect.workperformance.controller.hkefficiency;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ForbiddenException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.workperformance.pojo.dto.hkefficiency.widget.HkEfficiencyAverageHoursDTO;
    import cloud.wconnect.workperformance.pojo.query.hkefficiency.HkEfficiencyAverageHoursQuery;
    import cloud.wconnect.workperformance.service.hkefficiency.IHkEfficiencyWidgetService;
    import com.google.common.collect.Sets;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    import java.util.List;

    /**
     * Controller: Widget
     *
     * @author zc
     * @date 2023/12/08
     */
    @RestController
    @RequestMapping("/housekeeping-efficiency/widget")
    public class HKEfficiencyWidgetController {
        @Resource
        private IHkEfficiencyWidgetService widgetService;
        @Resource
        private PropertyI18nRedisService propertyI18nRedisService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 获取单间房平均耗时数据
         *
         * @param query 查询条件
         * @return HousekeepingEfficiencyAverageHoursDTO 集合
         * @author zc
         * @date 2023/12/8
         */
        @ApiId(980)
        @GetMapping("/average-hours")
        public List<HkEfficiencyAverageHoursDTO> listAverageHours(@Valid HkEfficiencyAverageHoursQuery query) {
            if (!Sets.newHashSet(sessionContext.getPropertyIds()).containsAll(query.getPropertyIds())) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(),
                        "Cannot be operated others property data; propertyIds: " + query.getPropertyIds());
            }
            List<PropertyDTO> propertyDTOList = propertyI18nRedisService.list(query.getPropertyIds());
            return widgetService.listAverageHours(propertyDTOList, query);
        }
    }