whyclxw
2024-10-31 d17a00b03b2553f16b7957abf97e1481c9a36d58
动环管理的添加修改删除
5个文件已添加
1个文件已修改
223 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/CircleInfController.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/CircleInfMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/CircleInf.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/CircleInfService.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/StationInfService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/CircleInfMapper.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/CircleInfController.java
New file
@@ -0,0 +1,94 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.factory.BattinfGroupFactory;
import com.whyc.pojo.*;
import com.whyc.service.BattInfService;
import com.whyc.service.CircleInfService;
import com.whyc.service.StationInfService;
import com.whyc.util.ActionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("circle")
@Api(tags = "动环管理")
public class CircleInfController {
    @Autowired
    private CircleInfService service;
    @Autowired
    private StationInfService sinfService;
    @Autowired
    private BattInfService binfService;
    @PostMapping
    @ApiOperation(value = "添加动环")
    @Transactional
    public Response add(@RequestBody CircleInf circleInf){
        int userId = ((UserInf)ActionUtil.getSession().getAttribute("user")).getUId().intValue();
        Response res = new Response();
        //校验机房站点是否存在,存在则不需要新建StationId
        StationInf sinf = sinfService.judgeStationName(circleInf.getStationName());
        if (sinf!=null) {
            circleInf.setStationId(sinf.getStationId());
        }else {
            //站点不存在,需要新建站点记录
            String nextStationId = binfService.getNextStationId();
            StationInf station = new StationInf();
            station.setStationId(nextStationId);
            station.setStationName(circleInf.getStationName());
            station.setStationName1(circleInf.getStationName1());
            station.setStationName2(circleInf.getStationName2());
            station.setStationName3(circleInf.getStationName3());
            station.setStationName5(circleInf.getStationName5());
            sinfService.insertStation(station);
            //powerInf.setStationId(String.valueOf(battInfService.searchMaxId_zj()));
            circleInf.setStationId(nextStationId);
        }
        //获取动环的设备id
        String devId = service.getDeviceId();
        circleInf.setDeviceId(devId);
        if (service.add(circleInf)>0){
            //添加机房站点到用户对应的包机组
            binfService.insertUserBattgroupBaojigroupBattgroupSelect(circleInf.getStationId(),0,userId);
            //添加电源站点时,更新ReInit字段为1,通讯程序监控变化重新初始化
            /*if(powerInf.getPowerDeviceType()== BattinfGroupFactory.DEVICE_POWER) {
                boolean flag = powerAppSysService.updateFlag("AppServer_Reinit_PowerData_EN");
                if (!flag) {
                    System.out.println("更新updateReInit接口失败");
                }
            }else{
                //充电机和绝缘装置的,更新另一个ReInit字段为1
                boolean flag = powerAppSysService.updateFlag("AppServer_Reinit_BattGroupData_EN");
                if (!flag) {
                    System.out.println("更新updateReInit接口失败");
                }
            }*/
            res.set(1,true,"添加成功");
        }else{
            res.set(1,false,"添加失败");
        }
        return res;
    }
    @PostMapping("update")
    @ApiOperation(value = "更新电源")
    public Response updateByDeviceId(@RequestBody CircleInf circleInf){
        service.updateByDeviceId(circleInf);
        return new Response().set(1,true,"更新成功");
    }
    @PostMapping("delete")
    @ApiOperation(value = "删除电源")
    public Response deleteByDeviceId(@RequestParam Integer deviceId){
        service.deleteByDeviceId(deviceId);
        return new Response().set(1,true,"删除成功");
    }
}
src/main/java/com/whyc/mapper/CircleInfMapper.java
New file
@@ -0,0 +1,8 @@
package com.whyc.mapper;
import com.whyc.pojo.CircleInf;
public interface CircleInfMapper extends CustomMapper<CircleInf>{
    //获取最大动环设备id
    Integer getMaxDeviceId();
}
src/main/java/com/whyc/pojo/CircleInf.java
New file
@@ -0,0 +1,67 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
 * <p>
 *
 * </p>
 *
 * @author lxw
 * @since 2024-10-31
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(schema = "db_circle",value = "tb_circle_inf")
@ApiModel(value="CircleInf对象", description="")
public class CircleInf implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId(value = "num", type = IdType.AUTO)
    private Integer num;
    private String stationId;
    private String stationName;
    private String stationName1;
    private String stationName2;
    private String stationName3;
    private String stationName4;
    private String stationName5;
    private String stationName6;
    private String stationName7;
    private String stationName8;
    private String stationName9;
    private String stationIp;
    private String deviceId;
    private String deviceName;
    private Date circleProductDate;
    private Date circleInuseDate;
}
src/main/java/com/whyc/service/CircleInfService.java
New file
@@ -0,0 +1,39 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.whyc.mapper.CircleInfMapper;
import com.whyc.pojo.CircleInf;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class CircleInfService {
    @Resource
    private CircleInfMapper mapper;
    public int add(CircleInf circleInf){
        return mapper.insert(circleInf);
    }
    public void updateByDeviceId(CircleInf circleInf){
        UpdateWrapper<CircleInf> wrapper = new UpdateWrapper<CircleInf>().eq("device_id",circleInf.getDeviceId());
        mapper.update(circleInf,wrapper);
    }
    public void deleteByDeviceId(Integer deviceId){
        QueryWrapper<CircleInf> wrapper = new QueryWrapper<CircleInf>().eq("device_id",deviceId);
        mapper.delete(wrapper);
    }
    //获取动环的设备id
    public String getDeviceId() {
        Integer devId = mapper.getMaxDeviceId();
        if(devId==null||devId==0){
            devId = 120*1000000;
        }
        devId+=1;
        return String.valueOf(devId);
    }
}
src/main/java/com/whyc/service/StationInfService.java
@@ -1051,4 +1051,12 @@
        //获取所有的动环信息
        return new Response().setII(1,true,map,"获取站点下所有设备信息");
    }
    //校验机房站点是否存在,存在则不需要新建StationId
    public StationInf judgeStationName(String stationName) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("station_name",stationName);
        wrapper.last("limit 1");
        StationInf sinf=mapper.selectOne(wrapper);
        return sinf;
    }
}
src/main/resources/mapper/CircleInfMapper.xml
New file
@@ -0,0 +1,7 @@
<?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.CircleInfMapper">
    <select id="getMaxDeviceId" resultType="java.lang.Integer">
        select max(device_id) as deviceId from db_circle.tb_circle_inf
    </select>
</mapper>