package com.hys.app.controller.erp.use;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.framework.exception.ServiceException;
import com.hys.app.model.erp.dos.MsgCompanyConfig;
import com.hys.app.model.erp.dto.IdsDto;
import com.hys.app.model.erp.dto.MsgConfigDTO;
import com.hys.app.model.erp.entity.Company;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.CompanyManager;
import com.hys.app.service.erp.MsgCompanyManager;
import com.hys.app.service.erp.MsgConfigManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "消息配置")
@RestController
@RequestMapping("/admin/erp/msgConfig")
@AllArgsConstructor
public class MsgCompanyController {

    private MsgCompanyManager msgCompanyManager;

    @PostMapping("bandMsg")
    @ApiOperation(value = "公司绑定模板")
    @Log(client = LogClient.admin, detail = "[${msgConfigDTO.title}]的消息")
    public void bandMsg(@Valid @RequestBody IdsDto idsDto) {
        msgCompanyManager.bandMsg(idsDto);
    }

    @GetMapping("getBandAllMsg")
    @ApiOperation(value = "获取公司绑定的所有模板")
    public List<MsgCompanyConfig> getAllMsg() {
        return msgCompanyManager.list(new LambdaQueryWrapper<MsgCompanyConfig>().eq(MsgCompanyConfig::getCompanyId, AdminUserContext.getCompanyId()));
    }
}
