|
@@ -1,19 +1,143 @@
|
|
|
package org.jeecg.modules.carUnit.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.jeecg.common.util.SpringContextUtils;
|
|
|
+import org.jeecg.modules.billet.storageBill.vo.StorageCenterExportRow;
|
|
|
+import org.jeecg.modules.billet.storageBill.vo.StorageCenterHeatNoInvoicingVO;
|
|
|
+import org.jeecg.modules.billet.storageBill.vo.StorageCenterInvoicingVO;
|
|
|
import org.jeecg.modules.carUnit.entity.CarUnit;
|
|
|
+import org.jeecg.modules.carUnit.entity.SysDict;
|
|
|
+import org.jeecg.modules.carUnit.entity.SysDictItem;
|
|
|
import org.jeecg.modules.carUnit.mapper.CarUnitMapper;
|
|
|
import org.jeecg.modules.carUnit.service.ICarUnitService;
|
|
|
+import org.jeecg.modules.carUnit.service.ISysDictItemService;
|
|
|
+import org.jeecg.modules.carUnit.service.ISysDictService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @Description: 车辆单位管理
|
|
|
* @Author: jeecg-boot
|
|
|
- * @Date: 2025-04-19
|
|
|
+ * @Date: 2025-04-19
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Service
|
|
|
public class CarUnitServiceImpl extends ServiceImpl<CarUnitMapper, CarUnit> implements ICarUnitService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CarUnitMapper carUnitMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<StorageCenterExportRow> buildExportData(List<StorageCenterInvoicingVO> records) {
|
|
|
+ List<StorageCenterExportRow> rows = new ArrayList<>();
|
|
|
+
|
|
|
+ for (StorageCenterInvoicingVO vo : records) {
|
|
|
+ Integer ccmNo = Optional.ofNullable(vo.getHeatNoDetails())
|
|
|
+ .flatMap(list -> list.stream().findFirst())
|
|
|
+ .map(StorageCenterInvoicingVO.HeatNoDetail::getCcmNo)
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ StorageCenterHeatNoInvoicingVO invoicing = vo.getStorageCenterHeatNoInvoicing();
|
|
|
+ if (invoicing == null) continue;
|
|
|
+
|
|
|
+ // 棒二 rollClubTwoDetails
|
|
|
+ if (invoicing.getRollClubTwoDetails() != null && invoicing.getRollClubThreeDetails() != null) {
|
|
|
+ for (StorageCenterHeatNoInvoicingVO.RollChargeDetail detail : invoicing.getRollClubTwoDetails().getRollChargeDetails()) {
|
|
|
+ StorageCenterExportRow row = convert(detail, ccmNo, "棒二");
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 棒三 rollClubThreeDetails
|
|
|
+ if (invoicing.getRollClubThreeDetails() != null) {
|
|
|
+ for (StorageCenterHeatNoInvoicingVO.RollChargeDetail detail : invoicing.getRollClubThreeDetails().getRollChargeDetails()) {
|
|
|
+ StorageCenterExportRow row = convert(detail, ccmNo, "棒三");
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上若 rollOutShippDetails(如有)
|
|
|
+ if (invoicing.getRollOutShippDetails() != null) {
|
|
|
+ for (StorageCenterHeatNoInvoicingVO.RollChargeDetail detail : invoicing.getRollOutShippDetails().getRollChargeDetails()) {
|
|
|
+ StorageCenterExportRow row = convert(detail, ccmNo, "上若");
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static String getTransportUnitNameByCarNumber(String carNumber) {
|
|
|
+ if (StringUtils.isBlank(carNumber)) return "";
|
|
|
+
|
|
|
+ CarUnitMapper carUnitMapper = SpringContextUtils.getBean(CarUnitMapper.class);
|
|
|
+ ISysDictItemService sysDictItemService = SpringContextUtils.getBean(ISysDictItemService.class);
|
|
|
+ // 查询 unitCode
|
|
|
+ String unitCode = carUnitMapper.getUnitByCarNumber(carNumber);
|
|
|
+ if (StringUtils.isBlank(unitCode)) return "其他";
|
|
|
+
|
|
|
+ // 查询 car_unit_type 下所有字典项(item_text + item_value)
|
|
|
+ String dictId = getDictId("car_unit_type");
|
|
|
+ if (StringUtils.isBlank(dictId)) return "其他";
|
|
|
+
|
|
|
+ List<SysDictItem> sysDictItems = sysDictItemService.list(
|
|
|
+ new LambdaQueryWrapper<SysDictItem>()
|
|
|
+ .eq(SysDictItem::getDictId, dictId)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 遍历匹配 unitCode 是否在 item_value 中
|
|
|
+ for (SysDictItem item : sysDictItems) {
|
|
|
+ if (unitCode.equals(item.getItemValue())) {
|
|
|
+ return item.getItemText(); // 匹配成功返回单位名称(如“辉腾”)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return "其他";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static StorageCenterExportRow convert(StorageCenterHeatNoInvoicingVO.RollChargeDetail detail, Integer ccmNo, String endpoint) {
|
|
|
+ StorageCenterExportRow row = new StorageCenterExportRow();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String dateString = sdf.format(detail.getCreateTime());
|
|
|
+ row.setFactoryDate(dateString);
|
|
|
+ row.setEndPoint(endpoint);
|
|
|
+ row.setLicensePlate(detail.getLicensePlate());
|
|
|
+ row.setHeatNo(detail.getHeatNo());
|
|
|
+ row.setAmount(detail.getAmount());
|
|
|
+ row.setTotalWeight(detail.getWeight());
|
|
|
+ row.setCcmNo(ccmNo);
|
|
|
+ row.setTransportUnit(getTransportUnitNameByCarNumber(detail.getLicensePlate()));
|
|
|
+ row.setWeightPerPiece(calcWeightPerPiece(detail.getWeight(), detail.getAmount()));
|
|
|
+ row.setSpec(detail.getSpec());
|
|
|
+ row.setBrand(detail.getBrandNum());
|
|
|
+
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static BigDecimal calcWeightPerPiece(BigDecimal total, Integer amount) {
|
|
|
+ if (total == null || amount == null || amount == 0) return BigDecimal.ZERO;
|
|
|
+ return total.divide(BigDecimal.valueOf(amount), 3, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getDictId(String dictCode) {
|
|
|
+ ISysDictService sysDictService = SpringContextUtils.getBean(ISysDictService.class);
|
|
|
+ SysDict dict = sysDictService.getOne(
|
|
|
+ new LambdaQueryWrapper<SysDict>()
|
|
|
+ .eq(SysDict::getDictCode, dictCode)
|
|
|
+ .last("LIMIT 1")
|
|
|
+ );
|
|
|
+ return dict != null ? dict.getId() : null;
|
|
|
+ }
|
|
|
}
|