李宇
2021-06-15 d00d1d584875b5b38c70c235963b46543a3eba28
src/main/java/com/nanometer/smartlab/controller/WarehouseStockMngController.java
@@ -1,15 +1,12 @@
package com.nanometer.smartlab.controller;
import com.nanometer.smartlab.dao.BaseMetaDao;
import com.nanometer.smartlab.dao.OpeApplyDao;
import com.nanometer.smartlab.dao.OpeReagentStatusDao;
import com.nanometer.smartlab.dao.OpeWarehouseReserveDao;
import com.nanometer.smartlab.entity.*;
import com.nanometer.smartlab.entity.dto.ApplyListDto;
import com.nanometer.smartlab.entity.enumtype.ApplyStatusVo;
import com.nanometer.smartlab.entity.enumtype.ApplyStatus;
import com.nanometer.smartlab.entity.enumtype.ArrivalStatus;
import com.nanometer.smartlab.entity.enumtype.SeeFlag;
import com.nanometer.smartlab.entity.enumtype.ValidFlag;
import com.nanometer.smartlab.entity.enumtype.*;
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.exception.ExceptionEnumCode;
import com.nanometer.smartlab.service.*;
@@ -50,8 +47,8 @@
/**
 * Created by cmower on 17/11/20.
 */
@Controller
@PropertySource(value = "WEB-INF/config.properties",encoding = "utf-8")
@Controller
@Scope("session")
public class WarehouseStockMngController extends BaseController {
@@ -74,6 +71,8 @@
   private SysSupplierService sysSupplierService;
   @Resource
   private OpeOrderService opeOrderService;
   @Resource
   private BaseMetaDao baseMetaDao;
   @Resource
   private MenuController menuController;
@@ -164,13 +163,17 @@
   private String endReagentCode;
   private String startReagentCodeForPerson;
   private String endReagentCodeForPerson;
   private String warehouseName;
   private Integer editFlag;
   private Integer isAllApply = 0;
   private StreamedContent file;
   @Value("${pdf.export.file.path}")
   private String pdfExportFilePath;
   @Value("${institute.name}")
   String instituteName;
   private boolean isExpired;
   private Hashtable printTable;
@@ -374,7 +377,7 @@
   private void initUserSelectList() {
      logger.info("WarehouseStockMngController initUserSelectList start");
      this.setUserSelectList(this.sysUserService.getSysUserList(null, null, null, null, null));
      this.setUserSelectList(this.sysUserService.getSysUserList(null, null, null, null, null,null,null));
      /**if(sysUserService.getSysUser(userId) == null)
      {
         this.laboratory = this.sysLaboratoryService.getSysLaboratoryListByDep(this.getUserDepartment());
@@ -530,9 +533,22 @@
      selectedTmpOrderList = null;
   }
   public void hideOrderTmp() {
      //清空
      selectedTmpOrderList = null;
      //隐藏
      RequestContext.getCurrentInstance().execute("document.getElementById('showTabOrder').style.display='none'");
   }
   public void  clearInputStorageTmp(){
      selectedInputStorageTmpOrderList = null;
   }
   public void hideInputStorageTmp(){
        selectedInputStorageTmpOrderList = null;
        RequestContext.getCurrentInstance().execute("document.getElementById('putInStorage').style.display='none'");
    }
   public void cancel(){
      if (trulySelectedList == null || trulySelectedList.size()<=0){
@@ -562,6 +578,10 @@
   }
   public void hide(){
      selectedTmpList = null;
      RequestContext.getCurrentInstance().execute("document.getElementById('showTab').style.display='none'");
   }
   public void cancelOrderTmp(){
      if (trulySelectedOrderList == null || trulySelectedOrderList.size()<=0){
         FacesUtils.info("至少选择一个");
@@ -623,7 +643,7 @@
         FacesUtils.info("至少选择一个");
         return;
      }
      this.userId = getUser().getId();
      this.menuController.goToPage(Constants.PAGE_WAREHOUSE_REAGENT_USE_NEW, Constants.PAGE_WAREHOUSE_STOCK_MNG);
   }
//
@@ -648,6 +668,8 @@
         }
      }
      checkTable = null;
      //
      this.userId = selectedTmpOrderList.get(0).getApplyUser();
      this.menuController.goToPage(Constants.PAGE_WAREHOUSE_REAGENT_USE_NEW_PERSON, Constants.PAGE_WAREHOUSE_STOCK_MNG);
   }
@@ -779,7 +801,7 @@
      //变换条码
      btCodeChange();
   }
   /**
   * 取消一个仓库领取
   */
@@ -1054,6 +1076,7 @@
      this.selectedInputStorageTmpOrderList = null;
      this.endReagentCodeForPerson = null;
      this.startReagentCodeForPerson = null;
      this.laboratoryId = null;
      this.useNum = null;
      this.menuController.backToPage();
   }
@@ -1190,16 +1213,20 @@
         printTable = new Hashtable();
         int sum = 0;
         List<ApplyListDto> applyList = new ArrayList<>();
         Map applyPersonInfo = sysUserService.getUser(userId);
         SysUser applyPersonInfo = sysUserService.getUser(userId);
         printTable.put("head", instituteName);
         printTable.put("title", "领用单");
         printTable.put("applyPerson", applyPersonInfo.get("name"));
         printTable.put("department", applyPersonInfo.get("meta_value"));
         printTable.put("applyPerson", applyPersonInfo.getName());
         printTable.put("department", applyPersonInfo.getDepartment());
         printTable.put("date", Utils.now("yyyy-MM-dd"));
         printTable.put("phone", applyPersonInfo.get("phone"));
         String receiptNum = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
         printTable.put("receiptNumber", receiptNum);
         printTable.put("project", applyPersonInfo.get("project"));
         if (StringUtils.isNotBlank(applyPersonInfo.getPhone())){
            printTable.put("phone", applyPersonInfo.getPhone());
         }
         if (StringUtils.isNotBlank(applyPersonInfo.getProject())){
            printTable.put("project", applyPersonInfo.getProject());
         }
         SysLaboratory lab = sysLaboratoryService.getSysLaboratory(laboratoryId);
         printTable.put("lab", lab.getName());
         this.receiptNumber = receiptNum;
@@ -1248,11 +1275,37 @@
   }
   /**
    * 点击打印  关联所有流向和领用单号e
    */
   public void associatedFlowReceiptNumber2() {
      try {
         opeUseFlowService.updateReceiptNumberByCode2(selectedTmpList, receiptNumber);
         //弹出打印窗口
         RequestContext.getCurrentInstance().execute("document.getElementById('indirectPrint').click()");
      } catch (Exception e) {
         logger.info(e.getMessage());
      }
   }
   public void closeDialog() {
      try {
         opeUseFlowService.updateReceiptNumberByCode(selectedTmpOrderList, receiptNumber);
         onCancelBtnClick();
      } catch (Exception e) {
         logger.info(e.getMessage());
      }
   }
   public void closeDialog2() {
      try {
         opeUseFlowService.updateReceiptNumberByCode2(selectedTmpList, receiptNumber);
         onCancelBtnClick();
      } catch (Exception e) {
         logger.info(e.getMessage());
      }
@@ -1441,14 +1494,18 @@
         printTable = null;
         printTable = new Hashtable();
         List<ApplyListDto> applyList = new ArrayList<>();
         Map applyPersonInfo = sysUserService.getUser(userId);
         SysUser applyPersonInfo = sysUserService.getUser(userId);
         printTable.put("head", instituteName);
         printTable.put("title", "领用单");
         printTable.put("applyPerson", applyPersonInfo.get("name"));
         printTable.put("department", applyPersonInfo.get("meta_value"));
         printTable.put("applyPerson", applyPersonInfo.getName());
         printTable.put("department", applyPersonInfo.getDepartment());
         printTable.put("date", Utils.now("yyyy-MM-dd"));
         printTable.put("phone", applyPersonInfo.get("phone"));
         printTable.put("project", applyPersonInfo.get("project"));
         if (StringUtils.isNotBlank(applyPersonInfo.getPhone())){
            printTable.put("phone", applyPersonInfo.getPhone());
         }
         if (StringUtils.isNotBlank(applyPersonInfo.getProject())){
            printTable.put("project", applyPersonInfo.getProject());
         }
         SysLaboratory lab = sysLaboratoryService.getSysLaboratory(laboratoryId);
         String receiptNum = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
         printTable.put("receiptNumber", receiptNum);
@@ -1463,11 +1520,19 @@
            if(selectWarehouseReserve.getFlag()==1){
               list.add(selectWarehouseReserve);
            }else{
               if (selectWarehouseReserve.getWarehouseId() == null) {
                  FacesUtils.warn("仓库不存在。");
                  return;
               }
               list2.add(selectWarehouseReserve);
            }
         }
         if(list.size()>0&&list!=null){
            for (OpeWarehouseReserve selectWarehouseReserve : list) {
               Map reagentDetail = sysReagentService.getReagentDetail(selectWarehouseReserve.getReagentId());
               if (reagentDetail == null) {
                  throw new Exception("试剂有误,请联系管理员");
               }
               List<String> reagentCodes = selectWarehouseReserve.getReagentCodes();
               if (reagentCodes != null && reagentCodes.size() > 0)
                  for (String opeReagentStatusId : reagentCodes) {
@@ -1494,7 +1559,6 @@
                     //}
                  }
               ApplyListDto lis = new ApplyListDto();
               Map reagentDetail = sysReagentService.getReagentDetail(selectWarehouseReserve.getReagentId());
               lis.setNum(String.valueOf(selectWarehouseReserve.getSelectNum())); //数量
               lis.setMainMetering(String.format("%s%s", reagentDetail.get("main_metering"), reagentDetail.get("unit")));
               lis.setControlProducts((String) reagentDetail.get("controlProducts"));
@@ -1512,10 +1576,15 @@
            //}
            this.opeWarehouseReserveService.claim(list, userId,projectNum);
         }
         if(list2.size()>0&&list2!=null){
            List<OpeApply> opeList=new ArrayList<>();
            //this.opeApplyService.getOpeApplyList(null,null,null,null,null)
            for(int i=0;i<list2.size();i++){
               Map reagentDetail = sysReagentService.getReagentDetail(list2.get(i).getReagentId());
               if (reagentDetail == null) {
                  throw new Exception("试剂有误,请联系管理员");
               }
               OpeApply opeApply=new OpeApply();
               opeApply.setArticleNumber(list2.get(i).getArticleNumber());
               opeApply.setHouseId(laboratoryId);
@@ -1535,7 +1604,6 @@
               this.opeLaboratoryReserveService.insert(lr);
               //opeList.add(this.opeApplyService.getOpeApply(list2.get(i).getId()));
               ApplyListDto lis = new ApplyListDto();
               Map reagentDetail = sysReagentService.getReagentDetail(list2.get(i).getReagentId());
               lis.setNum(String.valueOf(list2.get(i).getSelectNum())); //数量
               lis.setMainMetering(String.format("%s%s", reagentDetail.get("main_metering"), reagentDetail.get("unit")));
@@ -1550,8 +1618,38 @@
            }
            this.opeWarehouseReserveService.reagentDStore4(opeList,userId);
            for(int i=0;i<list2.size();i++){
               List<String> reagentCodes = opeReagentStatusService
                     .generateReagentCode(list2.get(i).getStartReagentCode2(), list2.get(i).getEndReagentCode2());
               Integer selectNum = list2.get(i).getSelectNum();
               for (int j = 0;j<selectNum;j++){
                  // 试剂使用情况入库insert
                  OpeUseFlow opeUseFlow = new OpeUseFlow();
                  opeUseFlow.setReagentCode(reagentCodes.get(0));
                  opeUseFlow.setStatus(ArrivalStatus.WAREHOUSE);
                  //仓库信息
                  List<OpeWarehouseReserve> warehouseReserveInfo = opeWarehouseReserveService
                        .selectWarehouseByRidAndArticleNumberAndWarehouse(list2.get(i).getReagent().getId()
                              , list2.get(i).getArticleNumber()
                              , list2.get(i).getWarehouseId());
                  opeUseFlow.setHouseId(list2.get(i).getWarehouseId());
                  opeUseFlow.setContainerId(warehouseReserveInfo.get(0).getContainerId());
                  opeUseFlow.setCreateTime(warehouseReserveInfo.get(0).getUpdateTime());
                  opeUseFlow.setUserId(warehouseReserveInfo.get(0).getUserId());
                  opeUseFlow.setRemainder(list2.get(i).getReagent().getMainMetering()!=null?list2.get(i).getReagent().getMainMetering():new BigDecimal(0));
                  opeUseFlow.setStoreType(StoreType.DIRECTSTORE);
                  Map<String, String> metaMap = new HashMap<>();
                  metaMap.put("groupId", "operate_status");
                  metaMap.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEIN.getKey()));
                  List<BaseMeta> baseMetaList = baseMetaDao.getBaseMetaList(metaMap);
                  opeUseFlow.setOperateState(baseMetaList.get(0).getId());
                  this.opeUseFlowService.insertOpeUseFlow(opeUseFlow);
                  reagentCodes.remove(0);
               }
               list2.get(i).setReserve(list2.get(i).getReserve()-list2.get(i).getSelectNum());
               opeWarehouseReserveDao.updateOpeWarehouseReserve(list2.get(i));
               opeWarehouseReserveDao.updateOpeWarehouseReserve2(list2.get(i));
            }
@@ -1577,6 +1675,17 @@
   */
   public void onSaveInputWarehouseClick(){
      try{
          //0.0输入校验
            for (OpeApplyReserve opeApplyReserve : opeApplyList) {
                if (StringUtils.isBlank(opeApplyReserve.getArticleNumber())) {
                    throw new BusinessException(ExceptionEnumCode.PARAM_EXIST, opeApplyReserve.getReagent().getName() + ":批号不能为空");
                }
                SysReagent sysReagent = sysReagentService.getSysReagent(opeApplyReserve.getReagent().getId());
            if (sysReagent == null){
               throw new BusinessException(ExceptionEnumCode.PARAM_EXIST, opeApplyReserve.getReagent().getName() + ":被删除");
            }
            }
         //用来检验提交表单得试剂条码是否重复
         Map<String,Boolean> checkTable= new HashMap<>();
         if (opeApplyList != null && opeApplyList.size() > 0) {
@@ -1629,11 +1738,11 @@
                  Map<String, Object> filters) {
               List<OpeWarehouseReserve> list = null;
               try {
                  int count = opeWarehouseReserveService.getOpeWarehouseReserveTotalCountByName(reagentId, supplierId,productSn);
                  int count = opeWarehouseReserveService.getOpeWarehouseReserveTotalCountByName(reagentId, supplierId,productSn,warehouseName);
                  this.setRowCount(count);
                  if (count > 0) {
                     list = opeWarehouseReserveService.getOpeWarehouseReserveListByName(reagentId, supplierId, first,
                           pageSize,productSn);
                           pageSize,productSn,warehouseName);
                  }
               } catch (Exception e) {
                  logger.error(e);
@@ -1679,11 +1788,11 @@
               }
               try {
                  int count = opeApplyService.getOpeApplyReserveTotalCountByNameFor(id,reagentId, userName,productSn,applyCode,status);
                  int count = opeApplyService.getOpeApplyReserveTotalCountByNameFor(id, reagentId, userName, productSn, applyCode, status, isAllApply,isExpired);
                  this.setRowCount(count);
                  if (count > 0) {
                     list = opeApplyService.getOpeApplyReserveListByNameFor(id,reagentId, userName, first,
                           pageSize,productSn,applyCode,status);
                     list = opeApplyService.getOpeApplyReserveListByNameFor(id, reagentId, userName, first,
                           pageSize, productSn, applyCode, status, isAllApply,isExpired);
                  }
               } catch (Exception e) {
                  logger.error(e);
@@ -1788,7 +1897,7 @@
            realDataList=selectedListForPerson;
         }else {
            realDataList = opeApplyService.getOpeApplyReserveListByNameFor(id,reagentId, userName, null,
                  null,productSn,applyCode,status);
                  null,productSn,applyCode,status,isAllApply,isExpired);
         }
         List<String> headerList = new ArrayList<>();
         headerList.add("申购编号");
@@ -1905,7 +2014,7 @@
            realDataList=selectedList;
         }else {
            realDataList = opeWarehouseReserveService.getOpeWarehouseReserveListByName(reagentId, supplierId, null,
                  null,productSn);
                  null,productSn,warehouseName);
         }
            List<String> headerList = new ArrayList<>();
            headerList.add("试剂名称");
@@ -2506,7 +2615,7 @@
            list.add(sysUser);
            applyUserSelectList = list;
         } else {
            applyUserSelectList = this.sysUserService.getSysUserList(null, null, null, null, null);
            applyUserSelectList = this.sysUserService.getSysUserList(null, null, null, null, null,null,null);
         }
      }
      return applyUserSelectList;
@@ -2641,31 +2750,37 @@
   public void resetLaboratory(){
      laboratory = null;
      laboratoryId = null;
      laboratoryContainers = null;
      //getLaboratory();
      //getLaboratoryContainers();
   }
//   public void setContainerId(){
//   }
   public void resetLaboratoryContainers() {
      laboratoryContainers = null;
      //getLaboratoryContainers();
   }
   public List<SysLaboratory> getLaboratory() {
      if(userId != null && userId.trim().length() > 0)
       if(userId != null && userId.trim().length() > 0)
      {
         this.laboratory = this.sysLaboratoryService.getSysLaboratoryListByDep(sysUserService.getSysUser(userId).getDepartment());
         //Todo 修改申领人的实验室显示信息
         this.laboratory = this.sysLaboratoryService.getSysLaboratoryListByUserId(userId);
         if(this.laboratory != null && this.laboratory.size() > 0)
         {
            //flag =true;
            //if(laboratoryId != null && laboratoryId.trim().length() > 0)
            //{
            //   this.oriLaboratoryId = this.laboratoryId;
            //}else
            //{
            //   this.oriLaboratoryId = this.laboratory.get(0).getId();
            //}
            this.laboratoryId=this.laboratory.get(0).getId();
            this.laboratoryContainers = this.sysLaboratoryContainerService.getSysLaboratoryContainerList(this.laboratory.get(0).getId());
            if(laboratoryId != null && laboratoryId.trim().length() > 0)
            {
               this.oriLaboratoryId = this.laboratoryId;
            }else
            {
               this.laboratoryId = this.laboratory.get(0).getId();
            }
//            this.laboratoryId = this.laboratory.get(0).getId();
            this.laboratoryContainers = this.sysLaboratoryContainerService.getSysLaboratoryContainerList(laboratoryId);
         }else {
            this.oriLaboratoryId = null;
            this.laboratoryContainers = null;
@@ -2684,7 +2799,7 @@
   }
   public List<SysLaboratoryContainer> getLaboratoryContainers() {
      if(laboratoryId != null && laboratoryId.trim().length() > 0)
       if(laboratoryId != null && laboratoryId.trim().length() > 0)
      {
         this.laboratoryContainers = this.sysLaboratoryContainerService.getSysLaboratoryContainerList(laboratoryId);
      }
@@ -2704,6 +2819,7 @@
   }
   public String getLaboratoryContainerId() {
      return laboratoryContainerId;
   }
@@ -2831,7 +2947,7 @@
   }
   public List getConsignee() {
      List<SysUser> dataList = this.sysUserService.getSysUserList(null, null, null, null, null);
      List<SysUser> dataList = this.sysUserService.getSysUserList(null, null, null, null, null,null,null);
      //将admin置于首位
      for (int i = 0; i < dataList.size(); i++) {
         if ("admin".equals(dataList.get(i).getAccount())){
@@ -2969,4 +3085,67 @@
   public void setReceiptNumber(String receiptNumber) {
      this.receiptNumber = receiptNumber;
   }
   public String getWarehouseName() {
      return warehouseName;
   }
   public void setWarehouseName(String warehouseName) {
      this.warehouseName = warehouseName;
   }
   public Integer getIsAllApply() {
      return isAllApply;
   }
   public void setIsAllApply(Integer isAllApply) {
      this.isAllApply = isAllApply;
   }
   public boolean getIsExpired() {
      return isExpired;
   }
   public void setIsExpired(boolean isExpired) {
      this.isExpired = isExpired;
   }
   //过期处理
   public void expireOrder() {
      //1.判断当前订单是否是已入库的状态
      if (this.selectedListForPerson.size() < 1) {
         FacesUtils.warn("请选择数据。");
         return;
      }
      ArrayList<String> ids = new ArrayList<>();
      for (OpeApplyReserve oa : this.selectedListForPerson) {
         ids.add(oa.getId());
         if (oa.getStatus() != ApplyStatus.SUPPLIER_CONFIRM) {
            FacesUtils.warn("只能让已确认状态的单子过期。");
            return;
         }
      }
      opeApplyService.updateOpeApplyStatus(ApplyStatus.EXPIRED, null, ids);
      FacesUtils.warn("操作成功。");
   }
   public void recoverOrder(){
      if (this.selectedListForPerson.size() < 1) {
         FacesUtils.warn("请选择数据。");
         return;
      }
      ArrayList<String> ids = new ArrayList<>();
      for (OpeApplyReserve oa : this.selectedListForPerson) {
         ids.add(oa.getId());
         if (oa.getStatus() != ApplyStatus.EXPIRED) {
            FacesUtils.warn("只能让过期单子恢复确认。");
            return;
         }
      }
      opeApplyService.updateOpeApplyStatus(ApplyStatus.SUPPLIER_CONFIRM, null, ids);
      FacesUtils.warn("操作成功。");
   }
}