师傅服务类目接口

This commit is contained in:
HH 2022-06-07 16:37:06 +08:00
parent b701516896
commit ffc1d6c177
8 changed files with 273 additions and 0 deletions

View File

@ -0,0 +1,88 @@
package com.ghy.web.controller.worker;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.text.Convert;
import com.ghy.worker.domain.WorkerGoodsCategory;
import com.ghy.worker.request.WorkerGoodsCategorySaveRequest;
import com.ghy.worker.service.WorkerGoodsCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 师傅服务类目Controller
*
* @author HH 2022/6/7
*/
@Slf4j
@Controller
@RequestMapping("worker/goods/category")
public class WorkerGoodsCategoryController {
@Resource
private WorkerGoodsCategoryService workerGoodsCategoryService;
/**
* 查询某个师傅的所有服务类目
*
* @param workerId 师傅ID
*/
@GetMapping("worker")
@ResponseBody
public AjaxResult getByWorker(Long workerId) {
return AjaxResult.success(workerGoodsCategoryService.getByWorker(workerId));
}
@PostMapping("save")
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public AjaxResult save(@RequestBody WorkerGoodsCategorySaveRequest request) {
Set<Long> goodsCategoryIds = request.getGoodsCategoryIds();
// 数据库中已存在的商品类目ID
Set<Long> existingId = workerGoodsCategoryService.getByWorker(request.getWorkerId()).stream()
.map(WorkerGoodsCategory::getGoodsCategoryId).collect(Collectors.toSet());
goodsCategoryIds.removeIf(existingId::contains);
if (CollectionUtils.isEmpty(goodsCategoryIds)) {
// 如果去重后ID集合为空 则结束
return AjaxResult.success();
}
for (Long goodsCategoryId : existingId) {
WorkerGoodsCategory wgc = new WorkerGoodsCategory();
wgc.setWorkerId(request.getWorkerId());
wgc.setGoodsCategoryId(goodsCategoryId);
workerGoodsCategoryService.insert(wgc);
}
return AjaxResult.success();
}
/**
* 删除某个师傅的所有服务类目
*
* @param workerId 师傅ID
*/
@DeleteMapping("worker")
@ResponseBody
public AjaxResult deleteByWorker(Long workerId) {
workerGoodsCategoryService.deleteByWorker(workerId);
return AjaxResult.success();
}
/**
* 通过主键删除
*
* @param ids 师傅服务类目表主键
*/
@DeleteMapping
@ResponseBody
public AjaxResult deleteByWorkerAreaId(String ids) {
Long[] idArray = Convert.toLongArray(ids);
workerGoodsCategoryService.delete(idArray);
return AjaxResult.success();
}
}

View File

@ -0,0 +1,28 @@
package com.ghy.worker.domain;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
/**
* 师傅服务类目
*
* @author HH 2022/6/7
*/
@Data
public class WorkerGoodsCategory extends BaseEntity {
/**
* 主键
*/
private Long workerGoodsCategoryId;
/**
* 师傅主键
*/
private Long workerId;
/**
* 商品类目主键
*/
private Long goodsCategoryId;
}

View File

@ -0,0 +1,21 @@
package com.ghy.worker.mapper;
import com.ghy.worker.domain.WorkerGoodsCategory;
import java.util.List;
/**
* 师傅服务类目Mapper
*
* @author HH 2022/6/7
*/
public interface WorkerGoodsCategoryMapper {
int insert(WorkerGoodsCategory workerGoodsCategory);
int delete(Long[] ids);
int deleteByWorker(Long workerId);
List<WorkerGoodsCategory> getByWorker(Long workerId);
}

View File

@ -0,0 +1,24 @@
package com.ghy.worker.request;
import lombok.Data;
import java.util.Set;
/**
* 保存师傅接单区域接口参数
*
* @author HH 2022/6/7
*/
@Data
public class WorkerGoodsCategorySaveRequest {
/**
* 师傅ID
*/
private Long workerId;
/**
* 第3级商品类目ID
*/
private Set<Long> goodsCategoryIds;
}

View File

