package com.crm.manager.controller;

import com.crm.manager.service.CommonService;
import com.crm.manager.service.SysRemitChannelFeignService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.model.entity.sys.remit.SysRemitChannelBatchUpdateEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 配置出金通道
 *
 * @author houn
 */
@RestController
@RequestMapping("/remit/channel")
public class SysRemitChannelController {

    @Autowired
    private SysRemitChannelFeignService sysRemitChannelFeignService;

    @Autowired
    private CommonService commonService;

    @PostMapping("/batch/update")
    public BaseResultDto updateBatchRate(@RequestBody @Validated SysRemitChannelBatchUpdateEntity entity) throws Exception {
        return sysRemitChannelFeignService.updateBatch(entity);
    }

    @PostMapping("/list")
    public BaseResultDto list() throws Exception {

        return sysRemitChannelFeignService.list();
    }

    @PostMapping("/get/code")
    public BaseResultDto getCodeList() throws Exception {

        return sysRemitChannelFeignService.getCodeList();
    }

    /**
     * 单个查询
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/single")
    public BaseResultDto single(@RequestBody @Validated SingleLongEntity entity) throws Exception {

        return sysRemitChannelFeignService.single(entity);
    }

    @PostMapping("/upload")
    public BaseResultDto upload(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        String middlePath = "/channel/remit";
        commonService.validated(file);
        String path = commonService.uploadFile(middlePath, file);
        return BaseResultDto.success(Constants.UPLOAD_SUCCESS, path);
    }


}
