mirror of https://github.com/jeecgboot/jeecg-boot
feature: product list page with editing feature
parent
710540a1c6
commit
255e304fd3
|
@ -10,6 +10,7 @@ import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.jeecg.modules.business.vo.ProductsParam;
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||||
|
@ -260,4 +261,16 @@ public class ProductController {
|
||||||
return Result.OK("文件导入失败!");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package org.jeecg.modules.business.mapper;
|
package org.jeecg.modules.business.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.jeecg.modules.business.entity.Product;
|
import org.jeecg.modules.business.entity.Product;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 商品
|
* @Description: 商品
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
|
@ -10,5 +13,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
* @Version: V1.0
|
* @Version: V1.0
|
||||||
*/
|
*/
|
||||||
public interface ProductMapper extends BaseMapper<Product> {
|
public interface ProductMapper extends BaseMapper<Product> {
|
||||||
|
void updateWeightBatch(@Param("products") List<Product> product);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!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">
|
<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>
|
</mapper>
|
|
@ -36,5 +36,6 @@ public interface IProductService extends IService<Product> {
|
||||||
* 批量删除一对多
|
* 批量删除一对多
|
||||||
*/
|
*/
|
||||||
public void delBatchMain (Collection<? extends Serializable> idList);
|
public void delBatchMain (Collection<? extends Serializable> idList);
|
||||||
|
|
||||||
|
public void updateWeightBatch (List<Product> productList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,5 +73,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||||
productMapper.deleteById(id);
|
productMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void updateWeightBatch (List<Product> productList) {
|
||||||
|
productMapper.updateWeightBatch(productList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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; }
|
||||||
|
}
|
Loading…
Reference in New Issue