|  |  | 
 |  |  | package com.dy.pmsProduct.schedule; | 
 |  |  |  | 
 |  |  | import cn.hutool.json.JSONArray; | 
 |  |  | import cn.hutool.json.JSONObject; | 
 |  |  | import com.dy.common.webUtil.QueryResultVo; | 
 |  |  | import com.dy.pmsGlobal.daoBa.BaUserMapper; | 
 |  |  | import com.dy.pmsGlobal.daoPlt.PltStationMapper; | 
 |  |  | import com.dy.pmsGlobal.daoPr.PrAssemblyPlanMapper; | 
 |  |  | import com.dy.pmsGlobal.daoPr.PrScheduleMapper; | 
 |  |  | import com.dy.pmsGlobal.daoPr.PrScheduleRelMapper; | 
 |  |  | import com.dy.pmsGlobal.pojoBa.BaUser; | 
 |  |  | import com.dy.pmsGlobal.pojoPlt.PltStation; | 
 |  |  | import com.dy.pmsGlobal.pojoPr.PrSchedule; | 
 |  |  | import com.dy.pmsGlobal.pojoPr.PrScheduleRel; | 
 |  |  | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  | import java.util.Optional; | 
 |  |  | import java.util.concurrent.ConcurrentHashMap; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | @Slf4j | 
 |  |  | @Service | 
 |  |  | 
 |  |  |     private PrScheduleRelMapper scheduleRelDao; | 
 |  |  |     private PrAssemblyPlanMapper assemblyPlanDao; | 
 |  |  |     private PltStationMapper stationDao; | 
 |  |  |     private BaUserMapper baUserDao; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     public void setStationDao(PltStationMapper stationDao) { | 
 |  |  |         this.stationDao = stationDao; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     public void setScheduleRelDao(PrScheduleRelMapper scheduleRelDao) { | 
 |  |  |         this.scheduleRelDao = scheduleRelDao; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     public void setAssemblyPlanDao(PrAssemblyPlanMapper assemblyPlanDao) { | 
 |  |  |         this.assemblyPlanDao = assemblyPlanDao; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     public void setScheduleDao(PrScheduleMapper scheduleDao) { | 
 |  |  |         this.scheduleDao = scheduleDao; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private void setBaUserMapper(BaUserMapper baUserDao) { | 
 |  |  |         this.baUserDao = baUserDao; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional | 
 |  |  |     public int save(PrSchedule schedule) { | 
 |  |  |         int count = scheduleDao.insertSelective(schedule); | 
 |  |  | 
 |  |  |         saveRel(schedule); | 
 |  |  |         return scheduleDao.updateByPrimaryKeySelective(schedule); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void saveRel(PrSchedule schedule) { | 
 |  |  |         schedule.relList.forEach(rel ->validateRelData(rel, schedule)); | 
 |  |  |         schedule.relList.forEach(rel -> validateRelData(rel, schedule)); | 
 |  |  |         schedule.relList.forEach(rel -> scheduleRelDao.insertSelective(rel)); | 
 |  |  |     } | 
 |  |  |     private void validateRelData(PrScheduleRel rel,PrSchedule schedule) { | 
 |  |  |  | 
 |  |  |     private void validateRelData(PrScheduleRel rel, PrSchedule schedule) { | 
 |  |  |         validatePlan(rel); | 
 |  |  |         validateStation(rel); | 
 |  |  |         rel.scheduleId = schedule.id; | 
 |  |  | 
 |  |  |         return scheduleDao.selectByPrimaryKey(id); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public List<BaUser> selectById() { | 
 |  |  |         List<BaUser> userList = baUserDao.getUserList(); | 
 |  |  |         return userList; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public QueryResultVo<List<PrSchedule>> selectSome(QueryVo vo) { | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo); | 
 |  |  |         //查询符合条件的记录总数 | 
 |  |  |         Long itemTotal = scheduleDao.selectSomeCount(params); | 
 |  |  |         QueryResultVo<List<PrSchedule>> rsVo = new QueryResultVo<>(vo.pageSize, vo.pageCurr) ; | 
 |  |  |         QueryResultVo<List<PrSchedule>> rsVo = new QueryResultVo<>(vo.pageSize, vo.pageCurr); | 
 |  |  |         //计算分页等信息 | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         //查询符合条件的记录 | 
 |  |  | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public List<Map<String, Object>> selectPlan(QueryVo vo) { | 
 |  |  |         List<Map<String,Object>> list = assemblyPlanDao.selectByPlanName(vo.planName); | 
 |  |  |  | 
 |  |  |         return list; | 
 |  |  |     public List<JSONObject> selectPlan(QueryVo vo) { | 
 |  |  |         List<JSONObject> list = assemblyPlanDao.selectByPlanName(vo.planName); | 
 |  |  |         Map<String, JSONObject> map = new ConcurrentHashMap<>(); // 使用并发安全的Map | 
 |  |  |         for(JSONObject item:list){ | 
 |  |  |             String planId = String.valueOf(item.getObj("planId")); | 
 |  |  |             JSONObject innerObject = new JSONObject() | 
 |  |  |                     .set("nodeId", String.valueOf(item.getObj("nodeId"))) | 
 |  |  |                     .set("content", item.getObj("content")); | 
 |  |  |             if(map.containsKey(planId)){ | 
 |  |  |                 JSONArray array = (JSONArray)map.get(planId).get("nodes"); | 
 |  |  |                 array.add(innerObject); | 
 |  |  |             }else{ | 
 |  |  |                 JSONArray array = new JSONArray(); | 
 |  |  |                 array.add(innerObject); | 
 |  |  |                 JSONObject outObject= new JSONObject() | 
 |  |  |                         .set("planId", planId) | 
 |  |  |                         .set("planName", item.getObj("planName")) | 
 |  |  |                         .set("nodes", array); | 
 |  |  |                 map.put(planId,outObject); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return map.values().stream().collect(Collectors.toList()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public List<PrSchedule> selectAll(QueryVo queryVo) { |