package com.moral.api.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; 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; import java.util.Collections; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.moral.api.entity.Rectify; import com.moral.api.service.RectifyService; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import com.moral.util.WebUtils; @Slf4j @Api(tags = {"企业整顿"}) @RestController @CrossOrigin(origins = "*", maxAge = 3600) @RequestMapping("rectify") public class RectifyController { @Autowired private RectifyService rectifyService; @PostMapping("addRectify") public ResultMessage addRectify(@RequestBody Rectify rectify) { if (rectify.getCityCode() == null || rectify.getCityName() == null) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } int count = rectifyService.addRectify(rectify); if (count > 0) { return ResultMessage.ok(); } return ResultMessage.fail(); } @ApiOperation(value = "分页整顿清单", notes = "分页整顿清单") @ApiImplicitParams({ @ApiImplicitParam(name = "cityCode", value = "城市编码", required = false, paramType = "query", dataType = "int"), @ApiImplicitParam(name = "time", value = "时间,例:2022", required = false, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"), @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int") }) @GetMapping("queryRectify") public ResultMessage queryRectify(HttpServletRequest request) { Map params = WebUtils.getParametersStartingWith(request, null); if (params.get("cityCode") == null || params.get("time") == null) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } Map response = rectifyService.queryRectifyByCityCode(params); return ResultMessage.ok(response); } @GetMapping("exportRectify") public ResultMessage exportRectify(HttpServletRequest request) { Map params = WebUtils.getParametersStartingWith(request, null); if (params.get("cityCode") == null || params.get("time") == null) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } List rectifies = rectifyService.exportRectifyByCityCode(params); return ResultMessage.ok(rectifies); } @PostMapping("updateRectify") public ResultMessage updateRectify(@RequestBody Rectify rectify) { if (rectify.getId() == null) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } int count = rectifyService.updateRectify(rectify); if (count > 0) { return ResultMessage.ok(); } return ResultMessage.fail(); } @GetMapping("deleteRectify") public ResultMessage deleteRectify(Integer id) { if (id == null) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } int count = rectifyService.deleteRectify(id); if (count > 0) { return ResultMessage.ok(); } return ResultMessage.fail(); } }