package com.crm.manager.controller;

import com.crm.manager.service.follow.FollowCommissionConfigService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.follow.config.FollowCommissionConfigDto;
import com.crm.rely.backend.core.entity.follow.config.FollowCommissionConfigAddEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author y
 * @create 2022/6/21
 */
@RestController
@RequestMapping("/follow/commission/config")
public class FollowCommissionConfigController {

    @Autowired
    private FollowCommissionConfigService followCommissionConfigService;

    /**
     * 保存代理跟单分成比例
     *
     * @param entities
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody List<FollowCommissionConfigAddEntity> entities) throws Exception {
        followCommissionConfigService.add(entities);
        return BaseResultDto.success();
    }

    /**
     * 获取所有代理跟单分成比例
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/list")
    public BaseResultDto<FollowCommissionConfigDto> list() throws Exception {
        return BaseResultDto.success(followCommissionConfigService.getList());
    }

}
