WS
2023-08-22 0c9c9b6df9f52ecd15f9211160a2be4507814a1c
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 (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);
            }