package com.bonus.material.purchase.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.purchase.domain.dto.PurchaseNoticePersonDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.purchase.domain.PurchaseNoticePerson;
import com.bonus.material.purchase.service.IPurchaseNoticePersonService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.page.TableDataInfo;

/**
 * 新购短信通知人员Controller
 *
 * @author syruan
 */
@Api(tags = "新购短信通知人员接口")
@RestController
@RequestMapping("/purchase_notice_person")
public class PurchaseNoticePersonController extends BaseController {

    @Resource
    private IPurchaseNoticePersonService purchaseNoticePersonService;

    /**
     * 查询新购短信通知人员列表
     */
    @ApiOperation(value = "查询新购短信通知人员列表")
    @RequiresPermissions("purchase:person:notice")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseNoticePerson purchaseNoticePerson) {
        List<PurchaseNoticePerson> list = purchaseNoticePersonService.selectPurchaseNoticePersonList(purchaseNoticePerson);
        return getDataTable(list);
    }

    /**
     * 查询新购短信通知人员列表
     */
    @ApiOperation(value = "查询等待选择的新购短信通知人员列表")
    @RequiresPermissions("purchase:person:notice")
    @GetMapping("/listUnSelected")
    public TableDataInfo listUnSelected(PurchaseNoticePerson purchaseNoticePerson) {
        List<PurchaseNoticePerson> list = purchaseNoticePersonService.getUnSelectedUserList(purchaseNoticePerson);
        return getDataTable(list);
    }

    /**
     * 导出新购短信通知人员列表
     */
    @ApiOperation(value = "导出新购短信通知人员列表")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:person:notice")
    @SysLog(title = "新购短信管理", businessType = OperaType.EXPORT, module = "物资新购->导出新购短信通知人员")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseNoticePerson purchaseNoticePerson) {
        List<PurchaseNoticePerson> list = purchaseNoticePersonService.selectPurchaseNoticePersonList(purchaseNoticePerson);
        ExcelUtil<PurchaseNoticePerson> util = new ExcelUtil<PurchaseNoticePerson>(PurchaseNoticePerson.class);
        util.exportExcel(response, list, "新购短信通知人员数据");
    }

    /**
     * 获取新购短信通知人员详细信息
     */
    @ApiOperation(value = "获取新购短信通知人员详细信息")
    @RequiresPermissions("purchase:person:notice")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(purchaseNoticePersonService.selectPurchaseNoticePersonById(id));
    }

    /**
     * 新增新购短信通知人员
     */
    @ApiOperation(value = "新增新购短信通知人员")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:person:notice")
    @SysLog(title = "新购短信通知人员", businessType = OperaType.INSERT, module = "物资新购->新增新购短信通知人员")
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseNoticePerson purchaseNoticePerson) {
        try {
            return toAjax(purchaseNoticePersonService.insertPurchaseNoticePerson(purchaseNoticePerson));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 批量新增--新购短信通知人员
     */
    @ApiOperation(value = "批量新增新购短信通知人员")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:person:notice")
    @SysLog(title = "批量新增新购短信通知人员", businessType = OperaType.INSERT, module = "物资新购->批量新增新购短信通知人员")
    @PostMapping("/batchAddNoticePerson")
    public AjaxResult batchAddNoticePerson(@RequestBody List<PurchaseNoticePerson> purchaseNoticePersonList) {
        try {
            return toAjax(purchaseNoticePersonService.insertBatchPurchaseNoticePerson(purchaseNoticePersonList));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 批量发送短信
     */
    @ApiOperation(value = "批量发送短信")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:person:notice")
    @SysLog(title = "批量发送短信", businessType = OperaType.UPDATE, module = "物资新购->批量发送短信")
    @PutMapping("/batchSendSms")
    public AjaxResult batchSendSms(@NotNull @Valid @RequestBody PurchaseNoticePersonDto purchaseNoticePersonDto) {
        return purchaseNoticePersonService.batchSendSms(purchaseNoticePersonDto);
    }

    /**
     * 修改新购短信通知人员
     */
    @ApiOperation(value = "修改新购短信通知人员")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:person:notice")
    @SysLog(title = "新购短信管理", businessType = OperaType.UPDATE, module = "物资新购->修改新购短信通知人员")
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseNoticePerson purchaseNoticePerson) {
        try {
            return toAjax(purchaseNoticePersonService.updatePurchaseNoticePerson(purchaseNoticePerson));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 删除新购短信通知人员
     */
    @ApiOperation(value = "删除新购短信通知人员")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:person:notice")
    @SysLog(title = "新购短信通知人员", businessType = OperaType.DELETE, module = "物资新购->删除新购短信通知人员")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(purchaseNoticePersonService.deletePurchaseNoticePersonByIds(ids));
    }
}
