diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java new file mode 100644 index 0000000..67f0011 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/24 15:55 + */ +@Data +public class AttrSelectionVO extends SelectionVO implements Serializable { + private DataItemVO item; +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java similarity index 100% rename from hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java rename to hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java similarity index 100% rename from hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java rename to hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java similarity index 100% rename from hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java rename to hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java index 6e6dec3..45145c9 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java @@ -19,6 +19,7 @@ package com.hnac.hzims.equipment.feign; import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.vo.DeviceVO; +import com.hnac.hzims.equipment.vo.RideDeviceVo; import org.springblade.core.tool.api.R; import org.springblade.system.vo.CreateTableVO; import org.springframework.cloud.openfeign.FeignClient; @@ -84,6 +85,9 @@ public interface IEmInfoClient { String DEVICE_BY_PATH = API_PREFIX + "/deviceByPath"; String EM_INFO_LIST = API_PREFIX + "/emInfoList"; + String RIDE_DEVICES = API_PREFIX + "/rideDevices"; + + @PostMapping(DETAIL) EmInfoEntity getByCode(@RequestParam("code") String id); @@ -169,4 +173,7 @@ public interface IEmInfoClient { @GetMapping(EM_INFO_LIST) R> emInfoList(EmInfoEntity req); + + @GetMapping(RIDE_DEVICES) + List rideDevices(@RequestParam("deptIds") List deptIds); } diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java index c411e7e..104d494 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java @@ -2,6 +2,7 @@ package com.hnac.hzims.equipment.feign; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.vo.DeviceVO; +import com.hnac.hzims.equipment.vo.RideDeviceVo; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; import org.springblade.system.vo.CreateTableVO; @@ -114,4 +115,9 @@ public class IEmInfoClientBack implements IEmInfoClient { public R> emInfoList(EmInfoEntity req) { return R.fail("远程调用失败"); } + + @Override + public List rideDevices(List longs) { + return new ArrayList<>(); + } } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java new file mode 100644 index 0000000..d73fa37 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.operational.fill.feign; + +import com.hnac.hzims.operational.OperationalConstants; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author ysj + */ +@FeignClient( + value = OperationalConstants.APP_NAME, + fallback = IGenerateClientFallback.class +) +public interface IGenerateClient { + + String API_PREFIX = "/feign/generate/"; + + String STATION_GENERATE_BY_TIME = API_PREFIX + "/stationGenerateByTime"; + + + @GetMapping(STATION_GENERATE_BY_TIME) + Double stationGenerateByTime(@RequestParam("stationId") String stationId, + @RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime); +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java new file mode 100644 index 0000000..da7c067 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.operational.fill.feign; + +import org.springframework.stereotype.Component; + +/** + * @author hx + */ +@Component +public class IGenerateClientFallback implements IGenerateClient { + + @Override + public Double stationGenerateByTime(String stationId, String startTime, String endTime) { + return 0.0; + } +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationRelation.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationRelation.java new file mode 100644 index 0000000..509ca22 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationRelation.java @@ -0,0 +1,130 @@ +package com.hnac.hzims.operational.station.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import okhttp3.internal.annotations.EverythingIsNonNull; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 站点和霍山生态流量电站的关联关系表 + * @author tanghaihao + * @date 2023年10月08日 13:58 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("station_relation") +public class StationRelation implements Serializable { + private static final long serialVersionUID=1L; + + /** + * ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 站点编码 + */ + @TableField("station_code") + private String stationCode; + + /** + * 站点名称 + */ + @TableField(exist = false) + private String stationName; + + /** + * 设备编码 + */ + @TableField("device_code") + private String deviceCode; + + /** + * 设备名称 + */ + @TableField(exist = false) + private String deviceName; + + /** + * 核定流量 + */ + @TableField("flow_value") + private String flowValue; + + /** + * 低级告警负责人id + */ + @TableField("low_soe_user_id") + private String lowSoeUserId; + + /** + * 低级告警电话号码 + */ + @TableField("low_soe_phone") + private String lowSoePhone; + + /** + * 中级告警负责人id + */ + @TableField("middle_soe_user_id") + private String middleSoeUserId; + + /** + * 中级告警电话号码 + */ + @TableField("middle_soe_phone") + private String middleSoePhone; + + /** + * 高级告警负责人id + */ + @TableField("high_soe_user_id") + private String highSoeUserId; + + /** + * 高级告警电话号码 + */ + @TableField("high_soe_phone") + private String highSoePhone; + + /** + * 当日是否发送预警 + */ + @TableField("send_warning") + private Integer sendWarning; + + /** + * 当日是否发送告警 + */ + @TableField("send_soe") + private Integer sendSoe; + + /** + * 创建时间 + */ + @TableField("create_time") + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField("update_time") + private LocalDateTime updateTime; + + /** + * 逻辑删除 + */ + @TableField("is_deleted") + private Integer isDeleted; +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java index cc8856a..28019bd 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java @@ -30,7 +30,7 @@ public interface IStationClient { String LIST = API_PREFIX + "/list"; String QUERY_EXIST_LGTD_LTTD = API_PREFIX + "/queryExistLgtdAndLttd"; String GET_ONE = API_PREFIX + "/getOne"; - + String GET_STATIONS_BY_TYPE_AND_DURATION = API_PREFIX + "/getStationByTypeAndDuration"; String QUERY_STATION_BY_CODES = API_PREFIX + "/querySatationByCodes"; @GetMapping(GET_LIST_ALL) @@ -81,4 +81,7 @@ public interface IStationClient { */ @PostMapping(QUERY_STATION_BY_CODES) R> querySatationByCodes(@RequestParam("codes") List codes); + + @GetMapping(GET_STATIONS_BY_TYPE_AND_DURATION) + R> getStationByTypeAndDuration(@RequestParam(required = false) String startTime,@RequestParam(required = false) String endTime,@RequestParam(required = false) String type); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java index 5c0aca1..eeb90e5 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java @@ -76,4 +76,9 @@ public class IStationClientFallBack implements IStationClient { public R> querySatationByCodes(List codes) { return R.data(new ArrayList<>()); } + + @Override + public R> getStationByTypeAndDuration(String startTime, String endTime, String type) { + return R.fail("远程调用失败!"); + } } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/HomeMapStationVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/HomeMapStationVo.java new file mode 100644 index 0000000..3aa7c25 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/vo/HomeMapStationVo.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.operational.station.vo; + +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.SqlCondition; +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.mp.support.QueryField; + +/** + * @author ysj + */ +@Data +public class HomeMapStationVo { + + @ApiModelProperty("行政区划") + private String areaCode; + + @ApiModelProperty("编号") + private String code; + + @ApiModelProperty("名称") + private String name; + + @ApiModelProperty("经度(东经)") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Float lgtd; + + @ApiModelProperty("纬度(北纬)") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Float lttd; + + @ApiModelProperty("所属机构") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long refDept; + + @ApiModelProperty("站点是否为国外 1:是;0:否") + private Boolean isAbroad; + + @ApiModelProperty("所属国家") + private String refCountry; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneTemplateDetailEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneTemplateDetailEntity.java index 9fe501f..3f3ff43 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneTemplateDetailEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneTemplateDetailEntity.java @@ -25,6 +25,14 @@ public class HygieneTemplateDetailEntity extends BaseEntity { @ApiModelProperty("责任区") private String zone; + @Size(max = 20, message = "责任人字段长度不能超过20") + @ApiModelProperty("责任人") + private String principal; + @ApiModelProperty("检查项") private String checkItem; + + @Size(max = 255, message = "检查项分值字段长度不能超过255") + @ApiModelProperty("检查项分值") + private String checkItemScore; } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java index 637da20..de29497 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java @@ -9,6 +9,7 @@ import com.hnac.hzims.common.utils.Condition; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.service.IEmInfoService; import com.hnac.hzims.equipment.vo.DeviceVO; +import com.hnac.hzims.equipment.vo.RideDeviceVo; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.ObjectUtil; @@ -155,6 +156,12 @@ public class EmInfoClient implements IEmInfoClient { return R.data(service.list(queryWrapper)); } + @Override + @GetMapping(RIDE_DEVICES) + public List rideDevices(@RequestParam("deptIds") List deptIds) { + return service.rideDevices(deptIds); + } + @PostMapping(GET_EM_CREATE_TABLE) @Override public List getEmCreateTable(List tableNames) { diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java index a2cb335..7244763 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.java @@ -19,4 +19,5 @@ public interface EmParamMapper extends UserDataScopeBaseMapper { List selectRideCountGroupEmIdByDepts(@Param("list") List list); + List rides(@Param("deviceIds") List deviceIds); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml index bf699b0..09861ea 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/EmParamMapper.xml @@ -53,4 +53,13 @@ 'installedCapacity') + diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java index ead9dee..5632b61 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmInfoService.java @@ -98,4 +98,6 @@ public interface IEmInfoService extends BaseService { List select(Long deptId); List getEmInfoTree(EmInfoEntity req); + + List rideDevices(List deptIds); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java index 9284338..ca087ff 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/IEmParamService.java @@ -19,4 +19,5 @@ public interface IEmParamService extends BaseService { Map> getRideCountGroupEmIdByDepts(List emIds); + List rides(List deviceIds); } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java index fb6fb04..75d0db5 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java @@ -949,4 +949,51 @@ public class EmInfoServiceImpl extends BaseServiceImpl rideDevices(List deptIds) { + // 查询设备 + List devices = this.list(Wrappers.lambdaQuery() + .in(EmInfoEntity::getDepartment,deptIds) + .eq(EmInfoEntity::getHomePageDisplay,"1") + .eq(EmInfoEntity::getEmType,"2") + ); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); + } + List paramList = paramService.rides(devices.stream().map(EmInfoEntity::getId).collect(Collectors.toList())); + return devices.stream().map(device->{ + RideDeviceVo rideDevice = new RideDeviceVo(); + BeanUtil.copyProperties(device,rideDevice); + // 寻找设备配置参数 + List itemParamList = paramList.stream().filter(o->device.getId().equals(o.getInfoId())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(itemParamList)) { + // 遍历设备配置参数 + for (EmParamEntity paramEntity : itemParamList) { + String paramName = paramEntity.getParamName(); + switch (paramName) { + case "ct": + case "CT": + rideDevice.setCt(Double.parseDouble(paramEntity.getParamValue())); + break; + case "pt": + case "PT": + rideDevice.setPt(Double.parseDouble(paramEntity.getParamValue())); + break; + default: + break; + } + } + // 设置ct * pt + if (null != rideDevice.getCt() && null != rideDevice.getPt()) { + rideDevice.setRide(rideDevice.getCt() * rideDevice.getPt()); + }else{ + rideDevice.setRide(1.0); + } + }else{ + rideDevice.setRide(1.0); + } + return rideDevice; + }).collect(Collectors.toList()); + } + } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java index 394189f..cd4f0c6 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmParamServiceImpl.java @@ -69,4 +69,9 @@ public class EmParamServiceImpl extends BaseServiceImpl rides(List deviceIds) { + return this.baseMapper.rides(deviceIds); + } } diff --git a/hzims-service/hzims-big-model/pom.xml b/hzims-service/hzims-big-model/pom.xml index cedb16a..91ae6d1 100644 --- a/hzims-service/hzims-big-model/pom.xml +++ b/hzims-service/hzims-big-model/pom.xml @@ -75,6 +75,10 @@ com.hnac.hzinfo.data hzinfo-data-sdk + + com.hnac.hzims + equipment-api + diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java index 4b1d359..8ce75d0 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java @@ -21,6 +21,7 @@ public enum FuncRouteEnum { CHOOSE_FAULT("choose_fault","选择故障",null), CONFIRM_YK("confirm_yk","遥控确认", FunctionConstants.TypeEnum.PARAMS), SHOW_PARAM("show_param","设备参数查询", FunctionConstants.TypeEnum.PARAMS), + CHOOSE_YC("choose_yc","选择遥测数据",FunctionConstants.TypeEnum.CHOOSE) ; @Getter private String funcCode; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java new file mode 100644 index 0000000..ea935c1 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/24 17:14 + */ +@AllArgsConstructor +public enum SearchStationTypeEnum { + STATION_TOTAL("电站总数量",null,"智能运维平台接入电站总数为:%s"), + SET_TOTAL("站点总数量",null,"智能运维平台接入站点总数为:%s"), + HYDROPOWER_TOTAL("水电站总数量","0","智能运维平台接入水电站总数为:%s"), + WIND_POWER_TOTAL("风电场总数量","1","智能运维平台接入风电场总数为:%s"), + ENERGY_STORAGE_TOTAL("储能站总数量","3","智能运维平台接入储能站总数为:%s"), + PHOTOVOLTAIC_TOTAL("光伏站总数量","5","智能运维平台接入光伏站总数为:%s"), + CHARGE_TOTAL("充电站总数量","7","智能运维平台接入充电站总数为:%s"), + STATION_NUM("电站接入量",null,"智能运维平台接入电站总数为:%s"), + SET_NUM("站点接入量",null,"智能运维平台接入站点总数为:%s"), + HYDROPOWER_NUM("水电站接入量","0","智能运维平台接入水电站接入量为:%s"), + WIND_POWER_NUM("风电场接入量","1","智能运维平台接入风电场接入量为:%s"), + ENERGY_STORAGE_NUM("储能站接入量","3","智能运维平台接入储能站接入量为:%s"), + PHOTOVOLTAIC_NUM("光伏站接入量","5","智能运维平台接入光伏站接入量为:%s"), + CHARGE_NUM("充电站接入量","7","智能运维平台接入充电站接入量为:%s"), + ; + + @Getter + private String searchStationType; + @Getter + private String stationType; + @Getter + private String label; + + public static SearchStationTypeEnum getTypeEnum(String searchStationType) { + return Arrays.stream(SearchStationTypeEnum.class.getEnumConstants()) + .filter(e -> e.getSearchStationType().equals(searchStationType)) + .findFirst() + .orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java new file mode 100644 index 0000000..0692d62 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/24 17:13 + */ +@AllArgsConstructor +public enum SearchTypeEnum { + REAL("实时"), + HISTORY("历史") + ; + @Getter + private String searchType; + + public static SearchTypeEnum getSearchType(String searchType) { + return Arrays.stream(SearchTypeEnum.class.getEnumConstants()) + .filter(e -> e.getSearchType().equals(searchType)) + .findFirst() + .orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java index 40e79b3..c109e57 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java @@ -1,14 +1,13 @@ package com.hnac.hzims.bigmodel.interactive.controller; -import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.bigmodel.BigModelConstants; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +import com.hnac.hzims.bigmodel.interactive.vo.StationSearchVO; import com.hnac.hzinfo.log.annotation.Business; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; @@ -16,9 +15,7 @@ import org.springblade.core.tool.api.R; import org.springblade.system.dto.ControlDTO; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.Map; +import java.text.DecimalFormat; /** * @Author: huangxing @@ -77,4 +74,22 @@ public class InteractiveController { public R sendRemoteControl(@RequestBody ControlDTO operate) { return interactiveService.sendRemoteControl(operate); } + + @ApiOperation("解析接入站点数量") + @ApiOperationSupport(order = 7) + @PostMapping("/resolveStations") + public R resolveStations(@RequestBody StationSearchVO req) { + return R.data(interactiveService.resolveStations(req.getStartTime(),req.getEndTime(),req.getType(),req.getEnumType())); + } + + @ApiOperation("站点发电量") + @ApiOperationSupport(order = 7) + @RequestMapping(value = "/generation",method = {RequestMethod.GET,RequestMethod.POST}) + public R generation(@RequestParam @ApiParam("站点编号") String stationId, + @RequestParam @ApiParam("开始时间") String startTime, + @RequestParam @ApiParam("结束时间")String endTime) { + double generate = interactiveService.generation(stationId,startTime,endTime); + DecimalFormat format = new DecimalFormat("0.00"); + return R.data(format.format(generate) + "kWh"); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java index 2f6588a..c6433df 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java @@ -2,6 +2,7 @@ package com.hnac.hzims.bigmodel.interactive.service; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; import org.springblade.core.tool.api.R; import org.springblade.system.dto.ControlDTO; @@ -14,6 +15,8 @@ import java.util.Map; */ public interface IInteractiveService { + ExtraVO resolveStations(String startTime, String endTime, String type, String enumType); + R resolve(ModelFunctionReq req); R ask(String question,String sessionId,String userId); @@ -43,4 +46,6 @@ public interface IInteractiveService { R knowledgeAsk(String question, String sessionId, String userId, String knowledge); R sendRemoteControl(ControlDTO operate); + + Double generation(String stationId, String startTime, String endTime); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java index 9502fec..60d910d 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java @@ -12,15 +12,14 @@ import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import com.hnac.hzims.operational.station.feign.IStationClient; import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; +import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; +import org.springblade.core.tool.utils.*; import org.springblade.system.dto.ControlDTO; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -45,6 +44,7 @@ public class ExtraResolveStrategyService { private final IStationVideoTypeClient videoTypeClient; private final JumpRouteJoinStrategy jumpRouteJoinStrategy; private final DeviceClient deviceClient; + private final BladeLogger logger; private final RedisTemplate redisTemplate; /** @@ -74,24 +74,60 @@ public class ExtraResolveStrategyService { return this.resolveConfirmRemote(extra); case SHOW_PARAM: return this.resolveShowParam(extra); + case CHOOSE_YC: + return this.resolveChooseYc(extra); default: break; } } } + else if(extra.containsKey("extra")){ + return extra.getObject("extra",ExtraVO.class); + } return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); } + private ExtraVO resolveChooseYc(JSONObject extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + if(data.containsKey("ycs")) { + List attrs = JSONArray.parseArray(JSON.toJSONString(data.get("ycs")), AttrSelectionVO.class); + result.setSelection(attrs); + } + result.setFuncCode(FuncRouteEnum.CHOOSE_YC.getFuncCode()); + result.setSpecial(true); + result.setType(FuncRouteEnum.CHOOSE_YC.getType().getType()); + return result; + } + private ExtraVO resolveShowParam(Map extra) { ExtraVO result = new ExtraVO(); result.setFuncCode(FuncRouteEnum.SHOW_PARAM.getFuncCode()); result.setType(FuncRouteEnum.SHOW_PARAM.getType().getType()); Map param = new HashMap(1); DataVO data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")),DataVO.class); - if(Func.isNotEmpty(data) && Func.isNotEmpty(data.getReal()) && Func.isNotEmpty(data.getReal().getTime()) && StringUtil.isNotBlank(data.getReal().getTime())) { - RealDataVO real = data.getReal(); - Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); - real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); + if(Func.isNotEmpty(data)) { + if(Func.isNotEmpty(data.getReal())) { + if(Func.isNotEmpty(data.getReal().getTime()) && StringUtil.isNotBlank(data.getReal().getTime())) { + RealDataVO real = data.getReal(); + Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); + real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); + } + } +// if(Func.isNotEmpty(data.getItem())) { +// if("历史".equals(data.getType())) { +// // 历史数据需要手动查询功能ID供前端使用 +// DataItemVO item = data.getItem(); +// R> attrR = deviceClient.getOnlineAttr(item.getDeviceId()); +// if(attrR.isSuccess() && CollectionUtil.isNotEmpty(attrR.getData())) { +// List attrList = attrR.getData(); +// Optional facDeviceIdOptional = attrList.stream().parallel().filter(f -> item.getSignage().equals(f.getSignage())) +// .map(DeviceInstanceAttrVO::getFacDeviceAttrId).findFirst(); +// logger.info("hzims-big-model:resolveShowParam:facDeviceId",facDeviceIdOptional.orElse("")); +// item.setAttrId(facDeviceIdOptional.orElse(null)); +// } +// } +// } } param.put("data", data); result.setParams(param); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java index f5571dd..8041056 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java @@ -5,25 +5,42 @@ import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; import com.hnac.hzims.bigmodel.entity.FunctionEntity; import com.hnac.hzims.bigmodel.function.service.IFunctionService; import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.constants.SearchStationTypeEnum; +import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; import com.hnac.hzims.bigmodel.interactive.service.IParamsService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzims.equipment.feign.IEmInfoClient; + import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.equipment.vo.RideDeviceVo; +import com.hnac.hzims.operational.fill.feign.IGenerateClient; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; +import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; +import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; import com.xxl.job.core.log.XxlJobLogger; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.MapUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; +import org.springblade.core.tool.utils.*; import org.springblade.system.dto.ControlDTO; import org.springblade.system.dto.DeptStationDTO; import org.springblade.system.feign.IDeptClient; @@ -35,7 +52,10 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; import javax.servlet.http.HttpServletResponse; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.*; import java.util.stream.Collectors; import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; @@ -52,8 +72,14 @@ public class InteractiveServiceImpl implements IInteractiveService { private final BladeLogger logger; + private final IEmInfoClient deviceClient; + private final IRemoteClient remoteClient; + private final IStationClient stationClient; + + private final IGenerateClient generateClient; + private final IJumpPageService jumpPageService; private final IParamsService paramsService; @@ -66,12 +92,44 @@ public class InteractiveServiceImpl implements IInteractiveService { private final RedisTemplate redisTemplate; + private final IAnalyseDataSearchClient analyseDataSearchClient; + private final ExtraResolveStrategyService extraResolveStrategyService; + private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("station-device-generate-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); + @Value("${fdp.host}") private String fdpHost; @Override + public ExtraVO resolveStations(String startTime, String endTime, String type, String enumType) { + ExtraVO extraVO = new ExtraVO(); + extraVO.setType(TypeEnum.PARAMS.getType()); + extraVO.setFuncCode("stations_num"); + String label; + SearchStationTypeEnum stationTypeEnum = SearchStationTypeEnum.getTypeEnum(enumType); + if(!startTime.equals(endTime)) { + label = String.format("自%s到%s时间为止,",startTime,endTime); + } + else { + startTime = null; + endTime = null; + label = "目前"; + } + R> stationListR = stationClient.getStationByTypeAndDuration(startTime, endTime, stationTypeEnum.getStationType()); + Assert.isTrue(stationListR.isSuccess(),() -> { + throw new ServiceException("获取接入站点数量失败!"); + }); + Map params = new HashMap<>(); + params.put("searchStationType",stationTypeEnum.getSearchStationType()); + params.put("label",label + String.format(stationTypeEnum.getLabel(),stationListR.getData().size())); + params.put("startTime",startTime); + params.put("endTime",endTime); + extraVO.setParams(params); + return extraVO; + } + + @Override public R resolve(ModelFunctionReq req) { logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); @@ -115,18 +173,7 @@ public class InteractiveServiceImpl implements IInteractiveService { } private void addQuestionSessionId(String sessionId) { - // 添加redis问题会话 - Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); - if(ObjectUtil.isEmpty(json)){ - List asks = Collections.singletonList(sessionId); - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); - }else{ - List asks = JSONObject.parseArray(json.toString(),String.class); - if(!asks.contains(sessionId)){ - asks.add(sessionId); - } - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); - } + redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId); } @Override @@ -277,4 +324,96 @@ public class InteractiveServiceImpl implements IInteractiveService { public R sendRemoteControl(ControlDTO operate) { return remoteClient.sendCtrl(operate); } + + /** + * 站点发电量 + * @param stationId + * @param startTime + * @param endTime + * @return + */ + @Override + public Double generation(String stationId, String startTime, String endTime) { + // 步骤1.查询站点 + R station = stationClient.getStationByCode(stationId); + if(!station.isSuccess() || ObjectUtil.isEmpty(station.getData())){ + return 0.0; + } + // 步骤2.查询填报发电量 + double fill = generateClient.stationGenerateByTime(stationId,startTime,endTime); + + // 步骤3.查询设备 + List devices = deviceClient.rideDevices(Collections.singletonList(station.getData().getRefDept())); + if(CollectionUtil.isEmpty(devices)){ + return fill; + } + // 步骤4.遍历设备查询发电量 + // 监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(devices.size()); + List deviceGenerate = new CopyOnWriteArrayList(); + for(RideDeviceVo device : devices){ + pool.submit(()->{ + deviceGenerate.add(this.periodTargetFloat(startTime,endTime,5,6,device.getNumber(),device.getRide(), HomePageConstant.HYDROPOWER_GENERATE_POWER)); + }); + countDownLatch.countDown(); + } + //所有模板数据获取完成后释放锁 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + return fill + deviceGenerate.stream().mapToDouble(Double::doubleValue).sum(); + } + + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param ride 配电比 + * @param signages 指标 + * @return + */ + private Double periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Double ride,String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + analyzeDataConditionPO.setKeepFigures(2); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + // 间隔 + analyzeDataConditionPO.setTimeInterval(1); + analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + signboardConditions.add(analyzeDataConditionPO); + po.setSignboardConditions(signboardConditions); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return 0.0; + } + List records = result.getData(); + if(CollectionUtil.isEmpty(records)){ + return 0.0; + } + AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); + if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { + return 0.0; + } + List analyseDataTaosVOList = analyzeDataConditionVO.getList(); + if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { + return 0.0; + } + AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); + if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { + return 0.0; + } + return Double.parseDouble(analyseDataTaosVO.getVal()) * ride; + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java new file mode 100644 index 0000000..d111b70 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/25 14:03 + */ +@Data +public class StationSearchVO implements Serializable { + + private String startTime; + + private String endTime; + + @NotBlank(message = "查询类型不能为空") + private String type; + + private String enumType; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java index 85affae..e145733 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java @@ -23,6 +23,7 @@ import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springframework.data.redis.core.RedisTemplate; @@ -90,12 +91,7 @@ public class InteractiveSchedule { @XxlJob(GET_INTERACTIVE_RESULT) public ReturnT getInteractiveResult(String params) { - Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); - if(ObjectUtil.isEmpty(json)){ - XxlJobLogger.log("未获取到问题标识,或者用户未进行提问!"); - return ReturnT.SUCCESS; - } - List sessionIds = JSONObject.parseArray(json.toString(),String.class); + List sessionIds = redisTemplate.opsForList().range(HZIMS_BIGMODEL_ASK_KEY, 0, -1); if(CollectionUtil.isEmpty(sessionIds)){ XxlJobLogger.log("问题都已经回答完毕!"); return ReturnT.SUCCESS; @@ -106,13 +102,13 @@ public class InteractiveSchedule { if(sessionIds.contains(answerVO.getSessionId())){ WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); + if(Func.isNotEmpty(session)) { + wsService.sendMessage(session,message); + } } - // 问题回答完成,去除redis问题标记 - if(answerVO.getRunning() == 0){ - sessionIds.remove(answerVO.getSessionId()); + if(answerVO.getRunning() == 0) { + redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,answerVO.getSessionId()); } - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); }, getAnswerPoolExecutor)); return ReturnT.SUCCESS; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java index 7317f54..0f210b7 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java @@ -1,5 +1,7 @@ package com.hnac.hzims.bigmodel.schedule; +import com.hnac.hzims.common.constant.CommonConstant; + /** * @Author: huangxing * @Date: 2024/04/28 16:19 @@ -18,6 +20,6 @@ public interface XxlJobHandlerConstant { String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; - String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; + String HZIMS_BIGMODEL_ASK_KEY = CommonConstant.TENANT_ID + ":hzims:bigmodel:ask:key"; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java index 23b8d2e..c8a5ce8 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java @@ -117,6 +117,8 @@ public class InteractiveHandler extends TextWebSocketHandler { case CHOOSE_FAULT: this.handleFaultChoose(messageContext,sessionId); break; + case CHOOSE_YC: + this.handleDataChoose(messageContext,sessionId); default: break; } @@ -209,4 +211,16 @@ public class InteractiveHandler extends TextWebSocketHandler { extra.put("data",data); interactiveService.specialAsk(sessionId,userId,extra); } + + private void handleDataChoose(JSONObject messageContext,String sessionId) { + IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); + String userId = messageContext.getString("userId"); + String funcCode = messageContext.getString("funcCode"); + FaultSelectionVO selectionVO = messageContext.getObject("selection",FaultSelectionVO.class); + Map extra = new HashMap<>(2); + extra.put("func",funcCode); + extra.put("data",selectionVO); + interactiveService.specialAsk(sessionId,userId,extra); + } + } diff --git a/hzims-service/message/pom.xml b/hzims-service/message/pom.xml index 2dcf390..7f5519f 100644 --- a/hzims-service/message/pom.xml +++ b/hzims-service/message/pom.xml @@ -88,7 +88,6 @@ org.springblade blade-system-api - 5.0.2-SNAPSHOT diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java index abe2ff8..54b5591 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/controller/GenerateController.java @@ -80,4 +80,13 @@ public class GenerateController extends BladeController { return service.pageCondition(filter, query); } + /** + * 新增 + */ + @PostMapping("/test") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "测试发电量保存", notes = "传入InsertPowerEntity对象") + public R test(@RequestBody GenerateEntity entity) { + return R.status(service.test(entity)); + } } \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/feign/GenerateClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/feign/GenerateClient.java new file mode 100644 index 0000000..22030a1 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/feign/GenerateClient.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.operational.fill.feign; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.fill.entity.GenerateEntity; +import com.hnac.hzims.operational.fill.service.GenerateService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Date; +import java.util.List; + + +/** + * @author ysj + */ +@RestController +@Slf4j +@AllArgsConstructor +public class GenerateClient implements IGenerateClient { + + private final GenerateService generateService; + + @Override + @GetMapping(STATION_GENERATE_BY_TIME) + public Double stationGenerateByTime(@RequestParam("stationId") String stationId, + @RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime) { + Date start = DateUtil.parse(startTime,DateUtil.PATTERN_DATETIME); + List generates = generateService.list(Wrappers.lambdaQuery() + .eq(GenerateEntity::getStationCode,stationId) + .ge(GenerateEntity::getFillDate,DateUtil.format(start,DateUtil.PATTERN_DATE)) + .le(GenerateEntity::getFillDate,endTime) + ); + if(CollectionUtil.isEmpty(generates)){ + return 0.0; + } + return generates.stream().mapToDouble(GenerateEntity::getGenerate).sum(); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java index 699bd03..fa68b8a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java @@ -37,4 +37,6 @@ public interface GenerateService extends BaseService { List generateThreeYear(String start, String end, String station); List fillPowerMon(String code); + + boolean test(GenerateEntity entity); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index bc33c70..b3141e0 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -26,10 +26,7 @@ import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -246,6 +243,29 @@ public class GenerateServiceImpl extends BaseServiceImpl 0){ + entity.setId(null); + entity.setFillDate(DateUtil.format(start,DateUtil.PATTERN_DATE)); + entity.setGenerate((random.nextDouble() * 1360) + 19000); + this.save(entity); + calendar.add(Calendar.DAY_OF_MONTH,1); + start = calendar.getTime(); + } + return true; + } + /** * 获取近年月份集合 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java index 14d1292..fe2130f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java @@ -15,10 +15,13 @@ public interface IAnalyseDataService { List getAnalyzeCodeBySignages(Function convert, T resource); + List analyzeCodeBySignages(List list); + + List periodTargetSignages(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, List signages); List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages); List periodTargetDatas(String startTime, String endTime, Integer accessRules, Integer cycleType, List deviceCodes, String signages); - Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Integer ride ,String signages); + Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Double ride ,String signages); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java index 927d6d2..865f0e8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java @@ -22,7 +22,10 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -47,6 +50,58 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { return result; } + /** + * 查询设备实例属性标识 + * @param list + * @return + */ + @Override + public List analyzeCodeBySignages(List list) { + R> result = analyseDataSearchClient.getAnalyzeCodeBySignages(list); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return new ArrayList<>(); + } + return result.getData(); + } + + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param signages 指标集合 + * @return + */ + @Override + public List periodTargetSignages(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, List signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + signages.forEach(signage->{ + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setKeepFigures(2); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + analyzeDataConditionPO.setSignages(signage); + // 间隔 + analyzeDataConditionPO.setTimeInterval(1); + analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + signboardConditions.add(analyzeDataConditionPO); + }); + po.setSignboardConditions(signboardConditions); + log.error("period_targets_data_request {}",po); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return new ArrayList<>(); + } + log.error("period_targets_data_resp {}",result); + return result.getData(); + } + /*** * 指标数据列表查询 * @param startTime 开始时间 @@ -134,7 +189,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { * @return */ @Override - public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Integer ride,String signages) { + public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Double ride,String signages) { AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); List signboardConditions = new ArrayList<>(); AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); @@ -170,7 +225,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { return 0f; } - return Float.parseFloat(Optional.ofNullable(analyseDataTaosVO.getVal()).orElse("0")) * ride; + return Float.parseFloat(String.valueOf(Double.parseDouble(analyseDataTaosVO.getVal()) * ride)) ; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index cba31a3..98d399a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -631,6 +631,8 @@ public class HydropowerServiceImpl implements HydropowerService { // 年发电量 kpi.setGenerateYear(targets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum()); // 月发电量 + + kpi.setGenerateMon(targets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum()); // 日发电量 kpi.setGenerateDay(targets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerDay).sum()); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/RunReportConstant.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/RunReportConstant.java index 90d534b..2fae440 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/RunReportConstant.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/RunReportConstant.java @@ -5,4 +5,9 @@ public interface RunReportConstant { * 运行月报定时任务 */ String TASK_VALUE_RUN_REPORT_CREATE = "runReportCreateHandler"; + + /** + * 数据平台霍山生态流量监测模型标识 + */ + String HS_MODEL_SIGNAGE = "hs_ecological_flow_model"; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java index 7351f30..ce3a5c3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationController.java @@ -10,6 +10,7 @@ import com.hnac.hzims.operational.data.service.HzimsDataService; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzims.operational.station.vo.HomeMapStationVo; import com.hnac.hzims.operational.station.vo.StationVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -177,9 +178,9 @@ public class StationController extends BladeController { @ApiLog @GetMapping("/getHomeStationList") @ApiOperationSupport(order = 91) - @ApiOperation(value = "获取首页站点列表", notes = "") - public R> getHomeStationList(@RequestParam(value = "deptId", required = false) Long deptId, @RequestParam(value = "types", required = false) List types, @RequestParam(value = "serveType", required = false) Integer serveType) { - return R.data(stationService.getHomeStationList(deptId, types, serveType,true)); + @ApiOperation(value = "获取首页地图站点列表", notes = "") + public R> getHomeStationList() { + return R.data(stationService.homeMapStationVo()); } @ApiLog diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationRelationController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationRelationController.java new file mode 100644 index 0000000..0241dbd --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationRelationController.java @@ -0,0 +1,134 @@ +package com.hnac.hzims.operational.station.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.operational.station.RunReportConstant; +import com.hnac.hzims.operational.station.entity.StationRelation; +import com.hnac.hzims.operational.station.service.IStationRelationService; +import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiOperationSupport; +import lombok.AllArgsConstructor; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +/** + * @author tanghaihao + * @date 2023年10月08日 15:04 + */ + +@RestController +@RequestMapping("/station/station-relation") +@AllArgsConstructor +@Api(value = "站点和霍山生态流量电站的关联关系管理",tags = "站点和霍山生态流量电站的关联关系管理") +public class StationRelationController { + private final IStationRelationService stationRelationService; + private final DeviceClient deviceClient; + + @GetMapping("/list") + @ApiOperation("查询列表") + @ApiOperationSupport(order = 1) + public R> list(StationRelation stationRelation) { + + return R.data(stationRelationService.getStationRelationList(stationRelation)); + } + + @GetMapping("/page") + @ApiOperation("分页查询列表") + @ApiOperationSupport(order = 2) + public R> page(StationRelation stationRelation, Query query) { + + return R.data(stationRelationService.getStationRelationPageList(stationRelation, query)); + } + + @PostMapping("/save") + @ApiOperation("保存") + @ApiOperationSupport(order = 3) + public R save(@RequestBody @Valid StationRelation stationRelation) { + if (Func.isEmpty(stationRelation.getStationCode())) { + return R.fail("站点编码不能为空"); + } + if (Func.isEmpty(stationRelation.getDeviceCode())) { + return R.fail("设备编码不能为空"); + } + if (Func.isEmpty(stationRelation.getLowSoeUserId())) { + return R.fail("低级告警负责人不能为空"); + } + if (Func.isEmpty(stationRelation.getLowSoePhone())) { + return R.fail("低级告警电话号码不能为空"); + } + if (Func.isEmpty(stationRelation.getMiddleSoeUserId())) { + return R.fail("中级告警负责人不能为空"); + } + if (Func.isEmpty(stationRelation.getMiddleSoePhone())) { + return R.fail("中级告警电话号码不能为空"); + } + if (Func.isEmpty(stationRelation.getHighSoeUserId())) { + return R.fail("高级告警负责人不能为空"); + } + if (Func.isEmpty(stationRelation.getHighSoePhone())) { + return R.fail("高级告警电话号码不能为空"); + } + if (Func.isEmpty(stationRelation.getFlowValue())) { + return R.fail("核定流量不能为空"); + } + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + wrapper.and(item -> item.eq(StationRelation::getStationCode, stationRelation.getStationCode()) + .or().eq(StationRelation::getDeviceCode, stationRelation.getDeviceCode())); + wrapper.eq(StationRelation::getIsDeleted, 0); + int count = stationRelationService.count(wrapper); + if (count > 0) { + return R.fail("站点关联关系已存在"); + } + return R.status(stationRelationService.save(stationRelation)); + } + + @PostMapping("/update") + @ApiOperation("编辑") + @ApiOperationSupport(order = 4) + public R update(@RequestBody @Valid StationRelation stationRelation) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + wrapper.and(item -> item.eq(StationRelation::getStationCode, stationRelation.getStationCode()) + .or().eq(StationRelation::getDeviceCode, stationRelation.getDeviceCode())); + wrapper.eq(StationRelation::getIsDeleted, 0); + wrapper.ne(StationRelation::getId, stationRelation.getId()); + int count = stationRelationService.count(wrapper); + if (count > 0) { + return R.fail("站点关联关系已存在"); + } + return R.status(stationRelationService.updateById(stationRelation)); + } + + @GetMapping("/remove") + @ApiOperation("删除") + @ApiOperationSupport(order = 5) + public R remove(Long id) { + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.set(StationRelation::getIsDeleted, 1); + wrapper.eq(StationRelation::getId, id); + stationRelationService.update(wrapper); + return R.success("操作成功"); + } + + @GetMapping("/getDevice") + @ApiOperation("获取生态流量模型的设备信息") + @ApiOperationSupport(order = 6) + public R> getDevice() { + R> rData = deviceClient.getDeviceByModelSignage(RunReportConstant.HS_MODEL_SIGNAGE); + if (rData.getCode() == 200) { + List data = rData.getData(); + return R.data(data); + } else { + return R.fail("获取设备信息失败"); + } + } + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java index e9cf868..b2ca924 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java @@ -14,6 +14,7 @@ import org.springblade.core.mp.support.Condition; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.user.entity.User; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; @@ -137,6 +138,18 @@ public class StationClient implements IStationClient { .in(StationEntity::getCode,codes))); } + @Override + @GetMapping("/getStationByTypeAndDuration") + public R> getStationByTypeAndDuration(@RequestParam(required = false) String startTime, + @RequestParam(required = false) String endTime, + @RequestParam(required = false) String type) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() + .eq(StringUtil.isNotBlank(type) && Func.isNotEmpty(type),StationEntity::getType, type) + .le(StringUtil.isNotBlank(endTime) && Func.isNotEmpty(endTime),StationEntity::getCreateTime, endTime) + .ge(StringUtil.isNotBlank(startTime) && Func.isNotEmpty(startTime),StationEntity::getCreateTime, startTime); + return R.data(stationService.list(wrapper)); + } + @Override @PostMapping("/getStationByCodeOrRedDept") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationRelationMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationRelationMapper.java new file mode 100644 index 0000000..e08e69e --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationRelationMapper.java @@ -0,0 +1,8 @@ +package com.hnac.hzims.operational.station.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.operational.station.entity.StationRelation; + +public interface StationRelationMapper extends BaseMapper { + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationRelationMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationRelationMapper.xml new file mode 100644 index 0000000..e1cfa29 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationRelationMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationRelationService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationRelationService.java new file mode 100644 index 0000000..e8e9964 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationRelationService.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.operational.station.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.operational.station.entity.StationRelation; +import org.springblade.core.mp.support.Query; + +import java.util.List; + +/** + * @author tanghaihao + * @date 2023年10月08日 15:04 + */ +public interface IStationRelationService extends IService { + + List getStationRelationList(StationRelation stationRelation); + + IPage getStationRelationPageList(StationRelation stationRelation, Query query); +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java index 4e3faac..b54f579 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.station.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.main.vo.StationCountVo; import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.vo.HomeMapStationVo; import com.hnac.hzims.operational.station.vo.StationAndDeptVo; import com.hnac.hzims.operational.station.vo.StationVO; import org.springblade.core.mp.base.BaseService; @@ -136,4 +137,6 @@ public interface IStationService extends BaseService { * @return 更新是否成功 */ boolean updateBatchSort(List req); + + List homeMapStationVo(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationRelationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationRelationServiceImpl.java new file mode 100644 index 0000000..6e02935 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationRelationServiceImpl.java @@ -0,0 +1,47 @@ +package com.hnac.hzims.operational.station.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.operational.station.entity.StationRelation; +import com.hnac.hzims.operational.station.mapper.StationRelationMapper; +import com.hnac.hzims.operational.station.service.IStationRelationService; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.utils.Func; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author tanghaihao + * @date 2023年10月08日 14:37 + */ +@Service +public class StationRelationServiceImpl extends ServiceImpl implements IStationRelationService { + @Override + public List getStationRelationList(StationRelation stationRelation) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + if (Func.isNotEmpty(stationRelation.getStationCode())) { + wrapper.eq(StationRelation::getStationCode, stationRelation.getStationCode()); + } + if (Func.isNotEmpty(stationRelation.getDeviceCode())) { + wrapper.eq(StationRelation::getDeviceCode, stationRelation.getDeviceCode()); + } + wrapper.eq(StationRelation::getIsDeleted, 0); + return this.list(wrapper); + } + + @Override + public IPage getStationRelationPageList(StationRelation stationRelation, Query query) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + if (Func.isNotEmpty(stationRelation.getStationCode())) { + wrapper.eq(StationRelation::getStationCode, stationRelation.getStationCode()); + } + if (Func.isNotEmpty(stationRelation.getDeviceCode())) { + wrapper.eq(StationRelation::getDeviceCode, stationRelation.getDeviceCode()); + } + wrapper.eq(StationRelation::getIsDeleted, 0); + return this.page(Condition.getPage(query), wrapper); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index aa58a0f..6b85aa8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java @@ -25,6 +25,7 @@ import com.hnac.hzims.operational.station.mapper.StationMapper; import com.hnac.hzims.operational.station.service.IStationAttributeService; import com.hnac.hzims.operational.station.service.IStationPushConfigService; import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzims.operational.station.vo.HomeMapStationVo; import com.hnac.hzims.operational.station.vo.StationAndDeptVo; import com.hnac.hzims.operational.station.vo.StationPushConfigVO; import com.hnac.hzims.operational.station.vo.StationVO; @@ -776,4 +777,31 @@ public class StationServiceImpl extends BaseServiceImpl homeMapStationVo() { + List stations = this.list(Wrappers.lambdaQuery() + .isNotNull(StationEntity::getRefDept) + .isNotNull(StationEntity::getAreaCode) + ); + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); + } + return stations.stream().map(o->{ + HomeMapStationVo mapStation = new HomeMapStationVo(); + mapStation.setAreaCode(o.getAreaCode()); + mapStation.setName(o.getName()); + mapStation.setCode(o.getCode()); + mapStation.setLttd(o.getLttd()); + mapStation.setLgtd(o.getLgtd()); + mapStation.setRefDept(o.getRefDept()); + mapStation.setIsAbroad(o.getIsAbroad()); + mapStation.setRefCountry(o.getRefCountry()); + return mapStation; + }).collect(Collectors.toList()); + } } diff --git a/hzims-service/operational/src/main/resources/db/2.0.5.sql b/hzims-service/operational/src/main/resources/db/2.0.5.sql new file mode 100644 index 0000000..01b2814 --- /dev/null +++ b/hzims-service/operational/src/main/resources/db/2.0.5.sql @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS `station_relation`; +CREATE TABLE `station_relation` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `station_code` varchar(200) DEFAULT NULL COMMENT '站点编码', + `device_code` varchar(128) DEFAULT NULL COMMENT '设备编码', + `send_warning` int(11) DEFAULT '0' COMMENT '当日是否发送预警', + `send_soe` int(11) DEFAULT '0' COMMENT '当日是否发送告警', + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', + `is_deleted` tinyint(1) DEFAULT '0' COMMENT '逻辑删除', + `low_soe_user_id` varchar(20) DEFAULT NULL COMMENT '低级告警负责人id', + `low_soe_phone` varchar(20) DEFAULT NULL COMMENT '低级告警电话号码', + `middle_soe_user_id` varchar(20) DEFAULT NULL COMMENT '中级告警负责人id', + `middle_soe_phone` varchar(20) DEFAULT NULL COMMENT '中级告警电话号码', + `high_soe_user_id` varchar(20) DEFAULT NULL COMMENT '高级告警负责人id', + `high_soe_phone` varchar(20) DEFAULT NULL COMMENT '高级告警电话号码', + `flow_value` double(12,3) DEFAULT NULL COMMENT '核定流量', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='站点和霍山生态流量电站的关联关系表'; \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java index e6c0c3e..fe2739c 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java @@ -218,7 +218,7 @@ public class HygieneController extends BladeController { @ApiOperation(value = "卫生自查模板详情") @ApiOperationSupport(order = 18) @Operate(label = "卫生自查模板详情", type = BusinessType.QUERY, ignore = false) - public R hygieneTemplateDetail(@RequestParam Long id) { + public R hygieneTemplateDetail(@RequestParam Long id) { HygieneTemplateDetailVO detail = hygieneTemplateService.getHygieneTemplateDetail(id); return R.data(detail); } @@ -227,7 +227,7 @@ public class HygieneController extends BladeController { @ApiOperation(value = "卫生自查模板分页") @ApiOperationSupport(order = 19) @Operate(label = "卫生自查模板分页", type = BusinessType.QUERY, ignore = false) - public R hygieneTemplatePage(@ApiIgnore @RequestParam Map param, Query query) { + public R> hygieneTemplatePage(@ApiIgnore @RequestParam Map param, Query query) { IPage page = hygieneTemplateService.page(Condition.getPage(query), Condition.getQueryWrapper( param, HygieneTemplateEntity.class)); return R.data(page); diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java index 946d92b..8170e95 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java @@ -7,7 +7,6 @@ import org.apache.ibatis.annotations.Mapper; import org.springblade.core.datascope.annotation.UserDataAuth; import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; - /** * 卫生自查计划Mapper类 * diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateDetailService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateDetailService.java index de71dad..463b0b5 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateDetailService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateDetailService.java @@ -18,4 +18,11 @@ public interface IHygieneTemplateDetailService extends IService getListByTemplateId(Long templateId); + + /** + * 删除关联模板详情数据 + * @param templateId 模板id + * @return true-成功,false-失败 + */ + boolean removeReferenceDetail(Long templateId); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateService.java index 71493f9..5f45e16 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneTemplateService.java @@ -39,4 +39,11 @@ public interface IHygieneTemplateService extends IService * @return 详情 */ HygieneTemplateDetailVO getHygieneTemplateDetail(Long id); + + /** + * 根据模板名获取模板 + * @param name 模板名 + * @return 模板实体类 + */ + HygieneTemplateEntity getHygieneTemplateByName(String name); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java index 2c3b176..4ad0ca5 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java @@ -18,6 +18,7 @@ import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; import com.hnac.hzims.safeproduct.service.IHygienePlanService; import com.hnac.hzims.safeproduct.service.IHygieneRecordService; import com.hnac.hzims.safeproduct.service.IHygieneZoneService; +import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.vo.HygienePlanDetailVO; import com.hnac.hzims.safeproduct.vo.HygieneMonthVO; import org.springblade.core.log.exception.ServiceException; @@ -62,15 +63,16 @@ public class HygienePlanServiceImpl extends ServiceImpl zoneList = hygienePlanDTO.getZoneList(); - // 若计划新增成功,新增关联责任区数据 - if (savePlan) { - hygienePlan = getPlanByName(hygienePlanDTO.getName()); - for (HygieneZoneEntity zone : zoneList) { - // 传计划id - if (hygienePlan != null) { - zone.setHygienePlanId(hygienePlan.getId()); - } - String[] scores = zone.getCheckItemScore().split(",|,"); - // 校验检查项总成绩是否为标准总成绩 - getSumScore(scores, hygienePlanDTO.getStandardScore()); - } - // 校验通过则批量新增责任区数据 - return R.status(hygieneZoneService.saveBatch(zoneList)); + hygienePlan = getPlanByName(hygienePlanDTO.getName()); + for (HygieneZoneEntity zone : zoneList) { + zone.setHygienePlanId(hygienePlan.getId()); + String[] scores = zone.getCheckItemScore().split(",|,"); + // 校验检查项总成绩是否为标准总成绩 + BaseUtil.getSumScore(scores, hygienePlanDTO.getStandardScore()); } - return R.status(Boolean.FALSE); + // 校验通过则批量新增责任区数据 + return R.status(hygieneZoneService.saveBatch(zoneList)); } /** @@ -152,18 +151,26 @@ public class HygienePlanServiceImpl extends ServiceImpl zoneList = hygienePlanDTO.getZoneList(); - // 若计划修改成功,修改关联责任区数据 - if (updatePlan) { - for (HygieneZoneEntity zone : zoneList) { - String[] scores = zone.getCheckItemScore().split(",|,"); - // 校验检查项总成绩是否为标准总成绩 - getSumScore(scores, hygienePlanDTO.getStandardScore()); - } - // 校验通过则批量修改责任区数据 - return R.status(hygieneZoneService.updateBatchById(zoneList)); + // 删除旧的责任区数据 + boolean removeZone = hygieneZoneService.removeReferenceZone(hygienePlanDTO.getId()); + if (!removeZone) { + throw new ServiceException("删除旧的责任区数据失败"); + } + // 新增新的责任区数据 + hygienePlan = getPlanByName(hygienePlanDTO.getName()); + for (HygieneZoneEntity zone : zoneList) { + zone.setHygienePlanId(hygienePlan.getId()); + String[] scores = zone.getCheckItemScore().split(",|,"); + // 校验检查项总成绩是否为标准总成绩 + BaseUtil.getSumScore(scores, hygienePlanDTO.getStandardScore()); } - return R.status(Boolean.FALSE); + // 校验通过则批量修改责任区数据 + return R.status(hygieneZoneService.saveBatch(zoneList)); } /** @@ -210,24 +217,6 @@ public class HygienePlanServiceImpl extends ServiceImpl standardScore) { - throw new ServiceException("累计分值超过标准总分值"); - } - } - if (sum < standardScore) { - throw new ServiceException("标准总分值未全部分配"); - } - } - - /** * 根据编码查询卫生自查计划 */ @Override diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java index 24d3a9f..b38db24 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java @@ -84,9 +84,9 @@ public class HygieneRecordServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(HygieneTemplateDetailEntity::getTemplateId, templateId); + List list = this.list(queryWrapper); + List ids = list.stream().map(HygieneTemplateDetailEntity::getId).collect(Collectors.toList()); + return this.removeByIds(ids); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneTemplateServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneTemplateServiceImpl.java index efceb94..af8ff3a 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneTemplateServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneTemplateServiceImpl.java @@ -8,9 +8,9 @@ import com.hnac.hzims.safeproduct.entity.HygieneTemplateEntity; import com.hnac.hzims.safeproduct.mapper.HygieneTemplateMapper; import com.hnac.hzims.safeproduct.service.IHygieneTemplateDetailService; import com.hnac.hzims.safeproduct.service.IHygieneTemplateService; +import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.vo.HygieneTemplateDetailVO; import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.CollectionUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -37,19 +37,28 @@ public class HygieneTemplateServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.lambda().eq(HygieneTemplateEntity::getTemplateName, templateName); - List list = this.list(queryWrapper); - if (CollectionUtil.isNotEmpty(list)) { + // 重名校验 + HygieneTemplateEntity hygieneTemplate = getHygieneTemplateByName(templateName); + if (hygieneTemplate != null) { throw new ServiceException("模板名不可重复"); } - HygieneTemplateEntity hygieneTemplate = new HygieneTemplateEntity(); - hygieneTemplate.setTemplateName(templateName); - boolean saveTemplate = this.save(hygieneTemplate); + // 新增模板 + HygieneTemplateEntity hygieneTemplateEntity = new HygieneTemplateEntity(); + hygieneTemplateEntity.setTemplateName(templateName); + boolean saveTemplate = this.save(hygieneTemplateEntity); if (!saveTemplate) { throw new ServiceException("卫生自查模板新增失败"); } - return hygieneTemplateDetailService.saveBatch(hygieneTemplateDTO.getTemplateDetailList()); + // 新增模板详情 + hygieneTemplate = getHygieneTemplateByName(templateName); + List detailList = hygieneTemplateDTO.getTemplateDetailList(); + for (HygieneTemplateDetailEntity detail : detailList) { + detail.setTemplateId(hygieneTemplate.getId()); + String[] scores = detail.getCheckItemScore().split(",|,"); + // 校验检查项总成绩是否为标准总成绩 + BaseUtil.getSumScore(scores, 100); + } + return hygieneTemplateDetailService.saveBatch(detailList); } /** @@ -60,21 +69,37 @@ public class HygieneTemplateServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(HygieneTemplateEntity::getTemplateName, templateName); queryWrapper.lambda().ne(HygieneTemplateEntity::getId, templateId); - List list = this.list(queryWrapper); - if (CollectionUtil.isNotEmpty(list)) { + HygieneTemplateEntity hygieneTemplate = this.getOne(queryWrapper); + if (hygieneTemplate != null) { throw new ServiceException("模板名不可重复"); } - HygieneTemplateEntity hygieneTemplate = new HygieneTemplateEntity(); - hygieneTemplate.setId(templateId); - hygieneTemplate.setTemplateName(templateName); - boolean updateTemplate = this.updateById(hygieneTemplate); + // 更新模板 + HygieneTemplateEntity hygieneTemplateEntity = new HygieneTemplateEntity(); + hygieneTemplateEntity.setId(templateId); + hygieneTemplateEntity.setTemplateName(templateName); + boolean updateTemplate = this.updateById(hygieneTemplateEntity); if (!updateTemplate) { - throw new ServiceException("卫生自查模板修改失败"); + throw new ServiceException("卫生自查模板更新失败"); } - return hygieneTemplateDetailService.updateBatchById(hygieneTemplateDTO.getTemplateDetailList()); + // 更新模板详情 + // 删除旧的模板详情数据 + boolean removeDetail = hygieneTemplateDetailService.removeReferenceDetail(templateId); + if (!removeDetail) { + throw new ServiceException("卫生自查模板详情数据删除失败"); + } + // 新增新的模板详情数据 + hygieneTemplate = getHygieneTemplateByName(templateName); + List detailList = hygieneTemplateDTO.getTemplateDetailList(); + for (HygieneTemplateDetailEntity detail : detailList) { + detail.setTemplateId(hygieneTemplate.getId()); + String[] scores = detail.getCheckItemScore().split(",|,"); + BaseUtil.getSumScore(scores, 100); + } + return hygieneTemplateDetailService.saveBatch(detailList); } /** @@ -104,4 +129,14 @@ public class HygieneTemplateServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(HygieneTemplateEntity::getTemplateName, name); + return this.getOne(queryWrapper); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java index da74c7f..76aada7 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java @@ -395,4 +395,22 @@ public class BaseUtil { } return fileName; } + + /** + * 计算累计分值 + * @param scores 各项分值 + * @param standardScore 标准总分值 + */ + public static void getSumScore(String[] scores, Integer standardScore) { + int sum = 0; + for (String score : scores) { + sum += Integer.parseInt(score); + if (sum > standardScore) { + throw new ServiceException("累计分值超过标准总分值"); + } + } + if (sum < standardScore) { + throw new ServiceException("标准总分值未全部分配"); + } + } } diff --git a/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql b/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql index 3730612..26bf967 100644 --- a/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql +++ b/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql @@ -31,7 +31,9 @@ CREATE TABLE IF NOT EXISTS `hzims_hygiene_template_detail` ( `id` bigint(20) NOT NULL COMMENT '主键ID', `template_id` bigint(20) NOT NULL COMMENT '模板id', `zone` varchar(50) NOT NULL COMMENT '责任区', + `prinicipal` varchar(20) NOT NULL COMMENT '责任人', `check_item` mediumtext NOT NULL COMMENT '检查项', + `check_item_score` varchar(255) NOT NULL COMMENT '检查项分值', `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',