소스 검색

공지사항(사이트공지, 내부공지) 기능 추가

gagamel 5 년 전
부모
커밋
277790a129

+ 92 - 0
style24.admin/src/main/java/com/style24/admin/biz/dao/TsaNoticeDao.java

@@ -0,0 +1,92 @@
+package com.style24.admin.biz.dao;
+
+import java.util.Collection;
+
+import com.style24.core.support.annotation.ShopDs;
+import com.style24.persistence.domain.Notice;
+
+/**
+ * 공지사항 Dao
+ * 
+ * @author gagamel
+ * @since 2020. 10. 30
+ */
+@ShopDs
+public interface TsaNoticeDao {
+
+	/**
+	 * 공지사항 목록
+	 * @param notice - 공지사항 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	Collection<Notice> getNoticeList(Notice notice);
+
+	/**
+	 * 공지사항 수신자 목록
+	 * @param noticeSq - 공지사항일련번호
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	Collection<Notice> getNoticeReceiverList(Integer noticeSq);
+
+	/**
+	 * 공지사항 파일 목록
+	 * @param noticeSq - 공지사항일련번호
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	Collection<Notice> getNoticeFileList(Integer noticeSq);
+
+	/**
+	 * 공지사항 저장
+	 * @param notice - 공지사항 정보
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	void createNotice(Notice notice);
+
+	/**
+	 * 공지사항 수정
+	 * @param notice - 공지사항 정보
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	void updateNotice(Notice notice);
+
+	/**
+	 * 공지사항 파일 저장
+	 * @param notice - 공지사항 정보
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	void createNoitceFlie(Notice notice);
+
+	/**
+	 * 공지사항 파일 삭제
+	 * @param notice - 공지사항 정보
+	 * @author jaewonHo
+	 * @since 2020. 01. 15
+	 */
+	void deleteNoticeFile(Notice notice);
+
+	/**
+	 * 공지사항 수신자 삭제
+	 * @param notice - 공지사항 정보
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	void deleteNoticeReceiver(Notice notice);
+
+	/**
+	 * 공지사항 수신자 저장
+	 * @param notice - 공지사항 정보
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	void createNoticeReceiver(Notice notice);
+
+}

+ 127 - 0
style24.admin/src/main/java/com/style24/admin/biz/service/TsaNoticeService.java

@@ -0,0 +1,127 @@
+package com.style24.admin.biz.service;
+
+import java.util.Collection;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.style24.admin.biz.dao.TsaNoticeDao;
+import com.style24.admin.support.security.session.TsaSession;
+import com.style24.persistence.domain.Notice;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 공지사항 Service
+ *
+ * @author gagamel
+ * @since 2020. 10. 30
+ */
+@Service
+@Slf4j
+public class TsaNoticeService {
+
+	@Autowired
+	private TsaNoticeDao noticeDao;
+
+	/**
+	 * 공지사항 목록
+	 * @param notice - 공지사항 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	public Collection<Notice> getNoticeList(Notice notice) {
+		return noticeDao.getNoticeList(notice);
+	}
+
+	/**
+	 * 공지사항 수신자 목록
+	 * @param noticeSq - 공지사항일련번호
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	public Collection<Notice> getNoticeReceiverList(Integer noticeSq) {
+		return noticeDao.getNoticeReceiverList(noticeSq);
+	}
+
+	/**
+	 * 공지사항 파일 목록
+	 * @param noticeSq - 공지사항일련번호
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	public Collection<Notice> getNoticeFileList(Integer noticeSq) {
+		return noticeDao.getNoticeFileList(noticeSq);
+	}
+
+	/**
+	 * 공지사항 저장
+	 * @param notice - 공지사항 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	@Transactional("shopTxnManager")
+	public void saveNotice(Notice notice) {
+		notice.setRegNo(TsaSession.getInfo().getUserNo());
+		notice.setUpdNo(TsaSession.getInfo().getUserNo());
+
+		// 신규 일때
+		if (notice.getNoticeSq() == null) {
+			// 공지사항 저장
+			noticeDao.createNotice(notice);
+
+			// 등록된 사용자번호 값 가져오기
+			Integer noticeSq = notice.getNoticeSq();
+			log.info("noticeSq: {}", noticeSq);
+			notice.setNoticeSq(noticeSq);
+		} else {
+			// 공지사항 수정
+			noticeDao.updateNotice(notice);
+		}
+
+		// 수신자 저장
+		if (!StringUtils.isAllBlank(notice.getReceiverIds())) {
+			noticeDao.deleteNoticeReceiver(notice);
+
+//			for (int i = 0; i < notice.getReceiverIds().length; i++) {
+			for (String receiverId : notice.getReceiverIds()) {
+				if (StringUtils.isNotBlank(receiverId)) {
+					notice.setReceiverId(receiverId);
+					log.info("noticeReceiver: {}", notice);
+					noticeDao.createNoticeReceiver(notice);
+				}
+			}
+		}
+
+		// 파일이 존재할때
+		if (!StringUtils.isAllBlank(notice.getSysFileNms())) {
+			noticeDao.deleteNoticeFile(notice);
+
+			for (int i = 0; i < notice.getFileCnt(); i++) {
+				notice.setOrgFileNm(notice.getOrgFileNms()[i]);
+				notice.setSysFileNm(notice.getSysFileNms()[i]);
+				log.info("noticeFile: {}", notice);
+				noticeDao.createNoitceFlie(notice);
+			}
+		}
+	}
+
+	/**
+	 * 공지사항 첨부파일 삭제
+	 * @param notice - 공지사항 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	@Transactional("shopTxnManager")
+	public void deleteNoticeFile(Notice notice) {
+		noticeDao.deleteNoticeFile(notice);
+	}
+
+}

+ 155 - 0
style24.admin/src/main/java/com/style24/admin/biz/web/TsaBoardController.java

@@ -0,0 +1,155 @@
+package com.style24.admin.biz.web;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.style24.admin.biz.service.TsaNoticeService;
+import com.style24.admin.biz.service.TsaRendererService;
+import com.style24.admin.support.controller.TsaBaseController;
+import com.style24.admin.support.env.TsaConstants;
+import com.style24.core.support.message.TscMessageByLocale;
+import com.style24.persistence.domain.Notice;
+
+import lombok.extern.slf4j.Slf4j;
+
+import com.gagaframework.web.rest.server.GagaResponse;
+import com.gagaframework.web.util.GagaFileUtil;
+
+/**
+ * 게시판 Controller
+ *
+ * @author gagamel
+ * @since 2020. 10. 30
+ */
+@Controller
+@RequestMapping("/board")
+@Slf4j
+public class TsaBoardController extends TsaBaseController {
+
+	@Autowired
+	private TscMessageByLocale message;
+
+	@Autowired
+	private TsaNoticeService noticeService;
+
+	@Autowired
+	private TsaRendererService rendererService;
+
+	@Value("${upload.default.target.path}")
+	private String uploadTargetPath;
+
+	/**
+	 * 공지사항 화면
+	 * @param noticeType - 공지유형(10:사이트공지, 20:내부공지)
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	@GetMapping("/notice/form/{noticeType}")
+	public ModelAndView noticeForm(@PathVariable String noticeType) {
+		ModelAndView mav = new ModelAndView();
+
+		// 공지유형
+		mav.addObject("noticeType", noticeType);
+
+		// 수신자 목록
+		// 공지유형이 "10:사이트공지"일 때는 사이트 목록
+		// 공지유형이 "20:내부공지"일 때는 공지수신자-조직 목록
+		if (noticeType.equals(TsaConstants.NoticeType.SITE.value())) {
+			mav.addObject("noticeReceiverList", rendererService.getAvailCommonCodeList("G000"));
+		} else if (noticeType.equals(TsaConstants.NoticeType.INNER.value())) {
+			mav.addObject("noticeReceiverList", rendererService.getAvailCommonCodeList("G048"));
+		}
+
+		mav.setViewName("board/NoticeForm");
+
+		return mav;
+	}
+
+	/**
+	 * 사이트 공지 목록
+	 * @param notice - 공지사항 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	@PostMapping("/notice/list")
+	@ResponseBody
+	public Collection<Notice> getNoticeList(@RequestBody Notice notice) {
+		return noticeService.getNoticeList(notice);
+	}
+
+	/**
+	 * 공지사항 수신자 목록
+	 * @param noticeSq - 공지사항일련번호
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	@GetMapping("/notice/receiver/list/{noticeSq}")
+	@ResponseBody
+	public Collection<Notice> getNoticeReceiverList(@PathVariable Integer noticeSq) {
+		return noticeService.getNoticeReceiverList(noticeSq);
+	}
+
+	/**
+	 * 공지사항 파일목록 조회
+	 * @param noticeSq - 공지사항일련번호
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	@GetMapping("/notice/file/list/{noticeSq}")
+	@ResponseBody
+	public Collection<Notice> getNoticeFileList(@PathVariable Integer noticeSq) {
+		return noticeService.getNoticeFileList(noticeSq);
+	}
+
+	/**
+	 * 공지사항 저장
+	 * @param notice - 공지사항 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2020. 10. 30
+	 */
+	@PostMapping("/notice/save")
+	@ResponseBody
+	public GagaResponse saveNotice(@RequestBody Notice notice) {
+		noticeService.saveNotice(notice);
+		return super.ok(message.getMessage("SUCC_0001"));
+	}
+
+	/**
+	 * 첨부파일 삭제
+	 * @param notice - 공지사항 정보
+	 * @return
+	 * @throws IOException
+	 * @author gagamel
+	 * @since 2020. 3. 24
+	 */
+	@PostMapping("/notice/file/delete")
+	@ResponseBody
+	public GagaResponse deleteNoticeFile(@RequestBody Notice notice) throws IOException {
+		// 파일 삭제
+		String fileName = GagaFileUtil.getConcatenationPath(uploadTargetPath, "board", notice.getSysFileNm());
+
+		GagaFileUtil.deleteFile(fileName);
+
+		// 삭제된 파일 DB 처리
+		noticeService.deleteNoticeFile(notice);
+
+		return super.ok(message.getMessage("SUCC_0003"));
+	}
+
+}

+ 16 - 0
style24.admin/src/main/java/com/style24/admin/support/env/TsaConstants.java

@@ -13,4 +13,20 @@ public class TsaConstants {
 
 	public static final String EXCEL_FOOTER_TITLE = "Copyright(c) 2020 STYLE24, All rights reserved.";
 
+	// 공지유형
+	public enum NoticeType {
+		SITE("G047_10"),
+		INNER("G047_20");
+
+		private String value;
+
+		private NoticeType(String value) {
+			this.value = value;
+		}
+
+		public String value() {
+			return value;
+		}
+	}
+
 }

+ 47 - 0
style24.admin/src/main/java/com/style24/persistence/domain/Notice.java

@@ -0,0 +1,47 @@
+package com.style24.persistence.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.style24.persistence.TscBaseDomain;
+
+import lombok.Data;
+
+/**
+ * 공지사항 Domain
+ * 
+ * @author gagamel
+ * @since 2020. 10. 30
+ */
+@SuppressWarnings("serial")
+@Data
+public class Notice extends TscBaseDomain {
+
+	private Integer noticeSq;		// 공지사항일련번호
+	private String noticeType;		// 공지사항유형
+	private String urgentYn;		// 긴급여부
+	private String noticeTitle;		// 공지사항제목
+	private String noticeContent;	// 공지사항내용
+	private int fileCnt;			// 파일건수
+	private String noticeStdt;		// 공지시작일시
+	private String noticeEddt;		// 공지종료일시
+	private int readCnt;			// 조회수
+	private String useYn;			// 사용여부
+
+	// 검색용
+	private String startDt;			// 시작일자
+	private String endDt;			// 종료일자
+	private String receiverId;		// 수신자ID
+
+	// 공지사항 수신자
+	@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
+	private String[] receiverIds;
+
+	// 공지사항 첨부파일
+	private Integer seq;
+	private String orgFileNm;
+	private String sysFileNm;
+	@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
+	private String[] orgFileNms;
+	@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
+	private String[] sysFileNms;
+
+}

+ 175 - 0
style24.admin/src/main/java/com/style24/persistence/mybatis/shop/TsaNotice.xml

@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.style24.admin.biz.dao.TsaNoticeDao">
+
+	<!-- 공지사항 목록 -->
+	<select id="getNoticeList" parameterType="Notice" resultType="Notice">
+		/* TsaNotice.getNoticeList */
+		SELECT A.NOTICE_SQ                                         /*공지번호*/
+		     , A.NOTICE_TYPE                                       /*공지유형*/
+		     , A.URGENT_YN                                         /*긴급여부*/
+		     , A.NOTICE_TITLE                                      /*공지제목*/
+		     , A.NOTICE_CONTENT                                    /*공지내용*/
+		     , IFNULL((SELECT COUNT(*)
+		               FROM   TB_NOTICE_FILE
+		               WHERE  NOTICE_SQ = A.NOTICE_SQ
+		              ),0)                          AS FILE_CNT    /*파일건수*/
+		     , DATE_FORMAT(A.NOTICE_STDT,'%Y%m%d')  AS NOTICE_STDT /*공지시작일자*/
+		     , DATE_FORMAT(A.NOTICE_EDDT,'%Y%m%d')  AS NOTICE_EDDT /*공지종료일자*/
+		     , A.USE_YN                                            /*사용여부*/
+		     , A.READ_CNT                                          /*조회수*/
+		     , FN_GET_USER_NM(A.REG_NO)             AS REG_NM      /*등록자*/
+		     , DATE_FORMAT(A.REG_DT,'%Y%m%d%H%i%S') AS REG_DT      /*등록일시*/
+		     , FN_GET_USER_NM(A.UPD_NO)             AS UPD_NM      /*수정자*/
+		     , DATE_FORMAT(A.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT      /*수정일시*/
+		FROM   TB_NOTICE A
+		WHERE  A.NOTICE_TYPE = #{noticeType}
+		<if test="startDt != null and startDt !=''">
+		AND    A.REG_DT <![CDATA[>=]]> STR_TO_DATE(#{startDt},'%Y-%m-%d')
+		</if>
+		<if test="startDt != null and startDt !='' and endDt != null and endDt != ''">
+		AND    A.REG_DT <![CDATA[<]]> DATE_ADD(STR_TO_DATE(#{endDt},'%Y-%m-%d'),INTERVAL 1 DAY)
+		</if>
+		<if test='useYn != null and useYn !=""'>
+		AND    A.USE_YN = #{useYn}
+		</if>
+		<if test="noticeTitle != null and noticeTitle !=''">
+		AND    LOWER(A.NOTICE_TITLE) LIKE CONCAT('%',LOWER(#{noticeTitle}),'%')
+		</if>
+		<if test='receiverId != null and receiverId !=""'>
+		AND    A.NOTICE_SQ IN (SELECT NOTICE_SQ
+		                       FROM   TB_NOTICE_RECEIVER
+		                       WHERE  RECEIVER_ID = #{receiverId}
+		                      )
+		</if>
+		ORDER  BY A.URGENT_YN DESC, A.NOTICE_SQ DESC
+	</select>
+
+	<!-- 공지사항 수신자 목록 -->
+	<select id="getNoticeReceiverList" parameterType="Integer" resultType="Notice">
+		/* TsaNotice.getNoticeReceiverList */
+		SELECT RECEIVER_ID
+		FROM   TB_NOTICE_RECEIVER
+		WHERE  NOTICE_SQ = #{noticeSq}
+	</select>
+
+	<!-- 공지사항 파일 목록 -->
+	<select id="getNoticeFileList" parameterType="Integer" resultType="Notice">
+		/* TsaNotice.getNoticeFileList */
+		SELECT NOTICE_SQ
+		     , SEQ
+		     , ORG_FILE_NM
+		     , SYS_FILE_NM
+		FROM   TB_NOTICE_FILE
+		WHERE  NOTICE_SQ = #{noticeSq}
+	</select>
+
+	<!-- 공지사항 저장 -->
+	<insert id="createNotice" parameterType="Notice" keyProperty="noticeSq">
+		/* TsaNotice.createNotice */
+		INSERT INTO TB_NOTICE (
+		       NOTICE_SQ
+		     , NOTICE_TYPE
+		     , NOTICE_TITLE
+		     , NOTICE_STDT
+		     , NOTICE_EDDT
+		     , NOTICE_CONTENT
+		     , URGENT_YN
+		     , USE_YN
+		     , READ_CNT
+		     , REG_NO
+		     , REG_DT
+		     , UPD_NO
+		     , UPD_DT
+		)
+		VALUES (
+		       NULL
+		     , #{noticeType}
+		     , #{noticeTitle}
+		     , STR_TO_DATE(#{noticeStdt},'%Y-%m-%d')
+		     , STR_TO_DATE(#{noticeEddt},'%Y-%m-%d')
+		     , #{noticeContent}
+		     , IFNULL(#{urgentYn},'N')
+		     , #{useYn}
+		     , IFNULL(#{readCnt},0)
+		     , #{regNo}
+		     , NOW()
+		     , #{updNo}
+		     , NOW()
+		)
+	</insert>
+
+	<!-- 공지사항 수정 -->
+	<update id="updateNotice" parameterType="Notice">
+		/* TsaNotice.updateNotice */
+		UPDATE TB_NOTICE
+		SET    NOTICE_TITLE = #{noticeTitle}
+		     , NOTICE_CONTENT = #{noticeContent}
+		     , NOTICE_STDT = STR_TO_DATE(#{noticeStdt},'%Y-%m-%d')
+		     , NOTICE_EDDT = STR_TO_DATE(#{noticeEddt},'%Y-%m-%d')
+		     , URGENT_YN = IFNULL(#{urgentYn},'N')
+		     , USE_YN = #{useYn}
+		     , UPD_NO = #{updNo}
+		     , UPD_DT = NOW()
+		WHERE  NOTICE_SQ = #{noticeSq}
+	</update>
+
+	<!-- 공지사항 수신자 삭제 -->
+	<delete id="deleteNoticeReceiver" parameterType="Notice">
+		/* TsaNotice.deleteNoticeReceiver */
+		DELETE FROM TB_NOTICE_RECEIVER
+		WHERE  NOTICE_SQ = #{noticeSq}
+	</delete>
+
+	<!--공지사항 수신자 등록 -->
+	<insert id="createNoticeReceiver" parameterType="Notice">
+		/* TsaNotice.createNoticeReceiver */
+		INSERT INTO TB_NOTICE_RECEIVER (
+		       NOTICE_SQ
+		     , RECEIVER_ID
+		     , REG_NO
+		     , REG_DT
+		)
+		VALUES (
+		       #{noticeSq}
+		     , #{receiverId}
+		     , #{regNo}
+		     , NOW()
+		)
+	</insert>
+
+	<!-- 공지사항 파일 삭제 -->
+	<delete id="deleteNoticeFile" parameterType="Notice">
+		/* TsaNotice.deleteNoticeFile */
+		DELETE FROM TB_NOTICE_FILE
+		WHERE  NOTICE_SQ = #{noticeSq}
+		<if test="seq != null and seq !=''">
+		AND    SEQ = #{seq}
+		</if>
+	</delete>
+
+	<!-- 공지사항 파일 저장 -->
+	<insert id="createNoitceFlie" parameterType="Notice">
+		/* TsaNotice.createNoitceFlie */
+		INSERT INTO TB_NOTICE_FILE (
+		       NOTICE_SQ
+		     , SEQ
+		     , ORG_FILE_NM
+		     , SYS_FILE_NM
+		     , REG_NO
+		     , REG_DT
+		)
+		VALUES (
+		       #{noticeSq}
+		     , IFNULL((SELECT MAX(SEQ)
+		               FROM   TB_NOTICE_FILE
+		               WHERE  NOTICE_SQ = #{noticeSq}
+		              ),0) + 1
+		     , #{orgFileNm}
+		     , #{sysFileNm}
+		     , #{regNo}
+		     , NOW()
+		)
+	</insert>
+
+</mapper>