|
@@ -0,0 +1,288 @@
|
|
|
+package com.persagy.apm.report.config.function.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.base.CaseFormat;
|
|
|
+import com.persagy.apm.common.constant.enums.ValidEnum;
|
|
|
+import com.persagy.apm.common.context.AppContext;
|
|
|
+import com.persagy.apm.common.model.dto.Sort;
|
|
|
+import com.persagy.apm.report.config.function.constant.enums.EnergyTypeEnum;
|
|
|
+import com.persagy.apm.report.config.function.constant.enums.FunctionTypeEnum;
|
|
|
+import com.persagy.apm.report.config.function.dao.FunctionMapper;
|
|
|
+import com.persagy.apm.report.config.function.model.ConvertFunctionTool;
|
|
|
+import com.persagy.apm.report.config.function.model.Function;
|
|
|
+import com.persagy.apm.report.config.function.model.dto.AddFunctionDTO;
|
|
|
+import com.persagy.apm.report.config.function.model.dto.PageQueryFunctionDTO;
|
|
|
+import com.persagy.apm.report.config.function.model.dto.QueryFunctionDTO;
|
|
|
+import com.persagy.apm.report.config.function.model.dto.UpdateFunctionDTO;
|
|
|
+import com.persagy.apm.report.config.function.service.IFunctionService;
|
|
|
+import com.persagy.apm.report.dependencies.centermiddleware.model.dto.QueryItemInfoDTO;
|
|
|
+import com.persagy.apm.report.dependencies.centermiddleware.service.ICenterMiddlewareWebService;
|
|
|
+import com.persagy.apm.report.dependencies.saasweb.model.vo.SimpleProjectVO;
|
|
|
+import com.persagy.apm.report.dependencies.saasweb.service.ISaasWebService;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.assertj.core.util.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 能耗报告信息点(Function) service层
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FunctionServiceImpl extends ServiceImpl<FunctionMapper, Function>
|
|
|
+ implements IFunctionService {
|
|
|
+ @Autowired
|
|
|
+ private ICenterMiddlewareWebService centerMiddlewareWebService;
|
|
|
+ @Autowired
|
|
|
+ private ISaasWebService saasWebService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建能耗报告信息点
|
|
|
+ *
|
|
|
+ * @return 能耗报告信息点主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String createFunction(AddFunctionDTO addFunctionDTO) {
|
|
|
+ Function function = ConvertFunctionTool.INSTANCE.convertAddDto2Entity(addFunctionDTO);
|
|
|
+ // 设置默认值
|
|
|
+ setDefaultValue(function);
|
|
|
+ save(function);
|
|
|
+ return function.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如果某些字段没有赋值,使用默认的值
|
|
|
+ *
|
|
|
+ * @param function 能耗报告信息点实体
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/12 12:29 下午
|
|
|
+ */
|
|
|
+ private void setDefaultValue(Function function) {
|
|
|
+ function.setCreator(AppContext.getContext().getAccountId());
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 能耗报告信息点详情
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 部门do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Function queryFunctionDetail(String id) {
|
|
|
+ Function function = getById(id);
|
|
|
+ if (function == null) {
|
|
|
+ throw new IllegalArgumentException("查看Function详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
+ }
|
|
|
+ return function;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新能耗报告信息点
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateFunction(UpdateFunctionDTO updateFunctionDTO) {
|
|
|
+ Function function = getById(updateFunctionDTO.getId());
|
|
|
+ function = ConvertFunctionTool.INSTANCE.convertUpdateDto2Entity(function, updateFunctionDTO);
|
|
|
+ function.setModifier(AppContext.getContext().getAccountId());
|
|
|
+ updateById(function);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验能耗报告信息点是否可删除
|
|
|
+ *
|
|
|
+ * @param id 能耗报告信息点主键
|
|
|
+ * @return 能耗报告信息点do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+ public Function checkDeletable(String id) {
|
|
|
+ if (id == null) {
|
|
|
+ throw new IllegalArgumentException("删除Function时发生异常,主键为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Function function = getById(id);
|
|
|
+
|
|
|
+ if (function == null) {
|
|
|
+ throw new IllegalArgumentException("删除Function时发生异常,找不到要删除的数据,id:" + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return function;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除能耗报告信息点
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteFunction(String id) {
|
|
|
+ // 校验是否可删除
|
|
|
+ Function function = checkDeletable(id);
|
|
|
+
|
|
|
+ function.setValid(ValidEnum.FALSE.getType());
|
|
|
+ updateById(function);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询能耗报告信息点
|
|
|
+ *
|
|
|
+ * @return List<Function>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Function> queryFunctionList(QueryFunctionDTO queryFunctionDTO) {
|
|
|
+ QueryWrapper<Function> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(Function.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, Function.PROP_CREATIONTIME);
|
|
|
+
|
|
|
+ if (queryFunctionDTO != null) {
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(queryFunctionDTO.getFunctionIdList())) {
|
|
|
+ queryWrapper.in(Function.PROP_ID, queryFunctionDTO.getFunctionIdList());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(queryFunctionDTO.getGroupCode())) {
|
|
|
+ queryWrapper.eq(Function.PROP_GROUP_CODE, queryFunctionDTO.getGroupCode());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(queryFunctionDTO.getEnergyType())) {
|
|
|
+ queryWrapper.eq(Function.PROP_ENERGY_TYPE, queryFunctionDTO.getEnergyType());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(queryFunctionDTO.getBuildingType())) {
|
|
|
+ queryWrapper.eq(Function.PROP_BUILDING_TYPE, queryFunctionDTO.getBuildingType());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(queryFunctionDTO.getFunctionType())) {
|
|
|
+ queryWrapper.eq(Function.PROP_FUNCTION_TYPE, queryFunctionDTO.getFunctionType());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(queryFunctionDTO.getModelCode())) {
|
|
|
+ queryWrapper.eq(Function.PROP_MODEL_CODE, queryFunctionDTO.getModelCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(queryFunctionDTO.getItemId())) {
|
|
|
+ queryWrapper.eq(Function.PROP_ITEM_ID, queryFunctionDTO.getItemId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询能耗报告信息点
|
|
|
+ *
|
|
|
+ * @return IPage<Function>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-05-20 19:05:34
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<Function> pageQueryFunction(PageQueryFunctionDTO pageQueryFunctionDTO) {
|
|
|
+ QueryWrapper<Function> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(Function.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
+ IPage<Function> pageParam = new Page<>(pageQueryFunctionDTO.getPage(), pageQueryFunctionDTO.getSize(), true);
|
|
|
+ // 排序信息
|
|
|
+ if (CollectionUtils.isEmpty(pageQueryFunctionDTO.getOrders())) {
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, Function.PROP_CREATIONTIME);
|
|
|
+ } else {
|
|
|
+ List<Sort> orders = pageQueryFunctionDTO.getOrders();
|
|
|
+ for (Sort sort : orders) {
|
|
|
+ // 将驼峰转换为下划线格式
|
|
|
+ sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
+ queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryFunctionDTO.getGroupCode())) {
|
|
|
+ queryWrapper.like(Function.PROP_GROUP_CODE, pageQueryFunctionDTO.getGroupCode());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryFunctionDTO.getEnergyType())) {
|
|
|
+ queryWrapper.like(Function.PROP_ENERGY_TYPE, pageQueryFunctionDTO.getEnergyType());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryFunctionDTO.getBuildingType())) {
|
|
|
+ queryWrapper.like(Function.PROP_BUILDING_TYPE, pageQueryFunctionDTO.getBuildingType());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryFunctionDTO.getFunctionType())) {
|
|
|
+ queryWrapper.like(Function.PROP_FUNCTION_TYPE, pageQueryFunctionDTO.getFunctionType());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryFunctionDTO.getModelCode())) {
|
|
|
+ queryWrapper.like(Function.PROP_MODEL_CODE, pageQueryFunctionDTO.getModelCode());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryFunctionDTO.getItemId())) {
|
|
|
+ queryWrapper.like(Function.PROP_ITEM_ID, pageQueryFunctionDTO.getItemId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getItemName(Function function, String projectId) {
|
|
|
+ // 获取项目信息
|
|
|
+ SimpleProjectVO simpleProjectInfo = saasWebService.getSimpleProjectInfo(projectId);
|
|
|
+
|
|
|
+ if (simpleProjectInfo == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ QueryItemInfoDTO queryItemInfoDTO = new QueryItemInfoDTO();
|
|
|
+ // 注意这里应该传入项目本地编码
|
|
|
+ queryItemInfoDTO.setProjectId(simpleProjectInfo.getProjectLocalID());
|
|
|
+ queryItemInfoDTO.setBuildingId(simpleProjectInfo.getProjectLocalID());
|
|
|
+ // 是否是用电条目
|
|
|
+ boolean isEnergyItem = EnergyTypeEnum.ELECTRICITY.getType().toString().equals(function.getEnergyType());
|
|
|
+ // 是否是能耗类型
|
|
|
+ boolean isEnergyType = FunctionTypeEnum.ENERGY.getType().equals(function.getFunctionType());
|
|
|
+ // 是否是费用类型
|
|
|
+ boolean isCostType = FunctionTypeEnum.COST.getType().equals(function.getFunctionType());
|
|
|
+ // 统计条目
|
|
|
+ String sumItem = "sumItem";
|
|
|
+ // 是否从调研获取条目名称
|
|
|
+ boolean getNameFromResearch = isEnergyItem &&
|
|
|
+ (isEnergyType || (isCostType && !sumItem.equals(function.getItemId())));
|
|
|
+ if (getNameFromResearch) {
|
|
|
+ queryItemInfoDTO.setModelCode(function.getModelCode());
|
|
|
+ queryItemInfoDTO.setItemIdList(Lists.newArrayList(function.getItemId()));
|
|
|
+ Map<String, String> itemNameMap = centerMiddlewareWebService.getItemNameMap(queryItemInfoDTO);
|
|
|
+ if (itemNameMap != null) {
|
|
|
+ return itemNameMap.get(function.getItemId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return function.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+}
|