车辆管理修改

master
ljw 2025-12-15 15:51:38 +08:00
parent ec68e8fc3e
commit d687b0e258
4 changed files with 77 additions and 9 deletions

View File

@ -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();
} }

View File

@ -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;
}

View File

@ -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);

View File

@ -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)));
} }
} }