Merge pull request #132 from LQYBill/feat/ydhDeleteTracking

fix: sku weight export effective date format
pull/8040/head
Qiuyi LI 2025-02-18 11:42:25 +01:00 committed by GitHub
commit 210a2de464
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 57 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -17,6 +18,7 @@ import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.business.entity.Sku;
import org.jeecg.modules.business.entity.SkuWeight;
import org.jeecg.modules.business.mongoService.SkuMongoService;
@ -69,9 +71,12 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
private ISecurityService securityService;
@Autowired
private SkuMongoService skuMongoService;
@Resource
private JeecgBaseConfig jeecgBaseConfig;
private final static Integer NUMBER_OF_SKU_EXCEL_COLUMNS = 3;
private final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
*
*
@ -159,23 +164,28 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
/**
* excel
*
* @param skuIds
* @param request
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(@RequestParam(value = "selections[]", required = false) List<String> skuIds) {
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;
public ModelAndView exportXls(HttpServletRequest request) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<String> selections = new ArrayList<>();
request.getParameterMap().forEach((k,v) -> {
if(k.equals("selections[]")) {
selections.addAll(Arrays.asList(v));
}
});
List<SkuWeight> exportList = skuWeightService.exportToExcel(selections);
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
mv.addObject(NormalExcelConstants.FILE_NAME, "SKU重量");
mv.addObject(NormalExcelConstants.CLASS, SkuWeight.class);
ExportParams exportParams=new ExportParams("SKU重量报表", "导出人:" + sysUser.getRealname(), "SKU重量");
exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
mv.addObject(NormalExcelConstants.PARAMS,exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
return mv;
}
/**
@ -185,7 +195,7 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
* @param response
* @return
*/
@Transactional
@Transactional
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
log.info("Importing Sku weights from Excel...");

View File

@ -69,7 +69,9 @@ public class SkuWeight implements Serializable {
/**
*
*/
@Excel(name = "生效日期", width = 15)
@JsonFormat(timezone = "GMT+2", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "生效日期", width = 15, format = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "生效日期")
private java.util.Date effectiveDate;
}

View File

@ -20,7 +20,10 @@ public interface SkuWeightMapper extends BaseMapper<SkuWeight> {
String searchFirstEmptyWeightSku(@Param("skuIds") List<String> skuIds);
List<SkuWeight> exportToExcel(@Param("skuIds") List<String> skuIds);
List<SkuWeightPage> listLatestWeights();
List<SkuWeightPage> listLatestWeightForSkus(@Param("skuIds") List<String> skuIds);
}

View File

@ -62,4 +62,23 @@
</foreach>
ORDER BY erp_code;
</select>
<select id="exportToExcel" resultType="org.jeecg.modules.business.entity.SkuWeight">
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 sw
)
SELECT s.erp_code as sku_id, lsw.weight, lsw.effective_date
FROM latestSkuWeights lsw
JOIN sku s ON s.id = lsw.sku_id
WHERE lsw.sku_id IN
<foreach collection="skuIds" separator="," open="(" close=")" index="index" item="id">
#{id}
</foreach>
AND lsw.rn = 1;
</select>
</mapper>

View File

@ -17,6 +17,7 @@ public interface ISkuWeightService extends IService<SkuWeight> {
String searchFirstEmptyWeightSku(List<String> skuIds);
List<SkuWeight> exportToExcel(List<String> skuIds);
/**
* used to export all latest weights for front, so instead of fetching skuId, we fetch erpCode
* @return

View File

@ -34,6 +34,11 @@ public class SkuWeightServiceImpl extends ServiceImpl<SkuWeightMapper, SkuWeight
return skuWeightMapper.searchFirstEmptyWeightSku(skuIds);
}
@Override
public List<SkuWeight> exportToExcel(List<String> skuIds) {
return skuWeightMapper.exportToExcel(skuIds);
}
@Override
public List<SkuWeightPage> listLatestWeights() {
return skuWeightMapper.listLatestWeights();