去除外键之产品类型表jsh_materialcategory相关修改

This commit is contained in:
qiankunpingtai
2019-04-11 10:01:33 +08:00
parent a184aabd9b
commit 3fa79da3aa
7 changed files with 139 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.MaterialCategory;
import com.jsh.erp.datasource.entities.SerialNumberEx;
@@ -151,9 +152,20 @@ public class MaterialCategoryController {
* @return java.lang.Object
*/
@RequestMapping(value = "/batchDeleteMaterialCategory")
public Object batchDeleteMaterialCategory(@RequestParam("ids") String ids) throws Exception {
public Object batchDeleteMaterialCategory(@RequestParam("ids") String ids,@RequestParam(value="deleteType",
required =false,defaultValue= BusinessConstants.DELETE_TYPE_NORMAL)String deleteType) throws Exception {
JSONObject result = ExceptionConstants.standardSuccess();
int i= materialCategoryService.batchDeleteMaterialCategoryByIds(ids);
int i=0;
if(BusinessConstants.DELETE_TYPE_NORMAL.equals(deleteType)){
i= materialCategoryService.batchDeleteMaterialCategoryByIdsNormal(ids);
}else if(BusinessConstants.DELETE_TYPE_FORCE.equals(deleteType)){
i= materialCategoryService.batchDeleteMaterialCategoryByIds(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){
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_DELETE_FAILED_CODE,
ExceptionConstants.MATERIAL_CATEGORY_DELETE_FAILED_MSG);

View File

@@ -35,4 +35,6 @@ public interface MaterialCategoryMapperEx {
int editMaterialCategory(MaterialCategory mc);
List<MaterialCategory> getMaterialCategoryBySerialNo(@Param("serialNo") String serialNo);
List<MaterialCategory> getMaterialCategoryListByCategoryIds(@Param("parentIds") String[] categoryIds);
}

View File

@@ -1,5 +1,6 @@
package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.AccountHead;
import com.jsh.erp.datasource.entities.Material;
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
import org.apache.ibatis.annotations.Param;
@@ -57,4 +58,6 @@ public interface MaterialMapperEx {
List<Material> getMaterialEnableSerialNumberList(Map<String, Object> parameterMap);
int batchDeleteMaterialByIds(@Param("updateTime") Date updateTime, @Param("updater") Long updater, @Param("ids") String ids[]);
List<Material> getMaterialListByCategoryIds(@Param("categoryIds") String[] categoryIds);
}

View File

@@ -1,13 +1,13 @@
package com.jsh.erp.service.materialCategory;
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.MaterialCategory;
import com.jsh.erp.datasource.entities.MaterialCategoryExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapper;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapperEx;
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
import com.jsh.erp.datasource.vo.TreeNode;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.log.LogService;
@@ -37,6 +37,8 @@ public class MaterialCategoryService {
private UserService userService;
@Resource
private LogService logService;
@Resource
private MaterialMapperEx materialMapperEx;
public MaterialCategory getMaterialCategory(long id) {
return materialCategoryMapper.selectByPrimaryKey(id);
@@ -216,5 +218,52 @@ public class MaterialCategoryService {
}
}
/**
* create by: qiankunpingtai
* websitehttps://qiankunpingtai.cn
* description:
* 正常删除,要考虑数据完整性,进行完整性校验
* create time: 2019/4/11 9:26
* @Param: ids
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialCategoryByIdsNormal(String ids) throws Exception {
/**
* 校验
* 1、产品表 jsh_material
* 2、产品类型表 jsh_materialcategory
* 是否有相关数据
* */
int deleteTotal=0;
if(StringUtils.isEmpty(ids)){
return deleteTotal;
}
String [] idArray=ids.split(",");
/**
* 校验产品表 jsh_material
* */
List<Material> materialList=materialMapperEx.getMaterialListByCategoryIds(idArray);
if(materialList!=null&&materialList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
/**
* 校验产品类型表 jsh_materialcategory
* */
List<MaterialCategory> materialCategoryList=materialCategoryMapperEx.getMaterialCategoryListByCategoryIds(idArray);
if(materialCategoryList!=null&&materialCategoryList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
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= batchDeleteMaterialCategoryByIds(ids);
return deleteTotal;
}
}

View File

@@ -107,5 +107,17 @@
and serial_no=#{serialNo}
and ifnull(status,'0') !='2'
</select>
<select id="getMaterialCategoryListByCategoryIds" resultMap="com.jsh.erp.datasource.mappers.MaterialCategoryMapper.BaseResultMap">
select
<include refid="com.jsh.erp.datasource.mappers.MaterialCategoryMapper.Base_Column_List" />
from jsh_materialcategory
where 1=1
and parentId in (
<foreach collection="parentIds" item="parentId" separator=",">
#{parentId}
</foreach>
)
and ifnull(status,'0') !='2'
</select>
</mapper>

View File

@@ -149,6 +149,18 @@
</foreach>
)
</update>
<select id="getMaterialListByCategoryIds" resultMap="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap">
select
<include refid="com.jsh.erp.datasource.mappers.MaterialMapper.Base_Column_List" />
from jsh_material
where 1=1
and categoryId in (
<foreach collection="categoryIds" item="categoryId" separator=",">
#{categoryId}
</foreach>
)
and ifnull(delete_Flag,'0') !='1'
</select>
</mapper>