package com.crm.manager.controller;

import com.crm.manager.service.ib.CustomCommissionApplyFeignService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
import com.crm.rely.backend.core.dto.custom.commission.CustomCommissionApplyDto;
import com.crm.rely.backend.core.entity.custom.commission.CustomCommissionApplyApproveEntity;
import com.crm.rely.backend.core.entity.custom.commission.CustomCommissionApplyListEntity;
import com.crm.rely.backend.core.entity.custom.info.InfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.Date;
import java.util.List;

/**
 * Created by max on 2020/8/25.
 */
@RestController
@RequestMapping("/custom/commission/apply")
public class CustomCommissionApplyController {

    @Autowired
    private CustomCommissionApplyFeignService customCommissionApplyFeignService;

    @PostMapping("/list")
    public BaseResultWithPagerDto<List<CustomCommissionApplyDto>> getList(@RequestBody CustomCommissionApplyListEntity entity, InfoEntity infoEntity) throws Exception {
        return customCommissionApplyFeignService.getList(entity);
    }

    @PostMapping("/approve")
    public BaseResultDto<Object> approve(@RequestBody @Validated CustomCommissionApplyApproveEntity entity, InfoEntity infoEntity) throws Exception {
        entity.setApproveTime(new Date());
        entity.setApproveUser(infoEntity.getIbInfo().getId());
        return customCommissionApplyFeignService.approve(entity);
    }

}
