package com.mortals.xhx.module.device.web;

import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.device.model.DeviceModuleUseEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceModuleUseService;
import com.mortals.xhx.module.device.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.stream.Collectors;
/**
*
* 设备模块使用频率
*
* @author zxfei
* @date 2022-07-02
*/
@RestController
@RequestMapping("device/module/use")
public class DeviceModuleUseController extends BaseCRUDJsonBodyMappingController<DeviceModuleUseService,DeviceModuleUseEntity,Long> {

    @Autowired
    private ParamService paramService;
    @Autowired
    private DeviceService deviceService;

    public DeviceModuleUseController(){
        super.setModuleDesc( "设备模块使用频率");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        this.addDict(model, "deviceId", deviceService.find(new DeviceQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getDeviceName())));
        super.init(model, context);
    }

    @Override
    @UnAuth
    public Rest<Object> list(DeviceModuleUseEntity query) {
        return super.list(query);
    }

    @Override
    @UnAuth
    public String info(Long id) {
        return super.info(id);
    }
}