热门类目/类目别名/类目图片

This commit is contained in:
kuang.yife 2023-02-11 10:38:42 +08:00
parent 16b52e6339
commit 1d53ad5a51
7 changed files with 113 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import com.ghy.common.enums.BusinessType;
import com.ghy.common.enums.ImgType;
import com.ghy.common.utils.ExceptionUtil;
import com.ghy.common.utils.ShiroUtils;
import com.ghy.common.utils.StringUtils;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.domain.GoodsImgs;
import com.ghy.goods.service.DeptGoodsCategoryService;
@ -116,14 +117,18 @@ public class GoodsDeptCategoryController extends BaseController {
GoodsImgs qryImgsObj = new GoodsImgs();
qryImgsObj.setRemark(hotCategory.getDeptGoodsCategoryId().toString());
qryImgsObj.setImgType(ImgType.HOT_CATEGORY_IMG.getId());
qryImgsObj.setGoodsId(0l);
qryImgsObj.setGoodsId(0L);
List<GoodsImgs> goodsImgs = goodsImgsService.qryGoodsImgs(qryImgsObj);
hotCategory.setHotCategoryImgs(goodsImgs.stream().map(GoodsImgs::getImgUrl).collect(Collectors.toList()));
HotCategoryResponse hotCategoryResponse = new HotCategoryResponse();
BeanUtils.copyProperties(hotCategory, hotCategoryResponse);
hotCategoryResponse.setId(hotCategory.getDeptGoodsCategoryId());
hotCategoryResponse.setName(hotCategory.getGoodsCategoryName());
if(StringUtils.isNotEmpty(hotCategory.getHotName())){
hotCategoryResponse.setName(hotCategory.getHotName());
}else {
hotCategoryResponse.setName(hotCategory.getGoodsCategoryName());
}
hotCategoryResponse.setDesc(hotCategory.getRemark());
hotCategoryResponse.setImgs(hotCategory.getHotCategoryImgs());
responses.add(hotCategoryResponse);

View File

@ -11,6 +11,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 七牛云
@ -42,4 +46,28 @@ public class QiniuController {
}
}
/**
* 七牛云上传单个
*/
@PostMapping(value = "/dept/upload")
@ResponseBody
@ApiOperation("七牛云上传接口")
public AjaxResult uploadFile(HttpServletRequest request, HttpServletResponse response) {
try {
String name = request.getParameter("name");
// 转型为MultipartHttpRequest
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获得实际
MultipartFile file= multipartRequest.getFile(name);
// 上传后返回的文件路径
String fileUrl = QiniuUtils.upload(file.getBytes());
logger.info("upload return url is : " + fileUrl);
AjaxResult ajax = AjaxResult.success();
ajax.put("url", fileUrl);
return ajax;
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
}

View File

@ -2,6 +2,7 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('类目列表')"/>
<th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
@ -144,7 +145,7 @@
formatter: function (value, row, index) {
if (row.parentId !== 0) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deptGoodsCategoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.deptGoodsCategoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
// actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.deptGoodsCategoryId + '\')"><i class="fa fa-plus"></i>新增</a> ');
// actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.deptGoodsCategoryId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');

View File

@ -126,11 +126,31 @@
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-3 control-label">热门名称:</label>
<div class="col-sm-9">
<input name="hotName" placeholder="请输入热门名称" class="form-control" type="text" maxlength="12"
th:field="*{hotName}">
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">热门类目图片:</label>
<div class="col-sm-8">
<input type="text" name="categoryUrl" value="" hidden>
<input type="file" name="categoryUrlImg" id="categoryUrlImg" multiple class="file" />
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript">
var prefix = ctx + "goods/deptcategory";
@ -150,6 +170,34 @@
}
}
// 商品封面上传
$('#categoryUrlImg').fileinput({
language: 'zh', //设置语言
dropZoneEnabled: false, //是否显示拖拽区域
showPreview: false,
uploadExtraData: {
"name": "categoryUrlImg"
},
dropZoneTitle: "可以将图片拖放到这里", //拖拽区域显示文字
uploadUrl: ctx + 'tool/qiniu/dept/upload', //上传路径
allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg'], //指定上传文件类型
maxFileSize: 0,
maxFileSize: 12048, //上传文件最大值单位kb
uploadAsync: true, //异步上传
maxFileCount: 3 //上传文件最大个数。
}).on("fileuploaded", function(event,data) { //异步上传成功后回调
if(data.response.code === 0){
var imgUrl = $("input[name='categoryUrl']").val();
if(imgUrl){
$("input[name='categoryUrl']").val( imgUrl + "," + data.response.url)
}else {
$("input[name='categoryUrl']").val(data.response.url)
}
}else {
alert("上传失败!");
}
});
</script>
</body>
</html>

