Authored by suibianqige

--task=null --user=杨长江 订单服务配置

... ... @@ -47,8 +47,9 @@ public @interface MetaProperty {
boolean scale() default false;
/**
* 数据类型:option:代表下拉框,可选
*
* 数据类型:option 代表下拉框,可选
* int 整数型(前台做数据校验用)
* double 浮点型(前台做数据校验用)
* @return
*/
String type() default "";
... ...
... ... @@ -72,7 +72,7 @@ public class BuyerPenalty {
@MetaProperty(desc = "最高罚款(元)",rootGroup ="预售规则", childGroup ="仓库收货前",type = "double")
private Double max;
@MetaProperty(desc = "最罚款(元)",rootGroup ="预售规则", childGroup ="仓库收货前",type = "double")
@MetaProperty(desc = "最罚款(元)",rootGroup ="预售规则", childGroup ="仓库收货前",type = "double")
private Double min;
}
... ... @@ -152,10 +152,10 @@ public class BuyerPenalty {
@Data
private static class TriggerCaseMap{
private BeforeSellerDeliver beforeSellerDeliver;
private BeforeDepotReceive beforeDepotReceive;
private BeforeSellerDeliver beforeSellerDeliver;
@Data
private static class BeforeDepotReceive{
... ...
package com.yoho.order.metaconfig;
import com.alibaba.fastjson.annotation.JSONField;
import com.yoho.order.annotation.MetaProperty;
import lombok.Data;
import org.springframework.stereotype.Component;
... ... @@ -13,13 +14,24 @@ import org.springframework.stereotype.Component;
@Component("seller_enter_threshold")
public class SellerEnterThreshold {
private SuperEntry SUPER_ENTRY;
/**
* 用fastJson把对象转成json字符串,会自动把
* 属性的首字母转成小写,加JSONField注解就会取
* 注解中配置的name属性
*
* fastJson另外的一个坑,如果属性首字母大写,加注解也不起作用
*/
@JSONField(name = "SUPER_ENTRY")
private SuperEntry sUPER_ENTRY;
private Common COMMON;
@JSONField(name = "COMMON")
private Common cOMMON;
private LargeSettlement LARGE_SETTLEMENT;
@JSONField(name = "LARGE_SETTLEMENT")
private LargeSettlement lARGE_SETTLEMENT;
private FastDeliverySuper FAST_DELIVERY_SUPER;
@JSONField(name = "FAST_DELIVERY_SUPER")
private FastDeliverySuper fAST_DELIVERY_SUPER;
@Data
private static class SuperEntry{
... ...
... ... @@ -46,4 +46,9 @@ public class MetaConfig {
* 属性集合
*/
private List<PropertyItem> propertyItem;
/**
* 格式化时间
*/
private String createTimeStr;
}
... ...
... ... @@ -27,11 +27,12 @@
select count(1)
from meta_config
<where>
1 = 1
<if test="code != null and code != ''">
code = #{code,jdbcType=VARCHAR}
and code like concat('%',#{code,jdbcType=VARCHAR},'%')
</if>
<if test="code != null and code != ''">
title = #{title,jdbcType=VARCHAR}
<if test="title != null and title != ''">
and title like concat('%', #{title,jdbcType=VARCHAR},'%')
</if>
</where>
</select>
... ... @@ -41,11 +42,12 @@
<include refid="Base_Column_List"/>
from meta_config
<where>
1 = 1
<if test="code != null and code != ''">
code = #{code,jdbcType=VARCHAR}
and code like concat('%',#{code,jdbcType=VARCHAR},'%')
</if>
<if test="code != null and code != ''">
title = #{title,jdbcType=VARCHAR}
<if test="title != null and title != ''">
and title like concat('%', #{title,jdbcType=VARCHAR},'%')
</if>
</where>
order by id asc
... ... @@ -66,13 +68,13 @@
<if test="code != null and code != ''">
code = #{code,jdbcType=VARCHAR},
</if>
<if test="code != null and code != ''">
<if test="title != null and title != ''">
title = #{title,jdbcType=VARCHAR},
</if>
<if test="code != null and code != ''">
<if test="desc != null and desc != ''">
`desc` = #{desc,jdbcType=VARCHAR},
</if>
<if test="code != null and code != ''">
<if test="value != null and value != ''">
`value` = #{value,jdbcType=VARCHAR},
</if>
</set>
... ...
package com.yoho.ufo.order.controller;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.order.model.MetaConfig;
import com.yoho.order.model.MetaConfigReq;
import com.yoho.service.model.order.response.PageResponse;
... ... @@ -21,24 +22,37 @@ public class MetaConfigController {
@Autowired
private IMetaConfigService metaConfigService;
@Autowired
private ServiceCaller serviceCaller;
/**
* 分页查询配置项
* @param metaConfigReq
* @return
*/
@RequestMapping(value = "/list")
public ApiResponse list(MetaConfigReq metaConfigReq){
PageResponse<MetaConfig> pageResponse = this.metaConfigService.list(metaConfigReq);
return new ApiResponse.ApiResponseBuilder().code(200).data(pageResponse).build();
}
/**
* 查询单个配置项内容
* @param code
* @return
*/
@RequestMapping(value = "/detail")
public ApiResponse getOne(String code){
MetaConfig config = metaConfigService.selectByCode(code);
System.out.println(config);
return new ApiResponse.ApiResponseBuilder().code(200).data(config).build();
}
/**
* 更新配置
* @param metaConfig
* @return
*/
@RequestMapping(value = "/update")
public ApiResponse update(MetaConfig metaConfig){
System.out.println(metaConfig.getValue());
return new ApiResponse.ApiResponseBuilder().code(200).build();
return metaConfigService.updateByPrimaryKey(metaConfig);
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.yoho.ufo.order.service;
import com.yoho.order.model.MetaConfig;
import com.yoho.order.model.MetaConfigReq;
import com.yoho.service.model.order.response.PageResponse;
import com.yoho.ufo.service.model.ApiResponse;
/**
* @Author: 杨长江
... ... @@ -30,7 +31,7 @@ public interface IMetaConfigService {
* @param config
* @return
*/
int updateByPrimaryKey(MetaConfig config);
ApiResponse updateByPrimaryKey(MetaConfig config);
/**
... ...
package com.yoho.ufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.order.annotation.MetaProperty;
import com.yoho.order.dal.MetaConfigMapper;
import com.yoho.order.model.MetaConfig;
... ... @@ -8,6 +10,10 @@ import com.yoho.order.model.MetaConfigReq;
import com.yoho.order.model.PropertyItem;
import com.yoho.service.model.order.response.PageResponse;
import com.yoho.ufo.order.service.IMetaConfigService;
import com.yoho.ufo.service.model.ApiResponse;
import com.yoho.ufo.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
... ... @@ -16,6 +22,8 @@ import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Author: 杨长江
... ... @@ -29,6 +37,9 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon
@Autowired
private MetaConfigMapper metaConfigMapper;
@Redis("gwNoSyncRedis")
private YHRedisTemplate yhRedisTemplate;
private ApplicationContext applicationContext;
/**
... ... @@ -36,6 +47,34 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon
*/
private StringBuffer collectionName;
private static final Logger LOGGER = LoggerFactory.getLogger(MetaConfigServiceImpl.class);
/**
* SuperEntry SUPER_ENTRY;
*
* Common COMMON;
*
* LargeSettlement LARGE_SETTLEMENT;
*
* FastDeliverySuper FAST_DELIVERY_SUPER;
* 这里几个属性名称非要大写,无奈
*/
private static final String[] upperCaseClassNameArray= {"SuperEntry","Common","LargeSettlement","FastDeliverySuper"};
/**
* HkInStock hk_in_stock
*/
private static final String[] splitUnderLineClassNameArray = {"HkInStock"};
/**
* 上面的数组转成列表
*/
private static final List<String> upperCaseClassNameList = Arrays.asList(upperCaseClassNameArray);
/**
* 上面的数组转成列表
*/
private static final List<String> splitUnderLineClassNameList = Arrays.asList(splitUnderLineClassNameArray);
@Override
public MetaConfig selectByPrimaryKey(int id) {
return this.metaConfigMapper.selectByPrimaryKey(id);
... ... @@ -71,8 +110,37 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon
}
@Override
public int updateByPrimaryKey(MetaConfig config) {
return this.metaConfigMapper.updateByPrimaryKey(config);
public ApiResponse updateByPrimaryKey(MetaConfig config) {
Object bean = applicationContext.getBean(config.getCode());
//如果根据code找不到bean,说明code被修改了,抛异常,直接返回
if(Objects.isNull(bean)){
return new ApiResponse.ApiResponseBuilder().code(500).message("数据校验出错,操作失败").build();
}
//验证json格式是否正确
Object object;
try {
object = JSONObject.parseObject(config.getValue(), bean.getClass());
}catch (Exception e){
LOGGER.error("JSON数据格式/类型错误",e);
return new ApiResponse.ApiResponseBuilder().code(500).message("数据校验出错,操作失败").build();
}
if(Objects.isNull(object)){
return new ApiResponse.ApiResponseBuilder().code(500).message("数据校验出错,操作失败").build();
}
config.setValue(JSONObject.toJSONString(object));
LOGGER.info("更新服务配置 ------------>" + config);
int n = this.metaConfigMapper.updateByPrimaryKey(config);
/**
* 清除缓存
*/
/*if(n > 0){
LOGGER.info("清除服务配置缓存(key) ------------->" + config.getCode());
yhRedisTemplate.delete(RedisKeyBuilder.newInstance().appendFixed(config.getCode()));
}*/
return new ApiResponse.ApiResponseBuilder().code(200).data(n).build();
}
@Override
... ... @@ -80,10 +148,17 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon
int count = this.metaConfigMapper.countByCondition(metaConfigReq);
List<MetaConfig> list = null;
if(count >0){
if(count >=0){
list = this.metaConfigMapper.listByCondition(metaConfigReq);
}
if(null != list && list.size() > 0){
list.stream().forEach(item -> {
if(null != item.getCreateTime() && 0 != item.getCreateTime()){
item.setCreateTimeStr(DateUtil.int2DateStr(item.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
}
});
}
PageResponse<MetaConfig> pageResponse = new PageResponse();
pageResponse.setList(list);
pageResponse.setPageNo(metaConfigReq.getPage());
... ... @@ -133,10 +208,23 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon
String[] clazzNames = clazzName.split("\\$");
StringBuffer prefix = new StringBuffer();
// 拼接该属性的完整限定名
Arrays.asList(clazzNames).stream().skip(1).forEach((s) ->
// 本不想代码耦合度太高,无奈之举
Arrays.asList(clazzNames).stream().skip(1).forEach((s) ->{
if(upperCaseClassNameList.contains(s)){
// 下划线分隔,字母全部大写
prefix.append(camelToUnderLine(s).substring(1).toUpperCase())
.append(".");
}else if(splitUnderLineClassNameList.contains(s)){
// 下划线分隔,字母全部小写
prefix.append(camelToUnderLine(s).substring(1))
.append(".");
}else{
prefix.append(Character.toLowerCase(s.charAt(0)))
.append(s.substring(1))
.append("."));
.append(".");
}
});
String pName = prefix.toString() + field.getName();
// 如果该属性完整的限定名包含CollectionName,那么则替换
if(collectionName != null){
... ... @@ -192,4 +280,21 @@ public class MetaConfigServiceImpl implements IMetaConfigService, ApplicationCon
}
}
}
/**
* 驼峰转下划线
* @param str
* @return
*/
public static String camelToUnderLine(String str) {
Pattern humpPattern = Pattern.compile("[A-Z]");
Matcher matcher = humpPattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
}
matcher.appendTail(sb);
return sb.toString();
}
}
... ...
... ... @@ -19,10 +19,10 @@
<hr style="border:1px solid #ddd;"><br>
<div style="border:1px solid #ddd;border-radius:5px 5px 5px 5px;">
<div style="margin-left: 10px;margin-top: 20px;margin-bottom: 20px">
<label>订单编号:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<label>编号:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<input id="code" type="text" class="easyui-textbox" style="width:150px">
<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标题</label>
<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名称</label>
<input id="title" type="text" class="easyui-textbox" style="width:150px"/>
<a id="searchBtn" class="btn-info">查询</a>
<a id="allBtn" class="btn-success">全部</a>
... ... @@ -38,8 +38,11 @@
<script>
var code;
var keyValueMap = {};
// 值是比例(0~1四位小数)的键
var keyScaleList =[];
// 值是整数的键
var keyIntList =[];
// 值是浮点型的键
var keyDoubleList =[];
$(function() {
... ... @@ -48,7 +51,7 @@
onClick : function() {
$("#configListTable").datagrid("load", {
code : $("#code").val(),
uid : $("#title").val(),
title : $("#title").val(),
});
}
});
... ... @@ -58,16 +61,16 @@
iconCls: "icon-import",
onClick: function () {
$("#code").textbox('setValue','');
$("#uid").textbox('setValue','');
$("#title").textbox('setValue','');
$("#configListTable").datagrid("load", {
});
}
});
getOrderList();
getConfigList();
});
function getOrderList(){
function getConfigList(){
$("#configListTable").myDatagrid({
fit: true,
fitColumns: true,
... ... @@ -93,15 +96,10 @@
align: "center",
width: 40
}, {
title: "修改时间",
field: "uid",
align: "center",
width: 40
}, {
title: "创建时间",
field: "productName",
field: "createTimeStr",
align: "center",
width: 40
width: 40,
}, {
title: "操作",
field: "operations",
... ... @@ -153,54 +151,13 @@
handler: function () {
$.messager.confirm("确认", message, function (flag) {
if (flag) {
var a = toJSON();
delete a.id;
delete a.code;
delete a.title;
delete a.desc;
delete a.value;
$("#metaConfigEditForm #value").val(JSON.stringify(a));
var url = contextPath + "/metaConfig/update";
/*var code = $('#metaConfigEditForm #code').val();
if (code == '' || code == null || code == undefined) {
$.messager.alert("提示", '编码不能为空!', "error");
return false;
}
var title = $('#metaConfigEditForm #title').val();
if (title == '' || title == null || title == undefined) {
$.messager.alert("提示", '标题不能为空!', "error");
return false;
}
for(key in keyValueMap){
var val = $("#metaConfigEditForm [name = '"+key+"']").val();
if (val == '' || val == null || val == undefined) {
$.messager.alert("提示", keyValueMap[key] + '不能为空!', "error");
return false;
}
}*/
/*for(key in keyValueMap){
var val = $("#metaConfigEditForm [name = '"+key+"']").val();
if (val == '' || val == null || val == undefined) {
$.messager.alert("提示", keyValueMap[key] + '不能为空!', "error");
return false;
}
}*/
//debugger;
// 校验整数
if(keyIntList.length > 0){
for(var i=0; i< keyIntList.length; i++){
var val = $("#metaConfigEditForm [name = '"+keyIntList[i]+"']").val();
var reg = /^\d+$ /;
var reg = /^\d+$/;
if(!reg.test(val)){
$.messager.alert("提示", keyValueMap[keyIntList[i]] + '字段必须为非负整数!', "error");
return false;
... ... @@ -208,30 +165,39 @@
}
}
// 校验比例(0~1两位四位小数)
if(keyScaleList.length > 0){
for(var i=0; i< keyScaleList.length; i++){
var val = $("#metaConfigEditForm [name = '"+keyScaleList[i]+"']").val();
var reg = /^(0(.\d{1,2})?)|(1(.0{1,2})?)$/;
var reg = /^(0(.\d{1,4})?)$|^(1(.0{1,2})?)$/;
if(!reg.test(val)){
$.messager.alert("提示", keyValueMap[keyIntList[i]] + '字段必须为0~1之间的两位小数!', "error");
$.messager.alert("提示", keyValueMap[keyScaleList[i]] + '字段必须为0~1之间的小数(最多保留四位)!', "error");
return false;
}
}
}
// 校验浮点数
if(keyDoubleList.length > 0){
for(var i=0; i< keyDoubleList.length; i++){
var reg = /^[0-9]+(.[0-9]{2})?$/;
var reg = /^[0-9]+(.[0-9]{1,4})?$/;
var val = $("#metaConfigEditForm [name = '"+keyDoubleList[i]+"']").val();
if(!reg.test(val)){
$.messager.alert("提示", keyValueMap[keyIntList[i]] + '字段必须为数字(保留两位小数)!', "error");
$.messager.alert("提示", keyValueMap[keyDoubleList[i]] + '字段必须为数字(最多保留四位小数)!', "error");
return false;
}
}
}
//把form转化成json
var a = toJSON();
delete a.id;
delete a.code;
delete a.title;
delete a.desc;
delete a.value;
$("#metaConfigEditForm #value").val(JSON.stringify(a));
$("#metaConfigEditForm").form("submit", {
url: url,
onSubmit: function () {
... ...