| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentDetailedDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentDto; |
| | | import org.jeecg.modules.mdc.entity.*; |
| | | import org.jeecg.modules.mdc.mapper.DncDevicePermissionMapper; |
| | | import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; |
| | | import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper; |
| | | import org.jeecg.modules.mdc.model.MdcEquipmentTree; |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.util.DncCopyEquipment; |
| | | import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil; |
| | | import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil; |
| | | import org.jeecg.modules.mdc.vo.*; |
| | | import org.jeecg.modules.system.entity.*; |
| | | import org.jeecg.modules.system.mapper.DncDevicePermissionMapper; |
| | | import org.jeecg.modules.system.mapper.MdcEquipmentDepartMapper; |
| | | import org.jeecg.modules.system.mapper.MdcProductionEquipmentMapper; |
| | | import org.jeecg.modules.system.service.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | |
| | | |
| | | @Resource |
| | | private DncDevicePermissionMapper dncDevicePermissionMapper; |
| | | |
| | | @Value("${fileNCPath}") |
| | | private String fileNCPath; |
| | | |
| | | |
| | | @Override |
| | |
| | | mdcProductionEquipmentMapper.insert(mdcProductionEquipment); |
| | | } |
| | | } |
| | | //step.3 保存设备对应的产线权限 |
| | | addDevicePermission(mdcEquipment); |
| | | } |
| | | |
| | | @Override |
| | |
| | | break; |
| | | } |
| | | } |
| | | //平移设备目录下现有结构与文件 |
| | | //获取原有结构 |
| | | String OldPath=""; |
| | | String NewPath=""; |
| | | List<String> OldStrings=mdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (OldStrings != null && !OldStrings.isEmpty()) { |
| | | OldPath = fileNCPath+"/"+StringUtils.join(OldStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId(); |
| | | } |
| | | //step.1 修改设备基础信息 |
| | | this.updateById(mdcEquipment); |
| | | //step.2 修改部门 |
| | |
| | | mdcEquipmentDepartMapper.insert(equipmentDepart); |
| | | } |
| | | } |
| | | //删除所有设备权限 |
| | | dncDevicePermissionMapper.delete(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getDeviceId, mdcEquipment.getId())); |
| | | //step.3 修改产线 |
| | | String productions = mdcEquipment.getSelectedProduction(); |
| | | String[] array = {}; |
| | |
| | | mdcProductionEquipmentMapper.insert(productionEquipment); |
| | | } |
| | | } |
| | | List<String> NewStrings = mdcProductionService.findListParentTreeAll(mdcEquipment.getId()); |
| | | if (NewStrings != null && !NewStrings.isEmpty()) { |
| | | NewPath = fileNCPath+"/"+StringUtils.join(NewStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId(); |
| | | } |
| | | // 平移OldPath下的文件到NewPath下 |
| | | DncCopyEquipment.CopyEquipmentPath(OldPath,NewPath); |
| | | //保存设备对应的产线权限 |
| | | addDevicePermission(mdcEquipment); |
| | | //step.4 修改设备权限 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | List<DncDevicePermission> dncDevicePermissions=dncDevicePermissionMapper.selectList(new LambdaQueryWrapper<DncDevicePermission>() |
| | | .eq(DncDevicePermission::getDeviceId, mdcEquipment.getId()).eq(DncDevicePermission ::getUserId, userId)); |
| | | if (CollectionUtils.isEmpty(dncDevicePermissions)){ |
| | | DncDevicePermission dncDevicePermission=new DncDevicePermission(); |
| | | dncDevicePermission.setDeviceId(mdcEquipment.getId()); |
| | | dncDevicePermission.setUserId(userId); |
| | | dncDevicePermissionMapper.insert(dncDevicePermission); |
| | | } |
| | | } |
| | | |
| | | private void addDevicePermission(MdcEquipment mdcEquipment) { |
| | | List<String> productionIds=mdcProductionEquipmentMapper |
| | | .selectList(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, mdcEquipment.getId())) |
| | | .stream().map(MdcProductionEquipment::getProductionId).collect(Collectors.toList()); |
| | | List<MdcUserProduction> mdcUserProductionList=mdcUserProductionService.queryByProductionIds(productionIds); |
| | | mdcUserProductionList.forEach(item->{ |
| | | DncDevicePermission devicePermission=new DncDevicePermission(); |
| | | devicePermission.setDeviceId(mdcEquipment.getId()); |
| | | devicePermission.setUserId(item.getUserId()); |
| | | dncDevicePermissionMapper.insert(devicePermission); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | |
| | | line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id)); |
| | | // 3. 删除设备产线关系 |
| | | line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id)); |
| | | |
| | | // 4. 删除设备权限 |
| | | line += dncDevicePermissionMapper.delete(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, id)); |
| | | return line != 0; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void removeEquipmentForProduction(String productionId, String equipmentId) { |
| | | mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).eq(MdcProductionEquipment::getEquipmentId, equipmentId)); |
| | | //移除设备权限 |
| | | dncDevicePermissionMapper.delete(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, equipmentId)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | |
| | | @Override |
| | | public List<MdcEquipmentTree> loadTreeListByProduction(String userId,String type) { |
| | | public List<MdcEquipmentTree> loadTreeListByProduction(String userId) { |
| | | //获取所有产线数据 |
| | | List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); |
| | | //根据用户id获取拥有的产线信息集合 |
| | |
| | | //组装产线设备树 |
| | | List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); |
| | | //填充设备数据 |
| | | FillEquipmentByProduction(treeList,type); |
| | | FillEquipmentByProduction(treeList); |
| | | return treeList; |
| | | } |
| | | |
| | |
| | | /** |
| | | * 产线设备树填充设备数据 |
| | | */ |
| | | private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList,String type) { |
| | | private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) { |
| | | for (MdcEquipmentTree mdcEquipmentTree : treeList) { |
| | | List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey(),type); |
| | | List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey()); |
| | | if (equipmentList != null && !equipmentList.isEmpty()) { |
| | | for (MdcEquipment mdcEquipment : equipmentList) { |
| | | MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment); |
| | |
| | | mdcEquipmentTree.setLeaf(false); |
| | | } |
| | | if (!mdcEquipmentTree.getChildren().isEmpty()) { |
| | | FillEquipmentByProduction(mdcEquipmentTree.getChildren(),type); |
| | | FillEquipmentByProduction(mdcEquipmentTree.getChildren()); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids,String type) { |
| | | public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids) { |
| | | List<String> productionIds = Arrays.asList(ids.split(",")); |
| | | //获取所有产线数据 |
| | | List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); |
| | |
| | | //组装产线设备树 |
| | | List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); |
| | | //填充设备数据 |
| | | FillEquipmentByProduction(treeList,type); |
| | | FillEquipmentByProduction(treeList); |
| | | return treeList; |
| | | } |
| | | |