package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.BattDto;
|
import com.whyc.dto.PowerDto;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.BattInfMapper;
|
import com.whyc.pojo.db_station.BattInf;
|
import com.whyc.pojo.db_station.PowerInf;
|
import com.whyc.pojo.db_station.StationInf;
|
import com.whyc.pojo.db_user.User;
|
import com.whyc.util.ActionUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.List;
|
|
@Service
|
public class BattInfService {
|
@Autowired(required = false)
|
private BattInfMapper mapper;
|
|
/*新建电池组(新的设备新的电池组)
|
* @param binf
|
* 1.在电源下新建设备,记录设备编号,devNum,设备名称为设备类型+devNum
|
*/
|
public Response addDev(BattInf adddinf) {
|
QueryWrapper wrapper=new QueryWrapper();
|
wrapper.eq("station_id",adddinf.getStationId());
|
wrapper.eq("power_id",adddinf.getPowerId());
|
return new Response().set(1, true, "新建电池组(新的设备新的电池组)");
|
}
|
//设备下添加电源
|
@Transactional
|
public Response addBatt(BattInf addbinf) {
|
//判断电池组是否存在
|
QueryWrapper wrapper=new QueryWrapper();
|
wrapper.eq("station_id",addbinf.getStationId());
|
wrapper.eq("power_id",addbinf.getPowerId());
|
wrapper.eq("dev_name",addbinf.getDevName());
|
wrapper.eq("battgroup_name",addbinf.getBattgroupName());
|
wrapper.last("limit 1");
|
BattInf binf=mapper.selectOne(wrapper);
|
int devId=0;
|
int battGroupId=0;
|
if(binf!=null){
|
return new Response().set(1,false,"当前电源机房下已添加过该电池组");
|
}else {
|
//获取对应的设备id,电池组
|
devId = mapper.getMaxdevId();
|
battGroupId=mapper.getMaxBattGroupId();
|
if (devId == 0) {//数据库中没有站点
|
devId = 10001;
|
} else {
|
devId += 1;
|
}
|
if (battGroupId == 0) {//数据库中没有站点
|
battGroupId = 10001;
|
} else {
|
battGroupId += 1;
|
}
|
addbinf.setDevId(devId);
|
addbinf.setBattgroupId(battGroupId);
|
addbinf.setCreateTime(new Date());
|
mapper.insert(addbinf);
|
return new Response().set(1, true, "添加电池组");
|
}
|
}
|
//删除电源
|
public Response delBatt(Integer bid) {
|
UpdateWrapper wrapper=new UpdateWrapper();
|
wrapper.eq("battgroup_id",bid);
|
mapper.delete(wrapper);
|
return new Response().set(1,true);
|
}
|
//修改电源
|
public Response updateBatt(BattInf binf) {
|
UpdateWrapper wrapper=new UpdateWrapper();
|
wrapper.eq("battgroup_id",binf.getBattgroupId());
|
if(binf.getBattgroupName()!=null){
|
wrapper.set("battgroup_name",binf.getBattgroupName());
|
}
|
if(binf.getMonvolstd()!=null){
|
wrapper.set("monvolstd",binf.getMonvolstd());
|
}
|
if(binf.getMoncapstd()!=null){
|
wrapper.set("moncapstd",binf.getMoncapstd());
|
}
|
if(binf.getMonresstd()!=null){
|
wrapper.set("monresstd",binf.getMonresstd());
|
}
|
if(binf.getProduct()!=null){
|
wrapper.set("product",binf.getProduct());
|
}
|
if(binf.getMoncount()!=null){
|
wrapper.set("moncount",binf.getMoncount());
|
}
|
if(binf.getModel()!=null){
|
wrapper.set("model",binf.getModel());
|
}
|
mapper.update((BattInf) ActionUtil.objeNull,wrapper);
|
return new Response().set(1,true);
|
}
|
//查询电池
|
public Response getBatt(BattDto dto) {
|
User user= ActionUtil.getUser();
|
dto.setUid(user.getId());
|
PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
|
List<BattInf> list=mapper.getBatt(dto);
|
PageInfo pageInfo=new PageInfo(list);
|
return new Response().setII(1,list!=null,pageInfo,"查询电池");
|
}
|
|
}
|