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

import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.metting.model.MettingRecordEntity;
import com.mortals.xhx.module.metting.service.MettingRecordService;
import com.mortals.xhx.module.room.model.RoomQuery;
import com.mortals.xhx.module.room.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 会议记录
 *
 * @author zxfei
 * @date 2023-05-22
 */
@RestController
@RequestMapping("metting/record")
public class MettingRecordController extends BaseCRUDJsonBodyMappingController<MettingRecordService, MettingRecordEntity, Long> {

    @Autowired
    private ParamService paramService;
    @Autowired
    private RoomService roomService;


    public MettingRecordController() {
        super.setModuleDesc("会议记录");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        this.addDict(model, "meetStatus", paramService.getParamBySecondOrganize("MettingRecord", "meetStatus"));
        this.addDict(model, "finishMethod", paramService.getParamBySecondOrganize("MettingRecord", "finishMethod"));

        this.addDict(model, "roomId", roomService.find(new RoomQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getRoomName(), (o, n) -> n)));
        super.init(model, context);
    }

    @Override
    protected void doListBefore(MettingRecordEntity query, Map<String, Object> model, Context context) throws AppException {
        super.doListBefore(query, model, context);
        query.setOrderColList(Arrays.asList(new OrderCol("createTime", OrderCol.DESCENDING)));
    }
}