mirror of https://github.com/jeecgboot/jeecg-boot
feat : export sku weight via Excel, fix log for front
parent
b23a273b89
commit
da932802d7
|
@ -32,9 +32,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
||||||
import org.jeecg.modules.business.vo.Responses;
|
import org.jeecg.modules.business.vo.Responses;
|
||||||
|
import org.jeecg.modules.business.vo.SkuWeightPage;
|
||||||
import org.jeecg.modules.business.vo.SkuWeightParam;
|
import org.jeecg.modules.business.vo.SkuWeightParam;
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||||
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -157,12 +159,23 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
|
||||||
/**
|
/**
|
||||||
* 导出excel
|
* 导出excel
|
||||||
*
|
*
|
||||||
* @param request
|
* @param skuIds
|
||||||
* @param skuWeight
|
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/exportXls")
|
@RequestMapping(value = "/exportXls")
|
||||||
public ModelAndView exportXls(HttpServletRequest request, SkuWeight skuWeight) {
|
public ModelAndView exportXls(@RequestParam(value = "selections[]", required = false) List<String> skuIds) {
|
||||||
return super.exportXls(request, skuWeight, SkuWeight.class, "sku_weight");
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
List<SkuWeightPage> skuWeightList;
|
||||||
|
if (skuIds == null || skuIds.isEmpty()) {
|
||||||
|
skuWeightList = skuWeightService.listLatestWeights();
|
||||||
|
} else {
|
||||||
|
skuWeightList = skuWeightService.listLatestWeightForSkus(skuIds);
|
||||||
|
}
|
||||||
|
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||||
|
mv.addObject(NormalExcelConstants.FILE_NAME, "SKU重量列表");
|
||||||
|
mv.addObject(NormalExcelConstants.CLASS, SkuWeightPage.class);
|
||||||
|
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("SKU重量数据", "导出人:" + sysUser.getRealname(), "SKU重量"));
|
||||||
|
mv.addObject(NormalExcelConstants.DATA_LIST, skuWeightList);
|
||||||
|
return mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -313,7 +326,10 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
|
||||||
List<SkuWeight> skuWeights = new ArrayList<>(skuWeightsMap.values());
|
List<SkuWeight> skuWeights = new ArrayList<>(skuWeightsMap.values());
|
||||||
Responses responses = skuListMabangService.mabangSkuWeightUpdate(skuWeights);
|
Responses responses = skuListMabangService.mabangSkuWeightUpdate(skuWeights);
|
||||||
List<SkuWeight> skuWeightSuccesses = new ArrayList<>();
|
List<SkuWeight> skuWeightSuccesses = new ArrayList<>();
|
||||||
responses.getSuccesses().forEach(skuErpCode -> skuWeightSuccesses.add(skuWeightsMap.get(skuErpCode)));
|
responses.getSuccesses().forEach(skuErpCode -> {
|
||||||
|
String erpCode = skuErpCode.split(":")[0].trim();
|
||||||
|
skuWeightSuccesses.add(skuWeightsMap.get(erpCode));
|
||||||
|
});
|
||||||
|
|
||||||
skuWeightSuccesses.forEach(skuWeight -> skuMongoService.upsertSkuWeight(skuWeight));
|
skuWeightSuccesses.forEach(skuWeight -> skuMongoService.upsertSkuWeight(skuWeight));
|
||||||
skuWeightService.saveBatch(skuWeights);
|
skuWeightService.saveBatch(skuWeights);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.jeecg.modules.business.entity.SkuWeight;
|
import org.jeecg.modules.business.entity.SkuWeight;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.jeecg.modules.business.vo.SkuWeightPage;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,4 +19,8 @@ public interface SkuWeightMapper extends BaseMapper<SkuWeight> {
|
||||||
SkuWeight getBySkuId(@Param("skuId") String skuId);
|
SkuWeight getBySkuId(@Param("skuId") String skuId);
|
||||||
|
|
||||||
String searchFirstEmptyWeightSku(@Param("skuIds") List<String> skuIds);
|
String searchFirstEmptyWeightSku(@Param("skuIds") List<String> skuIds);
|
||||||
|
|
||||||
|
List<SkuWeightPage> listLatestWeights();
|
||||||
|
|
||||||
|
List<SkuWeightPage> listLatestWeightForSkus(@Param("skuIds") List<String> skuIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,42 @@
|
||||||
)
|
)
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
</select>
|
</select>
|
||||||
|
<select id="listLatestWeights" resultType="org.jeecg.modules.business.vo.SkuWeightPage">
|
||||||
|
WITH latestSkuWeights AS (
|
||||||
|
SELECT
|
||||||
|
sku_id,
|
||||||
|
weight,
|
||||||
|
effective_date,
|
||||||
|
ROW_NUMBER() OVER (PARTITION BY sku_id ORDER BY effective_date DESC) AS rn
|
||||||
|
FROM sku_weight
|
||||||
|
)
|
||||||
|
SELECT s.erp_code,
|
||||||
|
lsw.effective_date,
|
||||||
|
lsw.weight
|
||||||
|
FROM sku s
|
||||||
|
LEFT JOIN latestSkuWeights lsw ON s.id = lsw.sku_id AND lsw.rn = 1
|
||||||
|
WHERE s.status = 3
|
||||||
|
ORDER BY erp_code;
|
||||||
|
</select>
|
||||||
|
<select id="listLatestWeightForSkus" resultType="org.jeecg.modules.business.vo.SkuWeightPage">
|
||||||
|
WITH latestSkuWeights AS (
|
||||||
|
SELECT
|
||||||
|
sku_id,
|
||||||
|
weight,
|
||||||
|
effective_date,
|
||||||
|
ROW_NUMBER() OVER (PARTITION BY sku_id ORDER BY effective_date DESC) AS rn
|
||||||
|
FROM sku_weight
|
||||||
|
)
|
||||||
|
SELECT s.erp_code,
|
||||||
|
lsw.effective_date,
|
||||||
|
lsw.weight
|
||||||
|
FROM sku s
|
||||||
|
LEFT JOIN latestSkuWeights lsw ON s.id = lsw.sku_id AND lsw.rn = 1
|
||||||
|
WHERE s.status = 3
|
||||||
|
AND sku_id IN
|
||||||
|
<foreach collection="skuIds" item="skuId" open="(" separator="," close=")">
|
||||||
|
#{skuId}
|
||||||
|
</foreach>
|
||||||
|
ORDER BY erp_code;
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
|
@ -2,6 +2,7 @@ package org.jeecg.modules.business.service;
|
||||||
|
|
||||||
import org.jeecg.modules.business.entity.SkuWeight;
|
import org.jeecg.modules.business.entity.SkuWeight;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.jeecg.modules.business.vo.SkuWeightPage;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -15,4 +16,12 @@ public interface ISkuWeightService extends IService<SkuWeight> {
|
||||||
SkuWeight getBySkuId(String skuId);
|
SkuWeight getBySkuId(String skuId);
|
||||||
|
|
||||||
String searchFirstEmptyWeightSku(List<String> skuIds);
|
String searchFirstEmptyWeightSku(List<String> skuIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to export all latest weights for front, so instead of fetching skuId, we fetch erpCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SkuWeightPage> listLatestWeights();
|
||||||
|
|
||||||
|
List<SkuWeightPage> listLatestWeightForSkus(List<String> skuIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.modules.business.entity.SkuWeight;
|
import org.jeecg.modules.business.entity.SkuWeight;
|
||||||
import org.jeecg.modules.business.mapper.SkuWeightMapper;
|
import org.jeecg.modules.business.mapper.SkuWeightMapper;
|
||||||
import org.jeecg.modules.business.service.ISkuWeightService;
|
import org.jeecg.modules.business.service.ISkuWeightService;
|
||||||
|
import org.jeecg.modules.business.vo.SkuWeightPage;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -32,4 +33,14 @@ public class SkuWeightServiceImpl extends ServiceImpl<SkuWeightMapper, SkuWeight
|
||||||
public String searchFirstEmptyWeightSku(List<String> skuIds) {
|
public String searchFirstEmptyWeightSku(List<String> skuIds) {
|
||||||
return skuWeightMapper.searchFirstEmptyWeightSku(skuIds);
|
return skuWeightMapper.searchFirstEmptyWeightSku(skuIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SkuWeightPage> listLatestWeights() {
|
||||||
|
return skuWeightMapper.listLatestWeights();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SkuWeightPage> listLatestWeightForSkus(List<String> skuIds) {
|
||||||
|
return skuWeightMapper.listLatestWeightForSkus(skuIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.jeecg.modules.business.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel(value = "sku_weight Page对象", description = "SKU重量")
|
||||||
|
|
||||||
|
public class SkuWeightPage {
|
||||||
|
@Excel(name = "ERP中商品代码", width = 15)
|
||||||
|
@ApiModelProperty(value = "ERP中商品代码")
|
||||||
|
private String erpCode;
|
||||||
|
@Excel(name = "重量", width = 15)
|
||||||
|
@ApiModelProperty(value = "重量")
|
||||||
|
private Integer weight;
|
||||||
|
@Excel(name = "生效日期", width = 15)
|
||||||
|
@ApiModelProperty(value = "生效日期")
|
||||||
|
private Date effectiveDate;
|
||||||
|
}
|
Loading…
Reference in New Issue