package com.madeu.service.web.webtreatmentprocedure.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.madeu.dao.web.webtreatmentprocedureproduct.WebTreatmentProcedureProductSqlMapDAO;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.madeu.constants.Constants;
import com.madeu.dao.web.webauthmenurelation.WebAuthMenuRelationSqlMapDAO;
import com.madeu.dao.web.webmember.WebMemberSqlMapDAO;
import com.madeu.dao.web.webtreatment.WebTreatmentSqlMapDAO;
import com.madeu.dao.web.webtreatmentprocedure.WebTreatmentProcedureSqlMapDAO;
import com.madeu.dao.web.webtreatmentprocedurearea.WebTreatmentProcedureAreaSqlMapDAO;
import com.madeu.dao.web.webtreatmentproceduredoctor.WebTreatmentProcedureDoctorSqlMapDAO;
import com.madeu.dao.web.webtreatmentprocedureprice.WebTreatmentProcedurePriceSqlMapDAO;
import com.madeu.service.web.webtreatmentprocedure.WebTreatmentProcedureService;
import com.madeu.util.ValidationCheckUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("WebTreatmentProcedureService")
public class WebTreatmentProcedureServiceImpl implements WebTreatmentProcedureService {
	
	@Autowired
	private WebTreatmentProcedureSqlMapDAO webTreatmentProcedureSqlMapDAO;
	
	@Autowired
	private WebMemberSqlMapDAO webMemberSqlMapDAO;
	
	@Autowired
	private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;
	
	@Autowired
	private WebTreatmentProcedureAreaSqlMapDAO webTreatmentProcedureAreaSqlMapDAO;
	
	@Autowired
	private WebTreatmentProcedurePriceSqlMapDAO webTreatmentProcedurePriceSqlMapDAO;
	
	@Autowired
	private WebTreatmentProcedureDoctorSqlMapDAO webTreatmentProcedureDoctorSqlMapDAO;
	@Autowired

	private WebTreatmentProcedureProductSqlMapDAO webTreatmentProcedureProductSqlMapDAO;

	@Autowired
	private WebTreatmentSqlMapDAO webTreatmentSqlMapDAO;
	

