1
This commit is contained in:
@ -165,7 +165,8 @@ public class EquipmentPlanTypeController {
|
||||
String id = request.getParameter("id");
|
||||
EquipmentPlanType equipmentPlanType = this.equipmentPlanTypeService.selectById(id);
|
||||
model.addAttribute("equipmentPlanType", equipmentPlanType);
|
||||
return "maintenance/equipmentPlanTypeView";
|
||||
// Return edit page so user can view parent and manage child records
|
||||
return "maintenance/equipmentPlanTypeEdit";
|
||||
}
|
||||
/**
|
||||
* 打开编辑界面
|
||||
@ -235,6 +236,12 @@ public class EquipmentPlanTypeController {
|
||||
|
||||
/**
|
||||
* 根据code获取类型下拉数据
|
||||
* 支持多种数据结构:
|
||||
* 1. 标准结构:code='wx'的父记录 -> 返回其子记录
|
||||
* 2. 简化结构:code='wx'的父记录无子记录 -> 返回该父记录本身
|
||||
* 3. 子记录结构:无code='wx'父记录但有type='0'的子记录 -> 返回这些子记录
|
||||
* 4. 扁平结构:只有type='0'的记录(无论pid) -> 返回这些记录
|
||||
* 5. 最终兜底:返回所有相关类型的记录
|
||||
* @param request
|
||||
* @param model
|
||||
* @return
|
||||
@ -242,31 +249,98 @@ public class EquipmentPlanTypeController {
|
||||
@RequestMapping("/getSelectList4Code.do")
|
||||
public String getSelectList4Code(HttpServletRequest request,Model model){
|
||||
String code = request.getParameter("code");
|
||||
String wherestr = "where 1=1 ";
|
||||
String pid = "";
|
||||
|
||||
EquipmentPlanType equipmentPlanType = equipmentPlanTypeService.selectByWhere("where code = '"+code+"' ");
|
||||
if(equipmentPlanType!=null){
|
||||
pid = equipmentPlanType.getId();//获取大类id
|
||||
}
|
||||
|
||||
if(pid!=null && !pid.equals("")){
|
||||
wherestr += " and pid = '"+pid+"'";
|
||||
}else {
|
||||
wherestr += " and pid = '-1'";
|
||||
}
|
||||
|
||||
List<EquipmentPlanType> list = this.equipmentPlanTypeService.selectListByWhere(wherestr+"order by morder asc");
|
||||
JSONArray json = new JSONArray();
|
||||
if(list!=null && list.size()>0){
|
||||
for(int i=0;i<list.size();i++){
|
||||
JSONObject jsonObject =new JSONObject();
|
||||
jsonObject.put("id", list.get(i).getId());
|
||||
jsonObject.put("text", list.get(i).getName());
|
||||
|
||||
if(code == null || code.isEmpty()){
|
||||
model.addAttribute("result", json.toString());
|
||||
return "result";
|
||||
}
|
||||
|
||||
String typeValue = getTypeValueByCode(code);
|
||||
|
||||
// Step 1: Try to find parent record by code
|
||||
EquipmentPlanType parentType = equipmentPlanTypeService.selectByWhere("where code = '"+code+"' ");
|
||||
|
||||
if(parentType != null){
|
||||
// Parent found, try to get children
|
||||
String pid = parentType.getId();
|
||||
List<EquipmentPlanType> list = this.equipmentPlanTypeService.selectListByWhere("where pid = '"+pid+"' order by morder asc");
|
||||
|
||||
if(list != null && list.size() > 0){
|
||||
// Standard case: return children
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", list.get(i).getId());
|
||||
jsonObject.put("text", list.get(i).getName());
|
||||
json.add(jsonObject);
|
||||
}
|
||||
} else {
|
||||
// No children, return parent itself as the only option
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", parentType.getId());
|
||||
jsonObject.put("text", parentType.getName());
|
||||
json.add(jsonObject);
|
||||
}
|
||||
} else if(typeValue != null){
|
||||
// Step 2: No parent with code, try multiple fallback strategies
|
||||
|
||||
// 2a: First try child records with specific type (pid != '-1')
|
||||
List<EquipmentPlanType> list = this.equipmentPlanTypeService.selectListByWhere(
|
||||
"where type = '"+typeValue+"' and pid != '-1' order by morder asc");
|
||||
|
||||
if(list != null && list.size() > 0){
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", list.get(i).getId());
|
||||
jsonObject.put("text", list.get(i).getName());
|
||||
json.add(jsonObject);
|
||||
}
|
||||
} else {
|
||||
// 2b: Try all records with specific type (including root records with pid='-1')
|
||||
list = this.equipmentPlanTypeService.selectListByWhere(
|
||||
"where type = '"+typeValue+"' order by morder asc");
|
||||
|
||||
if(list != null && list.size() > 0){
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", list.get(i).getId());
|
||||
jsonObject.put("text", list.get(i).getName());
|
||||
json.add(jsonObject);
|
||||
}
|
||||
} else {
|
||||
// 2c: Final fallback - return all root records (pid='-1')
|
||||
// This handles the case where user added parent records without setting type
|
||||
list = this.equipmentPlanTypeService.selectListByWhere(
|
||||
"where pid = '-1' order by morder asc");
|
||||
if(list != null && list.size() > 0){
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", list.get(i).getId());
|
||||
jsonObject.put("text", list.get(i).getName());
|
||||
json.add(jsonObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model.addAttribute("result", json.toString());
|
||||
return "result";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取对应的type值
|
||||
* @param code
|
||||
* @return type值
|
||||
*/
|
||||
private String getTypeValueByCode(String code){
|
||||
if(EquipmentPlanType.Code_Type_Wx.equals(code)){
|
||||
return EquipmentPlanType.Type_Wx; // "0"
|
||||
} else if(EquipmentPlanType.Code_Type_By.equals(code)){
|
||||
return EquipmentPlanType.Type_Ty; // "1"
|
||||
} else if(EquipmentPlanType.Code_Type_Dx.equals(code)){
|
||||
return EquipmentPlanType.Type_Dx; // "5"
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +50,12 @@ public class PipelineDataController {
|
||||
if (request.getParameter("search_pipeline_area") != null && !request.getParameter("search_pipeline_area").isEmpty()) {
|
||||
wherestr += " and pipeline_area = '" + request.getParameter("search_pipeline_area") + "'";
|
||||
}
|
||||
if (request.getParameter("search_pipe_material") != null && !request.getParameter("search_pipe_material").isEmpty()) {
|
||||
wherestr += " and pipe_material like '%" + request.getParameter("search_pipe_material") + "%'";
|
||||
}
|
||||
if (request.getParameter("search_associated_plant") != null && !request.getParameter("search_associated_plant").isEmpty()) {
|
||||
wherestr += " and associated_plant like '%" + request.getParameter("search_associated_plant") + "%'";
|
||||
}
|
||||
PageHelper.startPage(page, rows);
|
||||
List<PipelineData> list = this.pipelineDataService.selectListByWhere(wherestr + orderstr);
|
||||
PageInfo<PipelineData> pInfo = new PageInfo<PipelineData>(list);
|
||||
|
||||
@ -444,7 +444,11 @@ public class MPointController {
|
||||
if (dbCount != esCount) {
|
||||
// 数据不一致,将数据库全量数据更新到ES
|
||||
logger.info("ES与DB数据总数不一致,执行全量同步并返回数据库结果");
|
||||
this.mPointService.syncAllDbDataToEs();
|
||||
try {
|
||||
this.syncAllDbDataToEs();
|
||||
} catch (Exception e) {
|
||||
logger.error("执行全量同步ES异常:", e);
|
||||
}
|
||||
|
||||
// 构建数据库查询条件,返回数据库结果至前端
|
||||
String wherestr = " where 1=1 ";
|
||||
@ -587,6 +591,33 @@ public class MPointController {
|
||||
return new ModelAndView("result");
|
||||
}
|
||||
|
||||
public void syncAllDbDataToEs() {
|
||||
logger.info("ES与数据库数据总数不一致,开始全量同步数据库数据到ES...");
|
||||
MPoint query = new MPoint();
|
||||
query.setWhere("where 1=1");
|
||||
List<MPoint> allDbData = mPointService.selectListAllByWhere(query);
|
||||
if (allDbData != null && !allDbData.isEmpty()) {
|
||||
List<MPointES> esList = new ArrayList<>();
|
||||
for (MPoint mPoint : allDbData) {
|
||||
try {
|
||||
MPointES mPointES = MPointES.format(mPoint);
|
||||
esList.add(mPointES);
|
||||
} catch (Exception e) {
|
||||
logger.error("转换MPointES失败, id=" + mPoint.getId() + ", error=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (!esList.isEmpty()) {
|
||||
try {
|
||||
mPointRepo.saveAll(esList);
|
||||
logger.info("全量同步完成,共同步 " + esList.size() + " 条数据到ES");
|
||||
} catch (Exception e) {
|
||||
logger.error("批量保存ES失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getKeyword(String searchName, List<Unit> units) {
|
||||
int lastMatchNum = 1;
|
||||
String keyword = "";
|
||||
|
||||
@ -77,6 +77,18 @@ public class PipelineData extends SQLAdapter implements Serializable {
|
||||
@Column(name = "pipeline_area", length = 20)
|
||||
private String pipelineArea;
|
||||
|
||||
/**
|
||||
* 管道材质
|
||||
*/
|
||||
@Column(name = "pipe_material", length = 50)
|
||||
private String pipeMaterial;
|
||||
|
||||
/**
|
||||
* 所属厂站
|
||||
*/
|
||||
@Column(name = "associated_plant", length = 100)
|
||||
private String associatedPlant;
|
||||
|
||||
// 构造方法
|
||||
public PipelineData() {
|
||||
}
|
||||
@ -162,6 +174,22 @@ public class PipelineData extends SQLAdapter implements Serializable {
|
||||
this.pipelineArea = pipelineArea;
|
||||
}
|
||||
|
||||
public String getPipeMaterial() {
|
||||
return pipeMaterial;
|
||||
}
|
||||
|
||||
public void setPipeMaterial(String pipeMaterial) {
|
||||
this.pipeMaterial = pipeMaterial;
|
||||
}
|
||||
|
||||
public String getAssociatedPlant() {
|
||||
return associatedPlant;
|
||||
}
|
||||
|
||||
public void setAssociatedPlant(String associatedPlant) {
|
||||
this.associatedPlant = associatedPlant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PipelineData{" +
|
||||
@ -175,6 +203,8 @@ public class PipelineData extends SQLAdapter implements Serializable {
|
||||
", endGroundElevationM=" + endGroundElevationM +
|
||||
", pipelineInvertElevationM=" + pipelineInvertElevationM +
|
||||
", pipelineArea='" + pipelineArea + '\'' +
|
||||
", pipeMaterial='" + pipeMaterial + '\'' +
|
||||
", associatedPlant='" + associatedPlant + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -12,10 +12,13 @@
|
||||
<result column="end_ground_elevation_m" property="endGroundElevationM" jdbcType="DECIMAL" />
|
||||
<result column="pipeline_invert_elevation_m" property="pipelineInvertElevationM" jdbcType="DECIMAL" />
|
||||
<result column="pipeline_area" property="pipelineArea" jdbcType="VARCHAR" />
|
||||
<result column="pipe_material" property="pipeMaterial" jdbcType="VARCHAR" />
|
||||
<result column="associated_plant" property="associatedPlant" jdbcType="VARCHAR" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List" >
|
||||
id, pipeline_name, diameter_mm, length_m, start_burial_depth_m, end_burial_depth_m,
|
||||
start_ground_elevation_m, end_ground_elevation_m, pipeline_invert_elevation_m, pipeline_area
|
||||
start_ground_elevation_m, end_ground_elevation_m, pipeline_invert_elevation_m, pipeline_area,
|
||||
pipe_material, associated_plant
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
|
||||
select
|
||||
@ -31,11 +34,12 @@
|
||||
insert into tb_pipeline_data (pipeline_name, diameter_mm,
|
||||
length_m, start_burial_depth_m, end_burial_depth_m,
|
||||
start_ground_elevation_m, end_ground_elevation_m,
|
||||
pipeline_invert_elevation_m, pipeline_area)
|
||||
pipeline_invert_elevation_m, pipeline_area, pipe_material, associated_plant)
|
||||
values (#{pipelineName,jdbcType=VARCHAR}, #{diameterMm,jdbcType=DECIMAL},
|
||||
#{lengthM,jdbcType=DECIMAL}, #{startBurialDepthM,jdbcType=DECIMAL}, #{endBurialDepthM,jdbcType=DECIMAL},
|
||||
#{startGroundElevationM,jdbcType=DECIMAL}, #{endGroundElevationM,jdbcType=DECIMAL},
|
||||
#{pipelineInvertElevationM,jdbcType=DECIMAL}, #{pipelineArea,jdbcType=VARCHAR})
|
||||
#{pipelineInvertElevationM,jdbcType=DECIMAL}, #{pipelineArea,jdbcType=VARCHAR},
|
||||
#{pipeMaterial,jdbcType=VARCHAR}, #{associatedPlant,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.sipai.entity.pipeline.PipelineData" useGeneratedKeys="true" keyProperty="id" >
|
||||
insert into tb_pipeline_data
|
||||
@ -68,6 +72,12 @@
|
||||
<if test="pipelineArea != null" >
|
||||
pipeline_area,
|
||||
</if>
|
||||
<if test="pipeMaterial != null" >
|
||||
pipe_material,
|
||||
</if>
|
||||
<if test="associatedPlant != null" >
|
||||
associated_plant,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
||||
|
||||
@ -98,6 +108,12 @@
|
||||
<if test="pipelineArea != null" >
|
||||
#{pipelineArea,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="pipeMaterial != null" >
|
||||
#{pipeMaterial,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="associatedPlant != null" >
|
||||
#{associatedPlant,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.sipai.entity.pipeline.PipelineData" >
|
||||
@ -130,6 +146,12 @@
|
||||
<if test="pipelineArea != null" >
|
||||
pipeline_area = #{pipelineArea,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="pipeMaterial != null" >
|
||||
pipe_material = #{pipeMaterial,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="associatedPlant != null" >
|
||||
associated_plant = #{associatedPlant,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
@ -143,7 +165,9 @@
|
||||
start_ground_elevation_m = #{startGroundElevationM,jdbcType=DECIMAL},
|
||||
end_ground_elevation_m = #{endGroundElevationM,jdbcType=DECIMAL},
|
||||
pipeline_invert_elevation_m = #{pipelineInvertElevationM,jdbcType=DECIMAL},
|
||||
pipeline_area = #{pipelineArea,jdbcType=VARCHAR}
|
||||
pipeline_area = #{pipelineArea,jdbcType=VARCHAR},
|
||||
pipe_material = #{pipeMaterial,jdbcType=VARCHAR},
|
||||
associated_plant = #{associatedPlant,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
<select id="selectListByWhere" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
|
||||
@ -17,15 +17,14 @@ import com.sipai.service.equipment.EquipmentCardService;
|
||||
import com.sipai.service.user.UnitService;
|
||||
import com.sipai.service.work.ModbusFigService;
|
||||
import com.sipai.service.work.ScadaPic_MPointService;
|
||||
import com.sipai.tools.CommString;
|
||||
import com.sipai.tools.CommUtil;
|
||||
import com.sipai.tools.ValueTypeEnum;
|
||||
import com.sipai.tools.*;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
@ -713,32 +712,6 @@ public class MPointService {
|
||||
/**
|
||||
* 将数据库全量数据同步到ES
|
||||
*/
|
||||
public void syncAllDbDataToEs() {
|
||||
logger.info("ES与数据库数据总数不一致,开始全量同步数据库数据到ES...");
|
||||
MPoint query = new MPoint();
|
||||
query.setWhere("where 1=1");
|
||||
List<MPoint> allDbData = mPointDao.selectListByWhere(query);
|
||||
if (allDbData != null && allDbData.size() > 0) {
|
||||
List<MPointES> esList = new ArrayList<>();
|
||||
for (MPoint mPoint : allDbData) {
|
||||
try {
|
||||
MPointES mPointES = MPointES.format(mPoint);
|
||||
esList.add(mPointES);
|
||||
} catch (Exception e) {
|
||||
logger.error("转换MPointES失败, id=" + mPoint.getId() + ", error=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (esList.size() > 0) {
|
||||
try {
|
||||
mPointRepo.saveAll(esList);
|
||||
logger.info("全量同步完成,共同步 " + esList.size() + " 条数据到ES");
|
||||
} catch (Exception e) {
|
||||
logger.error("批量保存ES失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int updateValue(String bizId, MPoint entity, MPointHistory mPointHistory) {
|
||||
@ -1818,4 +1791,9 @@ public class MPointService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@DataSourceTypeAnno(value = DataSources.SCADA_0533JS)
|
||||
public List<MPoint> selectListAllByWhere(MPoint query) {
|
||||
return mPointDao.selectListByWhere(query);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,9 @@ package com.sipai.tools;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/*@Aspect // for aop
|
||||
@Component // for auto scan
|
||||
@ -20,11 +23,19 @@ public class DataSourceInterceptor {
|
||||
// return;
|
||||
// }
|
||||
String fullMethodPath = signature.toString();
|
||||
MethodSignature methodSignature = (MethodSignature) signature;
|
||||
Method method = methodSignature.getMethod();
|
||||
DataSourceTypeAnno typeAnno = method.getAnnotation(DataSourceTypeAnno.class);
|
||||
DataSources sourceEnum = null;
|
||||
if (typeAnno != null) {
|
||||
sourceEnum = typeAnno.value();
|
||||
}
|
||||
// Object argus = argusObjects[0];
|
||||
if (fullMethodPath.contains(".scada.")) {
|
||||
DataSourceHolder.setDataSources(DataSources.valueOf("SCADA_0533JS"));
|
||||
String packageName = method.getDeclaringClass().getName();
|
||||
if (fullMethodPath.contains(".scada.") || packageName.contains(".scada.") || (sourceEnum == DataSources.SCADA_0533JS)) {
|
||||
DataSourceHolder.setDataSources(DataSources.SCADA_0533JS);
|
||||
} else {
|
||||
DataSourceHolder.setDataSources(DataSources.valueOf("MASTER"));
|
||||
DataSourceHolder.setDataSources(DataSources.MASTER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
17
src/main/java/com/sipai/tools/DataSourceTypeAnno.java
Normal file
17
src/main/java/com/sipai/tools/DataSourceTypeAnno.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.sipai.tools;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 自定义注解
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME) // 在运行时可见
|
||||
@Target(ElementType.METHOD) // 注解可以用在方法上
|
||||
public @interface DataSourceTypeAnno {
|
||||
//使用方式在service层方法上添加@DataSourceTypeAnno(DataSourceEnum.数据源枚举类型)用于指定所使用的数据源
|
||||
DataSources value() default DataSources.MASTER;
|
||||
// DataSourceEnum value() default DataSourceEnum.SCADA_JSWS;
|
||||
}
|
||||
Reference in New Issue
Block a user