package com.crm.manager.controller;

import com.crm.manager.service.CommonService;
import com.crm.manager.service.SysRemittanceChannelFeignService;
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.remittance.channel.SysRemittanceChannelBatchUpdateEntity;
import com.crm.rely.backend.model.entity.sys.remittance.channel.SysRemittanceChannelSearchEntity;
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("/remittance/channel")
public class SysRemittanceChannelController {

    @Autowired
    private SysRemittanceChannelFeignService sysRemittanceChannelFeignService;

    @Autowired
    private CommonService commonService;

    @PostMapping("/batch/update")
    public BaseResultDto updateBatch(@RequestBody @Validated SysRemittanceChannelBatchUpdateEntity entity) throws Exception {

        return sysRemittanceChannelFeignService.updateBatch(entity);
    }

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

        return sysRemittanceChannelFeignService.list();
    }

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

        return sysRemittanceChannelFeignService.getCodeList();
    }

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

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