完成初版

This commit is contained in:
2026-06-18 16:26:31 +08:00
parent 6ca67ec941
commit 8e3dd5e1cd
27 changed files with 5024 additions and 678 deletions

View File

@@ -3,6 +3,7 @@ package com.seeyon.apps.assetsmap.constants;
public enum AssetsMapConstans {
plugin("assetsmap",""),
ASSETSFORMNO("assetsformno","资产表单"),
ASSETSDETAILURLCONFIGFORMNO("","资产详情URL配置表单"),
;
private String defaultValue;

View File

@@ -0,0 +1,54 @@
package com.seeyon.apps.assetsmap.fieldCtrl;
import com.seeyon.cap4.form.bean.ParamDefinition;
import com.seeyon.cap4.form.bean.fieldCtrl.FormFieldCustomCtrl;
import com.seeyon.cap4.form.util.Enums;
public class BoundConfigFieldCtrl extends FormFieldCustomCtrl {
@Override
public String getPCInjectionInfo() {
return "{path:'apps_res/cap/customCtrlResources/goMapBtnResources',jsUri:'/js/boundConfig.js',initMethod:'init',nameSpace:'" + getNameSpace() + "'}";
}
@Override
public String getMBInjectionInfo() {
return "{path:'http://mapResource.v5.cmp/v1.0.0/',weixinpath:'invoice',jsUri:'js/location.js',initMethod:'init',nameSpace:'"+getNameSpace()+"'}";
}
@Override
public String getKey() {
return "17179214358792461983";
}
@Override
public boolean canUse(Enums.FormType formType) {
return true;
}
@Override
public String[] getDefaultVal(String s) {
return new String[0];
}
public String getNameSpace() {
return "field_" + this.getKey();
}
public String getFieldLength() {
return "20";
}
@Override
public String getText() {
return "绘制资产边界";
}
@Override
public void init() {
setPluginId("assetsmap");
setIcon("cap-icon-custom-button");
ParamDefinition param = new ParamDefinition();
param.setParamType(Enums.ParamType.button);
addDefinition(param);
}
}

View File

@@ -0,0 +1,61 @@
package com.seeyon.apps.assetsmap.fieldCtrl;
import com.seeyon.cap4.form.bean.ParamDefinition;
import com.seeyon.cap4.form.bean.fieldCtrl.FormFieldCustomCtrl;
import com.seeyon.cap4.form.util.Enums;
public class GoMapFieldCtrl extends FormFieldCustomCtrl {
@Override
public String getPCInjectionInfo() {
return "{path:'apps_res/cap/customCtrlResources/goMapBtnResources',jsUri:'/js/goMapInit.js',initMethod:'init',nameSpace:'" + getNameSpace() + "'}";
}
@Override
public String getMBInjectionInfo() {
return "{path:'http://mapResource.v5.cmp/v1.0.0/',weixinpath:'invoice',jsUri:'js/location.js',initMethod:'init',nameSpace:'"+getNameSpace()+"'}";
}
@Override
public String getKey() {
return "17179215134928371056";
}
@Override
public boolean canUse(Enums.FormType formType) {
return true;
}
@Override
public String[] getDefaultVal(String s) {
return new String[0];
}
public String getNameSpace() {
return "field_" + this.getKey();
}
public String getFieldLength() {
return "20";
}
@Override
public String getText() {
return "跳转资产地图按钮";
}
/**
* 控件初始化接口此接口在控件初始化的时候会调用主要用于定义控件所属插件id、在表单编辑器中的图标、表单编辑器中有哪些属性可以设置。
* 使用举例:在接口中定义自定义控件在在表单编辑器中有哪些控件属性需要配置
*/
@Override
public void init() {
//设置图标和插件ID
setPluginId("assetsmap");
setIcon("cap-icon-custom-button");
// 自定义参数
ParamDefinition esignContractCompareBtnParam = new ParamDefinition();
esignContractCompareBtnParam.setParamType(Enums.ParamType.button);
addDefinition(esignContractCompareBtnParam);
}
}

View File

@@ -0,0 +1,54 @@
package com.seeyon.apps.assetsmap.fieldCtrl;
import com.seeyon.cap4.form.bean.ParamDefinition;
import com.seeyon.cap4.form.bean.fieldCtrl.FormFieldCustomCtrl;
import com.seeyon.cap4.form.util.Enums;
public class LocationFieldCtrl extends FormFieldCustomCtrl {
@Override
public String getPCInjectionInfo() {
return "{path:'apps_res/cap/customCtrlResources/goMapBtnResources',jsUri:'/js/location.js',initMethod:'init',nameSpace:'" + getNameSpace() + "'}";
}
@Override
public String getMBInjectionInfo() {
return getPCInjectionInfo();
}
@Override
public String getKey() {
return "17179214358792461984";
}
@Override
public boolean canUse(Enums.FormType formType) {
return true;
}
@Override
public String[] getDefaultVal(String s) {
return new String[0];
}
public String getNameSpace() {
return "field_" + this.getKey();
}
public String getFieldLength() {
return "20";
}
@Override
public String getText() {
return "资产定位按钮";
}
@Override
public void init() {
setPluginId("assetsmap");
setIcon("cap-icon-custom-button");
ParamDefinition param = new ParamDefinition();
param.setParamType(Enums.ParamType.button);
addDefinition(param);
}
}

View File

@@ -0,0 +1,49 @@
package com.seeyon.apps.assetsmap.kit;
import com.seeyon.ctp.common.SystemEnvironment;
/**
* Description
* <pre>获取A8产品下面的文件夹路径</pre>
* Date 2019年10月11日 上午9:42:49<br>
* Copyright(c) Beijing Seeyon Software Co.,LTD
*/
public class A8FolderKit {
private static String A8_APPLICAION_FLODER = "";
/**
* Description:
* <pre>获取到A8的安装模目录ApacheJetspeed目录的父目录</pre>
* @return
*/
public static String getApplicationFolder() {
if("".equals(A8_APPLICAION_FLODER)) {
String installPath = SystemEnvironment.getApplicationFolder();
A8_APPLICAION_FLODER = installPath.split("ApacheJetspeed")[0].replaceAll("\\\\", "/");
}
return A8_APPLICAION_FLODER;
}
/**
* Description:
* <pre>获取配置文件的地址</pre>
* @return
*/
public static String getCodePropertiesPath() {
String path = getApplicationFolder() + "ApacheJetspeed/webapps/seeyon/WEB-INF/classes/code.properties";
return path;
}
public static String getPropertiesPath(String fileName) {
String path = getApplicationFolder() + "ApacheJetspeed/webapps/seeyon/WEB-INF/classes/" + fileName;
return path;
}
public static String getZSJCodePropertiesPath() {
String path = getApplicationFolder() + "ApacheJetspeed/webapps/seeyon/WEB-INF/classes/ZSJcode.properties";
return path;
}
}

View File

@@ -0,0 +1,196 @@
package com.seeyon.apps.assetsmap.kit;
import com.seeyon.cap4.form.bean.*;
import com.seeyon.cap4.form.service.CAP4FormManager;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.log.CtpLogFactory;
import org.apache.commons.logging.Log;
import java.util.List;
import java.util.Map;
/**
* Description
* <pre>操作CAP4表单和字段</pre>
* @author FanGaowei<br>
* Copyright(c) Beijing Seeyon Software Co.,LTD
*/
public class CAP4FormKit {
private static final Log LOGGER = CtpLogFactory.getLog(CAP4FormKit.class);
public static FormBean getFormBean(CAP4FormManager cap4FormManager, String code) {
FormBean formBean = null;
try {
formBean = cap4FormManager.getFormByFormCode(code);
} catch(BusinessException e) {
LOGGER.error("获取表单发生异常,编号:" + code, e);
}
return formBean;
}
/**
* 根据表单的显示名称获取字段的值
* @param bean
* @param disPlay
* @return
*/
public static Object getFieldValue(FormDataBean bean, String disPlay) {
if(bean == null) {
return null;
}
FormTableBean table = bean.getFormTable();
if(table == null) {
return null;
}
FormFieldBean field = table.getFieldBeanByDisplay(disPlay);
if(field == null) {
return null;
}
return bean.getFieldValue(field.getName());
}
public static int getIntValue(FormDataBean bean, String disPlay) {
Object value = getFieldValue(bean, disPlay);
return StrKit.toInteger(value);
}
public static String getFieldStrValue(FormDataBean bean, String disPlay) {
Object value = getFieldValue(bean, disPlay);
return StrKit.str(value);
}
public static Object getFieldValueByName(FormDataBean bean, String fieldName) {
return bean.getFieldValue(fieldName);
}
/**
* 根据表单的显示名称获取字段是 field000
* @param bean
* @param disPlay
* @return
*/
public static String getFieldTaleId(FormBean bean, String disPlay) {
if(bean == null) {
return null;
}
FormTableBean table = bean.getMasterTableBean();
return getFieldTaleId(table, disPlay);
}
/**
* 直接根据table来获取
* @param table
* @param disPlay
* @return
*/
public static String getFieldTaleId(FormTableBean table, String disPlay) {
if(table == null) {
return null;
}
FormFieldBean field = table.getFieldBeanByDisplay(disPlay);
if(field == null) {
return null;
}
return field.getName();
}
public static String getFieldTaleId(FormDataBean bean, String disPlay) {
if(bean == null) {
return null;
}
FormTableBean table = bean.getFormTable();
if(table == null) {
return null;
}
FormFieldBean field = table.getFieldBeanByDisplay(disPlay);
if(field == null) {
return null;
}
return field.getName();
}
public static FormFieldBean getFieldBean(FormDataBean bean, String disPlay) {
if(bean == null) {
return null;
}
FormTableBean table = bean.getFormTable();
if(table == null) {
return null;
}
return table.getFieldBeanByDisplay(disPlay);
}
public static FormFieldBean getFieldBean(FormTableBean bean, String disPlay) {
if(bean == null) {
return null;
}
return bean.getFieldBeanByDisplay(disPlay);
}
/**
* Description:
* <pre></pre>
* @param bean 这里的bean必须是getMasterBean() 方法获取到的bean
* @param disPlay
* @param value
*/
public static void setCellValue(FormDataBean bean, String disPlay, Object value) {
FormFieldBean cell = CAP4FormKit.getFieldBean(bean, disPlay);
if(cell != null) {
bean.addFieldValue(cell.getName(), value);
}
}
public static void setCellValue(FormDataSubBean bean, String disPlay, Object value) {
FormFieldBean cell = CAP4FormKit.getFieldBean(bean, disPlay);
if(cell != null) {
bean.addFieldValue(cell.getName(), value);
}
}
/**
* Description:
* <pre>只适用于只有一个子表的表单</pre>
* @param colManager
* @param data
* @return
* @throws Exception
*/
public static List<FormDataSubBean> getSubBeans(FormDataMasterBean master) throws Exception {
Map<String, List<FormDataSubBean>> subs = master.getSubTables();
if(null != subs && subs.size() > 0) {
for(String key : subs.keySet()) {
return subs.get(key);
}
}
return null;
}
public static List<FormDataSubBean> getSubBeansByDisPlay(FormDataMasterBean master, String display) throws Exception {
Map<String, List<FormDataSubBean>> subs = master.getSubTables();
if(null != subs && subs.size() > 0) {
for(String key : subs.keySet()) {
if(display.equals(subs.get(key).get(0).getFormTable().getDisplay())) {
return subs.get(key);
}
}
}
return null;
}
/**
* Description:
* <pre>获取从表字段</pre>
* @param sub
* @param disPlay
* @return
*/
public static Object getSubFieldValue(FormDataSubBean sub, String disPlay) {
return getFieldValue(sub, disPlay);
}
}

View File

@@ -0,0 +1,92 @@
package com.seeyon.apps.assetsmap.kit;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.util.JDBCAgent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* <pre>
* 直接操作数据库的类
* </pre>
* @date 2018年11月8日 上午11:10:15
* @Copyright(c) Beijing Seeyon Software Co.,LTD
*/
public class DBKit {
@SuppressWarnings("unchecked")
public static List<Map<String, Object>> excuteSQL(String sql, List<Object> params) throws Exception {
List<Map<String, Object>> list = new ArrayList<>();
JDBCAgent jdbc = new JDBCAgent(true, false);
try {
if(null == params) {
jdbc.execute(sql);
} else {
jdbc.execute(sql, params);
}
if(!sql.startsWith("update")) {
list = jdbc.resultSetToList();
}
} catch(Exception e) {
e.printStackTrace();
throw e;
} finally {
jdbc.close();
}
return list;
}
public static int updateBatch(String sql, List<List<Object>> params) throws BusinessException {
JDBCAgent agent = new JDBCAgent(true, false);
try {
agent.batch1Prepare(sql);
for(List<Object> param : params) {
agent.batch2Add(param);
}
return agent.batch3Execute();
} catch(Exception e) {
throw new BusinessException(e);
} finally {
agent.close();
}
}
/**
* 不成熟按照这个自己进行sql的编写只需要获取字段是 数据库的 field000 就行 根据cap4formkit。getFieldTableId
* sub表也一样只是多一步判断而已如果只有一个重复表就不存在
* @param formbean 根据表单编号获取
* @param fields field1, "商品编号" 会解析成 field000x as field1, 如果不存在则直接用后面的
* @param conditions
* @param params
* @return
* @throws Exception
*/
/*public static List<Map<String, Object>> selectSQL(FormBean formbean, Map<String, String> fields, List<FormCondition> conditions) throws Exception {
List<Object> params = new ArrayList<Object>();
StringBuffer sb = new StringBuffer();
sb.append("select ");
for(String key : fields.keySet()) {
String field = CAP4FormKit.getFieldTaleId(formbean, fields.get(key));
if(StrKit.isNull(field)) {
field = fields.get(key);
}
sb.append(" ").append(field).append(" as ").append(key).append(",");
}
sb.deleteCharAt(sb.lastIndexOf(","));
sb.append(" from ").append(formbean.getMasterTableBean().getTableName());
sb.append(" where 1 = 1 ");
if(!StrKit.isNull(conditions)) {
for(FormCondition c : conditions) {
sb.append(ConditionKit.getWhere(formbean, c));
params.add(c.getParam1());
if(null != c.getParam2()) {
params.add(c.getParam2());
}
}
}
return excuteSQL(sb.toString(), params);
}*/
}

View File

@@ -0,0 +1,293 @@
package com.seeyon.apps.assetsmap.kit;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 日期处理工具类
* @Copyright Beijing Seeyon Software Co.,LTD
*/
public class DateKit {
private static SimpleDateFormat simple = new SimpleDateFormat("yyyyMMdd");
private static SimpleDateFormat sixFormat = new SimpleDateFormat("yyMMdd");
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM");
private static SimpleDateFormat weekDay = new SimpleDateFormat("MM-dd");
private static SimpleDateFormat hour = new SimpleDateFormat("HH:mm");
private static SimpleDateFormat detailDate = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private static final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五","星期六" };
public static int getYear(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.YEAR);
}
public static String getSixDate() {
return getSixDate(null);
}
public static String getSixDate(Date date) {
if(null == date) {
return sixFormat.format(new Date());
}
return sixFormat.format(date);
}
/**
* 获取这个时间属于一年的第几周
* @param date
* @return
*/
public static int getWeekNum(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int week = cal.get(Calendar.WEEK_OF_YEAR);
// 如果是星期天那么需要减1
if("星期日".equals(DateKit.getDayWeekName(date))) {
week -= 1;
}
return week;
}
/**
* Description:
*
* <pre>
* 获取一周
* </pre>
*
* @param date
* @return
*/
public static void getWeekInterval(Map<String, Object> param) {
Calendar cal = Calendar.getInstance();
// 判断要计算的日期是否是周日,如果是则减一天计算周六的,否则会出问题,计算到下一周去了
int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
if(1 == dayWeek) {
cal.add(Calendar.DAY_OF_MONTH, -1);
}
// System.out.println("要计算日期为:" + sdf.format(cal.getTime())); // 输出要计算日期
// 设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
cal.setFirstDayOfWeek(Calendar.MONDAY);
// 获得当前日期是一个星期的第几天
int day = cal.get(Calendar.DAY_OF_WEEK);
// 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
param.put("startDate", cal.getTime());
// System.out.println("所在周星期一的日期:" + imptimeBegin);
cal.add(Calendar.DATE, 6);
param.put("endDate", cal.getTime());
// System.out.println("所在周星期日的日期:" + imptimeEnd);
}
/**
* Description:
*
* <pre>
* 根据传入的日期,获取当前日期所在的一周时间段
* </pre>
*
* @param date
* @return
*/
public static void getWeekInterval(Map<String, Object> param, Date now) {
Calendar cal = Calendar.getInstance();
cal.setTime(now);
// 判断要计算的日期是否是周日,如果是则减一天计算周六的,否则会出问题,计算到下一周去了
int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
if(1 == dayWeek) {
cal.add(Calendar.DAY_OF_MONTH, -1);
}
// System.out.println("要计算日期为:" + sdf.format(cal.getTime())); // 输出要计算日期
// 设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
cal.setFirstDayOfWeek(Calendar.MONDAY);
// 获得当前日期是一个星期的第几天
int day = cal.get(Calendar.DAY_OF_WEEK);
// 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
String time = DateKit.getDayDate(cal.getTime()) + " 00:00:00";
try {
param.put("beginDate", DateKit.getdayDate(time));
} catch(Exception e) {
// TODO
}
// System.out.println("所在周星期一的日期:" + imptimeBegin);
cal.add(Calendar.DATE, 6);
time = DateKit.getDayDate(cal.getTime()) + " 23:59:59";
try {
param.put("endDate", DateKit.getdayDate(time));
} catch(Exception e) {
//
}
// System.out.println("所在周星期日的日期:" + imptimeEnd);
}
public static String getSimpleDate(Date date) {
if(date == null) {
return "";
}
return simple.format(date);
}
/**
* 给日志格式化使用
* @param date
* @return
*/
public static String getDate4Cal(Date date) {
if(date == null) {
return "";
}
return hour.format(date);
}
public static String getDateString(Date date) {
if(date == null) {
return "";
}
return sdf.format(date);
}
public static String getDayDate(Date date) {
if(date == null) {
return "";
}
return dayFormat.format(date);
}
public static String getWeekDay(Date date) {
if(date == null) {
return "";
}
return weekDay.format(date);
}
/**
* Description:
*
* <pre>
* 获取多少天以后的日期
* </pre>
*
* @param day
* @return
*/
public static Date getDayAfter(int day) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, day);
return cal.getTime();
}
// 获得某天的几天后
public static Date getDayAfter(Date d, int day) {
Calendar cal = Calendar.getInstance();
cal.setTime(d);
cal.add(Calendar.DATE, day);
return cal.getTime();
}
/**
* 获取一个月有多少天
* @param year
* @param month
* @return
*/
public static int getDaysByYearMonth(int year, int month) {
Calendar a = Calendar.getInstance();
a.set(Calendar.YEAR, year);
a.set(Calendar.MONTH, month);
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
int maxDate = a.get(Calendar.DATE);
return maxDate;
}
/**
* 获取今天是星期几
* @param date
* @return
*/
public static String getDayWeekName(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
if(dayOfWeek < 0)
dayOfWeek = 0;
return dayNames[dayOfWeek];
}
/**
* 解析时间先解析yyyy-MM-dd HH:mm:ss
* @param dateStr
* @return
* @throws ParseException
* @throws Exception
*/
public static Date getdayDate(String dateStr) throws Exception {
try {
return sdf.parse(dateStr);
} catch(Exception e) {
try {
return detailDate.parse(dateStr);
} catch(Exception e1) {
try {
return dayFormat.parse(dateStr);
} catch(Exception e2) {
try {
return simple.parse(dateStr);
}
catch(Exception e3) {
return monthFormat.parse(dateStr);
}
}
}
}
}
/**
* 根据时间获取周区间字符串
* @param now
* @return 第XX周2018-08-27至2018-09-02
*/
public static String getWeekNumAndDateZone(Date now) {
StringBuffer sb = new StringBuffer();
sb.append("");
sb.append(getWeekNum(now));
sb.append("周:");
Map<String, Object> param = new HashMap<String, Object>();
getWeekInterval(param, now);
Date beginDate = (Date)param.get("beginDate");
Date endDate = (Date)param.get("endDate");
sb.append(dayFormat.format(beginDate));
sb.append("");
sb.append(dayFormat.format(endDate));
return sb.toString();
}
/**
* 根据日期和时间获取一个返回该日期该时间的date
* @param d 日期
* @param time 时间 HH:mm格式
* @return d日期+time时间
* @throws ParseException
*/
public static Date getDateFromTime(Date d, String time) throws ParseException {
String dateTime = dayFormat.format(d) + " " + time;
return detailDate.parse(dateTime);
}
}

