package com.xinelu.manage.controller.propagandainfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.propagandainfo.PropagandaInfo;
import com.xinelu.manage.dto.propagandainfo.PropagandaInfoDto;
import com.xinelu.manage.dto.propagandainfo.PropagandaInfoSaveDto;
import com.xinelu.manage.dto.propagandainfo.PropagandaUpdateDto;
import com.xinelu.manage.service.propagandainfo.IPropagandaInfoService;
import com.xinelu.manage.vo.department.DepartmentBaseVo;
import com.xinelu.manage.vo.propagandainfo.PropagandaMaterialsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 宣教库管理Controller
 *
 * @author haown
 * @date 2024-02-27
 */
@Api(tags = "宣教库管理控制器")
@RestController
@RequestMapping("/manage/propaganda")
public class PropagandaInfoController extends BaseController {
    @Resource
    private IPropagandaInfoService propagandaInfoService;

	/**
	 * 查询宣教库管理列表
	 */
	@ApiOperation("分页查询宣教库管理列表")
	@GetMapping("/list")
    public TableDataInfo list(PropagandaInfoDto propagandaInfo) {
        startPage();
        List<PropagandaInfo> list = propagandaInfoService.selectPropagandaInfoList(propagandaInfo);
        return getDataTable(list);
    }

    /**
     * 导出宣教库管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:propaganda:export')")
    @Log(title = "宣教库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropagandaInfoDto propagandaInfo) {
        List<PropagandaInfo> list = propagandaInfoService.selectPropagandaInfoList(propagandaInfo);
        ExcelUtil<PropagandaInfo> util = new ExcelUtil<PropagandaInfo>(PropagandaInfo. class);
        util.exportExcel(response, list, "宣教库管理数据");
    }

    /**
     * 获取宣教库管理详细信息
     */
    @ApiOperation("根据id获取宣教库管理详细信息")
    @GetMapping(value = "/{id}")
    public R<PropagandaMaterialsVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(propagandaInfoService.selectPropagandaInfoById(id));
    }

	/**
	 * 获取宣教库管理信息
	 */
	@ApiOperation("根据id获取宣教库管理信息")
	@PreAuthorize("@ss.hasPermi('manage:propaganda:query')")
	@GetMapping(value = "getById/{id}")
	public R<PropagandaInfo> getById(@PathVariable("id") Long id) {
		return R.ok(propagandaInfoService.getById(id));
	}
    /**
     * 新增宣教库管理
     */
    @ApiOperation("新增宣教库信息")
    @PreAuthorize("@ss.hasPermi('manage:propaganda:add')")
    @Log(title = "宣教库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropagandaInfoSaveDto propagandaInfoSaveDto) {
        return toAjax(propagandaInfoService.insertPropagandaInfo(propagandaInfoSaveDto));
    }

    /**
     * 修改宣教库管理
     */
    @ApiOperation("修改宣教库信息")
    @PreAuthorize("@ss.hasPermi('manage:propaganda:edit')")
    @Log(title = "宣教库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropagandaInfoSaveDto propagandaInfoSaveDto) {
        return toAjax(propagandaInfoService.updatePropagandaInfo(propagandaInfoSaveDto));
    }

	/**
	 * 复制宣教内容
	 */
	@ApiOperation("复制宣教内容")
	@PreAuthorize("@ss.hasPermi('manage:propaganda:add')")
	@GetMapping("/copy/{id}")
	public R<String> copy(@PathVariable Long id) {
		int flag = propagandaInfoService.copyPropagandaInfo(id);
		return flag > 0 ? R.ok() : R.fail();
	}

	/**
	 * 修改宣教信息状态
	 */
	@ApiOperation("修改宣教库信息")
	@PreAuthorize("@ss.hasPermi('manage:propaganda:edit')")
	@Log(title = "宣教库管理", businessType = BusinessType.UPDATE)
	@PostMapping("/updateStatus")
	public R<String> updateStatus(@RequestBody PropagandaUpdateDto propagandaInfo) {
		int flag = propagandaInfoService.updateStatus(propagandaInfo);
		return flag < 0 ? R.fail() : R.ok();
	}

    /**
     * 删除宣教库管理
     */
    @ApiOperation("批量删除宣教库信息")
    @PreAuthorize("@ss.hasPermi('manage:propaganda:remove')")
    @Log(title = "宣教库管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(propagandaInfoService.deletePropagandaInfoByIds(ids));
    }

	/**
	 * 查询科室信息列表及包含宣教库数量
	 */
	@ApiOperation("查询科室信息列表及包含宣教库数量")
	@GetMapping("/selectNumByDept")
	public R<DepartmentBaseVo> selectNumByDept(PropagandaInfoDto propagandaInfoDto) {
		DepartmentBaseVo departmentBaseVo = propagandaInfoService.selectNumByDept(propagandaInfoDto);
		return R.ok(departmentBaseVo);
	}
}
