딱히 없음
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package co.nook.app.DefaultTodo.dao;
|
||||
|
||||
import co.nook.app.DefaultTodo.service.DefaultTodoMapper;
|
||||
import co.nook.app.DefaultTodo.service.DefaultTodoService;
|
||||
import co.nook.app.DefaultTodo.vo.DefaultTodoVo;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Repository("defaultTodoDao")
|
||||
public class DefaultTodoDao implements DefaultTodoService{
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
public DefaultTodoDao( JdbcTemplate jdbcTemplate){
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
private final String SELECT_ALL = "SELECT * from defaultTodo";
|
||||
@Override
|
||||
public ArrayList<DefaultTodoVo> selectAll(){
|
||||
return (ArrayList<DefaultTodoVo>)jdbcTemplate.query(SELECT_ALL , new DefaultTodoMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultTodoVo select(int key){
|
||||
return null;
|
||||
}
|
||||
|
||||
private final String INSERT = "INSERT INTO defaultTodo " +
|
||||
"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
@Override
|
||||
public int insert(DefaultTodoVo vo){
|
||||
return jdbcTemplate.update(INSERT,
|
||||
vo.getdTodoNo(),
|
||||
vo.getdIsAlways(),
|
||||
vo.getdContent(),
|
||||
vo.getdDay(),
|
||||
vo.getdMinCount(),
|
||||
vo.getdMaxCount(),
|
||||
vo.getdNpcName(),
|
||||
vo.getdIsEvent(),
|
||||
vo.getdEventStartDate(),
|
||||
vo.getdEventStartHour(),
|
||||
vo.getdEventEndDate(),
|
||||
vo.getdEventEndHour(),
|
||||
vo.getdSpecialFunction(),
|
||||
vo.getdSpecialData1(),
|
||||
vo.getdSpecialData2(),
|
||||
vo.getdSpecialData3(),
|
||||
vo.getdSpecialData4()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(DefaultTodoVo vo){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int key){
|
||||
return 0;
|
||||
}
|
||||
|
||||
private final String TRUNCATE = "TRUNCATE TABLE defaultTodo";
|
||||
@Override
|
||||
public void truncate(){
|
||||
jdbcTemplate.update(TRUNCATE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package co.nook.app.DefaultTodo.service;
|
||||
|
||||
import co.nook.app.DefaultTodo.vo.DefaultTodoVo;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DefaultTodoMapper implements RowMapper<DefaultTodoVo>{
|
||||
@Override
|
||||
public DefaultTodoVo mapRow(ResultSet rs, int rowNum) throws SQLException{
|
||||
DefaultTodoVo vo = new DefaultTodoVo();
|
||||
|
||||
vo.setdTodoNo(rs.getInt("dTodoNo"));
|
||||
vo.setdIsAlways(rs.getString("dIsAlways"));
|
||||
vo.setdContent(rs.getString("dContent"));
|
||||
vo.setdDay(rs.getString("dDay"));
|
||||
vo.setdMinCount(rs.getInt("dMinCount"));
|
||||
vo.setdMaxCount(rs.getInt("dMaxCount"));
|
||||
vo.setdNpcName(rs.getString("dNpcName"));
|
||||
vo.setdIsEvent(rs.getString("dIsEvent"));
|
||||
vo.setdEventStartDate(rs.getString("dEventStartDate"));
|
||||
vo.setdEventStartHour(rs.getInt("dEventStartHour"));
|
||||
vo.setdEventEndDate(rs.getString("dEventEndDate"));
|
||||
vo.setdEventEndHour(rs.getInt("dEventEndHour"));
|
||||
vo.setdSpecialFunction(rs.getString("dSpecialFunction"));
|
||||
vo.setdSpecialData1(rs.getString("dSpecialData1"));
|
||||
vo.setdSpecialData2(rs.getString("dSpecialData2"));
|
||||
vo.setdSpecialData3(rs.getString("dSpecialData3"));
|
||||
vo.setdSpecialData4(rs.getString("dSpecialData4"));
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package co.nook.app.DefaultTodo.service;
|
||||
|
||||
import co.nook.app.DefaultTodo.vo.DefaultTodoVo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface DefaultTodoService{
|
||||
public ArrayList<DefaultTodoVo> selectAll();
|
||||
public DefaultTodoVo select(int key);
|
||||
public int insert(DefaultTodoVo vo);
|
||||
public int update(DefaultTodoVo vo);
|
||||
public int delete(int key);
|
||||
public void truncate();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package co.nook.app.DefaultTodo.service;
|
||||
|
||||
import co.nook.app.DefaultTodo.dao.DefaultTodoDao;
|
||||
import co.nook.app.DefaultTodo.vo.DefaultTodoVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Service("defaultTodoService")
|
||||
public class DefaultTodoServiceImpl implements DefaultTodoService{
|
||||
|
||||
public DefaultTodoDao defaultTodoDao;
|
||||
|
||||
@Autowired
|
||||
public DefaultTodoServiceImpl(DefaultTodoDao defaultTodoDao){
|
||||
this.defaultTodoDao = defaultTodoDao;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ArrayList<DefaultTodoVo> selectAll(){
|
||||
return defaultTodoDao.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultTodoVo select(int key){
|
||||
return defaultTodoDao.select(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(DefaultTodoVo vo){
|
||||
return defaultTodoDao.insert(vo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(DefaultTodoVo vo){
|
||||
return defaultTodoDao.update(vo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(int key){
|
||||
return defaultTodoDao.delete(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void truncate(){
|
||||
defaultTodoDao.truncate();
|
||||
}
|
||||
}
|
||||
157
src/main/java/co/nook/app/DefaultTodo/vo/DefaultTodoVo.java
Normal file
157
src/main/java/co/nook/app/DefaultTodo/vo/DefaultTodoVo.java
Normal file
@@ -0,0 +1,157 @@
|
||||
package co.nook.app.DefaultTodo.vo;
|
||||
|
||||
public class DefaultTodoVo{
|
||||
private int dTodoNo;
|
||||
private String dIsAlways;
|
||||
private String dContent;
|
||||
private String dDay;
|
||||
private Integer dMinCount;
|
||||
private Integer dMaxCount;
|
||||
private String dNpcName;
|
||||
private String dIsEvent;
|
||||
private String dEventStartDate;
|
||||
private Integer dEventStartHour;
|
||||
private String dEventEndDate;
|
||||
private Integer dEventEndHour;
|
||||
private String dSpecialFunction;
|
||||
private String dSpecialData1;
|
||||
private String dSpecialData2;
|
||||
private String dSpecialData3;
|
||||
private String dSpecialData4;
|
||||
|
||||
public int getdTodoNo(){
|
||||
return dTodoNo;
|
||||
}
|
||||
|
||||
public void setdTodoNo(int dTodoNo){
|
||||
this.dTodoNo = dTodoNo;
|
||||
}
|
||||
|
||||
public String getdIsAlways(){
|
||||
return dIsAlways;
|
||||
}
|
||||
|
||||
public void setdIsAlways(String dIsAlways){
|
||||
this.dIsAlways = dIsAlways;
|
||||
}
|
||||
|
||||
public String getdContent(){
|
||||
return dContent;
|
||||
}
|
||||
|
||||
public void setdContent(String dContent){
|
||||
this.dContent = dContent;
|
||||
}
|
||||
|
||||
public String getdDay(){
|
||||
return dDay;
|
||||
}
|
||||
|
||||
public void setdDay(String dDay){
|
||||
this.dDay = dDay;
|
||||
}
|
||||
|
||||
public Integer getdMinCount(){
|
||||
return dMinCount;
|
||||
}
|
||||
|
||||
public void setdMinCount(Integer dMinCount){
|
||||
this.dMinCount = dMinCount;
|
||||
}
|
||||
|
||||
public Integer getdMaxCount(){
|
||||
return dMaxCount;
|
||||
}
|
||||
|
||||
public void setdMaxCount(Integer dMaxCount){
|
||||
this.dMaxCount = dMaxCount;
|
||||
}
|
||||
|
||||
public String getdNpcName(){
|
||||
return dNpcName;
|
||||
}
|
||||
|
||||
public void setdNpcName(String dNpcName){
|
||||
this.dNpcName = dNpcName;
|
||||
}
|
||||
|
||||
public String getdIsEvent(){
|
||||
return dIsEvent;
|
||||
}
|
||||
|
||||
public void setdIsEvent(String dIsEvent){
|
||||
this.dIsEvent = dIsEvent;
|
||||
}
|
||||
|
||||
public String getdEventStartDate(){
|
||||
return dEventStartDate;
|
||||
}
|
||||
|
||||
public void setdEventStartDate(String dEventStartDate){
|
||||
this.dEventStartDate = dEventStartDate;
|
||||
}
|
||||
|
||||
public Integer getdEventStartHour(){
|
||||
return dEventStartHour;
|
||||
}
|
||||
|
||||
public void setdEventStartHour(Integer dEventStartHour){
|
||||
this.dEventStartHour = dEventStartHour;
|
||||
}
|
||||
|
||||
public String getdEventEndDate(){
|
||||
return dEventEndDate;
|
||||
}
|
||||
|
||||
public void setdEventEndDate(String dEventEndDate){
|
||||
this.dEventEndDate = dEventEndDate;
|
||||
}
|
||||
|
||||
public Integer getdEventEndHour(){
|
||||
return dEventEndHour;
|
||||
}
|
||||
|
||||
public void setdEventEndHour(Integer dEventEndHour){
|
||||
this.dEventEndHour = dEventEndHour;
|
||||
}
|
||||
|
||||
public String getdSpecialFunction(){
|
||||
return dSpecialFunction;
|
||||
}
|
||||
|
||||
public void setdSpecialFunction(String dSpecialFunction){
|
||||
this.dSpecialFunction = dSpecialFunction;
|
||||
}
|
||||
|
||||
public String getdSpecialData1(){
|
||||
return dSpecialData1;
|
||||
}
|
||||
|
||||
public void setdSpecialData1(String dSpecialData1){
|
||||
this.dSpecialData1 = dSpecialData1;
|
||||
}
|
||||
|
||||
public String getdSpecialData2(){
|
||||
return dSpecialData2;
|
||||
}
|
||||
|
||||
public void setdSpecialData2(String dSpecialData2){
|
||||
this.dSpecialData2 = dSpecialData2;
|
||||
}
|
||||
|
||||
public String getdSpecialData3(){
|
||||
return dSpecialData3;
|
||||
}
|
||||
|
||||
public void setdSpecialData3(String dSpecialData3){
|
||||
this.dSpecialData3 = dSpecialData3;
|
||||
}
|
||||
|
||||
public String getdSpecialData4(){
|
||||
return dSpecialData4;
|
||||
}
|
||||
|
||||
public void setdSpecialData4(String dSpecialData4){
|
||||
this.dSpecialData4 = dSpecialData4;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package co.nook.app.DefaultTodo.web;
|
||||
|
||||
import co.nook.app.DefaultTodo.service.DefaultTodoService;
|
||||
import co.nook.app.DefaultTodo.vo.DefaultTodoVo;
|
||||
import com.opencsv.CSVReader;
|
||||
import com.opencsv.exceptions.CsvValidationException;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Controller
|
||||
public class DefaultTodoController{
|
||||
|
||||
private DefaultTodoService defaultTodoService;
|
||||
|
||||
public DefaultTodoController(DefaultTodoService defaultTodoService){
|
||||
this.defaultTodoService = defaultTodoService;
|
||||
}
|
||||
|
||||
@RequestMapping("/adminDataInsertPage.do")
|
||||
public String adminDataInsertPage(Model model){
|
||||
ArrayList<DefaultTodoVo> list = defaultTodoService.selectAll();
|
||||
System.out.println("Size : " +list.size());
|
||||
model.addAttribute("list", list);
|
||||
|
||||
return "admin/admin_data";
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/defaultDataInsert.do", method = RequestMethod.POST)
|
||||
public String defaultDataInsert(HttpServletRequest request, MultipartFile file, Model model){
|
||||
if(!verifyDefaultTodoFile(file))
|
||||
return "invalid";
|
||||
|
||||
String path = request.getServletContext().getRealPath("\\WEB-INF\\uploaded\\");
|
||||
System.out.println(path);
|
||||
String saveName = file.getOriginalFilename();
|
||||
File saveFile = new File(path, saveName);
|
||||
boolean isSaved = false;
|
||||
try{
|
||||
file.transferTo(saveFile);
|
||||
isSaved = true;
|
||||
}catch( IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
try{
|
||||
if(isSaved){
|
||||
//TODO : 파일이 제대로된 데이터인지 검증하는 단계 필요
|
||||
InputStreamReader iReader =new InputStreamReader(file.getInputStream(), "UTF-8");
|
||||
//CSVReader reader = new CSVReader(new FileReader( path+"\\"+saveName));
|
||||
CSVReader reader = new CSVReader(iReader);
|
||||
|
||||
defaultTodoService.truncate();
|
||||
String [] nextLine;
|
||||
int line = 1;
|
||||
while((nextLine = reader.readNext()) != null){
|
||||
|
||||
if(line > 3){
|
||||
DefaultTodoVo vo = csvLineToVo(nextLine);
|
||||
defaultTodoService.insert(vo);
|
||||
}
|
||||
++line;
|
||||
}
|
||||
iReader.close();
|
||||
}
|
||||
}catch(CsvValidationException | IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ArrayList<DefaultTodoVo> list = defaultTodoService.selectAll();
|
||||
model.addAttribute("list", list);
|
||||
|
||||
return String.valueOf(isSaved);
|
||||
}
|
||||
private DefaultTodoVo csvLineToVo(String[] line){
|
||||
DefaultTodoVo vo = new DefaultTodoVo();
|
||||
vo.setdTodoNo(Integer.valueOf(line[0]));
|
||||
vo.setdIsAlways(line[1].toUpperCase().trim());
|
||||
vo.setdContent(line[2].trim());
|
||||
vo.setdDay(line[3].trim());
|
||||
vo.setdMinCount( line[4].isEmpty()? null: Integer.valueOf(line[4]) );
|
||||
vo.setdMaxCount( line[5].isEmpty()? null : Integer.valueOf(line[5]) );
|
||||
vo.setdNpcName(line[6].trim());
|
||||
vo.setdIsEvent(line[7].toUpperCase().trim());
|
||||
vo.setdEventStartDate(line[8].isEmpty()? null : line[8].trim());
|
||||
vo.setdEventStartHour(line[9].isEmpty()? null: Integer.valueOf(line[9]));
|
||||
vo.setdEventEndDate(line[10].isEmpty()? null: line[10].trim());
|
||||
vo.setdEventEndHour(line[11].isEmpty()? null: Integer.valueOf(line[11]));
|
||||
vo.setdSpecialFunction(line[12].isEmpty()? null: line[12].trim());
|
||||
vo.setdSpecialData1(line[13].isEmpty()? null: line[13].trim());
|
||||
vo.setdSpecialData2(line[14].isEmpty()? null: line[14].trim());
|
||||
vo.setdSpecialData3(line[15].isEmpty()? null: line[15].trim());
|
||||
vo.setdSpecialData4(line[16].isEmpty()? null: line[16].trim());
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
private boolean verifyDefaultTodoFile(MultipartFile file){
|
||||
|
||||
try{
|
||||
InputStreamReader iReader =new InputStreamReader(file.getInputStream(), "UTF-8");
|
||||
CSVReader reader = new CSVReader(iReader);
|
||||
String[] lines;
|
||||
|
||||
int line = 1;
|
||||
while((lines = reader.readNext()) != null){
|
||||
if( line > 3){
|
||||
if((! lines[0].isEmpty() && NumberUtils.isCreatable(lines[0])) == false){
|
||||
System.out.println(1);
|
||||
System.out.println(lines[0]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
if((! lines[1].isEmpty() && isStringBoolean(lines[1])) == false){
|
||||
System.out.println(2);
|
||||
System.out.println(lines[1]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
if((! lines[2].isEmpty()) == false){
|
||||
System.out.println(3);
|
||||
System.out.println(lines[2]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
if((! lines[3].isEmpty() && isStringDay(lines[3])) == false){
|
||||
System.out.println(4);
|
||||
System.out.println(lines[3]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
if(! lines[4].isEmpty()){
|
||||
if(NumberUtils.isCreatable(lines[4]) == false){
|
||||
System.out.println(5);
|
||||
System.out.println(lines[4]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(! lines[5].isEmpty()){
|
||||
if(NumberUtils.isCreatable(lines[5]) == false){
|
||||
System.out.println(6);
|
||||
System.out.println(lines[5]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if((! lines[7].isEmpty() && isStringBoolean(lines[7])) == false){
|
||||
System.out.println(7);
|
||||
System.out.println(lines[7]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(! lines[8].isEmpty()){
|
||||
if(! isValidDate(lines[8])){
|
||||
System.out.println(8);
|
||||
System.out.println(lines[8]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(! lines[9].isEmpty()){
|
||||
if(! NumberUtils.isCreatable(lines[9])){
|
||||
System.out.println(9);
|
||||
System.out.println(lines[9]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(! lines[10].isEmpty()){
|
||||
if(! isValidDate(lines[10])){
|
||||
System.out.println(10);
|
||||
System.out.println(lines[10]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(! lines[11].isEmpty()){
|
||||
if(! NumberUtils.isCreatable(lines[11])){
|
||||
System.out.println(11);
|
||||
System.out.println(lines[11]);
|
||||
reader.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
++line;
|
||||
}
|
||||
|
||||
reader.close();
|
||||
return true;
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isStringBoolean(String str){
|
||||
String temp = str.toLowerCase();
|
||||
|
||||
if( temp.equals("true") || temp.equals("false")){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
final String[] days = {"월","화","수","목","금","토","일"};
|
||||
private boolean isStringDay(String str){
|
||||
String[] strings = str.split(",");
|
||||
for( int i = 0 ; i < strings.length; ++i){
|
||||
strings[i] = strings[i].trim();
|
||||
if ( !StringUtils.containsAny(strings[i], days) )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isValidDate(String str){
|
||||
|
||||
|
||||
str = str.replace(" ","" );
|
||||
String[] strings = str.split(",");
|
||||
if(strings.length != 2)
|
||||
return false;
|
||||
|
||||
|
||||
String[] temp = strings[0].split("/");
|
||||
if( temp.length != 2)
|
||||
return false;
|
||||
|
||||
if(!NumberUtils.isCreatable(temp[0]) || !NumberUtils.isCreatable(temp[1]))
|
||||
return false;
|
||||
int left = Integer.parseInt(temp[0]);
|
||||
int right = Integer.parseInt(temp[1]);
|
||||
if(left > 99 || left < 1 || right > 99 || right < 1)
|
||||
return false;
|
||||
|
||||
temp = strings[1].split("/");
|
||||
if( temp.length != 2)
|
||||
return false;
|
||||
|
||||
if(!NumberUtils.isCreatable(temp[0]) || !NumberUtils.isCreatable(temp[1]))
|
||||
return false;
|
||||
left = Integer.parseInt(temp[0]);
|
||||
right = Integer.parseInt(temp[1]);
|
||||
if(left > 99 || left < 1 || right > 99 || right < 1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class HomeController {
|
||||
|
||||
model.addAttribute("serverTime", formattedDate );
|
||||
|
||||
return "login/login_form";
|
||||
return "home";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class UserDao implements UserService{
|
||||
final String SELECT_BY_ID = "select * from user where id = ?";
|
||||
@Override
|
||||
public UserVo select( String id ){
|
||||
|
||||
try {
|
||||
return jdbcTemplate.queryForObject(SELECT_BY_ID, new UserMapper(), id );
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
|
||||
Reference in New Issue
Block a user