View File

@@ -0,0 +1,115 @@
package com.seeyon.apps.assetsmap.kit;
import org.apache.tools.ant.util.DateUtils;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
* @date 2018年5月23日上午9:05:01
* @Copyright Beijing Seeyon Software Co.,LTD
*/
public class StrKit {
public static String str(Object o) {
if(o == null) {
return "";
}
if(o instanceof Date) {
return DateUtils.format((Date) o, "yyyy-MM-dd HH:mm:ss");
}
if(o instanceof String) {
return (String)o;
}
return o.toString();
}
public static float toFloat(Object o) {
if(o == null) {
return 0f;
} else if(o instanceof Float) {
return (Float)o;
} else if(o instanceof String) {
return Float.valueOf((String)o);
} else if(o instanceof BigDecimal) {
return ((BigDecimal)o).floatValue();
}
return 0f;
}
public static Long toLong(Object o) {
if(null == o) {
return 0L;
} else if(o instanceof Long) {
return (Long)o;
} else if(o instanceof String) {
if("".equals(o)) {
return 0L;
}
return Long.valueOf((String)o);
} else if(o instanceof BigDecimal) {
return ((BigDecimal)o).longValue();
}
return 0L;
}
/**
* 取int值为空返回0
* @param obj 对象
* @return
*/
public static Integer toInteger(Object obj) {
if(obj == null) {
return 0;
} else if(obj instanceof Long){
return ((Long)obj).intValue();
} else if(obj instanceof BigDecimal) {
return ((BigDecimal)obj).intValue();
}else if(obj instanceof String) {
String o = (String) obj;
if("".equals(o)) {
return 0;
} else {
try {
return Integer.valueOf((String) obj);
} catch(Exception e) {
return 0;
}
}
} else if(obj instanceof Integer) {
return (Integer) obj;
}
return 0;
}
public static List<?> toList(Object o) {
if(o == null) {
return null;
} else if(o instanceof List) {
return (List<?>) o;
} else {
return null;
}
}
/**
* 判断对象是否为空
* @param o
* @return
*/
public static boolean isNull(Object o) {
if(null == o) {
return true;
}
if(o instanceof String) {
return "".equals((String) o);
}
if(o instanceof Collection) {
// 集合数量为0 则为空
return ((Collection<?>) o).size() == 0;
}
return false;
}
}

