|
@@ -3,10 +3,17 @@ package com.pj.api.open.service;
|
|
|
import cn.hutool.cache.CacheUtil;
|
|
|
import cn.hutool.cache.impl.TimedCache;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.img.ImgUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.pj.api.open.ResultJson;
|
|
|
import com.pj.api.open.bo.CheckCarNumberBO;
|
|
|
+import com.pj.api.open.bo.InRecordBO;
|
|
|
import com.pj.constants.UserTypeEnum;
|
|
|
+import com.pj.current.config.SystemObject;
|
|
|
+import com.pj.current.task.TaskService;
|
|
|
import com.pj.project.tb_business.BusinessMessageManager;
|
|
|
import com.pj.project.tb_business.TbBusiness;
|
|
|
import com.pj.project.tb_business.TbBusinessService;
|
|
@@ -15,18 +22,29 @@ import com.pj.project.tb_business_car.TbBusinessCar;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCarService;
|
|
|
import com.pj.project.tb_business_item.TbBusinessItem;
|
|
|
import com.pj.project.tb_business_item.TbBusinessItemService;
|
|
|
+import com.pj.project.tb_business_people.TbBusinessPeople;
|
|
|
+import com.pj.project.tb_business_people.TbBusinessPeopleService;
|
|
|
import com.pj.project.tb_car.TbCar;
|
|
|
import com.pj.project.tb_car.TbCarService;
|
|
|
+import com.pj.project.tb_car_no_color.TbCarNoColor;
|
|
|
+import com.pj.project.tb_car_no_color.TbCarNoColorService;
|
|
|
+import com.pj.project4sp.uploadfile.UploadConfig;
|
|
|
import com.pj.utils.cache.RedisUtil;
|
|
|
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import sun.misc.BASE64Decoder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.xml.crypto.Data;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -46,6 +64,13 @@ public class OpenService {
|
|
|
@Resource
|
|
|
private TbCarService tbCarService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ TaskService taskService;
|
|
|
+ @Resource
|
|
|
+ TbCarNoColorService tbCarNoColorService;
|
|
|
+ @Resource
|
|
|
+ private TbBusinessPeopleService tbBusinessPeopleService;
|
|
|
+
|
|
|
private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
|
|
|
|
|
|
|
|
@@ -65,16 +90,20 @@ public class OpenService {
|
|
|
carNo = carNo.toUpperCase();
|
|
|
TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
Date now = new Date();
|
|
|
- checkFree(carNo, 1, now);
|
|
|
- if (tbBusinessCar == null || (tbBusinessCar.getRealInTime() != null && tbBusinessCar.getRealOutTime() != null)) {
|
|
|
+ TbCar tbCar = tbCarService.findByCardNo(carNo);
|
|
|
+ if (tbBusinessCar == null || (tbBusinessCar.getRealInTime() != null && tbBusinessCar.getRealOutTime() != null)||tbBusinessCar.getPay()==1) {
|
|
|
tbBusinessCar = new TbBusinessCar();
|
|
|
- tbBusinessCar.setCarNo(carNo).setPay(0).setCarSize(3D).setIsLock(0).setInImage(image)
|
|
|
- .setInChannel(channel).setRealInTime(now).setBasePartMoney(new BigDecimal("0"));
|
|
|
+ tbBusinessCar.setCarNo(carNo).setPay(0).setCarSize(0D).setIsLock(0).setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时")
|
|
|
+ .setInChannel(channel).setRealInTime(now).setBasePartMoney(new BigDecimal("0")).setTimeUpdate(now)
|
|
|
+ .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
|
|
|
tbBusinessCarService.save(tbBusinessCar);
|
|
|
+ CoverBase64ToUrl(image, tbBusinessCar.getId(), 1);
|
|
|
return;
|
|
|
}
|
|
|
- tbBusinessCar.setRealInTime(now).setInChannel(channel).setInImage(image);
|
|
|
+ tbBusinessCar.setRealInTime(now).setInChannel(channel).setTimeUpdate(now)
|
|
|
+ .setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时");
|
|
|
tbBusinessCarService.saveOrUpdate(tbBusinessCar);
|
|
|
+ CoverBase64ToUrl(image, tbBusinessCar.getId(), 1);
|
|
|
if (!CAR_LIST.contains(carNo)) {
|
|
|
TbBusiness tbBusiness = tbBusinessService.getById(tbBusinessCar.getBusinessId());
|
|
|
if (tbBusiness != null) {
|
|
@@ -85,34 +114,61 @@ public class OpenService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void CoverBase64ToUrl(String base64image, String carId, int inOrOut) {
|
|
|
+ if (StrUtil.isEmpty(base64image)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ taskService.addTask(new CoverBase64ToImageTask("=======" + carId + "", 2000, carId, base64image, inOrOut));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private ResultJson handlerOut(String carNo, String channel, String image) {
|
|
|
carNo = carNo.toUpperCase();
|
|
|
- TbBusinessCar tbBusinessCar = tbBusinessCarService.findNotOutCar(carNo);
|
|
|
+ TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
|
|
|
if (tbBusinessCar == null) {
|
|
|
return ResultJson.error("未查询到入场记录");
|
|
|
}
|
|
|
Date now = new Date();
|
|
|
+ if (StrUtil.isNotEmpty(tbBusinessCar.getColor())) {
|
|
|
+ List<TbCarNoColor> freeList = tbCarNoColorService.getFreeColor();
|
|
|
+ List<String> colorList = freeList.stream().map(f -> f.getCarNoColor().substring(0, 1)).collect(Collectors.toList());
|
|
|
+ String color = tbBusinessCar.getColor().substring(0, 1);
|
|
|
+ if (colorList.contains(color)) {
|
|
|
+ tbBusinessCar.setRealOutTime(now).setTimeUpdate(now).setOutChannel(channel);
|
|
|
+ tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ CoverBase64ToUrl(image, tbBusinessCar.getId(), 2);
|
|
|
+ return ResultJson.success();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (checkFree(carNo, 2, now)) {
|
|
|
- tbBusinessCar.setRealOutTime(now).setOutImage(image);
|
|
|
+ tbBusinessCar.setRealOutTime(now).setTimeUpdate(now).setOutChannel(channel);
|
|
|
tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ CoverBase64ToUrl(image, tbBusinessCar.getId(), 2);
|
|
|
return ResultJson.success();
|
|
|
}
|
|
|
if (tbBusinessCar.getIsLock() == 1) {
|
|
|
return ResultJson.error("车辆已锁定");
|
|
|
}
|
|
|
-
|
|
|
String businessId = tbBusinessCar.getBusinessId();
|
|
|
- BigDecimal price = tbBusinessService.calculationPartMoney(tbBusinessCar.getRealInTime(), now, StrUtil.isNotEmpty(businessId));
|
|
|
- double dif = price.subtract(tbBusinessCar.getMoney()).doubleValue();
|
|
|
+ BigDecimal price = new BigDecimal("0");
|
|
|
+ if (CAR_LIST.contains(carNo.substring(0, 1))) {
|
|
|
+ Date inTime=tbBusinessCar.getRealInTime();
|
|
|
+ if (tbBusinessCar.getPay()==1){
|
|
|
+ inTime=tbBusinessCar.getPayTime();
|
|
|
+ }
|
|
|
+ price = tbBusinessService.calculationPartMoney(inTime, now);
|
|
|
+ }
|
|
|
+// double dif = price.subtract(tbBusinessCar.getMoney()).doubleValue();
|
|
|
+ double dif = price.doubleValue();
|
|
|
if (dif > 0) {
|
|
|
- tbBusinessCar.setPay(0).setOutImage(image);
|
|
|
- tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
RedisUtil.set(channel, carNo);
|
|
|
return ResultJson.error("请缴停车费" + dif + "元");
|
|
|
}
|
|
|
if (StrUtil.isEmpty(businessId)) {
|
|
|
- tbBusinessCar.setRealOutTime(now).setOutChannel(channel).setOutImage(image);
|
|
|
+ tbBusinessCar.setRealOutTime(now).setOutChannel(channel).setTimeUpdate(now);
|
|
|
tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ CoverBase64ToUrl(image, tbBusinessCar.getId(), 2);
|
|
|
return ResultJson.success();
|
|
|
}
|
|
|
TbBusiness business = tbBusinessService.getById(businessId);
|
|
@@ -120,9 +176,10 @@ public class OpenService {
|
|
|
.stream().filter(tbBusinessItem -> tbBusinessItem.getPayStatus() == 1).collect(Collectors.toList());
|
|
|
BigDecimal itemPayPrice = new BigDecimal("0");
|
|
|
for (TbBusinessItem tbBusinessItem : items) {
|
|
|
- itemPayPrice = itemPayPrice.add(tbBusinessItem.getItemPrice());
|
|
|
+ itemPayPrice = itemPayPrice.add(tbBusinessItem.getItemPrice().multiply(new BigDecimal(tbBusinessItem.getNum())));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
if (!CAR_LIST.contains(StrUtil.sub(carNo, 0, 1))) {
|
|
|
if (!business.getItemPrice().equals(itemPayPrice) && business.getCustomerType() != 2) {
|
|
|
return ResultJson.error("请缴纳业务费用");
|
|
@@ -132,8 +189,9 @@ public class OpenService {
|
|
|
if (TbBusiness.BusinessType.CAR_DISINCLE.getCode().equals(business.getBusinessType()) && !business.getItemPrice().equals(itemPayPrice)) {
|
|
|
return ResultJson.error("请缴纳业务费用");
|
|
|
}
|
|
|
- tbBusinessCar.setRealOutTime(now).setOutChannel(channel).setOutImage(image);
|
|
|
+ tbBusinessCar.setRealOutTime(now).setOutChannel(channel).setTimeUpdate(now);
|
|
|
tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ CoverBase64ToUrl(image, tbBusinessCar.getId(), 2);
|
|
|
return ResultJson.success();
|
|
|
}
|
|
|
|
|
@@ -151,4 +209,17 @@ public class OpenService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public void handlerInRecord(InRecordBO inRecordBO) {
|
|
|
+ String carNo = inRecordBO.getCarNumber().trim().toUpperCase();
|
|
|
+ // 入场==>取车牌颜色
|
|
|
+ List<TbBusinessCar> cars = tbBusinessCarService.findByCarNo(carNo);
|
|
|
+ cars.stream().filter(obj -> StrUtil.isEmpty(obj.getColor()))
|
|
|
+ .forEach(tbBusinessCar -> {
|
|
|
+ tbBusinessCar.setColor(inRecordBO.getCarColor());
|
|
|
+ tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
+ });
|
|
|
+ if (cars.isEmpty()) {
|
|
|
+ //handlerIn(carNo, inRecordBO.getChannelName(), null);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|