package com.czg.controller.admin;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.market.entity.MkDistributionGroup;
import com.czg.market.service.MkDistributionGroupService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * 全民股东群聊
 *
 * @author ww
 */
@RestController
@RequestMapping("/admin/disGroup")
public class ADisGroupController {

    @Resource
    private MkDistributionGroupService mkDistributionGroupService;

    /**
     * 全民股东群聊
     */
    @GetMapping
    @SaAdminCheckPermission(parentName = "全民股东群聊", value = "share:config", name = "全民股东群聊-配置")
    public CzgResult<MkDistributionGroup> getShareBase() {
        return CzgResult.success(mkDistributionGroupService.getById(StpKit.USER.getShopId()));
    }

    /**
     * 全民股东群聊:新增/修改
     */
    @PostMapping
    @SaAdminCheckPermission(parentName = "全民股东群聊", value = "share:up", name = "全民股东群聊-新增/修改")
    public CzgResult<Boolean> editShareBase(@RequestBody MkDistributionGroup group) {
        group.setShopId(StpKit.USER.getShopId());
        MkDistributionGroup share = mkDistributionGroupService.getById(group.getShopId());
        if (share == null) {
            return CzgResult.success(mkDistributionGroupService.save(group));
        } else {
            return CzgResult.success(mkDistributionGroupService.updateById(group));
        }
    }
}