This commit is contained in:
kuang.yifei@iwhalecloud.com 2022-06-10 16:44:26 +08:00
commit 297e441c75
2 changed files with 49 additions and 14 deletions

View File

@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/goods/goods")
@ -43,13 +42,13 @@ public class GoodsController extends BaseController {
return PREFIX + "/goods";
}
// @RequiresPermissions("goods:goods:list")
// @RequiresPermissions("goods:goods:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(@RequestBody Goods goods) {
public TableDataInfo list(Goods goods) {
startPage();
List<Goods> list = goodsService.selectGoodsList(goods);
list.forEach(one->{
list.forEach(one -> {
// 补全商品
List<GoodsArea> goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId());
one.setGoodsAreaList(goodsAreas);
@ -70,13 +69,13 @@ public class GoodsController extends BaseController {
deptGoodsCategory.setLevel(2);
List<DeptGoodsCategory> categoryList = deptGoodsCategoryService.list(deptGoodsCategory);
Collection<Long> ids = new ArrayList<>();
categoryList.forEach(category->{
categoryList.forEach(category -> {
ids.add(category.getGoodsCategoryId());
});
startPage();
List<Goods> list = goodsService.selectByCategoryIds(ids);
list.forEach(one->{
list.forEach(one -> {
// 补全商品
List<GoodsArea> goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId());
one.setGoodsAreaList(goodsAreas);
@ -90,11 +89,11 @@ public class GoodsController extends BaseController {
@PostMapping("/addGoods")
@ResponseBody
public AjaxResult addGoods(@RequestBody Goods goods){
public AjaxResult addGoods(@RequestBody Goods goods) {
try {
goodsService.addGoods(goods);
return AjaxResult.success("新增成功");
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
@ -103,7 +102,7 @@ public class GoodsController extends BaseController {
@PostMapping("/getDetail")
@ResponseBody
public AjaxResult getDetail(@RequestBody Goods goods){
public AjaxResult getDetail(@RequestBody Goods goods) {
try {
Goods result = goodsService.selectById(goods.getGoodsId());
@ -124,7 +123,7 @@ public class GoodsController extends BaseController {
result.setGoodsStandardList(goodsStandards);
return AjaxResult.success(result);
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
@ -222,4 +221,25 @@ public class GoodsController extends BaseController {
return goodsService.checkGoodsCodeUnique(goods);
}
/**
* 修改商品状态
*
* @param goodsId 商品ID
* @param status 0=上架,1=下架,2删除
*/
@PostMapping("/status")
@ResponseBody
public AjaxResult status(Long goodsId, Integer status) {
try {
Goods goods = new Goods();
goods.setGoodsId(goodsId);
goods.setStatus(status);
goodsService.updateGoods(goods);
return AjaxResult.success("操作成功");
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
}
}
}

View File

@ -16,7 +16,7 @@
<li>
类目状态:<select name="status" th:with="type=${@dict.getType('goods_status')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" />
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"/>
</select>
</li>
<li>
@ -34,9 +34,9 @@
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="goods:goods:add">
<i class="fa fa-plus"></i> 新增
</a>
<!-- <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:goods:edit">-->
<!-- <i class="fa fa-edit"></i> 修改-->
<!-- </a>-->
<!-- <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:goods:edit">-->
<!-- <i class="fa fa-edit"></i> 修改-->
<!-- </a>-->
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table"></table>
@ -111,6 +111,12 @@
align: 'left',
formatter: function (value, row, index) {
var actions = [];
if (row.status === 1) {
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="enable(\'' + row.goodsId + '\')"><i class="fa fa-arrow-up"></i>上架</a> ');
}
if (row.status === 0) {
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-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');
@ -119,6 +125,15 @@
};
$.table.init(options);
});
function enable(goodsId) {
$.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" + 0);
}
function disable(goodsId) {
$.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" + 1);
}
</script>
</body>
</html>