From aacbbe3aa5dbd1299548bf65edf499086a7fbf89 Mon Sep 17 00:00:00 2001 From: qiankunpingtai Date: Fri, 19 Apr 2019 11:36:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=B0=81=E8=A3=85=E4=B9=8B?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8F=B7=E4=BF=A1=E6=81=AF=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serialNumber/SerialNumberComponent.java | 16 +- .../serialNumber/SerialNumberService.java | 270 +++++++++++++++--- 2 files changed, 234 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberComponent.java b/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberComponent.java index 7bf04d5e..7cc89dde 100644 --- a/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberComponent.java +++ b/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberComponent.java @@ -26,16 +26,16 @@ public class SerialNumberComponent implements ICommonQuery { private SerialNumberService serialNumberService; @Override - public Object selectOne(String condition) { + public Object selectOne(String condition)throws Exception { return null; } @Override - public List select(Map map) { + public List select(Map map)throws Exception { return getSerialNumberList(map); } - private List getSerialNumberList(Map map) { + private List getSerialNumberList(Map map) throws Exception{ String search = map.get(Constants.SEARCH); String serialNumber = StringUtil.getInfo(search, "serialNumber"); String materialName = StringUtil.getInfo(search, "materialName"); @@ -43,7 +43,7 @@ public class SerialNumberComponent implements ICommonQuery { } @Override - public Long counts(Map map) { + public Long counts(Map map)throws Exception { String search = map.get(Constants.SEARCH); String serialNumber = StringUtil.getInfo(search, "serialNumber"); String materialName = StringUtil.getInfo(search, "materialName"); @@ -56,22 +56,22 @@ public class SerialNumberComponent implements ICommonQuery { } @Override - public int update(String beanJson, Long id) { + public int update(String beanJson, Long id)throws Exception { return serialNumberService.updateSerialNumber(beanJson, id); } @Override - public int delete(Long id) { + public int delete(Long id)throws Exception { return serialNumberService.deleteSerialNumber(id); } @Override - public int batchDelete(String ids) { + public int batchDelete(String ids)throws Exception { return serialNumberService.batchDeleteSerialNumber(ids); } @Override - public int checkIsNameExist(Long id, String serialNumber) { + public int checkIsNameExist(Long id, String serialNumber) throws Exception{ return serialNumberService.checkIsNameExist(id, serialNumber); } } diff --git a/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberService.java b/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberService.java index 2bfcf2b6..498ce83c 100644 --- a/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberService.java +++ b/src/main/java/com/jsh/erp/service/serialNumber/SerialNumberService.java @@ -32,7 +32,7 @@ import java.util.List; */ @Service public class SerialNumberService { - private Logger logger = LoggerFactory.getLogger(MaterialService.class); + private Logger logger = LoggerFactory.getLogger(SerialNumberService.class); @Resource private SerialNumberMapper serialNumberMapper; @@ -48,84 +48,190 @@ public class SerialNumberService { private LogService logService; - public SerialNumber getSerialNumber(long id) { - return serialNumberMapper.selectByPrimaryKey(id); + public SerialNumber getSerialNumber(long id)throws Exception { + SerialNumber result=null; + try{ + result=serialNumberMapper.selectByPrimaryKey(id); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } + return result; } - public List getSerialNumber() { + public List getSerialNumber()throws Exception { SerialNumberExample example = new SerialNumberExample(); - return serialNumberMapper.selectByExample(example); + List list=null; + try{ + list=serialNumberMapper.selectByExample(example); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } + return list; } - public List select(String serialNumber, String materialName, Integer offset, Integer rows) { - return serialNumberMapperEx.selectByConditionSerialNumber(serialNumber, materialName,offset, rows); + public List select(String serialNumber, String materialName, Integer offset, Integer rows)throws Exception { + List list=null; + try{ + list=serialNumberMapperEx.selectByConditionSerialNumber(serialNumber, materialName,offset, rows); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } + return list; } - public Long countSerialNumber(String serialNumber,String materialName) { - return serialNumberMapperEx.countSerialNumber(serialNumber, materialName); + public Long countSerialNumber(String serialNumber,String materialName)throws Exception { + Long result=null; + try{ + result=serialNumberMapperEx.countSerialNumber(serialNumber, materialName); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } + return result; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int insertSerialNumber(String beanJson, HttpServletRequest request)throws Exception { SerialNumber serialNumber = JSONObject.parseObject(beanJson, SerialNumber.class); logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SERIAL_NUMBER, BusinessConstants.LOG_OPERATION_TYPE_ADD, request); - return serialNumberMapper.insertSelective(serialNumber); + int result=0; + try{ + result=serialNumberMapper.insertSelective(serialNumber); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int updateSerialNumber(String beanJson, Long id) { + public int updateSerialNumber(String beanJson, Long id) throws Exception{ SerialNumber serialNumber = JSONObject.parseObject(beanJson, SerialNumber.class); serialNumber.setId(id); - int res = serialNumberMapper.updateByPrimaryKeySelective(serialNumber); - return res; + int result=0; + try{ + result=serialNumberMapper.updateByPrimaryKeySelective(serialNumber); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int deleteSerialNumber(Long id) { - return serialNumberMapper.deleteByPrimaryKey(id); + public int deleteSerialNumber(Long id)throws Exception { + int result=0; + try{ + result=serialNumberMapper.deleteByPrimaryKey(id); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int batchDeleteSerialNumber(String ids) { + public int batchDeleteSerialNumber(String ids)throws Exception { List idList = StringUtil.strToLongList(ids); SerialNumberExample example = new SerialNumberExample(); example.createCriteria().andIdIn(idList); - return serialNumberMapper.deleteByExample(example); + int result=0; + try{ + result=serialNumberMapper.deleteByExample(example); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } - public int checkIsNameExist(Long id, String serialNumber) { + public int checkIsNameExist(Long id, String serialNumber)throws Exception { SerialNumberExample example = new SerialNumberExample(); example.createCriteria().andIdNotEqualTo(id).andSerialNumberEqualTo(serialNumber).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = serialNumberMapper.selectByExample(example); - return list.size(); + List list=null; + try{ + list=serialNumberMapper.selectByExample(example); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } + return list==null?0:list.size(); } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int batchSetEnable(Boolean enabled, String materialIDs) { + public int batchSetEnable(Boolean enabled, String materialIDs)throws Exception{ List ids = StringUtil.strToLongList(materialIDs); SerialNumber serialNumber = new SerialNumber(); SerialNumberExample example = new SerialNumberExample(); example.createCriteria().andIdIn(ids); - return serialNumberMapper.updateByExampleSelective(serialNumber, example); + int result=0; + try{ + result=serialNumberMapper.updateByExampleSelective(serialNumber, example); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } - public List findById(Long id){ - return serialNumberMapperEx.findById(id); + public List findById(Long id)throws Exception{ + List list=null; + try{ + list=serialNumberMapperEx.findById(id); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } + return list; } - public void checkIsExist(Long id, String materialName, String serialNumber) { + public void checkIsExist(Long id, String materialName, String serialNumber) throws Exception{ /** * 商品名称不为空时,检查商品名称是否存在 * */ if(StringUtil.isNotEmpty(materialName)){ - List mlist = materialMapperEx.findByMaterialName(materialName); + List mlist=null; + try{ + mlist = materialMapperEx.findByMaterialName(materialName); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } + if(mlist==null||mlist.size()<1){ //商品名称不存在 throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_EXISTS_CODE, @@ -140,7 +246,15 @@ public class SerialNumberService { /*** * 判断序列号是否已存在 * */ - List list = serialNumberMapperEx.findBySerialNumber(serialNumber); + List list=null; + try{ + list = serialNumberMapperEx.findBySerialNumber(serialNumber); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } if(list!=null&&list.size()>0){ if(list.size()>1){ //存在多个同名序列号 @@ -187,8 +301,16 @@ public class SerialNumberService { User userInfo=userService.getCurrentUser(); serialNumberEx.setCreator(userInfo==null?null:userInfo.getId()); serialNumberEx.setUpdater(userInfo==null?null:userInfo.getId()); - int result=serialNumberMapperEx.addSerialNumber(serialNumberEx); - if(result==1){ + int result=0; + try{ + result = serialNumberMapperEx.addSerialNumber(serialNumberEx); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + if(result>0){ return serialNumberEx; } return null; @@ -207,8 +329,16 @@ public class SerialNumberService { serialNumberEx.setUpdateTime(date); User userInfo=userService.getCurrentUser(); serialNumberEx.setUpdater(userInfo==null?null:userInfo.getId()); - int result = serialNumberMapperEx.updateSerialNumber(serialNumberEx); - if(result==1){ + int result=0; + try{ + result = serialNumberMapperEx.updateSerialNumber(serialNumberEx); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + if(result>0){ return serialNumberEx; } return null; @@ -221,9 +351,17 @@ public class SerialNumberService { * @Param: materialName * @return Long 满足使用条件的商品的id */ - public Long checkMaterialName(String materialName){ + public Long checkMaterialName(String materialName)throws Exception{ if(StringUtil.isNotEmpty(materialName)) { - List mlist = materialMapperEx.findByMaterialName(materialName); + List mlist=null; + try{ + mlist = materialMapperEx.findByMaterialName(materialName); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); + } if (mlist == null || mlist.size() < 1) { //商品名称不存在 throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_EXISTS_CODE, @@ -258,7 +396,7 @@ public class SerialNumberService { * @Param: materialName * @return Long 满足使用条件的商品的id */ - public Long getSerialNumberMaterialIdByMaterialName(String materialName){ + public Long getSerialNumberMaterialIdByMaterialName(String materialName)throws Exception{ if(StringUtil.isNotEmpty(materialName)){ //计算商品库存和目前占用的可用序列号数量关系 //库存=入库-出库 @@ -290,14 +428,22 @@ public class SerialNumberService { public void checkAndUpdateSerialNumber(DepotItem depotItem,User userInfo) throws Exception{ if(depotItem!=null){ //查询商品下已分配的可用序列号数量 - int SerialNumberSum= serialNumberMapperEx.countSerialNumberByMaterialIdAndDepotheadId(depotItem.getMaterialid(),null,BusinessConstants.IS_SELL_HOLD); - //BasicNumber=OperNumber*ratio - if((depotItem.getBasicnumber()==null?0:depotItem.getBasicnumber()).intValue()>SerialNumberSum){ - //获取商品名称 - Material material= materialMapper.selectByPrimaryKey(depotItem.getMaterialid()); - throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_CODE, - String.format(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_MSG,material==null?"":material.getName())); + try{ + int SerialNumberSum= serialNumberMapperEx.countSerialNumberByMaterialIdAndDepotheadId(depotItem.getMaterialid(),null,BusinessConstants.IS_SELL_HOLD); + //BasicNumber=OperNumber*ratio + if((depotItem.getBasicnumber()==null?0:depotItem.getBasicnumber()).intValue()>SerialNumberSum){ + //获取商品名称 + Material material= materialMapper.selectByPrimaryKey(depotItem.getMaterialid()); + throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_CODE, + String.format(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_MSG,material==null?"":material.getName())); + } + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, + ExceptionConstants.DATA_READ_FAIL_MSG); } + //商品下序列号充足,分配序列号 sellSerialNumber(depotItem.getMaterialid(),depotItem.getHeaderid(),(depotItem.getBasicnumber()==null?0:depotItem.getBasicnumber()).intValue(),userInfo); } @@ -320,7 +466,16 @@ public class SerialNumberService { */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int sellSerialNumber(Long materialId, Long depotheadId,int count,User user) throws Exception{ - return serialNumberMapperEx.sellSerialNumber(materialId,depotheadId,count,new Date(),user==null?null:user.getId()); + int result=0; + try{ + result = serialNumberMapperEx.sellSerialNumber(materialId,depotheadId,count,new Date(),user==null?null:user.getId()); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } /** @@ -336,7 +491,16 @@ public class SerialNumberService { */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int cancelSerialNumber(Long materialId, Long depotheadId,int count,User user) throws Exception{ - return serialNumberMapperEx.cancelSerialNumber(materialId,depotheadId,count,new Date(),user==null?null:user.getId()); + int result=0; + try{ + result = serialNumberMapperEx.cancelSerialNumber(materialId,depotheadId,count,new Date(),user==null?null:user.getId()); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } /** @@ -386,6 +550,15 @@ public class SerialNumberService { each.setSerialNumber(new StringBuffer(prefixBuf.toString()).append(insertNum).toString()); list.add(each); } + int result=0; + try{ + result = serialNumberMapperEx.batAddSerialNumber(list); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } serialNumberMapperEx.batAddSerialNumber(list); batAddTotal -= BusinessConstants.BATCH_INSERT_MAX_NUMBER; }while(batAddTotal>0); @@ -407,7 +580,16 @@ public class SerialNumberService { ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); User userInfo=userService.getCurrentUser(); String [] idArray=ids.split(","); - return serialNumberMapperEx.batchDeleteSerialNumberByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); + int result=0; + try{ + result = serialNumberMapperEx.batchDeleteSerialNumberByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); + }catch(Exception e){ + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); + throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE, + ExceptionConstants.DATA_WRITE_FAIL_MSG); + } + return result; } }