package cn.com.goldenwater.dcproj.controller.wr; import cn.com.goldenwater.dcproj.model.WrGwsB; import cn.com.goldenwater.dcproj.param.WrGwsBParam; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.service.WrGwsBService; 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/wrGwsB") public class WrGwsBController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private WrGwsBService wrGwsBService; @Autowired private OlBisInspOrgService olBisInspOrgService; @ApiOperation(value = "添加") @RequestMapping(value = "/insert", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "wrGwsB", value = "WrGwsB", required = true) @RequestBody WrGwsB wrGwsB) { String uuid = ""; JSONObject json = new JSONObject(); try { if (StringUtils.isNotBlank(wrGwsB.getGwsCd())) { String cwsCd = wrGwsB.getGwsCd().substring(0, 6) + "000000"; wrGwsB.setAdCode(cwsCd); } uuid = wrGwsBService.add(wrGwsB); 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 = "/del/{id}", method = RequestMethod.GET) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = wrGwsBService.delete(id); JSONObject json = new JSONObject(); json.put("code", ret); return buildSuccessResponse(json); } @ApiOperation(value = "更新信息") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "wrGwsB", value = "WrGwsB", required = true) @RequestBody WrGwsB wrGwsB) { try { wrGwsBService.modify(wrGwsB); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(wrGwsB); } @ApiOperation(value = "根据ID获取(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { WrGwsB wrGwsB = wrGwsBService.get(id); return buildSuccessResponse(wrGwsB); } @ApiOperation(value = "获取列表(分页)") @RequestMapping(value = "/queryListByPage", method = {RequestMethod.POST}) public BaseResponse> queryListByPage(@RequestBody WrGwsBParam param) { PageInfo list = new PageInfo<>(); param.setProvince(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()))); try { String adCode = param.getAdCode(); if (adCode.contains("00")) { adCode = adCode.replace("00", ""); param.setAdCode(adCode); } list = wrGwsBService.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 WrGwsBParam param) { List list = new ArrayList<>(); try { list = wrGwsBService.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 WrGwsBParam param) { WrGwsB one = new WrGwsB(); try { one = wrGwsBService.getBy(param); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(one); } }