Compare commits
No commits in common. "d12153d6f4cf80a02fc531a0e93a7c670e48d6d8" and "52a019c3414cd5a3ed40b0220ee84bf413742917" have entirely different histories.
d12153d6f4
...
52a019c341
|
|
@ -4,15 +4,15 @@ import com.njzscloud.common.core.utils.R;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import com.njzscloud.dispose.cst.truck.pojo.entity.TruckEntity;
|
import com.njzscloud.dispose.cst.truck.pojo.entity.TruckEntity;
|
||||||
import com.njzscloud.dispose.cst.truck.pojo.param.DelTruckParam;
|
|
||||||
import com.njzscloud.dispose.cst.truck.service.TruckService;
|
import com.njzscloud.dispose.cst.truck.service.TruckService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆信息
|
* 车辆信息
|
||||||
*
|
|
||||||
* @author ljw
|
* @author ljw
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -45,8 +45,8 @@ public class TruckController {
|
||||||
* 删除
|
* 删除
|
||||||
*/
|
*/
|
||||||
@PostMapping("/del")
|
@PostMapping("/del")
|
||||||
public R<?> del(@RequestBody DelTruckParam param) {
|
public R<?> del(@RequestBody List<Long> ids) {
|
||||||
truckService.del(param.getIds(), param.getManager(), param.getCustomerId());
|
truckService.del(ids);
|
||||||
return R.success();
|
return R.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package com.njzscloud.dispose.cst.truck.pojo.param;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆删除参数
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
public class DelTruckParam {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 要删除的车辆ID列表
|
|
||||||
*/
|
|
||||||
private List<Long> ids;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否管理员
|
|
||||||
*/
|
|
||||||
private Boolean manager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户ID
|
|
||||||
*/
|
|
||||||
private Long customerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ public interface TruckService extends IService<TruckEntity> {
|
||||||
|
|
||||||
void modify(TruckEntity truckEntity);
|
void modify(TruckEntity truckEntity);
|
||||||
|
|
||||||
void del(List<Long> ids, Boolean manager, Long customerId);
|
void del(List<Long> ids);
|
||||||
|
|
||||||
TruckEntity detail(Long id);
|
TruckEntity detail(Long id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import com.njzscloud.common.security.util.SecurityUtil;
|
|
||||||
import com.njzscloud.dispose.cst.truck.mapper.TruckMapper;
|
import com.njzscloud.dispose.cst.truck.mapper.TruckMapper;
|
||||||
import com.njzscloud.dispose.cst.truck.pojo.entity.TruckEntity;
|
import com.njzscloud.dispose.cst.truck.pojo.entity.TruckEntity;
|
||||||
import com.njzscloud.dispose.cst.truck.service.TruckService;
|
import com.njzscloud.dispose.cst.truck.service.TruckService;
|
||||||
|
|
@ -17,7 +16,6 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆信息
|
* 车辆信息
|
||||||
*
|
|
||||||
* @author ljw
|
* @author ljw
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -32,46 +30,13 @@ public class TruckServiceImpl extends ServiceImpl<TruckMapper, TruckEntity> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void modify(TruckEntity truckEntity) {
|
public void modify(TruckEntity truckEntity) {
|
||||||
if (!SecurityUtil.isAdmin()) {
|
this.updateById(truckEntity);
|
||||||
// id和customerId必传
|
|
||||||
if (truckEntity.getId() == null || truckEntity.getCustomerId() == null) {
|
|
||||||
throw new RuntimeException("id和customerId必传");
|
|
||||||
}
|
|
||||||
TruckEntity old = this.getById(truckEntity.getId());
|
|
||||||
if (truckEntity.getCustomerId().equals(old.getCustomerId())) {
|
|
||||||
// 传参customerId与旧数据customerId一致,说明是修改自己名下的车辆,允许修改
|
|
||||||
this.updateById(truckEntity);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("无修改权限");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.updateById(truckEntity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void del(List<Long> ids, Boolean manager, Long customerId) {
|
public void del(List<Long> ids) {
|
||||||
if (!SecurityUtil.isAdmin()) {
|
this.removeBatchByIds(ids);
|
||||||
// id和customerId必传
|
|
||||||
if (manager == null || customerId == null) {
|
|
||||||
throw new RuntimeException("manager和customerId必传");
|
|
||||||
}
|
|
||||||
// 只能删除自己名下车辆
|
|
||||||
List<TruckEntity> trucks = this.listByIds(ids);
|
|
||||||
if (!trucks.stream().allMatch(truck -> truck.getCustomerId().equals(customerId))) {
|
|
||||||
throw new RuntimeException("无删除权限");
|
|
||||||
}
|
|
||||||
if (!manager) {
|
|
||||||
// 非管理员直接删除即可
|
|
||||||
this.removeBatchByIds(ids);
|
|
||||||
} else {
|
|
||||||
// 管理员则是把orgId置空,解绑
|
|
||||||
this.update(Wrappers.<TruckEntity>lambdaUpdate().set(TruckEntity::getOrgId, null).in(TruckEntity::getId, ids));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.removeBatchByIds(ids);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -81,7 +46,7 @@ public class TruckServiceImpl extends ServiceImpl<TruckMapper, TruckEntity> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<TruckEntity> paging(PageParam pageParam, TruckEntity truckEntity) {
|
public PageResult<TruckEntity> paging(PageParam pageParam, TruckEntity truckEntity) {
|
||||||
return PageResult.of(this.page(pageParam.toPage(), Wrappers.query(truckEntity)));
|
return PageResult.of(this.page(pageParam.toPage(), Wrappers.<TruckEntity>query(truckEntity)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue