package cn.com.goldenwater.dcproj.controller.wr; import cn.com.goldenwater.dcproj.model.WrSwsB; import cn.com.goldenwater.dcproj.param.WrSwsBParam; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.service.WrSwsBService; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import com.github.pagehelper.PageInfo; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; import com.alibaba.fastjson.JSONObject; /** * @author zhengdafei * @date 2019-3-3 */ @Api(value = "", tags = " 地表水水源地基本信息表") @RestController @RequestMapping("/dc/insp/wrSwsB") public class WrSwsBController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private WrSwsBService wrSwsBService; @Autowired private OlBisInspOrgService olBisInspOrgService; @ApiOperation(value = "添加") @RequestMapping(value = "/insert", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "wrSwsB", value = "WrSwsB", required = true) @RequestBody WrSwsB wrSwsB) { String uuid = ""; JSONObject json = new JSONObject(); try { uuid = wrSwsBService.add(wrSwsB); json.put("id", uuid); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(json); } @ApiOperation(value = "根据ID删除") @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = wrSwsBService.delete(id); JSONObject json = new JSONObject(); json.put("code", ret); return buildSuccessResponse(json); } @ApiOperation(value = "更新信息") @RequestMapping(value = "/update", method = RequestMethod.PUT) public BaseResponse update(@ApiParam(name = "wrSwsB", value = "WrSwsB", required = true) @RequestBody WrSwsB wrSwsB) { int ret = 0; try { ret = wrSwsBService.modify(wrSwsB); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(wrSwsB); } @ApiOperation(value = "根据ID获取(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { WrSwsB wrSwsB = wrSwsBService.get(id); return buildSuccessResponse(wrSwsB); } @ApiOperation(value = "获取列表(分页)") @RequestMapping(value = "/queryListByPage", method = {RequestMethod.POST}) public BaseResponse> queryListByPage(@RequestBody WrSwsBParam param) { PageInfo list = new PageInfo<>(); param.setProvince(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); try { if (StringUtils.isNotBlank(param.getAdCode())) { String adCode = param.getAdCode(); if (adCode.contains("00")) { adCode = adCode.replace("00", ""); param.setAdCode(adCode); } } list = wrSwsBService.queryListByPage(param); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(list); } @ApiOperation(value = "获取列表") @RequestMapping(value = "/queryList", method = {RequestMethod.POST}) public BaseResponse> queryList(@RequestBody WrSwsBParam param) { List list = new ArrayList<>(); try { list = wrSwsBService.queryList(param); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(list); } @ApiOperation(value = "获取一个对象") @RequestMapping(value = "/getBy", method = {RequestMethod.POST}) public BaseResponse getBy(@RequestBody WrSwsBParam param) { WrSwsB one = new WrSwsB(); try { one = wrSwsBService.getBy(param); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(one); } }