CooperationController.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package com.lemon.lifecenter.controller;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.web.bind.annotation.ModelAttribute;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import org.springframework.web.servlet.ModelAndView;
  16. import com.lemon.lifecenter.common.LifeCenterConfigVO;
  17. import com.lemon.lifecenter.common.LifeCenterController;
  18. import com.lemon.lifecenter.common.LifeCenterFunction;
  19. import com.lemon.lifecenter.common.LifeCenterPaging;
  20. import com.lemon.lifecenter.common.LifeCenterSessionController;
  21. import com.lemon.lifecenter.dto.CooperationDTO;
  22. import com.lemon.lifecenter.service.CooperationService;
  23. @Controller
  24. @RequestMapping("/cooperation")
  25. public class CooperationController extends LifeCenterController {
  26. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  27. @Autowired
  28. private CooperationService service;
  29. @Autowired
  30. private LifeCenterConfigVO config;
  31. private LifeCenterPaging paging;
  32. @RequestMapping( "/list" )
  33. public ModelAndView list(
  34. @ModelAttribute("dto") final CooperationDTO dto,
  35. @RequestParam(value="page", required=false, defaultValue="1") int page,
  36. @RequestParam(value="useYn", required=false, defaultValue="") String useYn,
  37. @RequestParam(value="sData", required=false, defaultValue="") String sData,
  38. @RequestParam(value="selectState", required=false, defaultValue="") String selectState) {
  39. dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
  40. dto.setLimitMax( config.pageDataSize );
  41. dto.setUseYn(useYn);
  42. if (selectState.equals("sCode")) {
  43. dto.setCooperativeCode(sData);
  44. } else if (selectState.equals("sName")) {
  45. dto.setCooperativeName(sData);
  46. }
  47. int total = service.selectCooperationTotal(dto);
  48. List<CooperationDTO> list = new ArrayList<CooperationDTO>();
  49. if (total > 0) {
  50. list = service.selectCooperationList(dto);
  51. }
  52. String param = "selectState="+selectState+"&sData="+sData+"&useYn="+useYn;
  53. paging = LifeCenterPaging.getInstance();
  54. paging.paging(config, total, page, param);
  55. ModelAndView mv = setMV( "cooperation/list" );
  56. mv.addObject("total", total);
  57. mv.addObject("list", list);
  58. mv.addObject("paging", paging);
  59. mv.addObject("page", page);
  60. mv.addObject("pageSize", dto.getLimitMax());
  61. mv.addObject("selectState", selectState);
  62. mv.addObject("sData", sData);
  63. mv.addObject("useYn", useYn);
  64. return mv;
  65. }
  66. @RequestMapping( "/new" )
  67. public ModelAndView newCooperation() {
  68. ModelAndView mv = setMV( "cooperation/new" );
  69. return mv;
  70. }
  71. @RequestMapping( value = "/new/insert", method = RequestMethod.POST)
  72. public String insertCooperation(
  73. @ModelAttribute("dto") final CooperationDTO dto,
  74. HttpServletRequest request,HttpServletResponse response) {
  75. String sesId = LifeCenterSessionController.getSession( request, "sesId" );
  76. dto.setCreateBy(sesId);
  77. service.insertCooperation(dto);
  78. LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '협력병원이 등록되었습니다.', callBack : function(){ location.href='/cooperation/info?cooperativeCode="+dto.getCooperativeCode()+"'; } });" );
  79. return "/common/blank";
  80. //return "redirect:/cooperation/info?cooperativeCode="+dto.getCooperativeCode();
  81. }
  82. @RequestMapping( "/info" )
  83. public ModelAndView info(@RequestParam(value="cooperativeCode", required=false, defaultValue="" ) String cooperativeCode) {
  84. int cnt = service.selectCooperationInfoOneCount(cooperativeCode);
  85. if (cnt == 0) {
  86. }
  87. CooperationDTO dto = new CooperationDTO();
  88. dto = service.selectCooperationInfoOne(cooperativeCode);
  89. ModelAndView mv = setMV( "cooperation/info" );
  90. mv.addObject("info", dto);
  91. return mv;
  92. }
  93. @RequestMapping( "/edit" )
  94. public ModelAndView edit(@RequestParam(value="cooperativeCode", required=false, defaultValue="" ) String cooperativeCode) {
  95. int cnt = service.selectCooperationInfoOneCount(cooperativeCode);
  96. if (cnt == 0) {
  97. }
  98. CooperationDTO dto = new CooperationDTO();
  99. dto = service.selectCooperationInfoOne(cooperativeCode);
  100. ModelAndView mv = setMV( "cooperation/edit" );
  101. mv.addObject("info", dto);
  102. return mv;
  103. }
  104. @RequestMapping( "/edit/update" )
  105. public String updateCooperation(
  106. @ModelAttribute("dto") final CooperationDTO dto,
  107. HttpServletRequest request,HttpServletResponse response) {
  108. String sesId = LifeCenterSessionController.getSession( request, "sesId" );
  109. dto.setUpdateBy(sesId);
  110. service.updateCooperationInfo(dto);
  111. LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '협력병원 정보가 수정되었습니다.', callBack : function(){ location.href='/cooperation/info?cooperativeCode="+dto.getCooperativeCode()+"'; } });" );
  112. return "/common/blank";
  113. //return "redirect:/cooperation/info?cooperativeCode="+dto.getCooperativeCode();
  114. }
  115. @RequestMapping( value="/duplicateCheck", method = RequestMethod.POST )
  116. @ResponseBody
  117. public boolean duplicateCheck(
  118. @RequestParam(value="cooperativeCode", required=false, defaultValue="" ) String cooperativeCode,
  119. @RequestParam(value="cooperativeCodeTemp", required=false, defaultValue="" ) String cooperativeCodeTemp) {
  120. boolean result = false;
  121. if (!cooperativeCode.equals("") && !cooperativeCodeTemp.equals("")) {
  122. if (cooperativeCode.equals(cooperativeCodeTemp)) {
  123. return true;
  124. }
  125. }
  126. if( cooperativeCode.trim().equals( "" ) ) {
  127. result = false;
  128. } else {
  129. int count = service.duplicateCheck(cooperativeCode);
  130. if( count == 0 ) {
  131. result = true;
  132. }
  133. }
  134. return result;
  135. }
  136. }