From ff9a0de5aca0e9cac4883cea7bec4715c643f470 Mon Sep 17 00:00:00 2001 From: qiankunpingtai Date: Thu, 18 Apr 2019 21:48:22 +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=95=86=E5=93=81=E4=BF=A1=E6=81=AF=E5=90=8E=E5=8F=B0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erp/controller/MaterialController.java | 14 +- .../service/material/MaterialComponent.java | 18 +- .../erp/service/material/MaterialService.java | 253 +++++++++++++++--- 3 files changed, 227 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/jsh/erp/controller/MaterialController.java b/src/main/java/com/jsh/erp/controller/MaterialController.java index ea3cebd4..4bf35c6b 100644 --- a/src/main/java/com/jsh/erp/controller/MaterialController.java +++ b/src/main/java/com/jsh/erp/controller/MaterialController.java @@ -46,7 +46,7 @@ public class MaterialController { @RequestParam("standard") String standard, @RequestParam("mfrs") String mfrs, @RequestParam("otherField1") String otherField1, @RequestParam("otherField2") String otherField2, @RequestParam("otherField3") String otherField3, @RequestParam("unit") String unit,@RequestParam("unitId") Long unitId, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { Map objectMap = new HashMap(); int exist = materialService.checkIsExist(id, name, model, color, standard, mfrs, otherField1, otherField2, otherField3, unit, unitId); @@ -85,7 +85,7 @@ public class MaterialController { * @return */ @GetMapping(value = "/findById") - public BaseResponseInfo findById(@RequestParam("id") Long id, HttpServletRequest request) { + public BaseResponseInfo findById(@RequestParam("id") Long id, HttpServletRequest request) throws Exception{ BaseResponseInfo res = new BaseResponseInfo(); try { List list = materialService.findById(id); @@ -106,7 +106,7 @@ public class MaterialController { * @return */ @GetMapping(value = "/findBySelect") - public JSONArray findBySelect(@RequestParam("mpList") String mpList, HttpServletRequest request) { + public JSONArray findBySelect(@RequestParam("mpList") String mpList, HttpServletRequest request) throws Exception{ JSONArray dataArray = new JSONArray(); try { List dataList = materialService.findBySelect(); @@ -163,7 +163,7 @@ public class MaterialController { * @return */ @GetMapping(value = "/findByOrder") - public BaseResponseInfo findByOrder(HttpServletRequest request) { + public BaseResponseInfo findByOrder(HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); try { @@ -203,7 +203,7 @@ public class MaterialController { @RequestParam("model") String model, @RequestParam("categoryId") Long categoryId, @RequestParam("categoryIds") String categoryIds, - HttpServletRequest request, HttpServletResponse response) { + HttpServletRequest request, HttpServletResponse response)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); String message = "成功"; @@ -303,7 +303,7 @@ public class MaterialController { response.sendRedirect("../pages/materials/material.html"); } - public BigDecimal parseBigDecimalEx(String str){ + public BigDecimal parseBigDecimalEx(String str)throws Exception{ if(!StringUtil.isEmpty(str)) { return new BigDecimal(str); } else { @@ -313,7 +313,7 @@ public class MaterialController { @RequestMapping(value = "/getMaterialEnableSerialNumberList") public String getMaterialEnableSerialNumberList(@RequestParam(value = Constants.PAGE_SIZE, required = false) Integer pageSize, @RequestParam(value = Constants.CURRENT_PAGE, required = false) Integer currentPage, - @RequestParam(value = Constants.SEARCH, required = false) String search) { + @RequestParam(value = Constants.SEARCH, required = false) String search)throws Exception { Map parameterMap = new HashMap(); //查询参数 JSONObject obj=JSON.parseObject(search); diff --git a/src/main/java/com/jsh/erp/service/material/MaterialComponent.java b/src/main/java/com/jsh/erp/service/material/MaterialComponent.java index 9e0021c5..7b2ca3d2 100644 --- a/src/main/java/com/jsh/erp/service/material/MaterialComponent.java +++ b/src/main/java/com/jsh/erp/service/material/MaterialComponent.java @@ -21,16 +21,16 @@ public class MaterialComponent implements ICommonQuery { private MaterialService materialService; @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 getMaterialList(map); } - private List getMaterialList(Map map) { + private List getMaterialList(Map map) throws Exception{ String search = map.get(Constants.SEARCH); String name = StringUtil.getInfo(search, "name"); String model = StringUtil.getInfo(search, "model"); @@ -42,7 +42,7 @@ public class MaterialComponent 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"); String model = StringUtil.getInfo(search, "model"); @@ -53,27 +53,27 @@ public class MaterialComponent implements ICommonQuery { } @Override - public int insert(String beanJson, HttpServletRequest request) { + public int insert(String beanJson, HttpServletRequest request) throws Exception{ return materialService.insertMaterial(beanJson, request); } @Override - public int update(String beanJson, Long id) { + public int update(String beanJson, Long id)throws Exception { return materialService.updateMaterial(beanJson, id); } @Override - public int delete(Long id) { + public int delete(Long id)throws Exception { return materialService.deleteMaterial(id); } @Override - public int batchDelete(String ids) { + public int batchDelete(String ids)throws Exception { return materialService.batchDeleteMaterial(ids); } @Override - public int checkIsNameExist(Long id, String name) { + public int checkIsNameExist(Long id, String name)throws Exception { return materialService.checkIsNameExist(id, name); } diff --git a/src/main/java/com/jsh/erp/service/material/MaterialService.java b/src/main/java/com/jsh/erp/service/material/MaterialService.java index f03dccca..ac219245 100644 --- a/src/main/java/com/jsh/erp/service/material/MaterialService.java +++ b/src/main/java/com/jsh/erp/service/material/MaterialService.java @@ -39,20 +39,47 @@ public class MaterialService { @Resource private DepotItemMapperEx depotItemMapperEx; - public Material getMaterial(long id) { - return materialMapper.selectByPrimaryKey(id); + public Material getMaterial(long id)throws Exception { + Material result=null; + try{ + result=materialMapper.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 getMaterial() { + public List getMaterial() throws Exception{ MaterialExample example = new MaterialExample(); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - return materialMapper.selectByExample(example); + List list=null; + try{ + list=materialMapper.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, String model,Long categoryId, String categoryIds,String mpList, int offset, int rows) { + public List select(String name, String model,Long categoryId, String categoryIds,String mpList, int offset, int rows) + throws Exception{ String[] mpArr = mpList.split(","); List resList = new ArrayList(); - List list = materialMapperEx.selectByConditionMaterial(name, model,categoryId,categoryIds,mpList, offset, rows); + List list =null; + try{ + list= materialMapperEx.selectByConditionMaterial(name, model,categoryId,categoryIds,mpList, 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); + } if (null != list) { for (MaterialVo4Unit m : list) { //扩展信息 @@ -84,53 +111,106 @@ public class MaterialService { return resList; } - public Long countMaterial(String name, String model,Long categoryId, String categoryIds,String mpList) { - return materialMapperEx.countsByMaterial(name, model,categoryId,categoryIds,mpList); + public Long countMaterial(String name, String model,Long categoryId, String categoryIds,String mpList)throws Exception { + Long result =null; + try{ + result= materialMapperEx.countsByMaterial(name, model,categoryId,categoryIds,mpList); + }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 insertMaterial(String beanJson, HttpServletRequest request) { + public int insertMaterial(String beanJson, HttpServletRequest request)throws Exception { Material material = JSONObject.parseObject(beanJson, Material.class); material.setEnabled(true); - return materialMapper.insertSelective(material); + int result =0; + try{ + result= materialMapper.insertSelective(material); + }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 updateMaterial(String beanJson, Long id) { + public int updateMaterial(String beanJson, Long id) throws Exception{ Material material = JSONObject.parseObject(beanJson, Material.class); material.setId(id); - int res = materialMapper.updateByPrimaryKeySelective(material); - Long unitId = material.getUnitid(); - if(unitId != null) { - materialMapperEx.updatePriceNullByPrimaryKey(id); //将价格置空 - } else { - materialMapperEx.updateUnitIdNullByPrimaryKey(id); //将多单位置空 + int res =0; + try{ + res= materialMapper.updateByPrimaryKeySelective(material); + Long unitId = material.getUnitid(); + if(unitId != null) { + materialMapperEx.updatePriceNullByPrimaryKey(id); //将价格置空 + } else { + materialMapperEx.updateUnitIdNullByPrimaryKey(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 res; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int deleteMaterial(Long id) { - return materialMapper.deleteByPrimaryKey(id); + public int deleteMaterial(Long id)throws Exception { + int result =0; + try{ + result= materialMapper.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 batchDeleteMaterial(String ids) { + public int batchDeleteMaterial(String ids)throws Exception { List idList = StringUtil.strToLongList(ids); MaterialExample example = new MaterialExample(); example.createCriteria().andIdIn(idList); - return materialMapper.deleteByExample(example); + int result =0; + try{ + result= materialMapper.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 { MaterialExample example = new MaterialExample(); example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = materialMapper.selectByExample(example); - return list.size(); + List list =null; + try{ + list= materialMapper.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(); } public int checkIsExist(Long id, String name, String model, String color, String standard, String mfrs, - String otherField1, String otherField2, String otherField3, String unit, Long unitId) { + String otherField1, String otherField2, String otherField3, String unit, Long unitId)throws Exception { MaterialExample example = new MaterialExample(); MaterialExample.Criteria criteria = example.createCriteria(); criteria.andNameEqualTo(name).andModelEqualTo(model).andColorEqualTo(color) @@ -145,8 +225,16 @@ public class MaterialService { if (unitId !=null) { criteria.andUnitidEqualTo(unitId); } - List list = materialMapper.selectByExample(example); - return list.size(); + List list =null; + try{ + list= materialMapper.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) @@ -159,31 +247,84 @@ public class MaterialService { material.setEnabled(enabled); MaterialExample example = new MaterialExample(); example.createCriteria().andIdIn(ids); - return materialMapper.updateByExampleSelective(material, example); + int result =0; + try{ + result= materialMapper.updateByExampleSelective(material, 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 result; } - public String findUnitName(Long mId){ - return materialMapperEx.findUnitName(mId); + public String findUnitName(Long mId)throws Exception{ + String result =null; + try{ + result= materialMapperEx.findUnitName(mId); + }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 findById(Long id){ - return materialMapperEx.findById(id); + public List findById(Long id)throws Exception{ + List list =null; + try{ + list= materialMapperEx.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 List findBySelect(){ - return materialMapperEx.findBySelect(); + public List findBySelect()throws Exception{ + List list =null; + try{ + list= materialMapperEx.findBySelect(); + }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 findByOrder(){ + public List findByOrder()throws Exception{ MaterialExample example = new MaterialExample(); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); example.setOrderByClause("Name,Model asc"); - return materialMapper.selectByExample(example); + List list =null; + try{ + list= materialMapper.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 findByAll(String name, String model, Long categoryId, String categoryIds) { + public List findByAll(String name, String model, Long categoryId, String categoryIds)throws Exception { List resList = new ArrayList(); - List list = materialMapperEx.findByAll(name, model, categoryId, categoryIds); + List list =null; + try{ + list= materialMapperEx.findByAll(name, model, categoryId, categoryIds); + }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 (null != list) { for (MaterialVo4Unit m : list) { resList.add(m); @@ -205,6 +346,8 @@ public class MaterialService { info.code = 200; data.put("message", "成功"); } catch (Exception e) { + logger.error("异常码[{}],异常提示[{}],异常[{}]", + ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e); e.printStackTrace(); info.code = 500; data.put("message", e.getMessage()); @@ -213,8 +356,17 @@ public class MaterialService { return info; } - public List getMaterialEnableSerialNumberList(Map parameterMap) { - return materialMapperEx.getMaterialEnableSerialNumberList(parameterMap); + public List getMaterialEnableSerialNumberList(Map parameterMap)throws Exception { + List list =null; + try{ + list= materialMapperEx.getMaterialEnableSerialNumberList(parameterMap); + }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; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int batchDeleteMaterialByIds(String ids) throws Exception{ @@ -223,7 +375,16 @@ public class MaterialService { ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); User userInfo=userService.getCurrentUser(); String [] idArray=ids.split(","); - return materialMapperEx.batchDeleteMaterialByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); + int result =0; + try{ + result= materialMapperEx.batchDeleteMaterialByIds(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; } /** * create by: qiankunpingtai @@ -250,7 +411,15 @@ public class MaterialService { /** * 校验单据子表 jsh_depotitem * */ - List depotItemList=depotItemMapperEx.getDepotItemListListByMaterialIds(idArray); + List depotItemList =null; + try{ + depotItemList= depotItemMapperEx.getDepotItemListListByMaterialIds(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(depotItemList!=null&&depotItemList.size()>0){ logger.error("异常码[{}],异常提示[{}],参数,MaterialIds[{}]", ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);