GoodsStandard

This commit is contained in:
HH 2022-06-14 22:11:06 +08:00
parent 72e255338d
commit d3af40e1a2
8 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package com.ghy.web.controller.goods;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.page.TableDataInfo;
import com.ghy.goods.domain.GoodsStandard;
import com.ghy.goods.service.GoodsStandardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("goods/standard")
public class GoodsStandardController extends BaseController {
private static final String PREFIX = "goods/standard";
@Resource
private GoodsStandardService goodsStandardService;
@RequiresPermissions("goods:standard:view")
@GetMapping
public String goodsStandard(Long goodsId, ModelMap mmap) {
List<GoodsStandard> goodsStandardList = goodsStandardService.selectByGoodsId(goodsId);
mmap.put("goodsStandardList", goodsStandardList);
return PREFIX + "/goodsStandard";
}
@ResponseBody
@RequestMapping("list")
public TableDataInfo list(Long goodsId) {
startPage();
List<GoodsStandard> list = goodsStandardService.selectByGoodsId(goodsId);
return getDataTable(list);
}
/**
* 全量保存
*/
@ResponseBody
@PostMapping("save")
public AjaxResult save(@RequestBody List<GoodsStandard> goodsStandardList) {
return toAjax(goodsStandardService.save(goodsStandardList));
}
}

View File

@ -1131,6 +1131,11 @@ var table = {
$.modal.open("修改" + table.options.modalName, $.operate.editUrl(id)); $.modal.open("修改" + table.options.modalName, $.operate.editUrl(id));
} }
}, },
// 修改商品规格
goodsStandards: function(goodsId) {
table.set();
$.modal.open("修改商品规格", "/goods/standard?goodsId=" + goodsId);
},
// 修改信息以tab页展现 // 修改信息以tab页展现
editTab: function(id) { editTab: function(id) {
table.set(); table.set();

View File

@ -118,6 +118,7 @@
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="disable(\'' + row.goodsId + '\')"><i class="fa fa-arrow-down"></i>下架</a> '); actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="disable(\'' + row.goodsId + '\')"><i class="fa fa-arrow-down"></i>下架</a> ');
} }
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> '); actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.goodsStandards(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>商品规格</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>'); actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join(''); return actions.join('');
} }

View File

@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('修改商品规格')"/>
<th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
<form class="form-horizontal" id="form-goods-edit" th:object="${goodsStandardList}">
<!-- 遍历goodsStandardList -->
<th:block th:each="goodsStandard : ${goodsStandardList}" th:key="${goodsStandard.goodsStandardId}">
<div class="row">
<input id="goodsId" name="goodsId" type="hidden" th:field="*{goodsStandard.goodsId}"/>
<div class="form-group" th:each="goodsStandard : ${goodsStandardList}">
<label class="col-sm-2 control-label">规格名称</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="goodsStandardName"
th:field="*{goodsStandard.goodsStandardName}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">商品价格</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="goodsPrice"
th:field="*{goodsStandard.goodsPrice}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">优惠价</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="discountPrice"
th:field="*{goodsStandard.discountPrice}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">团购价</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="groupPrice"
th:field="*{goodsStandard.groupPrice}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">库存</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="goodsNum"
th:field="*{goodsStandard.goodsNum}"/>
</div>
</div>
</div>
</th:block>
</form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
const prefix = ctx + "goods/standard";
</script>
</body>
</html>

View File

@ -9,6 +9,7 @@ import java.util.List;
/** /**
* 商品规格 * 商品规格
*
* @author clunt * @author clunt
*/ */
public interface GoodsStandardMapper { public interface GoodsStandardMapper {
@ -45,4 +46,10 @@ public interface GoodsStandardMapper {
*/ */
List<GoodsStandard> checkStore(AppGoodsRequest request); List<GoodsStandard> checkStore(AppGoodsRequest request);
/**
* 用商品ID删除商品规格
*
* @param goodsId 商品ID
*/
int deleteByGoodsId(Long goodsId);
} }

View File

@ -8,6 +8,7 @@ import java.util.List;
/** /**
* 商品规格service层 * 商品规格service层
*
* @author clunt * @author clunt
*/ */
public interface GoodsStandardService { public interface GoodsStandardService {
@ -45,4 +46,8 @@ public interface GoodsStandardService {
*/ */
List<GoodsStandard> checkStore(AppGoodsRequest request); List<GoodsStandard> checkStore(AppGoodsRequest request);
/**
* 全量保存
*/
int save(List<GoodsStandard> goodsStandardList);
} }

View File

@ -6,14 +6,18 @@ import com.ghy.goods.request.AppGoodsRequest;
import com.ghy.goods.service.GoodsStandardService; import com.ghy.goods.service.GoodsStandardService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 商品规格impl层 * 商品规格impl层
*
* @author clunt * @author clunt
*/ */
@Slf4j @Slf4j
@ -53,4 +57,14 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
return goodsStandardMapper.checkStore(request); return goodsStandardMapper.checkStore(request);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public int save(List<GoodsStandard> goodsStandardList) {
Set<Long> goodsIds = goodsStandardList.stream().map(GoodsStandard::getGoodsId).collect(Collectors.toSet());
Assert.isTrue(goodsIds.size() == 1, "商品规格保存失败商品id不一致");
Long goodsId = goodsIds.iterator().next();
goodsStandardMapper.deleteByGoodsId(goodsId);
return goodsStandardMapper.batchInsert(goodsStandardList);
}
} }

View File

@ -93,4 +93,9 @@
where goods_standard_id = #{goodsStandardId} where goods_standard_id = #{goodsStandardId}
and goods_num >= #{num} and goods_num >= #{num}
</select> </select>
<delete id="deleteByGoodsId" parameterType="Long">
DELETE FROM goods_standard
WHERE goods_id = #{goodsId}
</delete>
</mapper> </mapper>