	/**
	 * 진료 시술 리스트 조회 (List, option)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListTreatmentProcedureOption(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebTreatmentProcedureServiceImpl selectListTreatmentProcedureOption START");

		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("treatmentProcedureSearchKeywordParam  :"+paramMap.get("treatmentProcedureSearchKeywordParam"));
		log.debug("treatmentProcedureSort                :"+paramMap.get("treatmentProcedureSort"));
		log.debug("treatmentProcedureStart               :"+paramMap.get("treatmentProcedureStart"));
		log.debug("treatmentProcedureLimit               :"+paramMap.get("treatmentProcedureLimit"));
		log.debug("treatmentProcedureSort                :"+paramMap.get("treatmentProcedureSort"));
		log.debug("treatmentProcedureDir                 :"+paramMap.get("treatmentProcedureDir"));
		log.debug("treatmentProcedureCurrentPage         :"+paramMap.get("treatmentProcedureCurrentPage"));

		List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

		try{
			boolean check  = true;
			
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 정렬 
				if(null==paramMap.get("treatmentProcedureDir")||("").equals(paramMap.get("treatmentProcedureDir"))){
					
				}
				else{
					String dir = String.valueOf(paramMap.get("treatmentProcedureDir"));
					if(("A").equals(dir)){
						paramMap.put("treatmentProcedureDir", "DESC");
					}
					else if(("B").equals(dir)){
						paramMap.put("treatmentProcedureDir", "ASC");
					}
					else {
						paramMap.put("treatmentProcedureDir", "DESC");
					}
				}
				
				paramMap.put("useYn", "Y");
				
				List<Map<String, Object>> totalCountListMap = webTreatmentProcedureSqlMapDAO.selectTotalTreatmentProcedureOptionCount(paramMap);
				int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0).get("totalCount")));
				
				if(0 < totalCount) {
					// 리스트 조회
					listMap = webTreatmentProcedureSqlMapDAO.selectListTreatmentProcedureOption(paramMap);
				}
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("totalCount", totalCount);
				map.put("rows",listMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebTreatmentProcedureServiceImpl selectListTreatmentProcedureOption END");
		return map;
	}

	/**
	 * 진료 시술 리스트 조회 2 (List, option, 페이징처리X)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListTreatmentProcedureOption2(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebTreatmentProcedureServiceImpl selectListTreatmentProcedureOption2 START");

		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("muTreatmentId       :"+paramMap.get("muTreatmentId"));

		try{
			boolean check  = true;

			String muTreatmentId = String.valueOf(paramMap.get("muTreatmentId"));
			String muTreatmentIdList = "";
			
			if(true != ValidationCheckUtil.emptyCheck(muTreatmentId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","진료 정보가 없습니다.");
			}else{
				String [] muTreatmentIdArr = muTreatmentId.split(",");
				for(int i=0; i<muTreatmentIdArr.length; i++){
					muTreatmentIdList = muTreatmentIdList.concat("'").concat(muTreatmentIdArr[i]).concat("',");
				}

				muTreatmentIdList = muTreatmentIdList.substring(0, muTreatmentIdList.lastIndexOf(","));
				paramMap.put("muTreatmentIdList", muTreatmentIdList);
			}
			
			if(true == check){
				List<Map<String, Object>> listMap = webTreatmentProcedureSqlMapDAO.selectListTreatmentProcedureOption2(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebTreatmentProcedureServiceImpl selectListTreatmentProcedureOption2 END");
		return map;
	}
	
	/**
	 * 진료 시술 리스트 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListTreatmentProcedure(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebTreatmentProcedureServiceImpl selectListTreatmentProcedure START");

		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("treatmentProcedureSearchKeywordParam  :"+paramMap.get("treatmentProcedureSearchKeywordParam"));
		log.debug("treatmentProcedureStart               :"+paramMap.get("treatmentProcedureStart"));
		log.debug("treatmentProcedureLimit               :"+paramMap.get("treatmentProcedureLimit"));
		log.debug("treatmentProcedureSort                :"+paramMap.get("treatmentProcedureSort"));
		log.debug("treatmentProcedureDir                 :"+paramMap.get("treatmentProcedureDir"));
		log.debug("treatmentProcedureCurrentPage         :"+paramMap.get("treatmentProcedureCurrentPage"));
		
		log.debug("muTreatmentId                         :"+paramMap.get("muTreatmentId"));
		
		List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();
		
		try{
			boolean check  = true;

			String muTreatmentId    = String.valueOf(paramMap.get("muTreatmentId"));
			
			if(true != ValidationCheckUtil.emptyCheck(muTreatmentId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","진료 정보가 없습니다.");
			}
			
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){

				List<Map<String, Object>> treatmentListMap = webTreatmentSqlMapDAO.selectTreatment(paramMap);
				
				if(1==treatmentListMap.size()) {
					// 정렬 
					if(null==paramMap.get("treatmentProcedureDir")||("").equals(paramMap.get("treatmentProcedureDir"))){
						
					}
					else{
						String dir = String.valueOf(paramMap.get("treatmentProcedureDir"));
						if(("A").equals(dir)){
							paramMap.put("treatmentProcedureDir", "DESC");
						}
						else if(("B").equals(dir)){
							paramMap.put("treatmentProcedureDir", "ASC");
						}
						else {
							paramMap.put("treatmentProcedureDir", "DESC");
						}
					}
					
					paramMap.put("useYn", "Y");
					
					List<Map<String, Object>> totalCountListMap = webTreatmentProcedureSqlMapDAO.selectTotalTreatmentProcedureCount(paramMap);
					int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0).get("totalCount")));
					
					if(0 < totalCount) {
						// 리스트 조회
						listMap = webTreatmentProcedureSqlMapDAO.selectListTreatmentProcedure(paramMap);
					}
					
					map.put("msgCode", Constants.OK);
					map.put("success","true");
					map.put("totalCount", totalCount);
					map.put("rows",listMap);
					map.put("treatmentName",treatmentListMap.get(0).get("treatmentName"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "진료 정보가 없습니다.");
				}
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebTreatmentProcedureServiceImpl selectListTreatmentProcedure END");
		return map;
	}
	
	/**
	 * 진료 시술 정보 상세 조회 (one)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectTreatmentProcedure(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebTreatmentProcedureServiceImpl selectTreatmentProcedure START");

		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId          :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass              :"+paramMap.get("menuClass"));
		
		log.debug("muTreatmentProcedureId :"+paramMap.get("muTreatmentProcedureId"));

		try{
			boolean check  = true;
			String muTreatmentProcedureId    = String.valueOf(paramMap.get("muTreatmentProcedureId"));
			
			// 정렬
			if(true != ValidationCheckUtil.emptyCheck(muTreatmentProcedureId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","진료 시술 정보가 없습니다.");
			}
			
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				List<Map<String, Object>> listMap = webTreatmentProcedureSqlMapDAO.selectTreatmentProcedure(paramMap);
				int listMapSize = listMap.size();
				
				if(1 == listMapSize) {
					// 시술약품
					List<Map<String, Object>> productListMap = webTreatmentProcedureProductSqlMapDAO.selectListTreatmentProcedureProduct(paramMap);
					listMap.get(0).put("productRows", productListMap);
					
					// 시술단가
					List<Map<String, Object>> priceListMap = webTreatmentProcedurePriceSqlMapDAO.selectListTreatmentProcedurePrice(paramMap);
					listMap.get(0).put("priceRows", priceListMap);
					
					// 시술닥터
					List<Map<String, Object>> doctorListMap = webTreatmentProcedureDoctorSqlMapDAO.selectListTreatmentProcedureDoctor(paramMap);
					listMap.get(0).put("doctorRows", doctorListMap);
				}
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
			}

		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}

		log.debug("WebTreatmentProcedureServiceImpl selectTreatmentProcedure END");
		return map;
	}
	
	/**
	 * 진료 시술 정보 등록
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> insertTreatmentProcedure(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebTreatmentProcedureServiceImpl insertTreatmentProcedure START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId          :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass              :"+paramMap.get("menuClass"));

		log.debug("muTreatmentId          :"+paramMap.get("muTreatmentId"));
		log.debug("procedureName          :"+paramMap.get("procedureName"));
		log.debug("insuranceType          :"+paramMap.get("insuranceType"));
		log.debug("price          		  :"+paramMap.get("price"));
		log.debug("discountprice          		  :"+paramMap.get("discountprice"));
		log.debug("vat                    :"+paramMap.get("vat"));

		log.debug("productRows            :"+paramMap.get("productRows"));
		log.debug("doctorRows             :"+paramMap.get("doctorRows"));

		try{
			boolean check  = true;
			String tId = String.valueOf(System.currentTimeMillis());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c1 = Calendar.getInstance();
			String tDate = sdf.format(c1.getTime());

			String muTreatmentId          = String.valueOf(paramMap.get("muTreatmentId"));
			String procedureName          = String.valueOf(paramMap.get("procedureName"));

			if(true != ValidationCheckUtil.emptyCheck(muTreatmentId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","진료 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(procedureName)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술명 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.lengthCheck(procedureName,50)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","시술명 정보는 50자를 넘을 수 없습니다.");
				}
			}
			
			// 상세 정보 확인
			// 약품
			JSONParser jsonParserTemp = new JSONParser();
			JSONObject jsonObjectTemp = (JSONObject) jsonParserTemp.parse(String.valueOf(paramMap.get("productRows")));
			if(jsonObjectTemp == null ||jsonObjectTemp.isEmpty()) {
//				check = false;
//				map.put("msgCode", Constants.FAIL);
//				map.put("msgDesc","약품 정보가 없습니다.");
			}
			else {
				JSONArray detailArray = (JSONArray) jsonObjectTemp.get("data");
				
				for(int j=0; j<detailArray.size(); j++){
					JSONObject detailObject = (JSONObject) detailArray.get(j);
					
					String orderNumber       = String.valueOf(detailObject.get("orderNumber"));
					String productName 		 = String.valueOf(detailObject.get("productName"));
					String productUseVolume  = String.valueOf(detailObject.get("productUseVolume"));

					if(true != ValidationCheckUtil.emptyCheck(orderNumber)){
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc","약품의 정렬순번 정보가 없습니다.");
					}
				}
			}
			
			// 시술단가
			String insuranceType       = String.valueOf(paramMap.get("insuranceType"));
			String price             = String.valueOf(paramMap.get("price"));
			String discountprice             = String.valueOf(paramMap.get("discountprice"));
			String vat               = String.valueOf(paramMap.get("vat"));

			if(true != ValidationCheckUtil.emptyCheck(insuranceType)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술단가의 선택 정보가 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(price)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술단가의 단가 정보가 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(vat)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술단가의 Vat 정보가 없습니다.");
			}

			// 닥터
			JSONParser jsonParserTemp3 = new JSONParser();
			JSONObject jsonObjectTemp3 = (JSONObject) jsonParserTemp3.parse(String.valueOf(paramMap.get("doctorRows")));
			if(jsonObjectTemp3 == null ||jsonObjectTemp3.isEmpty()) {
//				check = false;
//				map.put("msgCode", Constants.FAIL);
//				map.put("msgDesc","닥터 정보가 없습니다.");
			}
			else {
				JSONArray detailArray = (JSONArray) jsonObjectTemp3.get("data");
				
				for(int j=0; j<detailArray.size(); j++){
					JSONObject detailObject = (JSONObject) detailArray.get(j);
					
					String orderNumber       = String.valueOf(detailObject.get("orderNumber"));
					String muMemberId        = String.valueOf(detailObject.get("muMemberId"));
					
					if(true != ValidationCheckUtil.emptyCheck(orderNumber)){
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc","닥터의 정렬순번 정보가 없습니다.");
					}

//					if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
//						check = false;
//						map.put("msgCode", Constants.FAIL);
//						map.put("msgDesc","닥터의 닥터 정보가 없습니다.");
//					}
				}
			}
			ObjectMapper mapper = new ObjectMapper();
			JsonNode rootNode = mapper.readTree(String.valueOf(paramMap.get("productRows")));
			JsonNode dataNode = rootNode.path("data");
			List<HashMap<String, Object>> products = mapper.convertValue(dataNode, new TypeReference<List<HashMap<String, Object>>>(){});
			String productNames="";
			String volumes="";
			String unitNames="";

			if(products!=null) {
				// productName을 정렬하여 문자열로 변환
				productNames = products.stream()
						.map(p -> (String) p.get("productName"))
						.sorted()
						.collect(Collectors.joining(", "));

				// productUseVolume을 정렬하여 문자열로 변환
				volumes = products.stream()
						.map(p -> (String) p.get("productUseVolume"))
						.sorted()
						.collect(Collectors.joining(", "));

				unitNames = products.stream()
						.map(p -> (String) p.get("unitName"))
						.sorted()
						.collect(Collectors.joining(", "));
			}
			HashMap<String, Object> procedureDuplicateCheckMap = new HashMap<String, Object>();
			procedureDuplicateCheckMap.put("procedureName",procedureName);
			procedureDuplicateCheckMap.put("insuranceType",insuranceType);
			procedureDuplicateCheckMap.put("price",price);
			procedureDuplicateCheckMap.put("discountprice",discountprice);
			procedureDuplicateCheckMap.put("vat",vat);
			procedureDuplicateCheckMap.put("productNames",productNames);
			procedureDuplicateCheckMap.put("volumes",volumes);
			procedureDuplicateCheckMap.put("unitName",unitNames);

//			진료항목에 중복된 시술명 확인
			if(0<webTreatmentProcedureSqlMapDAO.selectTreatmentProcedureCount(procedureDuplicateCheckMap)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc", "이미 등록된 시술입니다.");
			}
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
				int authMenuRelationlistMapSize = authMenuRelationlistMap.size();
				
				if(1==authMenuRelationlistMapSize){
					
					if(("Y").equals(authMenuRelationlistMap.get(0).get("insertUseYn"))) {
						
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "등록 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}

			if(true == check){
				paramMap.put("tDate", tDate);
				paramMap.put("tId", tId);

				//  시술정보 등록
				String muTreatmentProcedureId = ("TP").concat(String.valueOf(System.currentTimeMillis()));
				paramMap.put("muTreatmentProcedureId",muTreatmentProcedureId);
				paramMap.put("muMemberId", paramMap.get("loginMemberId"));
				paramMap.put("enableYn", "Y");
				webTreatmentProcedureSqlMapDAO.insertTreatmentProcedure(paramMap);

				log.debug("muTreatmentProcedureId :"+paramMap.get("id"));
				paramMap.put("muTreatmentProcedureId", paramMap.get("id"));
				map.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));


				//시술단가 등록
				if( (null!=insuranceType&&!("").equals(insuranceType))
						||(null!=price&&!("").equals(price))
						||(null!=vat&&!("").equals(vat))) {
					HashMap<String, Object> TreatmentProcedurePriceParamMap = new HashMap<String, Object>();
					String muTreatmentProcedurePriceId = ("TPP").concat(String.valueOf(System.currentTimeMillis()));
					TreatmentProcedurePriceParamMap.put("tId",tId);
					TreatmentProcedurePriceParamMap.put("muTreatmentProcedurePriceId",muTreatmentProcedurePriceId);
					TreatmentProcedurePriceParamMap.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
					TreatmentProcedurePriceParamMap.put("insuranceType", insuranceType);
					TreatmentProcedurePriceParamMap.put("price", price);
					TreatmentProcedurePriceParamMap.put("discountprice", discountprice);
					TreatmentProcedurePriceParamMap.put("vat", vat);
					TreatmentProcedurePriceParamMap.put("regId", paramMap.get("regId"));
					TreatmentProcedurePriceParamMap.put("modId", paramMap.get("modId"));
					TreatmentProcedurePriceParamMap.put("tId", paramMap.get("tId"));
					TreatmentProcedurePriceParamMap.put("tDate", paramMap.get("tDate"));
					webTreatmentProcedurePriceSqlMapDAO.insertTreatmentProcedurePrice(TreatmentProcedurePriceParamMap);
				}

				// 닥터 등록
				JSONParser jsonParser3 = new JSONParser();
				JSONObject jsonObject3 = (JSONObject) jsonParser3.parse(String.valueOf(paramMap.get("doctorRows")));
				if(jsonObjectTemp3 != null && !jsonObjectTemp3.isEmpty()) {
					JSONArray detailArray3 = (JSONArray) jsonObject3.get("data");

					for (int j = 0; j < detailArray3.size(); j++) {
						JSONObject detailObject = (JSONObject) detailArray3.get(j);

						String orderNumber = String.valueOf(detailObject.get("orderNumber"));
						String muMemberId = String.valueOf(detailObject.get("muMemberId"));

						if ((null != orderNumber && !("").equals(orderNumber))
								|| (null != muMemberId && !("").equals(muMemberId))) {
							HashMap<String, Object> TreatmentProcedureDoctorParamMap = new HashMap<String, Object>();
							String muTreatmentProcedureDoctorId = ("TPD").concat(String.valueOf(System.currentTimeMillis()));
							TreatmentProcedureDoctorParamMap.put("tId", tId);
							TreatmentProcedureDoctorParamMap.put("muTreatmentProcedureDoctorId", muTreatmentProcedureDoctorId);
							TreatmentProcedureDoctorParamMap.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
							TreatmentProcedureDoctorParamMap.put("orderNumber", orderNumber);
							TreatmentProcedureDoctorParamMap.put("muMemberId", muMemberId);
							TreatmentProcedureDoctorParamMap.put("regId", paramMap.get("regId"));
							TreatmentProcedureDoctorParamMap.put("modId", paramMap.get("modId"));
							TreatmentProcedureDoctorParamMap.put("tId", paramMap.get("tId"));
							TreatmentProcedureDoctorParamMap.put("tDate", paramMap.get("tDate"));
							webTreatmentProcedureDoctorSqlMapDAO.insertTreatmentProcedureDoctor(TreatmentProcedureDoctorParamMap);
						}
					}
				}
				// 약품 등록
				JSONParser jsonParser4 = new JSONParser();
				JSONObject jsonObject4 = (JSONObject) jsonParser4.parse(String.valueOf(paramMap.get("productRows")));
				if(jsonObject4 != null && !jsonObject4.isEmpty()) {
					JSONArray detailArray4 = (JSONArray) jsonObject4.get("data");

					for(int j=0; j<detailArray4.size(); j++) {
						JSONObject detailObject = (JSONObject) detailArray4.get(j);

						String orderNumber = String.valueOf(detailObject.get("orderNumber"));
						String productName = String.valueOf(detailObject.get("productName"));
						String muProductId = String.valueOf(detailObject.get("muProductId"));
						String productUseVolume = String.valueOf(detailObject.get("productUseVolume"));
						String unitName 	= String.valueOf(detailObject.get("unitName"));
						String unitCode 	= String.valueOf(detailObject.get("unitCode"));

						if ((null != orderNumber && !("").equals(orderNumber))
								|| (null != productName && !("").equals(productName))
								|| (null != muProductId && !("").equals(muProductId))
								|| (null != productUseVolume && !("").equals(productUseVolume))
								|| (null != unitName && !("").equals(unitName))
								|| (null != unitCode && !("").equals(unitCode))) {
							HashMap<String, Object> TreatmentProcedureProductParamMap = new HashMap<String, Object>();
							String muTreatmentProcedureProductId = ("TPP").concat(String.valueOf(System.currentTimeMillis()));
							TreatmentProcedureProductParamMap.put("tId", tId);
							TreatmentProcedureProductParamMap.put("muTreatmentProcedureProductId", muTreatmentProcedureProductId);
							TreatmentProcedureProductParamMap.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
							TreatmentProcedureProductParamMap.put("orderNumber", orderNumber);
							TreatmentProcedureProductParamMap.put("productName", productName);
							TreatmentProcedureProductParamMap.put("muProductId", muProductId);
							TreatmentProcedureProductParamMap.put("productUseVolume", productUseVolume);
							TreatmentProcedureProductParamMap.put("unitName", unitName);
							TreatmentProcedureProductParamMap.put("unitCode", unitCode);
							TreatmentProcedureProductParamMap.put("regId", paramMap.get("regId"));
							TreatmentProcedureProductParamMap.put("modId", paramMap.get("modId"));
							TreatmentProcedureProductParamMap.put("tId", paramMap.get("tId"));
							TreatmentProcedureProductParamMap.put("tDate", paramMap.get("tDate"));
							webTreatmentProcedureProductSqlMapDAO.insertTreatmentProcedureProduct(TreatmentProcedureProductParamMap);
						}
					}
				}
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "등록되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebTreatmentProcedureServiceImpl insertTreatmentProcedure END");
		return map;
	}

	/**
	 * 진료 시술 정보 수정
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateTreatmentProcedure(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebTreatmentProcedureServiceImpl updateTreatmentProcedure START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		log.debug("loginMemberId          :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass              :"+paramMap.get("menuClass"));
		
		log.debug("muTreatmentProcedureId :"+paramMap.get("muTreatmentProcedureId"));
		
		log.debug("muTreatmentId          :"+paramMap.get("muTreatmentId"));
		log.debug("procedureName          :"+paramMap.get("procedureName"));
		log.debug("insuranceType          :"+paramMap.get("insuranceType"));
		log.debug("price          		  :"+paramMap.get("price"));
		log.debug("discountprice          		  :"+paramMap.get("discountprice"));
		log.debug("vat                    :"+paramMap.get("vat"));

		log.debug("productRows            :"+paramMap.get("productRows"));
		log.debug("doctorRows             :"+paramMap.get("doctorRows"));

		try{
			boolean check  = true;
			String tId = String.valueOf(System.currentTimeMillis());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c1 = Calendar.getInstance();
			String tDate = sdf.format(c1.getTime());

			String muTreatmentProcedureId = String.valueOf(paramMap.get("muTreatmentProcedureId"));
			String muTreatmentId          = String.valueOf(paramMap.get("muTreatmentId"));
			String procedureName          = String.valueOf(paramMap.get("procedureName"));

			if(true != ValidationCheckUtil.emptyCheck(muTreatmentProcedureId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","진료 시술 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muTreatmentId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","진료 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(procedureName)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술명 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.lengthCheck(procedureName,50)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","시술명 정보는 50자를 넘을 수 없습니다.");
				}
			}
			
			// 상세 정보 확인
			// 약품
			JSONParser jsonParserTemp = new JSONParser();
			JSONObject jsonObjectTemp = (JSONObject) jsonParserTemp.parse(String.valueOf(paramMap.get("productRows")));
			if(true == jsonObjectTemp.isEmpty()) {
//				check = false;
//				map.put("msgCode", Constants.FAIL);
//				map.put("msgDesc","약품 정보가 없습니다.");
			}
			else {
				JSONArray detailArray = (JSONArray) jsonObjectTemp.get("data");
				
				for(int j=0; j<detailArray.size(); j++){
					JSONObject detailObject = (JSONObject) detailArray.get(j);
					
					String orderNumber       = String.valueOf(detailObject.get("orderNumber"));
					String productName 		 = String.valueOf(detailObject.get("productName"));
					String productUseVolume  = String.valueOf(detailObject.get("productUseVolume"));

					if(true != ValidationCheckUtil.emptyCheck(orderNumber)){
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc","약품의 정렬순번 정보가 없습니다.");
					}
				}
			}
			
			// 시술단가
			String insuranceType       = String.valueOf(paramMap.get("insuranceType"));
			String price             = String.valueOf(paramMap.get("price"));
			String discountprice             = String.valueOf(paramMap.get("discountprice"));
			String vat               = String.valueOf(paramMap.get("vat"));

			if(true != ValidationCheckUtil.emptyCheck(insuranceType)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술단가의 선택 정보가 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(price)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술단가의 단가 정보가 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(vat)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술단가의 Vat 정보가 없습니다.");
			}

			// 닥터
			JSONParser jsonParserTemp3 = new JSONParser();
			JSONObject jsonObjectTemp3 = (JSONObject) jsonParserTemp3.parse(String.valueOf(paramMap.get("doctorRows")));
			if(true == jsonObjectTemp3.isEmpty()) {
//				check = false;
//				map.put("msgCode", Constants.FAIL);
//				map.put("msgDesc","닥터 정보가 없습니다.");
			}
			else {
				JSONArray detailArray = (JSONArray) jsonObjectTemp3.get("data");
				
				for(int j=0; j<detailArray.size(); j++){
					JSONObject detailObject = (JSONObject) detailArray.get(j);
					
					String orderNumber       = String.valueOf(detailObject.get("orderNumber"));
					String muMemberId        = String.valueOf(detailObject.get("muMemberId"));
					
					if(true != ValidationCheckUtil.emptyCheck(orderNumber)){
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc","닥터의 정렬순번 정보가 없습니다.");
					}

//					if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
//						check = false;
//						map.put("msgCode", Constants.FAIL);
//						map.put("msgDesc","닥터의 닥터 정보가 없습니다.");
//					}
				}
			}

			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
				int authMenuRelationlistMapSize = authMenuRelationlistMap.size();
				
				if(1==authMenuRelationlistMapSize){
					
					if(("Y").equals(authMenuRelationlistMap.get(0).get("updateUseYn"))) {
						
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "수정 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}
			
			if(true == check){
				paramMap.put("tDate", tDate);
				paramMap.put("tId", tId);
				
				webTreatmentProcedureSqlMapDAO.updateTreatmentProcedure(paramMap);
				map.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
				
				// 시술부위 삭제
				webTreatmentProcedureProductSqlMapDAO.deleteTreatmentProcedureProduct(paramMap);
				// 시술단가 삭제
				webTreatmentProcedurePriceSqlMapDAO.deleteTreatmentProcedurePrice(paramMap);
				// 닥터 삭제
				webTreatmentProcedureDoctorSqlMapDAO.deleteTreatmentProcedureDoctor(paramMap);

				if( (null!=insuranceType&&!("").equals(insuranceType))
						||(null!=price&&!("").equals(price))
						||(null!=vat&&!("").equals(vat))) {
					HashMap<String, Object> TreatmentProcedurePriceParamMap = new HashMap<String, Object>();
					String muTreatmentProcedurePriceId = ("TPP").concat(String.valueOf(System.currentTimeMillis()));
					TreatmentProcedurePriceParamMap.put("tId",tId);
					TreatmentProcedurePriceParamMap.put("muTreatmentProcedurePriceId",muTreatmentProcedurePriceId);
					TreatmentProcedurePriceParamMap.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
					TreatmentProcedurePriceParamMap.put("insuranceType", insuranceType);
					TreatmentProcedurePriceParamMap.put("price", price);
					TreatmentProcedurePriceParamMap.put("discountprice", discountprice);
					TreatmentProcedurePriceParamMap.put("vat", vat);
					TreatmentProcedurePriceParamMap.put("regId", paramMap.get("regId"));
					TreatmentProcedurePriceParamMap.put("modId", paramMap.get("modId"));
					TreatmentProcedurePriceParamMap.put("tId", paramMap.get("tId"));
					TreatmentProcedurePriceParamMap.put("tDate", paramMap.get("tDate"));
					webTreatmentProcedurePriceSqlMapDAO.insertTreatmentProcedurePrice(TreatmentProcedurePriceParamMap);
				}

				// 닥터 등록
				JSONParser jsonParser3 = new JSONParser();
				JSONObject jsonObject3 = (JSONObject) jsonParser3.parse(String.valueOf(paramMap.get("doctorRows")));
				if(jsonObjectTemp3 != null && !jsonObjectTemp3.isEmpty()) {
					JSONArray detailArray3 = (JSONArray) jsonObject3.get("data");
					for(int j=0; j<detailArray3.size(); j++){
						JSONObject detailObject = (JSONObject) detailArray3.get(j);

						String orderNumber       = String.valueOf(detailObject.get("orderNumber"));
						String muMemberId        = String.valueOf(detailObject.get("muMemberId"));
						
						if( (null!=orderNumber&&!("").equals(orderNumber))
								||(null!=muMemberId&&!("").equals(muMemberId))) {
							HashMap<String, Object> TreatmentProcedureDoctorParamMap = new HashMap<String, Object>();
							String muTreatmentProcedureDoctorId = ("TPD").concat(String.valueOf(System.currentTimeMillis()));
							TreatmentProcedureDoctorParamMap.put("tId",tId);
							TreatmentProcedureDoctorParamMap.put("muTreatmentProcedureDoctorId",muTreatmentProcedureDoctorId);
							TreatmentProcedureDoctorParamMap.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
							TreatmentProcedureDoctorParamMap.put("orderNumber", orderNumber);
							TreatmentProcedureDoctorParamMap.put("muMemberId", muMemberId);
							TreatmentProcedureDoctorParamMap.put("regId", paramMap.get("regId"));
							TreatmentProcedureDoctorParamMap.put("modId", paramMap.get("modId"));
							TreatmentProcedureDoctorParamMap.put("tId", paramMap.get("tId"));
							TreatmentProcedureDoctorParamMap.put("tDate", paramMap.get("tDate"));
							webTreatmentProcedureDoctorSqlMapDAO.insertTreatmentProcedureDoctor(TreatmentProcedureDoctorParamMap);
						}
					}
				}
				
				
				// 약품 등록
				JSONParser jsonParser4 = new JSONParser();
				JSONObject jsonObject4 = (JSONObject) jsonParser4.parse(String.valueOf(paramMap.get("productRows")));
				if(jsonObject4 != null && !jsonObject4.isEmpty()) {
					JSONArray detailArray4 = (JSONArray) jsonObject4.get("data");

					for(int j=0; j<detailArray4.size(); j++){
						JSONObject detailObject = (JSONObject) detailArray4.get(j);

						String orderNumber      = String.valueOf(detailObject.get("orderNumber"));
						String productName      = String.valueOf(detailObject.get("productName"));
						String muProductId      = String.valueOf(detailObject.get("muProductId"));
						String productUseVolume = String.valueOf(detailObject.get("productUseVolume"));
						String unitCode         = String.valueOf(detailObject.get("unitCode"));
						String unitName         = String.valueOf(detailObject.get("unitName"));

						if( (null!=orderNumber&&!("").equals(orderNumber))
								||(null!=productName&&!("").equals(productName))
								||(null!=muProductId&&!("").equals(muProductId))
								||(null!=productUseVolume&&!("").equals(productUseVolume))
								||(null!=unitCode&&!("").equals(unitCode))
								||(null!=unitName&&!("").equals(unitName))) {
							HashMap<String, Object> TreatmentProcedureProductParamMap = new HashMap<String, Object>();
							String muTreatmentProcedureProductId = ("TPP").concat(String.valueOf(System.currentTimeMillis()));
							TreatmentProcedureProductParamMap.put("tId",tId);
							TreatmentProcedureProductParamMap.put("muTreatmentProcedureProductId",muTreatmentProcedureProductId);
							TreatmentProcedureProductParamMap.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
							TreatmentProcedureProductParamMap.put("orderNumber", orderNumber);
							TreatmentProcedureProductParamMap.put("productName", productName);
							TreatmentProcedureProductParamMap.put("muProductId", muProductId);
							TreatmentProcedureProductParamMap.put("productUseVolume", productUseVolume);
							TreatmentProcedureProductParamMap.put("unitCode", unitCode);
							TreatmentProcedureProductParamMap.put("unitName", unitName);
							TreatmentProcedureProductParamMap.put("regId", paramMap.get("regId"));
							TreatmentProcedureProductParamMap.put("modId", paramMap.get("modId"));
							TreatmentProcedureProductParamMap.put("tId", paramMap.get("tId"));
							TreatmentProcedureProductParamMap.put("tDate", paramMap.get("tDate"));
							webTreatmentProcedureProductSqlMapDAO.insertTreatmentProcedureProduct(TreatmentProcedureProductParamMap);
						}
					}
				}
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "수정되었습니다.");
			}
			
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebTreatmentProcedureServiceImpl updateTreatmentProcedure END");
		return map;
	}

	/**
	 * 진료 시술 정보 활성화/비활성화
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateTreatmentProcedureEnableYn(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebTreatmentProcedureServiceImpl updateTreatmentProcedureEnableYn START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId          :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass              :"+paramMap.get("menuClass"));
		
		// ,로 구분
		log.debug("selectId               :"+paramMap.get("selectId"));
		log.debug("enableYn               :"+paramMap.get("enableYn"));
		
		try{
			boolean check  = true;
			
			String selectId          = String.valueOf(paramMap.get("selectId"));
			String enableYn          = String.valueOf(paramMap.get("enableYn"));

			if(true != ValidationCheckUtil.emptyCheck(selectId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc", "비활성화 대상이 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(enableYn)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc", "활성/비활성화 정보가 없습니다.");
			}

			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
				int authMenuRelationlistMapSize = authMenuRelationlistMap.size();
				
				if(1==authMenuRelationlistMapSize){
					
					if(("Y").equals(authMenuRelationlistMap.get(0).get("updateUseYn"))) {
						
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "수정 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}
			
			if(true == check){
				StringTokenizer selectData = new StringTokenizer(selectId, ",");
				while(selectData.hasMoreTokens()){//토큰이 계속 있을때 까지
					String muTreatmentProcedureId = selectData.nextToken();
					
					HashMap<String, Object> updateParamMap = new HashMap<String, Object>();
					updateParamMap.put("muTreatmentProcedureId", muTreatmentProcedureId);
					updateParamMap.put("enableYn", enableYn);
					updateParamMap.put("modId", paramMap.get("loginMemberId"));
					webTreatmentProcedureSqlMapDAO.updateTreatmentProcedureEnableYn(updateParamMap);
				}
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "처리 되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebTreatmentProcedureServiceImpl updateTreatmentProcedureEnableYn END");
		return map;
	}

	/**
	 * 진료 시술 정보 진료 이동
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateTreatmentProcedureTreatmentId(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebTreatmentProcedureServiceImpl updateTreatmentProcedureTreatmentId START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId          :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass              :"+paramMap.get("menuClass"));
		
		// ,로 구분
		log.debug("selectId               :"+paramMap.get("selectId"));
		log.debug("muTreatmentId          :"+paramMap.get("muTreatmentId"));
		
		try{
			boolean check  = true;
			
			String selectId          = String.valueOf(paramMap.get("selectId"));
			String muTreatmentId     = String.valueOf(paramMap.get("muTreatmentId"));

			if(true != ValidationCheckUtil.emptyCheck(selectId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc", "비활성화 대상이 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(muTreatmentId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc", "진료이동 정보가 없습니다.");
			}

			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
				int authMenuRelationlistMapSize = authMenuRelationlistMap.size();
				
				if(1==authMenuRelationlistMapSize){
					
					if(("Y").equals(authMenuRelationlistMap.get(0).get("updateUseYn"))) {
						
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "수정 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}
			
			if(true == check){
				StringTokenizer selectData = new StringTokenizer(selectId, ",");
				while(selectData.hasMoreTokens()){//토큰이 계속 있을때 까지
					String muTreatmentProcedureId = selectData.nextToken();
					
					HashMap<String, Object> updateParamMap = new HashMap<String, Object>();
					updateParamMap.put("muTreatmentProcedureId", muTreatmentProcedureId);
					updateParamMap.put("muTreatmentId", muTreatmentId);
					updateParamMap.put("modId", paramMap.get("loginMemberId"));
					webTreatmentProcedureSqlMapDAO.updateTreatmentProcedureTreatmentId(updateParamMap);
				}
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "이동 되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebTreatmentProcedureServiceImpl updateTreatmentProcedureTreatmentId END");
		return map;
	}
}
