| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringPool; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.DataBaseConstant; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | import org.jeecg.modules.eam.constant.AssetStatusEnum; |
| | | import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus; |
| | | import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum; |
| | | import org.jeecg.modules.eam.constant.EquipmentRepairStatus; |
| | | import org.jeecg.modules.eam.dto.EquipmentCategoryStatistics; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentExtend; |
| | | import org.jeecg.modules.eam.mapper.EamEquipmentMapper; |
| | |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.tree.FindsEquipmentProductionUtil; |
| | | import org.jeecg.modules.eam.vo.EamEquipmentTree; |
| | | import org.jeecg.modules.eam.vo.EquipmentSearchResult; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.entity.SysCategory; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | | import org.jeecgframework.poi.excel.entity.ExportParams; |
| | | import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | |
| | | /** |
| | | * @Description: 设备台账 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-03-19 |
| | | * @Date: 2025-03-19 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | |
| | | private IEamEquipmentExtendService equipmentExtendService; |
| | | @Autowired |
| | | private IMdcProductionService mdcProductionService; |
| | | |
| | | @Value("${jeecg.path.upload}") |
| | | private String upLoadPath; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | @Override |
| | | public IPage<EamEquipment> queryPageList(IPage<EamEquipment> page, EamEquipmentQuery eamEquipment) { |
| | | QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); |
| | | //用户权限 |
| | | queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if(sysUser == null){ |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id=? and t.pro_id=e.org_id", sysUser.getId()); |
| | | if(eamEquipment != null){ |
| | | if(StringUtils.isNotBlank(eamEquipment.getEquipmentCode())){ |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据车间过滤设备 |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id", sysUser.getId()); |
| | | } |
| | | //查询条件过滤 |
| | | if (eamEquipment != null) { |
| | | if (StringUtils.isNotBlank(eamEquipment.getEquipmentCode())) { |
| | | queryWrapper.like("e.equipment_code", eamEquipment.getEquipmentCode()); |
| | | } |
| | | if(StringUtils.isNotBlank(eamEquipment.getEquipmentName())){ |
| | | if (StringUtils.isNotBlank(eamEquipment.getEquipmentName())) { |
| | | queryWrapper.like("e.equipment_name", eamEquipment.getEquipmentName()); |
| | | } |
| | | if(StringUtils.isNotBlank(eamEquipment.getEquipmentImportance())){ |
| | | if (StringUtils.isNotBlank(eamEquipment.getEquipmentImportance())) { |
| | | queryWrapper.eq("e.equipment_importance", eamEquipment.getEquipmentImportance()); |
| | | } |
| | | if(StringUtils.isNotBlank(eamEquipment.getAssetStatus())){ |
| | | if (StringUtils.isNotBlank(eamEquipment.getAssetStatus())) { |
| | | queryWrapper.like("e.asset_status", eamEquipment.getAssetStatus()); |
| | | } |
| | | if(StringUtils.isNotBlank(eamEquipment.getTechnologyStatus())){ |
| | | if (StringUtils.isNotBlank(eamEquipment.getTechnologyStatus())) { |
| | | queryWrapper.like("e.technology_status", eamEquipment.getTechnologyStatus()); |
| | | } |
| | | if(StringUtils.isNotBlank(eamEquipment.getOperationSystem())){ |
| | | if (StringUtils.isNotBlank(eamEquipment.getOperationSystem())) { |
| | | queryWrapper.like("e.operation_system", eamEquipment.getOperationSystem()); |
| | | } |
| | | if(StringUtils.isNotBlank(eamEquipment.getOrgId())){ |
| | | queryWrapper.like("e.org_id", eamEquipment.getOrgId()); |
| | | if (StringUtils.isNotBlank(eamEquipment.getManufacturingEnterprise())) { |
| | | queryWrapper.like("e.manufacturing_enterprise", eamEquipment.getManufacturingEnterprise()); |
| | | } |
| | | if(StringUtils.isNotBlank(eamEquipment.getEquipmentCategory())){ |
| | | if (StringUtils.isNotBlank(eamEquipment.getOriginalValue())) { |
| | | queryWrapper.like("e.original_value", eamEquipment.getOriginalValue()); |
| | | } |
| | | if (StringUtils.isNotBlank(eamEquipment.getPerformanceIndicators())) { |
| | | queryWrapper.like("e.performance_indicators", eamEquipment.getPerformanceIndicators()); |
| | | } |
| | | if(oConvertUtils.isNotEmpty(eamEquipment.getLeaveFactoryStartTime()) && oConvertUtils.isNotEmpty(eamEquipment.getLeaveFactoryEndTime())){ |
| | | queryWrapper.ge("e.leave_factory_date",eamEquipment.getLeaveFactoryStartTime()); |
| | | queryWrapper.le("e.leave_factory_date",eamEquipment.getLeaveFactoryEndTime()); |
| | | } |
| | | if(oConvertUtils.isNotEmpty(eamEquipment.getAcceptanceCheckStartTime()) && oConvertUtils.isNotEmpty(eamEquipment.getAcceptanceCheckEndTime())){ |
| | | queryWrapper.ge("e.acceptance_check_date",eamEquipment.getAcceptanceCheckStartTime()); |
| | | queryWrapper.le("e.acceptance_check_date",eamEquipment.getAcceptanceCheckEndTime()); |
| | | } |
| | | if (StringUtils.isNotBlank(eamEquipment.getOrgId())) { |
| | | //车间编码不为空 |
| | | List<String> productIds = mdcProductionService.recursionChildren(eamEquipment.getOrgId()); |
| | | if (CollectionUtil.isNotEmpty(productIds)) { |
| | | //不做筛选 |
| | | queryWrapper.in("e.org_id", productIds); |
| | | } |
| | | } |
| | | if (StringUtils.isNotBlank(eamEquipment.getEquipmentCategory())) { |
| | | queryWrapper.like("e.equipment_category", eamEquipment.getEquipmentCategory()); |
| | | } |
| | | //排序 |
| | | if(StringUtils.isNotBlank(eamEquipment.getColumn()) && StringUtils.isNotBlank(eamEquipment.getOrder())){ |
| | | //queryWrapper.like("column", eamEquipment.getColumn()); |
| | | queryWrapper.orderByDesc("e.create_time"); |
| | | }else { |
| | | queryWrapper.orderByDesc("e.create_time"); |
| | | if (StringUtils.isNotBlank(eamEquipment.getEquipmentUse())) { |
| | | queryWrapper.like("e.equipment_use", eamEquipment.getEquipmentUse()); |
| | | } |
| | | }else { |
| | | queryWrapper.orderByDesc("e.create_time"); |
| | | if (StringUtils.isNotBlank(eamEquipment.getId())) { |
| | | queryWrapper.eq("e.id", eamEquipment.getId()); |
| | | } |
| | | //排序 |
| | | if (StringUtils.isNotBlank(eamEquipment.getColumn()) && StringUtils.isNotBlank(eamEquipment.getOrder())) { |
| | | //queryWrapper.like("column", eamEquipment.getColumn()); |
| | | String column = eamEquipment.getColumn(); |
| | | if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) { |
| | | column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX)); |
| | | } |
| | | if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(eamEquipment.getOrder())) { |
| | | queryWrapper.orderByAsc("e." + oConvertUtils.camelToUnderline(column)); |
| | | } else { |
| | | queryWrapper.orderByAsc("e." + oConvertUtils.camelToUnderline(column)); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByAsc("e.equipment_code"); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByAsc("e.equipment_code"); |
| | | } |
| | | |
| | | IPage<EamEquipment> ipage = eamEquipmentMapper.queryPageList(page, queryWrapper); |
| | | IPage<EamEquipment> ipage = eamEquipmentMapper.queryPageList(page, queryWrapper); |
| | | return ipage; |
| | | } |
| | | |
| | | @Override |
| | | public List<EquipmentSearchResult> asyncLoadEquipment(String keyword, Integer pageSize, String id) { |
| | | if (StringUtils.isNotBlank(id)) { |
| | | EamEquipment eamEquipment = eamEquipmentMapper.selectById(id); |
| | | if (eamEquipment != null) { |
| | | List<EquipmentSearchResult> resultList = new ArrayList<>(); |
| | | resultList.add(new EquipmentSearchResult(eamEquipment)); |
| | | return resultList; |
| | | } |
| | | } |
| | | IPage<EamEquipment> page = new Page<>(1, pageSize); |
| | | QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | queryWrapper.in("equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据车间过滤设备 |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=org_id", sysUser.getId()); |
| | | } |
| | | if (StringUtils.isNotBlank(keyword)) { |
| | | queryWrapper.like("equipment_code", keyword); |
| | | queryWrapper.or().like("equipment_name", keyword); |
| | | } |
| | | queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0); |
| | | IPage<EamEquipment> pageResult = eamEquipmentMapper.queryPageList(page, queryWrapper); |
| | | if (pageResult != null && CollectionUtil.isNotEmpty(pageResult.getRecords())) { |
| | | List<EquipmentSearchResult> resultList = new ArrayList<>(); |
| | | pageResult.getRecords().forEach((record) -> { |
| | | resultList.add(new EquipmentSearchResult(record)); |
| | | }); |
| | | return resultList; |
| | | } |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | @Override |
| | | public EamEquipment selectByEquipmentCode(String equipmentCode) { |
| | | if (StringUtils.isBlank(equipmentCode)) { |
| | | return null; |
| | | } |
| | | QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return null; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | queryWrapper.in("equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据车间过滤设备 |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=org_id", sysUser.getId()); |
| | | } |
| | | queryWrapper.eq("equipment_code", equipmentCode); |
| | | queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0); |
| | | |
| | | return eamEquipmentMapper.selectOne(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<EquipmentCategoryStatistics> queryLedgerStatistics() { |
| | | List<EquipmentCategoryStatistics> list = Lists.newArrayList(); |
| | | //获取所有已设置设备类别的设备信息 |
| | | List<EamEquipment> equipmentList = this.list(new LambdaQueryWrapper<EamEquipment>().isNotNull(EamEquipment::getEquipmentType)); |
| | | |
| | | //获取分类字典二级、三级以下包含当前分类的所有分类id |
| | | List<SysCategory> categoryTypeMap = eamEquipmentMapper.getCategoryTypeMap(); |
| | | if (CollectionUtils.isEmpty(equipmentList) || CollectionUtils.isEmpty(categoryTypeMap)) { |
| | | return list; |
| | | } |
| | | for (SysCategory sysCategory : categoryTypeMap) { |
| | | List<EamEquipment> eamEquipmentList = equipmentList.stream().filter(eamEquipment -> Arrays.asList(sysCategory.getChildCodes().split(StringPool.COMMA)).contains(eamEquipment.getEquipmentType())).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(eamEquipmentList)) { |
| | | continue; |
| | | } |
| | | EquipmentCategoryStatistics statistics = new EquipmentCategoryStatistics(); |
| | | statistics.setEquipmentType(sysCategory.getName()); |
| | | |
| | | //设置设备总数 |
| | | statistics.setEquipmentCount(eamEquipmentList.size()); |
| | | statistics.setOriginalValue(eamEquipmentList.stream().filter(eamEquipment -> eamEquipment.getOriginalValue() != null).map(EamEquipment::getOriginalValue).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | |
| | | //设置高精度信息 |
| | | List<EamEquipment> equipmentCategoryList = eamEquipmentList.stream().filter(eamEquipment -> "JMSB".equals(eamEquipment.getEquipmentCategory())).collect(Collectors.toList()); |
| | | statistics.setHighPrecisionCount(CollectionUtils.isNotEmpty(equipmentCategoryList) ? equipmentCategoryList.size() : 0); |
| | | statistics.setHighPrecisionOriginalValue(CollectionUtils.isNotEmpty(equipmentCategoryList) ? equipmentCategoryList.stream().map(eamEquipment -> eamEquipment.getOriginalValue() != null ? eamEquipment.getOriginalValue() : BigDecimal.ZERO).reduce(BigDecimal.ZERO, BigDecimal::add) : BigDecimal.ZERO); |
| | | |
| | | //设置国产信息 |
| | | List<EamEquipment> equipmentDomesticList = eamEquipmentList.stream().filter(eamEquipment -> "china".equals(eamEquipment.getOriginCountry())).collect(Collectors.toList()); |
| | | statistics.setDomesticCount(CollectionUtils.isNotEmpty(equipmentDomesticList) ? equipmentDomesticList.size() : 0); |
| | | statistics.setDomesticOriginalValue(CollectionUtils.isNotEmpty(equipmentDomesticList) ? equipmentDomesticList.stream().map(eamEquipment -> eamEquipment.getOriginalValue() != null ? eamEquipment.getOriginalValue() : BigDecimal.ZERO).reduce(BigDecimal.ZERO, BigDecimal::add) : BigDecimal.ZERO); |
| | | |
| | | //设置进口信息 |
| | | List<EamEquipment> equipmentImportList = eamEquipmentList.stream().filter(eamEquipment -> !"china".equals(eamEquipment.getOriginCountry())).collect(Collectors.toList()); |
| | | statistics.setImportCount(CollectionUtils.isNotEmpty(equipmentImportList) ? equipmentImportList.size() : 0); |
| | | statistics.setImportOriginalValue(CollectionUtils.isNotEmpty(equipmentImportList) ? equipmentImportList.stream().map(eamEquipment -> eamEquipment.getOriginalValue() != null ? eamEquipment.getOriginalValue() : BigDecimal.ZERO).reduce(BigDecimal.ZERO, BigDecimal::add) : BigDecimal.ZERO); |
| | | |
| | | //设置完好信息 |
| | | List<EamEquipment> equipmentIntactList = eamEquipmentList.stream().filter(eamEquipment -> StringPool.ONE.equals(eamEquipment.getTechnologyStatus())).collect(Collectors.toList()); |
| | | statistics.setIntactCount(CollectionUtils.isNotEmpty(equipmentIntactList) ? equipmentIntactList.size() : 0); |
| | | statistics.setIntactOriginalValue(CollectionUtils.isNotEmpty(equipmentIntactList) ? equipmentIntactList.stream().map(eamEquipment -> eamEquipment.getOriginalValue() != null ? eamEquipment.getOriginalValue() : BigDecimal.ZERO).reduce(BigDecimal.ZERO, BigDecimal::add) : BigDecimal.ZERO); |
| | | list.add(statistics); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public ModelAndView exportLedgerStatisticsXls(HttpServletRequest request, Class<EquipmentCategoryStatistics> clazz, String title) { |
| | | // 获取导出人 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | |
| | | // Step.2 获取导出数据 |
| | | List<EquipmentCategoryStatistics> exportList = queryLedgerStatistics(); |
| | | |
| | | // Step.3 AutoPoi 导出Excel |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | //此处设置的filename无效 ,前端会重更新设置一下 |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, title); |
| | | mv.addObject(NormalExcelConstants.CLASS, clazz); |
| | | //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置-------------------- |
| | | ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title); |
| | | exportParams.setImageBasePath(upLoadPath); |
| | | //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置---------------------- |
| | | mv.addObject(NormalExcelConstants.PARAMS, exportParams); |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, exportList); |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * 获取所有的产线id(包含所有上级) |
| | | */ |