From 6d847ba021fb494051ec710810a45fa8084f90ed Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期二, 22 八月 2023 23:23:55 +0800
Subject: [PATCH] 更新MODBUS-TCP协议 2
---
igds-recir/src/main/java/com/ld/igds/drug/service/HDrugLogApplyService.java | 112 +++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 82 insertions(+), 30 deletions(-)
diff --git a/igds-recir/src/main/java/com/ld/igds/drug/service/HDrugLogApplyService.java b/igds-recir/src/main/java/com/ld/igds/drug/service/HDrugLogApplyService.java
index 50dc1d6..81a16d8 100644
--- a/igds-recir/src/main/java/com/ld/igds/drug/service/HDrugLogApplyService.java
+++ b/igds-recir/src/main/java/com/ld/igds/drug/service/HDrugLogApplyService.java
@@ -7,8 +7,10 @@
import com.ld.igds.models.*;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.RedisUtil;
+import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Session;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -66,24 +68,35 @@
Session session = this.getSessionFactory().openSession();
data.setUpdateTime(new Date());
try {
- if (null == data.getId()) {
+ if (null == data.getXzbm()) {
String id = createId(data.getCompanyId());
- data.setId(id);
- session.save(data);
- } else {
- session.update(data);
+ data.setXzbm(id);
}
- if (CollectionUtils.isEmpty(data.getDrugLogPeople())) {
+ if (StringUtils.isEmpty(data.getDtlId())){
+ data.setDtlId(ContextUtil.getUUID());
+ }
+ if (StringUtils.isEmpty(data.getWayId())){
+ data.setWayId(ContextUtil.getUUID());
+ }
+ //娣诲姞绮儏瀛愯〃
+ saveDtl(data);
+ //娣诲姞澶囨鏂瑰紡瀛愯〃
+ saveWay(data);
+ //娣诲姞涓昏〃
+ session.saveOrUpdate(data);
+
+ if (!CollectionUtils.isEmpty(data.getDrugLogPeople())) {
for (DrugLogPeople drugLogPeople : data.getDrugLogPeople()) {
- if (null == drugLogPeople.getId()) {
- drugLogPeople.setId(ContextUtil.getUUID());
- drugLogPeople.setDrugLogId(data.getId());
- drugLogPeople.setCompanyId(data.getCompanyId());
+ if (null == drugLogPeople.getPropleId()) {
+ String tbrq = DateFormatUtils.format(data.getTbrq(), "yyyyMMdd");
+ drugLogPeople.setPropleId(ContextUtil.getUUID());
+ drugLogPeople.setId(data.getXzbm() + data.getDeptId() + tbrq);
+ drugLogPeople.setTbrq(data.getTbrq());
+ drugLogPeople.setDrugLogId(data.getXzbm());
drugLogPeople.setDeptId(data.getDeptId());
- session.save(drugLogPeople);
- } else {
- session.update(drugLogPeople);
}
+ session.saveOrUpdate(drugLogPeople);
+ session.flush();
}
}
} catch (Exception e) {
@@ -95,6 +108,45 @@
return null;
}
+ private void saveWay(DrugLogApply data) {
+ Session session = this.getSessionFactory().openSession();
+
+ try {
+ DrugLogWay way = new DrugLogWay();
+ BeanUtils.copyProperties(data, way);
+ way.setWayId(ContextUtil.getUUID());
+ String tbrq = DateFormatUtils.format(data.getTbrq(), "yyyyMMdd");
+ way.setId(data.getXzbm() + data.getDeptId() + tbrq);
+ session.saveOrUpdate(way);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
+ }
+
+ /**
+ * 鏍规嵁涓昏〃淇℃伅娣诲姞绮儏瀛楄〃
+ *
+ * @param data
+ */
+ private void saveDtl(DrugLogApply data) {
+ Session session = this.getSessionFactory().openSession();
+ try {
+ DrugLogDtl dtl = new DrugLogDtl();
+ BeanUtils.copyProperties(data, dtl);
+ String tbrq = DateFormatUtils.format(data.getTbrq(), "yyyyMMdd");
+ dtl.setId(data.getXzbm() + data.getDeptId() + tbrq);
+ session.saveOrUpdate(dtl);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
+ }
+
/**
* 鍒犻櫎鐔忚捀澶囨涓昏〃淇℃伅
*
@@ -104,7 +156,7 @@
public String delDrugLogApply(DrugLogApply data) {
Session session = this.getSessionFactory().openSession();
try {
- if (null != data.getId()) {
+ if (null != data.getXzbm()) {
session.delete(data);
for (DrugLogPeople drugLogPeople : data.getDrugLogPeople()) {
session.delete(drugLogPeople);
@@ -146,8 +198,6 @@
public List<DrugLogDtl> drugLogDtlList(Map<String, Object> param) throws Exception {
StringBuffer hql = new StringBuffer();
Map<String, Object> args = new HashMap<>();
- hql.append(" from " + DrugLogDtl.class.getName() + " where companyId=:companyId");
- args.put("companyId", ContextUtil.getCompanyId());
if (null != param) {
buildHql(hql, param, args);
}
@@ -161,9 +211,6 @@
* @return
*/
public String saveDrugLogDtl(DrugLogDtl data) {
- if (null == data.getCompanyId()) {
- data.setCompanyId(ContextUtil.getCompanyId());
- }
if (null == data.getDeptId()) {
data.setDeptId(ContextUtil.subDeptId(null));
}
@@ -216,9 +263,15 @@
public List<DrugLogPeople> drugLogPeopleList(Map<String, Object> param) throws Exception {
StringBuffer hql = new StringBuffer();
Map<String, Object> args = new HashMap<>();
- hql.append(" from " + DrugLogPeople.class.getName() + " where companyId=:companyId");
- args.put("companyId", ContextUtil.getCompanyId());
+
if (null != param) {
+
+ String xzbm = (String) param.get("xzbm");
+ String deptId = (String) param.get("deptId");
+ String tbrq = DateFormatUtils.format((Date) param.get("tbrq"), "yyyyMMdd");
+ String id = xzbm + deptId + tbrq;
+ hql.append(" from " + DrugLogPeople.class.getName() + " where id=:id");
+ args.put("id", id);
buildHql(hql, param, args);
}
return this.query(String.valueOf(hql), args);
@@ -231,9 +284,6 @@
* @return
*/
public String saveDrugLogPeople(DrugLogPeople data) {
- if (null == data.getCompanyId()) {
- data.setCompanyId(ContextUtil.getCompanyId());
- }
if (null == data.getDeptId()) {
data.setDeptId(ContextUtil.subDeptId(null));
}
@@ -285,9 +335,14 @@
public List<DrugLogWay> drugLogWayList(Map<String, Object> param) throws Exception {
StringBuffer hql = new StringBuffer();
Map<String, Object> args = new HashMap<>();
- hql.append(" from " + DrugLogWay.class.getName() + " where companyId=:companyId");
- args.put("companyId", ContextUtil.getCompanyId());
if (null != param) {
+
+ String xzbm = (String) param.get("xzbm");
+ String deptId = (String) param.get("deptId");
+ String tbrq = DateFormatUtils.format((Date) param.get("tbsj"), "yyMMdd");
+ String id = xzbm + deptId + tbrq;
+ hql.append(" from " + DrugLogWay.class.getName() + " where id=:id");
+ args.put("id", id);
buildHql(hql, param, args);
}
return this.query(String.valueOf(hql), args);
@@ -301,9 +356,6 @@
* @return
*/
public String saveDrugLogWay(DrugLogWay data) {
- if (null == data.getCompanyId()) {
- data.setCompanyId(ContextUtil.getCompanyId());
- }
if (null == data.getDeptId()) {
data.setDeptId(ContextUtil.subDeptId(null));
}
@@ -391,7 +443,7 @@
cacheId = "0001";
} else {
- String temp = drugLogApplies.get(0).getId();
+ String temp = drugLogApplies.get(0).getXzbm();
Integer i = Integer.valueOf(temp);
cacheId = String.format("%04d", ++i);
}
--
Gitblit v1.9.3