Browse Source

店铺关联分组增加

cangku
wangfukang 2 years ago
parent
commit
464ece7a27
  1. 41
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/controller/ShopRelationsController.java
  2. 19
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/mapper/ShopRelationsMapper.java
  3. 42
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/ShopRelationsService.java
  4. 86
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/impl/ShopRelationsServiceImpl.java
  5. 8
      hiver-modules/hiver-mall/src/main/resources/mapper/ShopRelationsMapper.xml

41
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/controller/ShopRelationsController.java

@ -102,4 +102,45 @@ public class ShopRelationsController {
return ResultUtil.error("获取店铺关联信息失败");
}
}
/**
* 根据店主id查询分组
*
* @param shopOwnerId
* @return Result
* @author 王富康
* @date 2024/8/4
*/
@RequestMapping(value = "/getShopRelationsByShopOwnerId", method = RequestMethod.POST)
@ApiOperation("查询店主的分组")
public Result getShopRelationsByShopOwnerId(String shopOwnerId) {
if (StringUtils.isEmpty(shopOwnerId)) {
return ResultUtil.error("店主id不能为空");
}
try {
List<ShopRelations> shopRelationsVoList = shopRelationsService.getShopRelationsByShopOwnerId(shopOwnerId);
return new ResultUtil<List<ShopRelations>>().setData(shopRelationsVoList);
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResultUtil.error("查询店主的分组失败");
}
}
// 修改分组店铺信息
@RequestMapping(value = "/updateShopRelations", method = RequestMethod.POST)
@ApiOperation("修改分组店铺信息")
public Result updateShopRelations(@RequestBody ShopRelations shopRelations) {
if (StringUtils.isEmpty(shopRelations.getId())) {
return ResultUtil.error("id不能为空");
}
try {
shopRelationsService.updateShopRelations(shopRelations);
return ResultUtil.success("修改分组店铺信息成功");
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResultUtil.error("修改分组店铺信息失败");
}
}
}

19
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/mapper/ShopRelationsMapper.java

@ -7,5 +7,24 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ShopRelationsMapper extends BaseMapper<ShopRelations> {
/**
* 根据店铺id获取关联的店铺信息
*
* @param shopId
* @return List<ShopRelations>
* @author 王富康
* @date 2024/8/4
*/
List<ShopRelations> getShopRelations(@Param("shopId") String shopId);
/**
* 根据店主id查询分组
*
* @param shopOwnerId
* @return List<ShopRelations>
* @author 王富康
* @date 2024/8/4
*/
List<ShopRelations> getShopRelationsByShopOwnerId(@Param("shopOwnerId") String shopOwnerId);
}

42
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/ShopRelationsService.java

@ -6,9 +6,51 @@ import cc.hiver.mall.shoprelations.vo.ShopRelationsVo;
import java.util.List;
public interface ShopRelationsService {
/**
* 新增店铺关联信息
*
* @param shopRelations
* @author 王富康
* @date 2024/8/4
*/
void addShopRelations(ShopRelations shopRelations);
/**
* 根据店铺id获取关联的店铺信息
*
* @param shopId
* @return List<ShopRelationsVo>
* @author 王富康
* @date 2024/8/4
*/
List<ShopRelationsVo> getShopRelations(String shopId);
/**
* 删除店铺关联信息
*
* @param id
* @author 王富康
* @date 2024/8/4
*/
void deleteShopRelations(String id);
/**
* 根据店主id查询分组
*
* @param shopOwnerId
* @return List<ShopRelations>
* @author 王富康
* @date 2024/8/4
*/
List<ShopRelations> getShopRelationsByShopOwnerId(String shopOwnerId);
/**
* 修改分组店铺信息
*
* @param shopRelations
* @author 王富康
* @date 2024/8/4
*/
void updateShopRelations(ShopRelations shopRelations);
}

86
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/shoprelations/service/impl/ShopRelationsServiceImpl.java

