package com.ld.igds.m.service; import com.bstek.bdf2.core.orm.hibernate.HibernateDao; import com.bstek.dorado.data.provider.Page; import com.ld.igds.constant.Constant; import com.ld.igds.inout.InoutConstant; import com.ld.igds.m.dto.NoticeDto; import com.ld.igds.m.dto.NoticeParam; import com.ld.igds.models.InoutNoticeIn; import com.ld.igds.models.InoutNoticeOut; import com.ld.igds.util.ContextUtil; 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.Repository; import java.util.*; @Repository public class HInoutNoticeService extends HibernateDao { @Autowired private InoutCommonService inoutManagerService; public void pageQueryIn(Page page, Map param) throws Exception { String hql = " from " + InoutNoticeIn.class.getName() + " where companyId =:companyId and deptId =:deptId"; Map args = new HashMap(); args.put("companyId", ContextUtil.getCompanyId()); args.put("deptId", ContextUtil.subDeptId(null)); Object year = param.get("year"); if (year == null) { param.put("year", DateFormatUtils.format(new Date(), "yyyy")); } String str = (String) param.get("id"); if (StringUtils.isNotEmpty(str)) { hql += " and id=:id"; args.put("id", str); } str = (String) param.get("customerId"); if (StringUtils.isNotEmpty(str)) { hql += " and customerId =:customerId"; args.put("customerId", str); } Object obj = param.get("year"); if (null != obj) { hql += " and year =:year"; args.put("year", obj + ""); } str = (String) param.get("auditStatus"); if (StringUtils.isNotEmpty(str)) { hql += " and auditStatus =:auditStatus"; args.put("auditStatus", str); } str = (String) param.get("completeStatus"); if (StringUtils.isNotEmpty(str)) { hql += " and completeStatus =:completeStatus"; args.put("completeStatus", str); } str = (String) param.get("foodVariety"); if (StringUtils.isNotEmpty(str)) { hql += " and foodVariety =:foodVariety"; args.put("foodVariety", str); } String countHql = " select count(*) " + hql; hql += " order by createTime"; this.pagingQuery(page, hql, countHql, args); } public String saveOrUpdateIn(InoutNoticeIn data) { //2023-09-02禁用,原因:同一个用户有多个合同,就导致有多个通知单 // //新增入库通知单时,需要进行唯一性判断。即保证单位、粮食品种、年份唯一,且不存在未完成状态的单子。 // if (Constant.YN_Y.equals(data.getTag())) { // data.setCompanyId(ContextUtil.getCompanyId()); // // NoticeParam param = new NoticeParam(); // param.setCompanyId(data.getCompanyId()); // param.setDeptId(data.getDeptId()); // param.setCustomerId(data.getCustomerId()); // param.setFoodVariety(data.getFoodVariety()); // param.setYear(data.getYear()); // //若有合同信息,添加合同信息 // if (StringUtils.isNotEmpty(data.getContractId())) { // param.setContractId(data.getContractId()); // } // //若有计划信息,添加计划信息 // if (StringUtils.isNotEmpty(data.getPlanId())) { // param.setPlanId(data.getPlanId()); // } // param.setCompleteStatus(InoutConstant.COMPLETE_STATUS_NONE); // Integer integer = inoutManagerService.queryNoticeIn(param); // if (integer > 0) { // return "新增的入库通知单已存在,不能再次新增,请核查!"; // } // } Session session = this.getSessionFactory().openSession(); try { if (Constant.YN_Y.equals(data.getTag())) { data.setCreateUser(ContextUtil.getLoginUserCName()); data.setAuditStatus(InoutConstant.STATUS_NONE); data.setCompleteStatus(InoutConstant.COMPLETE_STATUS_NONE); session.save(data); } else { session.update(data); } } finally { session.flush(); session.close(); } return null; } public String delDataIn(InoutNoticeIn data) { Session session = this.getSessionFactory().openSession(); try { session.delete(data); } finally { session.flush(); session.close(); } return null; } public void pageQueryOut(Page page, Map param) throws Exception { String hql = " from " + InoutNoticeOut.class.getName() + " where companyId =:companyId and deptId =:deptId"; Map args = new HashMap(); args.put("companyId", ContextUtil.getCompanyId()); args.put("deptId", ContextUtil.subDeptId(null)); Object year = param.get("year"); if (year == null) { param.put("year", DateFormatUtils.format(new Date(), "yyyy")); } String str = (String) param.get("id"); if (StringUtils.isNotEmpty(str)) { hql += " and id =:id"; args.put("id", str); } str = (String) param.get("customerId"); if (StringUtils.isNotEmpty(str)) { hql += " and customerId =:customerId"; args.put("customerId", str); } Object obj = param.get("year"); if (null != obj) { hql += " and year =:year"; args.put("year", obj + ""); } str = (String) param.get("auditStatus"); if (StringUtils.isNotEmpty(str)) { hql += " and auditStatus =:auditStatus"; args.put("auditStatus", str); } str = (String) param.get("completeStatus"); if (StringUtils.isNotEmpty(str)) { hql += " and completeStatus =:completeStatus"; args.put("completeStatus", str); } str = (String) param.get("foodVariety"); if (StringUtils.isNotEmpty(str)) { hql += " and foodVariety =:foodVariety"; args.put("foodVariety", str); } String countHql = " select count(*) " + hql; hql += " order by depotId + 0"; this.pagingQuery(page, hql, countHql, args); } public String saveOrUpdateOut(InoutNoticeOut data) { //2023-09-02 暂时禁用通知单唯一性判断,原因:同一个单位有多个合同,就有多个通知单 // //新增出库通知单时,需要进行唯一性判断。即保证单位、仓库、粮食品种、年份唯一,且不存在未完成状态的单子。 // if (Constant.YN_Y.equals(data.getTag())) { // data.setCompanyId(ContextUtil.getCompanyId()); // NoticeParam param = new NoticeParam(); // param.setCompanyId(data.getCompanyId()); // param.setDeptId(data.getDeptId()); // // param.setCustomerId(data.getCustomerId()); // param.setDepotId(data.getDepotId()); // param.setFoodVariety(data.getFoodVariety()); // param.setYear(data.getYear()); // //若有合同信息,添加合同信息 // if (StringUtils.isNotEmpty(data.getContractId())) { // param.setContractId(data.getContractId()); // } // //若有计划信息,添加计划信息 // if (StringUtils.isNotEmpty(data.getPlanId())) { // param.setPlanId(data.getPlanId()); // } // param.setCompleteStatus(InoutConstant.COMPLETE_STATUS_NONE); // Integer integer = inoutManagerService.queryNoticeOut(param); // if (integer > 0) { // return "新增的出库通知单已存在,不能再次新增,请核查!"; // } // } Session session = this.getSessionFactory().openSession(); try { if (Constant.YN_Y.equals(data.getTag())) { data.setCreateUser(ContextUtil.getLoginUserCName()); data.setAuditStatus(InoutConstant.STATUS_NONE); data.setCompleteStatus(InoutConstant.COMPLETE_STATUS_NONE); session.save(data); } else { session.update(data); } } finally { session.flush(); session.close(); } return null; } public String delDataOut(InoutNoticeOut data) { Session session = this.getSessionFactory().openSession(); try { session.delete(data); } finally { session.flush(); session.close(); } return null; } /** * 根据参数查询出入库通知单 * * @param parameter * @return */ public List queryNoticeByKey(Map parameter) { if (parameter == null) { return null; } String type = (String) parameter.get("type"); if (StringUtils.isEmpty(type)) { return null; } String hql = " from "; if (InoutConstant.TYPE_IN.equals(type)) { hql += InoutNoticeIn.class.getName(); } else { hql += InoutNoticeOut.class.getName(); } hql += " where companyId =:companyId and deptId =:deptId and completeStatus =:completeStatus"; Map args = new HashMap<>(); args.put("companyId", ContextUtil.getCompanyId()); args.put("deptId", ContextUtil.subDeptId(null)); args.put("completeStatus", "NONE"); String str = (String) parameter.get("customerId"); if (StringUtils.isNotEmpty(str)) { hql += " and customerId =:customerId"; args.put("customerId", str); } str = (String) parameter.get("foodVariety"); if (StringUtils.isNotEmpty(str)) { hql += " and foodVariety =:foodVariety"; args.put("foodVariety", str); } if (InoutConstant.TYPE_OUT.equals(type)) { str = (String) parameter.get("depotId"); if (StringUtils.isNotEmpty(str)) { hql += " and depotId =:depotId"; args.put("depotId", str); } } str = (String) parameter.get("key"); if (StringUtils.isNotEmpty(str)) { hql += " and (name like:name or customerName like:customerName) "; args.put("name", "%" + str + "%"); args.put("customerName", "%" + str + "%"); } hql += " order by id "; List list1 = this.query(hql, args); List list = new ArrayList<>(); if (list1 == null || list1.isEmpty()) { return null; } NoticeDto dto; for (Object o : list1) { dto = new NoticeDto(); BeanUtils.copyProperties(o, dto); list.add(dto); } return list; } /** * 根据id获取通知单信息 * * @param id * @param type * @return */ public NoticeDto queryNoticeById(String id, String type) { if (StringUtils.isEmpty(id) || StringUtils.isEmpty(type)) { return null; } String hql = " from "; if (InoutConstant.TYPE_IN.equals(type)) { hql += InoutNoticeIn.class.getName(); } else { hql += InoutNoticeOut.class.getName(); } hql += " where companyId =:companyId and deptId =:deptId and id =:id"; Map args = new HashMap(); args.put("companyId", ContextUtil.getCompanyId()); args.put("deptId", ContextUtil.subDeptId(null)); args.put("id", id); hql += " order by id "; List list = this.query(hql, args); if (list == null || list.isEmpty()) { return null; } NoticeDto dto = new NoticeDto(); BeanUtils.copyProperties(list.get(0), dto); return dto; } }