diff --git a/WebContent/WEB-INF/config/log4j-config.xml b/WebContent/WEB-INF/config/log4j-config.xml index 1b1f2a1e..0a2755c5 100644 --- a/WebContent/WEB-INF/config/log4j-config.xml +++ b/WebContent/WEB-INF/config/log4j-config.xml @@ -2,7 +2,7 @@ - + @@ -34,14 +34,28 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/WebContent/WEB-INF/config/mybatis-applicationConfig.xml b/WebContent/WEB-INF/config/mybatis-applicationConfig.xml index ed1d5322..02e5011b 100644 --- a/WebContent/WEB-INF/config/mybatis-applicationConfig.xml +++ b/WebContent/WEB-INF/config/mybatis-applicationConfig.xml @@ -3,9 +3,12 @@ "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> - - - - - + + + + + + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/config/spring-applicationContext.xml b/WebContent/WEB-INF/config/spring-applicationContext.xml index 4eba9ce3..33ffe0a4 100644 --- a/WebContent/WEB-INF/config/spring-applicationContext.xml +++ b/WebContent/WEB-INF/config/spring-applicationContext.xml @@ -24,26 +24,16 @@ - - - - - - - - - - - - + - + + @@ -52,38 +42,31 @@ - - + - + - + diff --git a/build/classes/com/dao/mapper/data-detaisl-mapper.xml b/build/classes/com/dao/mapper/data-detaisl-mapper.xml new file mode 100644 index 00000000..e5833f2e --- /dev/null +++ b/build/classes/com/dao/mapper/data-detaisl-mapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + and data_details.data_type=#{PagerOptions.dataType} + + + and + data_details.submitted_batch=#{PagerOptions.submittedBatch} + + + and data_details.city_name=#{PagerOptions.cityName} + + + and + data_details.district_name=#{PagerOptions.districtName} + + + and + data_details.data_version=#{PagerOptions.dataVersion} + + + and data_details=#{PagerOptions.systemName} + + + and data_details.data_year=#{PagerOptions.dataYear} + + + + and data_details.id>=#{idIndex} + + + and data_details.id>=0 + + + + ORDER BY data_details.id + LIMIT #{PagerOptions.limit} + + + + + + + + \ No newline at end of file diff --git a/build/classes/com/platform/controller/DataModelController.class b/build/classes/com/platform/controller/DataModelController.class new file mode 100644 index 00000000..fed287c8 Binary files /dev/null and b/build/classes/com/platform/controller/DataModelController.class differ diff --git a/build/classes/com/platform/dao/DataInfoDao.class b/build/classes/com/platform/dao/DataInfoDao.class new file mode 100644 index 00000000..aa06cdc6 Binary files /dev/null and b/build/classes/com/platform/dao/DataInfoDao.class differ diff --git a/build/classes/com/platform/entities/BasedType.class b/build/classes/com/platform/entities/BasedType.class new file mode 100644 index 00000000..30ba1020 Binary files /dev/null and b/build/classes/com/platform/entities/BasedType.class differ diff --git a/build/classes/com/platform/entities/DataInfoEntity.class b/build/classes/com/platform/entities/DataInfoEntity.class new file mode 100644 index 00000000..0bc0b835 Binary files /dev/null and b/build/classes/com/platform/entities/DataInfoEntity.class differ diff --git a/build/classes/com/platform/entities/PagerOptions.class b/build/classes/com/platform/entities/PagerOptions.class new file mode 100644 index 00000000..1395e15c Binary files /dev/null and b/build/classes/com/platform/entities/PagerOptions.class differ diff --git a/build/classes/com/platform/service/DataInfoService.class b/build/classes/com/platform/service/DataInfoService.class new file mode 100644 index 00000000..9db71bca Binary files /dev/null and b/build/classes/com/platform/service/DataInfoService.class differ diff --git a/build/classes/com/platform/service/DataInfoServiceImp.class b/build/classes/com/platform/service/DataInfoServiceImp.class new file mode 100644 index 00000000..822685ea Binary files /dev/null and b/build/classes/com/platform/service/DataInfoServiceImp.class differ diff --git a/build/classes/com/platform/service/EncodeInfoServiceImpl.class b/build/classes/com/platform/service/EncodeInfoServiceImpl.class index e057d40e..56590e83 100644 Binary files a/build/classes/com/platform/service/EncodeInfoServiceImpl.class and b/build/classes/com/platform/service/EncodeInfoServiceImpl.class differ diff --git a/build/classes/com/platform/test/TestController.class b/build/classes/com/platform/test/TestController.class index d61e98fd..3abc9c41 100644 Binary files a/build/classes/com/platform/test/TestController.class and b/build/classes/com/platform/test/TestController.class differ diff --git a/build/classes/com/platform/test/testSystemInfoDao.class b/build/classes/com/platform/test/testSystemInfoDao.class new file mode 100644 index 00000000..7f4d00c5 Binary files /dev/null and b/build/classes/com/platform/test/testSystemInfoDao.class differ diff --git a/build/classes/com/platform/utils/UtilsHelper.class b/build/classes/com/platform/utils/UtilsHelper.class new file mode 100644 index 00000000..6bd08b73 Binary files /dev/null and b/build/classes/com/platform/utils/UtilsHelper.class differ diff --git a/build/classes/spring-applicationContext-test.xml b/build/classes/spring-applicationContext-test.xml index 2bdabb7c..27b1248b 100644 --- a/build/classes/spring-applicationContext-test.xml +++ b/build/classes/spring-applicationContext-test.xml @@ -26,6 +26,7 @@ + diff --git a/src/com/dao/mapper/data-detaisl-mapper.xml b/src/com/dao/mapper/data-detaisl-mapper.xml new file mode 100644 index 00000000..e5833f2e --- /dev/null +++ b/src/com/dao/mapper/data-detaisl-mapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + and data_details.data_type=#{PagerOptions.dataType} + + + and + data_details.submitted_batch=#{PagerOptions.submittedBatch} + + + and data_details.city_name=#{PagerOptions.cityName} + + + and + data_details.district_name=#{PagerOptions.districtName} + + + and + data_details.data_version=#{PagerOptions.dataVersion} + + + and data_details=#{PagerOptions.systemName} + + + and data_details.data_year=#{PagerOptions.dataYear} + + + + and data_details.id>=#{idIndex} + + + and data_details.id>=0 + + + + ORDER BY data_details.id + LIMIT #{PagerOptions.limit} + + + + + + + + \ No newline at end of file diff --git a/src/com/platform/controller/DataModelController.java b/src/com/platform/controller/DataModelController.java new file mode 100644 index 00000000..965b3aad --- /dev/null +++ b/src/com/platform/controller/DataModelController.java @@ -0,0 +1,38 @@ +package com.platform.controller; + +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.platform.entities.PagerOptions; +import com.platform.service.DataInfoService; +import com.platform.utils.UtilsHelper; + +@Controller +public class DataModelController { + @Resource(name = "dataInfoService") + private DataInfoService dfs; + + public void setDfsImp(DataInfoService dfs) { + this.dfs = dfs; + } + + @RequestMapping("/data.json") + @ResponseBody + public ModelMap getAllDataToJson(HttpServletRequest res, HttpServletResponse req) { + Map paramMap = res.getParameterMap(); + Set keySet= paramMap.keySet(); + for(String str: keySet){ + System.out.println(str+":"+paramMap.get(str)); + } + return dfs.getPagerTableData((PagerOptions) UtilsHelper.newObjAndSetAttrsByClass(PagerOptions.class, res)); + } +} diff --git a/src/com/platform/dao/DataInfoDao.java b/src/com/platform/dao/DataInfoDao.java new file mode 100644 index 00000000..b367fd05 --- /dev/null +++ b/src/com/platform/dao/DataInfoDao.java @@ -0,0 +1,31 @@ +package com.platform.dao; + +import java.util.List; + +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import com.platform.entities.DataInfoEntity; +import com.platform.entities.PagerOptions; + +@Repository(value = "dataInfoDao") +public interface DataInfoDao { + + public List getLimitedDataInfoEntities( + @Param(value = "PagerOptions") PagerOptions pagerOptions); + + public int getLimitedDataCount( + @Param(value = "PagerOptions") PagerOptions pagerOptions); + + @Insert("INSERT INTO data_info(regionalism_code, system_code, data_type, data_version, submitted_batch, data_path, collection_time, data_charset)" + + " values(#{regionalismCcode},#{systemCcode},#{dataType},#{dataVersion},#{submittedBbatch},#{dataPath},#{collectionTime},#{dataCharset})") + public int inserRecode(@Param("regionalismCcode") String regionalismCcode, + @Param("systemCcode") int systemCcode, + @Param("dataType") String dataType, + @Param("dataVersion") int dataVersion, + @Param("submittedBbatch") String submittedBbatch, + @Param("dataPath") String dataPath, + @Param("collectionTime") String collectionTime, + @Param("dataCharset") String dataCharset); +} diff --git a/src/com/platform/entities/BasedType.java b/src/com/platform/entities/BasedType.java new file mode 100644 index 00000000..d133a0eb --- /dev/null +++ b/src/com/platform/entities/BasedType.java @@ -0,0 +1,48 @@ +package com.platform.entities; + +import java.util.Date; + +public enum BasedType { + + STRING("java.lang.String", String.class), INTEGER("java.lang.Integer", + Integer.class), SHORT("java.lang.Short", Short.class), LONG( + "java.lang.Long", Long.class), DATE("java.util.Date", Date.class); + + private String type; + private Class clazz; + + private BasedType(String type, Class clazz) { + this.type = type; + this.clazz = clazz; + } + + public static Class getTypeClass(String type) { + for (BasedType bt : BasedType.values()) { + if (bt.equals(type)) + return bt.clazz; + } + return null; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Class getClazz() { + return clazz; + } + + public void setClazz(Class clazz) { + this.clazz = clazz; + } + + @Override + public String toString() { + return this.type; + } + +} diff --git a/src/com/platform/entities/DataInfoEntity.java b/src/com/platform/entities/DataInfoEntity.java new file mode 100644 index 00000000..d3581c89 --- /dev/null +++ b/src/com/platform/entities/DataInfoEntity.java @@ -0,0 +1,186 @@ +package com.platform.entities; + +/** + * Ϣʵ + * + * @author wuming + * + */ +public class DataInfoEntity { + private int id; + private String regionalismCode; // + private String cityName; // + private String districtName; // + private int systemCode; // ϵͳ + private String systemName; // ϵͳ + private String dataType; // ͣ\籣\... + private int dataVersion; // ݰ汾 + private String submittedBatch; // ϱ + private String dataPath; // · + private String collectingTime; // ɼʱ + private String collectorContacts; // ɼ˵ϵ + private String charset; // ݵַ + private String collectorName; // ɼ + private String year; // + + public DataInfoEntity() { + } + + public DataInfoEntity(int id, String regionalismCode, String cityName, + String districtName, int systemCode, String systemName, + String dataType, int dataVersion, String submittedBatch, + String dataPath, String collectingTime, String collectorContacts, + String charset, String collectorName, String year) { + super(); + this.id = id; + this.regionalismCode = regionalismCode; + this.cityName = cityName; + this.districtName = districtName; + this.systemCode = systemCode; + this.systemName = systemName; + this.dataType = dataType; + this.dataVersion = dataVersion; + this.submittedBatch = submittedBatch; + this.dataPath = dataPath; + this.collectingTime = collectingTime; + this.collectorContacts = collectorContacts; + this.charset = charset; + this.collectorName = collectorName; + this.year = year; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getRegionalismCode() { + return regionalismCode; + } + + public void setRegionalismCode(String regionalismCode) { + this.regionalismCode = regionalismCode; + } + + public String getCityName() { + return cityName; + } + + public void setCityName(String cityName) { + this.cityName = cityName; + } + + public String getDistrictName() { + return districtName; + } + + public void setDistrictName(String districtName) { + this.districtName = districtName; + } + + public int getSystemCode() { + return systemCode; + } + + public void setSystemCode(int systemCode) { + this.systemCode = systemCode; + } + + public String getSystemName() { + return systemName; + } + + public void setSystemName(String systemName) { + this.systemName = systemName; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public int getDataVersion() { + return dataVersion; + } + + public void setDataVersion(int dataVersion) { + this.dataVersion = dataVersion; + } + + public String getSubmittedBatch() { + return submittedBatch; + } + + public void setSubmittedBatch(String submittedBatch) { + this.submittedBatch = submittedBatch; + } + + public String getDataPath() { + return dataPath; + } + + public void setDataPath(String dataPath) { + this.dataPath = dataPath; + } + + public String getCollectingTime() { + return collectingTime; + } + + public void setCollectingTime(String collectingTime) { + this.collectingTime = collectingTime; + } + + public String getCollectorContacts() { + return collectorContacts; + } + + public void setCollectorContacts(String collectorContacts) { + this.collectorContacts = collectorContacts; + } + + public String getCharset() { + return charset; + } + + public void setCharset(String charset) { + this.charset = charset; + } + + public String getCollectorName() { + return collectorName; + } + + public void setCollectorName(String collectorName) { + this.collectorName = collectorName; + } + + public String getYear() { + return year; + } + + public void setYear(String year) { + this.year = year; + } + + @Override + public String toString() { + return "id=" + this.id + " ,regionalismCode=" + this.regionalismCode + + " ,cityName=" + this.cityName + " ,districtName=" + + this.districtName + " ,systemCode=" + this.systemCode + + " ,systemName" + this.systemName + " ,dataType=" + + this.dataType + " ,dataVersion=" + this.dataVersion + + " ,submittedBatch=" + this.submittedBatch + " ,dataPath=" + + this.dataPath + " ,collectingTime=" + this.collectingTime + + " ,collectorContacts=" + this.collectorContacts + + " ,charset=" + this.charset + " ,collectorName=" + + this.collectorName + " ,year=" + this.year + ""; + } + +} diff --git a/src/com/platform/entities/PagerOptions.java b/src/com/platform/entities/PagerOptions.java new file mode 100644 index 00000000..e58d7813 --- /dev/null +++ b/src/com/platform/entities/PagerOptions.java @@ -0,0 +1,94 @@ +package com.platform.entities; + +public class PagerOptions { + private int idIndex; + + private String dataType; + + private String submittedBatch; + + private String cityName; + + private String districtName; + + private int dataVersion; + + private String systemName; + + private String dataYear; + + private int limit; + + public int getIdIndex() { + return idIndex; + } + + public void setIdIndex(int idIndex) { + this.idIndex = idIndex; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getSubmittedBatch() { + return submittedBatch; + } + + public void setSubmittedBatch(String submittedBatch) { + this.submittedBatch = submittedBatch; + } + + public String getCityName() { + return cityName; + } + + public void setCityName(String cityName) { + this.cityName = cityName; + } + + public String getDistrictName() { + return districtName; + } + + public void setDistrictName(String districtName) { + this.districtName = districtName; + } + + public int getDataVersion() { + return dataVersion; + } + + public void setDataVersion(int dataVersion) { + this.dataVersion = dataVersion; + } + + public String getSystemName() { + return systemName; + } + + public void setSystemName(String systemName) { + this.systemName = systemName; + } + + public String getDataYear() { + return dataYear; + } + + public void setDataYear(String dataYear) { + this.dataYear = dataYear; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + +} diff --git a/src/com/platform/service/DataInfoService.java b/src/com/platform/service/DataInfoService.java new file mode 100644 index 00000000..e6eb52c4 --- /dev/null +++ b/src/com/platform/service/DataInfoService.java @@ -0,0 +1,9 @@ +package com.platform.service; + +import org.springframework.ui.ModelMap; + +import com.platform.entities.PagerOptions; + +public interface DataInfoService { + public ModelMap getPagerTableData(PagerOptions pagerOptions); +} diff --git a/src/com/platform/service/DataInfoServiceImp.java b/src/com/platform/service/DataInfoServiceImp.java new file mode 100644 index 00000000..023ae251 --- /dev/null +++ b/src/com/platform/service/DataInfoServiceImp.java @@ -0,0 +1,34 @@ +package com.platform.service; + +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; +import org.springframework.ui.ModelMap; + +import com.platform.dao.DataInfoDao; +import com.platform.entities.DataInfoEntity; +import com.platform.entities.PagerOptions; + +@Service(value = "dataInfoService") +public class DataInfoServiceImp implements DataInfoService { + @Resource(name = "dataInfoDao") + private DataInfoDao dfdDao; + + public void setDfdDao(DataInfoDao dfdDao) { + this.dfdDao = dfdDao; + } + + @Override + public ModelMap getPagerTableData(PagerOptions pagerOptions) { + // TODO Auto-generated method stub + ModelMap modelMap = new ModelMap(); + List result = dfdDao + .getLimitedDataInfoEntities(pagerOptions); + int count = dfdDao.getLimitedDataCount(pagerOptions); + modelMap.addAttribute("data", result); + modelMap.addAttribute("length", count); + return modelMap; + } +} diff --git a/src/com/platform/service/EncodeInfoServiceImpl.java b/src/com/platform/service/EncodeInfoServiceImpl.java index 06770367..3e5fe735 100644 --- a/src/com/platform/service/EncodeInfoServiceImpl.java +++ b/src/com/platform/service/EncodeInfoServiceImpl.java @@ -41,7 +41,7 @@ public class EncodeInfoServiceImpl implements EncodeInfoService { public int deleteEncodeByCode(String code, String tableName) { // TODO Auto-generated method stub int cursor = eiDao.deleteEncodeByCode(code, tableName); - cursor = cursor / 0; + //cursor = cursor / 0; return cursor; } diff --git a/src/com/platform/utils/UtilsHelper.java b/src/com/platform/utils/UtilsHelper.java new file mode 100644 index 00000000..1c10ecbd --- /dev/null +++ b/src/com/platform/utils/UtilsHelper.java @@ -0,0 +1,90 @@ +package com.platform.utils; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; + +import com.platform.entities.BasedType; + +public class UtilsHelper { + public static Logger logger = Logger.getLogger(UtilsHelper.class); + + /** + * + * @param clazz + * @param req + * @return + */ + public static Object newObjAndSetAttrsByClass(Class clazz, + HttpServletRequest req) { + Object object = null; + try { + Class cls = Class.forName(clazz.getName()); + object = cls.newInstance(); + Field[] fileds = clazz.getDeclaredFields(); + for (Field fs : fileds) { + String fieldName = fs.getName(); + String fieldType = fs.getGenericType().toString(); + Object value = req.getAttribute(fieldName); + if (null != value) { + Method method = cls.getDeclaredMethod( + getAttributeSetName(fs), + BasedType.getTypeClass(fieldType)); + method.invoke(object, value); + } + } + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return object; + }; + + /** + * + * @param object + * @param req + * @return + */ + public static Object newObjAndSetAttrsByInstance(Object object, + HttpServletRequest req) { + return newObjAndSetAttrsByClass(object.getClass(), req); + } + + /** + * {@fs}set + * + * @param fs + * Զ + * @return set + */ + private static String getAttributeSetName(Field fs) { + String fieldName = fs.getName(); + char[] cs = fieldName.toCharArray(); + cs[0] -= 32; + return "set" + String.valueOf(cs); + } + +} diff --git a/test/com/platform/test/TestController.java b/test/com/platform/test/TestController.java index 4b19c6ca..662ee505 100644 --- a/test/com/platform/test/TestController.java +++ b/test/com/platform/test/TestController.java @@ -11,22 +11,24 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; +import com.platform.entities.EncodedInfoEntity; import com.platform.service.EncodeInfoService; @Controller public class TestController { - //private static Logger logger = Logger.getLogger(TestController.class); - @Resource(name = "encodeInfoService") - private EncodeInfoService eis; - + // private static Logger logger = Logger.getLogger(TestController.class); + @Resource(name = "encodeInfoService") + private EncodeInfoService eis; + public void setEis(EncodeInfoService eis) { this.eis = eis; } @RequestMapping("/hello") - public String hello(String name, HttpServletResponse res) { - System.out.println(name); - return "index.html"; + @ResponseBody + public List hello(String name, HttpServletResponse res) { + System.out.println(name); + return eis.getAllEncodeInfo("system_info"); } @RequestMapping("/json") @@ -42,4 +44,10 @@ public class TestController { public void testLog(HttpServletResponse res) { System.out.println(eis.getEncodeNameByCode("1", "system_info")); } + + @RequestMapping("/data111.json") + public void test(String name, HttpServletResponse res){ + + + } } diff --git a/test/com/platform/test/testSystemInfoDao.java b/test/com/platform/test/testSystemInfoDao.java new file mode 100644 index 00000000..c6d55374 --- /dev/null +++ b/test/com/platform/test/testSystemInfoDao.java @@ -0,0 +1,50 @@ +package com.platform.test; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.List; +import java.util.Scanner; + +import org.junit.Before; +import org.junit.Test; + +import com.platform.dao.DataInfoDao; +import com.platform.entities.DataInfoEntity; +import com.platform.entities.PagerOptions; + +public class testSystemInfoDao extends SMBasedTest { + private DataInfoDao dfDao; + + @Before + public void initBeforeFunction() { + dfDao = (DataInfoDao) this.applicationContext.getBean("dataInfoDao"); + } + + // @Test + public void testInsert() { + try { + Scanner in = new Scanner(new File( + "C:/Users/wuming/Desktop/data.txt")); + int count = 0; + while (in.hasNextLine()) { + String str = in.nextLine(); + String[] values = str.split("\t"); + System.out.println(values.length); + count++; + dfDao.inserRecode(values[0], Integer.parseInt(values[1]), "", + Integer.parseInt(values[3]), values[4], values[5], + values[6], values[7]); + } + System.out.println(count); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void test() { + //System.out.println(dfDao.getCount()); + } +} diff --git a/test/spring-applicationContext-test.xml b/test/spring-applicationContext-test.xml index 2bdabb7c..27b1248b 100644 --- a/test/spring-applicationContext-test.xml +++ b/test/spring-applicationContext-test.xml @@ -26,6 +26,7 @@ +