故障申报前后台实现权限校验
This commit is contained in:
parent
8144e4019e
commit
60caeef889
|
@ -21,14 +21,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
bf.user_id,
|
bf.user_id,
|
||||||
bf.vehicle_num,
|
bf.vehicle_num,
|
||||||
bf.store_id,
|
bf.store_id,
|
||||||
|
su.agent_id
|
||||||
|
<include refid="searchTables"/>
|
||||||
|
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<sql id="searchTables">
|
||||||
from bst_fault bf
|
from bst_fault bf
|
||||||
|
left join sys_user su on bf.store_id = su.user_id
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<sql id="searchCondition">
|
<sql id="searchCondition">
|
||||||
|
<if test="query.id != null and query.id != ''"> and bf.id = #{query.id}</if>
|
||||||
<if test="query.userName != null and query.userName != ''"> and bf.user_name like concat('%', #{query.userName}, '%')</if>
|
<if test="query.userName != null and query.userName != ''"> and bf.user_name like concat('%', #{query.userName}, '%')</if>
|
||||||
<if test="query.vehicleCode != null "> and bf.vehicle_code = #{query.vehicleCode}</if>
|
<if test="query.vehicleCode != null "> and bf.vehicle_code = #{query.vehicleCode}</if>
|
||||||
<if test="query.picture != null and query.picture != ''"> and bf.picture = #{query.picture}</if>
|
<if test="query.picture != null and query.picture != ''"> and bf.picture = #{query.picture}</if>
|
||||||
<if test="query.orderId != null and query.orderId != ''"> and bf.order_id = #{query.orderId}</if>
|
<if test="query.orderId != null and query.orderId != ''"> and bf.order_id = #{query.orderId}</if>
|
||||||
|
<if test="query.storeId != null and query.storeId != ''"> and bf.store_id = #{query.storeId}</if>
|
||||||
<if test="query.userId != null and query.userId != ''"> and bf.user_id = #{query.userId}</if>
|
<if test="query.userId != null and query.userId != ''"> and bf.user_id = #{query.userId}</if>
|
||||||
<if test="query.faultSiteList != null and query.faultSiteList != ''">
|
<if test="query.faultSiteList != null and query.faultSiteList != ''">
|
||||||
AND
|
AND
|
||||||
|
@ -38,9 +47,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</if>
|
</if>
|
||||||
<if test="query.faultDetail != null and query.faultDetail != ''"> and bf.fault_detail = #{query.faultDetail}</if>
|
<if test="query.faultDetail != null and query.faultDetail != ''"> and bf.fault_detail = #{query.faultDetail}</if>
|
||||||
<if test="query.appealStatus != null and query.appealStatus != ''"> and bf.appeal_status = #{query.appealStatus}</if>
|
<if test="query.appealStatus != null and query.appealStatus != ''"> and bf.appeal_status = #{query.appealStatus}</if>
|
||||||
${@com.ruoyi.framework.util.datascopeutil@dataScope(
|
${@com.ruoyi.framework.util.DataScopeUtil@dataScope(
|
||||||
null,
|
null,
|
||||||
"stroe_id",
|
"bf.store_id,su.agent_id",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
query.scope
|
query.scope
|
||||||
|
@ -62,11 +71,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
|
||||||
<select id="selectFaultByUserId" resultType="com.ruoyi.bst.fault.domain.FaultVO">
|
<select id="selectFaultByUserId" resultType="com.ruoyi.bst.fault.domain.FaultVO">
|
||||||
select
|
select
|
||||||
order_end_time,
|
bf.order_end_time,
|
||||||
vehicle_code,
|
bf.vehicle_code,
|
||||||
fault_site,
|
bf.fault_site,
|
||||||
create_time
|
bf.create_time
|
||||||
from bst_fault where user_id = #{userId}
|
from bst_fault bf where user_id = #{userId}
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,6 @@ import com.ruoyi.bst.fault.domain.FaultVO;
|
||||||
public interface FaultConverter {
|
public interface FaultConverter {
|
||||||
|
|
||||||
Fault toPo(FaultVO fault);
|
Fault toPo(FaultVO fault);
|
||||||
|
|
||||||
|
boolean canEdit(Long faultId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.ruoyi.bst.fault.service;
|
package com.ruoyi.bst.fault.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.ruoyi.bst.area.domain.AreaQuery;
|
||||||
|
import com.ruoyi.bst.area.domain.AreaVO;
|
||||||
import com.ruoyi.bst.fault.domain.Fault;
|
import com.ruoyi.bst.fault.domain.Fault;
|
||||||
import com.ruoyi.bst.fault.domain.FaultVO;
|
import com.ruoyi.bst.fault.domain.FaultVO;
|
||||||
import com.ruoyi.bst.fault.domain.FaultQuery;
|
import com.ruoyi.bst.fault.domain.FaultQuery;
|
||||||
|
@ -19,8 +22,13 @@ public interface FaultService
|
||||||
* @param id 故障主键
|
* @param id 故障主键
|
||||||
* @return 故障
|
* @return 故障
|
||||||
*/
|
*/
|
||||||
public FaultVO selectFaultById(Long id);
|
public FaultVO selectFaultById(Long id, boolean scope);
|
||||||
|
|
||||||
|
default FaultVO selectFaultById(Long id) {
|
||||||
|
return this.selectFaultById(id, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FaultVO selectOne(FaultQuery query);
|
||||||
/**
|
/**
|
||||||
* 查询故障列表
|
* 查询故障列表
|
||||||
*
|
*
|
||||||
|
@ -62,4 +70,6 @@ public interface FaultService
|
||||||
public int deleteFaultById(Long id);
|
public int deleteFaultById(Long id);
|
||||||
|
|
||||||
FaultVO selectFaultByUserId(Long id);
|
FaultVO selectFaultByUserId(Long id);
|
||||||
|
|
||||||
|
FaultVO handle(Fault fault);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.ruoyi.bst.fault.service.impl;
|
package com.ruoyi.bst.fault.service.impl;
|
||||||
|
|
||||||
|
import com.ruoyi.bst.area.domain.AreaVO;
|
||||||
import com.ruoyi.bst.device.domain.DeviceVO;
|
import com.ruoyi.bst.device.domain.DeviceVO;
|
||||||
import com.ruoyi.bst.device.service.DeviceService;
|
import com.ruoyi.bst.device.service.DeviceService;
|
||||||
import com.ruoyi.bst.fault.domain.Fault;
|
import com.ruoyi.bst.fault.domain.Fault;
|
||||||
|
import com.ruoyi.bst.fault.domain.FaultQuery;
|
||||||
import com.ruoyi.bst.fault.domain.FaultVO;
|
import com.ruoyi.bst.fault.domain.FaultVO;
|
||||||
import com.ruoyi.bst.fault.domain.enums.FaultStatus;
|
import com.ruoyi.bst.fault.domain.enums.FaultStatus;
|
||||||
import com.ruoyi.bst.fault.service.FaultConverter;
|
import com.ruoyi.bst.fault.service.FaultConverter;
|
||||||
|
@ -11,12 +13,16 @@ import com.ruoyi.bst.order.domain.OrderVO;
|
||||||
import com.ruoyi.bst.order.service.OrderService;
|
import com.ruoyi.bst.order.service.OrderService;
|
||||||
import com.ruoyi.common.core.domain.vo.UserVO;
|
import com.ruoyi.common.core.domain.vo.UserVO;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.ServiceUtil;
|
import com.ruoyi.common.utils.ServiceUtil;
|
||||||
import com.ruoyi.system.user.service.UserService;
|
import com.ruoyi.system.user.service.UserService;
|
||||||
import org.checkerframework.checker.units.qual.A;
|
import org.checkerframework.checker.units.qual.A;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AbnormalConverterImpl implements FaultConverter {
|
public class AbnormalConverterImpl implements FaultConverter {
|
||||||
|
|
||||||
|
@ -69,4 +75,40 @@ public class AbnormalConverterImpl implements FaultConverter {
|
||||||
}
|
}
|
||||||
return po;
|
return po;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canEdit(Long faultId) {
|
||||||
|
return canOperate(Arrays.asList(faultId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canOperate(List<Long> faultIds) {
|
||||||
|
if (SecurityUtils.isSysAdmin()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FaultQuery query = new FaultQuery();
|
||||||
|
query.setId(faultIds.get(0));
|
||||||
|
query.setScope(true);
|
||||||
|
List<FaultVO> faultList = faultService.selectFaultList(query);
|
||||||
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
|
||||||
|
// 判断是否可以处理故障
|
||||||
|
for (Long faultId : faultIds) {
|
||||||
|
FaultVO fault = faultList.stream()
|
||||||
|
.filter(item -> item.getId().equals(faultId))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
if (fault == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean canOperate = isStore(fault, userId);
|
||||||
|
if (!canOperate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isStore(FaultVO fault, Long userId) {
|
||||||
|
return fault != null && fault.getStoreId() != null && fault.getStoreId().equals(userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
package com.ruoyi.bst.fault.service.impl;
|
package com.ruoyi.bst.fault.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.ruoyi.bst.area.domain.AreaQuery;
|
||||||
|
import com.ruoyi.bst.area.domain.AreaVO;
|
||||||
|
import com.ruoyi.bst.fault.domain.enums.FaultHandleStatus;
|
||||||
|
import com.ruoyi.bst.fault.domain.enums.FaultStatus;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
|
import com.ruoyi.common.utils.ServiceUtil;
|
||||||
|
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.bst.fault.mapper.FaultMapper;
|
import com.ruoyi.bst.fault.mapper.FaultMapper;
|
||||||
|
@ -23,19 +31,29 @@ public class FaultServiceImpl implements FaultService
|
||||||
@Autowired
|
@Autowired
|
||||||
private FaultMapper faultMapper;
|
private FaultMapper faultMapper;
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询故障
|
|
||||||
*
|
|
||||||
* @param id 故障主键
|
|
||||||
* @return 故障
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public FaultVO selectFaultById(Long id)
|
public FaultVO selectFaultById(Long id, boolean scope) {
|
||||||
{
|
if (id == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
FaultQuery query = new FaultQuery();
|
||||||
|
query.setId(id);
|
||||||
|
query.setScope(scope);
|
||||||
|
|
||||||
return faultMapper.selectFaultById(id);
|
return this.selectOne(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FaultVO selectOne(FaultQuery query) {
|
||||||
|
PageHelper.startPage(1, 1);
|
||||||
|
List<FaultVO> list = faultMapper.selectFaultList(query);
|
||||||
|
if(list.isEmpty()) {
|
||||||
|
ServiceUtil.assertion(true,"当前故障信息不属于您");
|
||||||
|
}
|
||||||
|
return CollectionUtils.firstElement(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询故障列表
|
* 查询故障列表
|
||||||
*
|
*
|
||||||
|
@ -102,4 +120,20 @@ public class FaultServiceImpl implements FaultService
|
||||||
public FaultVO selectFaultByUserId(Long id) {
|
public FaultVO selectFaultByUserId(Long id) {
|
||||||
return faultMapper.selectFaultByUserId(id);
|
return faultMapper.selectFaultByUserId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FaultVO handle(Fault fault) {
|
||||||
|
FaultVO vo = faultMapper.selectFaultById(fault.getId());
|
||||||
|
ServiceUtil.assertion(vo == null,"当前申报信息不存在");
|
||||||
|
if (vo.getAppealStatus().equals(FaultStatus.PENGDING.getCode()) && fault.getHandle().equals(FaultHandleStatus.REJECTED.getCode())) {
|
||||||
|
vo.setAppealStatus(FaultStatus.REJECTED.getCode());
|
||||||
|
}else
|
||||||
|
if (vo.getAppealStatus().equals(FaultStatus.PENGDING.getCode()) && fault.getHandle().equals(FaultHandleStatus.DO.getCode())) {
|
||||||
|
vo.setAppealStatus(FaultStatus.REPAIRING.getCode());
|
||||||
|
}else
|
||||||
|
if (vo.getAppealStatus().equals(FaultStatus.REPAIRING.getCode()) && fault.getHandle().equals(FaultHandleStatus.DO.getCode())) {
|
||||||
|
vo.setAppealStatus(FaultStatus.COMPLETED.getCode());
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,11 @@ import com.ruoyi.bst.order.service.OrderService;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
|
import com.ruoyi.common.utils.ServiceUtil;
|
||||||
|
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.checkerframework.checker.units.qual.A;
|
import org.checkerframework.checker.units.qual.A;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.ruoyi.bst.fault.domain.FaultQuery;
|
||||||
import com.ruoyi.bst.fault.domain.FaultVO;
|
import com.ruoyi.bst.fault.domain.FaultVO;
|
||||||
import com.ruoyi.bst.fault.domain.enums.FaultHandleStatus;
|
import com.ruoyi.bst.fault.domain.enums.FaultHandleStatus;
|
||||||
import com.ruoyi.bst.fault.domain.enums.FaultStatus;
|
import com.ruoyi.bst.fault.domain.enums.FaultStatus;
|
||||||
|
import com.ruoyi.bst.fault.service.FaultConverter;
|
||||||
import com.ruoyi.bst.fault.service.FaultService;
|
import com.ruoyi.bst.fault.service.FaultService;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
@ -32,6 +33,8 @@ public class FaultController extends BaseController
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
private FaultService faultService;
|
private FaultService faultService;
|
||||||
|
@Autowired
|
||||||
|
private FaultConverter faultConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询故障列表
|
* 查询故障列表
|
||||||
|
@ -67,7 +70,7 @@ public class FaultController extends BaseController
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||||
{
|
{
|
||||||
return success(faultService.selectFaultById(id));
|
return success(faultService.selectFaultById(id,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,17 +118,10 @@ public class FaultController extends BaseController
|
||||||
@ApiOperation("处理申报信息")
|
@ApiOperation("处理申报信息")
|
||||||
@PutMapping("/handle")
|
@PutMapping("/handle")
|
||||||
public AjaxResult update(@RequestBody Fault fault) {
|
public AjaxResult update(@RequestBody Fault fault) {
|
||||||
FaultVO faultVO = faultService.selectFaultById(fault.getId());
|
if (!faultConverter.canEdit(fault.getId())){
|
||||||
if (faultVO.getAppealStatus().equals(FaultStatus.PENGDING.getCode()) && fault.getHandle().equals(FaultHandleStatus.REJECTED.getCode())) {
|
return AjaxResult.error("您没有权限修改id为" + fault.getId() + "的故障申报");
|
||||||
faultVO.setAppealStatus(FaultStatus.REJECTED.getCode());
|
|
||||||
}else
|
|
||||||
if (faultVO.getAppealStatus().equals(FaultStatus.PENGDING.getCode()) && fault.getHandle().equals(FaultHandleStatus.DO.getCode())) {
|
|
||||||
faultVO.setAppealStatus(FaultStatus.REPAIRING.getCode());
|
|
||||||
}else
|
|
||||||
if (faultVO.getAppealStatus().equals(FaultStatus.REPAIRING.getCode()) && fault.getHandle().equals(FaultHandleStatus.DO.getCode())) {
|
|
||||||
faultVO.setAppealStatus(FaultStatus.COMPLETED.getCode());
|
|
||||||
}
|
}
|
||||||
faultService.updateFault(faultVO);
|
faultService.updateFault(faultService.handle(fault));
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user