Commit 3159cce8 by guojuxing

根据名称和企业ID,查询分组数据

parent de636529
......@@ -15,4 +15,20 @@ public interface StoreGroupService {
* @return
*/
TabStoreGroup getStoreGroupByName(String storeGroupName, Integer enterpriseId);
/**
* 拖拽排序
* @param storeGroup
* @param toSortValue 要排序的值
*/
void dragSort(TabStoreGroup storeGroup, Integer toSortValue);
TabStoreGroup getStoreGroupById(Integer storeGroupId);
/**
* 更新排序值
* @param sort
* @param storeGroupId
*/
void updateSort(Integer sort, Integer storeGroupId);
}
......@@ -6,6 +6,8 @@ import com.gic.store.service.StoreGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author guojx
* @date 2019/7/3 2:18 PM
......@@ -19,4 +21,52 @@ public class StoreGroupServiceImpl implements StoreGroupService{
public TabStoreGroup getStoreGroupByName(String storeGroupName, Integer enterpriseId) {
return tabStoreGroupMapper.getStoreGroupByName(storeGroupName, enterpriseId);
}
@Override
public void dragSort(TabStoreGroup storeGroup, Integer toSortValue) {
Integer enterpriseId = storeGroup.getEnterpriseId();
Integer groupLevel = storeGroup.getGroupLevel();
Integer fromSortValue = storeGroup.getSort();
Integer storeGroupId = storeGroup.getStoreGroupId();
TabStoreGroup record = new TabStoreGroup();
record.setEnterpriseId(enterpriseId);
record.setGroupLevel(groupLevel);
List<TabStoreGroup> tabStoreGroupList = tabStoreGroupMapper.listStoreGroup(record);
if (fromSortValue > toSortValue) {
//如果是向上拖拽
for (int i = 0, length = tabStoreGroupList.size(); i < length; i ++) {
TabStoreGroup tabStoreGroup = tabStoreGroupList.get(i);
//如果大于setSortValue,都需要降低排序值,往后推
boolean isNeedDown = tabStoreGroup.getSort() >= toSortValue && tabStoreGroup.getSort() < fromSortValue;
if (isNeedDown) {
updateSort(tabStoreGroupList.get(i + 1).getSort(), tabStoreGroup.getStoreGroupId());
}
}
} else if (fromSortValue < toSortValue) {
//向下拖拽
for (int i = 0, length = tabStoreGroupList.size(); i < length; i ++) {
TabStoreGroup tabStoreGroup = tabStoreGroupList.get(i);
boolean isNeedUp = tabStoreGroup.getSort() <= toSortValue && tabStoreGroup.getSort() > fromSortValue;
if (isNeedUp) {
updateSort(tabStoreGroupList.get(i - 1).getSort(), tabStoreGroup.getStoreGroupId());
}
}
}
updateSort(toSortValue, storeGroupId);
}
@Override
public TabStoreGroup getStoreGroupById(Integer storeGroupId) {
return tabStoreGroupMapper.selectByPrimaryKey(storeGroupId);
}
@Override
public void updateSort(Integer sort, Integer storeGroupId) {
TabStoreGroup record = new TabStoreGroup();
record.setStoreGroupId(storeGroupId);
record.setSort(sort);
tabStoreGroupMapper.updateByPrimaryKeySelective(record);
}
}
......@@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -174,4 +175,16 @@ public class StoreFieldApiServiceImpl implements StoreFieldApiService{
storeFieldService.sortTopping(storeField.getEnterpriseId(), storeFieldId);
return ServiceResponse.success();
}
@Override
public ServiceResponse<List<StoreFieldDTO>> listStoreFieldByRegionId(Integer regionId) {
List<TabStoreField> tabStoreFieldList = storeFieldService.listStoreFieldByRegionId(regionId);
if (tabStoreFieldList == null) {
return ServiceResponse.success(new ArrayList<StoreFieldDTO>());
} else {
List<StoreFieldDTO> dtoList = EntityUtil.changeEntityListNew(StoreFieldDTO.class, tabStoreFieldList);
return ServiceResponse.success(dtoList);
}
}
}
package com.gic.store.service.outer;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.store.constant.StoreGroupConstant;
import com.gic.store.constant.StoreGroupErrorEnum;
......@@ -8,7 +9,9 @@ import com.gic.store.dto.StoreGroupDTO;
import com.gic.store.entity.TabStoreGroup;
import com.gic.store.exception.StoreGroupException;
import com.gic.store.service.StoreGroupApiService;
import com.gic.store.service.StoreGroupService;
import com.gic.store.service.StoreService;
import com.gic.store.utils.ErrorCode;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -36,6 +39,8 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
@Autowired
private StoreService storeService;
@Autowired
private StoreGroupService storeGroupService;
@Override
public int save(StoreGroupDTO storeGroupDTO) {
......@@ -249,6 +254,19 @@ public class StoreGroupApiServiceImpl implements StoreGroupApiService{
return save(noStoreGroup);
}
@Override
public ServiceResponse<Integer> dragSort(Integer storeGroupId, Integer setSortValue) {
TabStoreGroup tabStoreGroup = storeGroupService.getStoreGroupById(storeGroupId);
if (tabStoreGroup == null) {
return ServiceResponse.failure(ErrorCode.ERR_5.getCode(), "主键错误,查询不到数据");
}
if (setSortValue == null) {
return ServiceResponse.failure(ErrorCode.ERR_5.getCode(), "拖拽排序值不能为空过");
}
storeGroupService.dragSort(tabStoreGroup, setSortValue);
return ServiceResponse.success();
}
private int selectStoreGroupMaxSort(Integer enterpriseId, Integer groupLevel) {
return tabStoreGroupMapper.selectStoreGroupMaxSort(enterpriseId, groupLevel);
}
......
......@@ -281,9 +281,6 @@
<if test="regionId != null ">
and store_region_id like concat('%_', #{regionId}, '_%')
</if>
<if test="search != null and search != '' ">
and ( store_field_name like concat('%', #{search}, '%') or store_field_code like concat('%', #{search}, '%') )
</if>
order by sort
</select>
</mapper>
\ No newline at end of file
......@@ -19,6 +19,7 @@ import com.gic.store.web.qo.PageQO;
import com.gic.store.web.qo.storefield.StoreFieldQO;
import com.gic.store.web.qo.storefield.StoreFieldSelectQO;
import com.gic.store.web.vo.storefield.StoreFieldEditVO;
import com.gic.store.web.vo.storefield.StoreFieldRegionVO;
import com.gic.store.web.vo.storefield.StoreFieldVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -140,6 +141,19 @@ public class StoreFieldController {
}
}
@RequestMapping("/list-store-field-by-region-id")
public RestResponse listStoreFieldByRegionId(Integer regionId) {
if (regionId == null) {
RestResponse.failure(ErrorCode.ERR_5.getCode(), "域ID不能为空");
}
ServiceResponse<List<StoreFieldDTO>> result = storeFieldApiService.listStoreFieldByRegionId(regionId);
if (result.isSuccess()) {
return RestResponse.success(EntityUtil.changeEntityListNew(StoreFieldRegionVO.class, result.getResult()));
} else {
return RestResponse.failure(result.getCode(), result.getMessage());
}
}
@RequestMapping("/remove-store-field-batch")
public RestResponse removeStoreFieldBatch(boolean isDeleteAll, String storeFieldIds) {
if (isDeleteAll) {
......
package com.gic.store.web.controller;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.store.constant.StoreGroupConstant;
......@@ -53,6 +54,16 @@ public class StoreGroupController {
return RestResponse.success(storeGroupApiService.update(transferQoToDTO(storeGroupQO)));
}
@RequestMapping("/drag-sort")
public RestResponse dragSort(@Validated({StoreGroupQO.RemoveValidView.class, StoreGroupQO.SetSortValueValidView.class}) StoreGroupQO storeGroupQO) {
ServiceResponse result = storeGroupApiService.dragSort(storeGroupQO.getStoreGroupId(), storeGroupQO.getSortValue());
if (result.isSuccess()) {
return RestResponse.success();
} else {
return RestResponse.failure(result.getCode(), result.getMessage());
}
}
@RequestMapping("/sort")
public RestResponse sort(@Validated({StoreGroupQO.SortValidView.class}) StoreGroupQO storeGroupQO) {
return RestResponse.success(storeGroupApiService.sort(transferQoToDTO(storeGroupQO), storeGroupQO.isUp()));
......
......@@ -3,6 +3,7 @@ package com.gic.store.web.exception;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.store.constant.StoreGroupErrorEnum;
import com.gic.store.exception.StoreGroupException;
import com.gic.store.utils.ErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
......@@ -29,7 +30,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public RestResponse controllerException(HttpServletResponse response, Exception ex) {
logger.error("err", ex);
RestResponse failureResponse = getRestResponse(StoreGroupErrorEnum.Error.getCode(), StoreGroupErrorEnum.Error.getMessage());
RestResponse failureResponse = getRestResponse(ErrorCode.ERR_9999.getCode(), StoreGroupErrorEnum.Error.getMessage());
StringBuilder sb = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintWriter printWriter = new PrintWriter(baos)) {
......
......@@ -2,7 +2,10 @@ package com.gic.store.web.qo.storegroup;
import com.gic.store.constant.StoreGroupConstant;
import javax.validation.constraints.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
......@@ -29,6 +32,10 @@ public class StoreGroupQO implements Serializable{
public interface EditParentIdValidView {
}
public interface SetSortValueValidView {
}
......@@ -98,6 +105,12 @@ public class StoreGroupQO implements Serializable{
@Max(value = StoreGroupConstant.SORT_DOWN, message = "移动标志参数值错误,大于2", groups = {SortValidView.class})
private Integer upOrDown;
/**
* 想要排序的值
*/
@NotNull(message = "排序值不能为空", groups = {SetSortValueValidView.class})
private Integer sortValue;
private boolean isUp;
public Integer getStoreGroupId() {
......@@ -203,4 +216,12 @@ public class StoreGroupQO implements Serializable{
return false;
}
}
public Integer getSortValue() {
return sortValue;
}
public void setSortValue(Integer sortValue) {
this.sortValue = sortValue;
}
}
package com.gic.store.web.vo.storefield;
import java.io.Serializable;
/**
* @author guojx
* @date 2019/7/3 4:13 PM
*/
public class StoreFieldRegionVO implements Serializable{
private static final long serialVersionUID = -6082513310725549988L;
/**
*
*/
private Integer storeFieldId;
/**
* 属性名称
*/
private String storeFieldName;
/**
* 字段类型;1文本 2单选 3多选 4实数 5时间
*/
private Integer storeFieldType;
/**
* 字段详细配置
*/
private String storeFieldDetail;
/**
* 排序字段
*/
private Double sort;
public Integer getStoreFieldId() {
return storeFieldId;
}
public void setStoreFieldId(Integer storeFieldId) {
this.storeFieldId = storeFieldId;
}
public String getStoreFieldName() {
return storeFieldName;
}
public void setStoreFieldName(String storeFieldName) {
this.storeFieldName = storeFieldName;
}
public Integer getStoreFieldType() {
return storeFieldType;
}
public void setStoreFieldType(Integer storeFieldType) {
this.storeFieldType = storeFieldType;
}
public String getStoreFieldDetail() {
return storeFieldDetail;
}
public void setStoreFieldDetail(String storeFieldDetail) {
this.storeFieldDetail = storeFieldDetail;
}
public Double getSort() {
return sort;
}
public void setSort(Double sort) {
this.sort = sort;
}
}
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