package com.xzx.gc.shop.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzx.gc.common.constant.CommonEnum; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.dto.log.OperationAppLog; import com.xzx.gc.common.utils.MqUtil; import com.xzx.gc.entity.CoreUser; import com.xzx.gc.entity.ScoreGoodsCategory; import com.xzx.gc.model.JsonResult; import com.xzx.gc.model.admin.GoodsCategoryModel; import com.xzx.gc.shop.dto.QueryGoodsCategoryListDto; import com.xzx.gc.shop.mapper.ScoreGoodsCategoryMapper; import com.xzx.gc.shop.vo.QueryGoodsCategoryListVo; import com.xzx.gc.shop.vo.ViewGoodsCategoryVo; import com.xzx.gc.util.SessionUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; @Service @Transactional @Slf4j public class GoodsService { @Resource ScoreGoodsCategoryMapper scoreGoodsCategoryMapper; @Autowired private MqUtil mqUtil; public Map queryGoodsCategoryList(QueryGoodsCategoryListDto model) { String name = model.getName(); GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel(); goodsCategoryModel.setName(name); PageHelper.startPage(model.getPage(), model.getLimit()); List maps = scoreGoodsCategoryMapper.queryGoodsCategoryList(goodsCategoryModel); PageInfo pageInfo = new PageInfo(maps); int count = Convert.toInt(pageInfo.getTotal()); Map map = new HashMap<>(); map.put("data", maps); map.put("count", count); map.put("code", 0); return map; } public Long addGoodsCategory(GoodsCategoryModel model) { ScoreGoodsCategory scoreGoodsCategory = new ScoreGoodsCategory(); scoreGoodsCategory.setName(model.getName()); scoreGoodsCategory.setCategoryIden(model.getCategoryIden()); scoreGoodsCategory.setParentId(model.getParentId()); scoreGoodsCategory.setCreatedBy(model.getCreatedBy()); scoreGoodsCategory.setCreatedTime(model.getCreatedTime()); scoreGoodsCategoryMapper.insert(scoreGoodsCategory); return scoreGoodsCategory.getId(); } public void deleteGoodsCategory(long id) { scoreGoodsCategoryMapper.deleteByPrimaryKey(id); } public ViewGoodsCategoryVo viewGoodsCategoryById(long id) { ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id); ViewGoodsCategoryVo viewGoodsCategoryVo = new ViewGoodsCategoryVo(); viewGoodsCategoryVo.setId(scoreGoodsCategory.getId()); viewGoodsCategoryVo.setName(scoreGoodsCategory.getName()); viewGoodsCategoryVo.setCategoryIden(scoreGoodsCategory.getCategoryIden()); viewGoodsCategoryVo.setParentId(scoreGoodsCategory.getParentId()); return viewGoodsCategoryVo; } public void updateGoodsCategory(GoodsCategoryModel model) { long id = model.getId(); ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id); scoreGoodsCategory.setName(model.getName()); scoreGoodsCategory.setCategoryIden(model.getCategoryIden()); scoreGoodsCategory.setParentId(model.getParentId()); scoreGoodsCategoryMapper.updateByPrimaryKey(scoreGoodsCategory); } }