From 47a751cb301d05276ae5d75145d57b2d090fe4e1 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: 星期一, 01 七月 2024 10:58:35 +0800
Subject: [PATCH] change

---
 src/main/java/com/nanometer/smartlab/service/OpeUseFlowServiceImpl.java |  449 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 358 insertions(+), 91 deletions(-)

diff --git a/src/main/java/com/nanometer/smartlab/service/OpeUseFlowServiceImpl.java b/src/main/java/com/nanometer/smartlab/service/OpeUseFlowServiceImpl.java
index d0fe81d..2b01f35 100644
--- a/src/main/java/com/nanometer/smartlab/service/OpeUseFlowServiceImpl.java
+++ b/src/main/java/com/nanometer/smartlab/service/OpeUseFlowServiceImpl.java
@@ -8,13 +8,15 @@
 
 import javax.annotation.Resource;
 
-import com.nanometer.smartlab.dao.BaseMetaDao;
-import com.nanometer.smartlab.dao.SysLaboratoryContainerDao;
-import com.nanometer.smartlab.dao.SysWarehouseContainerDao;
+import com.hazelcast.core.IFunction;
+import com.nanometer.smartlab.dao.*;
 import com.nanometer.smartlab.entity.*;
+import com.nanometer.smartlab.entity.dto.OpeUseFlowQueryDto;
 import com.nanometer.smartlab.entity.dto.PersonUseDetail;
 import com.nanometer.smartlab.entity.enumtype.OperateStatus;
+import com.nanometer.smartlab.model.CommonPage;
 import com.nanometer.smartlab.util.Constants;
+import com.nanometer.smartlab.util.ExcelUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang3.time.DateUtils;
 import org.apache.log4j.Logger;
@@ -25,7 +27,6 @@
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
-import com.nanometer.smartlab.dao.OpeUseFlowDao;
 import com.nanometer.smartlab.entity.enumtype.ArrivalStatus;
 import com.nanometer.smartlab.entity.enumtype.SeeFlag;
 import com.nanometer.smartlab.exception.AlarmCode;
@@ -59,19 +60,13 @@
     private SysReagentService sysReagentService;
     @Resource
     private BaseMetaDao baseMetaDao;
+    @Resource
+    private OpeReagentStatusDao opeReagentStatusDao;
 
 
     @Transactional(propagation = Propagation.REQUIRED)
     public OpeUseFlow insertOpeUseFlow(OpeUseFlow opeUseFlow) {
         try {
-            if (opeUseFlow.getId() == null) {
-                opeUseFlow.setId(IDUtils.uuid());
-            }
-
-            if(opeUseFlow.getCreateTime()==null){
-            	opeUseFlow.setCreateTime(new Timestamp(System.currentTimeMillis()));
-            }
-
             this.opeUseFlowDao.insertOpeUseFlow(opeUseFlow);
             return opeUseFlow;
         } catch (DuplicateKeyException ex) {
@@ -88,8 +83,26 @@
         }
     }
 
