mirror of https://github.com/jeecgboot/jeecg-boot
Merge pull request #18 from LQYBill/feature/weightEdit
feature: product list page with editing featurepull/6221/head
commit
846f75b10d
1100
hs_err_pid12060.log
1100
hs_err_pid12060.log
File diff suppressed because one or more lines are too long
|
@ -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,18 @@ public class ProductController {
|
|||
return Result.OK("文件导入失败!");
|
||||
}
|
||||
|
||||
@PostMapping(value="/editBatch")
|
||||
public Result<?> editBatch(@RequestBody ProductsParam productsParam) {
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
List<Product> products = new ArrayList<>();
|
||||
for(String id : productsParam.getIds()) {
|
||||
Product product = new Product();
|
||||
product.setId(id);
|
||||
product.setWeight(productsParam.getWeight());
|
||||
product.setUpdateBy(sysUser.getUsername());
|
||||
products.add(product);
|
||||
}
|
||||
productService.updateWeightBatch(products);
|
||||
return Result.ok("Updated all products");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
<?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,
|
||||
update_by = case id
|
||||
<foreach collection="products" separator=" " open="" close="" index="index" item="item">
|
||||
when #{item.id} then #{item.updateBy}
|
||||
</foreach>
|
||||
end
|
||||
where id in
|
||||
<foreach collection="products" separator="," open="(" close=")" index="index" item="item">
|
||||
#{item.id}
|
||||
</foreach>
|
||||
</update>
|
||||
</mapper>
|
|
@ -36,5 +36,6 @@ public interface IProductService extends IService<Product> {
|
|||
* 批量删除一对多
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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