package com.nanometer.smartlab.service; import com.nanometer.smartlab.dao.OpeApplyDao; import com.nanometer.smartlab.dao.SysReagentDao; import com.nanometer.smartlab.entity.*; import com.nanometer.smartlab.entity.enumtype.ApplyStatus; import com.nanometer.smartlab.entity.enumtype.SeeFlag; import com.nanometer.smartlab.entity.enumtype.ValidFlag; import com.nanometer.smartlab.exception.AlarmCode; import com.nanometer.smartlab.exception.AlarmException; import com.nanometer.smartlab.exception.BusinessException; import com.nanometer.smartlab.exception.ExceptionEnumCode; import com.nanometer.smartlab.util.IDUtils; import com.nanometer.smartlab.util.MessageUtil; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.primefaces.event.FileUploadEvent; import org.primefaces.model.UploadedFile; import org.springframework.context.annotation.Lazy; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.sql.Timestamp; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; /** * Created by johnny on 17/12/12. */ @Service("opeApplyService") public class OpeApplyServiceImpl implements OpeApplyService { private static Logger logger = Logger.getLogger(OpeApplyService.class); @Resource(name = "opeApplyDao") OpeApplyDao opeApplyDao; @Lazy @Resource OpeOrderService opeOrderService; @Lazy @Resource OpeReagentStatusService opeReagentStatusService; @Lazy @Resource OpeWarehouseReserveService opeWarehouseReserveService; @Lazy @Resource SysReagentService sysReagentService; @Resource SysSequenceService sysSequenceService; @Resource private SysUserService sysUserService; @Transactional(propagation = Propagation.REQUIRED) public List getOpeApplyList(String reagentName, Timestamp startDeadline, Timestamp endDeadline, Integer status, String applyUserId, String approveUserId, String queryCas, Integer first, Integer pageSize,String applyCode,String applyUserName,Byte isShow) { try { Map params = new HashMap(); if (StringUtils.isNotBlank(reagentName)) { params.put("reagentName", "%" + reagentName + "%"); } params.put("startDeadline", startDeadline); params.put("endDeadline", endDeadline); params.put("status", status); params.put("isShow", isShow); if (StringUtils.isNotBlank(applyUserId)) { SysUser sysUser = sysUserService.getSysUser(applyUserId); // 不是管理员时,加入applyUserId if (sysUser.getSeeFlag().getKey() != SeeFlag.MANAGE.getKey() && sysUser.getSeeFlag().getKey() != SeeFlag.LEADING.getKey()) { params.put("applyUserId", applyUserId); } if("连悦".equals(sysUser.getName())){ params.remove("applyUserId"); } } params.put("approveUserId", approveUserId); if (StringUtils.isNotBlank(queryCas)) { params.put("cas", "%" + queryCas + "%"); } params.put("first", first); params.put("pageSize", pageSize); params.put("applyCode", applyCode); params.put("applyUserName", applyUserName); return this.opeApplyDao.getOpeApplyList(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public List getOpeApplyListForApproval(String applyUserName,String approvaUserName,String reagentName, Timestamp startDeadline, Timestamp endDeadline, Integer status, String applyUserId, String approveUserId, String queryCas, Integer first, Integer pageSize,String applyCode,String searchApproval) { try { Map params = new HashMap(); if (StringUtils.isNotBlank(reagentName)) { params.put("reagentName", "%" + reagentName + "%"); } params.put("startDeadline", startDeadline); params.put("endDeadline", endDeadline); params.put("status", status); params.put("searchApproval",searchApproval); if (StringUtils.isNotBlank(approveUserId)) { SysUser sysUser = sysUserService.getSysUser(approveUserId); // 不是管理员时,加入applyUserId if (sysUser.getSeeFlag().getKey() != SeeFlag.MANAGE.getKey() && sysUser.getSeeFlag().getKey() != SeeFlag.LEADING.getKey()) { params.put("approveUserId", approveUserId); } } params.put("applyUserId", applyUserId); if (StringUtils.isNotBlank(queryCas)) { params.put("cas", "%" + queryCas + "%"); } if (StringUtils.isNotBlank(approvaUserName)) { params.put("approvaUserName", "%" + approvaUserName + "%"); } if (StringUtils.isNotBlank(applyUserName)) { params.put("applyUserName", "%" + applyUserName + "%"); } params.put("first", first); params.put("pageSize", pageSize); params.put("applyCode", applyCode); return this.opeApplyDao.getOpeApplyList(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public int getOpeApplyTotalCountForApproval(String applyUserName,String approvaUserName,String reagentName, Timestamp startDeadline, Timestamp endDeadline, Integer status, String applyUserId, String approveUserId, String queryCas,String applyCode,String searchApproval) { try { Map params = new HashMap(); if (StringUtils.isNotBlank(reagentName)) { params.put("reagentName", "%" + reagentName + "%"); } params.put("startDeadline", startDeadline); params.put("endDeadline", endDeadline); params.put("status", status); params.put("searchApproval",searchApproval); if (StringUtils.isNotBlank(approveUserId)) { SysUser sysUser = sysUserService.getSysUser(approveUserId); // 不是管理员时,加入applyUserId if (sysUser.getSeeFlag().getKey() != SeeFlag.MANAGE.getKey() && sysUser.getSeeFlag().getKey() != SeeFlag.LEADING.getKey()) { params.put("approveUserId", approveUserId); } } if (StringUtils.isNotBlank(approvaUserName)) { params.put("approvaUserName", "%" + approvaUserName + "%"); } if (StringUtils.isNotBlank(applyUserName)) { params.put("applyUserName", "%" + applyUserName + "%"); } params.put("applyUserId", applyUserId); if (StringUtils.isNotBlank(queryCas)) { params.put("cas", "%" + queryCas + "%"); } params.put("applyCode", applyCode); return this.opeApplyDao.getOpeApplyTotalCount(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public int getOpeApplyTotalCount(String reagentName, Timestamp startDeadline, Timestamp endDeadline, Integer status, String applyUserId, String approveUserId, String queryCas,String applyCode,String applyUserName,Byte isShow) { try { Map params = new HashMap(); if (StringUtils.isNotBlank(reagentName)) { params.put("reagentName", "%" + reagentName + "%"); } params.put("startDeadline", startDeadline); params.put("endDeadline", endDeadline); params.put("status", status); params.put("isShow", isShow); if (StringUtils.isNotBlank(applyUserId)) { SysUser sysUser = sysUserService.getSysUser(applyUserId); // 不是管理员时,加入applyUserId if (sysUser.getSeeFlag().getKey() != SeeFlag.MANAGE.getKey() && sysUser.getSeeFlag().getKey() != SeeFlag.LEADING.getKey()) { params.put("applyUserId", applyUserId); } if("连悦".equals(sysUser.getName())){ params.remove("applyUserId"); } } params.put("approveUserId", approveUserId); params.put("applyUserName", applyUserName); if (StringUtils.isNotBlank(queryCas)) { params.put("cas", "%" + queryCas + "%"); } params.put("applyCode", applyCode); return this.opeApplyDao.getOpeApplyTotalCount(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public OpeApply getOpeApply(String id) { try { return this.opeApplyDao.getOpeApply(id); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public OpeApply insertOpeApply(OpeApply opeApply) { try { opeApply.setId(IDUtils.uuid()); this.opeApplyDao.insertOpeApply(opeApply); return opeApply; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public List insertOpeApplyList(List opeApplyList) { try { this.opeApplyDao.insertOpeApplyList(opeApplyList); return opeApplyList; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updateOpeApply(OpeApply opeApply) { try { int row = this.opeApplyDao.updateOpeApply(opeApply); if (row == 0) { return false; } return true; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updateFirst(String id) { try { Map params = new HashMap(); params.put("id",id); int row = this.opeApplyDao.updateFirst(params); if (row == 0) { return false; } return true; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updateFirst2(String id) { try { Map params = new HashMap(); params.put("id",id); int row = this.opeApplyDao.updateFirst2(params); if (row == 0) { return false; } return true; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updateOpeApplyProject(String newObjective,String oldObjective) { try { Map params = new HashMap(); params.put("newObjective", newObjective); params.put("oldObjective", oldObjective); int row = this.opeApplyDao.updateOpeApplyProject(params); return true; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Override public boolean updateSelectedOpeApplyStatus(String memo, List applyIds, String adminUserId, List adminApplyIds,List firstUserIds) { boolean apply = false, adminApply = false; if (!CollectionUtils.isEmpty(applyIds)) { apply = this.updateOpeApplyStatus(ApplyStatus.APPROVED, memo, applyIds); } if (!CollectionUtils.isEmpty(adminApplyIds)) { adminApply = this.updateOpeApplyAdminStatus2(memo, adminApplyIds, adminUserId,firstUserIds); } return apply || adminApply; } @Transactional(propagation = Propagation.REQUIRED) public boolean updateOpeApplyStatus(ApplyStatus status, String memo, List applyIds) { try { Map params = new HashMap(); params.put("status", status.getKey()); params.put("memo", memo); params.put("applyIds", applyIds); int row = this.opeApplyDao.updateOpeApplyStatus(params); if (row == 0) { return false; } return true; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updateOpeApplyAdminStatus2(String memo, List applyIds, String adminUserId,List firstUserIds) { try { for(int i=0;i params = new HashMap(); params.put("userId", adminUserId); params.put("memo", memo); params.put("id", applyIds.get(i)); params.put("beforeUserId",firstUserIds.get(i)); int row = this.opeApplyDao.updateOpeApplyAdmin2(params); if (row == 0) { return false; } } return true; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updateOpeApplyAdminStatus(String memo, List applyIds, String adminUserId,List firstUserIds) { try { Map params = new HashMap(); params.put("userId", adminUserId); params.put("memo", memo); params.put("applyIds", applyIds); params.put("firstUserIds",firstUserIds); int row = this.opeApplyDao.updateOpeApplyAdmin(params); if (row == 0) { return false; } return true; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Transactional(propagation = Propagation.REQUIRED) public boolean deleteOpeApply(List opeApplyList) { try { if (opeApplyList == null || opeApplyList.size() == 0) { return false; } List ids = new ArrayList(); for (OpeApply opeApply : opeApplyList) { ids.add(opeApply.getId()); } int row = this.opeApplyDao.deleteOpeApply(ids); if (row == 0) { return false; } return true; } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } public boolean isApplyPendingApproval(OpeApply opeApply) { if (opeApply != null && opeApply.getStatus() != null && opeApply.getStatus().getKey() == ApplyStatus.PENDING_APPROVAL.getKey()) { return true; } return false; } public boolean isApplyApproved(OpeApply opeApply) { if (opeApply != null && opeApply.getStatus() != null && opeApply.getStatus().getKey() == ApplyStatus.APPROVED.getKey()) { return true; } return false; } public boolean isAllowApplyCancel(OpeApply opeApply) { if (this.isApplyPendingApproval(opeApply) || this.isApplyApproved(opeApply)) { return true; } return false; } @Override public OpeApply selectOpeApplyByPrimaryKey(String id) { try { OpeApply info = this.opeApplyDao.selectOpeApplyByPrimaryKey(id); return info; } catch (DuplicateKeyException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); } catch (DataIntegrityViolationException ex) { logger.warn(ex.getMessage(), ex); throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); } } @Override public int getOpeApplyReserveTotalCountByName(String id,String reagentName, String personName) { try { Map params = new HashMap(); params.put("reagentName", reagentName); params.put("personName", personName); params.put("userId",id); return this.opeApplyDao.getOpeApplyReserveTotalCount(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Override public int getOpeApplyReserveTotalCountByNameFor(String id,String reagentName, String personName,String productSn,String applyCode,Integer status,Integer isAllApply,boolean isExpired) { try { Map params = new HashMap(); params.put("reagentName", reagentName); params.put("personName", personName); params.put("userId",id); params.put("productSn",productSn); params.put("applyCode",applyCode); if (isExpired) { params.put("status",ApplyStatus.EXPIRED); }else{ params.put("status", status); } params.put("isAllApply",isAllApply); return this.opeApplyDao.getOpeApplyReserveTotalCountFor(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Override public List getOpeApplyReserveListByNameFor(String id,String reagentName, String personName, Integer first, Integer pageSize,String productSn,String applyCode,Integer status,Integer isAllApply,boolean isExpired) { try { Map params = new HashMap(); params.put("reagentName", reagentName); params.put("personName", personName); params.put("userId",id); params.put("first", first); params.put("pageSize", pageSize); params.put("productSn",productSn); params.put("applyCode",applyCode); if (isExpired) { params.put("status",ApplyStatus.EXPIRED); }else{ params.put("status", status); } params.put("isAllApply",isAllApply); return this.opeApplyDao.getOpeApplyReserveListFor(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Override public List getOpeApplyReserveListByName(String id,String reagentName, String personName, Integer first, Integer pageSize) { try { Map params = new HashMap(); params.put("reagentName", reagentName); params.put("personName", personName); params.put("userId",id); params.put("first", first); params.put("pageSize", pageSize); return this.opeApplyDao.getOpeApplyReserveList(params); } catch (DataAccessException e) { logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updaetOpeApplyPrice(BigDecimal applyPrice, String id){ try{ Map params = new HashMap(); params.put("applyPrice", applyPrice); params.put("id", id); int row = this.opeApplyDao.updaetOpeApplyPrice(params); if (row == 0) { return false; } return true; }catch (DataAccessException e){ logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public boolean updaetOpeApplyStockFlag(int stockFlag, String id){ try{ Map params = new HashMap(); params.put("stockFlag", stockFlag); params.put("id", id); int row = this.opeApplyDao.updaetOpeApplyStockFlag(params); if (row == 0) { return false; } return true; }catch (DataAccessException e){ logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public boolean cancelApply(ApplyStatus status,String id){ try{ Map params = new HashMap(); params.put("status", status.getKey()); params.put("id", id); int row = this.opeApplyDao.cancelApply(params); if (row == 0) { return false; } return true; }catch (DataAccessException e){ logger.error(e.getMessage(), e); throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e); } } @Transactional(propagation = Propagation.REQUIRED) public ListselectByReId(String id){ return this.opeApplyDao.selectByReId(id); } @Transactional(propagation = Propagation.REQUIRED) public void updateByReId(String newReId,String oldReId){ Map params=new HashMap(); params.put("newReId",newReId); params.put("oldReId",oldReId); this.opeApplyDao.updateByReId(params); } @Override public OpeApplyReserve getOpeApplyDetail(String id) { return opeApplyDao.getOpeApplyDetail(id); } @Override public void updateOpeApplyInfo(ApplyStatus storage, String consigneeId, Timestamp arrivalTime, String applyId) { Map params = new HashMap(); params.put("status", storage); params.put("consigneeId", consigneeId); params.put("arrivalTime", arrivalTime); params.put("applyId", applyId); opeApplyDao.updateOpeApplyInfo(params); } @Override @Transactional public void orderInputWarehouse(List opeApplyList,String consigneeId,Timestamp arrivalTime) { for (OpeApplyReserve opeApplyReserve:opeApplyList) { //0.1获取该申购单的订单 OpeOrder oo = opeOrderService.getOrder(opeApplyReserve.getId()); if (oo == null) { throw new BusinessException(ExceptionEnumCode.ORDER_ERROR,"订单不存在"); } //0.2检查条码->得到试剂条码列表 List codeList = opeReagentStatusService .checkReagentCode(opeApplyReserve.getStartReagentCode2(), opeApplyReserve.getEndReagentCode2(), opeApplyReserve.getArrivalNum()); //1.入库 if (codeList == null){ //无条码入库 不需要增加状态和流向 //1.1库存表增加 opeWarehouseReserveService.insertOpeWarehouseReserve2(opeApplyReserve, oo,consigneeId); }else{ //条码入库 assert codeList.size() > 0; //1.1入库(库存表增加) opeWarehouseReserveService.insertOpeWarehouseReserve2(opeApplyReserve, oo,consigneeId); //1.2试剂状态表增加,流向增加 opeReagentStatusService.orderInputWarehouseReagentStatusAndUseFlow(opeApplyReserve,consigneeId,codeList,oo); } //2.更改申购单所属订单状态(判断子订单是否全部完成) //2.1更改该申购单的状态,收货人和到货时间 this.updateOpeApplyInfo(ApplyStatus.STORAGE,consigneeId,arrivalTime, opeApplyReserve.getId()); //2.2更改订单状态 List oas = opeOrderService.getOpeApplyListByOrder(oo.getId()); assert oas.size() > 0; //子订单是否全部入库,是则父单为已入库,否则未完成 boolean flag = oas.stream().allMatch(oa -> oa.getStatus() == ApplyStatus.STORAGE); oo.setConsigneeUserId(consigneeId); oo.setArrivalTime(arrivalTime); if (flag){ oo.setStatus(ApplyStatus.STORAGE); opeOrderService.updateOpeOrderStatus(oo); }else{ oo.setStatus(ApplyStatus.UNCOMPLETED); opeOrderService.updateOpeOrder(oo); } } } /** * 补贴条码更新订单的领用数量 */ @Override public void btUpdateApplyAndOrder(List opeList) { } @Override @Transactional public void importApply(FileUploadEvent event,SysUser user) throws IOException { UploadedFile file = event.getFile(); InputStream is = file.getInputstream(); boolean isExcel2003 = true; if (file.getFileName().matches("^.+\\.(?i)(xlsx)$")) { isExcel2003 = false; } Workbook wb = null; if (isExcel2003) { wb = new HSSFWorkbook(is); } else { wb = new XSSFWorkbook(is); } Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); ArrayList adds = new ArrayList<>(); Row row = null; int totalCells = 0; for (int i = 1; i < totalRows; i++) { List valuesList = new ArrayList(); row = sheet.getRow(i); totalCells = row.getLastCellNum(); //第10列是课题,其他都不能为空 for (int index = 0; index < totalCells; index++) { String cellInfo = ""; if (row.getCell(index) != null) { if (row.getCell(index).getCellType() == CellType.BLANK && index != 9) { throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "第" + ++i + "行:除了课题组都不能为空"); } if (row.getCell(index).getCellType() == CellType.NUMERIC) { DecimalFormat df = new DecimalFormat("#######"); //格式化number String字符 cellInfo = df.format(row.getCell(index).getNumericCellValue()); }else{ cellInfo = row.getCell(index).getStringCellValue(); } } valuesList.add(cellInfo); } Map detail = new HashMap<>(); detail.put("product_sn", valuesList.get(0)); detail.put("name", valuesList.get(1)); detail.put("reagent_format", valuesList.get(2)); detail.put("packing", valuesList.get(3)); detail.put("cas", valuesList.get(4)); detail.put("product_home", valuesList.get(5)); detail.put("reagent_type", valuesList.get(6)); SysReagent sysReagent = sysReagentService.getReagentByDetail(detail); if (sysReagent == null) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:试剂不存在或者有多条,导入失败"); //申购数量 Integer num = new Double(valuesList.get(7)).intValue(); if (num < 1) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:试剂申购数量不合法,导入失败"); //申购人姓名 String applyUserName = valuesList.get(8); SysUser applyUser = sysUserService.getUserByName(applyUserName); if (applyUser == null) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:申购人不存在或者申购人姓名存在重复,导入失败"); //课题组名称 String objective = valuesList.get(9); String format = "yyyy-MM-dd"; SimpleDateFormat dateFormat = new SimpleDateFormat(format); Date applyDate = null; int cellnum = 10; CellType type = row.getCell(cellnum).getCellType(); Object value = row.getCell(cellnum); if (null == value || StringUtils.isBlank(value.toString())) { throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行,申购日期不能为空"); } else { if (type.equals(CellType.NUMERIC)) { try { applyDate = row.getCell(cellnum).getDateCellValue(); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行,申购日期解析错误,请检查是否有无效字符"); } } else if (type.equals(CellType.STRING)) { String cellInfo = row.getCell(10).getStringCellValue(); try { applyDate = dateFormat.parse(cellInfo); } catch (ParseException e) { e.printStackTrace(); throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:申购日期不合法,应如2016-10-09,导入失败"); } } else { throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:申购日期解析错误,请检查是否有无效字符"); } } //选择的审批人姓名 String approveUserName = valuesList.get(11); //根据姓名获取用户信息的id SysUser approveUser = sysUserService.getUserByName(approveUserName); if (approveUser == null) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:审批人不存在或者审批人姓名存在重复,导入失败"); OpeApply opeApply = new OpeApply(); opeApply.setId(IDUtils.uuid()); opeApply.setValidFlag(ValidFlag.VALID); opeApply.setStatus(ApplyStatus.PENDING_APPROVAL); opeApply.setApplyCode(sysSequenceService.getApplyCode()); //设置试剂id opeApply.setReagent(sysReagent); assert applyDate != null; Timestamp applyTime = new Timestamp(applyDate.getTime()); opeApply.setCreateTime(applyTime); opeApply.setUpdateTime(applyTime); //价格 opeApply.setApplyPrice(sysReagent.getPrice()); //申购数量 opeApply.setNum(num); //申购人 opeApply.setApplyUserId(applyUser.getId()); //选择的审批人 opeApply.setApproveUserId(approveUser.getId()); //选择的课题组信息 opeApply.setObjective(objective); adds.add(opeApply); } if (adds.size() > 0) { opeApplyDao.insertList(adds); } } @Override public OpeApplyReserve getOpeApplyReserveListByNameForRowData(String rowKey) { return opeApplyDao.getOpeApplyReserveListByNameForRowData(rowKey); } }