@ -4,6 +4,7 @@ import cc.hiver.mall.shoprelations.entity.ShopRelations;
import cc.hiver.mall.shoprelations.mapper.ShopRelationsMapper;
import cc.hiver.mall.shoprelations.service.ShopRelationsService;
import cc.hiver.mall.shoprelations.vo.ShopRelationsVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -16,26 +17,101 @@ public class ShopRelationsServiceImpl implements ShopRelationsService {
@Autowired
private ShopRelationsMapper shopRelationsMapper;
/**
* 新增店铺关联信息
*
* @param shopRelations
* @author 王富康
* @date 2024/8/4
*/
@Override
public void addShopRelations(ShopRelations shopRelations) {
shopRelationsMapper.insert(shopRelations);
}
/**
* 根据店铺id获取关联的店铺信息
*
* @param shopId
* @return List<ShopRelationsVo>
* @author 王富康
* @date 2024/8/4
*/
@Override
public List<ShopRelationsVo> getShopRelations(String shopId) {
List<ShopRelations> shopRelations = shopRelationsMapper.getShopRelations(shopId);
List<ShopRelationsVo> shopRelationsVo = new ArrayList<>();
if(shopRelations != null && !shopRelations.isEmpty()){
// 查询出来包含当前店铺的分组信息
final List<ShopRelations> shopRelations = shopRelationsMapper.getShopRelations(shopId);
// 需要返回的跟当前店铺有关联的店铺信息
final List<ShopRelationsVo> shopRelationsVo = new ArrayList<>();
// 存放已经添加过的店铺id,用于去重
final List<String> shopIds = new ArrayList<>();
if (shopRelations != null && !shopRelations.isEmpty()) {
for (ShopRelations shopRelation : shopRelations) {
String groupShopId = shopRelation.getShopId();
String shopName = shopRelation.getShopName();
final String groupShopId = shopRelation.getShopId();
final String shopName = shopRelation.getShopName();
if (StringUtils.isEmpty(groupShopId)) {
// 根据都好分隔
final String[] groupShopIdArray = groupShopId.split(",");
final String[] groupshopNameArray = shopName.split(",");
for (int i = 0; i < groupShopIdArray.length; i++) {
// 判断是否已经添加过
if (!shopIds.contains(groupShopIdArray[i])) {
// 没有添加过,放进集合
shopIds.add(groupShopIdArray[i]);
// 没有添加过,放回返回集合
final ShopRelationsVo relationsVo = new ShopRelationsVo();
relationsVo.setShopId(groupShopIdArray[i]);
relationsVo.setShopName(groupshopNameArray[i]);
shopRelationsVo.add(relationsVo);
}
}
}
}
}
return shopRelationsVo;
}
/**
* 删除店铺关联信息
*
* @param id
* @author 王富康
* @date 2024/8/4
*/
@Override
public void deleteShopRelations(String id) {
shopRelationsMapper.deleteById(id);
}
/**
* 根据店主id查询分组
*
* @param shopOwnerId
* @return List<ShopRelations>
* @author 王富康
* @date 2024/8/4
*/
@Override
public List<ShopRelations> getShopRelationsByShopOwnerId(String shopOwnerId) {
return shopRelationsMapper.getShopRelationsByShopOwnerId(shopOwnerId);
}
/**
* 修改分组店铺信息
*
* @param shopRelations
* @author 王富康
* @date 2024/8/4
*/
@Override
public void updateShopRelations(ShopRelations shopRelations) {
// 只能修改分组名称及店铺信息,这里不要动其他数据
// 获取到之前的数据
final ShopRelations oldShopRelations = shopRelationsMapper.selectById(shopRelations.getId());
oldShopRelations.setGroupName(shopRelations.getGroupName());
oldShopRelations.setShopId(shopRelations.getShopId());
oldShopRelations.setShopName(shopRelations.getShopName());
// 更新
shopRelationsMapper.updateById(oldShopRelations);
}
}

8
hiver-modules/hiver-mall/src/main/resources/mapper/ShopRelationsMapper.xml

@ -35,4 +35,12 @@
from t_shop_relations
where shop_id like concat('%',#{shopId},'%')
</select>
<select id="getShopRelationsByShopOwnerId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_shop_relations
where shop_owner_id = #{shopOwnerId}
</select>
</mapper>
Loading…
Cancel
Save