View File

@@ -1,158 +1,469 @@
package com.seeyon.apps.assetsmap.service;
import cn.hutool.log.Log;
import com.seeyon.apps.assetsmap.config.AssetsMapConfigProvider;
import com.seeyon.apps.assetsmap.constants.AssetsMapConstans;
import com.seeyon.apps.assetsmap.vo.AssetsCatagory;
import com.seeyon.apps.assetsmap.vo.AssetsItem;
import com.seeyon.apps.assetsmap.vo.BoundsQueryVo;
import com.seeyon.apps.assetsmap.vo.RegionVo;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.organization.bo.V3xOrgDepartment;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem;
import com.seeyon.ctp.organization.bo.V3xOrgAccount;
import com.seeyon.ctp.organization.manager.OrgManager;
import com.seeyon.ctp.util.JDBCAgent;
import com.seeyon.utils.form.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
public class AssetsQueryService {
private AssetsMapConfigProvider configProvider = (AssetsMapConfigProvider) AppContext.getBean("assetsMapConfigProvider");
private OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
private static final Log log = Log.get(AssetsQueryService.class);
// 部门名称缓存,避免 N+1 查询
private Map<Long, String> deptCache = new HashMap<>();
private String getFormNo(){
return configProvider.getBizConfigByKey(AssetsMapConstans.ASSETSFORMNO);
}
private TableContext getMasterTableContext() throws Exception {
return FormTableExecutor.master(getFormNo());
}
public List<RegionVo> queryAllZoneAssets() throws Exception {
System.out.println("表单编码为:" + getFormNo());
TableContext tableContext = FormTableExecutor.master(getFormNo());
List<FormColumn> formColumns = FormTableExecutor.query(tableContext,null, null, true);
List<RegionVo> regionVos = new ArrayList<>();
List<FormWhereCondition> conditions = buildQueryCondition();
List<FormColumn> formColumns = FormTableExecutor.query(tableContext, null, conditions, true);
System.out.println("查询出的数据条数:" + formColumns.size());
// 用 Map 做 O(1) 查找,替代 List 遍历
Map<String, RegionVo> regionMap = new HashMap<>();
for (FormColumn formColumn : formColumns) {
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
if(fieldsMap == null) {
if (fieldsMap == null) {
continue;
}
upsertRegionVos(regionVos,fieldsMap);
upsertRegionVos(regionMap, fieldsMap);
}
return regionVos;
return new ArrayList<>(regionMap.values());
}
public void upsertRegionVos(List<RegionVo> regionVos, Map<String, Object> fieldsMap) {
private List<FormWhereCondition> buildQueryCondition() {
long currentAccountId = AppContext.currentAccountId();
List<FormWhereCondition> conditions = new ArrayList<>();
conditions.add(FormWhereCondition.build().display("所属单位-").value(currentAccountId).concatFactor(ClauseFactor.OR));
conditions.add(FormWhereCondition.build().display("管理单位-").value(currentAccountId).concatFactor(ClauseFactor.OR));
return conditions;
}
String latStr = (String) fieldsMap.get("纬度");
String lngStr = (String) fieldsMap.get("经度");
/**
* 视口懒加载:通过数据库层经纬度范围过滤,只查询视口内的资产
* 生成 SQL: WHERE 纬度 >= south AND 纬度 <= north AND 经度 >= west AND 经度 <= east
*/
public List<RegionVo> queryAssetsByBounds(BoundsQueryVo vo) throws Exception {
TableContext tableContext = FormTableExecutor.master(getFormNo());
List<FormWhereCondition> conditions = new ArrayList<>();
// 如果传了 assetId按 资产编号 精确查询,忽略经纬度范围
if (StringUtils.isNotBlank(vo.getAssetId())) {
conditions.add(FormWhereCondition.build().display("资产编号").value(vo.getAssetId()));
} else {
conditions.add(FormWhereCondition.build().display("经度-").between(vo.getWest(), vo.getEast()));
conditions.add(FormWhereCondition.build().display("纬度-").between(vo.getSouth(), vo.getNorth()));
}
conditions.add(FormWhereCondition.build().display("经度-").clauseFactor(ClauseFactor.NOT_NULL));
conditions.add(FormWhereCondition.build().display("纬度-").clauseFactor(ClauseFactor.NOT_NULL));
// 代码层过滤权限,避免 LIKE 导致索引失效
boolean showAll = showAll();
log.info("是否允许查看所有数据: " + showAll);
final String permIdStr = showAll ? null : (AppContext.currentAccountId() + "");
if (StringUtils.isNotBlank(vo.getOwner())) {
conditions.add(FormWhereCondition.build().display("所属单位").value(vo.getOwner()));
}
// 1⃣ 经纬度必须有
if (StringUtils.isAnyBlank(latStr, lngStr)) {
if (StringUtils.isNotBlank(vo.getLevel2())) {
conditions.add(FormWhereCondition.build().display("资产类型二级").value(vo.getLevel2()));
}
if (StringUtils.isNotBlank(vo.getLevel1())) {
conditions.add(FormWhereCondition.build().display("资产类型一级").value(vo.getLevel1()));
}
if (StringUtils.isNotBlank(vo.getLevel3())) {
conditions.add(FormWhereCondition.build().display("资产分类-").value(vo.getLevel3()));
}
System.out.println("开始查询资产数据");
List<FormColumn> formColumns = FormTableExecutor.query(tableContext, null, conditions, true);
// 代码层过滤权限(当前单位及下级单位)
if (!showAll && formColumns != null) {
List<String> unitIds = getCurrentAndChildUnitIds();
formColumns = formColumns.stream()
.filter(col -> {
Map<String, Object> fields = col.getFieldsMap();
if (fields == null) return false;
Object permObj = fields.get("查看权限-选单位");
String perm = permObj == null ? null : permObj.toString();
return hasPermission(perm, unitIds);
})
.collect(Collectors.toList());
}
log.info("权限过滤后的数据条数: " + formColumns.size());
Map<String, RegionVo> regionMap = new HashMap<>();
for (FormColumn formColumn : formColumns) {
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
if (fieldsMap == null) continue;
upsertRegionVos(regionMap, fieldsMap);
}
log.info("返回资产数据结果");
return new ArrayList<>(regionMap.values());
}
private boolean showAll() throws Exception {
V3xOrgAccount currentAccount = orgManager.getAccountById(AppContext.currentAccountId());
if(currentAccount == null) {
return false;
}else {
return currentAccount.getName().contains("国清办")
|| currentAccount.getName().contains("国资局")
|| currentAccount.getName().contains("软件开发");
}
}
/**
* 获取当前登录者单位及其所有下级单位的ID列表
*/
private List<String> getCurrentAndChildUnitIds() {
List<String> ids = new ArrayList<>();
long currentAccountId = AppContext.currentAccountId();
JDBCAgent jdbcAgent = new JDBCAgent();
try {
// 查当前单位的 path
jdbcAgent.execute("select path from org_unit where id = ?", currentAccountId);
List list = jdbcAgent.resultSetToList();
if (list == null || list.isEmpty()) {
ids.add(String.valueOf(currentAccountId));
return ids;
}
Map unitMap = (Map) list.get(0);
String rootPath = unitMap.get("path") + "";
// 查所有子单位
jdbcAgent.execute("select id from org_unit where path like ?", rootPath + "%");
list = jdbcAgent.resultSetToList();
if (list != null) {
for (Object o : list) {
Map map = (Map) o;
ids.add(map.get("id") + "");
}
}
} catch (Exception e) {
e.printStackTrace();
ids.add(String.valueOf(currentAccountId));
} finally {
jdbcAgent.close();
}
return ids;
}
/**
* 检查权限字段是否包含当前单位或下级单位
* permField: 逗号分隔的单位ID字符串如 "100,200,300"
* unitIds: 当前单位及下级单位ID列表
*/
private boolean hasPermission(String permField, List<String> unitIds) {
if (StringUtils.isBlank(permField) || unitIds == null || unitIds.isEmpty()) {
return false;
}
// 用逗号分隔后逐一匹配
String[] permParts = permField.split(",");
for (String part : permParts) {
String trimmed = part.trim();
if (unitIds.contains(trimmed)) {
return true;
}
}
return false;
}
/**
* 保存资产边界数据到表单字段"资产边界数据"
* polygonData: JSON格式包含polygon坐标和color颜色
*/
public void saveAssetPolygon(String assetId, String polygonData) throws Exception {
if (StringUtils.isBlank(assetId)) {
throw new IllegalArgumentException("assetId不能为空");
}
List<FormUpdateField> updateFields = new ArrayList<>();
updateFields.add(FormUpdateField.build().display("资产边界数据").value(polygonData));
List<FormWhereCondition> conditions = new ArrayList<>();
conditions.add(FormWhereCondition.build().display("id").value(assetId));
FormTableExecutor.update(getMasterTableContext(),updateFields,conditions);
}
public String getDetailBaseUrlByAssetsType(String assetsType) throws Exception {
TableContext master = FormTableExecutor.master(configProvider.getBizConfigByKey(AssetsMapConstans.ASSETSDETAILURLCONFIGFORMNO));
List<FormWhereCondition> conditions = new ArrayList<>();
if(StringUtils.isBlank(assetsType)) {
conditions.add(FormWhereCondition.build().display("资产类型").value("不动产"));
}else {
conditions.add(FormWhereCondition.build().display("资产类型").value(assetsType));
}
FormColumn formColumn = FormTableExecutor.queryOne(master, conditions, true);
if(formColumn == null) {
return null;
}
Object urlObj = formColumn.getFieldsMap().get("前置地址");
return urlObj == null ? null : urlObj.toString();
}
/**
* 查询单个资产的边界数据
*/
public Map<String, String> getAssetBound(String assetId) throws Exception {
if (StringUtils.isBlank(assetId)) {
return null;
}
TableContext tableContext = FormTableExecutor.master(getFormNo());
List<FormWhereCondition> conditions = new ArrayList<>();
conditions.add(FormWhereCondition.build().display("id").value(assetId));
FormColumn formColumn = FormTableExecutor.queryOne(tableContext, conditions, true);
if (formColumn == null) {
log.info("getAssetBound: 未查到记录, assetId=" + assetId);
return null;
}
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
if (fieldsMap == null) {
return null;
}
log.info("getAssetBound: 查到记录, assetId=" + assetId + ", 资产编号=" + fieldsMap.get("资产编号") + ", 资产名称=" + fieldsMap.get("资产名称"));
log.info("getAssetBound: 资产边界数据字段值=" + fieldsMap.get("资产边界数据") + ", 类型=" + (fieldsMap.get("资产边界数据") == null ? "null" : fieldsMap.get("资产边界数据").getClass().getName()));
Object boundObj = fieldsMap.get("资产边界数据");
String boundData = boundObj == null ? null : boundObj.toString();
Map<String, String> result = new HashMap<>();
result.put("boundData", boundData);
return result;
}
/**
* 返回当前登录者单位的树形结构
* path 每4字符代表一个层级如 0000 → 00000001 → 000000010001
*/
public List<Map<String, Object>> getDeptSelectOptions() throws BusinessException {
long currentAccountId = AppContext.currentAccountId();
JDBCAgent jdbcAgent = new JDBCAgent();
try {
// 查当前单位的 path
jdbcAgent.execute("select path from org_unit where id = ?", currentAccountId);
List list = jdbcAgent.resultSetToList();
if (list == null || list.isEmpty()) {
return new ArrayList<>();
}
Map unitMap = (Map) list.get(0);
String rootPath = unitMap.get("path") + "";
// 查所有子单位
jdbcAgent.execute("select id, name, path from org_unit where path like ?", rootPath + "%");
list = jdbcAgent.resultSetToList();
// 用 LinkedHashMap 保持插入顺序path → node
Map<String, Map<String, Object>> nodeMap = new LinkedHashMap<>();
for (Object o : list) {
Map map = (Map) o;
String path = map.get("path") + "";
Map<String, Object> node = new LinkedHashMap<>();
node.put("id", map.get("id") + "");
node.put("name", map.get("name") + "");
node.put("path", path);
node.put("children", new ArrayList<Map<String, Object>>());
nodeMap.put(path, node);
}
// 按 path 长度排序(浅层先处理),逐个挂到父节点
List<Map<String, Object>> roots = new ArrayList<>();
List<String> sortedPaths = new ArrayList<>(nodeMap.keySet());
Collections.sort(sortedPaths, Comparator.comparingInt(String::length));
for (String path : sortedPaths) {
Map<String, Object> node = nodeMap.get(path);
if (path.equals(rootPath) || path.length() <= 4) {
roots.add(node);
} else {
// 父节点 path = 去掉最后4字符
String parentPath = path.substring(0, path.length() - 4);
Map<String, Object> parent = nodeMap.get(parentPath);
if (parent != null) {
((List<Map<String, Object>>) parent.get("children")).add(node);
} else {
// 找不到父节点,作为根节点
roots.add(node);
}
}
}
return roots;
} catch (Exception e) {
e.printStackTrace();
return new ArrayList<>();
} finally {
jdbcAgent.close();
}
}
public Map<String,AssetsCatagory> getAssetsCatagorySelectOptions() throws Exception {
TableContext tableContext = FormTableExecutor.master(getFormNo());
Map<String, CtpEnumItem> enumItemMap = EnumMapUtils.getEnumItemMap(tableContext.getTableBean(), "资产分类");
if(enumItemMap == null) {
return new HashMap<>();
}
Map<String,AssetsCatagory> resultMap = new HashMap<>();
for (String key : enumItemMap.keySet()) {
CtpEnumItem tempItem = enumItemMap.get(key);
AssetsCatagory assetsCatagory = new AssetsCatagory();
assetsCatagory.setId(tempItem.getId() + "");
assetsCatagory.setShowValue(key);
resultMap.put(key,assetsCatagory);
}
return resultMap;
}
/**
* 生成 region 的唯一 key用于 Map 查找
*/
private String regionKey(double lat, double lng, String address) {
return lat + "_" + lng + "_" + address;
}
/**
* 优化:接收 Map 而非 ListO(1) 查找替代 O(n) 遍历
*/
public void upsertRegionVos(Map<String, RegionVo> regionMap, Map<String, Object> fieldsMap) {
BigDecimal latObj = (BigDecimal) fieldsMap.get("纬度-");
BigDecimal lngObj = (BigDecimal) fieldsMap.get("经度-");
if (latObj == null || lngObj == null) {
return;
}
double lat = Double.parseDouble(latStr);
double lng = Double.parseDouble(lngStr);
double lat = Double.parseDouble(latObj.toString());
double lng = Double.parseDouble(lngObj.toString());
String address = (String) fieldsMap.get("位置详情");
String owner = (String) fieldsMap.get("权属公司");
Object addrObj = fieldsMap.get("所在位置");
String address = addrObj == null ? null : addrObj.toString();
// 2⃣ 地址 & 权属公司建议也做非空控制(关键!)
if (StringUtils.isAnyBlank(address)) {
if (StringUtils.isBlank(address)) {
return;
}
String assetId = getStringValue(fieldsMap,"id");
String assetId = getStringValue(fieldsMap, "id");
AssetsItem newAsset = buildAssetsItem(fieldsMap);
Long managerId = fieldsMap.get("运营单位") == null ? null : Long.parseLong(fieldsMap.get("运营单位") + "");
String deptName = getDeptName(managerId);
// 3⃣ 查找区域
for (RegionVo regionVo : regionVos) {
// 3.1 经纬度必须存在
if (regionVo.getLat() == null || regionVo.getLng() == null) {
continue;
String key = regionKey(lat, lng, address);
RegionVo regionVo = regionMap.get(key);
if (regionVo != null) {
// 判断资产是否已存在
boolean exists = regionVo.getAssets().stream()
.anyMatch(a -> a.getId().equals(assetId));
if (!exists) {
regionVo.getAssets().add(newAsset);
}
} else {
// 新建区域
RegionVo newRegion = new RegionVo();
newRegion.setLat(lat);
newRegion.setLng(lng);
newRegion.setAddress(address);
newRegion.setManager(getStringValue(fieldsMap,"管理单位"));
boolean sameLocation =
Double.compare(regionVo.getLat(), lat) == 0 &&
Double.compare(regionVo.getLng(), lng) == 0;
List<AssetsItem> assets = new ArrayList<>();
assets.add(newAsset);
newRegion.setAssets(assets);
// 3.2 地址 & 权属公司必须非空才参与匹配
if (!sameLocation ||
StringUtils.isAnyBlank(regionVo.getAddress())) {
continue;
}
boolean sameAddress = address.equals(regionVo.getAddress());
if (sameAddress) {
// 4⃣ 判断资产是否存在
boolean exists = regionVo.getAssets().stream()
.anyMatch(a -> a.getId().equals(assetId) );
if (!exists) {
regionVo.getAssets().add(newAsset);
}
return;
}
regionMap.put(key, newRegion);
}
// 5⃣ 新建区域(这里可以放心,因为关键字段都有值)
RegionVo newRegion = new RegionVo();
newRegion.setLat(lat);
newRegion.setLng(lng);
newRegion.setAddress(address);
newRegion.setOwner(owner);
newRegion.setManager(deptName);
List<AssetsItem> assets = new ArrayList<>();
assets.add(newAsset);
newRegion.setAssets(assets);
regionVos.add(newRegion);
}
private String getDeptName(Long deptId) {
if(deptId != null) {
try {
V3xOrgDepartment department = orgManager.getDepartmentById(deptId);
if(department != null) {
return department.getName();
}
}catch (Exception e) {
}
/**
* 优化:带缓存的单位名称查询
*/
private String getUnitName(Long unitId) {
if (unitId == null) {
return null;
}
if (deptCache.containsKey(unitId)) {
return deptCache.get(unitId);
}
try {
V3xOrgAccount account = orgManager.getAccountById(unitId);
String name = account != null ? account.getName() : null;
deptCache.put(unitId, name);
return name;
} catch (Exception e) {
deptCache.put(unitId, null);
return null;
}
return null;
}
private AssetsItem buildAssetsItem(Map<String, Object> fieldsMap) {
AssetsItem assetsItem = new AssetsItem();
assetsItem.setId(getStringValue(fieldsMap,"id"));
assetsItem.setArea(fieldsMap.get("资产面积") == null ? null : Double.parseDouble(fieldsMap.get("资产面积") + ""));
assetsItem.setTenant(getStringValue(fieldsMap,"租户名称"));
assetsItem.setPurpose(getStringValue(fieldsMap,"资产用途"));
assetsItem.setRemark(getStringValue(fieldsMap,"备注"));
assetsItem.setOwner(getStringValue(fieldsMap,"权属单位"));
assetsItem.setAssetName(getStringValue(fieldsMap,"资产名称"));
assetsItem.setAddress(getStringValue(fieldsMap,"位置详情"));
String certNo = fieldsMap.get("权证号码") == null ? null : (String)fieldsMap.get("权证号码");
// assetsItem.setManager(fieldsMap.get("运营单位") == null ? null : (String)fieldsMap.get("运营单位") + "");
Long managerId = fieldsMap.get("运营单位") == null ? null : Long.parseLong(fieldsMap.get("运营单位") + "");
assetsItem.setLat(getStringValue(fieldsMap,"纬度"));
assetsItem.setLng(getStringValue(fieldsMap,"经度"));
assetsItem.setManager(getDeptName(managerId));
assetsItem.setCertNo(certNo);
assetsItem.setStatus(getStringValue(fieldsMap,"资产状态"));
assetsItem.setId(getStringValue(fieldsMap, "id"));
assetsItem.setArea(fieldsMap.get("数量面积") == null ? null : Double.parseDouble(fieldsMap.get("数量面积") + ""));
assetsItem.setAssetCode(getStringValue(fieldsMap, "资产编号"));
assetsItem.setRemark(getStringValue(fieldsMap, "备注"));
assetsItem.setAssetName(getStringValue(fieldsMap, "资产名称"));
assetsItem.setAddress(getStringValue(fieldsMap, "所在位置"));
assetsItem.setLat(Optional.ofNullable(fieldsMap.get("纬度-")).map(Object::toString).orElse(null));
assetsItem.setLng(Optional.ofNullable(fieldsMap.get("经度-")).map(Object::toString).orElse(null));
assetsItem.setManager(getStringValue(fieldsMap,"管理单位"));
assetsItem.setAssetType(getStringValue(fieldsMap, "资产类型一级"));
return assetsItem;
}
private String getStringValue(Map<String, Object> fieldsMap, String key) {
return fieldsMap.get(key) == null ? null : (String)fieldsMap.get(key);
Object val = fieldsMap.get(key);
return val == null ? null : val.toString();
}
public Integer countAssets(String type) throws BusinessException {
/**
* 优化一次查询全量数据内存中分类计数替代3次独立查询
*/
public Map<String, Integer> countAllStats() throws Exception {
TableContext tableContext = FormTableExecutor.master(getFormNo());
List<FormColumn> formColumns = FormTableExecutor.query(tableContext, null, null, true);
int total = 0;
int rented = 0;
int vacant = 0;
String rentedValue = EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(), "资产状态", "已租");
String vacantValue = EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(), "资产状态", "待租");
for (FormColumn col : formColumns) {
Map<String, Object> fields = col.getFieldsMap();
if (fields == null) continue;
total++;
String status = fields.get("资产状态") == null ? null : fields.get("资产状态") + "";
if (rentedValue != null && rentedValue.equals(status)) {
rented++;
} else if (vacantValue != null && vacantValue.equals(status)) {
vacant++;
}
}
Map<String, Integer> result = new HashMap<>();
result.put("total", total);
result.put("rented", rented);
result.put("vacant", vacant);
return result;
}
public Integer countAssets(String type) throws Exception {
TableContext tableContext = FormTableExecutor.master(getFormNo());
List<FormWhereCondition> conditions = new ArrayList<FormWhereCondition>();
if(type == null || "0".equals(type)) {
@@ -168,10 +479,76 @@ public class AssetsQueryService {
return formColumns.size();
}
public List<AssetsItem> queryAssetsByKeyword(String keyword) throws BusinessException {
/**
* 按筛选条件分页查询资产列表(不走视口),用于地图右侧列表展示
* 返回格式: {records: [...], total: n}
*/
public Map<String, Object> queryAssetList(BoundsQueryVo vo) throws Exception {
TableContext tableContext = FormTableExecutor.master(getFormNo());
List<FormWhereCondition> conditions = new ArrayList<>();
if (StringUtils.isNotBlank(vo.getOwner())) {
conditions.add(FormWhereCondition.build().display("所属单位").value(vo.getOwner()));
}
if (StringUtils.isNotBlank(vo.getLevel1())) {
conditions.add(FormWhereCondition.build().display("资产类型一级").value(vo.getLevel1()));
}
if (StringUtils.isNotBlank(vo.getLevel2())) {
conditions.add(FormWhereCondition.build().display("资产类型二级").value(vo.getLevel2()));
}
if (StringUtils.isNotBlank(vo.getLevel3())) {
conditions.add(FormWhereCondition.build().display("资产分类-").value(vo.getLevel3()));
}
if (StringUtils.isNotBlank(vo.getKeyword())) {
conditions.add(FormWhereCondition.build().display("资产名称").value(vo.getKeyword()).clauseFactor(ClauseFactor.LIKE)
.concatFactor(ClauseFactor.OR));
conditions.add(FormWhereCondition.build().display("资产编号").value(vo.getKeyword()).clauseFactor(ClauseFactor.LIKE));
}
// 先查全量用于权限过滤
List<FormColumn> formColumns = FormTableExecutor.query(tableContext, null, conditions, true);
// 权限过滤(当前单位及下级单位)
boolean showAll = showAll();
if (!showAll) {
List<String> unitIds = getCurrentAndChildUnitIds();
formColumns = formColumns.stream()
.filter(col -> {
Map<String, Object> fields = col.getFieldsMap();
if (fields == null) return false;
String perm = (String) fields.get("查看权限-选单位");
return hasPermission(perm, unitIds);
})
.collect(Collectors.toList());
}
int total = formColumns.size();
// 分页
int pageNum = vo.getPageNum() != null && vo.getPageNum() > 0 ? vo.getPageNum() : 1;
int pageSize = vo.getPageSize() != null && vo.getPageSize() > 0 ? vo.getPageSize() : 10;
int fromIndex = (pageNum - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, total);
List<AssetsItem> records = new ArrayList<>();
if (fromIndex < total) {
List<FormColumn> pageColumns = formColumns.subList(fromIndex, toIndex);
for (FormColumn col : pageColumns) {
Map<String, Object> fieldsMap = col.getFieldsMap();
if (fieldsMap == null) continue;
records.add(buildAssetsItem(fieldsMap));
}
}
Map<String, Object> result = new HashMap<>();
result.put("records", records);
result.put("total", total);
return result;
}
public List<AssetsItem> queryAssetsByKeyword(String keyword) throws Exception {
List<FormWhereCondition> conditions = new ArrayList<FormWhereCondition>();
if(StringUtils.isNotBlank(keyword)){
conditions.add(FormWhereCondition.build().display("位置详情").value(keyword).concatFactor(ClauseFactor.OR).clauseFactor(ClauseFactor.LIKE));
conditions.add(FormWhereCondition.build().display("所在位置").value(keyword).concatFactor(ClauseFactor.OR).clauseFactor(ClauseFactor.LIKE));
}
TableContext tableContext = FormTableExecutor.master(getFormNo());
List<FormColumn> formColumns = FormTableExecutor.pageQuery(tableContext,null, conditions, 1,10,true);

View File

@@ -0,0 +1,33 @@
package com.seeyon.apps.assetsmap.vo;
import java.util.Map;
public class AssetsCatagory {
private String id;
private String showValue;
private Map<String,AssetsCatagory> children;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getShowValue() {
return showValue;
}
public void setShowValue(String showValue) {
this.showValue = showValue;
}
public Map<String, AssetsCatagory> getChildren() {
return children;
}
public void setChildren(Map<String, AssetsCatagory> children) {
this.children = children;
}
}

View File

@@ -2,6 +2,7 @@ package com.seeyon.apps.assetsmap.vo;
public class AssetsItem {
private String id;
private String assetCode;
private String assetName;
private Long regionId;
private String purpose;
@@ -15,6 +16,9 @@ public class AssetsItem {
private String lng;
private String lat;
private String address;
private String assetType;
private String assetCategory;
private String boundData;
public String getId() {
return id;
@@ -24,6 +28,14 @@ public class AssetsItem {
this.id = id;
}
public String getAssetCode() {
return assetCode;
}
public void setAssetCode(String assetCode) {
this.assetCode = assetCode;
}
public Long getRegionId() {
return regionId;
}
@@ -127,4 +139,28 @@ public class AssetsItem {
public void setAddress(String address) {
this.address = address;
}
public String getAssetType() {
return assetType;
}
public void setAssetType(String assetType) {
this.assetType = assetType;
}
public String getAssetCategory() {
return assetCategory;
}
public void setAssetCategory(String assetCategory) {
this.assetCategory = assetCategory;
}
public String getBoundData() {
return boundData;
}
public void setBoundData(String boundData) {
this.boundData = boundData;
}
}

View File

@@ -0,0 +1,41 @@
package com.seeyon.apps.assetsmap.vo;
public class BoundsQueryVo {
private Double south;
private Double west;
private Double north;
private Double east;
private String owner;
private String level1;
private String level2;
private String level3;
private String assetId;
private String keyword;
private Integer pageNum;
private Integer pageSize;
public Double getSouth() { return south; }
public void setSouth(Double south) { this.south = south; }
public Double getWest() { return west; }
public void setWest(Double west) { this.west = west; }
public Double getNorth() { return north; }
public void setNorth(Double north) { this.north = north; }
public Double getEast() { return east; }
public void setEast(Double east) { this.east = east; }
public String getOwner() { return owner; }
public void setOwner(String owner) { this.owner = owner; }
public String getLevel1() { return level1; }
public void setLevel1(String level1) { this.level1 = level1; }
public String getLevel2() { return level2; }
public void setLevel2(String level2) { this.level2 = level2; }
public String getLevel3() { return level3; }
public void setLevel3(String level3) { this.level3 = level3; }
public String getAssetId() { return assetId; }
public void setAssetId(String assetId) { this.assetId = assetId; }
public String getKeyword() { return keyword; }
public void setKeyword(String keyword) { this.keyword = keyword; }
public Integer getPageNum() { return pageNum; }
public void setPageNum(Integer pageNum) { this.pageNum = pageNum; }
public Integer getPageSize() { return pageSize; }
public void setPageSize(Integer pageSize) { this.pageSize = pageSize; }
}

View File

@@ -2,7 +2,15 @@ package com.seeyon.ctp.rest.resources.assetsmap;
import cn.hutool.log.Log;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.aicloud.common.JsonUtils;
import com.seeyon.apps.assetsmap.kit.CAP4FormKit;
import com.seeyon.apps.assetsmap.service.AssetsQueryService;
import com.seeyon.apps.assetsmap.vo.AssetsCatagory;
import com.seeyon.apps.assetsmap.vo.BoundsQueryVo;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormFieldBean;
import com.seeyon.cap4.form.service.CAP4FormManager;
import com.seeyon.cap4.template.util.CAPFormUtil;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.rest.resources.BaseResource;
@@ -10,12 +18,15 @@ import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map;
@Path("/assetsRegion")
@Produces({"application/json", "application/xml"})
public class AssetsRegionResources extends BaseResource {
private static final Log log = Log.get(AssetsRegionResources.class);
private CAP4FormManager cap4FormManager = (CAP4FormManager) AppContext.getBean("cap4FormManager");
private AssetsQueryService assetsQueryService = (AssetsQueryService) AppContext.getBean("assetsQueryService");
@@ -34,12 +45,82 @@ public class AssetsRegionResources extends BaseResource {
}
@POST
@Path("/search")
@Path("/getByBounds")
@Produces({"application/json"})
@Consumes({"application/json"})
public Response search(JSONObject params) {
public Response getByBounds(BoundsQueryVo vo){
try {
return this.success(this.assetsQueryService.queryAssetsByKeyword(params.getString("keyword")));
log.info("按视口查询资产");
return success(assetsQueryService.queryAssetsByBounds(vo));
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
return fail("查询失败:" + e.getMessage());
}
}
@POST
@Path("/queryAssetList")
@Produces({"application/json"})
@Consumes({"application/json"})
public Response queryAssetList(BoundsQueryVo vo){
try {
return success(assetsQueryService.queryAssetList(vo));
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
return fail("查询失败:" + e.getMessage());
}
}
@GET
@Path("/getDeptOptions")
@Produces({"application/json"})
public Response getDeptOptions(){
try {
return success(assetsQueryService.getDeptSelectOptions());
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
return fail("查询失败:" + e.getMessage());
}
}
@GET
@Path("/getCategoryOptions")
@Produces({"application/json"})
public Response getCategoryOptions(){
try {
log.info("查询分类");
Map<String, AssetsCatagory> resMap = assetsQueryService.getAssetsCatagorySelectOptions();
log.info("查询结果: " + JsonUtils.toJSONString(resMap));
return success(resMap);
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
return fail("查询失败:" + e.getMessage());
}
}
@GET
@Path("/getAssetBound")
@Produces({"application/json"})
public Response getAssetBound(@QueryParam("assetId") String assetId){
try {
return success(assetsQueryService.getAssetBound(assetId));
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
return fail("查询失败:" + e.getMessage());
}
}
@GET
@Path("/search")
@Produces({"application/json"})
public Response search(@QueryParam("keyword") String keyword) {
try {
return this.success(this.assetsQueryService.queryAssetsByKeyword(keyword));
} catch (Exception e) {
log.error(e.getMessage(), new Object[]{e});
e.printStackTrace();
@@ -47,6 +128,48 @@ public class AssetsRegionResources extends BaseResource {
}
}
@POST
@Path("/formBackFill")
@Produces({"application/json"})
@Consumes({"application/json"})
public Response boundRefCallBack(Map<String, Object> params) {
try {
String masterId = (String) params.get("masterId");
String fieldDisplay = (String) params.get("fieldDisplay");
Object value = params.get("value");
FormDataMasterBean cacheFormData = cap4FormManager.getSessioMasterDataBean(Long.parseLong(masterId));
FormFieldBean fieldBean = CAP4FormKit.getFieldBean(cacheFormData, fieldDisplay);
Map<String, Object> displayValueMap = CAPFormUtil.getDisplayValueMap(value, fieldBean, null);
cacheFormData.addFieldValue(fieldBean.getName(), value);
Map<String, Object> mainData = new HashMap<>();
mainData.put(fieldBean.getName(), displayValueMap);
return success(mainData);
} catch (Exception e) {
log.error(e.getMessage(), e);
return fail("保存失败:" + e.getMessage());
}
}
@POST
@Path("/saveAssetPolygon")
@Produces({"application/json"})
@Consumes({"application/json"})
public Response saveAssetPolygon(JSONObject params){
try {
String assetId = params.getString("assetId");
String polygonData = params.getString("polygonData");
assetsQueryService.saveAssetPolygon(assetId, polygonData);
return success("保存成功");
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
return fail("保存失败:" + e.getMessage());
}
}
@Path("/countAssets")
@GET
@Produces({"application/json"})
@@ -60,4 +183,30 @@ public class AssetsRegionResources extends BaseResource {
return fail("查询失败:" + e.getMessage());
}
}
@Path("/countAllStats")
@GET
@Produces({"application/json"})
public Response countAllStats(){
try {
return success(assetsQueryService.countAllStats());
}catch (Exception e) {
log.error(e.getMessage(),e);
e.printStackTrace();
return fail("查询失败:" + e.getMessage());
}
}
@Path("/getDetailBaseUrlByAssetsType")
@GET
@Produces({"application/json"})
public Response getDetailBaseUrlByAssetsType(@QueryParam("assetsType")String assetsType){
try {
return success(assetsQueryService.getDetailBaseUrlByAssetsType(assetsType));
}catch (Exception e) {
log.error(e.getMessage(),e);
e.printStackTrace();
return fail("查询失败:" + e.getMessage());
}
}
}