|
|
@@ -6,34 +6,32 @@ public class GeneratorServiceDaoImplMapperListener extends BaseGenerator {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @param data
|
|
|
* @param fileContext
|
|
|
* @return
|
|
|
*/
|
|
|
//insert into business_store(store_id,b_id,user_id,name,address,tel,store_type_cd,nearby_landmarks,map_x,map_y,month,operate)
|
|
|
// values(#{storeId},#{bId},#{userId},#{name},#{address},#{tel},#{storeTypeCd},#{nearbyLandmarks},#{mapX},#{mapY},#{month},#{operate})
|
|
|
-
|
|
|
- private String dealSaveBusinessInfo(Data data,String fileContext){
|
|
|
- String sql = "insert into "+ data.getBusinessTableName() + "(\n";
|
|
|
+ private String dealSaveBusinessInfo(Data data, String fileContext) {
|
|
|
+ String sql = "insert into " + data.getBusinessTableName() + "(\n";
|
|
|
String sqlValue = "\n) values (\n";
|
|
|
|
|
|
- Map<String,String> params = data.getParams();
|
|
|
+ Map<String, String> params = data.getParams();
|
|
|
|
|
|
- for(String key:params.keySet()){
|
|
|
- if("statusCd".equals(key)){
|
|
|
+ for (String key : params.keySet()) {
|
|
|
+ if ("statusCd".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
- sql += params.get(key)+",";
|
|
|
- sqlValue += "#{"+key+"},";
|
|
|
+ sql += params.get(key) + ",";
|
|
|
+ sqlValue += "#{" + key + "},";
|
|
|
}
|
|
|
|
|
|
- sql = sql.endsWith(",")?sql.substring(0,sql.length()-1):sql;
|
|
|
- sqlValue = sqlValue.endsWith(",")?sqlValue.substring(0,sqlValue.length()-1):sqlValue;
|
|
|
+ sql = sql.endsWith(",") ? sql.substring(0, sql.length() - 1) : sql;
|
|
|
+ sqlValue = sqlValue.endsWith(",") ? sqlValue.substring(0, sqlValue.length() - 1) : sqlValue;
|
|
|
|
|
|
- sql += (sqlValue +"\n)");
|
|
|
+ sql += (sqlValue + "\n)");
|
|
|
|
|
|
- fileContext = fileContext.replace("$saveBusinessInfo$",sql);
|
|
|
+ fileContext = fileContext.replace("$saveBusinessInfo$", sql);
|
|
|
|
|
|
return fileContext;
|
|
|
|
|
|
@@ -41,42 +39,46 @@ public class GeneratorServiceDaoImplMapperListener extends BaseGenerator {
|
|
|
|
|
|
/**
|
|
|
* select s.store_id,s.b_id,s.user_id,s.name,s.address,s.tel,s.store_type_cd,s.nearby_landmarks,s.map_x,s.map_y,s.operate
|
|
|
- * from business_store s where 1 = 1
|
|
|
- * <if test="operate != null and operate != ''">
|
|
|
- * and s.operate = #{operate}
|
|
|
- * </if>
|
|
|
- * <if test="bId != null and bId !=''">
|
|
|
- * and s.b_id = #{bId}
|
|
|
- * </if>
|
|
|
- * <if test="storeId != null and storeId != ''">
|
|
|
- * and s.store_id = #{storeId}
|
|
|
- * </if>
|
|
|
+ * from business_store s where 1 = 1
|
|
|
+ * <if test="operate != null and operate != ''">
|
|
|
+ * and s.operate = #{operate}
|
|
|
+ * </if>
|
|
|
+ * <if test="bId != null and bId !=''">
|
|
|
+ * and s.b_id = #{bId}
|
|
|
+ * </if>
|
|
|
+ * <if test="storeId != null and storeId != ''">
|
|
|
+ * and s.store_id = #{storeId}
|
|
|
+ * </if>
|
|
|
+ *
|
|
|
* @param data
|
|
|
* @param fileContext
|
|
|
* @return
|
|
|
*/
|
|
|
- private String dealGetBusinessInfo(Data data,String fileContext){
|
|
|
+ private String dealGetBusinessInfo(Data data, String fileContext) {
|
|
|
String sql = "select ";
|
|
|
- String sqlValue = " \nfrom "+data.getBusinessTableName()+" t \nwhere 1 =1 \n";
|
|
|
+ String sqlValue = " \nfrom " + data.getBusinessTableName() + " t \nwhere 1 =1 \n";
|
|
|
|
|
|
- Map<String,String> params = data.getParams();
|
|
|
+ Map<String, String> params = data.getParams();
|
|
|
|
|
|
- for(String key:params.keySet()){
|
|
|
- if("statusCd".equals(key)){
|
|
|
+ for (String key : params.keySet()) {
|
|
|
+ if ("statusCd".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
- sql += ("t."+params.get(key)+",");
|
|
|
- sqlValue += "<if test=\""+key+" !=null and "+key+" != ''\">\n";
|
|
|
- sqlValue += " and t."+params.get(key)+"= #{"+key +"}\n";
|
|
|
+ sql += ("t." + params.get(key) + ",");
|
|
|
+ if (!key.equals(params.get(key))) {
|
|
|
+ sql += ("t." + params.get(key) + " " + key + ",");
|
|
|
+ }
|
|
|
+ sqlValue += "<if test=\"" + key + " !=null and " + key + " != ''\">\n";
|
|
|
+ sqlValue += " and t." + params.get(key) + "= #{" + key + "}\n";
|
|
|
sqlValue += "</if> \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
- sql = sql.endsWith(",")?sql.substring(0,sql.length()-1):sql;
|
|
|
+ sql = sql.endsWith(",") ? sql.substring(0, sql.length() - 1) : sql;
|
|
|
|
|
|
sql += sqlValue;
|
|
|
|
|
|
- fileContext = fileContext.replace("$getBusinessInfo$",sql);
|
|
|
+ fileContext = fileContext.replace("$getBusinessInfo$", sql);
|
|
|
|
|
|
return fileContext;
|
|
|
|
|
|
@@ -84,52 +86,52 @@ public class GeneratorServiceDaoImplMapperListener extends BaseGenerator {
|
|
|
|
|
|
/**
|
|
|
* insert into s_store(store_id,b_id,user_id,name,address,tel,store_type_cd,nearby_landmarks,map_x,map_y,status_cd)
|
|
|
- * select s.store_id,s.b_id,s.user_id,s.name,s.address,s.tel,s.store_type_cd,s.nearby_landmarks,s.map_x,s.map_y,'0'
|
|
|
- * from business_store s where
|
|
|
- * s.operate = 'ADD' and s.b_id=#{bId}
|
|
|
+ * select s.store_id,s.b_id,s.user_id,s.name,s.address,s.tel,s.store_type_cd,s.nearby_landmarks,s.map_x,s.map_y,'0'
|
|
|
+ * from business_store s where
|
|
|
+ * s.operate = 'ADD' and s.b_id=#{bId}
|
|
|
*/
|
|
|
- private String dealSaveInfoInstance(Data data,String fileContext){
|
|
|
- String sql = "insert into "+ data.getTableName() + "(\n";
|
|
|
+ private String dealSaveInfoInstance(Data data, String fileContext) {
|
|
|
+ String sql = "insert into " + data.getTableName() + "(\n";
|
|
|
String sqlValue = "select ";
|
|
|
- String sqlWhere = " from "+ data.getBusinessTableName() +" t where 1=1\n";
|
|
|
+ String sqlWhere = " from " + data.getBusinessTableName() + " t where 1=1\n";
|
|
|
|
|
|
- Map<String,String> params = data.getParams();
|
|
|
+ Map<String, String> params = data.getParams();
|
|
|
|
|
|
- for(String key:params.keySet()){
|
|
|
- if("operate".equals(key)){
|
|
|
+ for (String key : params.keySet()) {
|
|
|
+ if ("operate".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
- sql += params.get(key)+",";
|
|
|
+ sql += params.get(key) + ",";
|
|
|
|
|
|
- if("statusCd".equals(key)){
|
|
|
+ if ("statusCd".equals(key)) {
|
|
|
sqlValue += "'0',";
|
|
|
continue;
|
|
|
}
|
|
|
- sqlValue += "t."+params.get(key)+",";
|
|
|
+ sqlValue += "t." + params.get(key) + ",";
|
|
|
}
|
|
|
|
|
|
- for(String key:params.keySet()){
|
|
|
- if("statusCd".equals(key)){
|
|
|
+ for (String key : params.keySet()) {
|
|
|
+ if ("statusCd".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if("operate".equals(key)){
|
|
|
- sqlWhere += " and t."+params.get(key)+"= 'ADD'\n";
|
|
|
- }else{
|
|
|
- sqlWhere += "<if test=\""+key+" !=null and "+key+" != ''\">\n";
|
|
|
- sqlWhere += " and t."+params.get(key)+"= #{"+key +"}\n";
|
|
|
+ if ("operate".equals(key)) {
|
|
|
+ sqlWhere += " and t." + params.get(key) + "= 'ADD'\n";
|
|
|
+ } else {
|
|
|
+ sqlWhere += "<if test=\"" + key + " !=null and " + key + " != ''\">\n";
|
|
|
+ sqlWhere += " and t." + params.get(key) + "= #{" + key + "}\n";
|
|
|
sqlWhere += "</if> \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- sql = sql.endsWith(",")?sql.substring(0,sql.length()-1):sql;
|
|
|
- sqlValue = sqlValue.endsWith(",")?sqlValue.substring(0,sqlValue.length()-1):sqlValue;
|
|
|
+ sql = sql.endsWith(",") ? sql.substring(0, sql.length() - 1) : sql;
|
|
|
+ sqlValue = sqlValue.endsWith(",") ? sqlValue.substring(0, sqlValue.length() - 1) : sqlValue;
|
|
|
|
|
|
- sql += ("\n) "+ sqlValue + sqlWhere);
|
|
|
+ sql += ("\n) " + sqlValue + sqlWhere);
|
|
|
|
|
|
- fileContext = fileContext.replace("$saveInfoInstance$",sql);
|
|
|
+ fileContext = fileContext.replace("$saveInfoInstance$", sql);
|
|
|
|
|
|
return fileContext;
|
|
|
|
|
|
@@ -137,105 +139,109 @@ public class GeneratorServiceDaoImplMapperListener extends BaseGenerator {
|
|
|
|
|
|
/**
|
|
|
* select s.store_id,s.b_id,s.user_id,s.name,s.address,s.tel,s.store_type_cd,s.nearby_landmarks,s.map_x,s.map_y,s.status_cd
|
|
|
- * from s_store s
|
|
|
- * where 1=1
|
|
|
- * <if test="statusCd != null and statusCd != ''">
|
|
|
- * and s.status_cd = #{statusCd}
|
|
|
- * </if>
|
|
|
+ * from s_store s
|
|
|
+ * where 1=1
|
|
|
+ * <if test="statusCd != null and statusCd != ''">
|
|
|
+ * and s.status_cd = #{statusCd}
|
|
|
+ * </if>
|
|
|
+ *
|
|
|
+ * <if test="bId != null and bId !=''">
|
|
|
+ * and s.b_id = #{bId}
|
|
|
+ * </if>
|
|
|
+ * <if test="storeId != null and storeId !=''">
|
|
|
+ * and s.store_id = #{storeId}
|
|
|
+ * </if>
|
|
|
*
|
|
|
- * <if test="bId != null and bId !=''">
|
|
|
- * and s.b_id = #{bId}
|
|
|
- * </if>
|
|
|
- * <if test="storeId != null and storeId !=''">
|
|
|
- * and s.store_id = #{storeId}
|
|
|
- * </if>
|
|
|
* @param data
|
|
|
* @param fileContext
|
|
|
* @return
|
|
|
*/
|
|
|
- private String dealGetInfo(Data data,String fileContext){
|
|
|
+ private String dealGetInfo(Data data, String fileContext) {
|
|
|
String sql = "select ";
|
|
|
- String sqlValue = " \nfrom "+data.getTableName()+" t \nwhere 1 =1 \n";
|
|
|
+ String sqlValue = " \nfrom " + data.getTableName() + " t \nwhere 1 =1 \n";
|
|
|
|
|
|
- Map<String,String> params = data.getParams();
|
|
|
+ Map<String, String> params = data.getParams();
|
|
|
|
|
|
- for(String key:params.keySet()){
|
|
|
- if("operate".equals(key)){
|
|
|
+ for (String key : params.keySet()) {
|
|
|
+ if ("operate".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
- sql += ("t."+params.get(key)+",");
|
|
|
- sqlValue += "<if test=\""+key+" !=null and "+key+" != ''\">\n";
|
|
|
- sqlValue += " and t."+params.get(key)+"= #{"+key +"}\n";
|
|
|
+ sql += ("t." + params.get(key) + ",");
|
|
|
+ if (!key.equals(params.get(key))) {
|
|
|
+ sql += ("t." + params.get(key) + " " + key + ",");
|
|
|
+ }
|
|
|
+ sqlValue += "<if test=\"" + key + " !=null and " + key + " != ''\">\n";
|
|
|
+ sqlValue += " and t." + params.get(key) + "= #{" + key + "}\n";
|
|
|
sqlValue += "</if> \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
- sql = sql.endsWith(",")?sql.substring(0,sql.length()-1):sql;
|
|
|
+ sql = sql.endsWith(",") ? sql.substring(0, sql.length() - 1) : sql;
|
|
|
|
|
|
sql += sqlValue;
|
|
|
|
|
|
- fileContext = fileContext.replace("$getInfo$",sql);
|
|
|
+ fileContext = fileContext.replace("$getInfo$", sql);
|
|
|
|
|
|
return fileContext;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* update s_store s set s.status_cd = #{statusCd}
|
|
|
- * <if test="newBId != null and newBId != ''">
|
|
|
- * ,s.b_id = #{newBId}
|
|
|
- * </if>
|
|
|
- * <if test="userId != null and userId != ''">
|
|
|
- * ,s.user_id = #{userId}
|
|
|
- * </if>
|
|
|
- * <if test="name != null and name != ''">
|
|
|
- * ,s.name = #{name}
|
|
|
- * </if>
|
|
|
- * <if test="address != null and address != ''">
|
|
|
- * ,s.address = #{address}
|
|
|
- * </if>
|
|
|
- * <if test="tel != null and tel != ''">
|
|
|
- * ,s.tel = #{tel}
|
|
|
- * </if>
|
|
|
- * <if test="storeTypeCd != null and storeTypeCd != ''">
|
|
|
- * ,s.store_type_cd = #{storeTypeCd}
|
|
|
- * </if>
|
|
|
- * <if test="nearbyLandmarks != null and nearbyLandmarks != ''">
|
|
|
- * ,s.nearby_landmarks = #{nearbyLandmarks}
|
|
|
- * </if>
|
|
|
- * <if test="mapX != null and mapX != ''">
|
|
|
- * ,s.map_x = #{mapX}
|
|
|
- * </if>
|
|
|
- * <if test="mapY != null and mapY != ''">
|
|
|
- * ,s.map_y = #{mapY}
|
|
|
- * </if>
|
|
|
- * where 1=1
|
|
|
- * <if test="bId != null and bId !=''">
|
|
|
- * and s.b_id = #{bId}
|
|
|
- * </if>
|
|
|
- * <if test="storeId != null and storeId !=''">
|
|
|
- * and s.store_id = #{storeId}
|
|
|
- * </if>
|
|
|
+ * <if test="newBId != null and newBId != ''">
|
|
|
+ * ,s.b_id = #{newBId}
|
|
|
+ * </if>
|
|
|
+ * <if test="userId != null and userId != ''">
|
|
|
+ * ,s.user_id = #{userId}
|
|
|
+ * </if>
|
|
|
+ * <if test="name != null and name != ''">
|
|
|
+ * ,s.name = #{name}
|
|
|
+ * </if>
|
|
|
+ * <if test="address != null and address != ''">
|
|
|
+ * ,s.address = #{address}
|
|
|
+ * </if>
|
|
|
+ * <if test="tel != null and tel != ''">
|
|
|
+ * ,s.tel = #{tel}
|
|
|
+ * </if>
|
|
|
+ * <if test="storeTypeCd != null and storeTypeCd != ''">
|
|
|
+ * ,s.store_type_cd = #{storeTypeCd}
|
|
|
+ * </if>
|
|
|
+ * <if test="nearbyLandmarks != null and nearbyLandmarks != ''">
|
|
|
+ * ,s.nearby_landmarks = #{nearbyLandmarks}
|
|
|
+ * </if>
|
|
|
+ * <if test="mapX != null and mapX != ''">
|
|
|
+ * ,s.map_x = #{mapX}
|
|
|
+ * </if>
|
|
|
+ * <if test="mapY != null and mapY != ''">
|
|
|
+ * ,s.map_y = #{mapY}
|
|
|
+ * </if>
|
|
|
+ * where 1=1
|
|
|
+ * <if test="bId != null and bId !=''">
|
|
|
+ * and s.b_id = #{bId}
|
|
|
+ * </if>
|
|
|
+ * <if test="storeId != null and storeId !=''">
|
|
|
+ * and s.store_id = #{storeId}
|
|
|
+ * </if>
|
|
|
*/
|
|
|
- private String dealUpdateInfoInstance(Data data,String fileContext){
|
|
|
- String sql = "update "+ data.getTableName() + " t set t.status_cd = #{statusCd}\n";
|
|
|
+ private String dealUpdateInfoInstance(Data data, String fileContext) {
|
|
|
+ String sql = "update " + data.getTableName() + " t set t.status_cd = #{statusCd}\n";
|
|
|
String sqlWhere = " where 1=1 ";
|
|
|
|
|
|
- Map<String,String> params = data.getParams();
|
|
|
+ Map<String, String> params = data.getParams();
|
|
|
|
|
|
- for(String key:params.keySet()){
|
|
|
- if("operate".equals(key)){
|
|
|
+ for (String key : params.keySet()) {
|
|
|
+ if ("operate".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if("statusCd".equals(key)){
|
|
|
+ if ("statusCd".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
- if(!"bId".equals(key) && !data.getId().equals(key)) {
|
|
|
+ if (!"bId".equals(key) && !data.getId().equals(key)) {
|
|
|
sql += "<if test=\"" + key + " !=null and " + key + " != ''\">\n";
|
|
|
sql += ", t." + params.get(key) + "= #{" + key + "}\n";
|
|
|
sql += "</if> \n";
|
|
|
}
|
|
|
- if("bId".equals(key) || data.getId().equals(key)) {
|
|
|
+ if ("bId".equals(key) || data.getId().equals(key)) {
|
|
|
sqlWhere += "<if test=\"" + key + " !=null and " + key + " != ''\">\n";
|
|
|
sqlWhere += "and t." + params.get(key) + "= #{" + key + "}\n";
|
|
|
sqlWhere += "</if> \n";
|
|
|
@@ -244,7 +250,7 @@ public class GeneratorServiceDaoImplMapperListener extends BaseGenerator {
|
|
|
|
|
|
sql += sqlWhere;
|
|
|
|
|
|
- fileContext = fileContext.replace("$updateInfoInstance$",sql);
|
|
|
+ fileContext = fileContext.replace("$updateInfoInstance$", sql);
|
|
|
|
|
|
return fileContext;
|
|
|
|
|
|
@@ -254,22 +260,23 @@ public class GeneratorServiceDaoImplMapperListener extends BaseGenerator {
|
|
|
|
|
|
/**
|
|
|
* 生成代码
|
|
|
+ *
|
|
|
* @param data
|
|
|
*/
|
|
|
- public void generator(Data data){
|
|
|
+ public void generator(Data data) {
|
|
|
StringBuffer sb = readFile(this.getClass().getResource("/template/ServiceDaoImplMapper.txt").getFile());
|
|
|
String fileContext = sb.toString();
|
|
|
- fileContext = fileContext.replace("store",toLowerCaseFirstOne(data.getName()))
|
|
|
- .replace("Store",toUpperCaseFirstOne(data.getName()))
|
|
|
- .replace("商户",data.getDesc());
|
|
|
- fileContext = dealSaveBusinessInfo(data,fileContext);
|
|
|
- fileContext = dealGetBusinessInfo(data,fileContext);
|
|
|
- fileContext = dealSaveInfoInstance(data,fileContext);
|
|
|
- fileContext = dealGetInfo(data,fileContext);
|
|
|
- fileContext = dealUpdateInfoInstance(data,fileContext);
|
|
|
+ fileContext = fileContext.replace("store", toLowerCaseFirstOne(data.getName()))
|
|
|
+ .replace("Store", toUpperCaseFirstOne(data.getName()))
|
|
|
+ .replace("商户", data.getDesc());
|
|
|
+ fileContext = dealSaveBusinessInfo(data, fileContext);
|
|
|
+ fileContext = dealGetBusinessInfo(data, fileContext);
|
|
|
+ fileContext = dealSaveInfoInstance(data, fileContext);
|
|
|
+ fileContext = dealGetInfo(data, fileContext);
|
|
|
+ fileContext = dealUpdateInfoInstance(data, fileContext);
|
|
|
|
|
|
System.out.println(this.getClass().getResource("/listener").getPath());
|
|
|
- String writePath = this.getClass().getResource("/listener").getPath()+"/"+toUpperCaseFirstOne(data.getName())+"ServiceDaoImplMapper.xml";
|
|
|
+ String writePath = this.getClass().getResource("/listener").getPath() + "/" + toUpperCaseFirstOne(data.getName()) + "ServiceDaoImplMapper.xml";
|
|
|
writeFile(writePath,
|
|
|
fileContext);
|
|
|
}
|