增加类目 类型区分
This commit is contained in:
parent
270ad85a10
commit
57d5161b2c
|
|
@ -421,8 +421,35 @@ public class WorkerController extends BaseController {
|
|||
// 入驻商品区域信息持久化(类型2)
|
||||
workerAreaService.updateWorkerAreaByType(request.getWorkerId(), request.getWorkerGoodsAreas(), 2);
|
||||
|
||||
// 入驻服务品类信息持久化
|
||||
workerGoodsCategoryService.updateWorkerGoodsCategory(request.getWorkerId(), request.getGoodsCategories());
|
||||
// 入驻服务类目信息持久化(类型1)
|
||||
if (request.getServiceCategories() != null && !request.getServiceCategories().isEmpty()) {
|
||||
// 使用对象数组方式
|
||||
workerGoodsCategoryService.updateWorkerGoodsCategoryByType(request.getWorkerId(), request.getServiceCategories(), 1);
|
||||
} else if (request.getServiceCategoryIds() != null && !request.getServiceCategoryIds().isEmpty()) {
|
||||
// 使用ID数组方式(兼容旧版本)
|
||||
List<WorkerGoodsCategory> serviceCategories = request.getServiceCategoryIds().stream()
|
||||
.map(id -> {
|
||||
WorkerGoodsCategory category = new WorkerGoodsCategory();
|
||||
category.setGoodsCategoryId(id);
|
||||
return category;
|
||||
}).collect(Collectors.toList());
|
||||
workerGoodsCategoryService.updateWorkerGoodsCategoryByType(request.getWorkerId(), serviceCategories, 1);
|
||||
}
|
||||
|
||||
// 入驻商品类目信息持久化(类型2)
|
||||
if (request.getGoodsCategories() != null && !request.getGoodsCategories().isEmpty()) {
|
||||
// 使用对象数组方式
|
||||
workerGoodsCategoryService.updateWorkerGoodsCategoryByType(request.getWorkerId(), request.getGoodsCategories(), 2);
|
||||
} else if (request.getGoodsCategoryIds() != null && !request.getGoodsCategoryIds().isEmpty()) {
|
||||
// 使用ID数组方式(兼容旧版本)
|
||||
List<WorkerGoodsCategory> goodsCategories = request.getGoodsCategoryIds().stream()
|
||||
.map(id -> {
|
||||
WorkerGoodsCategory category = new WorkerGoodsCategory();
|
||||
category.setGoodsCategoryId(id);
|
||||
return category;
|
||||
}).collect(Collectors.toList());
|
||||
workerGoodsCategoryService.updateWorkerGoodsCategoryByType(request.getWorkerId(), goodsCategories, 2);
|
||||
}
|
||||
|
||||
// 更新师傅入驻类型为服务商
|
||||
Worker worker = new Worker();
|
||||
|
|
|
|||
|
|
@ -71,11 +71,20 @@ public class WorkerGoodsCategoryController extends BaseController {
|
|||
* 查询某个师傅的所有服务类目
|
||||
*
|
||||
* @param workerId 师傅ID
|
||||
* @param serviceType 服务类型:1=服务, 2=商品,不传则查询所有
|
||||
*/
|
||||
@GetMapping("worker")
|
||||
@ResponseBody
|
||||
public AjaxResult getByWorker(Long workerId) {
|
||||
List<WorkerGoodsCategory> list = workerGoodsCategoryService.getByWorker(workerId);
|
||||
public AjaxResult getByWorker(Long workerId, Integer serviceType) {
|
||||
List<WorkerGoodsCategory> list;
|
||||
if (serviceType != null) {
|
||||
// 根据服务类型查询
|
||||
list = workerGoodsCategoryService.getByWorkerIdAndType(workerId, serviceType);
|
||||
} else {
|
||||
// 查询所有类目(保持向后兼容)
|
||||
list = workerGoodsCategoryService.getByWorker(workerId);
|
||||
}
|
||||
|
||||
for (WorkerGoodsCategory item: list) {
|
||||
List<String> nameList = new ArrayList<String>();
|
||||
// 查询所有父级服务类目,拼接服务名称
|
||||
|
|
@ -89,6 +98,53 @@ public class WorkerGoodsCategoryController extends BaseController {
|
|||
}
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询某个师傅的服务类目(类型1)
|
||||
*
|
||||
* @param workerId 师傅ID
|
||||
*/
|
||||
@GetMapping("worker/service")
|
||||
@ResponseBody
|
||||
public AjaxResult getServiceCategoriesByWorker(Long workerId) {
|
||||
List<WorkerGoodsCategory> list = workerGoodsCategoryService.getByWorkerIdAndType(workerId, 1);
|
||||
for (WorkerGoodsCategory item: list) {
|
||||
List<String> nameList = new ArrayList<String>();
|
||||
// 查询所有父级服务类目,拼接服务名称
|
||||
GoodsCategory goodsCategory = goodsCategoryService.selectById(item.getGoodsCategoryId());
|
||||
while (goodsCategory.getParentCategoryId() != null) {
|
||||
nameList.add(goodsCategory.getGoodsCategoryName());
|
||||
goodsCategory = goodsCategoryService.selectById(goodsCategory.getParentCategoryId());
|
||||
}
|
||||
Collections.reverse(nameList);
|
||||
item.setMergeName(StringUtils.join(nameList, Constants.JOIN_SYMBOL));
|
||||
}
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询某个师傅的商品类目(类型2)
|
||||
*
|
||||
* @param workerId 师傅ID
|
||||
*/
|
||||
@GetMapping("worker/goods")
|
||||
@ResponseBody
|
||||
public AjaxResult getGoodsCategoriesByWorker(Long workerId) {
|
||||
List<WorkerGoodsCategory> list = workerGoodsCategoryService.getByWorkerIdAndType(workerId, 2);
|
||||
for (WorkerGoodsCategory item: list) {
|
||||
List<String> nameList = new ArrayList<String>();
|
||||
// 查询所有父级服务类目,拼接服务名称
|
||||
GoodsCategory goodsCategory = goodsCategoryService.selectById(item.getGoodsCategoryId());
|
||||
while (goodsCategory.getParentCategoryId() != null) {
|
||||
nameList.add(goodsCategory.getGoodsCategoryName());
|
||||
goodsCategory = goodsCategoryService.selectById(goodsCategory.getParentCategoryId());
|
||||
}
|
||||
Collections.reverse(nameList);
|
||||
item.setMergeName(StringUtils.join(nameList, Constants.JOIN_SYMBOL));
|
||||
}
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@GetMapping("worker/edit")
|
||||
@ResponseBody
|
||||
public AjaxResult getEditWorker(Long workerId) {
|
||||
|
|
|
|||
|
|
@ -24,9 +24,18 @@ public class WorkerSettledRequest {
|
|||
// 入驻商品区域
|
||||
private List<WorkerArea> workerGoodsAreas;
|
||||
|
||||
// 服务品类
|
||||
// 入驻服务类目
|
||||
private List<WorkerGoodsCategory> serviceCategories;
|
||||
|
||||
// 入驻商品类目
|
||||
private List<WorkerGoodsCategory> goodsCategories;
|
||||
|
||||
// 入驻服务类目ID列表(兼容旧版本)
|
||||
private List<Long> serviceCategoryIds;
|
||||
|
||||
// 入驻商品类目ID列表(兼容旧版本)
|
||||
private List<Long> goodsCategoryIds;
|
||||
|
||||
// 特殊技能
|
||||
// private List<WorkerSpecialSkill> specialSkills;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,4 +40,9 @@ public class WorkerGoodsCategory extends BaseEntity {
|
|||
private String mergeName;
|
||||
|
||||
private List<Long> goodsCategoryIds;
|
||||
|
||||
/**
|
||||
* 服务类型:1=服务, 2=商品
|
||||
*/
|
||||
private Integer serviceType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,15 @@ public interface WorkerGoodsCategoryMapper {
|
|||
|
||||
List<WorkerGoodsCategory> getByWorker(Long workerId);
|
||||
|
||||
/**
|
||||
* 根据师傅ID和服务类型删除服务类目
|
||||
*/
|
||||
int deleteByWorkerIdAndType(@Param("workerId") Long workerId, @Param("serviceType") Integer serviceType);
|
||||
|
||||
/**
|
||||
* 根据师傅ID和服务类型查询服务类目
|
||||
*/
|
||||
List<WorkerGoodsCategory> getByWorkerIdAndType(@Param("workerId") Long workerId, @Param("serviceType") Integer serviceType);
|
||||
|
||||
List<WorkerGoodsCategory> getWorkerGoodsCategory(WorkerGoodsCategory workerGoodsCategory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,5 +21,21 @@ public interface WorkerGoodsCategoryService {
|
|||
|
||||
void updateWorkerGoodsCategory(Long workerId, List<WorkerGoodsCategory> categories);
|
||||
|
||||
/**
|
||||
* 根据服务类型更新师傅服务类目
|
||||
* @param workerId 师傅ID
|
||||
* @param categories 类目列表
|
||||
* @param serviceType 服务类型:1=服务, 2=商品
|
||||
*/
|
||||
void updateWorkerGoodsCategoryByType(Long workerId, List<WorkerGoodsCategory> categories, Integer serviceType);
|
||||
|
||||
/**
|
||||
* 根据师傅ID和服务类型查询服务类目
|
||||
* @param workerId 师傅ID
|
||||
* @param serviceType 服务类型:1=服务, 2=商品
|
||||
* @return 服务类目列表
|
||||
*/
|
||||
List<WorkerGoodsCategory> getByWorkerIdAndType(Long workerId, Integer serviceType);
|
||||
|
||||
List<WorkerGoodsCategory> getWorkerGoodsCategory(WorkerGoodsCategory workerGoodsCategory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,4 +72,42 @@ public class WorkerGoodsCategoryServiceImpl implements WorkerGoodsCategoryServic
|
|||
public List<WorkerGoodsCategory> getWorkerGoodsCategory(WorkerGoodsCategory workerGoodsCategory) {
|
||||
return workerGoodsCategoryMapper.getWorkerGoodsCategory(workerGoodsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWorkerGoodsCategoryByType(Long workerId, List<WorkerGoodsCategory> categories, Integer serviceType) {
|
||||
if (categories == null || categories.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取该师傅该类型的已存在类目
|
||||
List<WorkerGoodsCategory> existCategories = workerGoodsCategoryMapper.getByWorkerIdAndType(workerId, serviceType);
|
||||
Set<Long> existCategoryIds = existCategories.stream().map(WorkerGoodsCategory::getGoodsCategoryId).collect(Collectors.toSet());
|
||||
Set<Long> categoryIds = categories.stream().map(WorkerGoodsCategory::getGoodsCategoryId).collect(Collectors.toSet());
|
||||
|
||||
// 新的类目-已存在类目的差集,为需要新加入的类目
|
||||
List<WorkerGoodsCategory> categories2Insert = CollectionUtils.subtract(categoryIds, existCategoryIds).stream().map(x -> {
|
||||
WorkerGoodsCategory obj = new WorkerGoodsCategory();
|
||||
obj.setWorkerId(workerId);
|
||||
obj.setGoodsCategoryId(x);
|
||||
obj.setServiceType(serviceType); // 设置类型:1=服务, 2=商品
|
||||
return obj;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 已存在类目-新的类目的差集,为需要删除的类目
|
||||
List<Long> id2DelList = existCategories.stream().filter(x -> !categoryIds.contains(x.getGoodsCategoryId()))
|
||||
.map(WorkerGoodsCategory::getWorkerGoodsCategoryId).collect(Collectors.toList());
|
||||
|
||||
if (!CollectionUtils.isEmpty(categories2Insert)) {
|
||||
workerGoodsCategoryMapper.batchInsert(categories2Insert);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(id2DelList)) {
|
||||
Long[] id2Del = new Long[]{};
|
||||
workerGoodsCategoryMapper.delete(id2DelList.toArray(id2Del));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkerGoodsCategory> getByWorkerIdAndType(Long workerId, Integer serviceType) {
|
||||
return workerGoodsCategoryMapper.getByWorkerIdAndType(workerId, serviceType);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
<result property="workerGoodsCategoryId" column="worker_goods_category_id"/>
|
||||
<result property="workerId" column="worker_id"/>
|
||||
<result property="goodsCategoryId" column="goods_category_id"/>
|
||||
<result property="serviceType" column="service_type"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
|
|
@ -15,7 +16,7 @@
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectWorkerGoodsCategory">
|
||||
SELECT wgc.worker_goods_category_id, wgc.worker_id, wgc.goods_category_id, wgc.create_by, wgc.create_time, wgc.update_by,
|
||||
SELECT wgc.worker_goods_category_id, wgc.worker_id, wgc.goods_category_id, wgc.service_type, wgc.create_by, wgc.create_time, wgc.update_by,
|
||||
wgc.update_time, wgc.remark, gc.goods_category_name
|
||||
FROM worker_goods_category wgc
|
||||
LEFT JOIN goods_category gc on gc.goods_category_id = wgc.goods_category_id
|
||||
|
|
@ -25,12 +26,14 @@
|
|||
INSERT INTO worker_goods_category(
|
||||
<if test="workerId != null and workerId > 0">worker_id,</if>
|
||||
<if test="goodsCategoryId != null and goodsCategoryId > 0">goods_category_id,</if>
|
||||
<if test="serviceType != null">service_type,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
create_time
|
||||
)VALUES(
|
||||
<if test="workerId != null and workerId > 0">#{workerId},</if>
|
||||
<if test="goodsCategoryId != null and goodsCategoryId > 0">#{goodsCategoryId},</if>
|
||||
<if test="serviceType != null">#{serviceType},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
sysdate()
|
||||
|
|
@ -38,10 +41,10 @@
|
|||
</insert>
|
||||
|
||||
<insert id="batchInsert" parameterType="list" >
|
||||
INSERT INTO worker_goods_category ( worker_id, goods_category_id, create_by, create_time)
|
||||
INSERT INTO worker_goods_category ( worker_id, goods_category_id, service_type, create_by, create_time)
|
||||
VALUES
|
||||
<foreach collection="workerCategories" separator="," item="item">
|
||||
(#{item.workerId}, #{item.goodsCategoryId}, #{item.workerId}, sysdate())
|
||||
(#{item.workerId}, #{item.goodsCategoryId}, #{item.serviceType}, #{item.workerId}, sysdate())
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
|
@ -50,6 +53,11 @@
|
|||
WHERE wgc.worker_id = #{workerId}
|
||||
</select>
|
||||
|
||||
<select id="getByWorkerIdAndType" resultMap="WorkerGoodsCategoryResult">
|
||||
<include refid="selectWorkerGoodsCategory"></include>
|
||||
WHERE wgc.worker_id = #{workerId} AND wgc.service_type = #{serviceType}
|
||||
</select>
|
||||
|
||||
<select id="getWorkerGoodsCategory" parameterType="com.ghy.worker.domain.WorkerGoodsCategory" resultMap="WorkerGoodsCategoryResult">
|
||||
<include refid="selectWorkerGoodsCategory"></include>
|
||||
<where>
|
||||
|
|
@ -75,6 +83,10 @@
|
|||
DELETE FROM worker_goods_category WHERE worker_id = #{workerId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByWorkerIdAndType">
|
||||
DELETE FROM worker_goods_category WHERE worker_id = #{workerId} AND service_type = #{serviceType}
|
||||
</delete>
|
||||
|
||||
<delete id="delete" parameterType="Long">
|
||||
DELETE FROM worker_goods_category WHERE worker_goods_category_id IN
|
||||
<foreach collection="array" item="id" open="(" separator="," close=")">
|
||||
|
|
|
|||
Loading…
Reference in New Issue