GoodsCategoryService and GoodsCategoryMapper
This commit is contained in:
parent
409ec52569
commit
37938e09c1
|
|
@ -1,8 +1,58 @@
|
|||
package com.ghy.goods.mapper;
|
||||
|
||||
import com.ghy.goods.domain.GoodsCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author clunt
|
||||
* 商品类别mapper层
|
||||
*/
|
||||
public interface GoodsCategoryMapper {
|
||||
|
||||
|
||||
/**
|
||||
* @param category 商品属性
|
||||
* @return 成功条数
|
||||
*/
|
||||
int insertCategoryGoods(GoodsCategory category);
|
||||
|
||||
/**
|
||||
* @param category 商品属性
|
||||
* @return 成功条数
|
||||
*/
|
||||
int updateGoodsCategory(GoodsCategory category);
|
||||
|
||||
/**
|
||||
* @param category 商品入参
|
||||
* @return 商品集合
|
||||
*/
|
||||
List<GoodsCategory> selectGoodsCategoryList(GoodsCategory category);
|
||||
|
||||
|
||||
/**
|
||||
* @param goodsCategoryId 商品id
|
||||
* @return 商品
|
||||
*/
|
||||
GoodsCategory selectById(Long goodsCategoryId);
|
||||
|
||||
/**
|
||||
* 批量删除商品信息
|
||||
*
|
||||
* @param goodsCategoryId 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteGoodsCategoryByIds(Long[] goodsCategoryId);
|
||||
|
||||
/**
|
||||
* @param goodsCategoryName 商品名称
|
||||
* @return 商品信息
|
||||
*/
|
||||
GoodsCategory selectByGoodsCategoryName(String goodsCategoryName);
|
||||
|
||||
/**
|
||||
* @param goodsCategoryCode 商品编码
|
||||
* @return 商品信息
|
||||
*/
|
||||
GoodsCategory selectByGoodsCategoryCode(String goodsCategoryCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,4 +55,12 @@ public interface GoodsMapper {
|
|||
*/
|
||||
public Goods checkGoodsCodeUnique(String goodsCode);
|
||||
|
||||
/**
|
||||
* 用商品类别ID查询一条商品信息
|
||||
* 一般用于校验商品类别是否正在被使用
|
||||
*
|
||||
* @param goodsCategoryId 设备类别ID
|
||||
* @return 商品信息
|
||||
*/
|
||||
Goods selectOneByGoodsCategoryId(Long goodsCategoryId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,60 @@
|
|||
package com.ghy.goods.service;
|
||||
|
||||
import com.ghy.goods.domain.GoodsCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author clunt
|
||||
* 商品类别接口
|
||||
*/
|
||||
public interface GoodsCategoryService {
|
||||
|
||||
|
||||
/**
|
||||
* @param goodsCategory 商品类别属性
|
||||
* @return 成功条数
|
||||
*/
|
||||
int insertGoodsCategory(GoodsCategory goodsCategory);
|
||||
|
||||
/**
|
||||
* @param goodsCategory 商品类别属性
|
||||
* @return 成功条数
|
||||
*/
|
||||
int updateGoodsCategory(GoodsCategory goodsCategory);
|
||||
|
||||
/**
|
||||
* @param goodsCategory 商品类别入参
|
||||
* @return 商品类别集合
|
||||
*/
|
||||
List<GoodsCategory> selectGoodsCategoryList(GoodsCategory goodsCategory);
|
||||
|
||||
|
||||
/**
|
||||
* @param goodsCategoryId 商品类别id
|
||||
* @return 商品类别
|
||||
*/
|
||||
GoodsCategory selectById(Long goodsCategoryId);
|
||||
|
||||
/**
|
||||
* @param ids 商品类别ids
|
||||
* @return 删除结果
|
||||
*/
|
||||
int deleteGoodsCategoryByIds(String ids);
|
||||
|
||||
/**
|
||||
* 校验商品类别名称是否重复
|
||||
*
|
||||
* @param goodsCategory 商品类别属性
|
||||
* @return 校验结果 true重复 false不重复
|
||||
*/
|
||||
boolean checkGoodsCategoryNameUnique(GoodsCategory goodsCategory);
|
||||
|
||||
/**
|
||||
* 校验商品类别编码是否重复
|
||||
*
|
||||
* @param goodsCategory 商品类别属性
|
||||
* @return 校验结果 true重复 false不重复
|
||||
*/
|
||||
boolean checkGoodsCategoryCodeUnique(GoodsCategory goodsCategory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,70 @@
|
|||
package com.ghy.goods.service.impl;
|
||||
|
||||
import com.ghy.common.core.text.Convert;
|
||||
import com.ghy.goods.domain.Goods;
|
||||
import com.ghy.goods.domain.GoodsCategory;
|
||||
import com.ghy.goods.mapper.GoodsCategoryMapper;
|
||||
import com.ghy.goods.mapper.GoodsMapper;
|
||||
import com.ghy.goods.service.GoodsCategoryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author clunt
|
||||
* 商品类别impl
|
||||
*/
|
||||
@Service
|
||||
public class GoodsCategoryServiceImpl implements GoodsCategoryService {
|
||||
|
||||
@Resource
|
||||
private GoodsMapper goodsMapper;
|
||||
@Resource
|
||||
GoodsCategoryMapper goodsCategoryMapper;
|
||||
|
||||
@Override
|
||||
public int insertGoodsCategory(GoodsCategory goodsCategory) {
|
||||
return goodsCategoryMapper.insertCategoryGoods(goodsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateGoodsCategory(GoodsCategory goodsCategory) {
|
||||
return goodsCategoryMapper.updateGoodsCategory(goodsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GoodsCategory> selectGoodsCategoryList(GoodsCategory goodsCategory) {
|
||||
return goodsCategoryMapper.selectGoodsCategoryList(goodsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoodsCategory selectById(Long goodsCategoryId) {
|
||||
return goodsCategoryMapper.selectById(goodsCategoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteGoodsCategoryByIds(String ids) {
|
||||
Long[] idArray = Convert.toLongArray(ids);
|
||||
for (Long id : idArray) {
|
||||
Goods goods = goodsMapper.selectOneByGoodsCategoryId(id);
|
||||
Assert.isNull(goods, "正在被使用的商品类别不能删除");
|
||||
}
|
||||
return goodsCategoryMapper.deleteGoodsCategoryByIds(idArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkGoodsCategoryNameUnique(GoodsCategory goodsCategory) {
|
||||
GoodsCategory category = goodsCategoryMapper.selectByGoodsCategoryName(goodsCategory.getGoodsCategoryName());
|
||||
if (category == null) return false;
|
||||
return category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkGoodsCategoryCodeUnique(GoodsCategory goodsCategory) {
|
||||
GoodsCategory category = goodsCategoryMapper.selectByGoodsCategoryCode(goodsCategory.getGoodsCategoryCode());
|
||||
if (category == null) return false;
|
||||
return category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ghy.goods.mapper.GoodsCategoryMapper">
|
||||
|
||||
<resultMap id="GoodsCategoryResult" type="com.ghy.goods.domain.GoodsCategory">
|
||||
<result property="goodsCategoryId" column="goods_category_id" />
|
||||
<result property="goodsCategoryCode" column="goods_category_code" />
|
||||
|
|
@ -23,4 +22,74 @@
|
|||
FROM goods_category
|
||||
</sql>
|
||||
|
||||
<select id="selectGoodsCategoryList" parameterType="com.ghy.goods.domain.GoodsCategory" resultMap="GoodsCategoryResult">
|
||||
<include refid="selectGoodsCategory" />
|
||||
<where>
|
||||
<if test="goodsCategoryCode != null and goodsCategoryCode != ''">
|
||||
AND goods_category_code like concat('%', #{goodsCategoryCode}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" parameterType="long" resultMap="GoodsCategoryResult">
|
||||
<include refid="selectGoodsCategory"/>
|
||||
WHERE goods_category_id = #{goodsCategoryId}
|
||||
</select>
|
||||
|
||||
<update id="updateGoodsCategory" parameterType="com.ghy.goods.domain.GoodsCategory">
|
||||
UPDATE goods_category
|
||||
<set>
|
||||
<if test="goodsCategoryCode != null and goodsCategoryCode != ''">goods_category_code = #{goodsCategoryCode},</if>
|
||||
<if test="goodsCategoryName != null and goodsCategoryName != ''">goods_category_name = #{goodsCategoryName},</if>
|
||||
<if test="parentCategoryId != null and parentCategoryId != ''">parent_category_id = #{parentCategoryId},</if>
|
||||
<if test="level != null and level != ''">level = #{level},</if>
|
||||
<if test="type != null and type != ''">type = #{type},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
WHERE goods_category_id = #{goodsCategoryId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteGoodsCategoryByIds" parameterType="Long">
|
||||
DELETE FROM goods_category WHERE goods_category_id IN
|
||||
<foreach collection="array" item="goodsCategoryId" open="(" separator="," close=")">
|
||||
#{goodsCategoryId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="insertCategoryGoods" parameterType="com.ghy.goods.domain.GoodsCategory" useGeneratedKeys="true"
|
||||
keyProperty="goodsCategoryId">
|
||||
insert into goods_category(
|
||||
<if test="goodsCategoryId != null and goodsCategoryId != 0">goods_category_id,</if>
|
||||
<if test="goodsCategoryCode != null and goodsCategoryCode != ''">goods_category_code,</if>
|
||||
<if test="goodsCategoryName != null and goodsCategoryName != ''">goods_category_name,</if>
|
||||
<if test="parentCategoryId != null and parentCategoryId != ''">parent_category_id,</if>
|
||||
<if test="level != null and level != ''">level,</if>
|
||||
<if test="type != null and type != ''">type,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="goodsCategoryId != null and goodsCategoryId != 0">#{goodsCategoryId},</if>
|
||||
<if test="goodsCategoryCode != null and goodsCategoryCode != ''">#{goodsCategoryCode},</if>
|
||||
<if test="goodsCategoryName != null and goodsCategoryName != ''">#{goodsCategoryName},</if>
|
||||
<if test="parentCategoryId != null and parentCategoryId != ''">#{parentCategoryId},</if>
|
||||
<if test="level != null and level != ''">#{level},</if>
|
||||
<if test="type != null and type != ''">#{type},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<select id="selectByGoodsCategoryName" parameterType="long" resultMap="GoodsCategoryResult">
|
||||
<include refid="selectGoodsCategory"/>
|
||||
WHERE goods_category_name = #{goodsCategoryName} LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectByGoodsCategoryCode" parameterType="long" resultMap="GoodsCategoryResult">
|
||||
<include refid="selectGoodsCategory"/>
|
||||
WHERE goods_category_code = #{goodsCategoryCode} LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -99,4 +99,9 @@
|
|||
where goods_code=#{goodsCode} limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectOneByGoodsCategoryId" parameterType="String" resultMap="GoodsResult">
|
||||
<include refid="selectGoods"/>
|
||||
WHERE goods_category_id = #{goodsCategoryId} LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue