商品类型管理
This commit is contained in:
parent
364443bc20
commit
72b91c1cc1
|
|
@ -57,4 +57,6 @@ public interface SupermarketMaterialMapper {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteSupermarketMaterialByMaterialIds(Long[] materialIds);
|
||||
|
||||
public int getSupermarketMaterialCountByMaterialTypes(Long[] materialTypeIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ public interface SupermarketMaterialTypeMapper {
|
|||
*/
|
||||
public SupermarketMaterialType selectSupermarketMaterialTypeByMaterialTypeId(Long materialTypeId);
|
||||
|
||||
public SupermarketMaterialType selectSupermarketMaterialTypeByMaterialTypeName(SupermarketMaterialType supermarketMaterialType);
|
||||
|
||||
/**
|
||||
* 查询商品类别列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package com.bonus.canteen.core.supermarket.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import com.bonus.canteen.core.supermarket.mapper.SupermarketMaterialMapper;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.canteen.core.supermarket.mapper.SupermarketMaterialTypeMapper;
|
||||
|
|
@ -19,6 +23,8 @@ import com.bonus.canteen.core.supermarket.service.ISupermarketMaterialTypeServic
|
|||
public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialTypeService {
|
||||
@Autowired
|
||||
private SupermarketMaterialTypeMapper supermarketMaterialTypeMapper;
|
||||
@Autowired
|
||||
private SupermarketMaterialMapper supermarketMaterialMapper;
|
||||
|
||||
/**
|
||||
* 查询商品类别
|
||||
|
|
@ -51,7 +57,12 @@ public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialT
|
|||
@Override
|
||||
public int insertSupermarketMaterialType(SupermarketMaterialType supermarketMaterialType) {
|
||||
supermarketMaterialType.setCreateTime(DateUtils.getNowDate());
|
||||
supermarketMaterialType.setCreateBy(SecurityUtils.getUsername());
|
||||
try {
|
||||
SupermarketMaterialType checkResult = supermarketMaterialTypeMapper.selectSupermarketMaterialTypeByMaterialTypeName(supermarketMaterialType);
|
||||
if (Objects.nonNull(checkResult)) {
|
||||
throw new ServiceException("改超市商品类别名已存在");
|
||||
}
|
||||
return supermarketMaterialTypeMapper.insertSupermarketMaterialType(supermarketMaterialType);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
|
|
@ -67,7 +78,14 @@ public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialT
|
|||
@Override
|
||||
public int updateSupermarketMaterialType(SupermarketMaterialType supermarketMaterialType) {
|
||||
supermarketMaterialType.setUpdateTime(DateUtils.getNowDate());
|
||||
supermarketMaterialType.setUpdateBy(SecurityUtils.getUsername());
|
||||
try {
|
||||
List<SupermarketMaterialType> allSupermarketMaterialTypeList = supermarketMaterialTypeMapper.selectSupermarketMaterialTypeList(new SupermarketMaterialType());
|
||||
List<String> otherSupermarketMaterialTypeList = allSupermarketMaterialTypeList.stream().filter(item -> !item.getMaterialTypeId().equals(supermarketMaterialType.getMaterialTypeId()))
|
||||
.map(SupermarketMaterialType::getMaterialTypeName).collect(Collectors.toList());
|
||||
if (otherSupermarketMaterialTypeList.contains(supermarketMaterialType.getMaterialTypeName())) {
|
||||
throw new ServiceException("改超市商品类别名已存在");
|
||||
}
|
||||
return supermarketMaterialTypeMapper.updateSupermarketMaterialType(supermarketMaterialType);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
|
|
@ -82,6 +100,10 @@ public class SupermarketMaterialTypeServiceImpl implements ISupermarketMaterialT
|
|||
*/
|
||||
@Override
|
||||
public int deleteSupermarketMaterialTypeByMaterialTypeIds(Long[] materialTypeIds) {
|
||||
int count = supermarketMaterialMapper.getSupermarketMaterialCountByMaterialTypes(materialTypeIds);
|
||||
if (count > 0) {
|
||||
throw new ServiceException("该超市商品类型含有商品信息,不能删除");
|
||||
}
|
||||
return supermarketMaterialTypeMapper.deleteSupermarketMaterialTypeByMaterialTypeIds(materialTypeIds);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,4 +143,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
#{materialId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="getSupermarketMaterialCountByMaterialTypes" resultType="Integer">
|
||||
select count(1)
|
||||
from supermarket_material
|
||||
where material_type_id in
|
||||
<foreach item="materialTypeId" collection="array" open="(" separator="," close=")">
|
||||
#{materialTypeId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -16,7 +16,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectSupermarketMaterialTypeVo">
|
||||
select material_type_id, material_type_name, parent_id, level, area_id, create_by, create_time, update_by, update_time from supermarket_material_type
|
||||
select material_type_id, material_type_name, parent_id, level, area_id, create_by, create_time, update_by, update_time
|
||||
from supermarket_material_type
|
||||
</sql>
|
||||
|
||||
<select id="selectSupermarketMaterialTypeList" parameterType="com.bonus.canteen.core.supermarket.domain.SupermarketMaterialType" resultMap="SupermarketMaterialTypeResult">
|
||||
|
|
@ -33,6 +34,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectSupermarketMaterialTypeVo"/>
|
||||
where material_type_id = #{materialTypeId}
|
||||
</select>
|
||||
|
||||
<select id="selectSupermarketMaterialTypeByMaterialTypeName" resultMap="SupermarketMaterialTypeResult">
|
||||
<include refid="selectSupermarketMaterialTypeVo"/>
|
||||
where material_type_name = #{materialTypeName}
|
||||
</select>
|
||||
|
||||
<insert id="insertSupermarketMaterialType" parameterType="com.bonus.canteen.core.supermarket.domain.SupermarketMaterialType" useGeneratedKeys="true" keyProperty="materialTypeId">
|
||||
insert into supermarket_material_type
|
||||
|
|
|
|||
Loading…
Reference in New Issue