From a86630e1e49f6f86a2c234a8c309df0ac379bb37 Mon Sep 17 00:00:00 2001 From: qiankunpingtai Date: Thu, 11 Apr 2019 10:36:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=96=E9=94=AE=E4=B9=8B?= =?UTF-8?q?=E5=A4=9A=E5=8D=95=E4=BD=8D=E8=A1=A8jsh=5Funit=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- erp_web/pages/manage/unit.html | 56 ++++++++++++++++++- .../jsh/erp/controller/UnitController.java | 16 +++++- .../datasource/mappers/MaterialMapperEx.java | 2 + .../com/jsh/erp/service/unit/UnitService.java | 45 ++++++++++++++- .../resources/mapper_xml/MaterialMapperEx.xml | 12 ++++ 5 files changed, 126 insertions(+), 5 deletions(-) diff --git a/erp_web/pages/manage/unit.html b/erp_web/pages/manage/unit.html index 7b352659..c36b433a 100644 --- a/erp_web/pages/manage/unit.html +++ b/erp_web/pages/manage/unit.html @@ -206,7 +206,17 @@ if(res && res.code == 200) { $("#searchBtn").click(); } else { - $.messager.alert('删除提示', '删除计量单位失败,请稍后再试!', 'error'); + if(res && res.code == 601){ + var jsondata={}; + jsondata.ids=unitID; + jsondata.deleteType='2'; + var type='single'; + batDeleteUnitForceConfirm(res,"/unit/batchDeleteUnitByIds",jsondata,type); + }else if(res && res.code == 600){ + $.messager.alert('删除提示', res.msg, 'error'); + }else{ + $.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error'); + } } }, //此处添加错误处理 @@ -251,7 +261,17 @@ $("#searchBtn").click(); $(":checkbox").attr("checked", false); } else { - $.messager.alert('删除提示', '删除计量单位失败,请稍后再试!', 'error'); + if(res && res.code == 601){ + var jsondata={}; + jsondata.ids=ids; + jsondata.deleteType='2'; + var type='batch'; + batDeleteUnitForceConfirm(res,"/unit/batchDeleteUnitByIds",jsondata,type); + }else if(res && res.code == 600){ + $.messager.alert('删除提示', res.msg, 'error'); + }else{ + $.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error'); + } } }, //此处添加错误处理 @@ -264,6 +284,38 @@ }); } } + /** + * 确认强制删除 + * */ + function batDeleteUnitForceConfirm(res,url,jsondata,type) { + $.messager.confirm('删除确认', res.msg, function (r) { + if (r) { + $.ajax({ + type: "post", + url: url, + dataType: "json", + data: (jsondata), + success: function (res) { + if(res && res.code == 200) { + $("#searchBtn").click(); + if(type=='batch'){ + $(":checkbox").attr("checked", false); + } + }else if(res && res.code == 600){ + $.messager.alert('删除提示', res.msg, 'error'); + }else { + $.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error'); + } + }, + //此处添加错误处理 + error: function () { + $.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error'); + return; + } + }); + } + }); + } //增加 var url; diff --git a/src/main/java/com/jsh/erp/controller/UnitController.java b/src/main/java/com/jsh/erp/controller/UnitController.java index 72c031b6..1dbf7dd2 100644 --- a/src/main/java/com/jsh/erp/controller/UnitController.java +++ b/src/main/java/com/jsh/erp/controller/UnitController.java @@ -1,6 +1,7 @@ package com.jsh.erp.controller; import com.alibaba.fastjson.JSONObject; +import com.jsh.erp.constants.BusinessConstants; import com.jsh.erp.constants.ExceptionConstants; import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.service.unit.UnitService; @@ -34,9 +35,20 @@ public class UnitController { * @return java.lang.Object */ @RequestMapping(value = "/batchDeleteUnitByIds") - public Object batchDeleteUnitByIds(@RequestParam("ids") String ids) throws Exception { + public Object batchDeleteUnitByIds(@RequestParam("ids") String ids,@RequestParam(value="deleteType", + required =false,defaultValue= BusinessConstants.DELETE_TYPE_NORMAL)String deleteType) throws Exception { JSONObject result = ExceptionConstants.standardSuccess(); - int i= unitService.batchDeleteUnitByIds(ids); + int i=0; + if(BusinessConstants.DELETE_TYPE_NORMAL.equals(deleteType)){ + i= unitService.batchDeleteUnitByIdsNormal(ids); + }else if(BusinessConstants.DELETE_TYPE_FORCE.equals(deleteType)){ + i= unitService.batchDeleteUnitByIds(ids); + }else{ + logger.error("异常码[{}],异常提示[{}],参数,ids[{}],deleteType[{}]", + ExceptionConstants.DELETE_REFUSED_CODE,ExceptionConstants.DELETE_REFUSED_MSG,ids,deleteType); + throw new BusinessRunTimeException(ExceptionConstants.DELETE_REFUSED_CODE, + ExceptionConstants.DELETE_REFUSED_MSG); + } if(i<1){ logger.error("异常码[{}],异常提示[{}],参数,ids[{}]", ExceptionConstants.UNIT_DELETE_FAILED_CODE,ExceptionConstants.UNIT_DELETE_FAILED_MSG,ids); diff --git a/src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java b/src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java index 4794aea2..20b609c4 100644 --- a/src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java +++ b/src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java @@ -60,4 +60,6 @@ public interface MaterialMapperEx { int batchDeleteMaterialByIds(@Param("updateTime") Date updateTime, @Param("updater") Long updater, @Param("ids") String ids[]); List getMaterialListByCategoryIds(@Param("categoryIds") String[] categoryIds); + + List getMaterialListByUnitIds(@Param("unitIds") String[] unitIds); } 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 2838306a..65a7b0dc 100644 --- a/src/main/java/com/jsh/erp/service/unit/UnitService.java +++ b/src/main/java/com/jsh/erp/service/unit/UnitService.java @@ -1,12 +1,17 @@ package com.jsh.erp.service.unit; 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.mappers.MaterialMapperEx; import com.jsh.erp.datasource.mappers.UnitMapper; import com.jsh.erp.datasource.mappers.UnitMapperEx; +import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.service.log.LogService; import com.jsh.erp.service.user.UserService; import com.jsh.erp.utils.StringUtil; @@ -35,6 +40,8 @@ public class UnitService { private UserService userService; @Resource private LogService logService; + @Resource + private MaterialMapperEx materialMapperEx; public Unit getUnit(long id) { return unitMapper.selectByPrimaryKey(id); @@ -95,5 +102,41 @@ public class UnitService { return unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); } - + /** + * create by: qiankunpingtai + * website:https://qiankunpingtai.cn + * description: + * 正常删除,要考虑数据完整性,进行完整性校验 + * create time: 2019/4/11 10:20 + * @Param: ids + * @return int + */ + @Transactional(value = "transactionManager", rollbackFor = Exception.class) + public int batchDeleteUnitByIdsNormal(String ids) throws Exception { + /** + * 校验 + * 1、产品表 jsh_material + * 是否有相关数据 + * */ + int deleteTotal=0; + if(StringUtils.isEmpty(ids)){ + return deleteTotal; + } + String [] idArray=ids.split(","); + /** + * 校验产品表 jsh_material + * */ + List materialList=materialMapperEx.getMaterialListByUnitIds(idArray); + if(materialList!=null&&materialList.size()>0){ + logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]", + ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids); + throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE, + ExceptionConstants.DELETE_FORCE_CONFIRM_MSG); + } + /** + * 校验通过执行删除操作 + * */ + deleteTotal= batchDeleteUnitByIds(ids); + return deleteTotal; + } } diff --git a/src/main/resources/mapper_xml/MaterialMapperEx.xml b/src/main/resources/mapper_xml/MaterialMapperEx.xml index 97f29cbf..fe000c24 100644 --- a/src/main/resources/mapper_xml/MaterialMapperEx.xml +++ b/src/main/resources/mapper_xml/MaterialMapperEx.xml @@ -161,6 +161,18 @@ ) and ifnull(delete_Flag,'0') !='1' + \ No newline at end of file