@ -0,0 +1,21 @@
package com.ghy.worker.service;
import com.ghy.worker.domain.WorkerGoodsCategory;
import java.util.List;
/**
* 师傅服务类目Service
*
* @author HH 2022/6/7
*/
public interface WorkerGoodsCategoryService {
int insert(WorkerGoodsCategory workerGoodsCategory);
int delete(Long[] ids);
int deleteByWorker(Long workerId);
List<WorkerGoodsCategory> getByWorker(Long workerId);
}

View File

@ -0,0 +1,41 @@
package com.ghy.worker.service.impl;
import com.ghy.worker.domain.WorkerGoodsCategory;
import com.ghy.worker.mapper.WorkerGoodsCategoryMapper;
import com.ghy.worker.service.WorkerGoodsCategoryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 师傅服务类目Service
*
* @author HH 2022/6/7
*/
@Service
public class WorkerGoodsCategoryServiceImpl implements WorkerGoodsCategoryService {
@Resource
private WorkerGoodsCategoryMapper workerGoodsCategoryMapper;
@Override
public int insert(WorkerGoodsCategory workerGoodsCategory) {
return workerGoodsCategoryMapper.insert(workerGoodsCategory);
}
@Override
public int delete(Long[] ids) {
return workerGoodsCategoryMapper.delete(ids);
}
@Override
public int deleteByWorker(Long workerId) {
return workerGoodsCategoryMapper.deleteByWorker(workerId);
}
@Override
public List<WorkerGoodsCategory> getByWorker(Long workerId) {
return workerGoodsCategoryMapper.getByWorker(workerId);
}
}

View File

@ -8,6 +8,7 @@
<result property="provinceId" column="province_id"/> <result property="provinceId" column="province_id"/>
<result property="cityId" column="city_id"/> <result property="cityId" column="city_id"/>
<result property="districtId" column="district_id"/> <result property="districtId" column="district_id"/>
<result property="streetId" column="street_id"/>
<result property="createBy" column="create_by"/> <result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/> <result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by"/>
@ -21,6 +22,7 @@
<if test="provinceId != null and provinceId > 0">province_id,</if> <if test="provinceId != null and provinceId > 0">province_id,</if>
<if test="cityId != null and cityId > 0">city_id,</if> <if test="cityId != null and cityId > 0">city_id,</if>
<if test="districtId != null and districtId > 0">district_id,</if> <if test="districtId != null and districtId > 0">district_id,</if>
<if test="streetId != null and streetId > 0">street_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if> <if test="remark != null and remark != ''">remark,</if>
create_time create_time
@ -29,6 +31,7 @@
<if test="provinceId != null and provinceId > 0">#{provinceId},</if> <if test="provinceId != null and provinceId > 0">#{provinceId},</if>
<if test="cityId != null and cityId > 0">#{cityId},</if> <if test="cityId != null and cityId > 0">#{cityId},</if>
<if test="districtId != null and districtId > 0">#{districtId},</if> <if test="districtId != null and districtId > 0">#{districtId},</if>
<if test="streetId != null and streetId > 0">#{streetId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if> <if test="remark != null and remark != ''">#{remark},</if>
sysdate() sysdate()

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ghy.worker.mapper.WorkerGoodsCategoryMapper">
<resultMap id="WorkerGoodsCategoryResult" type="com.ghy.worker.domain.WorkerGoodsCategory">
<result property="workerGoodsCategoryId" column="worker_goods_category_id"/>
<result property="workerId" column="worker_id"/>
<result property="goodsCategoryId" column="goods_category_id"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
</resultMap>
<insert id="insert" parameterType="com.ghy.worker.domain.WorkerGoodsCategory" useGeneratedKeys="true" keyProperty="workerGoodsCategoryId">
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="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="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
)
</insert>
<select id="getByWorker" parameterType="Long" resultMap="WorkerGoodsCategoryResult">
SELECT * FROM worker_goods_category WHERE worker_id = #{workerId}
</select>
<delete id="deleteByWorker" parameterType="Long">
DELETE FROM worker_goods_category WHERE worker_id = #{workerId}
</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=")">
#{id}
</foreach>
</delete>
</mapper>