车辆管理修改
parent
ec68e8fc3e
commit
d687b0e258
|
|
@ -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 List<Long> ids) {
|
public R<?> del(@RequestBody DelTruckParam param) {
|
||||||
truckService.del(ids);
|
truckService.del(param.getIds(), param.getManager(), param.getCustomerId());
|
||||||
return R.success();
|
return R.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
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);
|
void del(List<Long> ids, Boolean manager, Long customerId);
|
||||||
|
|
||||||
TruckEntity detail(Long id);
|
TruckEntity detail(Long id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ 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;
|
||||||
|
|
@ -16,6 +17,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆信息
|
* 车辆信息
|
||||||
|
*
|
||||||
* @author ljw
|
* @author ljw
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -30,13 +32,46 @@ public class TruckServiceImpl extends ServiceImpl<TruckMapper, TruckEntity> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void modify(TruckEntity truckEntity) {
|
public void modify(TruckEntity truckEntity) {
|
||||||
this.updateById(truckEntity);
|
if (!SecurityUtil.isAdmin()) {
|
||||||
|
// 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) {
|
public void del(List<Long> ids, Boolean manager, Long customerId) {
|
||||||
this.removeBatchByIds(ids);
|
if (!SecurityUtil.isAdmin()) {
|
||||||
|
// 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
|
||||||
|
|
@ -46,7 +81,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.<TruckEntity>query(truckEntity)));
|
return PageResult.of(this.page(pageParam.toPage(), Wrappers.query(truckEntity)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue