package com.lemon.lifecenter.controller; import java.util.ArrayList; import java.util.List; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.lemon.lifecenter.common.LifeCenterConfigVO; import com.lemon.lifecenter.common.LifeCenterController; import com.lemon.lifecenter.common.LifeCenterFunction; import com.lemon.lifecenter.common.LifeCenterPaging; import com.lemon.lifecenter.dto.CenterInfoDTO; import com.lemon.lifecenter.dto.LocationDTO; import com.lemon.lifecenter.dto.LoginDTO; import com.lemon.lifecenter.dto.StaffDTO; import com.lemon.lifecenter.service.CenterService; import com.lemon.lifecenter.service.LoginService; import com.lemon.lifecenter.service.StaffService; // 의료진관리 contorller @Controller @RequestMapping("/staff") public class StaffController extends LifeCenterController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private LoginService loginService; @Autowired private StaffService memberService; @Autowired private LifeCenterConfigVO config; private LifeCenterPaging paging; @RequestMapping("/new") public ModelAndView staffNew() { List centerList = memberService.selectCenterList(); ModelAndView mv = setMV("staff/new"); mv.addObject("centerList", centerList); return mv; } @RequestMapping("/newRegist") public String staffNewRegist( @ModelAttribute("dto") final StaffDTO dto, @RequestParam(value="centerCode", required=true) String centerCode, @RequestParam(value="passwordConfirm", required=true) String passwordConfirm) throws Exception { String pw = dto.getPassword(); dto.setPassword(LifeCenterFunction.aesEncrypt(config.aesKey, config.IV, pw)); dto.setGroupIdx("3"); memberService.insertStaff(dto); return "redirect:./info?staffId=" + dto.getId(); } @RequestMapping("/info") public ModelAndView staffInfo( @RequestParam(value="staffId", required=false, defaultValue="") String staffID) { StaffDTO dto = new StaffDTO(); dto.setId(staffID); dto = memberService.selectMemberInfo(dto); ModelAndView mv = setMV("staff/info"); mv.addObject("info", dto); return mv; } @RequestMapping("/edit") public ModelAndView staffEdit( @RequestParam(value="staffId", required=false, defaultValue="") String staffId, @RequestParam(value="centerCode", required=false, defaultValue="") String centerCode, @RequestParam(value="groupIdx", required=false, defaultValue="") String groupIdx) { List centerList = memberService.selectCenterList(); StaffDTO dto = new StaffDTO(); dto.setId(staffId); dto = memberService.selectMemberInfo(dto); ModelAndView mv = setMV("staff/edit"); mv.addObject("info", dto); mv.addObject("centerCode", centerCode); mv.addObject("groupIdx", groupIdx); mv.addObject("centerList", centerList); return mv; } @RequestMapping("/myinfo") public ModelAndView staffMyinfo() { ModelAndView mv = setMV("staff/myinfo"); return mv; } @RequestMapping("/list") public ModelAndView staffList( @ModelAttribute("dto") final StaffDTO dto, @RequestParam(value="selectState", required=false, defaultValue="") String selectState, @RequestParam(value="sData", required=false, defaultValue="") String sData, @RequestParam(value="useYn", required=false, defaultValue="") String useYn, @RequestParam(value="page", required=false, defaultValue="1") int page) { logger.error("selectState -- > " + selectState); logger.error("sData -- > " + sData); logger.error("useYn -- > " + useYn); if (selectState.equals("sId")) { dto.setId(sData); } else if (selectState.equals("sName")) { dto.setName(sData); } else { dto.setCenterName(sData); } dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize ); dto.setLimitMax( config.pageDataSize ); int total = memberService.selectMemeberListCount(dto); List list = new ArrayList(); if (total > 0) { list = memberService.selectMemberList(dto); } String param = ""; paging = LifeCenterPaging.getInstance(); paging.paging(config, total, page, param); ModelAndView mv = setMV("staff/list"); mv.addObject("total", total); mv.addObject("selectState", selectState); mv.addObject("sData", sData); mv.addObject("useYn", useYn); mv.addObject("item", list); mv.addObject("paging", paging); return mv; } @RequestMapping( value="/duplicateIdCheck", method = RequestMethod.POST ) @ResponseBody public boolean duplicateIdCheck( @RequestParam( value="staffId", required = false, defaultValue = "" ) String id ) { boolean result = false; // false : 중복 , true : 중복아님 JSONObject obj = new JSONObject(); LoginDTO dto = new LoginDTO(); if( id.trim().equals( "" ) ) { result = false; } else { dto.setId( id.trim() ); int count = loginService.selectMemberIdCount( dto ); if( count == 0 ) { result = true; } } // obj.put( "result" , result ); return result; } }