| | |
| | | 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.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | public void pageDrug(Page<Drug> page, Map<String, Object> param) throws Exception { |
| | | StringBuffer hql = new StringBuffer(); |
| | | Map<String, Object> args = new HashMap<>(); |
| | | hql.append(" from " + Drug.class.getName() + " where companyId=:companyId"); |
| | | args.put("companyId", ContextUtil.getCompanyId()); |
| | | hql.append(" from " + Drug.class.getName() + " where deptId=:deptId"); |
| | | args.put("deptId", ContextUtil.subDeptId(null)); |
| | | if (null != param) { |
| | | buildHql(hql, param, args); |
| | | } |
| | |
| | | if (null == data.getDeptId()) { |
| | | data.setDeptId(ContextUtil.subDeptId(null)); |
| | | } |
| | | DefaultDept dept = sysDeptService.getDeptById(data.getDeptId()); |
| | | data.setDeptName(dept.getName()); |
| | | Session session = this.getSessionFactory().openSession(); |
| | | data.setUpdateTime(new Date()); |
| | | data.setUpdateUser(ContextUtil.getLoginUserCName()); |
| | | try { |
| | | if (null == data.getId()) { |
| | | String id = createId(data.getCompanyId(), data.getDeptId()); |
| | | String id = createId(data.getCompanyId(), data.getCgrq()); |
| | | data.setId(id); |
| | | session.save(data); |
| | | } else { |
| | |
| | | |
| | | } |
| | | |
| | | public String createId(String companyId, String deptId) { |
| | | public String createId(String companyId, Date time) { |
| | | |
| | | String timeKey = DateFormatUtils.format(time, "yyyyMMdd"); |
| | | // 从缓存中获取已有的组织编码 |
| | | String cacheKey = RedisConst.buildKey(companyId, HDrugService.CACHE_DRUG_ID); |
| | | |
| | | String cacheId = (String) redisUtil.get(cacheKey); |
| | | |
| | | if (null != cacheId && cacheId.indexOf(deptId) >= 0) { |
| | | if (null != cacheId && cacheId.indexOf(timeKey) >= 0) { |
| | | String temp = cacheId.substring(cacheId.length() - 3); |
| | | Integer i = Integer.valueOf(temp); |
| | | cacheId = deptId + String.format("%03d", ++i); |
| | | cacheId = timeKey + String.format("%03d", ++i); |
| | | } else { |
| | | List<Drug> result = listDrug(companyId, null); |
| | | if (null == result || result.size() == 0) { |
| | | cacheId = deptId + "001"; |
| | | cacheId = timeKey + "001"; |
| | | } else { |
| | | Drug drug = result.get(0); |
| | | String temp = drug.getId().substring(drug.getId().length() - 3); |
| | | Integer i = Integer.valueOf(temp); |
| | | cacheId = deptId + String.format("%03d", ++i); |
| | | cacheId = timeKey + String.format("%03d", ++i); |
| | | } |
| | | } |
| | | // 更新缓存 |
| | |
| | | } |
| | | str = (String) param.get("name"); |
| | | if (StringUtils.isNotEmpty(str)) { |
| | | hql.append(" and name like :name"); |
| | | hql.append(" and name like:name"); |
| | | args.put("name", "%" + str + "%"); |
| | | } |
| | | Date date = (Date) param.get("start"); |