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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.Result;
import com.sqx.modules.bl.commission.ywy.entity.YwyConfig;
import com.sqx.modules.bl.commission.ywy.service.YwyConfigService;
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/ywyConfig")
@Api(value = "分佣管理", tags = {"业务员配置"})
public class YwyConfigController {

    @Autowired
    private YwyConfigService service;

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

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