| | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除熏蒸备案主表信息 |
| | | * |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public String saveDrugLogDtl(DrugLogDtl data) { |
| | | if (null == data.getCompanyId()) { |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | if (null == data.getDeptId()) { |
| | | data.setDeptId(ContextUtil.subDeptId(null)); |
| | | } |
| | |
| | | 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); |
| | |
| | | * @return |
| | | */ |
| | | public String saveDrugLogPeople(DrugLogPeople data) { |
| | | if (null == data.getCompanyId()) { |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | if (null == data.getDeptId()) { |
| | | data.setDeptId(ContextUtil.subDeptId(null)); |
| | | } |
| | |
| | | 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); |
| | |
| | | * @return |
| | | */ |
| | | public String saveDrugLogWay(DrugLogWay data) { |
| | | if (null == data.getCompanyId()) { |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | if (null == data.getDeptId()) { |
| | | data.setDeptId(ContextUtil.subDeptId(null)); |
| | | } |
| | |
| | | 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); |
| | | } |