package com.madeu.crm.contentsBbs.service.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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.madeu.common.dao.CommonDao;
import com.madeu.common.service.AttachFileService;
import com.madeu.constants.Constants;
import com.madeu.crm.contentsBbs.service.ContentsBbsService;
import com.madeu.dao.web.webauthmenurelation.WebAuthMenuRelationSqlMapDAO;
import com.madeu.dao.web.webmember.WebMemberSqlMapDAO;
import com.madeu.service.common.file.FileService;
import com.madeu.util.ValidationCheckUtil;

import io.micrometer.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("ContentsBbsService")
public class ContentsBbsServiceImpl implements ContentsBbsService {

	/*
	 * @Autowired private WebTreatmentPetitSqlMapDAO webTreatmentPetitSqlMapDAO;
	 */
    
    @Autowired
    private CommonDao cmmnDAO;
    
    @Autowired
    private WebMemberSqlMapDAO webMemberSqlMapDAO;

    @Autowired
    private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;

    @Autowired
    private FileService fileService;
    
    @Autowired
    private AttachFileService afs;
    
    
	@Value("${url.cdn}")
	String CDN_URL;

    /**
     * 홈페이지 시술예약(쁘띠) 리스트 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListWebTreatmentPetitIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebTreatmentPetitServiceImpl selectListWebTreatmentPetitIntro START");

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

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

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

        try{
            boolean check  = true;

            String menuClass    = String.valueOf(paramMap.get("menuClass"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(menuClass)){
                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){
                    map.put("msgCode", Constants.OK);
                    map.put("success","true");

                    map.put("selectUseYn", authMenuRelationlistMap.get(0).get("selectUseYn"));
                    map.put("insertUseYn", authMenuRelationlistMap.get(0).get("insertUseYn"));
                    map.put("updateUseYn", authMenuRelationlistMap.get(0).get("updateUseYn"));
                    map.put("deleteUseYn", authMenuRelationlistMap.get(0).get("deleteUseYn"));
                    map.put("downloadUseYn", authMenuRelationlistMap.get(0).get("downloadUseYn"));
                }
                else {
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebTreatmentPetitServiceImpl selectListWebTreatmentPetitIntro END");
        return map;
    }

    /**
     * 홈페이지 시술예약(쁘띠) 리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> getContentsBbsList(HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebTreatmentPetitServiceImpl selectListWebTreatmentPetit START");

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

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

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

        log.debug("webTreatmentPetitSearchKeywordParam  :"+paramMap.get("webTreatmentPetitSearchKeywordParam"));
        log.debug("webTreatmentPetitSort                :"+paramMap.get("webTreatmentPetitSort"));
        log.debug("webTreatmentPetitStart               :"+paramMap.get("webTreatmentPetitStart"));
        log.debug("webTreatmentPetitLimit               :"+paramMap.get("webTreatmentPetitLimit"));
        log.debug("webTreatmentPetitSort                :"+paramMap.get("webTreatmentPetitSort"));
        log.debug("webTreatmentPetitDir                 :"+paramMap.get("webTreatmentPetitDir"));
        log.debug("webTreatmentPetitCurrentPage         :"+paramMap.get("webTreatmentPetitCurrentPage"));

        log.debug("webTreatmentPetitSearchStartDate     :"+paramMap.get("webTreatmentPetitSearchStartDate"));
        log.debug("webTreatmentPetitSearchEndDate       :"+paramMap.get("webTreatmentPetitSearchEndDate"));

        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){
                // 권한 조회
                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);

                if(1==authMenuRelationlistMap.size()){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

                    }
                    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){
                // 정렬 
                if(null==paramMap.get("webTreatmentPetitDir")||("").equals(paramMap.get("webTreatmentPetitDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("webTreatmentPetitDir"));
                    if(("A").equals(dir)){
                        paramMap.put("webTreatmentPetitDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("webTreatmentPetitDir", "ASC");
                    }
                    else {
                        paramMap.put("webTreatmentPetitDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");
                
                //List<Map<String, Object>> totalCountListMap = webTreatmentPetitSqlMapDAO.selectTotalWebTreatmentPetitCount(paramMap);
                int totalCount = cmmnDAO.selectCount("ContentsBbsSql.getContentsBbsCnt", paramMap);

                if(0 < totalCount) {
                    // 리스트 조회
                    //listMap = webTreatmentPetitSqlMapDAO.selectListWebTreatmentPetit(paramMap);
                    listMap = cmmnDAO.selectList("ContentsBbsSql.getContentsBbsList", 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("WebTreatmentPetitServiceImpl selectListWebTreatmentPetit END");
        return map;
    }

    /**
     * 홈페이지 시술예약(쁘띠)정보 상세 조회 (one)
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> getContentsBbs(
            HashMap<String, Object> paramMap) throws Exception {

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

        try{
            boolean check  = true;
            String postNo    = String.valueOf(paramMap.get("postNo"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(postNo)){
                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);

                if(1==authMenuRelationlistMap.size()){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

                    }
                    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){
                
                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("detail", cmmnDAO.select("ContentsBbsSql.getContentsBbs", paramMap));
                map.put("treatmentList", cmmnDAO.selectList("ContentsBbsSql.getProcedureList", paramMap));
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebTreatmentPetitServiceImpl selectWebTreatmentPetit END");
        return map;
    }

    /**
     * 홈페이지 시술예약(쁘띠) 콘텐츠 등록 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> insertWebTreatmentPetitIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebTreatmentPetitServiceImpl insertWebTreatmentPetitIntro START");

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

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

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

        try{
            boolean check  = true;

            String menuClass    = String.valueOf(paramMap.get("menuClass"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(menuClass)){
                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){
                    map.put("msgCode", Constants.OK);
                    map.put("success","true");

                    map.put("selectUseYn", authMenuRelationlistMap.get(0).get("selectUseYn"));
                    map.put("insertUseYn", authMenuRelationlistMap.get(0).get("insertUseYn"));
                    map.put("updateUseYn", authMenuRelationlistMap.get(0).get("updateUseYn"));
                    map.put("deleteUseYn", authMenuRelationlistMap.get(0).get("deleteUseYn"));
                    map.put("downloadUseYn", authMenuRelationlistMap.get(0).get("downloadUseYn"));
                }
                else {
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }
            //List<Map<String, Object>> listMap = webTreatmentPetitSqlMapDAO.selectWebTreatmentPetitCategory(paramMap);
            List<Map<String, Object>> listMap = cmmnDAO.selectList("ContentsBbsSql.getCategoryList",paramMap);
            map.put("categorylist", listMap);
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebTreatmentPetitServiceImpl insertWebTreatmentPetitIntro END");
        return map;
    }

    /**
     * 홈페이지 시술예약(쁘띠) 정보 등록
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> putContentsBbs(
            HashMap<String, Object> paramMap, MultipartFile file, MultipartFile content_file) throws Exception{
        log.debug("WebTreatmentPetitServiceImpl insertTreatmentPetit START");

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

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

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

        log.debug("title               :"+paramMap.get("title"));
        log.debug("content              :"+paramMap.get("content"));
        log.debug("hashtag              :"+paramMap.get("hashtag"));
        log.debug("thumbnail_bottom_txt              :"+paramMap.get("thumbnail_bottom_txt"));
        log.debug("file                :"+file);
        log.debug("content_file                :"+content_file);
        log.debug("treatmentlist                :"+paramMap.get("treatmentlist"));
        log.debug("treatmentprocedurelist                :"+paramMap.get("treatmentprocedurelist"));

        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 title           = String.valueOf(paramMap.get("title"));
            String content          = String.valueOf(paramMap.get("content"));
            String hashtag          = String.valueOf(paramMap.get("hashtag"));
            String thumbnail_bottom_txt          = String.valueOf(paramMap.get("thumbnail_bottom_txt"));
            String[] treatmentlist          = String.valueOf(paramMap.get("treatmentlist")).split(",");
            String[] treatmentprocedurelist          = String.valueOf(paramMap.get("treatmentprocedurelist")).split(",");

            if(true != ValidationCheckUtil.emptyCheck(title)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","제목 정보가 없습니다.");
            }

//            if(true != ValidationCheckUtil.emptyCheck(content)){
//                check = false;
//                map.put("msgCode", Constants.FAIL);
//                map.put("msgDesc","시술예약(쁘띠) 상세 정보가 없습니다.");
//            }
//            if(true != ValidationCheckUtil.emptyCheck(hashtag)){
//                check = false;
//                map.put("msgCode", Constants.FAIL);
//                map.put("msgDesc","시술예약(쁘띠) 해시태그 정보가 없습니다.");
//            }
//            if(true != ValidationCheckUtil.emptyCheck(thumbnail_bottom_txt)){
//                check = false;
//                map.put("msgCode", Constants.FAIL);
//                map.put("msgDesc","시술예약(쁘띠) 썸네일 하단 정보가 없습니다.");
//            }
//
//            if(null==file|| file.isEmpty()){
//                check = false;
//                map.put("msgCode", Constants.FAIL);
//                map.put("msgDesc","배너 이미지 정보가 없습니다.");
//            }
//            if(null==content_file|| content_file.isEmpty()){
//                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){

                if (null != file && !file.isEmpty()) {
                	Map<String, Object> thumbnailImgMap = afs.saveAttachFile("img", file);
                	paramMap.put("thumbnailAttachfileId", thumbnailImgMap.get("attachfileId"));
                }

                if (null != content_file && !content_file.isEmpty()) {
                	Map<String, Object> contentsImgMap = afs.saveAttachFile("img", content_file);
                    paramMap.put("contentsAttachfileId", contentsImgMap.get("attachfileId"));
                }
                paramMap.put("tDate", tDate);
                paramMap.put("tId", tId);

                paramMap.put("muMemberId", paramMap.get("loginMemberId"));
                // 게시글 등록
                cmmnDAO.insert("ContentsBbsSql.putContentsBbs", paramMap);

                
                for(int i = 0; i < treatmentlist.length; i++) {
                	if(StringUtils.isNotEmpty(treatmentlist[i]) && 
                     	   StringUtils.isNotEmpty(treatmentprocedurelist[i])) {
	                	paramMap.put("muTreatmentId", treatmentlist[i]);
	                	paramMap.put("muTreatmentProcedureId", treatmentprocedurelist[i]);
	                	
	                	cmmnDAO.insert("ContentsBbsSql.putContentsBbsProcedure", paramMap);
                	}
                }
                
                
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebTreatmentPetitServiceImpl insertWebTreatmentPetit END");
        return map;
    }

    /**
     * 홈페이지 시술예약(쁘띠) 수정 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> moveContentsBbs(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebTreatmentPetitServiceImpl updateWebTreatmentPetitIntro START");

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

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

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

        try{
            boolean check  = true;

            String menuClass    = String.valueOf(paramMap.get("menuClass"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(menuClass)){
                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){
                    map.put("msgCode", Constants.OK);
                    map.put("success","true");

                    map.put("selectUseYn", authMenuRelationlistMap.get(0).get("selectUseYn"));
                    map.put("insertUseYn", authMenuRelationlistMap.get(0).get("insertUseYn"));
                    map.put("updateUseYn", authMenuRelationlistMap.get(0).get("updateUseYn"));
                    map.put("deleteUseYn", authMenuRelationlistMap.get(0).get("deleteUseYn"));
                    map.put("downloadUseYn", authMenuRelationlistMap.get(0).get("downloadUseYn"));
                }
                else {
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            map.put("category", cmmnDAO.selectList("ContentsBbsSql.getCategoryList", paramMap));

        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebTreatmentPetitServiceImpl updateWebTreatmentPetitIntro END");
        return map;
    }

    /**
     * 홈페이지 시술예약(쁘띠) 정보 수정
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> modContentsBbs(
            HashMap<String, Object> paramMap, MultipartFile file, MultipartFile content_file) throws Exception{

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

        try{
            boolean check  = true;

            String title           = String.valueOf(paramMap.get("title"));
            String content          = String.valueOf(paramMap.get("content"));
            String hashtag          = String.valueOf(paramMap.get("hashtag"));
            String thumbnailBottomTxt          = String.valueOf(paramMap.get("thumbnailBottomTxt"));
            String[] treatmentlist          = String.valueOf(paramMap.get("treatmentlist")).split(",");
            String[] treatmentprocedurelist          = String.valueOf(paramMap.get("treatmentprocedurelist")).split(",");
            
//            String treatmentpetitStartDate  = String.valueOf(paramMap.get("treatmentpetitStartDate"));
//            String treatmentpetitEndDate    = String.valueOf(paramMap.get("treatmentpetitEndDate"));

            if(true != ValidationCheckUtil.emptyCheck(title)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","제목 정보가 없습니다.");
            }
            /*
            if(true != ValidationCheckUtil.emptyCheck(content)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","시술예약(쁘띠) 상세 정보가 없습니다.");
            }
            if(true != ValidationCheckUtil.emptyCheck(hashtag)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","시술예약(쁘띠) 해시태그 정보가 없습니다.");
            }
            if(true != ValidationCheckUtil.emptyCheck(thumbnailBottomTxt)){
                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){
            	if (null != file && !file.isEmpty()) {
                	Map<String, Object> thumbnailImgMap = afs.saveAttachFile("img", file);
                	paramMap.put("thumbnailAttachfileId", thumbnailImgMap.get("attachfileId"));
                }

                if (null != content_file && !content_file.isEmpty()) {
                	Map<String, Object> contentsImgMap = afs.saveAttachFile("img", content_file);
                    paramMap.put("contentsAttachfileId", contentsImgMap.get("attachfileId"));
                }
                paramMap.put("muMemberId", paramMap.get("loginMemberId"));
                
                
                cmmnDAO.update("ContentsBbsSql.modContentsBbs", paramMap);
                //webTreatmentPetitSqlMapDAO.updateWebTreatmentPetit(paramMap);
                
                
                
                map.put("postNo", paramMap.get("postNo"));
                cmmnDAO.delete("ContentsBbsSql.delContentsBbsProcedure", paramMap);
                //webTreatmentPetitSqlMapDAO..updateWebTreatmentListDiet(paramMap);
                for(int i = 0; i < treatmentlist.length; i++) {
                	if(StringUtils.isNotEmpty(treatmentlist[i]) && 
                	   StringUtils.isNotEmpty(treatmentprocedurelist[i])) {
                		paramMap.put("muTreatmentId", treatmentlist[i]);
                    	paramMap.put("muTreatmentProcedureId", treatmentprocedurelist[i]);
                    	cmmnDAO.insert("ContentsBbsSql.putContentsBbsProcedure", paramMap);
                	}
                	
                }
                
                
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "수정되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebTreatmentPetitServiceImpl updateWebTreatmentPetit END");
        return map;
    }

    /**
     * 홈페이지 시술예약(쁘띠) 정보 삭제
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> delContentsBbs(
            HashMap<String, Object> paramMap) throws Exception{

    	HashMap<String, Object> map = new HashMap<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){
                // 권한 조회
                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("deleteUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "삭제 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }
            int delCnt = 0;
            if(true == check) {
            	
            	
            	delCnt = cmmnDAO.update("ContentsBbsSql.delContentsBbs", paramMap);
            	map.put("msgCode", Constants.OK);
                map.put("msgDesc", delCnt + "건 삭제 되었습니다.");
            }

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

        log.debug("WebTreatmentPetitServiceImpl deleteWebTreatmentPetit END");
        return map;
    }
    
    /**
     * 고객 리스트 조회.(List,Option)
     * 예약팝업에서 고객 조회
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListTreatmentOption(HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebTreatmentPetitServiceImpl selectListTreatmentOption START");

        HashMap<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> listMap = new ArrayList<>();
        log.debug("userSearchKeywordParam   :"+paramMap.get("userSearchKeywordParam"));
        log.debug("userTypeCode             :"+paramMap.get("userTypeCode"));
        log.debug("membershipYn             :"+paramMap.get("membershipYn"));
        log.debug("nationalityCode          :"+paramMap.get("nationalityCode"));
        log.debug("loginMemberId            :"+paramMap.get("loginMemberId"));
        log.debug("userSort                 :"+paramMap.get("userSort"));
        log.debug("userStart                :"+paramMap.get("userStart"));
        log.debug("nationality              :"+paramMap.get("nationality"));
        log.debug("menuClass                :"+paramMap.get("menuClass"));
        log.debug("userType                 :"+paramMap.get("userType"));
        log.debug("userLimit                :"+paramMap.get("userLimit"));

        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("userDir")||("").equals(paramMap.get("userDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("userDir"));
                    if(("A").equals(dir)){
                        paramMap.put("userDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("userDir", "ASC");
                    }
                    else {
                        paramMap.put("userDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");

                int totalCount = cmmnDAO.selectCount("WebTreatmentPetit.selectTotalTreatmentCount", paramMap);
                if( 0 < totalCount ){
                    listMap = cmmnDAO.selectList("WebTreatmentPetit.selectListTreatment", 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("WebTreatmentPetitServiceImpl selectListTreatmentOption END");
        return map;
    }
}
