| | |
| | | package com.nanometer.smartlab.service; |
| | | |
| | | import java.util.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.google.common.collect.ImmutableBiMap; |
| | | import com.nanometer.smartlab.entity.*; |
| | | import com.nanometer.smartlab.entity.enumtype.ArrivalStatus; |
| | | import com.nanometer.smartlab.dao.SysLaboratoryContainerDao; |
| | | import com.nanometer.smartlab.entity.SysLaboratory; |
| | | import com.nanometer.smartlab.entity.SysLaboratoryContainer; |
| | | 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.model.CommonPage; |
| | | import com.nanometer.smartlab.util.ExcelUtils; |
| | | 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.springframework.dao.DataAccessException; |
| | |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.nanometer.smartlab.dao.SysLaboratoryContainerDao; |
| | | 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 javax.annotation.Resource; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by cmower on 17/11/20. |
| | |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public List<SysLaboratoryContainer> getSysLaboratoryContainerList(String laboratoryType, String laboratoryName, |
| | | String laboratoryId,String project,String controllerName, Integer first, Integer pageSize) { |
| | | Long laboratoryId,String project, Integer first, Integer pageSize) { |
| | | try { |
| | | Map<String, Object> params = new HashMap<String, Object>(); |
| | | if (StringUtils.isNotBlank(laboratoryType)) { |
| | |
| | | if (StringUtils.isNotBlank(laboratoryName)) { |
| | | params.put("laboratoryName", "%" + laboratoryName + "%"); |
| | | } |
| | | if (StringUtils.isNotBlank(laboratoryId)) { |
| | | if (laboratoryId!=null) { |
| | | params.put("laboratoryId", laboratoryId); |
| | | } |
| | | params.put("project", project); |
| | | params.put("controllerName", controllerName); |
| | | params.put("first", first); |
| | | params.put("pageSize", pageSize); |
| | | return this.sysLaboratoryContainerDao.getSysLaboratoryContainerList(params); |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public List<SysLaboratoryContainer> getSysLaboratoryContainerList( |
| | | String laboratoryId) { |
| | | return getSysLaboratoryContainerList(null,null,laboratoryId,null,null,null,null); |
| | | @Override |
| | | public CommonPage<SysLaboratoryContainer> getSysLaboratoryContainerList(Integer pageNum, Integer pageSize, String name, String controllerName) { |
| | | if(pageNum==null||pageNum<1){ |
| | | pageNum=1; |
| | | } |
| | | if(pageSize==null||pageSize<1){ |
| | | pageSize=10; |
| | | } |
| | | if(pageSize>50){ |
| | | pageSize=50; |
| | | } |
| | | Map<String, Object> params = new HashMap<>(); |
| | | if (StringUtils.isNotBlank(name)) { |
| | | params.put("laboratoryName","%" + name+ "%"); |
| | | } |
| | | if (StringUtils.isNotBlank(controllerName)) { |
| | | params.put("controllerName", "%" + controllerName + "%"); |
| | | } |
| | | params.put("first", (pageNum-1)*pageSize); |
| | | params.put("pageSize", pageSize); |
| | | CommonPage commonPage=new CommonPage(); |
| | | commonPage.setPageNum(pageNum); |
| | | commonPage.setPageSize(pageSize); |
| | | Long total=new Long(sysLaboratoryContainerDao.getSysLaboratoryContainerTotalCount(params)); |
| | | commonPage.setTotal(total); |
| | | commonPage.setTotalPage(CommonPage.getTotalPage(total,pageSize)); |
| | | List<SysLaboratoryContainer> sysReagents=sysLaboratoryContainerDao.getSysLaboratoryContainerSimpleInfoList(params); |
| | | commonPage.setList(sysReagents); |
| | | return commonPage; |
| | | |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public int getSysLaboratoryContainerTotalCount(String laboratoryType, String laboratoryName, String laboratoryId,String project,String controllerName) { |
| | | public List<SysLaboratoryContainer> getSysLaboratoryContainerList( |
| | | Long laboratoryId) { |
| | | return getSysLaboratoryContainerList(null,null,laboratoryId,null,null,null); |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public int getSysLaboratoryContainerTotalCount(String laboratoryType, String laboratoryName, Long laboratoryId,String project) { |
| | | try { |
| | | Map<String, Object> params = new HashMap<String, Object>(); |
| | | if (StringUtils.isNotBlank(laboratoryType)) { |
| | |
| | | if (StringUtils.isNotBlank(laboratoryName)) { |
| | | params.put("laboratoryName", "%" + laboratoryName + "%"); |
| | | } |
| | | if (StringUtils.isNotBlank(laboratoryId)) { |
| | | if (laboratoryId!=null) { |
| | | params.put("laboratoryId", laboratoryId); |
| | | } |
| | | params.put("project", project); |
| | | params.put("controllerName", controllerName); |
| | | return this.sysLaboratoryContainerDao.getSysLaboratoryContainerTotalCount(params); |
| | | } catch (DataAccessException e) { |
| | | logger.error(e.getMessage(), e); |
| | |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public SysLaboratoryContainer getSysLaboratoryContainer(String id) { |
| | | public SysLaboratoryContainer getSysLaboratoryContainer(Long id) { |
| | | try { |
| | | return this.sysLaboratoryContainerDao.getSysLaboratoryContainer(id); |
| | | } catch (DataAccessException e) { |
| | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public SysLaboratoryContainer insertSysLaboratoryContainer(SysLaboratoryContainer sysLaboratoryContainer) { |
| | | try { |
| | | if (sysLaboratoryContainer.getId() == null) { |
| | | sysLaboratoryContainer.setId(IDUtils.uuid()); |
| | | } |
| | | // if (sysLaboratoryContainer.getId() == null) { |
| | | // sysLaboratoryContainer.setId(IDUtils.uuid()); |
| | | // } |
| | | this.sysLaboratoryContainerDao.insertSysLaboratoryContainer(sysLaboratoryContainer); |
| | | this.sysLaboratoryContainerDao.updateSLContainerUser(sysLaboratoryContainer); |
| | | return sysLaboratoryContainer; |
| | |
| | | return false; |
| | | } |
| | | |
| | | List<String> ids = new ArrayList<String>(); |
| | | List<Long> ids = new ArrayList<Long>(); |
| | | for (SysLaboratoryContainer sysLaboratoryContainer : sysLaboratoryContainerList) { |
| | | ids.add(sysLaboratoryContainer.getId()); |
| | | this.sysLaboratoryContainerDao.updateSLContainerUser(sysLaboratoryContainer); |
| | |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public boolean isSysLaboratoryContainerExist(String containerCode, String editId) { |
| | | public boolean isSysLaboratoryContainerExist(String containerCode, Long editId) { |
| | | try { |
| | | Map<String, Object> params = new HashMap<String, Object>(); |
| | | params.put("containerCode", containerCode); |
| | | params.put("editId", editId); |
| | | |
| | | int count = this.sysLaboratoryContainerDao.getSysLaboratoryContainerTotalCount(params); |
| | | int count = this.sysLaboratoryContainerDao.getSysLaboratoryContainerExist(params); |
| | | return count > 0; |
| | | } catch (DataAccessException e) { |
| | | logger.error(e.getMessage(), e); |
| | |
| | | container.setId(containermpl.getId()); |
| | | this.sysLaboratoryContainerDao.updateSysLaboratoryContainer(container); |
| | | }else{ |
| | | if (containermpl == null) { |
| | | container.setId(IDUtils.uuid()); |
| | | } |
| | | // if (containermpl == null) { |
| | | // container.setId(IDUtils.uuid()); |
| | | // } |
| | | this.sysLaboratoryContainerDao.insertSysLaboratoryContainer(container); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public void updateInfo(Float temp,Float humidity,Float voc1,String containerId,String flag) { |
| | | public void updateInfo(Float temp,Float humidity,Float voc1,Long containerId,String flag) { |
| | | try { |
| | | Map<String, Object> params = new HashMap<String, Object>(); |
| | | params.put("temp", temp); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map> exportExcelList(String laboratoryType, String laboratoryName) { |
| | | public List<Map> exportExcelList(String laboratoryType, String laboratoryName,String project,String controllerName) { |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("type", laboratoryType); |
| | | params.put("name", laboratoryName); |
| | | params.put("project", project); |
| | | params.put("controllerName", controllerName); |
| | | return sysLaboratoryContainerDao.exportExcelList(params); |
| | | } |
| | | |
| | |
| | | map.put("infoCode", "临时存储库状态码"); |
| | | map.put("structure", "临时存储库结构"); |
| | | map.put("name", "临时存储库名称"); |
| | | map.put("project", "课题组"); |
| | | ExcelUtils.export2Excel(list,"实验室临时存储库管理",map); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectProjectsByContainerCode(String containerCode) { |
| | | String projects = sysLaboratoryContainerDao.selectProjectsByContainerCode(containerCode); |
| | | if (projects != null){ |
| | | return Arrays.asList(projects.split(",")); |
| | | List<String> projects = sysLaboratoryContainerDao.selectProjectsByContainerCode(containerCode); |
| | | if (projects.size() > 0){ |
| | | List<String> projectList = new ArrayList<>(); |
| | | for (String project : projects){ |
| | | if (StringUtils.isNotBlank(project)){ |
| | | projectList.addAll(Arrays.asList(project.split(","))); |
| | | } |
| | | } |
| | | return projectList; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public boolean delBySlcIds(List<SysLaboratory> sysLaboratoryList) { |
| | | try { |
| | | if (sysLaboratoryList == null || sysLaboratoryList.size() == 0) { |
| | | return false; |
| | | } |
| | | |
| | | List<Long> ids = new ArrayList<Long>(); |
| | | for (SysLaboratory sysLaboratory : sysLaboratoryList) { |
| | | ids.add(sysLaboratory.getId()); |
| | | } |
| | | |
| | | int row = this.sysLaboratoryContainerDao.delSlcIds(ids); |
| | | return row != 0; |
| | | } 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); |
| | | } |
| | | } |
| | | |
| | | } |