| @@ -399,6 +399,7 @@ | |||||
| watch: { | watch: { | ||||
| async tablename() { | async tablename() { | ||||
| if (this.$route.params.tablename) { | if (this.$route.params.tablename) { | ||||
| this.haveSearch = false; | |||||
| this.progress = true; | this.progress = true; | ||||
| this.title = ''; | this.title = ''; | ||||
| await this.getHeaders(); | await this.getHeaders(); | ||||
| @@ -430,6 +431,7 @@ | |||||
| this.headers = []; | this.headers = []; | ||||
| this.headers.push({'text': '', 'value': 'actions', sortable: false}); | this.headers.push({'text': '', 'value': 'actions', sortable: false}); | ||||
| this.insertItem = {}; | this.insertItem = {}; | ||||
| this.searchItem = {}; | |||||
| this.cols = resp.data.data; | this.cols = resp.data.data; | ||||
| resp.data.data.forEach((item) => { | resp.data.data.forEach((item) => { | ||||
| let header = {'text': null, 'value': null}; | let header = {'text': null, 'value': null}; | ||||
| @@ -470,6 +472,7 @@ | |||||
| delete this.insertItem.tablename; | delete this.insertItem.tablename; | ||||
| this.getInventories(); | this.getInventories(); | ||||
| this.close(); | this.close(); | ||||
| alert('已新增'); | |||||
| } | } | ||||
| ); | ); | ||||
| }, | }, | ||||
| @@ -504,7 +507,11 @@ | |||||
| let yes = confirm('確定刪除'); | let yes = confirm('確定刪除'); | ||||
| if (yes) { | if (yes) { | ||||
| this.$axios.delete(`/deleteOne?tablename=${this.tablename}&&id=${item.id}`).then(() => { | this.$axios.delete(`/deleteOne?tablename=${this.tablename}&&id=${item.id}`).then(() => { | ||||
| this.getInventories(); | |||||
| if (this.haveSearch === true) { | |||||
| this.search(); | |||||
| } else { | |||||
| this.getInventories(); | |||||
| } | |||||
| alert('已刪除'); | alert('已刪除'); | ||||
| }); | }); | ||||
| } | } | ||||
| @@ -546,6 +553,7 @@ | |||||
| } | } | ||||
| }, | }, | ||||
| importFile() { | importFile() { | ||||
| this.progress = true; | |||||
| const formData = new FormData(); | const formData = new FormData(); | ||||
| formData.append('tablename', this.tablename); | formData.append('tablename', this.tablename); | ||||
| formData.append('file', this.file); | formData.append('file', this.file); | ||||
| @@ -553,6 +561,7 @@ | |||||
| document.getElementById('file').value = null; | document.getElementById('file').value = null; | ||||
| this.getInventories(); | this.getInventories(); | ||||
| this.file = null; | this.file = null; | ||||
| this.progress = false; | |||||
| this.dialogImport = false; | this.dialogImport = false; | ||||
| }); | }); | ||||
| @@ -2,7 +2,7 @@ import axios from 'axios'; | |||||
| //在開發環境中的測試 development | //在開發環境中的測試 development | ||||
| if(process.env.NODE_ENV === 'development') { | if(process.env.NODE_ENV === 'development') { | ||||
| axios.defaults.baseURL = '/api' | |||||
| axios.defaults.baseURL = '/rms/api' | |||||
| } | } | ||||
| //在生產環境中的測試 production | //在生產環境中的測試 production | ||||
| if(process.env.NODE_ENV === 'production') { | if(process.env.NODE_ENV === 'production') { | ||||
| @@ -17,10 +17,10 @@ module.exports= { | |||||
| devServer: { | devServer: { | ||||
| proxy: { | proxy: { | ||||
| '/api': { | '/api': { | ||||
| target: 'http://localhost:8081/api/', | |||||
| target: 'http://localhost:8080/rms/api/', | |||||
| changeOrigin: true, | changeOrigin: true, | ||||
| pathRewrite: { | pathRewrite: { | ||||
| '^/api': '', | |||||
| '^/rms/api': '', | |||||
| }, | }, | ||||
| }, | }, | ||||
| }, | }, | ||||
| @@ -11,7 +11,7 @@ | |||||
| <groupId>com.moze</groupId> | <groupId>com.moze</groupId> | ||||
| <artifactId>rms</artifactId> | <artifactId>rms</artifactId> | ||||
| <version>0.0.1-SNAPSHOT</version> | |||||
| <version>1.0</version> | |||||
| <packaging>war</packaging> | <packaging>war</packaging> | ||||
| <name>rms</name> | <name>rms</name> | ||||
| @@ -0,0 +1,33 @@ | |||||
| package com.moze.rms; | |||||
| import org.springframework.stereotype.Component; | |||||
| import org.springframework.web.servlet.HandlerInterceptor; | |||||
| import javax.servlet.RequestDispatcher; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| @Component | |||||
| public class RequestInterceptor implements HandlerInterceptor { | |||||
| @Override | |||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |||||
| String uri = request.getRequestURI().substring(request.getContextPath().length()); | |||||
| // //當呼叫後端api | |||||
| if (uri.startsWith("/api/")) { | |||||
| return true; | |||||
| } else { | |||||
| if (uri.equals("/index.html")) { | |||||
| return true; | |||||
| } else if (uri.startsWith("/js/") || uri.startsWith("/manifest") || uri.startsWith("/img") || uri.startsWith("/fonts") || uri.startsWith("/css")) { | |||||
| return true; | |||||
| } else { | |||||
| RequestDispatcher dispatcher = request.getRequestDispatcher("/index.html"); | |||||
| dispatcher.forward(request, response); | |||||
| return false; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -23,21 +23,21 @@ public class JdbiFactory { | |||||
| public Jdbi getInstance() { | public Jdbi getInstance() { | ||||
| TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(dataSource); | TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(dataSource); | ||||
| Jdbi jdbi = Jdbi.create(proxy); | Jdbi jdbi = Jdbi.create(proxy); | ||||
| jdbi.setSqlLogger(new SqlLogger() { | |||||
| @Override | |||||
| public void logBeforeExecution(StatementContext ctx) { | |||||
| if (ctx.getStatement() != null) | |||||
| System.out.println(ctx.getStatement().toString()); | |||||
| } | |||||
| // jdbi.setSqlLogger(new SqlLogger() { | |||||
| // @Override | // @Override | ||||
| // public void logAfterExecution(StatementContext context) { | |||||
| //// jdbi.setSqlLogger(SqlLogger.NOP_SQL_LOGGER); | |||||
| // public void logBeforeExecution(StatementContext ctx) { | |||||
| // if (ctx.getStatement() != null) | |||||
| //// System.out.println(ctx.getStatement().toString()); | |||||
| // } | // } | ||||
| // @Override | |||||
| // public void logException(StatementContext context, SQLException ex) { | |||||
| //// jdbi.setSqlLogger(SqlLogger.NOP_SQL_LOGGER); | |||||
| // } | |||||
| }); | |||||
| //// @Override | |||||
| //// public void logAfterExecution(StatementContext context) { | |||||
| ////// jdbi.setSqlLogger(SqlLogger.NOP_SQL_LOGGER); | |||||
| //// } | |||||
| //// @Override | |||||
| //// public void logException(StatementContext context, SQLException ex) { | |||||
| ////// jdbi.setSqlLogger(SqlLogger.NOP_SQL_LOGGER); | |||||
| //// } | |||||
| // }); | |||||
| return jdbi.installPlugin(new SqlObjectPlugin()); | return jdbi.installPlugin(new SqlObjectPlugin()); | ||||
| } | } | ||||
| // @Bean | // @Bean | ||||
| @@ -0,0 +1,34 @@ | |||||
| package com.moze.rms.config; | |||||
| import com.moze.rms.RequestInterceptor; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.context.annotation.Configuration; | |||||
| import org.springframework.web.servlet.config.annotation.EnableWebMvc; | |||||
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |||||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | |||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||||
| @Configuration | |||||
| @EnableWebMvc | |||||
| public class WebConfig implements WebMvcConfigurer { | |||||
| @Autowired | |||||
| private RequestInterceptor interceptor; | |||||
| @Override | |||||
| public void addInterceptors(InterceptorRegistry registry) { | |||||
| registry.addInterceptor(interceptor).addPathPatterns("/**"); | |||||
| } | |||||
| @Override | |||||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | |||||
| registry.addResourceHandler("/**").addResourceLocations( | |||||
| "classpath:/resources/*", | |||||
| "classpath:/resources/public/*", | |||||
| "classpath:/public/", | |||||
| "classpath:/public/", | |||||
| "/**"); | |||||
| } | |||||
| } | |||||
| @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.Optional; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("/api/account") | @RequestMapping("/api/account") | ||||
| @@ -17,8 +18,8 @@ public class AccountController { | |||||
| @PostMapping("/login") | @PostMapping("/login") | ||||
| public JsonResult login(@RequestBody Map<String, String> data) { | public JsonResult login(@RequestBody Map<String, String> data) { | ||||
| Map<String, Object> user = accountDAO.findUser(data.get("account")); | |||||
| if (user.get("pwd").equals(data.get("password"))) { | |||||
| Optional<Map<String, Object>> user = accountDAO.findUser(data.get("account")); | |||||
| if (user.isPresent() && user.get().get("pwd").equals(data.get("password"))) { | |||||
| return new JsonResult(StatusCode.SUCCESS, user); | return new JsonResult(StatusCode.SUCCESS, user); | ||||
| } else { | } else { | ||||
| return new JsonResult(StatusCode.NOT_LOGIN, null); | return new JsonResult(StatusCode.NOT_LOGIN, null); | ||||
| @@ -111,12 +111,15 @@ public class InventoryController { | |||||
| file.transferTo(f); | file.transferTo(f); | ||||
| ExcelImporter excelImporter = new ExcelImporter(f); | ExcelImporter excelImporter = new ExcelImporter(f); | ||||
| List<Map<String, String>> data = excelImporter.readAll().get("工作表1"); | List<Map<String, String>> data = excelImporter.readAll().get("工作表1"); | ||||
| System.out.println(data); | |||||
| data.remove(data.get(0)); | data.remove(data.get(0)); | ||||
| // List<MappingCol> mappingCols = mappingColDAO.findByTable(tablename); | |||||
| // | |||||
| // inventoryDAO.importInventories(tablename, mappingCols, data, searchDAO); | |||||
| // f.deleteOnExit(); | |||||
| List<MappingCol> mappingCols = mappingColDAO.findByTable(tablename); | |||||
| inventoryDAO.truncateTable(tablename); | |||||
| searchDAO.deleteByTablename(tablename); | |||||
| inventoryDAO.importInventories(tablename, mappingCols, data, searchDAO); | |||||
| f.deleteOnExit(); | |||||
| return new JsonResult(StatusCode.SUCCESS, null); | return new JsonResult(StatusCode.SUCCESS, null); | ||||
| } | } | ||||
| @@ -8,14 +8,15 @@ import org.jdbi.v3.sqlobject.statement.SqlQuery; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.Optional; | |||||
| public interface AccountDAO extends SqlObject { | public interface AccountDAO extends SqlObject { | ||||
| @RegisterBeanMapper(Object.class) | @RegisterBeanMapper(Object.class) | ||||
| default Map<String, Object> findUser(String account) { | |||||
| default Optional<Map<String, Object>> findUser(String account) { | |||||
| Handle handle = this.getHandle(); | Handle handle = this.getHandle(); | ||||
| String sql = "select * from account where account = '" + account + "'"; | String sql = "select * from account where account = '" + account + "'"; | ||||
| return handle.createQuery(sql).mapToMap().one(); | |||||
| return handle.createQuery(sql).mapToMap().findOne(); | |||||
| } | } | ||||
| @RegisterBeanMapper(Account.class) | @RegisterBeanMapper(Account.class) | ||||
| @@ -281,7 +281,7 @@ public interface AssertDAO extends SqlObject { | |||||
| default void deleteColFromTable(String tablename, String colname) { | default void deleteColFromTable(String tablename, String colname) { | ||||
| Handle handle = this.getHandle(); | Handle handle = this.getHandle(); | ||||
| String sql = "ALTER TABLE " + tablename + " DROP " + colname; | |||||
| String sql = "ALTER TABLE " + tablename + " DROP column " + colname; | |||||
| handle.createUpdate(sql).execute(); | handle.createUpdate(sql).execute(); | ||||
| } | } | ||||
| @@ -78,12 +78,12 @@ public interface InventoryDAO extends SqlObject { | |||||
| Handle handle = this.getHandle(); | Handle handle = this.getHandle(); | ||||
| String sql = "select id from " + data.get("tablename") + " where "; | |||||
| String sql = "select top 1 id from " + data.get("tablename") + " where "; | |||||
| Iterator<Map.Entry<String, Object>> iterator = data.entrySet().iterator(); | Iterator<Map.Entry<String, Object>> iterator = data.entrySet().iterator(); | ||||
| while (iterator.hasNext()) { | while (iterator.hasNext()) { | ||||
| Map.Entry<String, Object> next = iterator.next(); | Map.Entry<String, Object> next = iterator.next(); | ||||
| String key = next.getKey(); | String key = next.getKey(); | ||||
| Object value = next.getValue().toString(); | |||||
| Object value = next.getValue() != null ? next.getValue().toString() : ""; | |||||
| if (key != "tablename" && key != "id") { | if (key != "tablename" && key != "id") { | ||||
| if (value != null) { | if (value != null) { | ||||
| sql += key + " = '" + value + "' and "; | sql += key + " = '" + value + "' and "; | ||||
| @@ -135,6 +135,9 @@ public interface InventoryDAO extends SqlObject { | |||||
| String key = next.getKey(); | String key = next.getKey(); | ||||
| Object value = next.getValue(); | Object value = next.getValue(); | ||||
| if (key != "tablename" && key != "id" && value != null) { | if (key != "tablename" && key != "id" && value != null) { | ||||
| if (value.toString().startsWith(" ") || value.toString().endsWith(" ")) { | |||||
| value = value.toString().trim(); | |||||
| } | |||||
| sql += " " + key + " like '%" + value + "%' and"; | sql += " " + key + " like '%" + value + "%' and"; | ||||
| } | } | ||||
| } | } | ||||
| @@ -181,4 +184,9 @@ public interface InventoryDAO extends SqlObject { | |||||
| } | } | ||||
| default void truncateTable(String tablename) { | |||||
| Handle handle = this.getHandle(); | |||||
| handle.createUpdate("truncate table " + tablename).execute(); | |||||
| } | |||||
| } | } | ||||
| @@ -38,11 +38,14 @@ public interface SearchDAO extends SqlObject { | |||||
| Handle handle = this.getHandle(); | Handle handle = this.getHandle(); | ||||
| String sql = "select "; | String sql = "select "; | ||||
| sql += tablename + ".*"; | sql += tablename + ".*"; | ||||
| sql += "from search "; | |||||
| sql += "join " + tablename + " on search.id = " + tablename + ".id "; | |||||
| sql += " from search "; | |||||
| sql += " join " + tablename + " on search.id = " + tablename + ".id "; | |||||
| sql += " and search.tablename = '" + tablename + "' "; | sql += " and search.tablename = '" + tablename + "' "; | ||||
| sql += "where text like '%' + '" + text + "' + '%' order by id"; | |||||
| if (text.startsWith(" ") || text.endsWith(" ")) { | |||||
| text = text.trim(); | |||||
| } | |||||
| sql += "where upper(text) like upper('%" + text + "%') order by id"; | |||||
| System.out.println(sql); | |||||
| return handle.createQuery(sql).mapToMap().list(); | return handle.createQuery(sql).mapToMap().list(); | ||||
| } | } | ||||
| @@ -55,7 +58,7 @@ public interface SearchDAO extends SqlObject { | |||||
| while (iterator.hasNext()) { | while (iterator.hasNext()) { | ||||
| Map.Entry<String, Object> next = iterator.next(); | Map.Entry<String, Object> next = iterator.next(); | ||||
| String key = next.getKey(); | String key = next.getKey(); | ||||
| Object value = next.getValue().toString(); | |||||
| Object value = next.getValue() != null ? next.getValue().toString() : ""; | |||||
| if (key != "id" && key != "tablename" && value != null) { | if (key != "id" && key != "tablename" && value != null) { | ||||
| text += value + " "; | text += value + " "; | ||||
| } | } | ||||
| @@ -86,6 +89,7 @@ public interface SearchDAO extends SqlObject { | |||||
| sql += "'" + id + "',"; | sql += "'" + id + "',"; | ||||
| sql += "'" + text + "'"; | sql += "'" + text + "'"; | ||||
| sql += ")"; | sql += ")"; | ||||
| System.out.println(sql); | |||||
| handle.createUpdate(sql).execute(); | handle.createUpdate(sql).execute(); | ||||
| } | } | ||||
| @@ -114,6 +118,9 @@ public interface SearchDAO extends SqlObject { | |||||
| @SqlUpdate("delete from search where tablename = ? and id = ?") | @SqlUpdate("delete from search where tablename = ? and id = ?") | ||||
| void deleteFromSearch(String tablename, String id); | void deleteFromSearch(String tablename, String id); | ||||
| @SqlUpdate("delete from search where tablename = ?") | |||||
| void deleteByTablename(String tablename); | |||||
| // default void bulkinsertSearch(String tablename, String id , List<Map<String, Object>> datas) { | // default void bulkinsertSearch(String tablename, String id , List<Map<String, Object>> datas) { | ||||
| // Handle handle = this.getHandle(); | // Handle handle = this.getHandle(); | ||||
| // } | // } | ||||
| @@ -199,7 +199,7 @@ public class ExcelExpoter { | |||||
| //寫入300000條後切換到下個工作表 | //寫入300000條後切換到下個工作表 | ||||
| if (rowNo % 300000 == 0) { | if (rowNo % 300000 == 0) { | ||||
| System.out.println("Current Sheet:" + rowNo / 300000); | System.out.println("Current Sheet:" + rowNo / 300000); | ||||
| sheet = wb.createSheet("工作簿" + (rowNo / 300000));//建立新的sheet物件 | |||||
| sheet = wb.createSheet("工作表1");//建立新的sheet物件 | |||||
| sheet = wb.getSheetAt(rowNo / 300000); //動態指定當前的工作表 | sheet = wb.getSheetAt(rowNo / 300000); //動態指定當前的工作表 | ||||
| pageRowNo = 0; //新建了工作表,重置工作表的行號為0 | pageRowNo = 0; //新建了工作表,重置工作表的行號為0 | ||||
| // -----------定義表頭----------- | // -----------定義表頭----------- | ||||
| @@ -2,6 +2,6 @@ | |||||
| spring.datasource.url=jdbc:sqlserver://172.105.222.191:1433;databaseName=rms; | spring.datasource.url=jdbc:sqlserver://172.105.222.191:1433;databaseName=rms; | ||||
| spring.datasource.username=sa | spring.datasource.username=sa | ||||
| spring.datasource.password=Moze794064,! | spring.datasource.password=Moze794064,! | ||||
| server.port=8081 | |||||
| server.port=8080 | |||||