package cn.com.goldenwater.dcproj.controller.vill; import cn.com.goldenwater.dcproj.dto.BisInspVlgdrinkProjManageDcdxDto; import cn.com.goldenwater.dcproj.dto.VillRgstrDto; import cn.com.goldenwater.dcproj.model.BisInspVlgdrinkProjManage; import cn.com.goldenwater.dcproj.param.BisInspVlgdrinkProjManageParam; import cn.com.goldenwater.dcproj.param.GetVillPageByNodeIdParam; import cn.com.goldenwater.dcproj.service.BisInspVlgdrinkProjManageService; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.target.VerifyBean; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; 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; /** * @author zhengdafei * @date 2019-2-19 */ @Api(value = "", tags = "农村饮水工程运行管理情况") @RestController @RequestMapping("/dc/insp/vlgdrinkProjManage") public class BisInspVlgdrinkProjManageController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspVlgdrinkProjManageService bisInspVlgdrinkProjManageService; @ApiOperation(value = "添加") @RequestMapping(value = "/insert", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspVlgdrinkProjManage", value = "BisInspVlgdrinkProjManage", required = true) @RequestBody BisInspVlgdrinkProjManage bisInspVlgdrinkProjManage) { String uuid = ""; JSONObject json = new JSONObject(); try { BisInspVlgdrinkProjManageParam param = new BisInspVlgdrinkProjManageParam(); param.setEngId(bisInspVlgdrinkProjManage.getEngId()); param.setCwsCode(bisInspVlgdrinkProjManage.getCwsCode()); List list = bisInspVlgdrinkProjManageService.queryList(param); if (list != null && list.size() == 1) { BisInspVlgdrinkProjManage bisInspVlgdrinkProjManageUpdate = list.get(0); this.update(bisInspVlgdrinkProjManageUpdate); json.put("id", bisInspVlgdrinkProjManageUpdate.getRunId()); } else { uuid = bisInspVlgdrinkProjManageService.add(bisInspVlgdrinkProjManage); 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.POST) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = bisInspVlgdrinkProjManageService.delete(id); JSONObject json = new JSONObject(); json.put("id", id); return buildSuccessResponse(json); } @ApiOperation(value = "更新信息") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "bisInspVlgdrinkProjManage", value = "BisInspVlgdrinkProjManage", required = true) @RequestBody BisInspVlgdrinkProjManage bisInspVlgdrinkProjManage) { try { int ret = bisInspVlgdrinkProjManageService.modify(bisInspVlgdrinkProjManage); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(bisInspVlgdrinkProjManage); } @ApiOperation(value = "根据ID获取(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspVlgdrinkProjManage bisInspVlgdrinkProjManage = bisInspVlgdrinkProjManageService.get(id); if (bisInspVlgdrinkProjManage == null) { bisInspVlgdrinkProjManage = new BisInspVlgdrinkProjManage(); } return buildSuccessResponse(bisInspVlgdrinkProjManage); } @ApiOperation(value = "获取列表(分页)") @RequestMapping(value = "/queryListByPage", method = {RequestMethod.GET, RequestMethod.POST}) public BaseResponse> queryListByPage(@RequestBody BisInspVlgdrinkProjManageParam param) { PageInfo list = new PageInfo<>(); try { list = bisInspVlgdrinkProjManageService.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.GET, RequestMethod.POST}) public BaseResponse> queryList(@RequestBody BisInspVlgdrinkProjManageParam param) { List list = new ArrayList<>(); try { list = bisInspVlgdrinkProjManageService.queryList(param); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(list); } @ApiOperation(value = "根据行政区划编码和人员id获取列表(不分页)") @RequestMapping(value = "/getListByCodeAndPerId", method = RequestMethod.POST) public BaseResponse> getListByCodeAndPerId(@RequestBody VillRgstrDto villRgstrDto) { List list = new ArrayList<>(); try { list = bisInspVlgdrinkProjManageService.getListByCodeAndPerId(villRgstrDto); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(list); } @ApiOperation(value = "根据行政区划编码和人员id获取列表(分页)") @RequestMapping(value = "/getPageByCodeAndPerId", method = RequestMethod.POST) public BaseResponse> getPageByCodeAndPerId(@RequestBody VillRgstrDto villRgstrDto) { try { PageInfo list = bisInspVlgdrinkProjManageService.getPageByCodeAndPerId(villRgstrDto); return buildSuccessResponse(list); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } } @ApiOperation(value = "获取单条") @RequestMapping(value = "/getBy", method = RequestMethod.POST) public BaseResponse getPageByCodeAndPerId(@RequestBody BisInspVlgdrinkProjManageParam param) { try { if (param == null) { return buildFailResponse("参数不能为空"); } BisInspVlgdrinkProjManage list = bisInspVlgdrinkProjManageService.getBy(param); return buildSuccessResponse(list); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } } @VerifyBean @ApiOperation(value = "根据节点id以及其他条件获取列表(分页,行政区只到县,还有用户填报的所在地)") @RequestMapping(value = "/getPageByNodeId", method = RequestMethod.POST) public BaseResponse> getPageByNodeId(@RequestBody GetVillPageByNodeIdParam p) throws Exception { PageInfo list = bisInspVlgdrinkProjManageService.getPageByNodeId(p); return buildSuccessResponse(list); } }