物资类型删除

This commit is contained in:
mashuai 2024-10-25 16:13:30 +08:00
parent ba96fddba5
commit 86cec30880
5 changed files with 36 additions and 6 deletions

View File

@ -174,9 +174,9 @@ public class TypeController extends BaseController {
@PreventRepeatSubmit
@RequiresPermissions("ma:type:remove")
@SysLog(title = "物资类型管理", businessType = OperaType.DELETE, module = "仓储管理->删除物资类型")
@DeleteMapping("/{typeIds}")
public AjaxResult remove(@PathVariable Long[] typeIds) {
return toAjax(typeService.deleteTypeByTypeIds(typeIds));
@DeleteMapping("/{typeId}")
public AjaxResult remove(@PathVariable Long typeId) {
return typeService.deleteTypeByTypeId(typeId);
}
/**

View File

@ -124,4 +124,11 @@ public interface TypeMapper {
int logicDeleteTypeByTypeIds(Long[] typeIds);
Type queryByName(String typeName);
/**
* 根据ID查询
* @param typeId
* @return
*/
List<Type> selectById(Long typeId);
}

View File

@ -84,7 +84,7 @@ public interface ITypeService {
* @param typeId 物资类型主键
* @return 结果
*/
int deleteTypeByTypeId(Long typeId);
AjaxResult deleteTypeByTypeId(Long typeId);
List<TreeSelect> getMaTypeTree(String typeName, String parentId);

View File

@ -6,6 +6,7 @@ import java.util.stream.Collectors;
import cn.hutool.core.util.ArrayUtil;
import com.bonus.common.biz.domain.TreeSelect;
import com.bonus.common.biz.enums.DataCodeEnum;
import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.domain.AjaxResult;
@ -20,6 +21,7 @@ import com.bonus.material.ma.vo.MaTypeListVo;
import com.bonus.material.ma.vo.MaTypeSelectVo;
import com.bonus.material.warehouse.domain.WhHouseSet;
import com.bonus.material.warehouse.service.IWhHouseSetService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import com.bonus.material.ma.mapper.TypeMapper;
import com.bonus.material.ma.domain.Type;
@ -265,6 +267,11 @@ public class TypeServiceImpl implements ITypeService {
*/
@Override
public int updateType(Type type) {
//根据类型名称判断去重
Type maType = typeMapper.queryByName(type.getTypeName());
if (maType != null && !maType.getTypeId().equals(type.getTypeId()) && maType.getParentId().equals(type.getParentId())) {
throw new RuntimeException("同级下类型名称存在重复!");
}
type.setUpdateTime(DateUtils.getNowDate());
type.setUpdateBy(SecurityUtils.getUserId().toString());
return typeMapper.updateType(type);
@ -288,8 +295,17 @@ public class TypeServiceImpl implements ITypeService {
* @return 结果
*/
@Override
public int deleteTypeByTypeId(Long typeId) {
return typeMapper.logicDeleteTypeByTypeId(typeId);
public AjaxResult deleteTypeByTypeId(Long typeId) {
//根据id查询删除类型下属是否有关联有关联无法删除
List<Type> list = typeMapper.selectById(typeId);
if (CollectionUtils.isNotEmpty(list)) {
return AjaxResult.error("该类型下有子类型,无法删除");
}
int result = typeMapper.logicDeleteTypeByTypeId(typeId);
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}

View File

@ -446,4 +446,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from ma_type
where type_name = #{typeName} and del_flag = '0'
</select>
<select id="selectById" resultType="com.bonus.material.ma.domain.Type">
select
type_id as typeId, parent_id as parentId, type_name as typeName, level as level
from ma_type
where parent_id = #{typeId} and del_flag = '0'
</select>
</mapper>