package com.ruoyi.web.controller.system; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.web.domain.dto.government.GovernmentInfoAddRequest; import com.ruoyi.web.domain.dto.government.GovernmentInfoEditRequest; import com.ruoyi.web.domain.dto.government.GovernmentInfoQueryRequest; import com.ruoyi.web.domain.vo.GovernmentInfoVO; import com.ruoyi.web.service.GovernmentInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Map; import static com.ruoyi.common.core.domain.AjaxResult.error; import static com.ruoyi.common.core.domain.AjaxResult.success; @Api(tags ="政府信息") @RestController @RequestMapping("/system/government") public class GovernmentInfoController { @Autowired private GovernmentInfoService governmentInfoService; /** * 添加政府信息 * * @param governmentInfoAddRequest * @return */ @ApiOperation("添加政府信息") @PostMapping("/add") public AjaxResult addGovernmentInfo(@RequestBody GovernmentInfoAddRequest governmentInfoAddRequest) { if (governmentInfoAddRequest == null) { return error("请求参数为空"); } System.out.println(governmentInfoAddRequest.getContent()); Integer id = governmentInfoService.addGovernmentInfo(governmentInfoAddRequest); return success(id); } /** * 删除政府信息 * * @param paramsMap * @return */ @ApiOperation("删除政府信息") @PostMapping("/delete") public AjaxResult deleteGovernmentInfo(@RequestBody Map paramsMap) { String ids = paramsMap.get("ids"); if (StrUtil.isBlank(ids)) { return error("请求参数为空"); } boolean b = governmentInfoService.deleteGovernmentInfo(ids); if (b) { return success("删除成功"); } return error("删除失败"); } /** * 编辑政府信息 * * @param governmentInfoEditRequest * @return */ @ApiOperation("编辑政府信息") @PostMapping("/edit") public AjaxResult editGovernmentInfo(@RequestBody GovernmentInfoEditRequest governmentInfoEditRequest) { if (governmentInfoEditRequest == null) { return error("请求参数为空"); } governmentInfoService.editGovernmentInfo(governmentInfoEditRequest); return AjaxResult.success(); } /** * 发布政府信息 * * @param id * @return */ @ApiOperation("发布政府信息") @PostMapping("/publish") public AjaxResult publishGovernmentInfo(@RequestBody Map params) { int id = params.get("id"); if (id <= 0) { return error("请求参数为空"); } boolean b = governmentInfoService.publishGovernmentInfo(id); if (b) { return AjaxResult.success("发布成功"); } else { return AjaxResult.error("发布失败"); } } /** * 下架政府信息 * * @param id * @return */ @ApiOperation("下架政府信息") @PostMapping("/remove") public AjaxResult removeGovernmentInfo(@RequestBody Map params) { int id = params.get("id"); if (id <= 0) { return error("请求参数为空"); } boolean b = governmentInfoService.removeGovernmentInfo(id); if (b) { return AjaxResult.success("下架成功"); } else { return AjaxResult.error("下架失败"); } } /** * 根据id获取政府信息 * * @param id * @return */ @ApiOperation("根据id获取政府信息") @GetMapping("/get") public AjaxResult getGovernmentInfoById(@RequestParam int id) { if (ObjectUtil.isEmpty(id)) { return error("请求参数为空"); } GovernmentInfoVO governmentInfoById = governmentInfoService.getGovernmentInfoById(id); return success(governmentInfoById); } /** * 分页获取政府信息列表 * * @param governmentInfoQueryRequest * @return */ @ApiOperation("分页获取政府信息列表") @PostMapping("/list/page") public AjaxResult listGovernmentInfoByPage(@RequestBody GovernmentInfoQueryRequest governmentInfoQueryRequest) { if (governmentInfoQueryRequest == null) { return error("请求参数为空"); } Page listGovernmentInfoByPageVO = governmentInfoService.getListGovernmentInfoByPage(governmentInfoQueryRequest); return success(listGovernmentInfoByPageVO); } }