단속사진관련 기능 이동(FileController -> Crdn06Controller)
parent
0171f96c4a
commit
a239d8d323
@ -1,308 +0,0 @@
|
||||
package cokr.xit.fims.base.web;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import cokr.xit.base.file.dao.FileMapper;
|
||||
import cokr.xit.base.file.service.FileQuery;
|
||||
import cokr.xit.base.file.service.bean.FileBean;
|
||||
import cokr.xit.fims.crdn.Crdn;
|
||||
import cokr.xit.fims.crdn.dao.CrdnInfoMapper;
|
||||
import cokr.xit.fims.sprt.Sprt;
|
||||
import cokr.xit.fims.sprt.service.bean.MediaBean;
|
||||
import cokr.xit.foundation.Downloadable;
|
||||
import cokr.xit.foundation.data.DataObject;
|
||||
|
||||
@Controller
|
||||
public class FileController extends cokr.xit.base.file.web.FileController {
|
||||
@Resource(name = "fileMapper")
|
||||
private FileMapper fileMapper;
|
||||
|
||||
@Resource(name = "crdnInfoMapper")
|
||||
private CrdnInfoMapper crdnInfoMapper;
|
||||
|
||||
@Resource(name="fileBean")
|
||||
private FileBean fileBean;
|
||||
|
||||
@Resource(name="mediaBean")
|
||||
private MediaBean mediaBean;
|
||||
|
||||
@Override
|
||||
public ModelAndView getFileList(FileQuery req) {
|
||||
ModelAndView mav = new ModelAndView("jsonView");
|
||||
|
||||
String infoType = ifEmpty(req.getInfoType(), () -> "");
|
||||
boolean singleKey = (req.getInfoKeys() != null && req.getInfoKeys().length == 1);
|
||||
|
||||
//파일 목록
|
||||
List<DataObject> fileInfoList = fileService().getFileList(req);
|
||||
for(DataObject fileInfo : fileInfoList) {
|
||||
List<DataObject> mosaicInfos = mediaBean.getMosaicList(fileInfo.string("FILE_ID"));
|
||||
if(mosaicInfos != null) {
|
||||
String mosaic = "";
|
||||
for(int i=0; i < mosaicInfos.size(); i++) {
|
||||
DataObject mosaicInfo = mosaicInfos.get(i);
|
||||
if(i != 0) {
|
||||
mosaic += "|";
|
||||
}
|
||||
mosaic += mosaicInfo.string("X_AXS")
|
||||
+ "," + mosaicInfo.string("Y_AXS")
|
||||
+ "," + mosaicInfo.string("MOSC_LEN")
|
||||
+ "," + mosaicInfo.string("MOSC_HGT");
|
||||
}
|
||||
fileInfo.set("MOSAIC", mosaic);
|
||||
} else {
|
||||
fileInfo.set("MOSAIC", "");
|
||||
}
|
||||
|
||||
}
|
||||
mav = setPagingInfo(mav, fileInfoList, "file");
|
||||
|
||||
//민원 동영상파일 첨부 여부
|
||||
String cvlcptVideoExistYn = "N";
|
||||
if(infoType.equals(Crdn.INF_TYPE) && singleKey) {
|
||||
|
||||
DataObject dataObject = crdnInfoMapper.selectCrdnInfo(req.getInfoKeys()[0]);
|
||||
|
||||
String linkTblNm = dataObject.string("LINK_TBL_NM");
|
||||
if(!linkTblNm.equals("")) { //민원연계자료
|
||||
FileQuery cvlcptFileQuery = new FileQuery();
|
||||
if(linkTblNm.equals("TB_ESB_INTERFACE")) {
|
||||
cvlcptFileQuery.setInfoType("010");
|
||||
} else if(linkTblNm.equals("TB_SA_CVLCPT_DTL")) {
|
||||
cvlcptFileQuery.setInfoType("020");
|
||||
} else {
|
||||
throw new RuntimeException("파일 조회 중 오류가 발생하였습니다.");
|
||||
}
|
||||
|
||||
cvlcptFileQuery.setInfoKeys(dataObject.string("LINK_ID"));
|
||||
List<DataObject> linkFileList = fileBean.getFileList(cvlcptFileQuery);
|
||||
if(linkFileList != null && !linkFileList.isEmpty()) {
|
||||
for(int i=0; i < linkFileList.size(); i++) {
|
||||
String mimeType = linkFileList.get(i).string("MIME_TYPE");
|
||||
if(Arrays.asList(Sprt.VIDEO_MIME_TYPE).contains(mimeType)) {
|
||||
cvlcptVideoExistYn = "Y";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mav.addObject("cvlcptVideoExistYn", cvlcptVideoExistYn);
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
|
||||
/** 메뉴얼을 다운로드한다.
|
||||
* @return 메뉴얼 파일
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping(name = "메뉴얼 다운로드", value = "/downloadMenual.do")
|
||||
public ModelAndView downloadMenual() throws Exception {
|
||||
ModelAndView mav = new ModelAndView("downloadView");
|
||||
|
||||
String filePath = ("menual/메뉴얼.pptx");
|
||||
ClassPathResource cps = new ClassPathResource(filePath);
|
||||
String menualVersion = "";
|
||||
try (XMLSlideShow slideShow = new XMLSlideShow(cps.getInputStream())) {
|
||||
menualVersion = slideShow
|
||||
.getProperties()
|
||||
.getCoreProperties()
|
||||
.getUnderlyingProperties()
|
||||
.getVersionProperty()
|
||||
.get();
|
||||
}
|
||||
|
||||
InputStream menualIS = cps.getInputStream();
|
||||
byte[] menualBytes = menualIS.readAllBytes();
|
||||
menualIS.close();
|
||||
|
||||
Consumer<OutputStream> writer = new Consumer<OutputStream>() {
|
||||
@Override
|
||||
public void accept(OutputStream os) {
|
||||
try {
|
||||
os.write(menualBytes);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mav.addObject("download",
|
||||
new Downloadable()
|
||||
.setContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation")
|
||||
.setWriter(writer)
|
||||
.setFilename("과태료통합관리시스템_메뉴얼"+"("+"v"+menualVersion+")"+".pptx")
|
||||
);
|
||||
|
||||
return mav;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(name = "SVG 이미지 파일 색상 변경", value = "/modifySvg/**")
|
||||
public void modifySvg(HttpServletRequest request, HttpServletResponse response) throws URISyntaxException, IOException, ParserConfigurationException, SAXException {
|
||||
String requestURI = request.getRequestURI().toString();
|
||||
|
||||
String filepath = requestURI.split("modifySvg")[1];
|
||||
filepath = URLDecoder.decode(filepath, "UTF-8");
|
||||
filepath = filepath.replaceAll("/", Matcher.quoteReplacement(File.separator));
|
||||
filepath = "svg" + filepath;
|
||||
|
||||
ClassPathResource resource = new ClassPathResource(filepath);
|
||||
InputStream is = resource.getInputStream();
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(is);
|
||||
Element root = document.getDocumentElement();
|
||||
NodeList nodeList = root.getChildNodes();
|
||||
|
||||
try {
|
||||
String modify = request.getParameter("modify");
|
||||
if(modify == null || modify.equals("")){
|
||||
|
||||
} else if(modify.equals("active")){
|
||||
updateTagFillColor(nodeList, "green");
|
||||
} else if(modify.equals("alert")){
|
||||
updateTagFillColor(nodeList, "red");
|
||||
}
|
||||
|
||||
String str4 = DocumentToString(document);
|
||||
byte[] bytes = str4.getBytes();
|
||||
|
||||
response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes");
|
||||
response.setHeader(HttpHeaders.CONTENT_TYPE, "image/svg+xml");
|
||||
response.setHeader(HttpHeaders.CONNECTION, "keep-alive");
|
||||
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, must-revalidate");
|
||||
response.setDateHeader(HttpHeaders.EXPIRES, 0);
|
||||
response.setHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
|
||||
response.setContentType("image/svg+xml");
|
||||
|
||||
OutputStream os = response.getOutputStream();
|
||||
os.write(bytes);
|
||||
os.flush();
|
||||
os.close();
|
||||
|
||||
|
||||
} catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String DocumentToString( Document doc )
|
||||
{
|
||||
try
|
||||
{
|
||||
StringWriter clsOutput = new StringWriter( );
|
||||
Transformer clsTrans = TransformerFactory.newInstance( ).newTransformer( );
|
||||
|
||||
clsTrans.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "no" );
|
||||
clsTrans.setOutputProperty( OutputKeys.METHOD, "xml" );
|
||||
clsTrans.setOutputProperty( OutputKeys.INDENT, "yes" );
|
||||
clsTrans.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
|
||||
|
||||
clsTrans.transform( new DOMSource( doc ), new StreamResult( clsOutput ) );
|
||||
|
||||
return clsOutput.toString( );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTagFillColor(NodeList nodeList, String newFillColor) {
|
||||
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
Node node = nodeList.item(i);
|
||||
NamedNodeMap namedNodeMap = node.getAttributes();
|
||||
if(namedNodeMap != null && namedNodeMap.getLength() > 0){
|
||||
for (int j = 0; j < namedNodeMap.getLength(); j++) {
|
||||
Node namedNode = namedNodeMap.item(j);
|
||||
if (namedNode.getNodeName().equalsIgnoreCase("fill")) {
|
||||
namedNode.setNodeValue(newFillColor); // Change the color of the fill attribute.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(name = "처리 전 파일업로드", value = "/uploadBeforeProcess.do")
|
||||
public ModelAndView uploadBeforeProcess(MultipartFile[] uploadFiles) {
|
||||
ModelAndView mav = new ModelAndView("jsonView");
|
||||
|
||||
boolean saved = false;
|
||||
|
||||
MultipartFile uploadFile = uploadFiles[0];
|
||||
String orginalFileName = uploadFile.getOriginalFilename();
|
||||
String extension = FilenameUtils.getExtension(orginalFileName);
|
||||
|
||||
SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String currentTime = ymdhmsFormat.format(new Date());
|
||||
|
||||
String folderPath = "files/temp/uploadFirst";
|
||||
File folder = new File(folderPath);
|
||||
folder.mkdirs();
|
||||
String filePath = folderPath + "/"+currentTime+"."+extension;
|
||||
File file = new File(filePath);
|
||||
|
||||
|
||||
try {
|
||||
uploadFile.transferTo(file);
|
||||
saved = true;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("파일업로드 오류"+e);
|
||||
}
|
||||
|
||||
mav.addObject("saved", saved);
|
||||
mav.addObject("filePath", filePath);
|
||||
return mav;
|
||||
}
|
||||
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
<?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="cokr.xit.base.file.dao.FileMapper">
|
||||
|
||||
<resultMap id="fileRow" type="cokr.xit.base.file.FileInfo">
|
||||
<result property="id" column="FILE_ID"/>
|
||||
<result property="infoType" column="INF_TYPE"/>
|
||||
<result property="infoKey" column="INF_KEY"/>
|
||||
<result property="subType" column="SUB_TYPE"/>
|
||||
<result property="name" column="FILE_NM"/>
|
||||
<result property="path" column="FILE_PATH"/>
|
||||
<result property="url" column="URL"/>
|
||||
<result property="mimeType" column="MIME_TYPE"/>
|
||||
<result property="size" column="FILE_SIZE"/>
|
||||
<result property="downloadCount" column="DNLD_CNT"/>
|
||||
<result property="sortOrder" column="SRT_ORD"/>
|
||||
<result property="createdAt" column="REG_DT"/>
|
||||
<result property="createdBy" column="RGTR"/>
|
||||
<result property="useYN" column="USE_YN"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="fileDir">CONCAT('files/', DIR, DATE_FORMAT(CURRENT_DATE, '/%Y/%m/%d/'))</sql>
|
||||
<sql id="fileUrl">FILE_PATH</sql>
|
||||
|
||||
<sql id="fileDirs">
|
||||
SELECT INF_TYPE
|
||||
,<include refid="cokr.xit.base.file.dao.FileMapper.fileDir" /> DIR
|
||||
FROM (
|
||||
SELECT '010' INF_TYPE, 'interface/attachment/smg' DIR UNION <!-- 국민 신문고 -->
|
||||
SELECT '020' INF_TYPE, 'interface/attachment/saeol' DIR UNION <!-- 세올 -->
|
||||
SELECT '030' INF_TYPE, 'interface/attachment/epost' DIR UNION <!-- epost -->
|
||||
|
||||
SELECT '100' INF_TYPE, 'attachment/violation' DIR UNION <!-- 단속 정보 -->
|
||||
SELECT '110' INF_TYPE, 'attachment/opinion' DIR UNION <!-- 의견 진술 -->
|
||||
SELECT '120' INF_TYPE, 'attachment/rent' DIR UNION <!-- 렌트카 첨부파일 -->
|
||||
SELECT '190' INF_TYPE, 'attachment/capture' DIR <!-- 캡쳐용 동영상 -->
|
||||
) FILE_DIRS
|
||||
</sql>
|
||||
|
||||
<sql id="selectFiles">
|
||||
<if test="fileIDs != null">
|
||||
SELECT A.FILE_ID
|
||||
, A.INF_TYPE
|
||||
, A.INF_KEY
|
||||
, A.SUB_TYPE
|
||||
, A.FILE_NM
|
||||
, A.FILE_PATH
|
||||
, A.MIME_TYPE
|
||||
, A.FILE_SIZE
|
||||
, A.DNLD_CNT
|
||||
, A.SRT_ORD
|
||||
, A.USE_YN
|
||||
, A.REG_DT
|
||||
, A.RGTR
|
||||
,<include refid="cokr.xit.base.file.dao.FileMapper.fileUrl" /> AS URL
|
||||
FROM TB_FILE A
|
||||
WHERE FILE_ID IN (<foreach collection="fileIDs" item="fileID" separator=",">#{fileID}</foreach>)
|
||||
ORDER BY FILE_ID
|
||||
</if>
|
||||
<if test="fileIDs == null">
|
||||
<include refid="utility.paging-prefix" />
|
||||
SELECT A.FILE_ID
|
||||
, A.INF_TYPE
|
||||
, A.INF_KEY
|
||||
, A.SUB_TYPE
|
||||
, A.FILE_NM
|
||||
, A.FILE_PATH
|
||||
, A.MIME_TYPE
|
||||
, A.FILE_SIZE
|
||||
, A.DNLD_CNT
|
||||
, A.SRT_ORD
|
||||
, A.USE_YN
|
||||
, A.REG_DT
|
||||
, A.RGTR
|
||||
,<include refid="cokr.xit.base.file.dao.FileMapper.fileUrl" /> AS URL
|
||||
FROM TB_FILE A
|
||||
<where>
|
||||
<if test="infoType != null"> AND A.INF_TYPE = #{infoType}</if>
|
||||
<if test="infoKeys != null"> AND INF_KEY IN (<foreach collection="infoKeys" item="infoKey" separator=",">#{infoKey}</foreach>)</if>
|
||||
AND USE_YN = 'Y'
|
||||
</where>
|
||||
<include refid="utility.orderBy" />
|
||||
<include refid="utility.paging-suffix" />
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="getFileList" parameterType="map" resultType="dataobject">
|
||||
/* 파일 목록 조회(fileMapper.getFileList) */
|
||||
<include refid="selectFiles" />
|
||||
</select>
|
||||
|
||||
<select id="getFilesOf" parameterType="map" resultMap="fileRow">
|
||||
/* 파일 가져오기(fileMapper.getFilesOf) */
|
||||
<include refid="selectFiles" />
|
||||
</select>
|
||||
|
||||
<select id="getFiles" parameterType="map" resultMap="fileRow">
|
||||
/* 파일 가져오기(fileMapper.getFiles) */
|
||||
<include refid="selectFiles" />
|
||||
</select>
|
||||
|
||||
<insert id="insertFile" parameterType="map">
|
||||
/* 파일 등록(fileMapper.insertFile) */
|
||||
<selectKey keyProperty="file.id,file.path" keyColumn="NEW_ID,PATH" resultType="map" order="BEFORE">
|
||||
SELECT NEW_ID
|
||||
, CONCAT(DIR, NEW_ID, '.', #{file.extension}) PATH
|
||||
FROM (
|
||||
SELECT NVL(MAX(FILE_ID) + 1, CONCAT(THIS_DAY, '00001')) NEW_ID
|
||||
FROM (<include refid="utility.selectThisDay" />) B
|
||||
LEFT OUTER JOIN TB_FILE A ON FILE_ID LIKE CONCAT(THIS_DAY, '%')
|
||||
) T1
|
||||
, (
|
||||
<include refid="fileDirs" />
|
||||
WHERE INF_TYPE = #{file.infoType}
|
||||
) T2
|
||||
</selectKey>
|
||||
INSERT INTO TB_FILE (
|
||||
FILE_ID
|
||||
, INF_TYPE
|
||||
, INF_KEY
|
||||
, SUB_TYPE
|
||||
, FILE_NM
|
||||
, FILE_PATH
|
||||
, MIME_TYPE
|
||||
, FILE_SIZE
|
||||
, DNLD_CNT
|
||||
, SRT_ORD
|
||||
, RGTR
|
||||
, REG_DT
|
||||
, USE_YN
|
||||
) VALUES (
|
||||
#{file.id}
|
||||
, #{file.infoType}
|
||||
, #{file.infoKey}
|
||||
, #{file.subType}
|
||||
, #{file.name}
|
||||
, #{file.path}
|
||||
, #{file.mimeType}
|
||||
, #{file.size}
|
||||
, #{file.downloadCount}
|
||||
, #{file.sortOrder}
|
||||
, #{currentUser.id}
|
||||
,<include refid="utility.now" />
|
||||
, 'Y'
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="reorder" parameterType="map">
|
||||
/* 파일 순서 변경(fileMapper.reorder) */
|
||||
UPDATE TB_FILE
|
||||
SET SRT_ORD = CASE FILE_ID
|
||||
<foreach collection="fileIDs" item="fileID" index="index" separator=" ">
|
||||
WHEN #{fileID} THEN #{index}
|
||||
</foreach>
|
||||
ELSE SRT_ORD END
|
||||
WHERE FILE_ID IN (<foreach collection="fileIDs" item="fileID" separator=",">#{fileID}</foreach>)
|
||||
</update>
|
||||
|
||||
<update id="updateDownloadCount" parameterType="map">
|
||||
/* 다운로드 횟수 증가(fileMapper.updateDownloadCount) */
|
||||
UPDATE TB_FILE SET
|
||||
DNLD_CNT = DNLD_CNT + 1
|
||||
WHERE USE_YN = 'Y'
|
||||
AND FILE_ID IN (<foreach collection="fileIDs" item="fileID" separator=",">#{fileID}</foreach>)
|
||||
</update>
|
||||
|
||||
<update id="removeFiles" parameterType="map">
|
||||
/* 파일 제거(fileMapper.removeFiles) */
|
||||
UPDATE TB_FILE
|
||||
SET USE_YN = 'N'
|
||||
WHERE USE_YN = 'Y'
|
||||
<if test="fileIDs != null"> AND FILE_ID IN (<foreach collection="fileIDs" item="fileID" separator=",">#{fileID}</foreach>)</if>
|
||||
<if test="infoKeys != null">
|
||||
AND INF_TYPE = #{infoType}
|
||||
AND INF_KEY IN (<foreach collection="infoKeys" item="infoKey" separator=",">#{infoKey}</foreach>)</if>
|
||||
</update>
|
||||
|
||||
<delete id="deleteFiles" parameterType="map">/* 파일 삭제(fileMapper.deleteFiles) */
|
||||
DELETE
|
||||
FROM TB_FILE
|
||||
<if test="fileIDs != null">WHERE FILE_ID IN (<foreach collection="fileIDs" item="fileID" separator=",">#{fileID}</foreach>)</if>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue