Commit 373d4388 by guojuxing

门店分组

parent 86a59c3e
......@@ -11,7 +11,8 @@ public enum StoreGroupErrorEnum {
AllStoreGroupError("3000", "所有门店已存在"),
ParentStoreGroupParamError("4000", "父级ID参数错误"),
EditDefaultStoreGroupError("5000", "默认分组:未分组门店,不可编辑"),
StoreGroupNotExist("6000", "门店分组主键错误,数据未查到");
StoreGroupNotExist("6000", "门店分组主键错误,数据未查到"),
SortError("7000", "排序错误!");
private String code;
private String message;
......
......@@ -45,8 +45,7 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
throw new StoreGroupException(StoreGroupErrorEnum.AllStoreGroupError.getCode(), StoreGroupErrorEnum.AllStoreGroupError.getMessage());
}
storeGroupDTO.setParentStoreGroupId(StoreGroupConstant.ALL_STORE_LEVEL);
}
if (groupLevel == StoreGroupConstant.FIRST_STORE_GROUP_LEVEL) {
} else if (groupLevel == StoreGroupConstant.FIRST_STORE_GROUP_LEVEL) {
//如果是第一级,则父级ID取所有门店,所有门店在初始化品牌的时候创建
TabStoreGroup allStoreGroup = tabStoreGroupMapper.selectAllStoreGroup(storeGroupDTO.getEnterpriseId(), StoreGroupConstant.ALL_STORE_LEVEL);
storeGroupDTO.setParentStoreGroupId(allStoreGroup.getStoreGroupId());
......@@ -54,11 +53,15 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
if (storeGroupDTO.getParentStoreGroupId() == null) {
throw new StoreGroupException(StoreGroupErrorEnum.ParentStoreGroupParamError.getCode(), StoreGroupErrorEnum.ParentStoreGroupParamError.getMessage());
}
validIsDefault(storeGroupDTO.getParentStoreGroupId());
}
storeGroupDTO.setCreateTime(new Date());
storeGroupDTO.setUpdateTime(new Date());
storeGroupDTO.setStatus(1);
if (storeGroupDTO.getIsDefault() == null) {
storeGroupDTO.setIsDefault(0);
}
//排序值
storeGroupDTO.setSort(selectStoreGroupMaxSort(storeGroupDTO.getEnterpriseId(), storeGroupDTO.getGroupLevel()) + 1);
int storeGroupId = tabStoreGroupMapper.insert(EntityUtil.changeEntityNew(TabStoreGroup.class, storeGroupDTO));
......@@ -89,14 +92,7 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
@Override
public int update(StoreGroupDTO storeGroupDTO) {
int storeGroupId = storeGroupDTO.getStoreGroupId();
TabStoreGroup oldStoreGroup = tabStoreGroupMapper.selectByPrimaryKey(storeGroupId);
if (oldStoreGroup == null) {
throw new StoreGroupException(StoreGroupErrorEnum.StoreGroupNotExist.getCode(), StoreGroupErrorEnum.StoreGroupNotExist.getMessage());
}
boolean isDefault = oldStoreGroup.getIsDefault() == StoreGroupConstant.IS_DEFAULT;
if (isDefault) {
throw new StoreGroupException(StoreGroupErrorEnum.EditDefaultStoreGroupError.getCode(), StoreGroupErrorEnum.EditDefaultStoreGroupError.getMessage());
}
TabStoreGroup oldStoreGroup = validIsDefault(storeGroupId);
if (storeGroupDTO.getGroupLevel() != StoreGroupConstant.FIRST_STORE_GROUP_LEVEL) {
//如果不是第一级,则可能有上级分组修改
if (storeGroupDTO.getParentStoreGroupId() == null) {
......@@ -140,8 +136,14 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
TabStoreGroup needUpdateSortStoreGroup;
if (isUp) {
needUpdateSortStoreGroup = tabStoreGroupMapper.getStoreGroupWhenMaxSort(enterpriseId, groupLevel, sort);
if (needUpdateSortStoreGroup == null) {
throw new StoreGroupException(StoreGroupErrorEnum.SortError.getCode(), "已经是第一条,不能上移");
}
} else {
needUpdateSortStoreGroup = tabStoreGroupMapper.getStoreGroupWhenMinSort(enterpriseId, groupLevel, sort);
if (needUpdateSortStoreGroup == null) {
throw new StoreGroupException(StoreGroupErrorEnum.SortError.getCode(), "已经是最后一条,不能下移");
}
}
updateSort(needUpdateSortStoreGroup.getStoreGroupId(), sort);
updateSort(storeGroupDTO.getStoreGroupId(), needUpdateSortStoreGroup.getSort());
......@@ -271,4 +273,20 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
List<TabStoreGroup> tabStoreGroupList = tabStoreGroupMapper.listStoreGroup(param);
return tabStoreGroupList;
}
/**
* 如果是默认门店,不可编辑
* @param storeGroupId
*/
private TabStoreGroup validIsDefault(int storeGroupId) {
TabStoreGroup storeGroup = tabStoreGroupMapper.selectByPrimaryKey(storeGroupId);
if (storeGroup == null) {
throw new StoreGroupException(StoreGroupErrorEnum.StoreGroupNotExist.getCode(), StoreGroupErrorEnum.StoreGroupNotExist.getMessage());
}
boolean isDefault = storeGroup.getIsDefault() == StoreGroupConstant.IS_DEFAULT;
if (isDefault) {
throw new StoreGroupException(StoreGroupErrorEnum.EditDefaultStoreGroupError.getCode(), StoreGroupErrorEnum.EditDefaultStoreGroupError.getMessage());
}
return storeGroup;
}
}
......@@ -199,7 +199,7 @@
select
<include refid="Base_Column_List" />
from
tab_store_group where status = 1 and enterprise_id = #{enterpriseId} and group_level = #{groupLevel} and sort > #{sort}
tab_store_group where status = 1 and enterprise_id = #{enterpriseId} and group_level = #{groupLevel} and sort > #{sort} and is_default = 0
order by sort
limit 1
</select>
......@@ -209,7 +209,7 @@
select
<include refid="Base_Column_List" />
from
tab_store_group where status = 1 and enterprise_id = #{enterpriseId} and group_level = #{groupLevel} and sort &lt; #{sort}
tab_store_group where status = 1 and enterprise_id = #{enterpriseId} and group_level = #{groupLevel} and sort &lt; #{sort} and is_default = 0
order by sort desc
limit 1
</select>
......
......@@ -40,7 +40,6 @@ public class StoreGroupController {
@RequestMapping("/save")
public RestResponse save(@Validated({StoreGroupQO.SaveValidView.class}) StoreGroupQO storeGroupQO) {
storeGroupQO.setIsDefault(0);
return RestResponse.success(storeGroupApiService.save(transferQoToDTO(storeGroupQO)));
}
......
......@@ -28,13 +28,13 @@ public class StoreGroupQO implements Serializable{
*
*
*/
@NotNull(message = "门店分组ID不能为空", groups = {RemoveValidView.class})
@NotNull(message = "门店分组ID不能为空", groups = {RemoveValidView.class, SortValidView.class})
private Integer storeGroupId;
/**
* 分组名称
*/
@NotBlank(message = "名称不能为空", groups = {SaveValidView.class, SortValidView.class})
@NotBlank(message = "名称不能为空", groups = {SaveValidView.class})
private String storeGroupName;
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment