package com.zjrs.zwnw.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import org.mohrss.leaf.core.framework.web.exception.AppException;
import com.zjrs.zwnw.portal.bpo.DhyyBPO;
import com.zjrs.zwnw.portal.dto.ChangeUseAppDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

@Api("管理")
@RestController
@RequestMapping("/api/portal/dhyy")
public class DhyyController {
    private static final Logger LOG = LoggerFactory.getLogger(DhyyController.class);

    @Resource
    private DhyyBPO dhyyBPO;

    @ApiOperation(value = "获取个人导航应用配置信息", notes = "根据条件查询消息列表1")
    @GetMapping(value = "/getuserApp")
    public AjaxResponse getuserApp() {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", dhyyBPO.getuserApp());
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

    @ApiOperation(value = "配置个人常用应用", notes = "根据条件查询消息列表1")
    @PostMapping(value = "/changeUseApp")
    public AjaxResponse changeUseApp(@RequestBody @Valid ChangeUseAppDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            dhyyBPO.changeUseApp(dto);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}
