Merge pull request #107 from LQYBill/feat/skuToCsv

Feat/SKU to csv
pull/8040/head
Qiuyi LI 2024-09-05 11:35:59 +02:00 committed by GitHub
commit 406a609b61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package org.jeecg.modules.business.domain.job;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.business.entity.Sku;
import org.jeecg.modules.business.service.ISkuService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
public class SkuToCsvJob implements Job {
@Autowired
private ISkuService skuService;
@Value("${jeecg.path.skuCsvPath}")
private String FILE_PATH;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
log.info("SkuToCsv Job is running ...");
List<Sku> skus = new ArrayList<>();
Sku firstLine = new Sku();
firstLine.setId("#");
firstLine.setErpCode("erp_code");
firstLine.setImageSource("image_source");
skus.add(firstLine);
skus.addAll(skuService.listImgUrls());
List<String> csvLines = skus.stream()
.map(sku -> String.format("%s,%s,%s", sku.getId(), sku.getErpCode(), sku.getImageSource())).collect(Collectors.toList());
File csvFile = new File(FILE_PATH);
try (PrintWriter writer = new PrintWriter(csvFile)) {
csvLines.forEach(writer::println);
} catch (FileNotFoundException e) {
log.error("Error writing to file", e);
}
log.info("SkuToCsv Job is done.");
}
}

View File

@ -68,4 +68,6 @@ public interface SkuMapper extends BaseMapper<Sku> {
List<SkuOrderPage> getInventoryByInvoiceNumber(@Param("invoiceNumber") String invoiceNumber);
List<Sku> listByClientId(@Param("clientId") String clientId);
List<Sku> listImgUrls();
}

View File

@ -413,4 +413,11 @@
JOIN product p ON s.product_id = p.id
WHERE client_sku.client_id = #{clientId};
</select>
<select id="listImgUrls" resultType="org.jeecg.modules.business.entity.Sku">
SELECT row_number() over (
ORDER BY create_time DESC
) as id, erp_code, image_source
FROM sku
WHERE image_source IS NOT NULL
</select>
</mapper>

View File

@ -104,4 +104,6 @@ public interface ISkuService extends IService<Sku> {
void updateBatchStockByIds(List<Sku> skuToUpdate);
List<SkuOrderPage> getInventoryByInvoiceNumber(String invoiceNumber);
List<Sku> listByClientId(String clientId);
List<Sku> listImgUrls();
}

View File

@ -480,4 +480,9 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements ISkuS
return skuMapper.listByClientId(clientId);
}
@Override
public List<Sku> listImgUrls() {
return skuMapper.listImgUrls();
}
}

View File

@ -233,6 +233,8 @@ jeecg:
shippingInvoiceDetailDir: /wia/invoices/shippingDetail
shippingInvoicePdfDir: /wia/invoices/pdf/shipping
shippingInvoiceDetailPdfDir: /wia/invoices/pdf/shippingDetail
# sku csv file for image search
skuCsvPath: /mnt/wia/products/sku.csv
# CDG location
CGS: /wia/files/WIASourcingCGCVF_mai.pdf
#webapp文件路径