From dbe3ed318dfe013663271fd64c8b8b152005e0b6 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 08 十月 2024 09:31:32 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pms-SV --- pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/schedule/ScheduleSv.java | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 153 insertions(+), 0 deletions(-) diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/schedule/ScheduleSv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/schedule/ScheduleSv.java new file mode 100644 index 0000000..5c35d2c --- /dev/null +++ b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/schedule/ScheduleSv.java @@ -0,0 +1,153 @@ +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 lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.common.utils.PojoUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class ScheduleSv { + private PrScheduleMapper scheduleDao; + 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 count; + } + @Transactional + public int update(PrSchedule schedule) { + scheduleRelDao.deleteByScheduleId(schedule.id); + saveRel(schedule); + return scheduleDao.updateByPrimaryKeySelective(schedule); + } + + private void saveRel(PrSchedule schedule) { + schedule.relList.forEach(rel -> validateRelData(rel, schedule)); + schedule.relList.forEach(rel -> scheduleRelDao.insertSelective(rel)); + } + + private void validateRelData(PrScheduleRel rel, PrSchedule schedule) { + validatePlan(rel); + validateStation(rel); + rel.scheduleId = schedule.id; + } + + private void validatePlan(PrScheduleRel rel) { + if (rel.planId != null && rel.nodeId != null) { + long countPlan = assemblyPlanDao.countByPlanIdAndNodeId(rel.planId, rel.nodeId); + if (countPlan == 0) { + log.error("鎺掔彮鏁版嵁涓嶅尮閰�, planId:{}, nodeId:{}", rel.planId, rel.nodeId); + throw new RuntimeException("鎺掔彮鏁版嵁涓嶅尮閰�, planId:" + rel.planId + ", nodeId:" + rel.nodeId); + } + } + } + + private void validateStation(PrScheduleRel rel) { + if (rel.stationId != null) { + Optional<PltStation> stationOpt = Optional.ofNullable(stationDao.selectByPrimaryKey(rel.stationId)); + stationOpt.orElseThrow(() -> { + log.error("宸ョ珯淇℃伅涓嶅瓨鍦�, stationId:{}", rel.stationId); + return new RuntimeException("宸ョ珯淇℃伅涓嶅瓨鍦�, stationId:" + rel.stationId); + }); + } + } + + public PrSchedule selectById(Long 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); + //璁$畻鍒嗛〉绛変俊鎭� + rsVo.calculateAndSet(itemTotal, params); + //鏌ヨ绗﹀悎鏉′欢鐨勮褰� + rsVo.obj = scheduleDao.selectSome(params); + return rsVo; + } + + public List<JSONObject> selectPlan(QueryVo vo) { + List<JSONObject> list = assemblyPlanDao.selectByPlanName(vo.planName); + Map<String, JSONObject> map = new ConcurrentHashMap<>(); // 浣跨敤骞跺彂瀹夊叏鐨凪ap + 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) { + return scheduleDao.selectAll(queryVo.scheduleDate, queryVo.userId); + } +} -- Gitblit v1.8.0