package com.crm.manager.controller;

import com.crm.manager.service.SysCountryGroupTypeService;
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.country.group.type.SysCountryGroupTypeSearchListDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.system.country.group.type.SysCountryGroupTypeAddEntity;
import com.crm.rely.backend.core.entity.system.country.group.type.SysCountryGroupTypeDeleteEntitys;
import com.crm.rely.backend.core.entity.system.country.group.type.SysCountryGroupTypeSearchListEntity;
import com.crm.rely.backend.core.entity.system.country.group.type.SysCountryGroupTypeUpdateEntity;
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("/country/group/type")
public class SysCountryGroupTypeController {

    @Autowired
    private SysCountryGroupTypeService service;


    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated SysCountryGroupTypeAddEntity entity) throws Exception {


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

    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated SysCountryGroupTypeDeleteEntitys entitys) throws Exception {

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


    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated SysCountryGroupTypeUpdateEntity entity) throws Exception {

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


    @PostMapping("/search/list")
    public ResultWithPagerDto<SysCountryGroupTypeSearchListDto> searchList(@RequestBody @Validated SysCountryGroupTypeSearchListEntity entity) throws Exception {


        ResultWithPagerDto<SysCountryGroupTypeSearchListDto> result = service.searchPageList(entity);

        return result;
    }


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

        SysCountryGroupTypeSearchListDto result = service.searchSingle(entity);

        return BaseResultDto.success(result);
    }
}
