Compare commits

..

No commits in common. "d12153d6f4cf80a02fc531a0e93a7c670e48d6d8" and "52a019c3414cd5a3ed40b0220ee84bf413742917" have entirely different histories.

4 changed files with 9 additions and 77 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.PageResult;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
*
*
* @author ljw
*/
@Slf4j
@ -45,8 +45,8 @@ public class TruckController {
*
*/
@PostMapping("/del")
public R<?> del(@RequestBody DelTruckParam param) {
truckService.del(param.getIds(), param.getManager(), param.getCustomerId());
public R<?> del(@RequestBody List<Long> ids) {
truckService.del(ids);
return R.success();
}

View File

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

View File

@ -17,7 +17,7 @@ public interface TruckService extends IService<TruckEntity> {
void modify(TruckEntity truckEntity);
void del(List<Long> ids, Boolean manager, Long customerId);
void del(List<Long> ids);
TruckEntity detail(Long id);

View File

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njzscloud.common.mp.support.PageParam;
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.pojo.entity.TruckEntity;
import com.njzscloud.dispose.cst.truck.service.TruckService;
@ -17,7 +16,6 @@ import java.util.List;
/**
*
*
* @author ljw
*/
@Slf4j
@ -32,46 +30,13 @@ public class TruckServiceImpl extends ServiceImpl<TruckMapper, TruckEntity> impl
@Override
public void modify(TruckEntity 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);
}
this.updateById(truckEntity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void del(List<Long> ids, Boolean manager, Long customerId) {
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);
}
public void del(List<Long> ids) {
this.removeBatchByIds(ids);
}
@Override
@ -81,7 +46,7 @@ public class TruckServiceImpl extends ServiceImpl<TruckMapper, TruckEntity> impl
@Override
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)));
}
}