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

import com.madeu.constants.Constants;
import com.madeu.dao.web.webphotodiet.WebPhotoDietSqlMapDAO;
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.webphotodiet.WebPhotoDietService;
import com.madeu.util.ValidationCheckUtil;
import lombok.extern.slf4j.Slf4j;
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 java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service("WebPhotoDietService")
public class WebPhotoDietServiceImpl implements WebPhotoDietService {

    @Autowired
    private WebPhotoDietSqlMapDAO webPhotoDietSqlMapDAO;

    @Autowired
    private WebMemberSqlMapDAO webMemberSqlMapDAO;

    @Autowired
    private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;

    @Autowired
    private FileService fileService;

	@Value("${url.cdn}")
	String CDN_URL;

    /**
     * 홈페이지 전후사진(다이어트) 리스트 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListWebPhotoDietIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebPhotoDietServiceImpl selectListWebPhotoDietIntro 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("WebPhotoDietServiceImpl selectListWebPhotoDietIntro END");
        return map;
    }

    /**
     * 홈페이지 전후사진(다이어트) 리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListWebPhotoDiet(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebPhotoDietServiceImpl selectListWebPhotoDiet START");

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

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

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

        log.debug("webPhotoDietSearchKeywordParam  :"+paramMap.get("webPhotoDietSearchKeywordParam"));
        log.debug("webPhotoDietSort                :"+paramMap.get("webPhotoDietSort"));
        log.debug("webPhotoDietStart               :"+paramMap.get("webPhotoDietStart"));
        log.debug("webPhotoDietLimit               :"+paramMap.get("webPhotoDietLimit"));
        log.debug("webPhotoDietSort                :"+paramMap.get("webPhotoDietSort"));
        log.debug("webPhotoDietDir                 :"+paramMap.get("webPhotoDietDir"));
        log.debug("webPhotoDietCurrentPage         :"+paramMap.get("webPhotoDietCurrentPage"));

        log.debug("webPhotoDietSearchStartDate     :"+paramMap.get("webPhotoDietSearchStartDate"));
        log.debug("webPhotoDietSearchEndDate       :"+paramMap.get("webPhotoDietSearchEndDate"));

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

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

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

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

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

    /**
     * 홈페이지 전후사진(다이어트)정보 상세 조회 (one)
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectWebPhotoDiet(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebPhotoDietServiceImpl selectPhotoDiet START");

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

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

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

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

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

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

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

    /**
     * 홈페이지 메인 배너 상세 이미지파일 저장
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> uploadFile(
            HashMap<String, Object> paramMap, MultipartFile file) throws Exception{
        log.debug("WebPhotoDietServiceImpl uploadFile START");

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

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

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

        log.debug("file                :"+file);

        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());

            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){

                if (null != file && !file.isEmpty()) {
                    HashMap<String, Object> uploadFileMap = new HashMap<String, Object>();
                    uploadFileMap.put("type", "WE");
                    uploadFileMap.put("fileType", "P");
                    uploadFileMap.put("fileName", file.getOriginalFilename());
                    HashMap<String, Object> fileMap = fileService.uploadFile(uploadFileMap, file);
                    String cdnUrl       = String.valueOf(fileMap.get("cdnUrl"));
                    String filePath     = String.valueOf(fileMap.get("filePath"));
                    String fileName     = String.valueOf(fileMap.get("fileName"));
                    String chgFileName  = file.getOriginalFilename();
                    paramMap.put("cdnUrl", cdnUrl);
                    paramMap.put("filePath", (CDN_URL).concat(filePath));
                    paramMap.put("fileName", fileName);
                    paramMap.put("originalFileName", chgFileName);
                }
                paramMap.put("tDate", tDate);
                paramMap.put("tId", tId);

                map.put("rows",paramMap);
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebPhotoDietServiceImpl uploadFile END");
        return map;
    }

    /**
     * 홈페이지 전후사진(다이어트) 콘텐츠 등록 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> insertWebPhotoDietIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebPhotoDietServiceImpl insertWebPhotoDietIntro 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 = webPhotoDietSqlMapDAO.selectListPhotoCategory(paramMap);
            map.put("categorylist", listMap);
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebPhotoDietServiceImpl insertWebPhotoDietIntro END");
        return map;
    }

    /**
     * 홈페이지 전후사진(다이어트) 정보 등록
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> insertWebPhotoDiet(
            HashMap<String, Object> paramMap, List<MultipartFile> files) throws Exception{
        log.debug("WebPhotoDietServiceImpl insertPhotoDiet 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("files                :"+files);

        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"));
            
            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(files == null || files.size() < 2 || files.get(0) == null || files.get(1) == null || files.get(0).isEmpty() || files.get(1).isEmpty()){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","Before/After 이미지 정보가 없습니다.");
            }

            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){
                // Before/After 파일 업로드
                MultipartFile beforeFile = files.get(0);
                MultipartFile afterFile = files.get(1);
                HashMap<String, Object> beforeFileMap = fileService.uploadFile(new HashMap<String, Object>() {{
                    put("type", "WE");
                    put("fileType", "P");
                    put("fileName", beforeFile.getOriginalFilename());
                }}, beforeFile);
                HashMap<String, Object> afterFileMap = fileService.uploadFile(new HashMap<String, Object>() {{
                    put("type", "WE");
                    put("fileType", "P");
                    put("fileName", afterFile.getOriginalFilename());
                }}, afterFile);
                paramMap.put("beforeFilePath", beforeFileMap.get("filePath"));
                paramMap.put("beforeFileName", beforeFileMap.get("fileName"));
                paramMap.put("beforeOriginalFileName", beforeFile.getOriginalFilename());
                paramMap.put("afterFilePath", afterFileMap.get("filePath"));
                paramMap.put("afterFileName", afterFileMap.get("fileName"));
                paramMap.put("afterOriginalFileName", afterFile.getOriginalFilename());
                paramMap.put("title", title);
                paramMap.put("content", content);
                
                webPhotoDietSqlMapDAO.insertWebPhotoDietBeforeFile(paramMap);
                log.debug("beforeId :"+paramMap.get("beforeId"));
                paramMap.put("beforeId", paramMap.get("beforeId"));
                webPhotoDietSqlMapDAO.insertWebPhotoDietAfterFile(paramMap);
                log.debug("afterId :"+paramMap.get("afterId"));
                paramMap.put("afterId", paramMap.get("afterId"));
            }
            if(true == check){
                paramMap.put("tDate", tDate);
                paramMap.put("tId", tId);
                String muWebPhotoDietId = ("E").concat(String.valueOf(System.currentTimeMillis()));
                paramMap.put("muWebPhotoDietId",muWebPhotoDietId);
                paramMap.put("muMemberId", paramMap.get("loginMemberId"));
                webPhotoDietSqlMapDAO.insertWebPhotoDiet(paramMap);
                log.debug("muWebPhotoDietId :"+paramMap.get("id"));
                paramMap.put("muWebPhotoDietId", paramMap.get("id"));
                map.put("muWebPhotoDietId", paramMap.get("muWebPhotoDietId"));
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebPhotoDietServiceImpl insertWebPhotoDiet END");
        return map;
    }

    /**
     * 홈페이지 전후사진(다이어트) 수정 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> updateWebPhotoDietIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebPhotoDietServiceImpl updateWebPhotoDietIntro 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 = webPhotoDietSqlMapDAO.selectListPhotoCategory(paramMap);
            map.put("categorylist", listMap);
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebPhotoDietServiceImpl updateWebPhotoDietIntro END");
        return map;
    }

    /**
     * 홈페이지 전후사진(다이어트) 정보 수정
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> updateWebPhotoDiet(
            HashMap<String, Object> paramMap, List<MultipartFile> files) throws Exception{
        log.debug("WebPhotoDietServiceImpl updateWebPhotoDiet START");

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

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
        log.debug("menuClass           :"+paramMap.get("menuClass"));
        log.debug("muWebPhotoDietId          :"+paramMap.get("muWebPhotoDietId"));
        log.debug("title               :"+paramMap.get("title"));
        log.debug("content              :"+paramMap.get("content"));
        log.debug("files                :"+files);

        try{
            boolean check  = true;

            String muWebPhotoDietId       = String.valueOf(paramMap.get("muWebPhotoDietId"));
            String title              = String.valueOf(paramMap.get("title"));
            String content             = String.valueOf(paramMap.get("content"));

            if(true != ValidationCheckUtil.emptyCheck(muWebPhotoDietId)){
                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","제목 정보가 없습니다.");
            }

            if(true != ValidationCheckUtil.emptyCheck(content)){
                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){
                // Before/After 파일 업로드 분기 처리
                MultipartFile beforeFile = files != null && files.size() > 0 ? files.get(0) : null;
                MultipartFile afterFile = files != null && files.size() > 1 ? files.get(1) : null;

                if (beforeFile != null && !beforeFile.isEmpty()) {
                    HashMap<String, Object> beforeFileMap = fileService.uploadFile(new HashMap<String, Object>() {{
                        put("type", "WE");
                        put("fileType", "P");
                        put("fileName", beforeFile.getOriginalFilename());
                    }}, beforeFile);
                    paramMap.put("beforeFilePath", beforeFileMap.get("filePath"));
                    paramMap.put("beforeFileName", beforeFileMap.get("fileName"));
                    paramMap.put("beforeOriginalFileName", beforeFile.getOriginalFilename());
                    webPhotoDietSqlMapDAO.insertWebPhotoDietBeforeFile(paramMap);
                    log.debug("beforeId :"+paramMap.get("beforeId"));
                    paramMap.put("beforeId", paramMap.get("beforeId"));
                }
                if (afterFile != null && !afterFile.isEmpty()) {
                    HashMap<String, Object> afterFileMap = fileService.uploadFile(new HashMap<String, Object>() {{
                        put("type", "WE");
                        put("fileType", "P");
                        put("fileName", afterFile.getOriginalFilename());
                    }}, afterFile);
                    paramMap.put("afterFilePath", afterFileMap.get("filePath"));
                    paramMap.put("afterFileName", afterFileMap.get("fileName"));
                    paramMap.put("afterOriginalFileName", afterFile.getOriginalFilename());
                    webPhotoDietSqlMapDAO.insertWebPhotoDietAfterFile(paramMap);
                    log.debug("afterId :"+paramMap.get("afterId"));
                    paramMap.put("afterId", paramMap.get("afterId"));
                }
                paramMap.put("title", title);
                paramMap.put("content", content);
            }
            if(true == check){
                paramMap.put("muWebPhotoDietId",muWebPhotoDietId);
                paramMap.put("muMemberId", paramMap.get("loginMemberId"));
                webPhotoDietSqlMapDAO.updateWebPhotoDiet(paramMap);
                map.put("muWebPhotoDietId", paramMap.get("muWebPhotoDietId"));
                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "수정되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebPhotoDietServiceImpl updateWebPhotoDiet END");
        return map;
    }

    /**
     * 홈페이지 전후사진(다이어트) 정보 삭제
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> deleteWebPhotoDiet(
            HashMap<String, Object> paramMap) throws Exception{
        log.debug("WebPhotoDietServiceImpl deleteWebPhotoDiet 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("categoryno          :"+paramMap.get("categoryno")); // categoryno 로그 추가

        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"));
                String categoryno = String.valueOf(paramMap.get("categoryno")); // categoryno 값 받기
                log.debug("deleteWebPhotoDiet selectId: " + selectId + ", categoryno: " + categoryno);
                // categoryno를 활용하려면 아래에서 사용
                StringTokenizer selectData = new StringTokenizer(selectId, ",");
                StringTokenizer categoryData = new StringTokenizer(categoryno != null ? categoryno : "", ",");
                while(selectData.hasMoreTokens()){//토큰이 계속 있을때 까지
                    String muWebPhotoDietId = selectData.nextToken();
                    String catNo = categoryData.hasMoreTokens() ? categoryData.nextToken() : null;

                    HashMap<String, Object> deleteParamMap = new HashMap<String, Object>();
                    deleteParamMap.put("muWebPhotoDietId", muWebPhotoDietId);
                    deleteParamMap.put("modId", paramMap.get("loginMemberId"));
                    if (catNo != null) {
                        deleteParamMap.put("categoryno", catNo);
                    }
                    webPhotoDietSqlMapDAO.deleteWebPhotoDiet(deleteParamMap);
                }

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

        log.debug("WebPhotoDietServiceImpl deleteWebPhotoDiet END");
        return map;
    }
}