View File

@ -27,6 +27,8 @@ public class DeptGoodsCategory extends GoodsCategory {
@Excel(name = "是否热门类目 0.不是,1.是", cellType = Excel.ColumnType.NUMERIC)
private Integer isHot;
private String hotName;
@Excel(name = "一级分销扣点比例", cellType = Excel.ColumnType.STRING)
private String oneRate;
@ -64,4 +66,9 @@ public class DeptGoodsCategory extends GoodsCategory {
private Boolean isAllNode;
private List<String> hotCategoryImgs;
private String categoryUrl;
private String hotCategoryName;
}

View File

@ -7,9 +7,11 @@ import com.ghy.common.core.text.Convert;
import com.ghy.common.utils.StringUtils;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.domain.GoodsImgs;
import com.ghy.goods.mapper.DeptGoodsCategoryMapper;
import com.ghy.goods.service.DeptGoodsCategoryService;
import com.ghy.goods.service.GoodsCategoryService;
import com.ghy.goods.service.GoodsImgsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -31,6 +33,8 @@ public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService {
private GoodsCategoryService goodsCategoryService;
@Resource
private DeptGoodsCategoryMapper deptGoodsCategoryMapper;
@Resource
private GoodsImgsService goodsImgsService;
@Override
public List<DeptGoodsCategory> list(DeptGoodsCategory category) {
@ -44,6 +48,19 @@ public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService {
@Override
public int edit(DeptGoodsCategory deptGoodsCategory) {
if(StringUtils.isNotEmpty(deptGoodsCategory.getCategoryUrl())){
String[] split = deptGoodsCategory.getCategoryUrl().split(",");
List<GoodsImgs> list = new ArrayList<>();
for (String url : split){
GoodsImgs goodsImgs = new GoodsImgs();
goodsImgs.setGoodsId(0L);
goodsImgs.setImgUrl(url);
goodsImgs.setImgType(3);
goodsImgs.setRemark(String.valueOf(deptGoodsCategory.getDeptGoodsCategoryId()));
list.add(goodsImgs);
}
goodsImgsService.batchInsert(list);
}
return deptGoodsCategoryMapper.updateDeptGoodsCategory(deptGoodsCategory);
}

View File

@ -16,6 +16,7 @@
<result property="type" column="type" />
<result property="categorySort" column="category_sort"/>
<result property="isHot" column="is_hot"/>
<result property="hotName" column="hot_name"/>
<result property="oneRate" column="one_rate"/>
<result property="twoRate" column="two_rate"/>
<result property="threeRate" column="three_rate"/>
@ -31,7 +32,7 @@
</resultMap>
<sql id="selectDeptGoodsCategory">
SELECT dept_goods_category_id, dept_id, goods_category_id, category_sort, is_hot,
SELECT dept_goods_category_id, dept_id, goods_category_id, category_sort, is_hot, hot_name,
one_rate, two_rate, three_rate, dept_rate, dept_money, retain_rate, retain_money, create_by, create_time, remark
FROM dept_goods_category
</sql>
@ -39,7 +40,7 @@
<sql id="selectJoin">
SELECT dgc.dept_goods_category_id, dgc.dept_id, dgc.goods_category_id, dgc.category_sort,
dgc.one_rate, dgc.two_rate, dgc.three_rate, dgc.create_by, dgc.create_time, dgc.remark,
dgc.is_hot, dgc.dept_rate, dgc.dept_money, dgc.retain_rate, dgc.retain_money,
dgc.is_hot, dgc.hot_name, dgc.dept_rate, dgc.dept_money, dgc.retain_rate, dgc.retain_money,
dgc.dept_category_name, gc.goods_category_name, gc.level, gc.parent_category_id, gc.type, gc.status,
gc.cover, gc.simple_goods_category_name
FROM dept_goods_category dgc LEFT JOIN goods_category gc ON dgc.goods_category_id = gc.goods_category_id
@ -67,6 +68,7 @@
<set>
<if test="deptCategoryName != null and deptCategoryName != ''">dept_category_name = #{deptCategoryName},</if>
<if test="isHot != null">is_hot = #{isHot},</if>
<if test="hotName != null">hot_name = #{hotName},</if>
<if test="deptRate != null and deptRate != ''">dept_rate = #{deptRate},</if>
<if test="deptMoney != null and deptMoney != ''">dept_money = #{deptMoney},</if>
<if test="retainRate != null and retainRate != ''">retain_rate = #{retainRate},</if>