+    @Override
+    public int batchInsertOpeUseFlow(List<OpeUseFlow> opeUseFlowList) {
+        try {
+            return this.opeUseFlowDao.batchInsertOpeUseFlow(opeUseFlowList);
+        } 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<OpeUseFlow> getOpeUseFlowList(String reagentId, String reagentCode, Integer status, String userId,
+    public List<OpeUseFlow> getOpeUseFlowList(Long reagentId, String reagentCode, Integer status, Long userId,
                                               Integer first, Integer pageSize) {
         try {
             Map<String, Object> params = new HashMap<String, Object>();
@@ -113,7 +126,7 @@
     }
 
     @Transactional(propagation = Propagation.REQUIRED)
-    public int getOpeUseFlowTotalCount(String reagentId, String reagentCode, Integer status, String userId) {
+    public int getOpeUseFlowTotalCount(Long reagentId, String reagentCode, Integer status, Long userId) {
         try {
             Map<String, Object> params = new HashMap<String, Object>();
             params.put("reagentId", reagentId);
@@ -134,8 +147,8 @@
     }
 
     @Transactional(propagation = Propagation.REQUIRED)
-    public List<OpeUseFlow> getOpeUseFlowListByName(String houseName,String reagentId, String reagentCode,String containerCode, Integer status, String userId,
-                                                    Date startDate,Date endDate,Integer first, Integer pageSize) {
+    public List<OpeUseFlow> getOpeUseFlowListByName(String houseName,Long reagentId, String reagentCode,String containerCode, Integer status, Long userId,
+                                                    Date startDate,Date endDate,Integer first, Integer pageSize,Integer operatestate) {
         try {
             Map<String, Object> params = new HashMap<String, Object>();
 
@@ -174,6 +187,7 @@
 
             params.put("status", status);
             params.put("houseName", houseName);
+            params.put("operatestate", operatestate);
             params.put("containerCode", containerCode);
             addParamByUserId(userId, params);
 
@@ -187,8 +201,57 @@
         }
     }
 
+    public CommonPage<OpeUseFlow> getOpeUseFlowSimpleInfoList(Integer pageNum, Integer pageSize, OpeUseFlowQueryDto opeUseFlowQueryDto) {
+        CommonPage commonPage=new CommonPage();
+        Map<String, Object> params = new HashMap<String, Object>();
+        if(pageNum==null||pageNum<1){
+            pageNum=1;
+        }
+        if(pageSize==null||pageSize<1){
+            pageSize=10;
+        }
+        if(pageSize>50){
+            pageSize=50;//每页最多查询50条记录
+        }
+        commonPage.setPageNum(pageNum);
+        commonPage.setPageSize(pageSize);
+
+        params.put("reagentName", opeUseFlowQueryDto.getReagentName());
+        if (StringUtils.isNotBlank(opeUseFlowQueryDto.getReagentCode())) {
+            params.put("reagentCode", "%" + opeUseFlowQueryDto.getReagentCode() + "%");
+        }
+        SimpleDateFormat sdfstart = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+        SimpleDateFormat sdfend = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
+        Date now = new Date();
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(now);
+        cal.add(Calendar.DATE, -7);
+        Date startTime = cal.getTime();
+        params.put("startDate",opeUseFlowQueryDto.getStartDate()!=null?opeUseFlowQueryDto.getStartDate():sdfstart.format(startTime));
+        params.put("endDate",opeUseFlowQueryDto.getEndDate()!=null?opeUseFlowQueryDto.getEndDate():sdfend.format(now));
+
+        params.put("houseName", opeUseFlowQueryDto.getHouseName());
+        params.put("operatestate", opeUseFlowQueryDto.getOperatestate());
+        params.put("containerCode", opeUseFlowQueryDto.getContainerCode());
+
+        params.put("first", (pageNum-1)*pageSize);
+        params.put("pageSize", pageSize);
+
+        Long total= new Long(this.opeUseFlowDao.getOpeUseFlowTotalCount(params));
+        commonPage.setTotalPage(CommonPage.getTotalPage(total,pageSize));
+        commonPage.setTotal(total);
+        List<OpeUseFlow> opeUseFlows= this.opeUseFlowDao.getOpeUseFlowSimpleInfoList(params);
+        commonPage.setList(opeUseFlows);
+        return commonPage;
+    }
+
+    @Override
+    public OpeUseFlow getLastUseFlow(String reagentCode) {
+        return this.opeUseFlowDao.getLastUseFlow(reagentCode);
+    }
+
     @Transactional(propagation = Propagation.REQUIRED)
-    public int getOpeUseFlowTotalCountByName(String houseName,String reagentId, String reagentCode,String containerCode, Integer status, String userId,Date startDate,Date endDate) {
+    public int getOpeUseFlowTotalCountByName(String houseName,Long reagentId, String reagentCode,String containerCode, Integer status, Long userId,Date startDate,Date endDate,Integer operatestate) {
         try {
             Map<String, Object> params = new HashMap<String, Object>();
             params.put("reagentName", reagentId);
@@ -225,6 +288,7 @@
                 params.put("endDate",sdfend.format(now));
             }
 
+            params.put("operatestate", operatestate);
             params.put("houseName", houseName);
             params.put("containerCode", containerCode);
             addParamByUserId(userId, params);
@@ -238,8 +302,8 @@
         }
     }
 
-    private void addParamByUserId(String userId, Map<String, Object> params) {
-        if (StringUtils.isNotBlank(userId)) {
+    private void addParamByUserId(Long userId, Map<String, Object> params) {
+        if (userId!=null) {
             SysUser sysUser = sysUserService.getSysUser(userId);
 
 			// 不是管理员时,加入userid
@@ -294,9 +358,9 @@
             //0:个人领用 1:在库 3:报废
             //<!--0:个人领用 1:在仓库sys_warehouse_container 2:在实验室sys_laboratory_container 3:报废-->
             OpeUseFlow opeUseFlow = new OpeUseFlow();
-            opeUseFlow.setId(IDUtils.uuid());
+       //     opeUseFlow.setId(IDUtils.uuid());
             opeUseFlow.setCreateTime(new Timestamp(DateUtils.parseDate(params.get("updateTime").toString(), Constants.TIME_PATTERN_YYYY_MM_DD_HH_MM_SS).getTime()));
-            opeUseFlow.setStatus(ArrivalStatus.parse(Integer.valueOf(String.valueOf(params.get("status")))));
+            opeUseFlow.setStatus(Integer.valueOf(String.valueOf(params.get("status"))));
             opeUseFlow.setReagentCode((String) params.get("reagentCode"));
             if (params.get("idcard") != null) {
                 SysUser sysUser = sysUserService.getSysUserByIdCard((String) params.get("idcard"));
@@ -305,8 +369,8 @@
                     continue;
                 }
                 opeUseFlow.setUserId(sysUser.getId());
-                opeUseFlow.setContainerId("0");
-                opeUseFlow.setHouseId("0");
+                opeUseFlow.setContainerId(0l);
+                opeUseFlow.setHouseId(0l);
             } else {
                 logger.error("The idcard is empty!");
                 continue;
@@ -315,13 +379,13 @@
                 SysWarehouseContainer container = sysWarehouseContainerDao.getSysWarehouseContainerByContainerCode((String) params.get("containerCode"));
                 if (Objects.isNull(container)==false) {
 					if (params.get("status").toString().equals("1")) {
-						opeUseFlow.setStatus(ArrivalStatus.WAREHOUSE);
+						opeUseFlow.setStatus(ArrivalStatus.WAREHOUSE.getKey());
 					} else {
-						opeUseFlow.setStatus(ArrivalStatus.PERSONAL);
+						opeUseFlow.setStatus(ArrivalStatus.PERSONAL.getKey());
 					}
                     opeUseFlow.setContainerId(container.getId());
                     opeUseFlow.setHouseId(container.getWarehouseId());
-                    opeUseFlow.setPlace(container.getStructure());
+                  //  opeUseFlow.setPlace(container.getStructure());
                 }else{
                     SysLaboratoryContainer sysLaboratoryContainer = sysLaboratoryContainerDao.getSysLaboratoryContainerByContainerCode((String) params.get("containerCode"));
                     if (Objects.isNull(sysLaboratoryContainer)) {
@@ -329,13 +393,13 @@
                         continue;
                     }
 					if (params.get("status").toString().equals("1")) {
-						opeUseFlow.setStatus(ArrivalStatus.LABORATORY);
+						opeUseFlow.setStatus(ArrivalStatus.LABORATORY.getKey());
 					} else {
-						opeUseFlow.setStatus(ArrivalStatus.PERSONAL);
+						opeUseFlow.setStatus(ArrivalStatus.PERSONAL.getKey());
 					}
                     opeUseFlow.setContainerId(sysLaboratoryContainer.getId());
                     opeUseFlow.setHouseId(sysLaboratoryContainer.getLaboratoryId());
-                    opeUseFlow.setPlace(sysLaboratoryContainer.getStructure());
+                   // opeUseFlow.setPlace(sysLaboratoryContainer.getStructure());
                 }
  //           }
 
@@ -372,29 +436,28 @@
     }
 
     @Override
-    public void updateReceiptNumber(String code, String receiptNumber) {
-        opeUseFlowDao.updateReceiptNumber(code, receiptNumber);
+    public void updateReceiptNumber(String code, String receiptNumber,String note) {
+        opeUseFlowDao.updateReceiptNumber(code, receiptNumber,note);
     }
 
+    //---------待完善------------20240408
     @Transactional
-    public void updateReceiptNumberByCode(List<OpeApplyReserve> selectedTmpOrderList,String receiptNumber) {
+    public void updateReceiptNumberByCode(List<OpeApplyReserve> selectedTmpOrderList,String receiptNumber,String note) {
 
         for (OpeApplyReserve oar : selectedTmpOrderList) {
-            //根据id或者试剂的条码直接查找 状态表单 查询订单所有的流向
-            List<String> codeTmp = opeReagentStatusService
-                    .generateReagentCode(oar.getStartReagentCode2(), oar.getEndReagentCode2());
-            assert codeTmp.size() > 0;
-
             if (oar.getFlag() == 1) {
                 //库中领取 code存的是 试剂状态的id
-                for (String statusId : codeTmp) {
-                    String code = opeReagentStatusService.getOpeReagentStatus(statusId).getReagentCode();
+                for (String reagentCode : oar.getReagentCodes()) {
+                    String code = opeReagentStatusService.getOpeReagentStatusByCode(reagentCode).getReagentCode();
                     //此时状态为领用待入库
-                    this.updateReceiptNumber(code, receiptNumber);
+                    this.updateReceiptNumber(code, receiptNumber,note);
                 }
             }else{
+                //根据id或者试剂的条码直接查找 状态表单 查询订单所有的流向
+                List<String> codeTmp = opeReagentStatusService
+                        .generateReagentCode(oar.getStartReagentCode2(), oar.getEndReagentCode2());
                 for (String code : codeTmp) {
-                    this.updateReceiptNumber(code, receiptNumber);
+                    this.updateReceiptNumber(code, receiptNumber,note);
                 }
             }
 
@@ -404,13 +467,13 @@
     }
 
     @Override
-    public Map<String, Integer> getRegentInfoFromReceiptNumber(String receiptNumber) {
+    public Map<Long, Integer> getRegentInfoFromReceiptNumber(String receiptNumber) {
         List<Map> maps = opeUseFlowDao.getRegentInfoFromReceiptNumber(receiptNumber);
         if (maps.size() > 0) {
-            Map<String, Integer> printInfo = new HashMap<>();
+            Map<Long, Integer> printInfo = new HashMap<>();
             for (Map map : maps) {
                 Integer count =Integer.parseInt(String.valueOf(map.get("count")));;
-                String reagentId = (String) map.get("reagentId");
+                Long reagentId = Long.valueOf(map.get("reagentId").toString());
                 SysReagent reagent = sysReagentService.getSysReagent(reagentId);
                 printInfo.put(reagent.getId(), count);
             }
@@ -423,32 +486,26 @@
     @Override
     public Map getApplyUserByReagentCode(String reagentCode) {
 
-        Map<String, String> metaMap2 = new HashMap<>();
-        metaMap2.put("groupId", "operate_status");
-        metaMap2.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey()));
-        List<BaseMeta> baseMetaList2 = baseMetaDao.getBaseMetaList(metaMap2);
-        String id = baseMetaList2.get(0).getId();
-        return opeUseFlowDao.getUserIdByReagentCode(reagentCode, id);
+        return opeUseFlowDao.getUserIdByReagentCode(reagentCode, OperateStatus.WAREHOUSEOUT.getKey());
     }
 
+    //---------待完善------------20240408
     @Override
-    public void updateReceiptNumberByCode2(List<OpeWarehouseReserve> selectTmpList, String receiptNumber) {
+    public void updateReceiptNumberByCode2(List<OpeWarehouseReserve> selectTmpList, String receiptNumber,String note) {
         for (OpeWarehouseReserve owr : selectTmpList) {
-            //根据id或者试剂的条码直接查找 状态表单 查询订单所有的流向
-            List<String> codeTmp = opeReagentStatusService
-                    .generateReagentCode(owr.getStartReagentCode2(), owr.getEndReagentCode2());
-            assert codeTmp.size() > 0;
-
             if (owr.getFlag() == 1) {
                 //库中领取 code存的是 试剂状态的id
-                for (String statusId : codeTmp) {
-                    String code = opeReagentStatusService.getOpeReagentStatus(statusId).getReagentCode();
+                for (String statusId : owr.getReagentCodes()) {
+                    String code = opeReagentStatusService.getOpeReagentStatusByCode(statusId).getReagentCode();
                     //此时状态为领用待入库
-                    this.updateReceiptNumber(code, receiptNumber);
+                    this.updateReceiptNumber(code, receiptNumber,note);
                 }
             }else{
+                //根据id或者试剂的条码直接查找 状态表单 查询订单所有的流向
+                List<String> codeTmp = opeReagentStatusService
+                        .generateReagentCode(owr.getStartReagentCode2(), owr.getEndReagentCode2());
                 for (String code : codeTmp) {
-                    this.updateReceiptNumber(code, receiptNumber);
+                    this.updateReceiptNumber(code, receiptNumber,note);
                 }
             }
 
@@ -457,12 +514,38 @@
     }
 
     @Override
-    public int getPersonalUseInfoCount(String reagentCode,String userId, Date startTime, Date endTime, String receiptNumber,
+    public int getPersonalUseInfoCount(String reagentCode,Long userId, Date startDate, Date endDate, String receiptNumber,
                                        String department, String project,String applyPerson,String reagentName) {
         Map<String,Object> params = new HashMap<>();
-        params.put("userId", userId);
-        params.put("startTime", startTime);
-        params.put("endTime", endTime);
+
+        SimpleDateFormat sdfstart = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+        SimpleDateFormat sdfend = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
+        Date now = new Date();
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(now);
+        cal.add(Calendar.DATE, -7);
+        Date startTime = cal.getTime();
+
+        if (null != startDate){
+            try {
+                params.put("startTime",sdfstart.format(startDate));
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        }else {
+            params.put("startTime",sdfstart.format(startTime));
+        }
+
+        if (null != endDate){
+            try {
+                params.put("endTime",sdfend.format(endDate));
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        }else {
+            params.put("endTime",sdfend.format(now));
+        }
+
         params.put("receiptNumber", receiptNumber);
         params.put("department", department);
         params.put("project", project);
@@ -470,39 +553,54 @@
         params.put("applyPerson", applyPerson);
         if (StringUtils.isNotBlank(reagentName)) {
             //根据试剂名获取单号
-
         }
         params.put("reagentName", reagentName);
-        //操作状态位仓库领取
-        Map<String, String> metaMap2 = new HashMap<>();
-        metaMap2.put("groupId", "operate_status");
-        metaMap2.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey()));
-        List<BaseMeta> baseMetas = baseMetaDao.getBaseMetaList(metaMap2);
-        params.put("operatestate", baseMetas.get(0).getId());
+        params.put("operatestate", OperateStatus.WAREHOUSEOUT.getKey());
+        params.put("operatestate1", OperateStatus.TRANSFER.getKey());
 
         addParamByUserId(userId, params);
         return opeUseFlowDao.countPersonalUseInfo(params);
     }
 
     @Override
-    public List<OpeUseFlow> getPersonalUseInfoList(String reagentCode,String userId, Date startTime, Date endTime, String receiptNumber,
+    public List<OpeUseFlow> getPersonalUseInfoList(String reagentCode,Long userId, Date startDate, Date endDate, String receiptNumber,
                                                    String department, String project,String applyPerson,String reagentName, int first, int pageSize) {
         Map<String, Object> params = new HashMap<>();
-        params.put("userId", userId);
-        params.put("startTime", startTime);
-        params.put("endTime", endTime);
+        SimpleDateFormat sdfstart = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+        SimpleDateFormat sdfend = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
+        Date now = new Date();
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(now);
+        cal.add(Calendar.DATE, -7);
+        Date startTime = cal.getTime();
+        if (null != startDate){
+            try {
+                params.put("startTime",sdfstart.format(startDate));
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        }else {
+            params.put("startTime",sdfstart.format(startTime));
+        }
+        if (null != endDate){
+            try {
+                params.put("endTime",sdfend.format(endDate));
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        }else {
+            params.put("endTime",sdfend.format(now));
+        }
         params.put("receiptNumber", receiptNumber);
         params.put("department", department);
         params.put("project", project);
         params.put("reagentCode", reagentCode);
         params.put("applyPerson", applyPerson);
         params.put("reagentName", reagentName);
-        //操作状态位仓库领取
-        Map<String, String> metaMap2 = new HashMap<>();
-        metaMap2.put("groupId", "operate_status");
-        metaMap2.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey()));
-        List<BaseMeta> baseMetas = baseMetaDao.getBaseMetaList(metaMap2);
-        params.put("operatestate", baseMetas.get(0).getId());
+        params.put("operatestate", OperateStatus.WAREHOUSEOUT.getKey());
+
+        params.put("operatestate1", OperateStatus.TRANSFER.getKey());
+
         params.put("first", first);
         params.put("pageSize", pageSize);
 
@@ -513,11 +611,10 @@
     @Override
     public List<PersonUseDetail> getApplyInfo(String receiptNumber) {
         Map<String,Object> params = new HashMap<>();
-        Map<String, String> metaMap2 = new HashMap<>();
-        metaMap2.put("groupId", "operate_status");
-        metaMap2.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey()));
-        List<BaseMeta> baseMetas = baseMetaDao.getBaseMetaList(metaMap2);
-        params.put("operatestate", baseMetas.get(0).getId());
+        params.put("operatestate", OperateStatus.WAREHOUSEOUT.getKey());
+
+        params.put("operatestate1", OperateStatus.TRANSFER.getKey());
+
         params.put("receiptNumber", receiptNumber);
 
         return  opeUseFlowDao.getApplyInfo(params);
@@ -528,11 +625,10 @@
     @Override
     public int getApplyInfoSize(String receiptNumber) {
         Map<String,Object> params = new HashMap<>();
-        Map<String, String> metaMap2 = new HashMap<>();
-        metaMap2.put("groupId", "operate_status");
-        metaMap2.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey()));
-        List<BaseMeta> baseMetas = baseMetaDao.getBaseMetaList(metaMap2);
-        params.put("operatestate", baseMetas.get(0).getId());
+        params.put("operatestate", OperateStatus.WAREHOUSEOUT.getKey());
+
+        params.put("operatestate1", OperateStatus.TRANSFER.getKey());
+
         params.put("receiptNumber", receiptNumber);
 
         return  opeUseFlowDao.getApplyInfoSize(params);
@@ -544,4 +640,175 @@
         return opeUseFlowDao.countOpeUseFlow(opeUseFlow);
     }
 
+    @Override
+    @Transactional
+    public void scrapReagent(Long reagentId,String reagentCode, Long userId) {
+        //1.试剂状态表更新试剂状态为报废
+        OpeReagentStatus status = opeReagentStatusService.getStatus(reagentId, reagentCode);
+        if (status.getStatus() == ArrivalStatus.SCRAP.getKey()) {
+            throw new BusinessException(ExceptionEnumCode.PARAM_ERR,"该试剂已是报废状态,无法进行操作");
+        }
+        //报废
+        status.setStatus(ArrivalStatus.SCRAP.getKey());
+        status.setUserId(userId);
+        opeReagentStatusDao.updateOpeReagentStatusDao(status);
+
+        //2.插入一条报废的流向记录
+        OpeUseFlow useFlow = new OpeUseFlow();
+        useFlow.setOperateState(OperateStatus.SCRAP.getKey());
+        useFlow.setReagentCode(reagentCode);
+        useFlow.setContainerId(status.getContainerId());
+        useFlow.setHouseId(status.getHouseId());
+        useFlow.setUserId(userId);
+        useFlow.setPlace(status.getPlace());
+        useFlow.setRemainder(status.getRemainder());
+        useFlow.setStoreType(status.getStoreType());
+        useFlow.setProjectId(status.getProjectId());
+        useFlow.setArticleNumber(status.getArticleNumber());
+
+        useFlow.setCreateTime(new Timestamp(new Date().getTime()));
+      //  useFlow.setId(IDUtils.uuid());
+        opeUseFlowDao.insertOpeUseFlow(useFlow);
+
+    }
+
+    @Override
+    public OpeUseFlow selectById(String id) {
+        return opeUseFlowDao.selectById(id);
+    }
+
+    @Override
+    public OpeUseFlow selectByReceiptNumber(String receiptNumber,Long userId) {
+
+        Map<String, Object> params = new HashMap<>();
+        params.put("userId", userId);
+        params.put("receiptNumber", receiptNumber);
+        //操作状态位仓库领取
+
+        params.put("operatestate", OperateStatus.WAREHOUSEOUT.getKey());
+
+        params.put("operatestate1", OperateStatus.TRANSFER.getKey());
+
+        addParamByUserId(userId, params);
+
+        return opeUseFlowDao.selectByReceiptNumber(params);
+    }
+
+    @Override
+    public List<Map> selectAll(String houseName, Long reagentId, String reagentCode, String containerCode, Long userId, Date startDate, Date endDate) {
+        try {
+            Map<String, Object> params = new HashMap<String, Object>();
+
+            params.put("reagentName", reagentId);
+            if (StringUtils.isNotBlank(reagentCode)) {
+                params.put("reagentCode", "%" + reagentCode + "%");
+            }
+            SimpleDateFormat sdfstart = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+            SimpleDateFormat sdfend = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
+            Date now = new Date();
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(now);
+            cal.add(Calendar.DATE, -7);
+            Date startTime = cal.getTime();
+
+            if (null != startDate){
+                try {
+                    params.put("startDate",sdfstart.format(startDate));
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }else {
+                params.put("startDate",sdfstart.format(startTime));
+            }
+            if (null != endDate){
+                try {
+                    params.put("endDate",sdfend.format(endDate));
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }else {
+                params.put("endDate",sdfend.format(now));
+            }
+            params.put("houseName", houseName);
+            params.put("containerCode", containerCode);
+            addParamByUserId(userId, params);
+            return opeUseFlowDao.selectAll(params);
+        } catch (DataAccessException e) {
+            logger.error(e.getMessage(), e);
+            throw new BusinessException(ExceptionEnumCode.DB_ERR,
+                    MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
+        }
+    }
+
+    @Override
+    public boolean export2Excel(List<Map> list) throws Exception {
+        Map<String,String> map = new LinkedHashMap<>();
+        map.put("reagentCode", "试剂条形码");
+        map.put("reagentName", "试剂名称");
+        map.put("laboratoryContainerCode", "柜号");
+        map.put("operatestateName", "操作状态");
+        map.put("remainder", "残存量");
+        map.put("userName", "持有者");
+        map.put("createTime", "更新时间");
+        map.put("warehouseContainerName", "场所名");
+        ExcelUtils.export2Excel(list,"试剂流向追踪列表",map);
+        return true;
+    }
+
+
+    /**
+     * @Description: 查询导出
+     */
+    @Override
+    public List<Map> selectExportDetail(String reagentCode, Long userId, Date startTime, Date endTime, String receiptNumber, String department, String project, String applyPerson, String reagentName) {
+        Map<String, Object> params = new HashMap<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        if (startTime != null) {
+            params.put("startTime", sdf.format(startTime) +" 00:00:00");
+        }
+
+        if (endTime != null) {
+            params.put("endTime", sdf.format(endTime) + " 23:59:59");
+        }
+
+        params.put("reagentCode", reagentCode);
+
+        params.put("endTime", endTime);
+        params.put("receiptNumber", receiptNumber);
+        params.put("department", department);
+        params.put("project", project);
+        params.put("applyPerson", applyPerson);
+        params.put("reagentName", reagentName);
+        params.put("groupId", "operate_status");
+
+        params.put("operatestate", OperateStatus.WAREHOUSEOUT.getKey());
+
+        params.put("operatestate1", OperateStatus.TRANSFER.getKey());
+        addParamByUserId(userId, params);
+        return opeUseFlowDao.selectDetail(params);
+    }
+
+    @Override
+    public boolean export22Excel(List<Map> list) throws Exception {
+        Map<String,String> map = new LinkedHashMap<>();
+        map.put("productSn", "产品编号");
+        map.put("reagentName", "试剂名称");
+        map.put("reagentCode", "试剂条形码");
+        map.put("controlProducts", "管制品");
+        map.put("reagentFormat", "规格型号");
+        map.put("perInfo", "包装");
+        map.put("productHome", "厂家");
+        map.put("articleNumber", "批号");
+        map.put("username", "申领人");
+        map.put("projectName", "课题组");
+        map.put("department", "部门");
+        map.put("location", "地点");
+        map.put("createTime", "领用时间");
+        ExcelUtils.export2Excel(list,"试剂领用记录表",map);
+        return true;
+    }
+
+
+
+
 }

--
Gitblit v1.9.2