|
|
@ -33,8 +33,10 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.yxt.anrui.portal.api.purchaserequisitionstore.PurchaseRequisitionStore; |
|
|
|
import com.yxt.anrui.portal.api.purchaserequisitionstore.PurchaseRequisitionStoreVo; |
|
|
|
import com.yxt.anrui.portal.api.purchaserequisitiontobacco.PurchaseRequisitionTobacco; |
|
|
|
import com.yxt.anrui.portal.api.purchaserequisitiontobacco.PurchaseRequisitionTobaccoQuery; |
|
|
|
import com.yxt.anrui.portal.api.purchaserequisitiontobacco.PurchaseRequisitionTobaccoVo; |
|
|
|
import com.yxt.common.base.config.component.FileUploadComponent; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
|
import com.yxt.common.base.utils.PagerUtil; |
|
|
@ -42,6 +44,7 @@ import com.yxt.common.core.query.PagerQuery; |
|
|
|
import com.yxt.common.core.result.FileUploadResult; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.supervise.portal.biz.purchaserequisitionstore.PurchaseRequisitionStoreService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
@ -71,6 +74,9 @@ import java.util.*; |
|
|
|
public class PurchaseRequisitionTobaccoService extends MybatisBaseService<PurchaseRequisitionTobaccoMapper, PurchaseRequisitionTobacco> { |
|
|
|
@Autowired |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
@Autowired |
|
|
|
private PurchaseRequisitionStoreService purchaseRequisitionStoreService; |
|
|
|
|
|
|
|
public PagerVo<PurchaseRequisitionTobacco> listPage(PagerQuery<PurchaseRequisitionTobaccoQuery> pq) { |
|
|
|
PurchaseRequisitionTobaccoQuery query = pq.getParams(); |
|
|
|
QueryWrapper<PurchaseRequisitionTobacco> qw = createQueryWrapper(query); |
|
|
@ -195,6 +201,7 @@ public class PurchaseRequisitionTobaccoService extends MybatisBaseService<Purcha |
|
|
|
log.info("list:{}", JSONObject.toJSONString(list)); |
|
|
|
log.info("zje:{}", JSONObject.toJSONString(zje)); |
|
|
|
} |
|
|
|
|
|
|
|
public void readBrandPeriodSorXls1(MultipartFile file) { |
|
|
|
|
|
|
|
ResultBean<FileUploadResult> fub = fileUploadComponent.uploadFile(file, "PurchaseRequisitionTobacco"); |
|
|
@ -203,6 +210,7 @@ public class PurchaseRequisitionTobaccoService extends MybatisBaseService<Purcha |
|
|
|
long millis = System.currentTimeMillis(); |
|
|
|
ExcelUtil.read07BySax(fp, -1, createRowHandler()); |
|
|
|
} |
|
|
|
|
|
|
|
private RowHandler createRowHandler() { |
|
|
|
return new RowHandler() { |
|
|
|
|
|
|
@ -213,6 +221,7 @@ public class PurchaseRequisitionTobaccoService extends MybatisBaseService<Purcha |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
int i = 0; |
|
|
|
int j = 0; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handle(int sheetIndex, long rowNum, List<Object> r) { |
|
|
|
map.put("sid", sid); |
|
|
@ -326,4 +335,158 @@ public class PurchaseRequisitionTobaccoService extends MybatisBaseService<Purcha |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public String readOrderXlsx(MultipartFile file) { |
|
|
|
ResultBean<FileUploadResult> fub = fileUploadComponent.uploadFile(file, "PurchaseRequisitionTobacco"); |
|
|
|
String filePath = fub.getData().getFilePath(); |
|
|
|
String fp = fileUploadComponent.getUploadPath() + filePath; |
|
|
|
String orderSid = UUID.randomUUID().toString(); |
|
|
|
ExcelUtil.read07BySax(fp, 0, createRowHandlerWithSid(orderSid)); |
|
|
|
return orderSid; |
|
|
|
} |
|
|
|
|
|
|
|
private RowHandler createRowHandlerWithSid(String orderSid) { |
|
|
|
return new RowHandler() { |
|
|
|
List<PurchaseRequisitionStore> toInsertList = new ArrayList<>(); |
|
|
|
Map<String, Object> orderMap = new HashMap<>(); |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handle(int sheetIndex, long rowNum, List<Object> r) { |
|
|
|
orderMap.put("sid", orderSid); |
|
|
|
if (rowNum == 1) { |
|
|
|
orderMap.put("code", r.get(2)); |
|
|
|
String tdrCode_s = r.get(4).toString(); |
|
|
|
String[] split = tdrCode_s.split("\\["); |
|
|
|
String s = split[1]; |
|
|
|
String replace = s.replace("]", ""); |
|
|
|
orderMap.put("tdrCode", replace);//填单人
|
|
|
|
orderMap.put("tdrName", split[0]);//填单人
|
|
|
|
orderMap.put("purchaseDate", r.get(6));//填单时间
|
|
|
|
orderMap.put("supplierName", r.get(6));//
|
|
|
|
orderMap.put("supplierCode", r.get(6));//
|
|
|
|
} |
|
|
|
if (rowNum == 2) { |
|
|
|
String s = r.get(2).toString(); |
|
|
|
String[] split = s.split("]"); |
|
|
|
orderMap.put("supplierName", split[1]);//
|
|
|
|
String s1 = split[0]; |
|
|
|
String replace = s1.replace("[", ""); |
|
|
|
orderMap.put("supplierCode", replace);//
|
|
|
|
String o = r.get(4).toString(); |
|
|
|
// String[] split1 = o.split("]");
|
|
|
|
orderMap.put("warehousePosition", o.substring(3)); |
|
|
|
// String s2 = split1[0];
|
|
|
|
// String replace1 = s2.replace("[", "");
|
|
|
|
orderMap.put("warehousePositionCode", o.substring(0, 3)); |
|
|
|
orderMap.put("arrivalDate", r.get(6)); |
|
|
|
} |
|
|
|
if (rowNum == 3) { |
|
|
|
String s = r.get(2).toString(); |
|
|
|
String[] split = s.split("\\["); |
|
|
|
orderMap.put("buyerName", split[0]);//
|
|
|
|
String s1 = split[1]; |
|
|
|
String replace = s1.replace("]", ""); |
|
|
|
orderMap.put("buyerCode", replace);//
|
|
|
|
String s3 = r.get(4).toString(); |
|
|
|
String substring = s3.substring(s3.indexOf("[") + 1, s3.indexOf("]")); |
|
|
|
String substring1 = s3.substring(s3.indexOf("]") + 1, s3.length()); |
|
|
|
orderMap.put("purchasingOrgCode", substring); |
|
|
|
orderMap.put("purchasingOrgName", substring1); |
|
|
|
String expiryDate = r.get(6) == null ? "" : r.get(6).toString(); |
|
|
|
orderMap.put("expiryDate", expiryDate); |
|
|
|
} |
|
|
|
if (rowNum == 4) { |
|
|
|
String completionStatus = r.get(6) == null ? "" : r.get(6).toString(); |
|
|
|
orderMap.put("completionStatus", completionStatus); |
|
|
|
orderMap.put("completionStatus", "0"); |
|
|
|
} |
|
|
|
|
|
|
|
if (rowNum > 5) { |
|
|
|
Map<String, Object> sd_map = new HashMap<>(); |
|
|
|
String o = "" + r.get(3); |
|
|
|
if (StringUtils.isNotBlank(o) && o.length() > 9) { |
|
|
|
try { |
|
|
|
sd_map.put("yCode", r.get(2));//卷烟代码
|
|
|
|
String[] split = o.split("]"); |
|
|
|
String substring = split[0].substring(split[0].indexOf("[") + 1, split[0].length()); |
|
|
|
sd_map.put("storeCode", substring);//门店代码
|
|
|
|
sd_map.put("storeName", split[1]);//门店名称
|
|
|
|
sd_map.put("price", r.get(4));//金额
|
|
|
|
sd_map.put("pc", r.get(5));//批次
|
|
|
|
sd_map.put("mainSid", orderSid);//关联sid
|
|
|
|
PurchaseRequisitionStore sd = new PurchaseRequisitionStore(); |
|
|
|
BeanUtil.fillBeanWithMap(sd_map, sd, true); |
|
|
|
toInsertList.add(sd); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
baseMapper.insertIntoImportDataInfo(sdf.format(new Date()), "烟草数据导入第" + rowNum + "出现异常" + e.getMessage()); |
|
|
|
System.err.println("i=" + rowNum + ",value=null"); |
|
|
|
} |
|
|
|
} |
|
|
|
log.info("productInformation:{}", JSONObject.toJSONString(sd_map)); |
|
|
|
log.info("rowNum:{}", rowNum); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handleCell(int sheetIndex, long rowIndex, int cellIndex, Object value, CellStyle xssfCellStyle) { |
|
|
|
RowHandler.super.handleCell(sheetIndex, rowIndex, cellIndex, value, xssfCellStyle); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void doAfterAllAnalysed() { |
|
|
|
if (orderMap != null && !orderMap.isEmpty()) { |
|
|
|
String orderCode = ("" + orderMap.get("purchaseDate")).replace(".", ""); |
|
|
|
PurchaseRequisitionTobaccoService.this.clearAllByCode(orderCode); |
|
|
|
PurchaseRequisitionTobacco sd = new PurchaseRequisitionTobacco(); |
|
|
|
BeanUtil.fillBeanWithMap(orderMap, sd, true); |
|
|
|
sd.setCode(orderCode); |
|
|
|
baseMapper.insert(sd); |
|
|
|
} |
|
|
|
if (toInsertList != null && !toInsertList.isEmpty()) { |
|
|
|
purchaseRequisitionStoreService.saveBatch(toInsertList); |
|
|
|
} |
|
|
|
RowHandler.super.doAfterAllAnalysed(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void clearAllByCode(String orderCode) { |
|
|
|
PurchaseRequisitionTobacco tt = fetchByCode(orderCode); |
|
|
|
if (tt == null) |
|
|
|
return; |
|
|
|
purchaseRequisitionStoreService.clearAllByMainSid(tt.getSid()); |
|
|
|
baseMapper.clearByCode(orderCode); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过单号查找订单信息 |
|
|
|
* |
|
|
|
* @param orderCode |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public PurchaseRequisitionTobacco fetchByCode(String orderCode) { |
|
|
|
QueryWrapper<PurchaseRequisitionTobacco> qw = new QueryWrapper<>(); |
|
|
|
qw.eq("code", orderCode); |
|
|
|
List<PurchaseRequisitionTobacco> list = baseMapper.selectList(qw); |
|
|
|
if (list == null || list.isEmpty()) |
|
|
|
return null; |
|
|
|
return list.get(0); |
|
|
|
} |
|
|
|
|
|
|
|
public PurchaseRequisitionTobaccoVo fetchVoBySid(String sid) { |
|
|
|
QueryWrapper<PurchaseRequisitionTobacco> qw = new QueryWrapper<>(); |
|
|
|
qw.eq("sid", sid); |
|
|
|
List<PurchaseRequisitionTobacco> list = baseMapper.selectList(qw); |
|
|
|
if (list == null || list.isEmpty()) |
|
|
|
return null; |
|
|
|
PurchaseRequisitionTobacco entity = list.get(0); |
|
|
|
PurchaseRequisitionTobaccoVo vo = new PurchaseRequisitionTobaccoVo(); |
|
|
|
BeanUtil.copyProperties(entity, vo, true); |
|
|
|
List<PurchaseRequisitionStoreVo> storeVoList = purchaseRequisitionStoreService.listVoByMainSid(sid); |
|
|
|
vo.setStoreList(storeVoList); |
|
|
|
return vo; |
|
|
|
} |
|
|
|
} |
|
|
|