package com.crm.manager.controller;

import com.crm.manager.service.UserReferralService;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.core.dto.user.info.UserReferralDto;
import com.crm.rely.backend.core.entity.user.info.UserReferralAddEntity;
import com.crm.rely.backend.core.entity.user.info.UserReferralEntity;
import com.crm.rely.backend.core.entity.user.info.UserReferralUpdateEntity;
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;

@RestController
@RequestMapping("/user/referral")
public class UserReferralController {

    @Autowired
    private UserReferralService userReferralService;

    /**
     * 添加入职人员
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated UserReferralAddEntity entity) throws Exception {
        userReferralService.add(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/search/list")
    public ResultWithPagerDto<UserReferralDto> pageList(@RequestBody UserReferralEntity entity) throws Exception {
        return userReferralService.searchPageList(entity);
    }

    @PostMapping("/update")
    public BaseResultDto update(@RequestBody UserReferralUpdateEntity entity) throws Exception {
        userReferralService.update(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/search/success/list")
    public ResultWithPagerDto<UserReferralDto> getSuccessPageList(@RequestBody UserReferralEntity entity) throws Exception {
        return userReferralService.getSuccessPageList(entity);
    }

}
