src/main/java/com/whyc/controller/BattDischargePlanTempController.java
@@ -52,6 +52,19 @@ } /** * 创建到临时表中 * @param resetCapPercent * @param startTime * @return * @throws ParseException */ @ApiOperation("创建放电计划审批清单") @GetMapping("generateDischargePlan2") public Response addGenerateDischargePlan2(@RequestParam Float resetCapPercent,@RequestParam String startTime) throws ParseException { return service.generateDischargePlan2(resetCapPercent,startTime); } /** * 取消创建的临时表 * @param startTime * @return src/main/java/com/whyc/mapper/AlarmManualClearMapper.java
@@ -8,4 +8,6 @@ public interface AlarmManualClearMapper extends CustomMapper<AlarmManualClear> { List<AlarmManualClear> getAll(AlarmManualClear param); List<Integer> getAllMainIds(); } src/main/java/com/whyc/mapper/BaoJiGroupBattGroupMapper.java
@@ -4,6 +4,7 @@ import com.whyc.pojo.Battinf; import com.whyc.pojo.BaojiGroupBattGroup; import com.whyc.pojo.UserInf; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -36,4 +37,6 @@ List<BaojiGroupBattGroup> getStationIdListWithDischargePlanFlag(); List<BaojiGroupBattGroup> getBaoJiGroupListWithinBattGroupListOfUser(@Param("userId") int userId); } src/main/java/com/whyc/mapper/BattDischargePlanTempMapper.java
@@ -11,4 +11,8 @@ BattDischargePlanTemp getValidOneByYear(@Param("planYear") int planYear); BattDischargePlanTemp getValidOneByYearOfUser(int planYear, int userId); List<BattDischargePlanTemp> getOccupiedTempList(); } src/main/java/com/whyc/pojo/WorkflowMain.java
@@ -97,6 +97,8 @@ @TableField(exist = false) private Map<String, Object> faultMap; private boolean FaultUploadDone; public WorkflowMain(Integer id, Integer status, String endReason, Date endTime) { this.id = id; this.status = status; @@ -323,4 +325,12 @@ public void setFaultMap(Map<String, Object> faultMap) { this.faultMap = faultMap; } public boolean isFaultUploadDone() { return FaultUploadDone; } public void setFaultUploadDone(boolean faultUploadDone) { FaultUploadDone = faultUploadDone; } } src/main/java/com/whyc/service/AlarmManualClearService.java
@@ -164,4 +164,12 @@ }); return new Response().set(1,pageInfo); } /** * 查询实施表中所有的main_id * @return */ public List<Integer> getAllMainIds(){ return mapper.getAllMainIds(); } } src/main/java/com/whyc/service/BaoJiGroupBattGroupService.java
@@ -99,4 +99,8 @@ public List<BaojiGroupBattGroup> getBaoJiGroupListWithinBattGroupList() { return mapper.getBaoJiGroupListWithinBattGroupList(); } public List<BaojiGroupBattGroup> getBaoJiGroupListWithinBattGroupListOfUser(int userId) { return mapper.getBaoJiGroupListWithinBattGroupListOfUser(userId); } } src/main/java/com/whyc/service/BaoJiGroupUserService.java
@@ -1,5 +1,7 @@ package com.whyc.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.gson.internal.$Gson$Types; import com.whyc.mapper.BaoJiGroupUserMapper; import com.whyc.mapper.UserInfMapper; @@ -70,4 +72,11 @@ Integer flag = mapper.getGroupFlag(userId); return flag != null && flag == 1; } public List<BaoJiGroupUser> getGroupListByUserId(int userId) { QueryWrapper<BaoJiGroupUser> query = Wrappers.query(); query.eq("uId",userId); return mapper.selectList(query); } } src/main/java/com/whyc/service/BattAlarmDataVerifyService.java
@@ -7,8 +7,10 @@ import com.whyc.dto.paramter.AlarmPar; import com.whyc.mapper.BattAlarmDataVerifyMapper; import com.whyc.pojo.BattAlarmDataVerify; import com.whyc.pojo.WorkflowMain; import com.whyc.util.ActionUtil; import com.whyc.util.MessageUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -20,14 +22,22 @@ @Resource private BattAlarmDataVerifyMapper mapper; @Autowired private AlarmManualClearService clearService; public Response<Object> getPage(AlarmPar param) { List<Integer> allMainIds = clearService.getAllMainIds(); //int userId = ActionUtil.getUser().getUId().intValue(); PageHelper.startPage(param.getPage().getPageCurr(),param.getPage().getPageSize()); List<BattAlarmDataVerify> list = mapper.getList(param); list.stream().forEach(data -> { for (BattAlarmDataVerify data : list) { data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmSignalId())); }); WorkflowMain main = data.getMain(); if (main != null && allMainIds.contains(main.getId())){ main.setFaultUploadDone(true); } } PageInfo<BattAlarmDataVerify> pageInfo = new PageInfo<>(list); return new Response<>().set(1,pageInfo); } src/main/java/com/whyc/service/BattDischargePlanTempService.java
@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.whyc.constant.RoleEnum; import com.whyc.constant.WorkflowDischargePlanEnum; import com.whyc.constant.WorkflowEnum; import com.whyc.dto.Response; @@ -242,6 +243,140 @@ } /** * 原则: * 0.每个站点只取第一组电池参与放电计划 * 1.每天最多1个节点站,每天最多3个放电站点 * 2.各班组尽量扁平,尽量保证各个组完全放电完成时间接近 * @return * @param resetCapPercent * @param startTimeStr */ @Transactional public Response generateDischargePlan2(Float resetCapPercent, String startTimeStr) throws ParseException { int userId = ActionUtil.getUser().getUId().intValue(); List<BattDischargePlanTemp> tempList = new LinkedList<>(); Date startTime = DateUtil.YYYY_MM_DD_HH_MM_SS.parse(startTimeStr); Calendar planTime = Calendar.getInstance(); planTime.setTime(startTime); //校验当前用户是否为管理员且只存在于一个包机组 int resultValue = checkUser(userId); if(resultValue == 2){ return new Response().set(1,false,"当前用户不是管理员"); }else if(resultValue == 3){ return new Response().set(1,false,"当前用户管理多个包机组,无法生成单个包机组放电计划"); } //一年度当前用户只能生成一次审核通过的放电计划,校验 int planYear = planTime.get(Calendar.YEAR); BattDischargePlanTemp tempDB = getValidOneByYearOfUser(planYear,userId); if(tempDB!=null){ return new Response().set(1,false,"当前年度已存在计划审批清单,无法重复生成"); } //查询所有可用的组以及每个组的站点 //planTime校验,避开节假日和周六日,TODO 以及已经审批占用的时间 planTime = checkAndGetPlanTime(planTime); List<BaojiGroupBattGroup> baoJiGroupListWithinBattGroupList = baoJiGroupBattGroupService.getBaoJiGroupListWithinBattGroupListOfUser(userId); //List<BattdischargePlan> planList = new LinkedList<>(); List<Battinf> planList = new LinkedList<>(); int prePlanSize = 3; int planSize = 0; while (prePlanSize != planSize && baoJiGroupListWithinBattGroupList.size()>0) { //当相等时,说明每天计划已经为0,计划完结 prePlanSize = planSize; //List<BattdischargePlan> subPlanList = getDischargePlanList(baoJiGroupListWithinBattGroupList,planTime); List<Battinf> subPlanList = getDischargePlanList2(baoJiGroupListWithinBattGroupList,planTime); //添加到电池放电计划List planList.addAll(subPlanList); //baoJiGroupListWithinBattGroupList重置为当前baoJiGroupListWithinBattGroupList-battGroupList //按日递增计划时间,同时避开节假日和周六日 planTime.add(Calendar.DAY_OF_MONTH,1); planTime = checkAndGetPlanTime(planTime); planSize = planList.size(); //整理数据,为下一天做放电计划做准备 //剔除已经不存在的班组 for (int i = baoJiGroupListWithinBattGroupList.size() - 1; i >= 0; i--) { if (baoJiGroupListWithinBattGroupList.get(i).getBattGroupList().size() == 0) { baoJiGroupListWithinBattGroupList.remove(i); } } //算法方式1:可以本次安排了放电计划的班组,排序到最后,其他瞬移. //算法方式2:滚动班组顺序,保证扁平.原第一顺位,变为最后顺位 List<Integer> existsBaojiGroupList = baoJiGroupListWithinBattGroupList.stream().map(BaojiGroupBattGroup::getBaojiGroupId).collect(Collectors.toList()); List<Integer> planedGroupIdExistsList = new LinkedList<>(); for (Battinf battinf : subPlanList) { int baojiGroupId = battinf.getNum(); if(existsBaojiGroupList.contains(baojiGroupId)) { planedGroupIdExistsList.add(baojiGroupId); } } int planedGroupIdExistsListSize = planedGroupIdExistsList.size(); int baoJiGroupListSize = baoJiGroupListWithinBattGroupList.size(); if(planedGroupIdExistsListSize >0) { if (baoJiGroupListSize >1){//班组数大于1组时调整排序才有意义 //班组<=3时才可能执行的调整逻辑,且执行过上次计划分配后的班组仍都存在可分配站点 //上次计划分配后的班组和当时存在的班组完全相同 if(baoJiGroupListSize == planedGroupIdExistsListSize) { //如果已经计划且还有站点需要放电的班组数量 = 需要放电的班组数量 baoJiGroupListWithinBattGroupList = adjustListMethod2(baoJiGroupListWithinBattGroupList); }else{ //必然是需要放电的班组数量>已经计划且还有站点需要放电的班组数量 adjustListMethod1(baoJiGroupListWithinBattGroupList, planedGroupIdExistsList); } } } //算法方式2:滚动班组顺序,保证扁平.原第一顺位,变为最后顺位 //baoJiGroupListWithinBattGroupList = adjustListMethod2(baoJiGroupListWithinBattGroupList, firstBaojiGroupId); } Date date = new Date(); for (Battinf battinf : planList) { BattDischargePlanTemp temp = new BattDischargePlanTemp(); temp.setBattGroupId(battinf.getBattGroupId()); temp.setBattGroupName(battinf.getBattGroupName()); temp.setStationId(battinf.getStationId()); temp.setStationName(battinf.getStationName()); temp.setNodeStation(battinf.getNodeStation()); temp.setGroupId(battinf.getNum().longValue()); temp.setGroupName(battinf.getInstallUser()); temp.setDischargeStartTime(battinf.getDischargeStartTime()); temp.setCreateTime(date); temp.setMonCapStd(battinf.getMonCapStd()); temp.setMonVolStd(battinf.getMonVolStd()); temp.setCapPercent(resetCapPercent); temp.setCreateUserId(userId); temp.setSubmitStatus(0); tempList.add(temp); } //存入临时表 if(tempList.size()>0) { insertBatch(tempList); return new Response().setII(1,true,tempList,null); }else{ return new Response().set(1,false,"未找到需要执行放电计划的机房"); } } private int checkUser(int userId) { int roleId = ActionUtil.getUser().getURole(); if(roleId!= RoleEnum.GROUP_LEADER.getId()){ return 2; //当前用户不是管理员 } List<BaoJiGroupUser> groupListByUserId = baoJiGroupUserService.getGroupListByUserId(userId); if(groupListByUserId.size()>1){ return 3; //管理员管理多个包机组,需要检查 } return 1; //通过 } private BattDischargePlanTemp getValidOneByYearOfUser(int planYear, int userId) { return mapper.getValidOneByYearOfUser(planYear,userId); } /**查看放电临时表中审核状态有效(包含审批中,审批通过) */ private BattDischargePlanTemp getValidOneByYear(int planYear) { return mapper.getValidOneByYear(planYear); @@ -287,6 +422,67 @@ return planTimeDo; } /**校验日期,避开节假日和周六日,及已经被占用的时间(审批中及审批通过的时间)*/ private Calendar checkAndGetPlanTime2(Calendar planTime) throws ParseException { Calendar planTimeOnce = checkAndGetOnce2(planTime); while (true){ Calendar planTimeTwice = checkAndGetOnce2(planTimeOnce); if(planTimeTwice.compareTo(planTimeOnce) == 0) { break; }else{ planTimeOnce = planTimeTwice; } } return planTimeOnce; } private Calendar checkAndGetOnce2(Calendar planTime) throws ParseException { Calendar planTimeDo = Calendar.getInstance(); planTimeDo.setTime(planTime.getTime()); //获取审批未占用的最早时间 List<Date> occupiedTime = getOccupiedTime(); planTimeDo = getEarliestTimeNotOccupied(planTimeDo,occupiedTime); //周六日的话,就推到星期一 int dayOfWeek = planTimeDo.get(Calendar.DAY_OF_WEEK); int saturday = Calendar.SATURDAY; int sunday = Calendar.SUNDAY; if(dayOfWeek == saturday){ planTimeDo.add(Calendar.DAY_OF_MONTH,2); }else if(dayOfWeek == sunday){ planTimeDo.add(Calendar.DAY_OF_MONTH,1); } //获取节假日 int year = planTimeDo.get(Calendar.YEAR); List<Holidays> holidays = holidaysService.getListByYear(year); List<Date> holidaysDateList = holidays.stream().map(Holidays::getDay).collect(Collectors.toList()); while (true){ if(holidaysDateList.contains(planTimeDo.getTime())){ planTimeDo.add(Calendar.DAY_OF_MONTH,1); }else{ break; } } return planTimeDo; } private Calendar getEarliestTimeNotOccupied(Calendar planTimeDo,List<Date> occupiedTime) { while (true){ if(occupiedTime.contains(planTimeDo.getTime())){ planTimeDo.add(Calendar.DAY_OF_MONTH,1); getEarliestTimeNotOccupied(planTimeDo,occupiedTime); }else{ return planTimeDo; } } } /**审批中及审批通过的*/ private List<Date> getOccupiedTime() { List<BattDischargePlanTemp> tempList = mapper.getOccupiedTempList(); return tempList.stream().map(BattDischargePlanTemp::getDischargeStartTime).collect(Collectors.toList()); } /** * 算法方式1:可以本次安排了放电计划的班组,排序到最后,其他瞬移. * @param baoJiGroupListWithinBattGroupList n src/main/java/com/whyc/service/DevAlarmDataVerifyService.java
@@ -11,7 +11,9 @@ import com.whyc.mapper.DevAlarmDataVerifyMapper; import com.whyc.pojo.BattAlarmDataVerify; import com.whyc.pojo.DevAlarmDataVerify; import com.whyc.pojo.WorkflowMain; import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -23,12 +25,20 @@ @Resource private DevAlarmDataVerifyMapper mapper; @Autowired private AlarmManualClearService clearService; public Response<Object> getPage(DevAlarmPar param) { List<Integer> allMainIds = clearService.getAllMainIds(); //int userId = ActionUtil.getUser().getUId().intValue(); PageHelper.startPage(param.getPage().getPageCurr(),param.getPage().getPageSize()); List<DevAlarmDataVerify> list = mapper.getList(param); list.stream().forEach(data -> { data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmType())); WorkflowMain main = data.getMain(); if (main != null && allMainIds.contains(main.getId())){ main.setFaultUploadDone(true); } }); PageInfo<DevAlarmDataVerify> pageInfo = new PageInfo<>(list); return new Response<>().set(1,pageInfo); src/main/java/com/whyc/service/PwrDevAlarmVerifyService.java
@@ -7,7 +7,9 @@ import com.whyc.mapper.PwrDevAlarmVerifyMapper; import com.whyc.pojo.PwrDevAlarmVerify; import com.whyc.pojo.PwrdevAlarm; import com.whyc.pojo.WorkflowMain; import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -19,11 +21,19 @@ @Resource private PwrDevAlarmVerifyMapper mapper; @Autowired private AlarmManualClearService clearService; public Response<Object> getPage(PwrdevAlarm param) { List<Integer> allMainIds = clearService.getAllMainIds(); //int userId = ActionUtil.getUser().getUId().intValue(); List<PwrDevAlarmVerify> list = mapper.getList(param); list.stream().forEach(data -> { data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmType())); WorkflowMain main = data.getMain(); if (main != null && allMainIds.contains(main.getId())){ main.setFaultUploadDone(true); } }); PageInfo<PwrDevAlarmVerify> pageInfo = new PageInfo<>(list); return new Response<>().set(1,pageInfo); src/main/resources/mapper/AlarmManualClearMapper.xml
@@ -37,4 +37,7 @@ and db_user.tb_user_inf.uid = db_user.tb_user_battgroup_baojigroup_usr.uid and db_user.tb_user_inf.uid = #{dealUserId}) </select> <select id="getAllMainIds" resultType="java.lang.Integer"> select main_id from db_alarm.tb_alarm_manual_clear </select> </mapper> src/main/resources/mapper/BaojiGroupBattGroupMapper.xml
@@ -101,6 +101,16 @@ where g.baoji_group_id = gb.baoji_group_id and gb.StationId = b.StationId and g.discharge_plan_flag = 1 and gb.BattGroupId!=0 </select> <select id="getBaoJiGroupListWithinBattGroupListOfUser" resultType="com.whyc.pojo.BaojiGroupBattGroup"> SELECT gb.baoji_group_id,g.baoji_group_name,gb.StationId,b.BattGroupId,b.StationName,b.BattGroupName,b.NodeStation,b.MonCapStd,b.MonVolStd FROM db_user.tb_user_battgroup_baojigroup_battgroup gb,db_user.tb_user_battgroup_baojigroup_usr gu,db_user.tb_user_battgroup_baojigroup g,db_battinf.tb_battinf b where g.baoji_group_id = gb.baoji_group_id and gb.StationId = b.StationId and gb.baoji_group_id = gu.baoji_group_id and gu.uId = #{userId} and b.GroupIndexInFBSDevice = 0 and b.FBSDeviceName like "%BTSE" </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> delete from tb_user_battgroup_baojigroup_battgroup src/main/resources/mapper/BattDischargePlanTempMapper.xml
@@ -17,5 +17,17 @@ and discharge_start_time like '${planYear}%' and m.status in(1,2) limit 1 </select> <select id="getValidOneByYearOfUser" resultType="com.whyc.pojo.BattDischargePlanTemp"> select t.*,m.status from web_site.tb_battdischarge_plan_temp t,web_site.tb_workflow_main m where t.main_id = m.id and create_user_id = #{userId} and discharge_start_time like '${planYear}%' and m.status in(1,2) limit 1 </select> <select id="getOccupiedTempList" resultType="com.whyc.pojo.BattDischargePlanTemp"> select t.* from web_site.tb_battdischarge_plan_temp t,web_site.tb_workflow_main m where t.main_id = m.id and m.status in (1,2) </select> </mapper>