package com.sqx.modules.bl.commission.fxy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.Result;
import com.sqx.modules.bl.commission.fxy.entity.FxyConfig;
import com.sqx.modules.bl.commission.fxy.service.FxyConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/commission/fxyConfig")
@Api(value = "分佣管理", tags = {"分销员配置"})
public class FxyConfigController {

    @Autowired
    private FxyConfigService service;

    @GetMapping("/info")
    @ApiOperation("查询分销员配置")
    public Result info(FxyConfig fxyConfig){
        FxyConfig entity = service.getById(fxyConfig);
        if(entity == null){
            entity = service.getOne(new QueryWrapper<FxyConfig>());
        }
        return Result.success().put("data",entity);
    }

    @PostMapping("/save")
    @ApiOperation("添加分销员")
    public Result save(FxyConfig fxyConfig){
        FxyConfig entity = service.getById(fxyConfig);
        if(entity!=null){
            service.updateById(fxyConfig);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            fxyConfig.setCreateTime(sdf.format(new Date()));
            service.save(fxyConfig);
        }
        return Result.success();
    }
}
