|
@@ -1,10 +1,25 @@
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
|
+import com.yh.saas.common.support.util.IdGenerator;
|
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.entity.ContractManagementInfo;
|
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.entity.SalesDeliveryReport;
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.StorageFeeRecord;
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.StorageFeeRecord;
|
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.entity.StorageFeeRecordCharge;
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.StorageFeeRecordMapper;
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.StorageFeeRecordMapper;
|
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.service.IContractManagementInfoService;
|
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.service.ISalesDeliveryReportService;
|
|
import com.yh.saas.plugin.yiliangyiyun.service.IStorageFeeRecordService;
|
|
import com.yh.saas.plugin.yiliangyiyun.service.IStorageFeeRecordService;
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -17,4 +32,270 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
public class StorageFeeRecordServiceImpl extends ServiceImpl<StorageFeeRecordMapper, StorageFeeRecord> implements IStorageFeeRecordService {
|
|
public class StorageFeeRecordServiceImpl extends ServiceImpl<StorageFeeRecordMapper, StorageFeeRecord> implements IStorageFeeRecordService {
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IContractManagementInfoService contractManagementInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISalesDeliveryReportService salesDeliveryReportService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成代储费记录
|
|
|
|
+ *
|
|
|
|
+ * @param contractNo
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public String addStorageFeeRecord(String contractNo) {
|
|
|
|
+
|
|
|
|
+ // 查询合同信息
|
|
|
|
+ ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>().eq("contract_no", contractNo));
|
|
|
|
+ if (contractManagementInfo != null) {
|
|
|
|
+ // 判断代储时间和现时间(返回值1 开始大于结束 2 开始小于结束 3 开始等于结束)
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ try {
|
|
|
|
+ String dateFlag1 = comparetoTime(sdf.format(new Date()), sdf.format(contractManagementInfo.getStorageFeeStartdate()));
|
|
|
|
+ // 开始时间大于当天时间 可继续执行
|
|
|
|
+ if (!"2".equals(dateFlag1)) {
|
|
|
|
+ String dateFlag = comparetoTime(sdf.format(new Date()), sdf.format(contractManagementInfo.getStorageFeeEnddate()));
|
|
|
|
+ // 结束时间 在当天时间 之前
|
|
|
|
+ if (!"2".equals(dateFlag)) {
|
|
|
|
+ EntityWrapper<SalesDeliveryReport> salesDeliveryReportEntityWrapper = new EntityWrapper<SalesDeliveryReport>();
|
|
|
|
+ salesDeliveryReportEntityWrapper.eq("contract_no", contractNo);
|
|
|
|
+ salesDeliveryReportEntityWrapper.and("DATE_FORMAT(retrieval_date,\"%Y%m%d\") <=\n" +
|
|
|
|
+ "DATE_FORMAT('" + contractManagementInfo.getStorageFeeEnddate() + "',\"%Y%m%d\")");
|
|
|
|
+ salesDeliveryReportEntityWrapper.groupBy("retrieval_date");
|
|
|
|
+ List<SalesDeliveryReport> salesDeliveryReports = salesDeliveryReportService.selectList(salesDeliveryReportEntityWrapper);
|
|
|
|
+ if (!CollectionUtils.isEmpty(salesDeliveryReports)) {
|
|
|
|
+ for (int i = 0; i < salesDeliveryReports.size(); i++) {
|
|
|
|
+ // 查询是否已经生成记录
|
|
|
|
+ EntityWrapper<StorageFeeRecord> storageFeeRecordEntityWrapper = new EntityWrapper<StorageFeeRecord>();
|
|
|
|
+ storageFeeRecordEntityWrapper.eq("contract_no", contractNo);
|
|
|
|
+ storageFeeRecordEntityWrapper.and("DATE_FORMAT(storage_fee_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + salesDeliveryReports.get(i).getRetrievalDate() + "',\"%Y%m%d\")");
|
|
|
|
+ StorageFeeRecord storageFeeRecord1 = this.selectOne(storageFeeRecordEntityWrapper);
|
|
|
|
+ if (storageFeeRecord1 == null) {
|
|
|
|
+ // 初始化
|
|
|
|
+ StorageFeeRecord storageFeeRecord = new StorageFeeRecord();
|
|
|
|
+ storageFeeRecord.setId(IdGenerator.generateUUID());
|
|
|
|
+ storageFeeRecord.setGoodsNameKey(contractManagementInfo.getGoodsNameKey());
|
|
|
|
+ storageFeeRecord.setGoodsName(contractManagementInfo.getGoodsName());
|
|
|
|
+ storageFeeRecord.setStorageFeeDate(salesDeliveryReports.get(i).getRetrievalDate());
|
|
|
|
+ storageFeeRecord.setStorageVolume(0f);
|
|
|
|
+ // 查询当日出库量
|
|
|
|
+ EntityWrapper<SalesDeliveryReport> salesDeliveryReportEntityWrapper1 = new EntityWrapper<SalesDeliveryReport>();
|
|
|
|
+ salesDeliveryReportEntityWrapper1.eq("contract_no", contractNo);
|
|
|
|
+ salesDeliveryReportEntityWrapper1.and("DATE_FORMAT(retrieval_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + contractManagementInfo.getStorageFeeEnddate() + "',\"%Y%m%d\")");
|
|
|
|
+ List<SalesDeliveryReport> salesDeliveryReports1 = salesDeliveryReportService.selectList(salesDeliveryReportEntityWrapper1);
|
|
|
|
+ Float ton = 0f;
|
|
|
|
+ if (!CollectionUtils.isEmpty(salesDeliveryReports1)) {
|
|
|
|
+ for (int j = 0; j < salesDeliveryReports1.size(); j++) {
|
|
|
|
+ ton = ton + salesDeliveryReports1.get(i).getNetWeight();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord.setDeliveryVolume(ton);
|
|
|
|
+ // 计算当日计费储量
|
|
|
|
+ String dateAfter = getSpecifiedDayBefore(sdf.format(salesDeliveryReports.get(i).getRetrievalDate()));
|
|
|
|
+ EntityWrapper<StorageFeeRecord> storageFeeRecordEntityWrapper2 = new EntityWrapper<StorageFeeRecord>();
|
|
|
|
+ storageFeeRecordEntityWrapper2.eq("contract_no", contractNo);
|
|
|
|
+ storageFeeRecordEntityWrapper2.and("DATE_FORMAT(storage_fee_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + dateAfter + "',\"%Y%m%d\")");
|
|
|
|
+ StorageFeeRecord storageFeeRecord2 = this.selectOne(storageFeeRecordEntityWrapper);
|
|
|
|
+ if (storageFeeRecord2 != null) {
|
|
|
|
+ storageFeeRecord.setDailyBillingReserves(storageFeeRecord2.getDailyBillingReserves() - storageFeeRecord.getDeliveryVolume() + storageFeeRecord.getStorageVolume());
|
|
|
|
+ } else {
|
|
|
|
+ storageFeeRecord.setDailyBillingReserves(contractManagementInfo.getStorageFeeWeight() - storageFeeRecord.getDeliveryVolume() + storageFeeRecord.getStorageVolume());
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord.setStorageFee(1.0);
|
|
|
|
+ storageFeeRecord.setReceivable(storageFeeRecord.getStorageFee()*storageFeeRecord.getDailyBillingReserves());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ // 已经生成过记录修改当日出库量
|
|
|
|
+ else {
|
|
|
|
+ // 查询当日出库量
|
|
|
|
+ EntityWrapper<SalesDeliveryReport> salesDeliveryReportEntityWrapper1 = new EntityWrapper<SalesDeliveryReport>();
|
|
|
|
+ salesDeliveryReportEntityWrapper1.eq("contract_no", contractNo);
|
|
|
|
+ salesDeliveryReportEntityWrapper1.and("DATE_FORMAT(retrieval_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + contractManagementInfo.getStorageFeeEnddate() + "',\"%Y%m%d\")");
|
|
|
|
+ List<SalesDeliveryReport> salesDeliveryReports1 = salesDeliveryReportService.selectList(salesDeliveryReportEntityWrapper1);
|
|
|
|
+ Float ton = 0f;
|
|
|
|
+ if (!CollectionUtils.isEmpty(salesDeliveryReports1)) {
|
|
|
|
+ for (int j = 0; j < salesDeliveryReports1.size(); j++) {
|
|
|
|
+ ton = ton + salesDeliveryReports1.get(i).getNetWeight();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord1.setDeliveryVolume(ton);
|
|
|
|
+ // 计算当日计费储量
|
|
|
|
+ String dateAfter = getSpecifiedDayBefore(sdf.format(salesDeliveryReports.get(i).getRetrievalDate()));
|
|
|
|
+ EntityWrapper<StorageFeeRecord> storageFeeRecordEntityWrapper2 = new EntityWrapper<StorageFeeRecord>();
|
|
|
|
+ storageFeeRecordEntityWrapper2.eq("contract_no", contractNo);
|
|
|
|
+ storageFeeRecordEntityWrapper2.and("DATE_FORMAT(storage_fee_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + dateAfter + "',\"%Y%m%d\")");
|
|
|
|
+ StorageFeeRecord storageFeeRecord2 = this.selectOne(storageFeeRecordEntityWrapper);
|
|
|
|
+ if (storageFeeRecord2 != null) {
|
|
|
|
+ storageFeeRecord1.setDailyBillingReserves(storageFeeRecord2.getDailyBillingReserves() - storageFeeRecord1.getDeliveryVolume() + storageFeeRecord1.getStorageVolume());
|
|
|
|
+ } else {
|
|
|
|
+ storageFeeRecord1.setDailyBillingReserves(contractManagementInfo.getStorageFeeWeight() - storageFeeRecord1.getDeliveryVolume() + storageFeeRecord1.getStorageVolume());
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord1.setReceivable(storageFeeRecord1.getStorageFee()*storageFeeRecord1.getDailyBillingReserves());
|
|
|
|
+ this.updateById(storageFeeRecord1);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ EntityWrapper<SalesDeliveryReport> salesDeliveryReportEntityWrapper = new EntityWrapper<SalesDeliveryReport>();
|
|
|
|
+ salesDeliveryReportEntityWrapper.eq("contract_no", contractNo);
|
|
|
|
+ salesDeliveryReportEntityWrapper.and("DATE_FORMAT(retrieval_date,\"%Y%m%d\") <=\n" +
|
|
|
|
+ "DATE_FORMAT('" + new Date() + "',\"%Y%m%d\")");
|
|
|
|
+ salesDeliveryReportEntityWrapper.groupBy("retrieval_date");
|
|
|
|
+ List<SalesDeliveryReport> salesDeliveryReports = salesDeliveryReportService.selectList(salesDeliveryReportEntityWrapper);
|
|
|
|
+ if (!CollectionUtils.isEmpty(salesDeliveryReports)) {
|
|
|
|
+ for (int i = 0; i < salesDeliveryReports.size(); i++) {
|
|
|
|
+ // 查询是否已经生成记录
|
|
|
|
+ EntityWrapper<StorageFeeRecord> storageFeeRecordEntityWrapper = new EntityWrapper<StorageFeeRecord>();
|
|
|
|
+ storageFeeRecordEntityWrapper.eq("contract_no", contractNo);
|
|
|
|
+ storageFeeRecordEntityWrapper.and("DATE_FORMAT(storage_fee_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + salesDeliveryReports.get(i).getRetrievalDate() + "',\"%Y%m%d\")");
|
|
|
|
+ StorageFeeRecord storageFeeRecord1 = this.selectOne(storageFeeRecordEntityWrapper);
|
|
|
|
+ if (storageFeeRecord1 == null) {
|
|
|
|
+ // 初始化
|
|
|
|
+ StorageFeeRecord storageFeeRecord = new StorageFeeRecord();
|
|
|
|
+ storageFeeRecord.setId(IdGenerator.generateUUID());
|
|
|
|
+ storageFeeRecord.setGoodsNameKey(contractManagementInfo.getGoodsNameKey());
|
|
|
|
+ storageFeeRecord.setGoodsName(contractManagementInfo.getGoodsName());
|
|
|
|
+ storageFeeRecord.setStorageFeeDate(salesDeliveryReports.get(i).getRetrievalDate());
|
|
|
|
+ storageFeeRecord.setStorageVolume(0f);
|
|
|
|
+ // 查询当日出库量
|
|
|
|
+ EntityWrapper<SalesDeliveryReport> salesDeliveryReportEntityWrapper1 = new EntityWrapper<SalesDeliveryReport>();
|
|
|
|
+ salesDeliveryReportEntityWrapper1.eq("contract_no", contractNo);
|
|
|
|
+ salesDeliveryReportEntityWrapper1.and("DATE_FORMAT(retrieval_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + contractManagementInfo.getStorageFeeEnddate() + "',\"%Y%m%d\")");
|
|
|
|
+ List<SalesDeliveryReport> salesDeliveryReports1 = salesDeliveryReportService.selectList(salesDeliveryReportEntityWrapper1);
|
|
|
|
+ Float ton = 0f;
|
|
|
|
+ if (!CollectionUtils.isEmpty(salesDeliveryReports1)) {
|
|
|
|
+ for (int j = 0; j < salesDeliveryReports1.size(); j++) {
|
|
|
|
+ ton = ton + salesDeliveryReports1.get(i).getNetWeight();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord.setDeliveryVolume(ton);
|
|
|
|
+ // 计算当日计费储量
|
|
|
|
+ String dateAfter = getSpecifiedDayBefore(sdf.format(salesDeliveryReports.get(i).getRetrievalDate()));
|
|
|
|
+ EntityWrapper<StorageFeeRecord> storageFeeRecordEntityWrapper2 = new EntityWrapper<StorageFeeRecord>();
|
|
|
|
+ storageFeeRecordEntityWrapper2.eq("contract_no", contractNo);
|
|
|
|
+ storageFeeRecordEntityWrapper2.and("DATE_FORMAT(storage_fee_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + dateAfter + "',\"%Y%m%d\")");
|
|
|
|
+ StorageFeeRecord storageFeeRecord2 = this.selectOne(storageFeeRecordEntityWrapper);
|
|
|
|
+ if (storageFeeRecord2 != null) {
|
|
|
|
+ storageFeeRecord.setDailyBillingReserves(storageFeeRecord2.getDailyBillingReserves() - storageFeeRecord.getDeliveryVolume() + storageFeeRecord.getStorageVolume());
|
|
|
|
+ } else {
|
|
|
|
+ storageFeeRecord.setDailyBillingReserves(contractManagementInfo.getStorageFeeWeight() - storageFeeRecord.getDeliveryVolume() + storageFeeRecord.getStorageVolume());
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord.setStorageFee(1.0);
|
|
|
|
+ storageFeeRecord.setReceivable(storageFeeRecord.getStorageFee()*storageFeeRecord.getDailyBillingReserves());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ // 已经生成过记录修改当日出库量
|
|
|
|
+ else {
|
|
|
|
+ // 查询当日出库量
|
|
|
|
+ EntityWrapper<SalesDeliveryReport> salesDeliveryReportEntityWrapper1 = new EntityWrapper<SalesDeliveryReport>();
|
|
|
|
+ salesDeliveryReportEntityWrapper1.eq("contract_no", contractNo);
|
|
|
|
+ salesDeliveryReportEntityWrapper1.and("DATE_FORMAT(retrieval_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + contractManagementInfo.getStorageFeeEnddate() + "',\"%Y%m%d\")");
|
|
|
|
+ List<SalesDeliveryReport> salesDeliveryReports1 = salesDeliveryReportService.selectList(salesDeliveryReportEntityWrapper1);
|
|
|
|
+ Float ton = 0f;
|
|
|
|
+ if (!CollectionUtils.isEmpty(salesDeliveryReports1)) {
|
|
|
|
+ for (int j = 0; j < salesDeliveryReports1.size(); j++) {
|
|
|
|
+ ton = ton + salesDeliveryReports1.get(i).getNetWeight();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord1.setDeliveryVolume(ton);
|
|
|
|
+ // 计算当日计费储量
|
|
|
|
+ String dateAfter = getSpecifiedDayBefore(sdf.format(salesDeliveryReports.get(i).getRetrievalDate()));
|
|
|
|
+ EntityWrapper<StorageFeeRecord> storageFeeRecordEntityWrapper2 = new EntityWrapper<StorageFeeRecord>();
|
|
|
|
+ storageFeeRecordEntityWrapper2.eq("contract_no", contractNo);
|
|
|
|
+ storageFeeRecordEntityWrapper2.and("DATE_FORMAT(storage_fee_date,\"%Y%m%d\") =\n" +
|
|
|
|
+ "DATE_FORMAT('" + dateAfter + "',\"%Y%m%d\")");
|
|
|
|
+ StorageFeeRecord storageFeeRecord2 = this.selectOne(storageFeeRecordEntityWrapper);
|
|
|
|
+ if (storageFeeRecord2 != null) {
|
|
|
|
+ storageFeeRecord1.setDailyBillingReserves(storageFeeRecord2.getDailyBillingReserves() - storageFeeRecord1.getDeliveryVolume() + storageFeeRecord1.getStorageVolume());
|
|
|
|
+ } else {
|
|
|
|
+ storageFeeRecord1.setDailyBillingReserves(contractManagementInfo.getStorageFeeWeight() - storageFeeRecord1.getDeliveryVolume() + storageFeeRecord1.getStorageVolume());
|
|
|
|
+ }
|
|
|
|
+ storageFeeRecord1.setReceivable(storageFeeRecord1.getStorageFee()*storageFeeRecord1.getDailyBillingReserves());
|
|
|
|
+ this.updateById(storageFeeRecord1);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return "ok";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获得指定日期的前一天
|
|
|
|
+ *
|
|
|
|
+ * @param specifiedDay
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public static String getSpecifiedDayBefore(String specifiedDay) {
|
|
|
|
+//SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
|
+ Date date = null;
|
|
|
|
+ try {
|
|
|
|
+ date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ c.setTime(date);
|
|
|
|
+ int day = c.get(Calendar.DATE);
|
|
|
|
+ c.set(Calendar.DATE, day - 1);
|
|
|
|
+
|
|
|
|
+ String dayBefore = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
|
|
|
|
+ return dayBefore;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String comparetoTime(String beginTime, String endTime) throws ParseException {
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ //String beginTime = "2018-06-01";
|
|
|
|
+ //String endTime = "2018-05-31";
|
|
|
|
+ Date bt = sdf.parse(beginTime);
|
|
|
|
+ Date et = sdf.parse(endTime);
|
|
|
|
+ if (bt.before(et)) {
|
|
|
|
+ //表示bt小于et
|
|
|
|
+ return "1";
|
|
|
|
+ } else {
|
|
|
|
+ //--反之
|
|
|
|
+ if (beginTime.equals(endTime)) {
|
|
|
|
+ return "3";
|
|
|
|
+ } else {
|
|
|
|
+ return "2";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|