package com.zc.business.controller; import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.ruoyi.common.utils.DateUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; 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.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.zc.business.domain.DcPublishingChannels; import com.zc.business.service.IDcPublishingChannelsService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; /** * 发布渠道Controller * * @author ruoyi * @date 2024-04-19 */ @RestController @RequestMapping("/business/channels") public class DcPublishingChannelsController extends BaseController { @Autowired private IDcPublishingChannelsService dcPublishingChannelsService; /** * 查询发布渠道列表 */ @PreAuthorize("@ss.hasPermi('business:channels:list')") @PostMapping("/list") public TableDataInfo list(@RequestBody DcPublishingChannels dcPublishingChannels) { startPage(); List list = dcPublishingChannelsService.selectDcPublishingChannelsList(dcPublishingChannels); return getDataTable(list); } /** * 导出发布渠道列表 */ @PreAuthorize("@ss.hasPermi('business:channels:export')") @Log(title = "发布渠道", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, DcPublishingChannels dcPublishingChannels) { List list = dcPublishingChannelsService.selectDcPublishingChannelsList(dcPublishingChannels); ExcelUtil util = new ExcelUtil<>(DcPublishingChannels.class); util.exportExcel(response, list, "发布渠道数据"); } /** * 获取发布渠道详细信息 */ @PreAuthorize("@ss.hasPermi('business:channels:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return AjaxResult.success(dcPublishingChannelsService.selectDcPublishingChannelsById(id)); } /** * 新增发布渠道 */ @PreAuthorize("@ss.hasPermi('business:channels:add')") @Log(title = "发布渠道", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody DcPublishingChannels dcPublishingChannels) { if (dcPublishingChannels.getDataCategory()==null){ return AjaxResult.error("参数错误"); } List channelsList = dcPublishingChannelsService. selectChannelsDataCategory(dcPublishingChannels.getDataCategory()); if (channelsList!=null&&channelsList.size()>0){ return AjaxResult.error("事件类型已存在"); } return toAjax(dcPublishingChannelsService.insertDcPublishingChannels(dcPublishingChannels)); } /** * 修改发布渠道 */ @PreAuthorize("@ss.hasPermi('business:channels:edit')") @Log(title = "发布渠道", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody DcPublishingChannels dcPublishingChannels) { return toAjax(dcPublishingChannelsService.updateDcPublishingChannels(dcPublishingChannels)); } /** * 删除发布渠道 */ @PreAuthorize("@ss.hasPermi('business:channels:remove')") @Log(title = "发布渠道", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(dcPublishingChannelsService.deleteDcPublishingChannelsByIds(ids)); } /** * 修改启用停用 */ @PostMapping("/updateEnabled") public AjaxResult updateEnabled(@RequestBody DcPublishingChannels dcPublishingChannels) { Integer enabled = dcPublishingChannels.getEnabled();//状态 if (enabled==null){ return AjaxResult.error("参数错误"); } if (enabled==2){ //启用状态,修改启用时间 dcPublishingChannels.setEnableDate(DateUtils.getNowDate()); } return toAjax(dcPublishingChannelsService.updateEnabled(dcPublishingChannels)); } //事件调度处置事件推送发布渠道 @PostMapping("/eventPublishChannels") public AjaxResult eventPublishChannels(@RequestBody HashMap map) { if (map==null||map.size()==0){ return AjaxResult.error("参数错误"); } String eventId = map.get("eventId").toString(); if (StringUtils.isBlank(eventId)){ return AjaxResult.error("参数错误"); } return AjaxResult.success(dcPublishingChannelsService.eventPublishChannels(eventId)); } }