From 3a97ed3e03c8969aef34d172bf46116596683bd3 Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期三, 27 九月 2023 21:50:00 +0800
Subject: [PATCH] 贝博粮情解析2
---
igds-recir/src/main/java/com/ld/igds/drug/service/HDrugLogApplyService.java | 164 ++++++++++++++++++++++++++++++++++--------------------
1 files changed, 103 insertions(+), 61 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 e0bdf8f..79420de 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
@@ -1,6 +1,5 @@
package com.ld.igds.drug.service;
-import com.bstek.bdf2.core.model.DefaultDept;
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.bstek.dorado.data.provider.Page;
import com.ld.igds.constant.RedisConst;
@@ -8,7 +7,9 @@
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
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;
@@ -45,7 +46,7 @@
if (null != param) {
buildHql(hql, param, args);
}
- hql.append(" order by id ");
+ hql.append(" order by xzbm ");
String countHql = "select count(*) " + hql.toString();
this.pagingQuery(page, String.valueOf(hql), countHql, args);
}
@@ -66,26 +67,36 @@
Session session = this.getSessionFactory().openSession();
data.setUpdateTime(new Date());
try {
- if (null == data.getId()) {
- String id = createId(data.getCompanyId());
- data.setId(id);
- session.save(data);
- } else {
- session.update(data);
+ if (null == data.getXzbm()) {
+ String id = createId(data.getCompanyId(), data.getTbrq());
+ data.setXzbm(id);
}
+ if (StringUtils.isEmpty(data.getDtlId())) {
+ data.setDtlId(ContextUtil.getUUID());
+ }
+ if (StringUtils.isEmpty(data.getWayId())) {
+ data.setWayId(ContextUtil.getUUID());
+ }
+ //娣诲姞涓昏〃
+ 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());
- drugLogPeople.setDeptId(data.getDeptId());
- session.save(drugLogPeople);
- } else {
- session.update(drugLogPeople);
+ if (null == drugLogPeople.getPropleId()) {
+ drugLogPeople.setPropleId(ContextUtil.getUUID());
+ drugLogPeople.setDrugLogId(data.getXzbm());
}
+ session.saveOrUpdate(drugLogPeople);
}
}
+ DrugLogWay way = new DrugLogWay();
+ BeanUtils.copyProperties(data, way);
+ way.setDrugLogId(data.getXzbm());
+ session.saveOrUpdate(way);
+ DrugLogDtl dtl = new DrugLogDtl();
+ BeanUtils.copyProperties(data, dtl);
+ way.setDrugLogId(data.getXzbm());
+ session.saveOrUpdate(dtl);
} catch (Exception e) {
e.printStackTrace();
} finally {
@@ -93,6 +104,41 @@
session.close();
}
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());
+ 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);
+ session.saveOrUpdate(dtl);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
}
/**
@@ -104,7 +150,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);
@@ -131,9 +177,10 @@
hql.append(" from " + DrugLogApply.class.getName() + " where companyId=:companyId");
args.put("companyId", ContextUtil.getCompanyId());
if (null != param) {
+
buildHql(hql, param, args);
}
- hql.append(" order by id desc");
+ hql.append(" order by xzbm desc");
return this.query(String.valueOf(hql), args);
}
@@ -146,8 +193,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,16 +206,10 @@
* @return
*/
public String saveDrugLogDtl(DrugLogDtl data) {
- if (null == data.getCompanyId()) {
- data.setCompanyId(ContextUtil.getCompanyId());
- }
- if (null == data.getDeptId()) {
- data.setDeptId(ContextUtil.subDeptId(null));
- }
Session session = this.getSessionFactory().openSession();
try {
- if (null == data.getId()) {
- data.setId(ContextUtil.getUUID());
+ if (null == data.getDtlId()) {
+ data.setDtlId(ContextUtil.getUUID());
session.save(data);
} else {
session.update(data);
@@ -194,7 +233,7 @@
public String delDrugLogDtl(DrugLogDtl data) {
Session session = this.getSessionFactory().openSession();
try {
- if (null != data.getId()) {
+ if (null != data.getDtlId()) {
session.delete(data);
}
} catch (Exception e) {
@@ -216,9 +255,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,16 +276,10 @@
* @return
*/
public String saveDrugLogPeople(DrugLogPeople data) {
- if (null == data.getCompanyId()) {
- data.setCompanyId(ContextUtil.getCompanyId());
- }
- if (null == data.getDeptId()) {
- data.setDeptId(ContextUtil.subDeptId(null));
- }
Session session = this.getSessionFactory().openSession();
try {
- if (null == data.getId()) {
- data.setId(ContextUtil.getUUID());
+ if (null == data.getPropleId()) {
+ data.setPropleId(ContextUtil.getUUID());
session.save(data);
} else {
session.update(data);
@@ -264,7 +303,7 @@
public String delDrugLogPeople(DrugLogPeople data) {
Session session = this.getSessionFactory().openSession();
try {
- if (null != data.getId()) {
+ if (null != data.getPropleId()) {
session.delete(data);
}
} catch (Exception e) {
@@ -285,9 +324,11 @@
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");
+ hql.append(" from " + DrugLogWay.class.getName() + " where id=:id");
+ args.put("id", xzbm);
buildHql(hql, param, args);
}
return this.query(String.valueOf(hql), args);
@@ -301,16 +342,10 @@
* @return
*/
public String saveDrugLogWay(DrugLogWay data) {
- if (null == data.getCompanyId()) {
- data.setCompanyId(ContextUtil.getCompanyId());
- }
- if (null == data.getDeptId()) {
- data.setDeptId(ContextUtil.subDeptId(null));
- }
Session session = this.getSessionFactory().openSession();
try {
- if (null == data.getId()) {
- data.setId(ContextUtil.getUUID());
+ if (null == data.getWayId()) {
+ data.setWayId(ContextUtil.getUUID());
session.save(data);
} else {
session.update(data);
@@ -333,7 +368,7 @@
public String delDrugLogWay(DrugLogWay data) {
Session session = this.getSessionFactory().openSession();
try {
- if (null != data.getId()) {
+ if (null != data.getWayId()) {
session.delete(data);
}
} catch (Exception e) {
@@ -358,6 +393,11 @@
hql.append(" and drugLogId=:drugLogId");
args.put("drugLogId", str);
}
+ str = (String) param.get("id");
+ if (StringUtils.isNotEmpty(str)) {
+ hql.append(" and xzbm like:id");
+ args.put("id", str + "%");
+ }
str = (String) param.get("depotId");
if (StringUtils.isNotEmpty(str)) {
hql.append(" and depotId=:depotId");
@@ -375,25 +415,27 @@
}
}
- public String createId(String companyId) throws Exception {
+ public String createId(String companyId, Date time) throws Exception {
+ String timeKey = DateFormatUtils.format(time, "yyyyMMdd");
// 浠庣紦瀛樹腑鑾峰彇宸叉湁鐨勭粍缁囩紪鐮�
String cacheKey = RedisConst.buildKey(companyId, HDrugLogApplyService.CACHE_DRUG_LOG_APPLY_ID);
String cacheId = (String) redisUtil.get(cacheKey);
-
- if (null != cacheId) {
- Integer i = Integer.valueOf(cacheId);
- cacheId = String.format("%04d", ++i);
+ if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
+ String temp = cacheId.substring(cacheId.length() - 4);
+ Integer i = Integer.valueOf(temp);
+ cacheId = timeKey + String.format("%04d", ++i);
} else {
- List<DrugLogApply> drugLogApplies = this.drugLogApplyList(null);
+ Map<String, Object> param = new HashMap<>();
+ param.put("id", timeKey);
+ List<DrugLogApply> drugLogApplies = this.drugLogApplyList(param);
if (null == drugLogApplies || drugLogApplies.size() == 0) {
- cacheId = "0001";
+ cacheId = timeKey + "0001";
} else {
-
- String temp = drugLogApplies.get(0).getId();
+ String temp = drugLogApplies.get(0).getXzbm();
Integer i = Integer.valueOf(temp);
- cacheId = String.format("%04d", ++i);
+ cacheId = timeKey + String.format("%04d", ++i);
}
}
// 鏇存柊缂撳瓨
--
Gitblit v1.9.3