whycxzp
2023-03-17 ab049c643b68186f0ee3895eebc155c81ec7f9de
更新放电计划
5个文件已添加
1个文件已修改
256 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/BattDischargePlanTempController.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/BattDischargePlanTempMapper.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/BattDischargePlanTemp.java 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattDischargePlanTempService.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattdischargePlanService.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/BattDischargePlanTempMapper.xml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/BattDischargePlanTempController.java
New file
@@ -0,0 +1,34 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.service.BattDischargePlanTempService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "放电计划临时表")
@RequestMapping("battDischargePlanTemp")
@RestController
public class BattDischargePlanTempController {
    @Autowired
    private BattDischargePlanTempService service;
    @ApiOperation(value = "获取可替换放电电池组信息列表",notes = "替换的推荐同班组:data,其他班组data2")
    @GetMapping(value = "replaceBattGroupList")
    public Response getReplaceBattGroupList(@RequestParam int battGroupId){
        return service.getReplaceBattGroupList(battGroupId);
    }
    @ApiOperation(value = "获取不可用的放电计划时间")
    @GetMapping(value = "disabledDischargeTime")
    public Response getDisabledDischargeTime(@RequestParam int battGroupId){
        return service.getDisabledDischargeTime(battGroupId);
    }
}
src/main/java/com/whyc/mapper/BattDischargePlanTempMapper.java
New file
@@ -0,0 +1,9 @@
package com.whyc.mapper;
import com.whyc.pojo.BattDischargePlanTemp;
public interface BattDischargePlanTempMapper extends CustomMapper<BattDischargePlanTemp> {
    void truncate();
}
src/main/java/com/whyc/pojo/BattDischargePlanTemp.java
New file
@@ -0,0 +1,106 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
@TableName(schema = "web_site",value = "tb_battdischarge_plan_temp")
public class BattDischargePlanTemp{
    @TableId(type=IdType.AUTO)
    private Integer id;
    private String stationId;
    private String stationName;
    private int battGroupId;
    private String battGroupName;
    private Long groupId;
    private String groupName;
    private Integer nodeStation;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date dischargeStartTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date createTime;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getStationId() {
        return stationId;
    }
    public void setStationId(String stationId) {
        this.stationId = stationId;
    }
    public String getStationName() {
        return stationName;
    }
    public void setStationName(String stationName) {
        this.stationName = stationName;
    }
    public int getBattGroupId() {
        return battGroupId;
    }
    public void setBattGroupId(int battGroupId) {
        this.battGroupId = battGroupId;
    }
    public String getBattGroupName() {
        return battGroupName;
    }
    public void setBattGroupName(String battGroupName) {
        this.battGroupName = battGroupName;
    }
    public Long getGroupId() {
        return groupId;
    }
    public void setGroupId(Long groupId) {
        this.groupId = groupId;
    }
    public String getGroupName() {
        return groupName;
    }
    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }
    public Integer getNodeStation() {
        return nodeStation;
    }
    public void setNodeStation(Integer nodeStation) {
        this.nodeStation = nodeStation;
    }
    public Date getDischargeStartTime() {
        return dischargeStartTime;
    }
    public void setDischargeStartTime(Date dischargeStartTime) {
        this.dischargeStartTime = dischargeStartTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
src/main/java/com/whyc/service/BattDischargePlanTempService.java
New file
@@ -0,0 +1,74 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.dto.Response;
import com.whyc.mapper.BattDischargePlanTempMapper;
import com.whyc.pojo.BattDischargePlanTemp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
@Service
public class BattDischargePlanTempService {
    @Resource
    private BattDischargePlanTempMapper mapper;
    @Autowired
    @Lazy
    private BattdischargePlanService planService;
    public void truncate() {
        mapper.truncate();
    }
    public void insertBatch(List<BattDischargePlanTemp> tempList) {
        mapper.insertBatchSomeColumn(tempList);
    }
    public Response getReplaceBattGroupList(int battGroupId) {
        List<BattDischargePlanTemp> tempList = mapper.selectList(null);
        List<BattDischargePlanTemp> recommendList = new LinkedList<>();
        List<BattDischargePlanTemp> list = new LinkedList<>();
        BattDischargePlanTemp currentTemp = null;
        for (BattDischargePlanTemp temp : tempList) {
            if(temp.getBattGroupId()==battGroupId){
                currentTemp = temp;
                break;
            }
        }
        //同类型替换,并且不能是同一天的
        for (BattDischargePlanTemp temp : tempList) {
            assert currentTemp != null;
            if(temp.getBattGroupId()!=battGroupId &&temp.getDischargeStartTime().compareTo(currentTemp.getDischargeStartTime())!=0 && temp.getNodeStation().equals(currentTemp.getNodeStation())){
                if(temp.getGroupId().equals(currentTemp.getGroupId())){ //同班组,推荐
                    recommendList.add(temp);
                }else{
                    list.add(temp);
                }
            }
        }
        return new Response().setII(1,recommendList,list,null);
    }
    public Response getDisabledDischargeTime(int battGroupId) {
        List<BattDischargePlanTemp> tempList = mapper.selectList(null);
        List<BattDischargePlanTemp> recommendList = new LinkedList<>();
        List<BattDischargePlanTemp> list = new LinkedList<>();
        BattDischargePlanTemp currentTemp = null;
        for (BattDischargePlanTemp temp : tempList) {
            if(temp.getBattGroupId()==battGroupId){
                currentTemp = temp;
                break;
            }
        }
        //不可用的时间,三种方式,层层筛选:1.当前电池组时间 2.其他 满足每天3个站点的时间 3.如果当前为节点站,再其他,存在节点站的时间
        return null;
    }
}
src/main/java/com/whyc/service/BattdischargePlanService.java
@@ -34,6 +34,9 @@
    @Resource
    private BaoJiGroupBattGroupService baoJiGroupBattGroupService;
    @Resource
    private BattDischargePlanTempService tempService;
    //查询
    public Response serchByCondition(BattdischargePlan battdischargePlan) {
        PageHelper.startPage(battdischargePlan.getPage().getPageCurr(), battdischargePlan.getPage().getPageSize());
@@ -211,6 +214,7 @@
     * @param startTimeStr
     */
    public Response generateDischargePlan(Float resetCapPercent, String startTimeStr) throws ParseException {
        List<BattDischargePlanTemp> tempList = new LinkedList<>();
        Date startTime = DateUtil.YYYY_MM_DD_HH_MM_SS.parse(startTimeStr);
        Calendar planTime = Calendar.getInstance();
        planTime.setTime(startTime);
@@ -233,7 +237,25 @@
            planSize = planList.size();
        }
        return new Response().set(1,planList);
        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);
            tempList.add(temp);
        }
        //存入临时表
        tempService.truncate();
        tempService.insertBatch(tempList);
        return new Response().set(1,tempList);
    }
    /**
src/main/resources/mapper/BattDischargePlanTempMapper.xml
New file
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.whyc.mapper.BattDischargePlanTempMapper" >
    <delete id="truncate">
        truncate web_site.tb_battdischarge_plan_temp
    </delete>
</mapper>