Commit d7256cca authored by ZWT's avatar ZWT

feat(能源管理系统): 基础信息配置

1.优化基础信息配置-柴发设备模块新增,修改,删除,查询接口,优化代码结构增加事务处理;
2.优化基础信息配置-储能设备模块新增,修改,删除,查询接口,优化代码结构增加事务处理;
3.优化基础信息配置-井口设备模块新增,修改,删除,查询接口,优化代码结构增加事务处理;
4.优化基础信息配置-光伏电站模块新增,修改,删除,查询接口,优化代码结构增加事务处理;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent e8b6644e
...@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; ...@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.base.entity.BasePhotovoltaicPlantEnt; import pps.core.base.entity.BasePhotovoltaicPlantEnt;
import pps.core.base.entity.BasePowerLineEnt;
import pps.core.base.entity.BasePowerLinePlantEnt; import pps.core.base.entity.BasePowerLinePlantEnt;
import pps.core.base.mapper.BasePhotovoltaicPlantMapper; import pps.core.base.mapper.BasePhotovoltaicPlantMapper;
import pps.core.base.mapper.BasePowerLinePlantMapper; import pps.core.base.mapper.BasePowerLinePlantMapper;
...@@ -31,6 +32,7 @@ import xstartup.feature.api.annotation.XApiAnonymous; ...@@ -31,6 +32,7 @@ import xstartup.feature.api.annotation.XApiAnonymous;
import xstartup.feature.api.annotation.XApiGet; import xstartup.feature.api.annotation.XApiGet;
import xstartup.feature.api.annotation.XApiPost; import xstartup.feature.api.annotation.XApiPost;
import xstartup.feature.mybatis.helper.XMapperHelper; import xstartup.feature.mybatis.helper.XMapperHelper;
import xstartup.helper.XTransactionHelper;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -49,26 +51,24 @@ public class BasePhotovoltaicPlantService extends BaseService { ...@@ -49,26 +51,24 @@ public class BasePhotovoltaicPlantService extends BaseService {
@XApiAnonymous @XApiAnonymous
@XApiPost @XApiPost
public XServiceResult createBasePhotovoltaicPlant(XContext context, CreateBasePhotovoltaicPlantInput input) { public XServiceResult createBasePhotovoltaicPlant(XContext context, CreateBasePhotovoltaicPlantInput input) {
return XTransactionHelper.begin(context, () -> {
BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class); BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class);
BasePhotovoltaicPlantEnt entity = new BasePhotovoltaicPlantEnt(); BasePhotovoltaicPlantEnt entity = XCopyUtils.copyNewObject(input, BasePhotovoltaicPlantEnt.class);
XCopyUtils.copyObject(input, entity);
PpsUserSession session = context.getSession(PpsUserSession.class); PpsUserSession session = context.getSession(PpsUserSession.class);
BaseUtils.setBaseModelDefault(entity, session); BaseUtils.setBaseModelDefault(entity, session);
mapper.insert(entity); mapper.insert(entity);
return XServiceResult.OK; return XServiceResult.OK;
});
} }
@XText("更新") @XText("更新")
@XApiAnonymous @XApiAnonymous
@XApiPost @XApiPost
public XServiceResult updateBasePhotovoltaicPlant(XContext context, UpdateBasePhotovoltaicPlantInput input) { public XServiceResult updateBasePhotovoltaicPlant(XContext context, UpdateBasePhotovoltaicPlantInput input) {
return XTransactionHelper.begin(context, () -> {
BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class); BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class);
QueryWrapper<BasePhotovoltaicPlantEnt> queryWrapper = new QueryWrapper<>(); BasePhotovoltaicPlantEnt entity = this.selectOneByPlantId(input.getId(), mapper);
queryWrapper.lambda() if (Objects.isNull(entity)) {
.eq(BasePhotovoltaicPlantEnt::getId, input.getId())
.eq(BasePhotovoltaicPlantEnt::getIsDeleted, BusinessConstant.ONE);
BasePhotovoltaicPlantEnt entity = mapper.selectOne(queryWrapper);
if (entity == null) {
return XServiceResult.error(context, XError.NotFound); return XServiceResult.error(context, XError.NotFound);
} }
XCopyUtils.copyObject(input, entity); XCopyUtils.copyObject(input, entity);
...@@ -76,6 +76,7 @@ public class BasePhotovoltaicPlantService extends BaseService { ...@@ -76,6 +76,7 @@ public class BasePhotovoltaicPlantService extends BaseService {
BaseUtils.setBaseModelDefault(entity, session); BaseUtils.setBaseModelDefault(entity, session);
mapper.updateById(entity); mapper.updateById(entity);
return XServiceResult.OK; return XServiceResult.OK;
});
} }
@XText("删除") @XText("删除")
...@@ -86,22 +87,20 @@ public class BasePhotovoltaicPlantService extends BaseService { ...@@ -86,22 +87,20 @@ public class BasePhotovoltaicPlantService extends BaseService {
if (this.checkPhotovoltaicIsReference(context, plantId)) { if (this.checkPhotovoltaicIsReference(context, plantId)) {
return XServiceResult.error(992, "当前光伏电站已被引用"); return XServiceResult.error(992, "当前光伏电站已被引用");
} }
return XTransactionHelper.begin(context, () -> {
BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class); BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class);
QueryWrapper<BasePhotovoltaicPlantEnt> queryWrapper = new QueryWrapper<>(); BasePhotovoltaicPlantEnt entity = this.selectOneByPlantId(plantId, mapper);
queryWrapper.lambda()
.eq(BasePhotovoltaicPlantEnt::getId, plantId)
.eq(BasePhotovoltaicPlantEnt::getIsDeleted, BusinessConstant.ONE);
BasePhotovoltaicPlantEnt entity = mapper.selectOne(queryWrapper);
if (Objects.isNull(entity)) { if (Objects.isNull(entity)) {
return XServiceResult.error(context, XError.NotFound); return XServiceResult.error(context, XError.NotFound);
} }
entity = new BasePhotovoltaicPlantEnt(); entity = new BasePhotovoltaicPlantEnt();
entity.setId(input.getId()); entity.setId(plantId);
entity.setIsDeleted(BusinessConstant.ZERO); entity.setIsDeleted(BusinessConstant.ZERO);
PpsUserSession session = context.getSession(PpsUserSession.class); PpsUserSession session = context.getSession(PpsUserSession.class);
BaseUtils.setBaseModelDefault(entity, session); BaseUtils.setBaseModelDefault(entity, session);
mapper.updateById(entity); mapper.updateById(entity);
return XServiceResult.OK; return XServiceResult.OK;
});
} }
@XText("根据id获取详情") @XText("根据id获取详情")
...@@ -109,23 +108,19 @@ public class BasePhotovoltaicPlantService extends BaseService { ...@@ -109,23 +108,19 @@ public class BasePhotovoltaicPlantService extends BaseService {
@XApiGet @XApiGet
public XSingleResult<GetBasePhotovoltaicPlantOutput> getBasePhotovoltaicPlant(XContext context, GetBasePhotovoltaicPlantInput input) { public XSingleResult<GetBasePhotovoltaicPlantOutput> getBasePhotovoltaicPlant(XContext context, GetBasePhotovoltaicPlantInput input) {
BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class); BasePhotovoltaicPlantMapper mapper = context.getBean(BasePhotovoltaicPlantMapper.class);
QueryWrapper<BasePhotovoltaicPlantEnt> queryWrapper = new QueryWrapper<>(); BasePhotovoltaicPlantEnt entity = this.selectOneByPlantId(input.getId(), mapper);
queryWrapper.lambda() if (Objects.isNull(entity)) {
.eq(BasePhotovoltaicPlantEnt::getId, input.getId())
.eq(BasePhotovoltaicPlantEnt::getIsDeleted, BusinessConstant.ONE);
BasePhotovoltaicPlantEnt entity = mapper.selectOne(queryWrapper);
if (entity == null) {
return XSingleResult.error(context, XError.NotFound); return XSingleResult.error(context, XError.NotFound);
} }
GetBasePhotovoltaicPlantOutput output = new GetBasePhotovoltaicPlantOutput(); GetBasePhotovoltaicPlantOutput output = XCopyUtils.copyNewObject(entity, GetBasePhotovoltaicPlantOutput.class);
XCopyUtils.copyObject(entity, output);
//根据组织机构的路径获取 //根据组织机构的路径获取
SysOrganizationViewMapper organizationViewMapper = context.getBean(SysOrganizationViewMapper.class); SysOrganizationViewMapper organizationViewMapper = context.getBean(SysOrganizationViewMapper.class);
SysOrganizationView organizationView = new SysOrganizationView(); SysOrganizationView organizationView = new SysOrganizationView();
organizationView.setId(entity.getOuId()); organizationView.setId(entity.getOuId());
organizationView = organizationViewMapper.selectOrgProvince(organizationView); organizationView = organizationViewMapper.selectOrgProvince(organizationView);
if (null != organizationView) if (Objects.nonNull(organizationView)) {
output.setProvince(organizationView.getProvinceName()); output.setProvince(organizationView.getProvinceName());
}
return XSingleResult.success(output); return XSingleResult.success(output);
} }
...@@ -206,4 +201,16 @@ public class BasePhotovoltaicPlantService extends BaseService { ...@@ -206,4 +201,16 @@ public class BasePhotovoltaicPlantService extends BaseService {
); );
return count > 0; return count > 0;
} }
/**
* 通过电站ID获取电站信息
*
* @param plantId 电站id
* @param mapper 映射器
* @return {@link BasePowerLineEnt}
*/
private BasePhotovoltaicPlantEnt selectOneByPlantId(String plantId, BasePhotovoltaicPlantMapper mapper) {
return mapper.selectOne(new LambdaQueryWrapper<BasePhotovoltaicPlantEnt>()
.eq(BaseModel::getId, plantId));
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment