From fed6bd0fb7454b63ba86af781521442568da4910 Mon Sep 17 00:00:00 2001 From: qiankunpingtai Date: Fri, 19 Apr 2019 14:50:00 +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=A4=9A=E5=8D=95=E4=BD=8D=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 --- .../jsh/erp/service/unit/UnitComponent.java | 18 +-- .../com/jsh/erp/service/unit/UnitService.java | 144 +++++++++++++++--- 2 files changed, 128 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/jsh/erp/service/unit/UnitComponent.java b/src/main/java/com/jsh/erp/service/unit/UnitComponent.java index 9241190e..98a66249 100644 --- a/src/main/java/com/jsh/erp/service/unit/UnitComponent.java +++ b/src/main/java/com/jsh/erp/service/unit/UnitComponent.java @@ -20,16 +20,16 @@ public class UnitComponent implements ICommonQuery { private UnitService unitService; @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 getUnitList(map); } - private List getUnitList(Map map) { + private List getUnitList(Map map)throws Exception { String search = map.get(Constants.SEARCH); String name = StringUtil.getInfo(search, "name"); String order = QueryUtils.order(map); @@ -37,34 +37,34 @@ public class UnitComponent implements ICommonQuery { } @Override - public Long counts(Map map) { + public Long counts(Map map)throws Exception { String search = map.get(Constants.SEARCH); String name = StringUtil.getInfo(search, "name"); return unitService.countUnit(name); } @Override - public int insert(String beanJson, HttpServletRequest request) { + public int insert(String beanJson, HttpServletRequest request)throws Exception { return unitService.insertUnit(beanJson, request); } @Override - public int update(String beanJson, Long id) { + public int update(String beanJson, Long id)throws Exception { return unitService.updateUnit(beanJson, id); } @Override - public int delete(Long id) { + public int delete(Long id)throws Exception { return unitService.deleteUnit(id); } @Override - public int batchDelete(String ids) { + public int batchDelete(String ids)throws Exception { return unitService.batchDeleteUnit(ids); } @Override - public int checkIsNameExist(Long id, String name) { + public int checkIsNameExist(Long id, String name)throws Exception { return unitService.checkIsNameExist(id, name); } diff --git a/src/main/java/com/jsh/erp/service/unit/UnitService.java b/src/main/java/com/jsh/erp/service/unit/UnitService.java index 48d12907..8c160e96 100644 --- a/src/main/java/com/jsh/erp/service/unit/UnitService.java +++ b/src/main/java/com/jsh/erp/service/unit/UnitService.java @@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.jsh.erp.constants.BusinessConstants; import com.jsh.erp.constants.ExceptionConstants; -import com.jsh.erp.datasource.entities.Material; -import com.jsh.erp.datasource.entities.Unit; -import com.jsh.erp.datasource.entities.UnitExample; -import com.jsh.erp.datasource.entities.User; +import com.jsh.erp.datasource.entities.*; import com.jsh.erp.datasource.mappers.MaterialMapperEx; import com.jsh.erp.datasource.mappers.UnitMapper; import com.jsh.erp.datasource.mappers.UnitMapperEx; @@ -43,55 +40,135 @@ public class UnitService { @Resource private MaterialMapperEx materialMapperEx; - public Unit getUnit(long id) { - return unitMapper.selectByPrimaryKey(id); + public Unit getUnit(long id)throws Exception { + Unit result=null; + try{ + result=unitMapper.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 getUnit() { + public List getUnit()throws Exception { UnitExample example = new UnitExample(); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - return unitMapper.selectByExample(example); + List list=null; + try{ + list=unitMapper.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 name, int offset, int rows) { - return unitMapperEx.selectByConditionUnit(name, offset, rows); + public List select(String name, int offset, int rows)throws Exception { + List list=null; + try{ + list=unitMapperEx.selectByConditionUnit(name, 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 countUnit(String name) { - return unitMapperEx.countsByUnit(name); + public Long countUnit(String name)throws Exception { + Long result=null; + try{ + result=unitMapperEx.countsByUnit(name); + }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 insertUnit(String beanJson, HttpServletRequest request) { + public int insertUnit(String beanJson, HttpServletRequest request)throws Exception { Unit unit = JSONObject.parseObject(beanJson, Unit.class); - return unitMapper.insertSelective(unit); + int result=0; + try{ + result=unitMapper.insertSelective(unit); + }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 updateUnit(String beanJson, Long id) { + public int updateUnit(String beanJson, Long id)throws Exception { Unit unit = JSONObject.parseObject(beanJson, Unit.class); unit.setId(id); - return unitMapper.updateByPrimaryKeySelective(unit); + int result=0; + try{ + result=unitMapper.updateByPrimaryKeySelective(unit); + }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 deleteUnit(Long id) { - return unitMapper.deleteByPrimaryKey(id); + public int deleteUnit(Long id)throws Exception { + int result=0; + try{ + result=unitMapper.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 batchDeleteUnit(String ids) { + public int batchDeleteUnit(String ids) throws Exception{ List idList = StringUtil.strToLongList(ids); UnitExample example = new UnitExample(); example.createCriteria().andIdIn(idList); - return unitMapper.deleteByExample(example); + int result=0; + try{ + result=unitMapper.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 name) { + public int checkIsNameExist(Long id, String name)throws Exception { UnitExample example = new UnitExample(); example.createCriteria().andIdNotEqualTo(id).andUnameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = unitMapper.selectByExample(example); - return list.size(); + List list=null; + try{ + list=unitMapper.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 batchDeleteUnitByIds(String ids)throws Exception { @@ -100,7 +177,16 @@ public class UnitService { ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); User userInfo=userService.getCurrentUser(); String [] idArray=ids.split(","); - return unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); + int result=0; + try{ + result=unitMapperEx.batchDeleteUnitByIds(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; } /** @@ -127,7 +213,15 @@ public class UnitService { /** * 校验产品表 jsh_material * */ - List materialList=materialMapperEx.getMaterialListByUnitIds(idArray); + List materialList=null; + try{ + materialList=materialMapperEx.getMaterialListByUnitIds(idArray); + }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(materialList!=null&&materialList.size()>0){ logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]", ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);