package com.gic.haoban.manage.web.controller;

import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.dto.OperationSettingDTO;
import com.gic.haoban.manage.api.service.OperationSettingApiService;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * desc：设置controller
 *
 * @author: YongEn
 * @date: 2021/8/26
 **/
@RestController
@RequestMapping("/setting")
public class SettingController extends WebBaseController {

    @Autowired
    private OperationSettingApiService operationSettingApiService;

    @RequestMapping("/operation-setting/save-or-update")
    private HaobanResponse operationSettingSaveOrUpdate(OperationSettingDTO dto) {
        // 保存或更新操作设置
        if (Objects.isNull(dto)
                || StringUtils.isEmpty(dto.getWxEnterpriseId())) {
            return resultResponse(HaoBanErrCode.ERR_2);
        }
        operationSettingApiService.saveOrUpdate(dto);
        return resultResponse(HaoBanErrCode.ERR_1);
    }

    @RequestMapping(value = "/get-operation-setting", method = RequestMethod.GET)
    private HaobanResponse getOperationSetting(String wxEnterpriseId) {
        // 查询操作配置
        OperationSettingDTO dto = operationSettingApiService.getByWxEnterpriseId(wxEnterpriseId);
        if (Objects.isNull(dto)) {
            return resultResponse(HaoBanErrCode.ERR_8);
        }
        return resultResponse(HaoBanErrCode.ERR_1, dto);
    }

}
