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

import com.madeu.constants.Constants;
import com.madeu.dao.web.webappboard.WebAppBoardSqlMapDAO;
import com.madeu.dao.web.webauthmenurelation.WebAuthMenuRelationSqlMapDAO;
import com.madeu.dao.web.webmember.WebMemberSqlMapDAO;
import com.madeu.service.common.file.FileService;
import com.madeu.service.web.webappboard.WebAppBoardService;
import com.madeu.util.ValidationCheckUtil;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service("WebAppBoardService")
public class WebAppBoardServiceImpl implements WebAppBoardService {

    @Autowired
    private WebAppBoardSqlMapDAO webAppBoardSqlMapDAO;

    @Autowired
    private WebMemberSqlMapDAO webMemberSqlMapDAO;

    @Autowired
    private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;

    @Autowired
    private FileService fileService;

    /**
     * 시술정보 보드 리스트 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListAppBoardIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebAppBoardServiceImpl selectListAppBoardIntro 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("WebAppBoardServiceImpl selectListAppBoardIntro END");
        return map;
    }

    /**
     * 시술정보 보드 등록 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> insertAppBoardIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebAppBoardServiceImpl insertAppBoardIntro 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("WebAppBoardServiceImpl insertAppBoardIntro END");
        return map;
    }

    /**
     * 시술정보 보드 수정 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> updateAppBoardIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebAppBoardServiceImpl updateAppBoardIntro 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("WebAppBoardServiceImpl updateAppBoardIntro END");
        return map;
    }

    /**
     * 보드리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListAppBoard(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebAppBoardServiceImpl selectListAppBoard START");

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

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

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

        log.debug("appBoardSearchKeywordParam  :"+paramMap.get("appBoardSearchKeywordParam"));
        log.debug("appBoardSort                :"+paramMap.get("appBoardSort"));
        log.debug("appBoardStart               :"+paramMap.get("appBoardStart"));
        log.debug("appBoardLimit               :"+paramMap.get("appBoardLimit"));
        log.debug("appBoardSort                :"+paramMap.get("appBoardSort"));
        log.debug("appBoardDir                 :"+paramMap.get("appBoardDir"));
        log.debug("appBoardCurrentPage         :"+paramMap.get("appBoardCurrentPage"));
        log.debug("appContentappContentCategoryName         :"+paramMap.get("appContentappContentCategoryName"));

        log.debug("appBoardSearchStartDate     :"+paramMap.get("appBoardSearchStartDate"));
        log.debug("appBoardSearchEndDate       :"+paramMap.get("appBoardSearchEndDate"));

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

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

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

                List<Map<String, Object>> totalCountListMap = webAppBoardSqlMapDAO.selectTotalAppBoardCount(paramMap);
                int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0).get("totalCount")));

                if(0 < totalCount) {
                    // 리스트 조회
                    listMap = webAppBoardSqlMapDAO.selectListAppBoard(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("WebAppBoardServiceImpl selectListAppBoard END");
        return map;
    }

    /**
     * 시술 보드 정보 상세 조회 (one)
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectAppBoard(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebAppBoardServiceImpl selectAppBoard START");

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

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

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

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

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

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(muAppBoardId)){
                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){
                List<Map<String, Object>> listMap = webAppBoardSqlMapDAO.selectAppBoard(paramMap);

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebAppBoardServiceImpl selectAppBoard END");
        return map;
    }

    /**
     * 시술 보드 정보 등록
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> insertAppBoard(
            HashMap<String, Object> paramMap, MultipartFile file) throws Exception{
        log.debug("WebAppBoardServiceImpl insertBoard 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("exposedYn           :"+paramMap.get("exposedYn"));
        log.debug("contentData         :"+paramMap.get("contentData"));

        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 exposedYn       = String.valueOf(paramMap.get("exposedYn"));
            String contentData     = String.valueOf(paramMap.get("contentData"));

            if(true != ValidationCheckUtil.emptyCheck(title)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","제목 정보가 없습니다.");
            }
//            else{
//                if(true != ValidationCheckUtil.lengthCheck(title,20)){
//                    check = false;
//                    map.put("msgCode", Constants.FAIL);
//                    map.put("msgDesc","제목 정보는 20자를 넘을 수 없습니다.");
//                }
//            }

            if(true != ValidationCheckUtil.emptyCheck(content)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","내용 정보가 없습니다.");
            }
//            else{
//                if(true != ValidationCheckUtil.lengthCheck(title,50)){
//                    check = false;
//                    map.put("msgCode", Constants.FAIL);
//                    map.put("msgDesc","내용 정보는 50자를 넘을 수 없습니다.");
//                }
//            }

            if(true != ValidationCheckUtil.emptyCheck(exposedYn)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","메인 홈 노출 정보가 없습니다.");
            }

            if(true != ValidationCheckUtil.emptyCheck(contentData)){
                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(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){
                String muAppBoardId = ("B").concat(String.valueOf(System.currentTimeMillis()));
                paramMap.put("muAppBoardId",muAppBoardId);
                paramMap.put("muMemberId", paramMap.get("loginMemberId"));
                webAppBoardSqlMapDAO.insertAppBoard(paramMap);

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

                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");

                JSONParser parser = new JSONParser();
                Object contentObj = parser.parse( contentData );
                JSONArray contentDataArray = (JSONArray) contentObj;
                for (Object contentDataObj : contentDataArray) {

                    JSONObject jsonObject = (JSONObject) contentDataObj;
                    HashMap<String, Object> dataMap = new HashMap<>();

                    String muBoardContentId = ("C").concat(String.valueOf(System.currentTimeMillis()));
                    dataMap.put("muBoardContentId",muBoardContentId);
                    dataMap.put("muAppBoardId",paramMap.get("muAppBoardId"));
                    dataMap.put("muAppContentId", jsonObject.get("muAppContentId"));
                    dataMap.put("title", jsonObject.get("title"));
                    dataMap.put("content", jsonObject.get("content"));
                    dataMap.put("filePath", jsonObject.get("filePath"));
                    dataMap.put("fileName", jsonObject.get("fileName"));
                    dataMap.put("originalFileName", jsonObject.get("originalFileName"));
                    dataMap.put("filePath2", jsonObject.get("filePath2"));
                    dataMap.put("fileName2", jsonObject.get("fileName2"));
                    dataMap.put("originalFileName2", jsonObject.get("originalFileName2"));
                    dataMap.put("contentWriteDate", jsonObject.get("writeDate"));
                    dataMap.put("categoryName", jsonObject.get("appContentCategoryName"));
                    dataMap.put("regId", paramMap.get("regId"));
                    dataMap.put("modId", paramMap.get("modId"));
                    webAppBoardSqlMapDAO.insertBoardContent(dataMap);

                    log.debug("muBoardContentId :"+dataMap.get("id"));
                }
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebAppBoardServiceImpl insertAppBoard END");
        return map;
    }

    /**
     * 보드정보 수정
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> updateAppBoard(
            HashMap<String, Object> paramMap, MultipartFile file) throws Exception{
        log.debug("WebAppBoardServiceImpl updateAppBoard 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("exposedYn           :"+paramMap.get("exposedYn"));
        log.debug("contentData         :"+paramMap.get("contentData"));

        try{
            boolean check  = true;

            String muAppBoardId       = String.valueOf(paramMap.get("muAppBoardId"));
            String title           = String.valueOf(paramMap.get("title"));
            String content         = String.valueOf(paramMap.get("content"));
            String exposedYn       = String.valueOf(paramMap.get("exposedYn"));
            String contentData     = String.valueOf(paramMap.get("contentData"));

            if(true != ValidationCheckUtil.emptyCheck(muAppBoardId)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","보드식별자 정보가 없습니다.");
            }

            if(true != ValidationCheckUtil.emptyCheck(title)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","제목 정보가 없습니다.");
            }
//            else{
//                if(true != ValidationCheckUtil.lengthCheck(title,20)){
//                    check = false;
//                    map.put("msgCode", Constants.FAIL);
//                    map.put("msgDesc","제목 정보는 20자를 넘을 수 없습니다.");
//                }
//            }

            if(true != ValidationCheckUtil.emptyCheck(content)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","내용 정보가 없습니다.");
            }
//            else{
//                if(true != ValidationCheckUtil.lengthCheck(content,50)){
//                    check = false;
//                    map.put("msgCode", Constants.FAIL);
//                    map.put("msgDesc","내용 정보는 50자를 넘을 수 없습니다.");
//                }
//            }

           if(true != ValidationCheckUtil.emptyCheck(exposedYn)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","메인 홈 노출 정보가 없습니다.");
            }

            if(true != ValidationCheckUtil.emptyCheck(contentData)){
                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){
                webAppBoardSqlMapDAO.updateAppBoard(paramMap);
                webAppBoardSqlMapDAO.updateAppBoardContent(paramMap);
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "수정되었습니다.");

                JSONParser parser = new JSONParser();
                Object contentObj = parser.parse( contentData );
                JSONArray contentDataArray = (JSONArray) contentObj;
                for (Object contentDataObj : contentDataArray) {

                    JSONObject jsonObject = (JSONObject) contentDataObj;
                    HashMap<String, Object> dataMap = new HashMap<>();

                    String muBoardContentId = ("C").concat(String.valueOf(System.currentTimeMillis()));
                    dataMap.put("muBoardContentId",muBoardContentId);
                    dataMap.put("muAppBoardId",paramMap.get("muAppBoardId"));
                    dataMap.put("muAppContentId", jsonObject.get("muAppContentId"));
                    dataMap.put("title", jsonObject.get("title"));
                    dataMap.put("content", jsonObject.get("content"));
                    dataMap.put("filePath", jsonObject.get("filePath"));
                    dataMap.put("fileName", jsonObject.get("fileName"));
                    dataMap.put("originalFileName", jsonObject.get("originalFileName"));
                    dataMap.put("filePath2", jsonObject.get("filePath2"));
                    dataMap.put("fileName2", jsonObject.get("fileName2"));
                    dataMap.put("originalFileName2", jsonObject.get("originalFileName2"));
                    dataMap.put("categoryName", jsonObject.get("appContentCategoryName"));
                    dataMap.put("contentWriteDate", jsonObject.get("writeDate"));
                    dataMap.put("regId", paramMap.get("regId"));
                    dataMap.put("modId", paramMap.get("modId"));
                    webAppBoardSqlMapDAO.insertBoardContent(dataMap);

                    log.debug("muBoardContentId :"+dataMap.get("id"));
                }
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebAppBoardServiceImpl updateAppBoard END");
        return map;
    }

    /**
     * 보드정보 삭제
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> deleteAppBoard(
            HashMap<String, Object> paramMap) throws Exception{
        log.debug("WebAppBoardServiceImpl deleteAppBoard 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"));

        try{
            boolean check  = true;

            if(null== paramMap.get("selectId") || ("").equals(paramMap.get("selectId"))){
                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("deleteUseYn"))) {

                    }
                    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){
                String selectId = String.valueOf(paramMap.get("selectId"));
                StringTokenizer selectData = new StringTokenizer(selectId, ",");
                while(selectData.hasMoreTokens()){//토큰이 계속 있을때 까지
                    String muAppBoardId = selectData.nextToken();

                    HashMap<String, Object> deleteParamMap = new HashMap<String, Object>();
                    deleteParamMap.put("muAppBoardId", muAppBoardId);
                    deleteParamMap.put("modId", paramMap.get("loginMemberId"));
                    webAppBoardSqlMapDAO.deleteAppBoard(deleteParamMap);
                    webAppBoardSqlMapDAO.updateAppBoardContent(deleteParamMap);
                }

                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "삭제 되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }

        log.debug("WebAppBoardServiceImpl deleteAppBoard END");
        return map;
    }
}

