| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.constants.AssetDeptConstant; |
| | | import com.ruoyi.system.dto.asset.AssetAdMaterialPriceDTO; |
| | | import com.ruoyi.system.mapper.AssetAdMaterialPriceMapper; |
| | | import com.ruoyi.system.model.AssetAdMaterialPrice; |
| | | import com.ruoyi.system.query.AssetAdMaterialPriceQuery; |
| | | import com.ruoyi.system.service.AssetAdMaterialPriceService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.vo.asset.AssetAdMaterialPriceVO; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2025-09-15 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor(onConstructor_ = {@Lazy}) |
| | | public class AssetAdMaterialPriceServiceImpl extends ServiceImpl<AssetAdMaterialPriceMapper, AssetAdMaterialPrice> implements AssetAdMaterialPriceService { |
| | | private final ISysUserService sysUserService; |
| | | @Override |
| | | public void addAssetAdMaterialPrice(AssetAdMaterialPriceDTO dto) { |
| | | AssetAdMaterialPrice entity = BeanUtil.copyProperties(dto, AssetAdMaterialPrice.class); |
| | | entity.setDeptId(Integer.parseInt(SecurityUtils.getLoginUser().getUser().getDeptId())); |
| | | entity.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName()); |
| | | entity.setCreateTime(LocalDateTime.now()); |
| | | save(entity); |
| | | } |
| | | |
| | | @Override |
| | | public void editAssetAdMaterialPrice(AssetAdMaterialPriceDTO dto) { |
| | | AssetAdMaterialPrice entity = BeanUtil.copyProperties(dto, AssetAdMaterialPrice.class); |
| | | entity.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName()); |
| | | entity.setUpdateTime(LocalDateTime.now()); |
| | | updateById(entity); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<AssetAdMaterialPriceVO> getPageList(AssetAdMaterialPriceQuery query) { |
| | | // 数据权限:超级管理员/资产管理部查看所有数据,其他部门查看当前及下级部门的数据 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | boolean isAdmin = SecurityUtils.isAdmin(userId); |
| | | |
| | | if (!isAdmin) { |
| | | try { |
| | | // 获取当前用户的部门名称 |
| | | String deptName = sysUserService.selectUserById(userId).getDeptName(); |
| | | |
| | | // 非超级管理员且非资产管理部,设置部门权限 |
| | | if (!AssetDeptConstant.ASSET_INVENTORY_DEPT_NAMES.contains(deptName)) { |
| | | query.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId())); |
| | | } |
| | | } catch (Exception e) { |
| | | // 如果获取部门信息失败,默认设置部门权限 |
| | | try { |
| | | query.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId())); |
| | | } catch (Exception ex) { |
| | | // ignore parse, leave null if cannot parse |
| | | } |
| | | } |
| | | } |
| | | // 直接使用Mapper的分页查询方法 |
| | | Page<AssetAdMaterialPriceVO> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | return baseMapper.getPageList(page, query); |
| | | } |
| | | |
| | | @Override |
| | | public AssetAdMaterialPriceVO getDetail(Integer id) { |
| | | AssetAdMaterialPrice entity = getById(id); |
| | | if (entity == null) { |
| | | return null; |
| | | } |
| | | return BeanUtil.copyProperties(entity, AssetAdMaterialPriceVO.class); |
| | | } |
| | | |
| | | @Override |
| | | public void importAssetAdMaterialPrice(List<AssetAdMaterialPriceDTO> list) { |
| | | if (CollUtil.isNotEmpty(list)) { |
| | | String currentUser = SecurityUtils.getLoginUser().getUser().getNickName(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | List<AssetAdMaterialPrice> entities = list.stream().map(dto -> { |
| | | AssetAdMaterialPrice entity = BeanUtil.copyProperties(dto, AssetAdMaterialPrice.class); |
| | | entity.setCreateBy(currentUser); |
| | | entity.setCreateTime(now); |
| | | return entity; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | saveBatch(entities); |
| | | } |
| | | } |
| | | } |