--task=null --user=杨长江 订单服务配置
Showing
9 changed files
with
197 additions
and
91 deletions
@@ -47,8 +47,9 @@ public @interface MetaProperty { | @@ -47,8 +47,9 @@ public @interface MetaProperty { | ||
47 | boolean scale() default false; | 47 | boolean scale() default false; |
48 | 48 | ||
49 | /** | 49 | /** |
50 | - * 数据类型:option:代表下拉框,可选 | ||
51 | - * | 50 | + * 数据类型:option 代表下拉框,可选 |
51 | + * int 整数型(前台做数据校验用) | ||
52 | + * double 浮点型(前台做数据校验用) | ||
52 | * @return | 53 | * @return |
53 | */ | 54 | */ |
54 | String type() default ""; | 55 | String type() default ""; |
@@ -72,7 +72,7 @@ public class BuyerPenalty { | @@ -72,7 +72,7 @@ public class BuyerPenalty { | ||
72 | @MetaProperty(desc = "最高罚款(元)",rootGroup ="预售规则", childGroup ="仓库收货前",type = "double") | 72 | @MetaProperty(desc = "最高罚款(元)",rootGroup ="预售规则", childGroup ="仓库收货前",type = "double") |
73 | private Double max; | 73 | private Double max; |
74 | 74 | ||
75 | - @MetaProperty(desc = "最高罚款(元)",rootGroup ="预售规则", childGroup ="仓库收货前",type = "double") | 75 | + @MetaProperty(desc = "最低罚款(元)",rootGroup ="预售规则", childGroup ="仓库收货前",type = "double") |
76 | private Double min; | 76 | private Double min; |
77 | } | 77 | } |
78 | 78 | ||
@@ -152,10 +152,10 @@ public class BuyerPenalty { | @@ -152,10 +152,10 @@ public class BuyerPenalty { | ||
152 | @Data | 152 | @Data |
153 | private static class TriggerCaseMap{ | 153 | private static class TriggerCaseMap{ |
154 | 154 | ||
155 | - private BeforeSellerDeliver beforeSellerDeliver; | ||
156 | - | ||
157 | private BeforeDepotReceive beforeDepotReceive; | 155 | private BeforeDepotReceive beforeDepotReceive; |
158 | 156 | ||
157 | + private BeforeSellerDeliver beforeSellerDeliver; | ||
158 | + | ||
159 | @Data | 159 | @Data |
160 | private static class BeforeDepotReceive{ | 160 | private static class BeforeDepotReceive{ |
161 | 161 |
1 | package com.yoho.order.metaconfig; | 1 | package com.yoho.order.metaconfig; |
2 | 2 | ||
3 | +import com.alibaba.fastjson.annotation.JSONField; | ||
3 | import com.yoho.order.annotation.MetaProperty; | 4 | import com.yoho.order.annotation.MetaProperty; |
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | import org.springframework.stereotype.Component; | 6 | import org.springframework.stereotype.Component; |
@@ -13,13 +14,24 @@ import org.springframework.stereotype.Component; | @@ -13,13 +14,24 @@ import org.springframework.stereotype.Component; | ||
13 | @Component("seller_enter_threshold") | 14 | @Component("seller_enter_threshold") |
14 | public class SellerEnterThreshold { | 15 | public class SellerEnterThreshold { |
15 | 16 | ||
16 | - private SuperEntry SUPER_ENTRY; | 17 | + /** |
18 | + * 用fastJson把对象转成json字符串,会自动把 | ||
19 | + * 属性的首字母转成小写,加JSONField注解就会取 | ||
20 | + * 注解中配置的name属性 | ||
21 | + * | ||
22 | + * fastJson另外的一个坑,如果属性首字母大写,加注解也不起作用 | ||
23 | + */ | ||
24 | + @JSONField(name = "SUPER_ENTRY") | ||
25 | + private SuperEntry sUPER_ENTRY; | ||
17 | 26 | ||
18 | - private Common COMMON; | 27 | + @JSONField(name = "COMMON") |
28 | + private Common cOMMON; | ||
19 | 29 | ||
20 | - private LargeSettlement LARGE_SETTLEMENT; | 30 | + @JSONField(name = "LARGE_SETTLEMENT") |
31 | + private LargeSettlement lARGE_SETTLEMENT; | ||
21 | 32 | ||
22 | - private FastDeliverySuper FAST_DELIVERY_SUPER; | 33 | + @JSONField(name = "FAST_DELIVERY_SUPER") |
34 | + private FastDeliverySuper fAST_DELIVERY_SUPER; | ||
23 | 35 | ||
24 | @Data | 36 | @Data |
25 | private static class SuperEntry{ | 37 | private static class SuperEntry{ |
@@ -27,11 +27,12 @@ | @@ -27,11 +27,12 @@ | ||
27 | select count(1) | 27 | select count(1) |
28 | from meta_config | 28 | from meta_config |
29 | <where> | 29 | <where> |
30 | + 1 = 1 | ||
30 | <if test="code != null and code != ''"> | 31 | <if test="code != null and code != ''"> |
31 | - code = #{code,jdbcType=VARCHAR} | 32 | + and code like concat('%',#{code,jdbcType=VARCHAR},'%') |
32 | </if> | 33 | </if> |
33 | - <if test="code != null and code != ''"> | ||
34 | - title = #{title,jdbcType=VARCHAR} | 34 | + <if test="title != null and title != ''"> |
35 | + and title like concat('%', #{title,jdbcType=VARCHAR},'%') | ||
35 | </if> | 36 | </if> |
36 | </where> | 37 | </where> |
37 | </select> | 38 | </select> |
@@ -41,11 +42,12 @@ | @@ -41,11 +42,12 @@ | ||
41 | <include refid="Base_Column_List"/> | 42 | <include refid="Base_Column_List"/> |
42 | from meta_config | 43 | from meta_config |
43 | <where> | 44 | <where> |
45 | + 1 = 1 | ||
44 | <if test="code != null and code != ''"> | 46 | <if test="code != null and code != ''"> |
45 | - code = #{code,jdbcType=VARCHAR} | 47 | + and code like concat('%',#{code,jdbcType=VARCHAR},'%') |
46 | </if> | 48 | </if> |
47 | - <if test="code != null and code != ''"> | ||
48 | - title = #{title,jdbcType=VARCHAR} | 49 | + <if test="title != null and title != ''"> |
50 | + and title like concat('%', #{title,jdbcType=VARCHAR},'%') | ||
49 | </if> | 51 | </if> |
50 | </where> | 52 | </where> |
51 | order by id asc | 53 | order by id asc |
@@ -66,13 +68,13 @@ | @@ -66,13 +68,13 @@ | ||
66 | <if test="code != null and code != ''"> | 68 | <if test="code != null and code != ''"> |
67 | code = #{code,jdbcType=VARCHAR}, | 69 | code = #{code,jdbcType=VARCHAR}, |
68 | </if> | 70 | </if> |
69 | - <if test="code != null and code != ''"> | 71 | + <if test="title != null and title != ''"> |
70 | title = #{title,jdbcType=VARCHAR}, | 72 | title = #{title,jdbcType=VARCHAR}, |
71 | </if> | 73 | </if> |
72 | - <if test="code != null and code != ''"> | 74 | + <if test="desc != null and desc != ''"> |
73 | `desc` = #{desc,jdbcType=VARCHAR}, | 75 | `desc` = #{desc,jdbcType=VARCHAR}, |
74 | </if> | 76 | </if> |
75 | - <if test="code != null and code != ''"> | 77 | + <if test="value != null and value != ''"> |
76 | `value` = #{value,jdbcType=VARCHAR}, | 78 | `value` = #{value,jdbcType=VARCHAR}, |
77 | </if> | 79 | </if> |
78 | </set> | 80 | </set> |
1 | package com.yoho.ufo.order.controller; | 1 | package com.yoho.ufo.order.controller; |
2 | 2 | ||
3 | +import com.yoho.core.rest.client.ServiceCaller; | ||
3 | import com.yoho.order.model.MetaConfig; | 4 | import com.yoho.order.model.MetaConfig; |
4 | import com.yoho.order.model.MetaConfigReq; | 5 | import com.yoho.order.model.MetaConfigReq; |
5 | import com.yoho.service.model.order.response.PageResponse; | 6 | import com.yoho.service.model.order.response.PageResponse; |
@@ -21,24 +22,37 @@ public class MetaConfigController { | @@ -21,24 +22,37 @@ public class MetaConfigController { | ||
21 | @Autowired | 22 | @Autowired |
22 | private IMetaConfigService metaConfigService; | 23 | private IMetaConfigService metaConfigService; |
23 | 24 | ||
25 | + @Autowired | ||
26 | + private ServiceCaller serviceCaller; | ||
27 | + /** | ||
28 | + * 分页查询配置项 | ||
29 | + * @param metaConfigReq | ||
30 | + * @return | ||
31 | + */ | ||
24 | @RequestMapping(value = "/list") | 32 | @RequestMapping(value = "/list") |
25 | public ApiResponse list(MetaConfigReq metaConfigReq){ | 33 | public ApiResponse list(MetaConfigReq metaConfigReq){ |
26 | - | ||
27 | PageResponse<MetaConfig> pageResponse = this.metaConfigService.list(metaConfigReq); | 34 | PageResponse<MetaConfig> pageResponse = this.metaConfigService.list(metaConfigReq); |
28 | return new ApiResponse.ApiResponseBuilder().code(200).data(pageResponse).build(); | 35 | return new ApiResponse.ApiResponseBuilder().code(200).data(pageResponse).build(); |
29 | } | 36 | } |
30 | 37 | ||
31 | - | 38 | + /** |
39 | + * 查询单个配置项内容 | ||
40 | + * @param code | ||
41 | + * @return | ||
42 | + */ | ||
32 | @RequestMapping(value = "/detail") | 43 | @RequestMapping(value = "/detail") |
33 | public ApiResponse getOne(String code){ | 44 | public ApiResponse getOne(String code){ |
34 | MetaConfig config = metaConfigService.selectByCode(code); | 45 | MetaConfig config = metaConfigService.selectByCode(code); |
35 | - System.out.println(config); | ||
36 | return new ApiResponse.ApiResponseBuilder().code(200).data(config).build(); | 46 | return new ApiResponse.ApiResponseBuilder().code(200).data(config).build(); |
37 | } | 47 | } |
38 | 48 | ||
49 | + /** | ||
50 | + * 更新配置 | ||
51 | + * @param metaConfig | ||
52 | + * @return | ||
53 | + */ | ||
39 | @RequestMapping(value = "/update") | 54 | @RequestMapping(value = "/update") |
40 | public ApiResponse update(MetaConfig metaConfig){ | 55 | public ApiResponse update(MetaConfig metaConfig){ |
41 | - System.out.println(metaConfig.getValue()); | ||
42 | - return new ApiResponse.ApiResponseBuilder().code(200).build(); | 56 | + return metaConfigService.updateByPrimaryKey(metaConfig); |
43 | } | 57 | } |
44 | } | 58 | } |
@@ -3,6 +3,7 @@ package com.yoho.ufo.order.service; | @@ -3,6 +3,7 @@ package com.yoho.ufo.order.service; | ||
3 | import com.yoho.order.model.MetaConfig; | 3 | import com.yoho.order.model.MetaConfig; |
4 | import com.yoho.order.model.MetaConfigReq; | 4 | import com.yoho.order.model.MetaConfigReq; |
5 | import com.yoho.service.model.order.response.PageResponse; | 5 | import com.yoho.service.model.order.response.PageResponse; |
6 | +import com.yoho.ufo.service.model.ApiResponse; | ||
6 | 7 | ||
7 | /** | 8 | /** |
8 | * @Author: 杨长江 | 9 | * @Author: 杨长江 |
@@ -30,7 +31,7 @@ public interface IMetaConfigService { | @@ -30,7 +31,7 @@ public interface IMetaConfigService { | ||
30 | * @param config | 31 | * @param config |
31 | * @return | 32 | * @return |
32 | */ | 33 | */ |
33 | - int updateByPrimaryKey(MetaConfig config); | 34 | + ApiResponse updateByPrimaryKey(MetaConfig config); |
34 | 35 | ||
35 | 36 | ||
36 | /** | 37 | /** |
1 | package com.yoho.ufo.order.service.impl; | 1 | package com.yoho.ufo.order.service.impl; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | +import com.yoho.core.redis.cluster.annotation.Redis; | ||
5 | +import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate; | ||
4 | import com.yoho.order.annotation.MetaProperty; | 6 | import com.yoho.order.annotation.MetaProperty; |
5 | import com.yoho.order.dal.MetaConfigMapper; | 7 | import com.yoho.order.dal.MetaConfigMapper; |
6 | import com.yoho.order.model.MetaConfig; | 8 | import com.yoho.order.model.MetaConfig; |
@@ -8,6 +10,10 @@ import com.yoho.order.model.MetaConfigReq; | @@ -8,6 +10,10 @@ import com.yoho.order.model.MetaConfigReq; | ||
8 | import com.yoho.order.model.PropertyItem; | 10 | import com.yoho.order.model.PropertyItem; |
9 | import com.yoho.service.model.order.response.PageResponse; | 11 | import com.yoho.service.model.order.response.PageResponse; |
10 | import com.yoho.ufo.order.service.IMetaConfigService; | 12 | import com.yoho.ufo.order.service.IMetaConfigService; |
13 | +import com.yoho.ufo.service.model.ApiResponse; | ||
14 | +import com.yoho.ufo.util.DateUtil; | ||
15 | +import org.slf4j.Logger; | ||
16 | +import org.slf4j.LoggerFactory; | ||
11 | import org.springframework.beans.BeansException; | 17 | import org.springframework.beans.BeansException; |
12 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
13 | import org.springframework.context.ApplicationContext; | 19 | import org.springframework.context.ApplicationContext; |
@@ -16,6 +22,8 @@ import org.springframework.stereotype.Service; | @@ -16,6 +22,8 @@ import org.springframework.stereotype.Service; | ||
16 | 22 | ||
17 | import java.lang.reflect.Field; | 23 | import java.lang.reflect.Field; |
18 | import java.util.*; | 24 | import java.util.*; |
25 | +import java.util.regex.Matcher; | ||
26 | +import java.util.regex.Pattern; | ||
19 | 27 | ||
20 | /** | 28 | /** |
21 | * @Author: 杨长江 | 29 | * @Author: 杨长江 |
@@ -29,6 +37,9 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | @@ -29,6 +37,9 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | ||
29 | @Autowired | 37 | @Autowired |
30 | private MetaConfigMapper metaConfigMapper; | 38 | private MetaConfigMapper metaConfigMapper; |
31 | 39 | ||
40 | + @Redis("gwNoSyncRedis") | ||
41 | + private YHRedisTemplate yhRedisTemplate; | ||
42 | + | ||
32 | private ApplicationContext applicationContext; | 43 | private ApplicationContext applicationContext; |
33 | 44 | ||
34 | /** | 45 | /** |
@@ -36,6 +47,34 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | @@ -36,6 +47,34 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | ||
36 | */ | 47 | */ |
37 | private StringBuffer collectionName; | 48 | private StringBuffer collectionName; |
38 | 49 | ||
50 | + private static final Logger LOGGER = LoggerFactory.getLogger(MetaConfigServiceImpl.class); | ||
51 | + | ||
52 | + /** | ||
53 | + * SuperEntry SUPER_ENTRY; | ||
54 | + * | ||
55 | + * Common COMMON; | ||
56 | + * | ||
57 | + * LargeSettlement LARGE_SETTLEMENT; | ||
58 | + * | ||
59 | + * FastDeliverySuper FAST_DELIVERY_SUPER; | ||
60 | + * 这里几个属性名称非要大写,无奈 | ||
61 | + */ | ||
62 | + private static final String[] upperCaseClassNameArray= {"SuperEntry","Common","LargeSettlement","FastDeliverySuper"}; | ||
63 | + | ||
64 | + /** | ||
65 | + * HkInStock hk_in_stock | ||
66 | + */ | ||
67 | + private static final String[] splitUnderLineClassNameArray = {"HkInStock"}; | ||
68 | + /** | ||
69 | + * 上面的数组转成列表 | ||
70 | + */ | ||
71 | + private static final List<String> upperCaseClassNameList = Arrays.asList(upperCaseClassNameArray); | ||
72 | + | ||
73 | + /** | ||
74 | + * 上面的数组转成列表 | ||
75 | + */ | ||
76 | + private static final List<String> splitUnderLineClassNameList = Arrays.asList(splitUnderLineClassNameArray); | ||
77 | + | ||
39 | @Override | 78 | @Override |
40 | public MetaConfig selectByPrimaryKey(int id) { | 79 | public MetaConfig selectByPrimaryKey(int id) { |
41 | return this.metaConfigMapper.selectByPrimaryKey(id); | 80 | return this.metaConfigMapper.selectByPrimaryKey(id); |
@@ -71,8 +110,37 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | @@ -71,8 +110,37 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | ||
71 | } | 110 | } |
72 | 111 | ||
73 | @Override | 112 | @Override |
74 | - public int updateByPrimaryKey(MetaConfig config) { | ||
75 | - return this.metaConfigMapper.updateByPrimaryKey(config); | 113 | + public ApiResponse updateByPrimaryKey(MetaConfig config) { |
114 | + | ||
115 | + Object bean = applicationContext.getBean(config.getCode()); | ||
116 | + | ||
117 | + //如果根据code找不到bean,说明code被修改了,抛异常,直接返回 | ||
118 | + if(Objects.isNull(bean)){ | ||
119 | + return new ApiResponse.ApiResponseBuilder().code(500).message("数据校验出错,操作失败").build(); | ||
120 | + } | ||
121 | + //验证json格式是否正确 | ||
122 | + Object object; | ||
123 | + try { | ||
124 | + object = JSONObject.parseObject(config.getValue(), bean.getClass()); | ||
125 | + }catch (Exception e){ | ||
126 | + LOGGER.error("JSON数据格式/类型错误",e); | ||
127 | + return new ApiResponse.ApiResponseBuilder().code(500).message("数据校验出错,操作失败").build(); | ||
128 | + } | ||
129 | + | ||
130 | + if(Objects.isNull(object)){ | ||
131 | + return new ApiResponse.ApiResponseBuilder().code(500).message("数据校验出错,操作失败").build(); | ||
132 | + } | ||
133 | + config.setValue(JSONObject.toJSONString(object)); | ||
134 | + LOGGER.info("更新服务配置 ------------>" + config); | ||
135 | + int n = this.metaConfigMapper.updateByPrimaryKey(config); | ||
136 | + /** | ||
137 | + * 清除缓存 | ||
138 | + */ | ||
139 | + /*if(n > 0){ | ||
140 | + LOGGER.info("清除服务配置缓存(key) ------------->" + config.getCode()); | ||
141 | + yhRedisTemplate.delete(RedisKeyBuilder.newInstance().appendFixed(config.getCode())); | ||
142 | + }*/ | ||
143 | + return new ApiResponse.ApiResponseBuilder().code(200).data(n).build(); | ||
76 | } | 144 | } |
77 | 145 | ||
78 | @Override | 146 | @Override |
@@ -80,10 +148,17 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | @@ -80,10 +148,17 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | ||
80 | 148 | ||
81 | int count = this.metaConfigMapper.countByCondition(metaConfigReq); | 149 | int count = this.metaConfigMapper.countByCondition(metaConfigReq); |
82 | List<MetaConfig> list = null; | 150 | List<MetaConfig> list = null; |
83 | - if(count >0){ | 151 | + if(count >=0){ |
84 | list = this.metaConfigMapper.listByCondition(metaConfigReq); | 152 | list = this.metaConfigMapper.listByCondition(metaConfigReq); |
85 | } | 153 | } |
86 | 154 | ||
155 | + if(null != list && list.size() > 0){ | ||
156 | + list.stream().forEach(item -> { | ||
157 | + if(null != item.getCreateTime() && 0 != item.getCreateTime()){ | ||
158 | + item.setCreateTimeStr(DateUtil.int2DateStr(item.getCreateTime(),"yyyy-MM-dd HH:mm:ss")); | ||
159 | + } | ||
160 | + }); | ||
161 | + } | ||
87 | PageResponse<MetaConfig> pageResponse = new PageResponse(); | 162 | PageResponse<MetaConfig> pageResponse = new PageResponse(); |
88 | pageResponse.setList(list); | 163 | pageResponse.setList(list); |
89 | pageResponse.setPageNo(metaConfigReq.getPage()); | 164 | pageResponse.setPageNo(metaConfigReq.getPage()); |
@@ -133,10 +208,23 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | @@ -133,10 +208,23 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | ||
133 | String[] clazzNames = clazzName.split("\\$"); | 208 | String[] clazzNames = clazzName.split("\\$"); |
134 | StringBuffer prefix = new StringBuffer(); | 209 | StringBuffer prefix = new StringBuffer(); |
135 | // 拼接该属性的完整限定名 | 210 | // 拼接该属性的完整限定名 |
136 | - Arrays.asList(clazzNames).stream().skip(1).forEach((s) -> | 211 | + |
212 | + // 本不想代码耦合度太高,无奈之举 | ||
213 | + Arrays.asList(clazzNames).stream().skip(1).forEach((s) ->{ | ||
214 | + if(upperCaseClassNameList.contains(s)){ | ||
215 | + // 下划线分隔,字母全部大写 | ||
216 | + prefix.append(camelToUnderLine(s).substring(1).toUpperCase()) | ||
217 | + .append("."); | ||
218 | + }else if(splitUnderLineClassNameList.contains(s)){ | ||
219 | + // 下划线分隔,字母全部小写 | ||
220 | + prefix.append(camelToUnderLine(s).substring(1)) | ||
221 | + .append("."); | ||
222 | + }else{ | ||
137 | prefix.append(Character.toLowerCase(s.charAt(0))) | 223 | prefix.append(Character.toLowerCase(s.charAt(0))) |
138 | .append(s.substring(1)) | 224 | .append(s.substring(1)) |
139 | - .append(".")); | 225 | + .append("."); |
226 | + } | ||
227 | + }); | ||
140 | String pName = prefix.toString() + field.getName(); | 228 | String pName = prefix.toString() + field.getName(); |
141 | // 如果该属性完整的限定名包含CollectionName,那么则替换 | 229 | // 如果该属性完整的限定名包含CollectionName,那么则替换 |
142 | if(collectionName != null){ | 230 | if(collectionName != null){ |
@@ -192,4 +280,21 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | @@ -192,4 +280,21 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon | ||
192 | } | 280 | } |
193 | } | 281 | } |
194 | } | 282 | } |
283 | + | ||
284 | + | ||
285 | + /** | ||
286 | + * 驼峰转下划线 | ||
287 | + * @param str | ||
288 | + * @return | ||
289 | + */ | ||
290 | + public static String camelToUnderLine(String str) { | ||
291 | + Pattern humpPattern = Pattern.compile("[A-Z]"); | ||
292 | + Matcher matcher = humpPattern.matcher(str); | ||
293 | + StringBuffer sb = new StringBuffer(); | ||
294 | + while (matcher.find()) { | ||
295 | + matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase()); | ||
296 | + } | ||
297 | + matcher.appendTail(sb); | ||
298 | + return sb.toString(); | ||
299 | + } | ||
195 | } | 300 | } |
@@ -19,10 +19,10 @@ | @@ -19,10 +19,10 @@ | ||
19 | <hr style="border:1px solid #ddd;"><br> | 19 | <hr style="border:1px solid #ddd;"><br> |
20 | <div style="border:1px solid #ddd;border-radius:5px 5px 5px 5px;"> | 20 | <div style="border:1px solid #ddd;border-radius:5px 5px 5px 5px;"> |
21 | <div style="margin-left: 10px;margin-top: 20px;margin-bottom: 20px"> | 21 | <div style="margin-left: 10px;margin-top: 20px;margin-bottom: 20px"> |
22 | - <label>订单编号: </label> | 22 | + <label>编号: </label> |
23 | <input id="code" type="text" class="easyui-textbox" style="width:150px"> | 23 | <input id="code" type="text" class="easyui-textbox" style="width:150px"> |
24 | 24 | ||
25 | - <label> 标题:</label> | 25 | + <label> 名称:</label> |
26 | <input id="title" type="text" class="easyui-textbox" style="width:150px"/> | 26 | <input id="title" type="text" class="easyui-textbox" style="width:150px"/> |
27 | <a id="searchBtn" class="btn-info">查询</a> | 27 | <a id="searchBtn" class="btn-info">查询</a> |
28 | <a id="allBtn" class="btn-success">全部</a> | 28 | <a id="allBtn" class="btn-success">全部</a> |
@@ -38,8 +38,11 @@ | @@ -38,8 +38,11 @@ | ||
38 | <script> | 38 | <script> |
39 | var code; | 39 | var code; |
40 | var keyValueMap = {}; | 40 | var keyValueMap = {}; |
41 | + // 值是比例(0~1四位小数)的键 | ||
41 | var keyScaleList =[]; | 42 | var keyScaleList =[]; |
43 | + // 值是整数的键 | ||
42 | var keyIntList =[]; | 44 | var keyIntList =[]; |
45 | + // 值是浮点型的键 | ||
43 | var keyDoubleList =[]; | 46 | var keyDoubleList =[]; |
44 | $(function() { | 47 | $(function() { |
45 | 48 | ||
@@ -48,7 +51,7 @@ | @@ -48,7 +51,7 @@ | ||
48 | onClick : function() { | 51 | onClick : function() { |
49 | $("#configListTable").datagrid("load", { | 52 | $("#configListTable").datagrid("load", { |
50 | code : $("#code").val(), | 53 | code : $("#code").val(), |
51 | - uid : $("#title").val(), | 54 | + title : $("#title").val(), |
52 | }); | 55 | }); |
53 | } | 56 | } |
54 | }); | 57 | }); |
@@ -58,16 +61,16 @@ | @@ -58,16 +61,16 @@ | ||
58 | iconCls: "icon-import", | 61 | iconCls: "icon-import", |
59 | onClick: function () { | 62 | onClick: function () { |
60 | $("#code").textbox('setValue',''); | 63 | $("#code").textbox('setValue',''); |
61 | - $("#uid").textbox('setValue',''); | 64 | + $("#title").textbox('setValue',''); |
62 | $("#configListTable").datagrid("load", { | 65 | $("#configListTable").datagrid("load", { |
63 | }); | 66 | }); |
64 | } | 67 | } |
65 | }); | 68 | }); |
66 | 69 | ||
67 | - getOrderList(); | 70 | + getConfigList(); |
68 | }); | 71 | }); |
69 | 72 | ||
70 | - function getOrderList(){ | 73 | + function getConfigList(){ |
71 | $("#configListTable").myDatagrid({ | 74 | $("#configListTable").myDatagrid({ |
72 | fit: true, | 75 | fit: true, |
73 | fitColumns: true, | 76 | fitColumns: true, |
@@ -93,15 +96,10 @@ | @@ -93,15 +96,10 @@ | ||
93 | align: "center", | 96 | align: "center", |
94 | width: 40 | 97 | width: 40 |
95 | }, { | 98 | }, { |
96 | - title: "修改时间", | ||
97 | - field: "uid", | ||
98 | - align: "center", | ||
99 | - width: 40 | ||
100 | - }, { | ||
101 | title: "创建时间", | 99 | title: "创建时间", |
102 | - field: "productName", | 100 | + field: "createTimeStr", |
103 | align: "center", | 101 | align: "center", |
104 | - width: 40 | 102 | + width: 40, |
105 | }, { | 103 | }, { |
106 | title: "操作", | 104 | title: "操作", |
107 | field: "operations", | 105 | field: "operations", |
@@ -153,54 +151,13 @@ | @@ -153,54 +151,13 @@ | ||
153 | handler: function () { | 151 | handler: function () { |
154 | $.messager.confirm("确认", message, function (flag) { | 152 | $.messager.confirm("确认", message, function (flag) { |
155 | if (flag) { | 153 | if (flag) { |
156 | - var a = toJSON(); | ||
157 | - delete a.id; | ||
158 | - delete a.code; | ||
159 | - delete a.title; | ||
160 | - delete a.desc; | ||
161 | - delete a.value; | ||
162 | - | ||
163 | - $("#metaConfigEditForm #value").val(JSON.stringify(a)); | ||
164 | - | ||
165 | var url = contextPath + "/metaConfig/update"; | 154 | var url = contextPath + "/metaConfig/update"; |
166 | - /*var code = $('#metaConfigEditForm #code').val(); | ||
167 | - if (code == '' || code == null || code == undefined) { | ||
168 | - $.messager.alert("提示", '编码不能为空!', "error"); | ||
169 | - return false; | ||
170 | - | ||
171 | - } | ||
172 | - | ||
173 | - var title = $('#metaConfigEditForm #title').val(); | ||
174 | - if (title == '' || title == null || title == undefined) { | ||
175 | - $.messager.alert("提示", '标题不能为空!', "error"); | ||
176 | - return false; | ||
177 | - | ||
178 | - } | ||
179 | - | ||
180 | - | ||
181 | - for(key in keyValueMap){ | ||
182 | - var val = $("#metaConfigEditForm [name = '"+key+"']").val(); | ||
183 | - if (val == '' || val == null || val == undefined) { | ||
184 | - $.messager.alert("提示", keyValueMap[key] + '不能为空!', "error"); | ||
185 | - return false; | ||
186 | - | ||
187 | - } | ||
188 | - }*/ | ||
189 | - | ||
190 | - /*for(key in keyValueMap){ | ||
191 | - var val = $("#metaConfigEditForm [name = '"+key+"']").val(); | ||
192 | - if (val == '' || val == null || val == undefined) { | ||
193 | - $.messager.alert("提示", keyValueMap[key] + '不能为空!', "error"); | ||
194 | - return false; | ||
195 | - | ||
196 | - } | ||
197 | - }*/ | ||
198 | - | ||
199 | //debugger; | 155 | //debugger; |
156 | + // 校验整数 | ||
200 | if(keyIntList.length > 0){ | 157 | if(keyIntList.length > 0){ |
201 | for(var i=0; i< keyIntList.length; i++){ | 158 | for(var i=0; i< keyIntList.length; i++){ |
202 | var val = $("#metaConfigEditForm [name = '"+keyIntList[i]+"']").val(); | 159 | var val = $("#metaConfigEditForm [name = '"+keyIntList[i]+"']").val(); |
203 | - var reg = /^\d+$ /; | 160 | + var reg = /^\d+$/; |
204 | if(!reg.test(val)){ | 161 | if(!reg.test(val)){ |
205 | $.messager.alert("提示", keyValueMap[keyIntList[i]] + '字段必须为非负整数!', "error"); | 162 | $.messager.alert("提示", keyValueMap[keyIntList[i]] + '字段必须为非负整数!', "error"); |
206 | return false; | 163 | return false; |
@@ -208,30 +165,39 @@ | @@ -208,30 +165,39 @@ | ||
208 | } | 165 | } |
209 | } | 166 | } |
210 | 167 | ||
211 | - | 168 | + // 校验比例(0~1两位四位小数) |
212 | if(keyScaleList.length > 0){ | 169 | if(keyScaleList.length > 0){ |
213 | for(var i=0; i< keyScaleList.length; i++){ | 170 | for(var i=0; i< keyScaleList.length; i++){ |
214 | var val = $("#metaConfigEditForm [name = '"+keyScaleList[i]+"']").val(); | 171 | var val = $("#metaConfigEditForm [name = '"+keyScaleList[i]+"']").val(); |
215 | - var reg = /^(0(.\d{1,2})?)|(1(.0{1,2})?)$/; | 172 | + var reg = /^(0(.\d{1,4})?)$|^(1(.0{1,2})?)$/; |
216 | if(!reg.test(val)){ | 173 | if(!reg.test(val)){ |
217 | - $.messager.alert("提示", keyValueMap[keyIntList[i]] + '字段必须为0~1之间的两位小数!', "error"); | 174 | + $.messager.alert("提示", keyValueMap[keyScaleList[i]] + '字段必须为0~1之间的小数(最多保留四位)!', "error"); |
218 | return false; | 175 | return false; |
219 | } | 176 | } |
220 | } | 177 | } |
221 | } | 178 | } |
222 | 179 | ||
223 | - | 180 | + // 校验浮点数 |
224 | if(keyDoubleList.length > 0){ | 181 | if(keyDoubleList.length > 0){ |
225 | for(var i=0; i< keyDoubleList.length; i++){ | 182 | for(var i=0; i< keyDoubleList.length; i++){ |
226 | - var reg = /^[0-9]+(.[0-9]{2})?$/; | 183 | + var reg = /^[0-9]+(.[0-9]{1,4})?$/; |
227 | var val = $("#metaConfigEditForm [name = '"+keyDoubleList[i]+"']").val(); | 184 | var val = $("#metaConfigEditForm [name = '"+keyDoubleList[i]+"']").val(); |
228 | if(!reg.test(val)){ | 185 | if(!reg.test(val)){ |
229 | - $.messager.alert("提示", keyValueMap[keyIntList[i]] + '字段必须为数字(保留两位小数)!', "error"); | 186 | + $.messager.alert("提示", keyValueMap[keyDoubleList[i]] + '字段必须为数字(最多保留四位小数)!', "error"); |
230 | return false; | 187 | return false; |
231 | } | 188 | } |
232 | } | 189 | } |
233 | } | 190 | } |
234 | 191 | ||
192 | + //把form转化成json | ||
193 | + var a = toJSON(); | ||
194 | + delete a.id; | ||
195 | + delete a.code; | ||
196 | + delete a.title; | ||
197 | + delete a.desc; | ||
198 | + delete a.value; | ||
199 | + $("#metaConfigEditForm #value").val(JSON.stringify(a)); | ||
200 | + | ||
235 | $("#metaConfigEditForm").form("submit", { | 201 | $("#metaConfigEditForm").form("submit", { |
236 | url: url, | 202 | url: url, |
237 | onSubmit: function () { | 203 | onSubmit: function () { |
-
Please register or login to post a comment