package com.crm.manager.controller;

import com.crm.login.rely.backend.controller.BaseLoginController;
import com.crm.manager.service.CommonService;
import com.crm.manager.service.activity.WebActivityCustomDepositRaffleWeekFeignService;
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.core.entity.web.activity.custom.deposit.raffle.WebActivityCustomDepositRaffleAddEntity;
import com.crm.rely.backend.core.entity.web.activity.custom.deposit.raffle.WebActivityCustomDepositRaffleDeleteEntity;
import com.crm.rely.backend.core.entity.web.activity.custom.deposit.raffle.WebActivityCustomDepositRaffleUpdateEntity;
import com.crm.rely.backend.core.entity.web.activity.custom.deposit.raffle.WebActivityCustomDepositRaffleWeekSearchListEntity;
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("/web/activity/custom/deposit/raffle")
public class WebActivityCustomDepositRaffleWeekController extends BaseLoginController {

    @Autowired
    private WebActivityCustomDepositRaffleWeekFeignService feignService;

    @Autowired
    private CommonService commonService;

    /**
     * 添加信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated WebActivityCustomDepositRaffleAddEntity entity) throws Exception {

        return feignService.add(entity);
    }

    /**
     * 删除信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated WebActivityCustomDepositRaffleDeleteEntity entity) throws Exception {


        return feignService.delete(entity);
    }

    /**
     * 修改信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated WebActivityCustomDepositRaffleUpdateEntity entity) throws Exception {


        return feignService.update(entity);
    }

    /**
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list")
    public BaseResultDto list(@RequestBody @Validated WebActivityCustomDepositRaffleWeekSearchListEntity entity) throws Exception {


        return feignService.pageSearchList(entity);

    }

    @PostMapping("/search/single")
    public BaseResultDto single(@RequestBody @Validated SingleLongEntity entity) throws Exception {

        return feignService.single(entity);

    }

    @RequestMapping("/{method}/upload")
    public BaseResultDto upload(@PathVariable("method") String method, @RequestParam(value = "file",
            required = false) MultipartFile file) throws Exception {

        if (!"add".equals(method) && !"update".equals(method)) {
            return BaseResultDto.error(Constants.SYSTEM_ERROR);
        }
        String middlePath = "/web/activity/custom/deposit/raffle";
        commonService.validated(file);
        String path = commonService.uploadFile(middlePath, file);

        return BaseResultDto.success(Constants.UPLOAD_SUCCESS, path);

    }
}
