feat(smartfactory): 新增获取登录用户工厂列表接口
新增接口用于获取登录用户所属工厂列表,无工厂类型限制。主要变化如下: - 在 FactoryInfoController 中添加 getFactoryALlListByLoginUser 方法 - 在 FactoryInfoService接口中定义 getFactoryALlListByLoginUser 方法 - 在 FactoryInfoServiceImpl 中实现 getFactoryALlListByLoginUser 方法 - 修改 FactoryInfoMapper 接口,增加 selectListByType 方法的重载版本
This commit is contained in:
parent
f477c366c4
commit
224a758f11
@ -142,6 +142,15 @@ public class FactoryInfoController {
|
||||
return success(BeanUtils.toBean(factoryInfo, FactorySimpleRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/factory-list-all")
|
||||
@Operation(summary = "取登录用户工厂列表, 登陆用户无工厂则拉取所有工厂 | 用于前端下拉框 | 无工厂类型限制")
|
||||
@PreAuthorize("@ss.hasPermission('smartfactory:factory-info:query')")
|
||||
public CommonResult<List<FactorySimpleRespVO>> getFactoryALlListByLoginUser() {
|
||||
|
||||
List<FactoryInfoDO> factoryInfo = factoryInfoService.getFactoryALlListByLoginUser();
|
||||
return success(BeanUtils.toBean(factoryInfo, FactorySimpleRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get-tree")
|
||||
@Operation(summary = "获得工厂树结构")
|
||||
@PreAuthorize("@ss.hasPermission('smartfactory:factory-info:query')")
|
||||
@ -205,4 +214,4 @@ public class FactoryInfoController {
|
||||
ExcelUtils.write(response, "工厂信息.xls", "数据", FactoryInfoRespVO.class,
|
||||
BeanUtils.toBean(list, FactoryInfoRespVO.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,11 +34,14 @@ public interface FactoryInfoMapper extends BaseMapperX<FactoryInfoDO> {
|
||||
}
|
||||
|
||||
default List<FactoryInfoDO> selectListByType(List<Long> factoryId) {
|
||||
return this.selectListByType(factoryId, Arrays.asList("2","3"));
|
||||
}
|
||||
|
||||
default List<FactoryInfoDO> selectListByType(List<Long> factoryId, List<String> types) {
|
||||
return selectList(new LambdaQueryWrapperX<FactoryInfoDO>()
|
||||
.eq(FactoryInfoDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
|
||||
.inIfPresent(FactoryInfoDO::getId, factoryId)
|
||||
.inIfPresent(FactoryInfoDO::getType, Arrays.asList(2,3)));
|
||||
.inIfPresent(FactoryInfoDO::getType, types));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,4 +61,4 @@ public interface FactoryInfoMapper extends BaseMapperX<FactoryInfoDO> {
|
||||
|
||||
List<FactoryProfitVO> selectProfit(@Param("factoryId") Long factoryId,
|
||||
@Param("month") String month);
|
||||
}
|
||||
}
|
||||
|
@ -164,4 +164,10 @@ public interface FactoryInfoService {
|
||||
* @return 工厂列表
|
||||
*/
|
||||
List<FactoryInfoDO> getList();
|
||||
|
||||
/**
|
||||
* 取登录用户工厂列表, 登陆用户无工厂则拉取所有工厂 | 用于前端下拉框 | 无工厂类型限制
|
||||
* @return
|
||||
*/
|
||||
List<FactoryInfoDO> getFactoryALlListByLoginUser();
|
||||
}
|
||||
|
@ -9,7 +9,10 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.Area;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.*;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryInfoPageReqVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryInfoSaveReqVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryProfitVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactoryUpdateStatusReqVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.FactoryRollDataRespVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo.ProvincesDataRespVO;
|
||||
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
|
||||
@ -23,6 +26,7 @@ import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespD
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -32,7 +36,8 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.smartfactory.enums.ErrorCodeConstants.FACTORY_INFO_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.smartfactory.enums.ErrorCodeConstants.FACTOYRY_EXISTS_STAFF;
|
||||
@ -42,6 +47,7 @@ import static cn.iocoder.yudao.module.smartfactory.enums.ErrorCodeConstants.FACT
|
||||
*
|
||||
* @author 姚君
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Validated
|
||||
public class FactoryInfoServiceImpl implements FactoryInfoService {
|
||||
@ -239,27 +245,7 @@ public class FactoryInfoServiceImpl implements FactoryInfoService {
|
||||
|
||||
@Override
|
||||
public List<FactoryInfoDO> getFactoryListByAuthority() {
|
||||
|
||||
List<Long> factoryIds = new ArrayList<>();
|
||||
DeptDataPermissionRespDTO deptDataPermission = permissionApi.getDeptDataPermission(getLoginUserId()).getCheckedData();
|
||||
// 如果当前登录用户数据权限 不是查看全部数据
|
||||
if (!deptDataPermission.getAll()) {
|
||||
|
||||
// 获取自己所在工厂
|
||||
DeptRespDTO respDTO = deptApi.getDept(userApi.getUser(getLoginUserId()).getCheckedData().getDeptId()).getCheckedData();
|
||||
if (respDTO != null && respDTO.getFactoryId() != null) {
|
||||
factoryIds.add(respDTO.getFactoryId());
|
||||
}
|
||||
|
||||
// 查找担任负责人的工厂信息
|
||||
List<DeptRespDTO> deptRespDTO = deptApi.getDeptByLeaderId(getLoginUserId()).getCheckedData();
|
||||
|
||||
if (deptRespDTO != null) {
|
||||
|
||||
factoryIds.addAll(convertList(deptRespDTO, DeptRespDTO::getFactoryId));
|
||||
}
|
||||
}
|
||||
|
||||
List<Long> factoryIds = this.getFactoryIdsByUserId(getLoginUserId());
|
||||
return factoryInfoMapper.selectListByType(factoryIds);
|
||||
}
|
||||
|
||||
@ -319,19 +305,19 @@ public class FactoryInfoServiceImpl implements FactoryInfoService {
|
||||
// 获取打包扣款明细
|
||||
List<SettlementItemDTO.Deduction> packageDeduction = item.stream()
|
||||
.filter(data -> data.getBusinessType() == 1)
|
||||
.flatMap( data -> data.getDeductionItems().stream())
|
||||
.flatMap(data -> data.getDeductionItems().stream())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 获取叉车扣款明细
|
||||
List<SettlementItemDTO.Deduction> forkliftDeduction = item.stream()
|
||||
.filter(data -> data.getBusinessType() == 2)
|
||||
.flatMap( data -> data.getDeductionItems().stream())
|
||||
.flatMap(data -> data.getDeductionItems().stream())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 获取搬运扣款明细
|
||||
List<SettlementItemDTO.Deduction> porterageDeduction = item.stream()
|
||||
.filter(data -> data.getBusinessType() == 3)
|
||||
.flatMap( data -> data.getDeductionItems().stream())
|
||||
.flatMap(data -> data.getDeductionItems().stream())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 设置打包扣款
|
||||
@ -340,7 +326,7 @@ public class FactoryInfoServiceImpl implements FactoryInfoService {
|
||||
vo.setForkliftDeductionItem(getDeduction(forkliftDeduction));
|
||||
// 设置搬运扣款
|
||||
vo.setPorterageDeductionItem(getDeduction(porterageDeduction));
|
||||
}else {
|
||||
} else {
|
||||
// 设置打包扣款
|
||||
vo.setPackageDeductionItem(getDeduction(null));
|
||||
// 设置叉车扣款
|
||||
@ -392,14 +378,14 @@ public class FactoryInfoServiceImpl implements FactoryInfoService {
|
||||
}
|
||||
|
||||
return deduction;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FactoryInfoDO> getCompanyFactoryList() {
|
||||
|
||||
return factoryInfoMapper.selectList(new LambdaQueryWrapperX<FactoryInfoDO>()
|
||||
.eq(FactoryInfoDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
|
||||
.in(FactoryInfoDO::getType, Arrays.asList(0,1)));
|
||||
.in(FactoryInfoDO::getType, Arrays.asList(0, 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -430,4 +416,38 @@ public class FactoryInfoServiceImpl implements FactoryInfoService {
|
||||
.eq(FactoryInfoDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
|
||||
.orderByAsc(FactoryInfoDO::getType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FactoryInfoDO> getFactoryALlListByLoginUser() {
|
||||
List<Long> factoryIds = this.getFactoryIdsByUserId(getLoginUserId());
|
||||
return factoryInfoMapper.selectListByType(factoryIds, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据当前登录用户获取到工厂ID - {获取当前登录用户所在部门 - 根据所在部门找到所对应的工厂(如果所在部门没有工厂则全部) 返回对应工厂id}
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public List<Long> getFactoryIdsByUserId(Long userId) {
|
||||
List<Long> factoryIds = new ArrayList<>();
|
||||
DeptDataPermissionRespDTO deptDataPermission = permissionApi.getDeptDataPermission(userId).getCheckedData();
|
||||
// 如果当前登录用户数据权限 不是查看全部数据
|
||||
if (!deptDataPermission.getAll()) {
|
||||
// 获取自己所在工厂
|
||||
DeptRespDTO respDTO = deptApi.getDept(userApi.getUser(userId).getCheckedData().getDeptId()).getCheckedData();
|
||||
if (respDTO != null && respDTO.getFactoryId() != null) {
|
||||
factoryIds.add(respDTO.getFactoryId());
|
||||
}
|
||||
|
||||
// 查找担任负责人的工厂信息
|
||||
List<DeptRespDTO> deptRespDTO = deptApi.getDeptByLeaderId(userId).getCheckedData();
|
||||
|
||||
if (deptRespDTO != null) {
|
||||
|
||||
factoryIds.addAll(convertList(deptRespDTO, DeptRespDTO::getFactoryId));
|
||||
}
|
||||
}
|
||||
return factoryIds;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user