mirror of https://github.com/jeecgboot/jeecg-boot
Merge pull request #141 from LQYBill/hotfix/importSkuWeightExcel
fix : import sku weightpull/8040/head
commit
45d8e2bf18
|
@ -10,11 +10,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
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.poi.ss.usermodel.*;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
|
@ -215,28 +211,39 @@ public class SkuWeightController extends JeecgController<SkuWeight, ISkuWeightSe
|
|||
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()){
|
||||
if(cell.getCellType().equals(CellType.BLANK)){
|
||||
responses.addFailure("Row " + rowIndex + " has empty cell at index " + cellIndex);
|
||||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
switch (cellIndex) {
|
||||
case 0:
|
||||
Sku sku = skuService.getByErpCode(cellValue);
|
||||
String skuCode = cell.getStringCellValue();
|
||||
Sku sku = skuService.getByErpCode(skuCode);
|
||||
if(sku == null){
|
||||
responses.addFailure("Row " + rowIndex + " SKU not found : " + cellValue);
|
||||
responses.addFailure("Row " + rowIndex + " SKU not found : " + skuCode);
|
||||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
erpCode = cellValue;
|
||||
erpCode = skuCode;
|
||||
skuWeight.setSkuId(sku.getId());
|
||||
break;
|
||||
case 1:
|
||||
skuWeight.setWeight((int) Double.parseDouble(cellValue));
|
||||
int weight;
|
||||
if(cell.getCellType().equals(CellType.STRING))
|
||||
weight = Integer.parseInt(cell.getStringCellValue());
|
||||
else if(cell.getCellType().equals(CellType.NUMERIC))
|
||||
weight = (int) cell.getNumericCellValue();
|
||||
else {
|
||||
responses.addFailure("Row " + rowIndex + " Weight is not a number - Sku : " + erpCode);
|
||||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
skuWeight.setWeight(weight);
|
||||
break;
|
||||
case 2:
|
||||
String cellValue = cell.getStringCellValue();
|
||||
Date effectiveDate = formatter.parse(cellValue);
|
||||
skuWeight.setEffectiveDate(effectiveDate);
|
||||
break;
|
||||
|
|
|
@ -42,11 +42,9 @@ public class SkuAssociationToClientJob implements Job {
|
|||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||
log.info("SkuAssociationToClientJob start");
|
||||
List<String> allSkusIds = skuService.list().stream().map(Sku::getId).collect(Collectors.toList());
|
||||
List<String> allClientSkuIds = clientSkuService.list().stream().map(ClientSku::getSkuId).collect(Collectors.toList());
|
||||
List<String> newSkusIds = allSkusIds.stream().filter(skuId -> !allClientSkuIds.contains(skuId)).collect(Collectors.toList());
|
||||
List<Sku> newSkus = skuService.listByIds(newSkusIds);
|
||||
List<String> unknownClientSkus = clientSkuService.saveClientSku(newSkus);
|
||||
List<Sku> unpairedSkus = clientSkuService.getUnpairedSkus();
|
||||
System.out.println("There is " + unpairedSkus.size() + "Unpaired Skus.");
|
||||
List<String> unknownClientSkus = clientSkuService.saveClientSku(unpairedSkus);
|
||||
|
||||
// send email for manual check
|
||||
if(!unknownClientSkus.isEmpty()) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import org.jeecg.modules.business.entity.ClientSku;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.business.entity.Sku;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
|
@ -18,4 +19,6 @@ public interface ClientSkuMapper extends BaseMapper<ClientSku> {
|
|||
public boolean deleteByMainId(@Param("mainId") String mainId);
|
||||
|
||||
List<ClientSku> selectByMainId(@Param("mainId") String mainId);
|
||||
|
||||
List<Sku> getUnpairedSkus();
|
||||
}
|
||||
|
|
|
@ -13,4 +13,11 @@
|
|||
FROM client_sku
|
||||
WHERE
|
||||
client_id = #{mainId} </select>
|
||||
|
||||
<select id="getUnpairedSkus" resultType="org.jeecg.modules.business.entity.Sku">
|
||||
SELECT s.*
|
||||
FROM sku s
|
||||
LEFT JOIN client_sku cs ON s.id = cs.sku_id
|
||||
WHERE cs.sku_id IS NULL;
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -19,4 +19,6 @@ public interface IClientSkuService extends IService<ClientSku> {
|
|||
List<String> saveClientSku(List<Sku> newSkus);
|
||||
|
||||
void addClientSku(String clientId, String skuId);
|
||||
|
||||
List<Sku> getUnpairedSkus();
|
||||
}
|
||||
|
|
|
@ -68,4 +68,9 @@ public class ClientSkuServiceImpl extends ServiceImpl<ClientSkuMapper, ClientSku
|
|||
clientSku.setSkuId(skuId);
|
||||
clientSkuMapper.insert(clientSku);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sku> getUnpairedSkus() {
|
||||
return clientSkuMapper.getUnpairedSkus();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue