mirror of https://github.com/jeecgboot/jeecg-boot
Merge remote-tracking branch 'origin/dev' into dev
commit
47bd8e83b5
|
@ -1,9 +1,18 @@
|
|||
package org.jeecg.modules.business.controller.admin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
|
@ -24,9 +33,13 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.modules.business.vo.Responses;
|
||||
import org.jeecg.modules.business.vo.SkuWeightParam;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
@ -54,7 +67,9 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
|
|||
private ISecurityService securityService;
|
||||
@Autowired
|
||||
private SkuMongoService skuMongoService;
|
||||
|
||||
|
||||
private final static Integer NUMBER_OF_SKU_EXCEL_COLUMNS = 3;
|
||||
private final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
|
@ -145,7 +160,6 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
|
|||
* @param request
|
||||
* @param skuWeight
|
||||
*/
|
||||
@RequiresPermissions("business:sku_weight:exportXls")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, SkuWeight skuWeight) {
|
||||
return super.exportXls(request, skuWeight, SkuWeight.class, "sku_weight");
|
||||
|
@ -158,10 +172,84 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
|
|||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("business:sku_weight:importExcel")
|
||||
@Transactional
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, SkuWeight.class);
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
log.info("Importing Sku weights from Excel...");
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
|
||||
Responses responses = new Responses();
|
||||
List<SkuWeight> skuWeights = new ArrayList<>();
|
||||
Map<String, SkuWeight> skuWeightMappedByErpCode = new HashMap<>();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();
|
||||
try (InputStream inputStream = file.getInputStream()){
|
||||
Workbook workbook = new XSSFWorkbook(inputStream);
|
||||
for (Sheet sheet : workbook) {
|
||||
int firstRow = sheet.getFirstRowNum();
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
for (int rowIndex = firstRow + 1; rowIndex <= lastRow; rowIndex++) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
SkuWeight skuWeight = new SkuWeight();
|
||||
boolean hasError = false;
|
||||
String erpCode = null;
|
||||
for (int cellIndex = row.getFirstCellNum(); cellIndex < NUMBER_OF_SKU_EXCEL_COLUMNS; cellIndex++) {
|
||||
Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
String cellValue = cell.getStringCellValue();
|
||||
if(hasError) continue;
|
||||
if(cellValue.isEmpty()){
|
||||
responses.addFailure("Row " + rowIndex + " has empty cell at index " + cellIndex);
|
||||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
switch (cellIndex) {
|
||||
case 0:
|
||||
Sku sku = skuService.getByErpCode(cellValue);
|
||||
if(sku == null){
|
||||
responses.addFailure("Row " + rowIndex + " SKU not found : " + cellValue);
|
||||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
erpCode = cellValue;
|
||||
skuWeight.setSkuId(sku.getId());
|
||||
break;
|
||||
case 1:
|
||||
skuWeight.setWeight((int) Double.parseDouble(cellValue));
|
||||
break;
|
||||
case 2:
|
||||
Date effectiveDate = formatter.parse(cellValue);
|
||||
skuWeight.setEffectiveDate(effectiveDate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(hasError) continue;
|
||||
skuWeights.add(skuWeight);
|
||||
assert erpCode != null;
|
||||
skuWeightMappedByErpCode.put(erpCode, skuWeight);
|
||||
}
|
||||
}
|
||||
log.info("Import weights for skus: {}", skuWeightMappedByErpCode.keySet());
|
||||
Responses mabangResponses = skuListMabangService.mabangSkuWeightUpdate(skuWeights);
|
||||
List<SkuWeight> skuWeightSuccesses = new ArrayList<>();
|
||||
mabangResponses.getSuccesses().forEach(skuErpCode -> skuWeightSuccesses.add(skuWeightMappedByErpCode.get(skuErpCode)));
|
||||
skuWeightSuccesses.forEach(skuWeight -> skuMongoService.upsertSkuWeight(skuWeight));
|
||||
skuWeightService.saveBatch(skuWeights);
|
||||
responses.setSuccesses(mabangResponses.getSuccesses());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
String msg = e.getMessage();
|
||||
log.error(msg, e);
|
||||
return Result.error("文件导入失败:" + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.OK(responses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -348,14 +348,17 @@ public class InvoiceController {
|
|||
InvoiceMetaData metaData;
|
||||
try {
|
||||
List<SkuQuantity> skuQuantities = skuService.getSkuQuantitiesFromOrderIds(param.orderIds());
|
||||
if(skuQuantities.isEmpty()) {
|
||||
return Result.error("Nothing to invoice.");
|
||||
}
|
||||
String purchaseId = purchaseOrderService.addPurchase(skuQuantities ,param.orderIds());
|
||||
metaData = purchaseOrderService.makeInvoice(purchaseId);
|
||||
platformOrderService.updatePurchaseInvoiceNumber(param.orderIds(), metaData.getInvoiceCode());
|
||||
|
||||
String clientCategory = clientCategoryService.getClientCategoryByClientId(param.clientID());
|
||||
// if(clientCategory.equals(ClientCategory.CategoryName.CONFIRMED.getName()) || clientCategory.equals(ClientCategory.CategoryName.VIP.getName())) {
|
||||
// balanceService.updateBalance(param.clientID(), metaData.getCode(), "purchase");
|
||||
// }
|
||||
if(clientCategory.equals(ClientCategory.CategoryName.CONFIRMED.getName()) || clientCategory.equals(ClientCategory.CategoryName.VIP.getName())) {
|
||||
balanceService.updateBalance(param.clientID(), metaData.getInvoiceCode(), "purchase");
|
||||
}
|
||||
if(clientCategory.equals(ClientCategory.CategoryName.SELF_SERVICE.getName())) {
|
||||
String subject = "Self-service purchase invoice";
|
||||
String destEmail = env.getProperty("spring.mail.username");
|
||||
|
|
|
@ -80,6 +80,8 @@ public class ShippingInvoiceController {
|
|||
@Autowired
|
||||
private IShippingInvoiceService shippingInvoiceService;
|
||||
@Autowired
|
||||
private ISecurityService securityService;
|
||||
@Autowired
|
||||
private FreeMarkerConfigurer freemarkerConfigurer;
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
@ -284,6 +286,24 @@ public class ShippingInvoiceController {
|
|||
*/
|
||||
@GetMapping(value = "/downloadCompleteInvoiceExcel")
|
||||
public ResponseEntity<?> download(@RequestParam("invoiceNumber") String invoiceNumber, @RequestParam("filetype") String filetype) throws IOException, UserException {
|
||||
boolean isEmployee = securityService.checkIsEmployee();
|
||||
Client client;
|
||||
if (!isEmployee) {
|
||||
client = clientService.getCurrentClient();
|
||||
if (client == null) {
|
||||
log.error("Couldn't find the client for the invoice number : {}", invoiceNumber);
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.contentType(MediaType.TEXT_PLAIN)
|
||||
.body("");
|
||||
}
|
||||
Client invoiceClient = clientService.getClientFromInvoice(invoiceNumber);
|
||||
if (invoiceClient == null || !invoiceClient.getId().equals(client.getId())) {
|
||||
log.error("Client {} is trying to download invoice {} which doesn't belong to him.", client.getInternalCode(), invoiceNumber);
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN)
|
||||
.contentType(MediaType.TEXT_PLAIN)
|
||||
.body("You are not allowed to download this invoice.");
|
||||
}
|
||||
}
|
||||
String filename = platformOrderShippingInvoiceService.getInvoiceList(invoiceNumber, filetype);
|
||||
if(!filename.equals("ERROR")) {
|
||||
File file = new File(filename);
|
||||
|
|
|
@ -1,24 +1,59 @@
|
|||
package org.jeecg.modules.business.domain.job;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.jeecg.modules.business.entity.Sku;
|
||||
import org.jeecg.modules.business.service.ISkuService;
|
||||
import org.jeecg.modules.business.service.MigrationService;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MongoMigrationJob implements Job {
|
||||
|
||||
@Autowired
|
||||
private MigrationService migrationService;
|
||||
@Autowired
|
||||
private ISkuService skuService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||
log.info("MongoMigrationJob start ..");
|
||||
migrationService.migrateSkuData();
|
||||
List<String> skuList = new ArrayList<>();
|
||||
JobDataMap jobDataMap = context.getMergedJobDataMap();
|
||||
String parameter = ((String) jobDataMap.get("parameter"));
|
||||
if (parameter != null) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(parameter);
|
||||
if(!jsonObject.isNull("skus")) {
|
||||
for (int i = 0; i < jsonObject.getJSONArray("skus").length(); i++) {
|
||||
skuList.add(jsonObject.getJSONArray("skus").getString(i));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Error while parsing parameter as JSON, falling back to default parameters.");
|
||||
}
|
||||
}
|
||||
if(skuList.isEmpty()) {
|
||||
log.info("Migrating all skus ..");
|
||||
migrationService.migrateSkuData();
|
||||
}
|
||||
else {
|
||||
log.info("Migrating skus: {}", skuList);
|
||||
for(String erpCode : skuList) {
|
||||
Sku sku = skuService.getByErpCode(erpCode);
|
||||
migrationService.migrateOneSku(sku);
|
||||
}
|
||||
}
|
||||
log.info("MongoMigrationJob end ..");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
|||
import org.springframework.data.mongodb.core.query.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -125,6 +126,15 @@ public class SkuMongoServiceImpl implements SkuMongoService {
|
|||
|
||||
@Override
|
||||
public void upsertSkuWeight(SkuWeight skuWeight) {
|
||||
SkuDocument skuDocument = findBySkuId(skuWeight.getSkuId());
|
||||
Date latestWeightInDB = Optional.ofNullable(skuDocument.getLatestSkuWeight())
|
||||
.map(SkuDocument.LatestSkuWeight::getEffectiveDate)
|
||||
.orElse(null);
|
||||
if(latestWeightInDB != null && latestWeightInDB.toInstant().isAfter(skuWeight.getEffectiveDate().toInstant())) {
|
||||
log.error("SKU {} weight was not updated in Mongo document, as the effective date {} is older than the one in the database {}",
|
||||
skuDocument.getErpCode(), skuWeight.getEffectiveDate(), skuDocument.getLatestSkuWeight().getEffectiveDate());
|
||||
return;
|
||||
}
|
||||
Query query = new Query(Criteria.where("skuId").is(skuWeight.getSkuId()));
|
||||
SkuDocument.LatestSkuWeight latestSkuWeight = SkuDocument.LatestSkuWeight.builder()
|
||||
.weight(skuWeight.getWeight())
|
||||
|
|
Loading…
Reference in New Issue