PRUDUCT_ORDER_LIST = Arrays.asList("1","2","3","4");
+ String MSG_GET_GROUP_GOODS_NULL = "查询当前类别的商品列表为空";
+ String MSG_PARAM_INVALID = "非法的请求参数";
- /**
- * 轮播图相关
- */
- Integer CAROUSE_COMMON_FAIL_4201 = 4201;
- String GET_ALL_CAROUSE_NULL = "查询的轮播图列表为空";
/**
- * 数据库增删改操作pattern
+ * 轮播图相关
*/
- //pattern
- String OPREARTION_METHOD_PATTERN = "操作类型:{0};操作结果:成功;操作类名:{1};操作方法:{2};传入参数:{3}";
- String OPREARTION_METHOD_INSERT = "新增";
- String OPREARTION_METHOD_DELETE = "删除";
- String OPREARTION_METHOD_UPDATE = "更新";
- String OPREARTION_METHOD_QUERY = "查询";
+ String MSG_GET_CAROUSE_NULL = "查询的轮播图列表为空";
}
diff --git a/src/main/java/com/hxtec/polaris/commons/utils/GenerateSequenceUtil.java b/src/main/java/com/hxtec/polaris/commons/utils/GenerateSequenceUtil.java
new file mode 100644
index 0000000..ff15dab
--- /dev/null
+++ b/src/main/java/com/hxtec/polaris/commons/utils/GenerateSequenceUtil.java
@@ -0,0 +1,49 @@
+package com.hxtec.polaris.commons.utils;
+
+import java.text.DecimalFormat;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+/**
+ * @Author yonyong
+ * @Description 根据时间生成唯一序列ID
+ * 时间精确到秒,ID最大值为99999且循环使用
+ * @Date 2019/11/19 17:16
+ * @Param
+ * @return
+ **/
+public class GenerateSequenceUtil {
+
+ private static final FieldPosition HELPER_POSITION = new FieldPosition(0);
+
+ /** 时间:精确到秒 */
+ private final static Format dateFormat = new SimpleDateFormat("YYYYMMddHHmmss");
+
+ private final static NumberFormat numberFormat = new DecimalFormat("00000");
+
+ private static int seq = 0;
+
+ private static final int MAX = 99999;
+
+ public static synchronized String generateSequenceNo() {
+
+ Calendar rightNow = Calendar.getInstance();
+
+ StringBuffer sb = new StringBuffer();
+
+ dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION);
+
+ numberFormat.format(seq, sb, HELPER_POSITION);
+
+ if (seq == MAX) {
+ seq = 0;
+ } else {
+ seq++;
+ }
+
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/hxtec/polaris/service/impl/CarouseServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/CarouseServiceImpl.java
index 055f3c4..223950f 100644
--- a/src/main/java/com/hxtec/polaris/service/impl/CarouseServiceImpl.java
+++ b/src/main/java/com/hxtec/polaris/service/impl/CarouseServiceImpl.java
@@ -31,7 +31,7 @@ public class CarouseServiceImpl implements CarouseService{
if (null != list && list.size()>0){
return Result.ok(list);
}else {
- throw new MyException(Result.error(CommonConstant.CAROUSE_COMMON_FAIL_4201,CommonConstant.GET_ALL_CAROUSE_NULL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4201,CommonConstant.MSG_GET_CAROUSE_NULL));
}
}
}
diff --git a/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java
index d7be232..4b5c10c 100644
--- a/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java
+++ b/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java
@@ -5,6 +5,7 @@ import com.hxtec.polaris.commons.api.vo.Result;
import com.hxtec.polaris.commons.constant.CommonConstant;
import com.hxtec.polaris.commons.exception.MyException;
import com.hxtec.polaris.commons.thread.BuildPathRunable;
+import com.hxtec.polaris.commons.utils.GenerateSequenceUtil;
import com.hxtec.polaris.entity.ShopCategory;
import com.hxtec.polaris.mapper.ShopCategoryMapper;
import com.hxtec.polaris.service.CategoryService;
@@ -34,10 +35,10 @@ import java.util.concurrent.ThreadFactory;
public class CategoryServiceImpl implements CategoryService {
private final static Logger logger = LoggerFactory.getLogger(CategoryServiceImpl.class);
- private static String CLASS_NAME = "CategoryServiceImpl";
- private static String METHOD_ADD_CATORY = "addCategory";
- private static String METHOD_DEL_CATORY = "deleteCategory";
- private static String METHOD_UPDATE_CATORY ="updateCategory";
+ private final static String LOG_CLASS_NAME = "CategoryServiceImpl";
+ private final static String LOG_METHOD_ADD_CATORY = "addCategory";
+ private final static String LOG_METHOD_DEL_CATORY = "deleteCategory";
+ private final static String LOG_METHOD_UPDATE_CATORY ="updateCategory";
@Resource
private ShopCategoryMapper shopCategoryMapper;
@@ -50,7 +51,7 @@ public class CategoryServiceImpl implements CategoryService {
return Result.ok(list);
}else {
//查询失败或查询到的数据为空
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_BUILD_TREE_SELECT_NO));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_SELECT_NO));
}
}
@@ -58,28 +59,29 @@ public class CategoryServiceImpl implements CategoryService {
public Object addCategory(String pid, String name) {
//请求参数不合法
if (!StringUtils.isNumeric(pid)){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.PARAM_FORMAT_INVALID));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_PARAM_INVALID));
}
//判断数据库中是否有该父节点
ShopCategory parentObject = shopCategoryMapper.selectByPrimaryKey(pid);
if (null == parentObject){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_PARENT_NODE_NO));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_PNODE_NO));
}
//实例赋值
ShopCategory shopCategory = setParam(pid,name);
-
+ //生成id
+ shopCategory.setId(GenerateSequenceUtil.generateSequenceNo());
//数据新增入库
int insertResult = 0;
try {
insertResult = shopCategoryMapper.insertCategory(shopCategory);
}catch (Exception e){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_INSERT_EXCEPTION));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_INSERT_EXCEPTION));
}
if (insertResult != 1){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_INSERT_FAIL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_INSERT_FAIL));
}
//构建分类路径
- StringBuilder path = new StringBuilder(CommonConstant.CATEGORY_PATH_SEPARATOR + shopCategory.getId());
+ StringBuilder path = new StringBuilder(CommonConstant.CHARACTOR_SEPARATOR + shopCategory.getId());
path.append(parentObject.getComment1());
shopCategory.setComment1(String.valueOf(path));
//更新路径
@@ -87,67 +89,67 @@ public class CategoryServiceImpl implements CategoryService {
try{
updateResult = shopCategoryMapper.updateCategoryDynamic(shopCategory);
}catch (Exception e){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_UPDATE_EXCEPTION));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_UPDATE_EXCEPTION));
}
if (updateResult < 0){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_UPDATE_FAIL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_UPDATE_FAIL));
}
String params = "pid="+pid+",name="+name;
- logger.info(MessageFormat.format(CommonConstant.OPREARTION_METHOD_PATTERN,CommonConstant.OPREARTION_METHOD_INSERT,
- CLASS_NAME,METHOD_ADD_CATORY,params));
- return Result.ok(CommonConstant.CATEGORY_INSERT_OK);
+ logger.info(MessageFormat.format(CommonConstant.LOG_PATTERN,CommonConstant.LOG_TYPE_INSERT,
+ LOG_CLASS_NAME,LOG_METHOD_ADD_CATORY,params));
+ return Result.ok(CommonConstant.MSG_CATEGORY_INSERT_OK);
}
@Override
public Object deleteCategory(List ids) {
//参数为空
if (null == ids || ids.size() == 0){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_DELETE_PARAM_NO));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_DELETE_NO));
}
for (String id : ids){
//参数不合法
if (!StringUtils.isNumeric(id)){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.PARAM_FORMAT_INVALID));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_PARAM_INVALID));
}
//更新shop_category表
int deletCategoryResult = 0;
try{
deletCategoryResult = shopCategoryMapper.deleteCategory(id);
}catch (Exception e){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_DELETE_EXCEPTION));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_DELETE_EXCEPTION));
}
if (deletCategoryResult < 0){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_DELETE_FAIL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_DELETE_FAIL));
}
}
String params = "ids="+ids;
- logger.info(MessageFormat.format(CommonConstant.OPREARTION_METHOD_PATTERN,CommonConstant.OPREARTION_METHOD_DELETE,
- CLASS_NAME,METHOD_DEL_CATORY,params));
- return Result.ok(CommonConstant.CATEGORY_DELETE_OK);
+ logger.info(MessageFormat.format(CommonConstant.LOG_PATTERN,CommonConstant.LOG_TYPE_DELETE,
+ LOG_CLASS_NAME, LOG_METHOD_DEL_CATORY,params));
+ return Result.ok(CommonConstant.MSG_CATEGORY_DELETE_OK);
}
@Override
public Object updateCategory(HttpServletRequest request,String pid, String id, String name) {
if (!StringUtils.isNumeric(pid) || !StringUtils.isNumeric(id) || StringUtils.isBlank(name)){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.PARAM_FORMAT_INVALID));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_PARAM_INVALID));
}
List tempList = shopCategoryMapper.getCategoryById(pid);
- if (null == tempList || tempList.size() ==0 || StringUtils.isBlank(tempList.get(0).getIsDelete()) || !CommonConstant.CATEGORY_IS_DELETE_NO.equals(tempList.get(0).getIsDelete())){
+ if (null == tempList || tempList.size() ==0 || StringUtils.isBlank(tempList.get(0).getIsDelete()) || !CommonConstant.CHARACTOR_NO.equals(tempList.get(0).getIsDelete())){
//如果该父节点对应的分类在数据库中没有记录或者删除状态是空或者已删除,则为故障节点,不能进行更新
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_UPDATE_PID_EXCEPTION));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_PID_EXCEPTION));
}
//执行更新操作
try {
doUpdateShopCategory(request,pid,id,name);
}catch (Exception e){
- throw new MyException(Result.error(CommonConstant.CATEGORY_COMMON_FAIL_4101,CommonConstant.CATEGORY_UPDATE_FAIL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4101,CommonConstant.MSG_CATEGORY_UPDATE_FAIL));
}
String params = "pid="+pid+",id="+id+",name="+name;
- logger.info(MessageFormat.format(CommonConstant.OPREARTION_METHOD_PATTERN,CommonConstant.OPREARTION_METHOD_UPDATE,
- CLASS_NAME,METHOD_UPDATE_CATORY,params));
- return Result.ok();
+ logger.info(MessageFormat.format(CommonConstant.LOG_PATTERN,CommonConstant.LOG_TYPE_UPDATE,
+ LOG_CLASS_NAME,LOG_METHOD_UPDATE_CATORY,params));
+ return Result.ok(CommonConstant.MSG_CATEGORY_UPDATE_OK);
}
/**
@@ -159,9 +161,9 @@ public class CategoryServiceImpl implements CategoryService {
private ShopCategory setParam(String pid, String name){
ShopCategory shopCategory = new ShopCategory();
shopCategory.setParentId(pid);
- shopCategory.setIsParent(CommonConstant.CATEGORY_IS_PARENT_NO);
+ shopCategory.setIsParent(CommonConstant.CHARACTOR_NO);
shopCategory.setName(name);
- shopCategory.setIsDelete(CommonConstant.CATEGORY_IS_DELETE_NO);
+ shopCategory.setIsDelete(CommonConstant.CHARACTOR_NO);
shopCategory.setCreateTime(new Date());
shopCategory.setUpdateTime(new Date());
return shopCategory;
@@ -197,7 +199,7 @@ public class CategoryServiceImpl implements CategoryService {
//调用线程,更新path
//把当前编辑的节点及其所有子节点挂到新的节点下面,更新路径
// 创建线程池
- ThreadFactory pool = new ThreadFactoryBuilder().setNameFormat(CommonConstant.CATEGORY_BUILD_PATH_NAME).build();
+ ThreadFactory pool = new ThreadFactoryBuilder().setNameFormat(CommonConstant.THREAD_CATEGORY_BUILD_PATH).build();
ServletContext context = request.getServletContext();
// 计数器
CountDownLatch doneSignal = new CountDownLatch(1);
diff --git a/src/main/java/com/hxtec/polaris/service/impl/GoodServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/GoodServiceImpl.java
index bb69428..0e6beb0 100644
--- a/src/main/java/com/hxtec/polaris/service/impl/GoodServiceImpl.java
+++ b/src/main/java/com/hxtec/polaris/service/impl/GoodServiceImpl.java
@@ -26,8 +26,8 @@ import java.util.Map;
@Service
@Transactional
public class GoodServiceImpl implements GoodService{
- private static final String TARGET_GROUP_NAME = "getTargrtGroupGoods";
- private static final String GUESS_LIKE_NAME = "getGuessLikeGoods";
+ private static final String METHOD_TARGET_GROUP_NAME = "getTargrtGroupGoods";
+ private static final String METHOD_GUESS_LIKE_NAME = "getGuessLikeGoods";
@Resource
private ShopProductBaseMapper shopProductBaseMapper;
@@ -41,7 +41,7 @@ public class GoodServiceImpl implements GoodService{
return Result.ok(mapList);
}else {
//查询失败或查询到的数据为空
- throw new MyException(Result.error(CommonConstant.GOODS_COMMON_FAIL_4201,CommonConstant.GET_ALL_GOODS_NULL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4301,CommonConstant.MSG_GET_ALL_GOODS_NULL));
}
}
@@ -49,7 +49,7 @@ public class GoodServiceImpl implements GoodService{
public Object getGuessLikeGoods(String page, String rows,String order) {
//如果是非法的请求
if (!ifParamsValid(page,rows,null,order)){
- throw new MyException(Result.error(CommonConstant.GOODS_COMMON_FAIL_4201,CommonConstant.PARAM_FORMAT_INVALID));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4301,CommonConstant.MSG_PARAM_INVALID));
}
Integer start = getFormatInt(page,rows,true);
Integer size = getFormatInt(page,rows,false);
@@ -58,7 +58,7 @@ public class GoodServiceImpl implements GoodService{
return Result.ok(mapList);
}else {
//查询失败或查询到的数据为空
- throw new MyException(Result.error(CommonConstant.GOODS_COMMON_FAIL_4201,CommonConstant.GET_GUESS_LIKE_GOODS_NULL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4301,CommonConstant.MSG_GET_GUESS_LIKE_GOODS_NULL));
}
}
@@ -71,7 +71,7 @@ public class GoodServiceImpl implements GoodService{
return Result.ok(mapList);
}else {
//查询失败或查询到的数据为空
- throw new MyException(Result.error(CommonConstant.GOODS_COMMON_FAIL_4201,CommonConstant.GET_CLASSFIED_SELECTED_GOODS_NULL));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4301,CommonConstant.MSG_GET_CLASSFIED_SELECTED_GOODS_NULL));
}
}
@@ -79,7 +79,7 @@ public class GoodServiceImpl implements GoodService{
public Object getTargrtGroupGoods(String page, String rows,String cid,String order) {
//如果是非法的请求
if (!ifParamsValid(page,rows,cid,order)){
- throw new MyException(Result.error(CommonConstant.GOODS_COMMON_FAIL_4201,CommonConstant.PARAM_FORMAT_INVALID));
+ throw new MyException(Result.error(CommonConstant.CODE_FAIL_4301,CommonConstant.MSG_PARAM_INVALID));
}
Integer start = (Integer.valueOf(page)-1)*Integer.valueOf(rows);
List