Commit 86a59c3e by guojuxing

门店分组

parent e376c7d7
......@@ -26,6 +26,15 @@ public class StoreGroupConstant {
*/
public final static int SORT_DOWN = 2;
/**
* 是否是默认门店,初始化品牌的时候会建立一条默认门店:未分组门店,不可编辑,1:是 0:否
*/
public final static int IS_DEFAULT = 1;
public final static int TEST_ENTERPRISE_ID = 10000;
......
......@@ -9,7 +9,9 @@ public enum StoreGroupErrorEnum {
DeleteError("1000", "该分组下存在门店,不能删除"),
GroupLevelError("2000", "分组层级参数数据错误"),
AllStoreGroupError("3000", "所有门店已存在"),
ParentStoreGroupParamError("4000", "父级ID参数错误");
ParentStoreGroupParamError("4000", "父级ID参数错误"),
EditDefaultStoreGroupError("5000", "默认分组:未分组门店,不可编辑"),
StoreGroupNotExist("6000", "门店分组主键错误,数据未查到");
private String code;
private String message;
......
......@@ -45,4 +45,11 @@ public interface StoreGroupApiService {
* @return
*/
int remove(int storeGroupId);
/**
* 初始化品牌调用:新建所有门店
* @param enterpriseId
* @return
*/
int insertDefaultStoreGroup(int enterpriseId);
}
......@@ -106,12 +106,12 @@ public interface TabStoreGroupMapper {
* @param groupLevel
* @return
*/
TabStoreGroup selectAllStoreGroup(Integer enterpriseId, Integer groupLevel);
TabStoreGroup selectAllStoreGroup(@Param("enterpriseId") Integer enterpriseId, @Param("groupLevel") Integer groupLevel);
/**
* 根据父级ID,统计下面是否有子节点
* @param parentId
* @return
*/
int countByParentId(Integer parentId);
int countByParentId(@Param("parentId") Integer parentId);
}
\ No newline at end of file
......@@ -80,6 +80,7 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
noStoreGroup.setEnterpriseId(storeGroupDTO.getEnterpriseId());
noStoreGroup.setGroupLevel(StoreGroupConstant.FIRST_STORE_GROUP_LEVEL);
noStoreGroup.setStoreGroupName("未分组门店");
noStoreGroup.setIsDefault(1);
save(noStoreGroup);
}
return storeGroupId;
......@@ -87,14 +88,21 @@ 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());
}
if (storeGroupDTO.getGroupLevel() != StoreGroupConstant.FIRST_STORE_GROUP_LEVEL) {
//如果不是第一级,则可能有上级分组修改
if (storeGroupDTO.getParentStoreGroupId() == null) {
throw new StoreGroupException(StoreGroupErrorEnum.ParentStoreGroupParamError.getCode(), StoreGroupErrorEnum.ParentStoreGroupParamError.getMessage());
}
int storeGroupParentId = storeGroupDTO.getParentStoreGroupId();
int storeGroupId = storeGroupDTO.getStoreGroupId();
TabStoreGroup oldStoreGroup = tabStoreGroupMapper.selectByPrimaryKey(storeGroupId);
int oldStoreGroupParentId = oldStoreGroup.getParentStoreGroupId();
boolean hasEditParentId = storeGroupParentId != oldStoreGroupParentId;
if (hasEditParentId) {
......@@ -160,7 +168,9 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
tabStoreGroupList.addAll(listStoreGroupByLevelAndName(storeGroupDTO.getGroupLevel(), storeGroupDTO.getEnterpriseId(), storeGroupDTO.getStoreGroupName()));
} else {
//查询全部
tabStoreGroupList.addAll(tabStoreGroupMapper.listStoreGroup(new TabStoreGroup()));
TabStoreGroup selectAll = new TabStoreGroup();
selectAll.setEnterpriseId(storeGroupDTO.getEnterpriseId());
tabStoreGroupList.addAll(tabStoreGroupMapper.listStoreGroup(selectAll));
}
return EntityUtil.changeEntityListNew(StoreGroupDTO.class, tabStoreGroupList);
......@@ -176,6 +186,16 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
return tabStoreGroupMapper.updateByPrimaryKeySelective(tabStoreGroup);
}
@Override
public int insertDefaultStoreGroup(int enterpriseId) {
StoreGroupDTO noStoreGroup = new StoreGroupDTO();
noStoreGroup.setEnterpriseId(enterpriseId);
noStoreGroup.setGroupLevel(StoreGroupConstant.ALL_STORE_LEVEL);
noStoreGroup.setStoreGroupName("所有门店");
noStoreGroup.setIsDefault(StoreGroupConstant.IS_DEFAULT);
return save(noStoreGroup);
}
private int selectStoreGroupMaxSort(Integer enterpriseId, Integer groupLevel) {
return tabStoreGroupMapper.selectStoreGroupMaxSort(enterpriseId, groupLevel);
}
......
......@@ -180,9 +180,9 @@
</select>
<select id="selectStoreGroupMaxSort" resultMap="BaseResultMap">
<select id="selectStoreGroupMaxSort" resultType="int">
select
ifnull(max(sort), 0)
IFNULL(MAX(sort), 0)
from
tab_store_group where status = 1 and enterprise_id = #{enterpriseId} and group_level = #{groupLevel}
</select>
......@@ -222,7 +222,7 @@
limit 1
</select>
<select id="countByParentId" resultMap="BaseResultMap">
<select id="countByParentId" resultType="int">
select
count(1)
from
......
......@@ -29,37 +29,29 @@ public class StoreGroupController {
private static final Logger logger = LoggerFactory.getLogger(StoreGroupController.class);
private static final int ENTERPRISE_ID = 10000;
@Autowired
private StoreGroupApiService storeGroupApiService;
@RequestMapping("/list")
public RestResponse listStoreGroup(StoreGroupQO storeGroupQO) {
StoreGroupDTO storeGroupDTO = EntityUtil.changeEntityNew(StoreGroupDTO.class, storeGroupQO);
List<StoreGroupDTO> list = storeGroupApiService.listStoreGroup(storeGroupDTO);
List<StoreGroupDTO> list = storeGroupApiService.listStoreGroup(transferQoToDTO(storeGroupQO));
return RestResponse.success(changeListToTree(StoreGroupConstant.ALL_STORE_LEVEL, list));
}
@RequestMapping("/save")
public RestResponse save(@Validated({StoreGroupQO.SaveValidView.class}) StoreGroupQO storeGroupQO) {
StoreGroupDTO storeGroupDTO = EntityUtil.changeEntityNew(StoreGroupDTO.class, storeGroupQO);
storeGroupDTO.setEnterpriseId(ENTERPRISE_ID);
return RestResponse.success(storeGroupApiService.save(storeGroupDTO));
storeGroupQO.setIsDefault(0);
return RestResponse.success(storeGroupApiService.save(transferQoToDTO(storeGroupQO)));
}
@RequestMapping("/edit")
public RestResponse edit(@Validated({StoreGroupQO.SaveValidView.class}) StoreGroupQO storeGroupQO) {
StoreGroupDTO storeGroupDTO = EntityUtil.changeEntityNew(StoreGroupDTO.class, storeGroupQO);
storeGroupDTO.setEnterpriseId(ENTERPRISE_ID);
return RestResponse.success(storeGroupApiService.update(storeGroupDTO));
public RestResponse edit(@Validated({StoreGroupQO.SaveValidView.class, StoreGroupQO.RemoveValidView.class}) StoreGroupQO storeGroupQO) {
return RestResponse.success(storeGroupApiService.update(transferQoToDTO(storeGroupQO)));
}
@RequestMapping("/sort")
public RestResponse sort(@Validated({StoreGroupQO.SortValidView.class}) StoreGroupQO storeGroupQO) {
StoreGroupDTO storeGroupDTO = EntityUtil.changeEntityNew(StoreGroupDTO.class, storeGroupQO);
storeGroupDTO.setEnterpriseId(ENTERPRISE_ID);
return RestResponse.success(storeGroupApiService.sort(storeGroupDTO, storeGroupQO.isUp()));
return RestResponse.success(storeGroupApiService.sort(transferQoToDTO(storeGroupQO), storeGroupQO.isUp()));
}
@RequestMapping("/remove")
......@@ -87,4 +79,10 @@ public class StoreGroupController {
}
return result;
}
private StoreGroupDTO transferQoToDTO(StoreGroupQO storeGroupQO) {
StoreGroupDTO storeGroupDTO = EntityUtil.changeEntityNew(StoreGroupDTO.class, storeGroupQO);
storeGroupDTO.setEnterpriseId(StoreGroupConstant.TEST_ENTERPRISE_ID);
return storeGroupDTO;
}
}
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