package com.crm.custom.controller;

import com.crm.custom.service.CustomInfoService;
import com.crm.custom.service.activity.ActivityRaceSignFeignService;
import com.crm.login.rely.backend.controller.BaseLoginController;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.login.InfoEntity;
import com.crm.rely.backend.model.dto.activity.ActivityRaceSignInfoDto;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignAddEntity;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignInfoEntity;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignListEntity;
import com.crm.rely.backend.model.entity.activity.ActivityRaceSignLoginEntity;
import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 比赛报名api
 *
 * @author y
 * @create 2022/7/19
 */
@RestController
@RequestMapping("/activity/race/sign")
public class ActivityRaceSignController extends BaseLoginController {

    @Autowired
    private ActivityRaceSignFeignService activityRaceSignFeignService;
    @Autowired
    private CustomInfoService customInfoService;

    /**
     * 添加报名
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto<Boolean> add(@RequestBody ActivityRaceSignAddEntity entity, InfoEntity infoEntity) throws Exception {
        entity.setCustomId(infoEntity.getId());
        CustomInfoTable custom = customInfoService.getById(infoEntity.getId());
        entity.setCId(custom.getCId());
        entity.setSignDate(new Date());
        return activityRaceSignFeignService.add(entity);
    }

    /**
     * 最近一次报名信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/recent")
    public BaseResultDto<ActivityRaceSignInfoDto> info(@RequestBody ActivityRaceSignInfoEntity entity, InfoEntity infoEntity) throws Exception {
        entity.setCustomId(infoEntity.getId());
        return activityRaceSignFeignService.info(entity);
    }

    /**
     * 根据ID获取报名信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/single")
    public BaseResultDto<ActivityRaceSignInfoDto> searchSingle(@RequestBody SingleLongEntity entity) throws Exception {
        return activityRaceSignFeignService.searchSingle(entity);
    }

    /**
     * 报名列表
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list")
    public BaseResultWithPagerDto<List<ActivityRaceSignInfoDto>>
    searchList(@RequestBody ActivityRaceSignListEntity entity, InfoEntity infoEntity) throws Exception {
        entity.setCustomId(infoEntity.getId());
        return activityRaceSignFeignService.searchList(entity);
    }

    /**
     * 获取可用的交易账户
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/logins")
    public BaseResultDto<List<Long>> logins(@RequestBody ActivityRaceSignLoginEntity entity, InfoEntity infoEntity) throws Exception {
        entity.setCustomId(infoEntity.getId());
        return activityRaceSignFeignService.logins(entity);
    }
}
