package com.crm.manager.controller;

import com.crm.manager.service.SysCustomBlacklistService;
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.system.blacklist.SysCustomBlacklistDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.system.blacklist.SysCustomBlacklistAddEntity;
import com.crm.rely.backend.core.entity.system.blacklist.SysCustomBlacklistDeleteEntitys;
import com.crm.rely.backend.core.entity.system.blacklist.SysCustomBlacklistSearchListEntity;
import com.crm.rely.backend.core.entity.system.blacklist.SysCustomBlacklistUpdateEntity;
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;

/**
 * 黑名单列表
 *
 * @author houn
 */
@RestController
@RequestMapping("/custom/blacklist")
public class SysCustomBlacklistController {

    @Autowired
    private SysCustomBlacklistService sysCustomBlacklistService;

    /**
     * 添加黑名单
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated SysCustomBlacklistAddEntity entity) throws Exception {

        sysCustomBlacklistService.add(entity);
        return BaseResultDto.success();
    }

    /**
     * 删除黑名单
     *
     * @param entitys
     * @return
     * @throws Exception
     */
    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated SysCustomBlacklistDeleteEntitys entitys) throws Exception {

        sysCustomBlacklistService.delete(entitys);
        return BaseResultDto.success();
    }

    /**
     * 修改黑名单
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated SysCustomBlacklistUpdateEntity entity) throws Exception {

        sysCustomBlacklistService.update(entity);
        return BaseResultDto.success();
    }


    /**
     * 列表黑名单
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list")
    public ResultWithPagerDto<SysCustomBlacklistDto> searchList(@RequestBody @Validated SysCustomBlacklistSearchListEntity entity) throws Exception {


        ResultWithPagerDto<SysCustomBlacklistDto> result = sysCustomBlacklistService.searchPageList(entity);

        return result;
    }

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

        SysCustomBlacklistDto result = sysCustomBlacklistService.searchSingle(entity);

        return BaseResultDto.success(result);
    }
}
