Merge branch 'master' of https://gitee.com/op-souls/ghy-all
This commit is contained in:
commit
a96ab58e1e
|
|
@ -0,0 +1,87 @@
|
||||||
|
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.WorkerArea;
|
||||||
|
import com.ghy.worker.request.WorkerAreaSaveRequest;
|
||||||
|
import com.ghy.worker.service.WorkerAreaService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 师傅接单区域
|
||||||
|
*
|
||||||
|
* @author HH 2022/6/7
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("worker/area")
|
||||||
|
public class WorkerAreaController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WorkerAreaService workerAreaService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询某个师傅的所有接单地区
|
||||||
|
*
|
||||||
|
* @param workerId 师傅ID
|
||||||
|
*/
|
||||||
|
@GetMapping("worker")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult getByWorker(Long workerId) {
|
||||||
|
return AjaxResult.success(workerAreaService.getByWorker(workerId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("save")
|
||||||
|
@ResponseBody
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult save(@RequestBody WorkerAreaSaveRequest request) {
|
||||||
|
Set<WorkerArea> areas = request.getAreas();
|
||||||
|
// 数据库中已存在的街道ID
|
||||||
|
Set<Long> existingArea = workerAreaService.getByWorker(request.getWorkerId()).stream()
|
||||||
|
.map(WorkerArea::getStreetId).collect(Collectors.toSet());
|
||||||
|
// 去掉重复
|
||||||
|
areas.removeIf(x -> existingArea.contains(x.getStreetId()));
|
||||||
|
if (CollectionUtils.isEmpty(areas)) {
|
||||||
|
// 如果去重后ID集合为空 则结束
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
for (WorkerArea area : areas) {
|
||||||
|
area.setWorkerId(request.getWorkerId());
|
||||||
|
workerAreaService.insert(area);
|
||||||
|
}
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除某个师傅的所有接单地区
|
||||||
|
*
|
||||||
|
* @param workerId 师傅ID
|
||||||
|
*/
|
||||||
|
@DeleteMapping("worker")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult deleteByWorker(Long workerId) {
|
||||||
|
workerAreaService.deleteByWorker(workerId);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除
|
||||||
|
*
|
||||||
|
* @param ids 接单地区表主键
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult deleteByWorkerAreaId(String ids) {
|
||||||
|
Long[] idArray = Convert.toLongArray(ids);
|
||||||
|
workerAreaService.delete(idArray);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,8 +23,10 @@ public class WorkerArea extends BaseEntity {
|
||||||
@Excel(name = "市区域id", cellType = Excel.ColumnType.NUMERIC)
|
@Excel(name = "市区域id", cellType = Excel.ColumnType.NUMERIC)
|
||||||
private Long cityId;
|
private Long cityId;
|
||||||
|
|
||||||
@Excel(name = "区县区域id", cellType = Excel.ColumnType.NUMERIC)
|
@Excel(name = "区/县区域id", cellType = Excel.ColumnType.NUMERIC)
|
||||||
private Long districtId;
|
private Long districtId;
|
||||||
|
|
||||||
|
@Excel(name = "街道区域id", cellType = Excel.ColumnType.NUMERIC)
|
||||||
|
private Long streetId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.ghy.worker.mapper;
|
||||||
|
|
||||||
import com.ghy.worker.domain.WorkerArea;
|
import com.ghy.worker.domain.WorkerArea;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 师父接单区域
|
* 师父接单区域
|
||||||
*
|
*
|
||||||
|
|
@ -11,9 +13,9 @@ public interface WorkerAreaMapper {
|
||||||
|
|
||||||
int insert(WorkerArea workerArea);
|
int insert(WorkerArea workerArea);
|
||||||
|
|
||||||
int delete(Long workerAreaId);
|
int delete(Long[] ids);
|
||||||
|
|
||||||
int deleteByWorker(Long workerId);
|
int deleteByWorker(Long workerId);
|
||||||
|
|
||||||
WorkerArea getByWorker(Long workerId);
|
List<WorkerArea> getByWorker(Long workerId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.ghy.worker.request;
|
||||||
|
|
||||||
|
import com.ghy.worker.domain.WorkerArea;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存师傅接单区域接口参数
|
||||||
|
*
|
||||||
|
* @author HH 2022/6/7
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WorkerAreaSaveRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 师傅ID
|
||||||
|
*/
|
||||||
|
private Long workerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第4级(level_type=4)地区
|
||||||
|
*/
|
||||||
|
private Set<WorkerArea> areas;
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ package com.ghy.worker.service;
|
||||||
|
|
||||||
import com.ghy.worker.domain.WorkerArea;
|
import com.ghy.worker.domain.WorkerArea;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 师父接单区域
|
* 师父接单区域
|
||||||
*
|
*
|
||||||
|
|
@ -11,9 +13,9 @@ public interface WorkerAreaService {
|
||||||
|
|
||||||
int insert(WorkerArea workerArea);
|
int insert(WorkerArea workerArea);
|
||||||
|
|
||||||
int delete(Long workerAreaId);
|
int delete(Long[] ids);
|
||||||
|
|
||||||
int deleteByWorker(Long workerId);
|
int deleteByWorker(Long workerId);
|
||||||
|
|
||||||
WorkerArea getByWorker(Long workerId);
|
List<WorkerArea> getByWorker(Long workerId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import com.ghy.worker.service.WorkerAreaService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class WorkerAreaServiceImpl implements WorkerAreaService {
|
public class WorkerAreaServiceImpl implements WorkerAreaService {
|
||||||
|
|
@ -19,8 +20,8 @@ public class WorkerAreaServiceImpl implements WorkerAreaService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Long workerAreaId) {
|
public int delete(Long[] ids) {
|
||||||
return workerAreaMapper.delete(workerAreaId);
|
return workerAreaMapper.delete(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -29,7 +30,7 @@ public class WorkerAreaServiceImpl implements WorkerAreaService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkerArea getByWorker(Long workerId) {
|
public List<WorkerArea> getByWorker(Long workerId) {
|
||||||
return workerAreaMapper.getByWorker(workerId);
|
return workerAreaMapper.getByWorker(workerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,10 @@
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="delete" parameterType="Long">
|
<delete id="delete" parameterType="Long">
|
||||||
DELETE FROM worker_area WHERE worker_area_id = #{workerAreaId}
|
DELETE FROM worker_area WHERE worker_area_id IN
|
||||||
|
<foreach collection="array" item="areaId" open="(" separator="," close=")">
|
||||||
|
#{areaId}
|
||||||
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue