feature: product list page with editing feature

pull/6221/head
Gauthier LO 2023-08-04 12:43:45 +02:00
parent 710540a1c6
commit 255e304fd3
6 changed files with 54 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.modules.business.vo.ProductsParam;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
@ -260,4 +261,16 @@ public class ProductController {
return Result.OK("文件导入失败!");
}
@PostMapping(value="/editBatch")
public Result<?> editBatch(@RequestBody ProductsParam productsParam) {
List<Product> products = new ArrayList<>();
for(String id : productsParam.getIds()) {
Product product = new Product();
product.setId(id);
product.setWeight(productsParam.getWeight());
products.add(product);
}
productService.updateWeightBatch(products);
return Result.ok("Updated all products");
}
}

View File

@ -1,8 +1,11 @@
package org.jeecg.modules.business.mapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.business.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/**
* @Description:
* @Author: jeecg-boot
@ -10,5 +13,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @Version: V1.0
*/
public interface ProductMapper extends BaseMapper<Product> {
void updateWeightBatch(@Param("products") List<Product> product);
}

View File

@ -1,5 +1,17 @@
<?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">
<mapper namespace="org.jeecg.modules.business.mapper.ProductMapper">
<update id="updateWeightBatch">
UPDATE product p
SET p.update_time = NOW(),
weight = case id
<foreach collection="products" separator=" " open="" close="" index="index" item="item">
when #{item.id} then #{item.weight}
</foreach>
end
where id in
<foreach collection="products" separator="," open="(" close=")" index="index" item="item">
#{item.id}
</foreach>
</update>
</mapper>

View File

@ -36,5 +36,6 @@ public interface IProductService extends IService<Product> {
*
*/
public void delBatchMain (Collection<? extends Serializable> idList);
public void updateWeightBatch (List<Product> productList);
}

View File

@ -73,5 +73,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
productMapper.deleteById(id);
}
}
@Override
@Transactional
public void updateWeightBatch (List<Product> productList) {
productMapper.updateWeightBatch(productList);
}
}

View File

@ -0,0 +1,16 @@
package org.jeecg.modules.business.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class ProductsParam {
private final List<String> ids;
private final int weight;
public ProductsParam(@JsonProperty("ids") List<String> ids, @JsonProperty("weight") int weight){
this.ids = ids;
this.weight = weight;
}
public List<String> getIds() { return ids; }
public int getWeight() { return weight; }
}