12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322 |
- package com.pj.project.tb_business;
- import java.math.BigDecimal;
- import java.time.LocalDateTime;
- import java.time.ZoneId;
- import java.time.format.DateTimeFormatter;
- import java.time.temporal.ChronoUnit;
- import java.util.*;
- import java.util.stream.Collectors;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.NumberUtil;
- import cn.hutool.core.util.RandomUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.http.HttpUtil;
- import cn.hutool.json.JSONObject;
- import cn.hutool.json.JSONUtil;
- import cn.hutool.log.StaticLog;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.google.gson.JsonObject;
- import com.pj.api.wx.bo.MsgDataBO;
- import com.pj.api.wx.service.WxService;
- import com.pj.constants.UserTypeEnum;
- import com.pj.current.config.*;
- import com.pj.current.satoken.StpUserUtil;
- import com.pj.project.oa.bo.OAResultBO;
- import com.pj.project.oa.bo.ParamsBO;
- import com.pj.project.relation_business_car.RelationBusinessCar;
- import com.pj.project.relation_business_car.RelationBusinessCarService;
- import com.pj.project.relation_type_item.RelationTypeItemService;
- 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_business_sort.TbBusinessSort;
- import com.pj.project.tb_business_sort.TbBusinessSortService;
- 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.project.tb_costomer.TbCostomer;
- import com.pj.project.tb_costomer.TbCostomerService;
- import com.pj.project.tb_declare.TbDeclare;
- import com.pj.project.tb_declare.TbDeclareService;
- import com.pj.project.tb_driver.TbDriver;
- import com.pj.project.tb_driver.TbDriverService;
- import com.pj.project.tb_goods.TbGoods;
- import com.pj.project.tb_goods.TbGoodsService;
- import com.pj.project.tb_item.TbItem;
- import com.pj.project.tb_item.TbItemService;
- import com.pj.project.tb_item_type.TbItemType;
- import com.pj.project.tb_item_type.TbItemTypeService;
- import com.pj.project.tb_notices.TbNoticesService;
- import com.pj.project.tb_sort_group.TbSortGroup;
- import com.pj.project.tb_sort_group.TbSortGroupService;
- import com.pj.project.tb_unit.TbUnit;
- import com.pj.project.tb_unit.TbUnitService;
- import com.pj.project4sp.admin.SpAdmin;
- import com.pj.project4sp.admin.SpAdminService;
- import com.pj.project4sp.global.BusinessException;
- import com.pj.utils.so.SoMap;
- import com.sun.org.apache.regexp.internal.RE;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import com.pj.utils.sg.*;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- /**
- * Service: tb_business -- 入境登记
- *
- * @author qzy
- */
- @Service
- @Transactional(rollbackFor = Exception.class)
- @Slf4j
- public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness> implements IService<TbBusiness> {
- /**
- * 底层 Mapper 对象
- */
- @Autowired
- TbBusinessMapper tbBusinessMapper;
- @Resource
- private TbCarService tbCarService;
- @Resource
- private TbDriverService tbDriverService;
- @Resource
- private TbCostomerService tbCostomerService;
- @Resource
- private TbItemService tbItemService;
- @Resource
- private TbItemTypeService tbItemTypeService;
- @Resource
- private TbBusinessItemService tbBusinessItemService;
- @Resource
- TbUnitService tbUnitService;
- @Resource
- TbBusinessPeopleService tbBusinessPeopleService;
- @Resource
- private PartConfig partConfig;
- @Resource
- private CarConfig carConfig;
- @Resource
- private TbNoticesService tbNoticesService;
- @Resource
- private TbCarNoColorService tbCarNoColorService;
- @Resource
- TbBusinessCarService tbBusinessCarService;
- @Resource
- @Lazy
- TbDeclareService tbDeclareService;
- @Resource
- WxConfig wxConfig;
- @Resource
- @Lazy
- WxService wxService;
- @Resource
- MyConfig myConfig;
- @Resource
- private SpAdminService spAdminService;
- @Resource
- private TbBusinessSortService tbBusinessSortService;
- @Resource
- private TbSortGroupService tbSortGroupService;
- @Resource
- private TbGoodsService tbGoodsService;
- @Resource
- private RelationBusinessCarService relationBusinessCarService;
- @Resource
- private OAConfig oaConfig;
- private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
- /**
- * 增
- */
- public AjaxJson addOrUpdate(TbBusiness t) {
- t.setBusinessType(TbBusiness.BusinessType.HOLD_CAR.getCode());
- if (StrUtil.isEmpty(t.getDeclareNo())) {
- throw new BusinessException("请选择申报单");
- }
- if (StrUtil.isNotEmpty(t.getId()) && StrUtil.isNotEmpty(t.getDeclareNo())) {
- TbBusiness db = this.getById(t.getId());
- if (!StrUtil.equals(db.getDeclareNo(), t.getDeclareNo())) {
- TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(db.getDeclareNo());
- if (tbDeclare != null) {
- tbDeclare.setBusinessId("");
- tbDeclareService.updateById(tbDeclare);
- }
- }
- }
- Double carSize = t.getCardSize();
- if (carSize != null && carSize > carConfig.getMaxLength()) {
- return AjaxJson.getError("车辆规格不能大于" + carConfig.getMaxLength());
- }
- Double netWeight = t.getNetWeight();
- if (netWeight != null && netWeight > carConfig.getMaxWeight()) {
- return AjaxJson.getError("车辆载重不能大于" + carConfig.getMaxWeight());
- }
- SpAdmin spAdmin = StpUserUtil.getAdmin();
- String createName = StrUtil.isEmpty(spAdmin.getNickname()) ? spAdmin.getName() : spAdmin.getNickname();
- t.setCreateBy(createName);
- createCarUnit(t);
- String customerId = t.getCustomerId();
- TbCostomer tbCostomer = tbCostomerService.getById(customerId);
- t.setCustomerName(tbCostomer.getName()).setCustomerType(tbCostomer.getPayType());
- if (StrUtil.equals(customerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
- t.setConfirmInputBy(StpUserUtil.getAdmin().getName())
- .setConfirmInput(1)
- .setConfirmInputTime(new Date());
- }
- if (StrUtil.isEmpty(t.getId())) {
- t.setCreateTime(new Date());
- t.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
- storeMsg(t.getCustomerId(), "新增一条业务数据:【" + t.getNo() + "】" + DateUtil.now() + "。");
- } else {
- storeMsg(t.getCustomerId(), "业务订单:【" + t.getNo() + "】数据发生更改," + DateUtil.now() + "。");
- }
- saveOrUpdate(t);
- createBusinessPeople(t);
- tbBusinessItemService.removeByBusinessId(t.getId());
- BigDecimal price = new BigDecimal(0);
- List<TbBusinessItem> items = JSONUtil.toList(t.getItemJson(), TbBusinessItem.class);
- int index = 1;
- for (TbBusinessItem item : items) {
- Double num = NumberUtil.parseDouble(item.getNum());
- TbItem tbItem = tbItemService.getById(item.getItemId());
- String typeId = tbItem.getTypeId();
- price = price.add(NumberUtil.mul(num, tbItem.getPrice()));
- TbItemType tbItemType = tbItemTypeService.getById(typeId);
- item.setBusinessId(t.getId()).setItemCode(tbItem.getItemCode()).setBusinessType(tbItem.getBusinessType())
- .setPayType(tbItem.getPayType()).setPayTypeName(tbItem.getPayTypeName())
- .setItemName(tbItem.getItemName()).setItemPrice(tbItem.getPrice())
- .setTaxRate(NumberUtil.div(tbItem.getTaxRate().doubleValue(), 100D, 2))
- .setItemTypeId(typeId).setItemTypeName(tbItemType.getName()).setBusinessType(tbItemType.getBusinessType())
- .setUnit(tbItem.getUnit()).setTotal(NumberUtil.mul(num, tbItem.getPrice())).setCreateTime(new Date())
- .setNo(t.getNo() + "0" + index);
- tbBusinessItemService.save(item);
- index++;
- }
- List<TbBusinessCar> carList = JSONUtil.toList(t.getCarJson(), TbBusinessCar.class);
- String chinaCarNo = carList.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
- t.setChinaCarNo(StrUtil.isNotEmpty(chinaCarNo) ? chinaCarNo.toUpperCase() : "");
- carList.forEach(tbBusinessCar -> {
- tbBusinessCar.setIsLock(0);
- String carNo = tbBusinessCar.getCarNo().toUpperCase();
- TbBusinessCar car = tbBusinessCarService.findInAndNoBusinessCar(carNo);
- if (car != null) {
- tbBusinessCar.setId(car.getId()).setRealInTime(car.getRealInTime()).setIsLock(car.getIsLock());
- }
- TbCar tbCar = tbCarService.findByCardNo(carNo);
- tbBusinessCar.setBusinessId(t.getId());
- tbBusinessCar.setCarNo(carNo).setCarCompany(tbCar != null ? tbCar.getCustomerName() : "临时");
- tbBusinessCar.setBusinessId(t.getId()).setCustomerId(t.getCustomerId());
- if (StrUtil.isEmpty(tbBusinessCar.getNo())) {
- tbBusinessCar.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
- }
- });
- String yueCarNo = t.getCardNo().toUpperCase();
- TbBusinessCar yueCar = tbBusinessCarService.findInAndNoBusinessCar(yueCarNo);
- if (yueCar == null) {
- yueCar = new TbBusinessCar();
- yueCar.setIsLock(0);
- }
- yueCar.setBusinessId(t.getId()).setCarSize(t.getCardSize()).setCarNo(yueCarNo).setCustomerId(t.getCustomerId());
- if (StrUtil.isEmpty(yueCar.getNo())) {
- yueCar.setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
- }
- carList.add(yueCar);
- tbBusinessCarService.saveOrUpdateBatch(carList);
- t.setItemPrice(price)
- .setTotalMoney(price);
- this.saveOrUpdate(t);
- if (StrUtil.isNotEmpty(t.getDeclareNo())) {
- TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(t.getDeclareNo());
- tbDeclare.setBusinessId(t.getId());
- tbDeclareService.updateById(tbDeclare);
- }
- return AjaxJson.getSuccess();
- }
- public void storeMsg(String businessCustomerId, String content) {
- String currentCustomerId = StpUserUtil.getCustomerId();
- if (StrUtil.equals(currentCustomerId, UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
- BusinessMessageManager.set(businessCustomerId, content);
- } else {
- BusinessMessageManager.set(UserTypeEnum.PLATFORM_ADMIN.getCustomerId(), content);
- }
- }
- private void createBusinessPeople(TbBusiness t) {
- tbBusinessPeopleService.removeByBusinessId(t.getId());
- List<TbBusinessPeople> peopleList = JSONUtil.toList(t.getPeopleJson(), TbBusinessPeople.class);
- peopleList.forEach(tbBusinessPeople -> tbBusinessPeople.setBusinessId(t.getId()).setCreateTime(new Date()));
- tbBusinessPeopleService.saveBatch(peopleList);
- }
- private void createCarUnit(TbBusiness t) {
- TbUnit tbUnit = tbUnitService.findByUnit(t.getCardSize());
- if (tbUnit == null) {
- tbUnit = new TbUnit();
- tbUnit.setUnit(t.getCardSize() + "");
- tbUnitService.save(tbUnit);
- }
- }
- private TbDriver createDriver(TbBusiness business) {
- TbDriver tbDriver = tbDriverService.findByIdCardNo(business.getCardNo());
- if (tbDriver == null) {
- tbDriver = new TbDriver();
- tbDriver.setCreateTime(new Date()).setIdCard(business.getCardNo())
- .setName(business.getDriverName()).setPhone(business.getDriverPhone());
- tbDriverService.save(tbDriver);
- }
- return tbDriver;
- }
- private TbCar createCar(TbBusiness business) {
- String cardNo = business.getCardNo();
- TbCar tbCar = tbCarService.findByCardNo(cardNo);
- if (tbCar == null) {
- tbCar = new TbCar();
- }
- tbCar.setCardNo(cardNo)
- .setCardSize(business.getCardSize())
- .setCountryName(business.getCountryName())
- .setLastGoodsName(business.getGoodsName())
- .setLastNetWeight(business.getNetWeight());
- tbCarService.saveOrUpdate(tbCar);
- return tbCar;
- }
- /**
- * 查集合 - 根据条件(参数为空时代表忽略指定条件)
- */
- public List<TbBusiness> getList(SoMap so) {
- return tbBusinessMapper.getList(so);
- }
- public void pay(String id, String payTicket) {
- TbBusiness tbBusiness = this.getById(id);
- SpAdmin admin = StpUserUtil.getAdmin();
- tbBusiness.setPayStatus(2).setPayBy(admin.getName())
- .setPayBy(StpUserUtil.getAdmin().getName())
- .setPayTicket(payTicket)
- .setPayTime(new Date());
- if (StrUtil.equals(admin.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
- tbBusiness.setAdminConfirmPay(1).setPayStatus(3)
- .setAdminConfirmPayBy(admin.getName()).setAdminConfirmPayTime(new Date());
- }
- this.updateById(tbBusiness);
- storeMsg(tbBusiness.getCustomerId(), "业务订单【" + tbBusiness.getNo() + "】已支付" + DateUtil.now() + "。");
- //发送消息
- String text = "您的费用已支付,业务单号[" + tbBusiness.getNo() + "]";
- tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
- }
- public void confirm(List<String> ids) {
- ids.forEach(id -> {
- TbBusiness business = this.getById(id);
- business.setConfirmInput(1).setAdminConfirmInput(1)
- .setConfirmInputTime(new Date())
- .setConfirmInputBy(StpUserUtil.getAdmin().getName());
- this.updateById(business);
- List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(business.getId());
- String carNoStr = cars.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
- storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认" + DateUtil.now() + "。");
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
- String messageType = business.getGoodsId();
- items.forEach(item -> {
- String businessType = item.getBusinessType();
- //合作伙伴创建+是否下单后付款
- if (!StrUtil.equals(businessType, TbCostomer.CustomerEnum.BUSINESS_TYPE.getType())) {
- String customerId = business.getCreateByCustomerId();
- List<String> customerType = new ArrayList<>();
- TbCostomer tbCostomer = tbCostomerService.getById(customerId);
- if (tbCostomer != null) {
- customerType = StrUtil.splitTrim(tbCostomer.getType(), ",");
- }
- if (customerType.contains(businessType)) {
- StaticLog.error("订单自动确认=======================" + id);
- MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), "系统自动确认",
- DateUtil.now(),
- business.getGoodsName() + "(" + item.getItemTypeName() + item.getItemName() + "-" + carNoStr + ")");
- List<SpAdmin> spAdminList = spAdminService.findByCustomerId(customerId);
- Date now = new Date();
- item.setPickCustomerId(customerId).setPick(1)
- .setPickCustomerName(tbCostomer.getName()).setPickTime(now)
- .setConfirm(1).setConfirmTime(now);
- tbBusinessItemService.updateById(item);
- List<String> customerMessageType = StrUtil.splitTrim(tbCostomer.getMessageType(), ",");
- if (customerMessageType.contains(messageType)) {
- spAdminList.stream().map(SpAdmin::getOpenid).forEach(openId -> {
- String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openId;
- wxService.sendTemplateMsg(wxConfig.getBusinessConfirmTemplate(), openId, msgDataBO, detailUrl);
- });
- }
- } else {
- StaticLog.error("正常流程=======================" + id);
- String remark = "车牌:";
- String carNo = business.getCardNo();
- String chinaCarNo = business.getChinaCarNo();
- if (StrUtil.isNotEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
- remark += carNo + "、" + chinaCarNo;
- }
- if (StrUtil.isEmpty(carNo) && StrUtil.isNotEmpty(chinaCarNo)) {
- remark += chinaCarNo;
- }
- if (StrUtil.isNotEmpty(carNo) && StrUtil.isEmpty(chinaCarNo)) {
- remark += carNo;
- }
- MsgDataBO msgDataBO = new MsgDataBO("订单号:" + item.getNo(), item.getItemTypeName(),
- item.getItemName(), business.getGoodsName(), DateUtil.now(), remark);
- List<String> openidList = tbCostomerService.findByMessageTypeOpenid(businessType, messageType);
- openidList.stream().filter(StrUtil::isNotEmpty).forEach(openid -> {
- String detailUrl = myConfig.getWebDomain() + "/pages/business-item/item-detail?itemId=" + item.getId() + "&openid=" + openid;
- wxService.sendTemplateMsg(wxConfig.getBusinessNoticeTemplate(), openid, msgDataBO, detailUrl);
- });
- }
- }
- });
- });
- }
- public void adminConfirmPay(List<String> ids, String ticket) {
- ids.forEach(id -> {
- TbBusiness business = this.getById(id);
- business.setAdminConfirmPayTime(new Date()).setAdminConfirmPay(1).setAdminConfirmPayBy(StpUserUtil.getAdmin().getName())
- .setPayStatus(3).setPayTicket(ticket);
- this.updateById(business);
- storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已确认支付" + DateUtil.now() + "。");
- //发送消息
- String text = "您的费用已支付,业务单号[" + business.getNo() + "]";
- tbNoticesService.sendNotice(business.getId(), business.getNo(), business.getCustomerId(), text);
- });
- }
- @Deprecated
- public void adminConfirmIn(String id, String inChannel) {
- TbBusiness tbBusiness = this.getById(id);
- tbBusiness.setRealInTime(new Date()).setInChannel(inChannel);
- this.updateById(tbBusiness);
- //更新境外车入场记录
- //更新中国车入场记录
- //发送消息
- String text = "您的车辆已入场,业务单号[" + tbBusiness.getNo() + "]";
- tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
- }
- public BigDecimal calculationPartMoney(Date iTime, Date oTime) {
- BigDecimal zero = new BigDecimal("0");
- if (iTime == null || oTime == null) {
- return zero;
- }
- LocalDateTime inDayTime = iTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
- LocalDateTime outDayTime = oTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
- long minutes = ChronoUnit.MINUTES.between(inDayTime, outDayTime);
- if (minutes < 0) {
- return zero;
- }
- long days = ChronoUnit.DAYS.between(inDayTime.toLocalDate(), outDayTime.toLocalDate());
- BigDecimal p = partConfig.getBasePrice();//乘积因子
- BigDecimal extraPrice = partConfig.getExtraPrice();
- int unit = (int) Math.ceil(NumberUtil.div(minutes, 24 * 60));
- if (minutes < partConfig.getFreeMinutes()) {
- unit = 0;
- }
- return p.multiply(new BigDecimal(unit)).add(new BigDecimal(days).multiply(extraPrice));
- }
- public Map<String, Object> getBusinessMoney(String businessCarId, String state) {
- Map<String, Object> result = new HashMap<>();
- List<TbBusiness> businessList = this.findOtherBusinessByCarId(businessCarId);
- businessList = businessList.stream().filter(tbBusiness -> 3 > tbBusiness.getPayStatus()).collect(Collectors.toList());
- Set<TbBusinessCar> cars = new HashSet<>();
- //越南车是否需要支付
- int vietnamCarPay = businessList.stream().anyMatch(tbBusiness -> {
- TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
- return tbGoods.getVietnamCarPay() == 1;
- }) ? 1 : 0;
- //中国车是否需要支付
- int chinaCarPay = businessList.stream().anyMatch(tbBusiness -> {
- TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
- return tbGoods.getChinaCarPay() == 1;
- }) ? 1 : 0;
- //无业务的车辆,中国车和越南车都需要支付
- if (businessList.isEmpty()) {
- vietnamCarPay = 1;
- chinaCarPay = 1;
- cars.add(tbBusinessCarService.getById(businessCarId));
- }
- businessList = businessList.stream().filter(tbBusiness -> {
- TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
- Integer payStep = tbGoods.getPayStep();
- //确认订单后方可缴费
- return TbGoods.PayStep.AFTER_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() == 1
- //或者下单后可缴费
- || TbGoods.PayStep.BEFORE_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() >= 0;
- }).collect(Collectors.toList());
- businessList.forEach(tbBusiness -> {
- List<TbBusinessCar> businessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
- cars.addAll(businessCars);
- });
- List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
- String businessIds = StrUtil.join(",", businessIdList);
- // result.put("type", businessType);
- result.put("showPay", true);
- result.put("businessId", businessIds);
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
- Date now = new Date();
- List<Map<String, Object>> carsList = new ArrayList<>();
- for (TbBusinessCar tbBusinessCar : cars) {
- Date inTime = tbBusinessCar.getRealInTime();
- BigDecimal partMoney = new BigDecimal("0");
- String carType = tbBusinessCar.getCarType();
- if (StrUtil.isEmpty(carType)) {
- carType = TbItem.ItemTypeEnum.EMPTY_TYPE.getType();
- }
- if (inTime != null && tbBusinessCar.getRealOutTime() == null) {
- if (tbBusinessCar.getPay() == 1 && tbBusinessCar.getPayTime() != null) {
- inTime = tbBusinessCar.getPayTime();
- }
- partMoney = this.calculationPartMoney(inTime, now);
- }
- 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)) {
- partMoney = new BigDecimal("0");
- }
- }
- //越南车牌,是否免费
- if (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0) {
- partMoney = new BigDecimal("0");
- }
- //中国车,是否免费
- if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) {
- partMoney = new BigDecimal("0");
- }
- Map<String, Object> carMap = new HashMap<>();
- carMap.put("price", partMoney);
- carMap.put("id", tbBusinessCar.getId());
- carMap.put("carNo", tbBusinessCar.getCarNo());
- carMap.put("pay", tbBusinessCar.getPay());
- carMap.put("no", tbBusinessCar.getNo());
- if (TbBusinessCar.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
- carMap.put("price", 0);
- }
- carsList.add(carMap);
- }
- result.put("carList", carsList.stream().sorted(Comparator.comparingDouble(obj -> Double.valueOf(obj.get("price").toString()))).collect(Collectors.toList()));
- BigDecimal itemsPrice = new BigDecimal("0");
- List<Map<String, Object>> itemList = new ArrayList<>();
- for (TbBusinessItem item : items) {
- BigDecimal itemPrice = item.getItemPrice().multiply(new BigDecimal(item.getNum()));
- if (item.getPayStatus() == 1) {
- continue;
- }
- itemsPrice = itemsPrice.add(itemPrice);
- Map<String, Object> itemMap = new HashMap<>();
- itemMap.put("id", item.getId());
- itemMap.put("name", item.getItemName() + "(" + item.getItemTypeName() + ")");
- itemMap.put("price", itemPrice);
- itemMap.put("pay", item.getPayStatus());
- itemList.add(itemMap);
- TbBusinessSort tbBusinessSort = tbBusinessSortService.findByItemTypeId(item.getItemTypeId());
- if (tbBusinessSort != null) {
- TbSortGroup sortGroup = tbSortGroupService.getById(tbBusinessSort.getGroupId());
- if (sortGroup.getCompletePay().equals(1) && sortGroup.getStatus().equals(1)) {
- List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sortGroup.getId());
- for (TbBusinessSort sort : sorts) {
- long count = items.stream().filter(tbBusinessItem -> StrUtil.equals(sort.getTypeId(), tbBusinessItem.getItemTypeId()))
- .count();
- if (count == 0) {
- result.put("showPay", false);
- }
- }
- }
- }
- }
- result.put("itemsPrice", itemsPrice);
- result.put("itemList", itemList);
- result.put("businessNo", businessList.stream().map(TbBusiness::getNo).distinct().collect(Collectors.joining("、")));
- result.put("goodsName", businessList.stream().map(TbBusiness::getGoodsName).distinct().collect(Collectors.joining("、")));
- return result;
- }
- public List<TbBusiness> findOtherBusinessByCarId(String businessCarId) {
- return tbBusinessMapper.findOtherBusinessByCarId(businessCarId);
- }
- public void uploadReport(TbBusiness tbBusiness) {
- this.updateById(tbBusiness);
- List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
- tbBusinessCarService.updateBatchById(cars);
- }
- public List<CarDisincle> getCarDisincleList(SoMap soMap) {
- return tbBusinessMapper.getCarDisincleList(soMap);
- }
- public TbBusiness getOtherBusinessById(String id) {
- TbBusiness tbBusiness = this.getById(id);
- List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(id);
- tbBusiness.setItems(tbBusinessItems);
- List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(id);
- tbBusiness.setCars(cars);
- return tbBusiness;
- }
- public void deleteOtherBusiness(String id) {
- TbBusiness db = super.getById(id);
- String declareNo = db.getDeclareNo();
- if (StrUtil.isNotEmpty(declareNo)) {
- tbDeclareService.rebackDeclareNo(declareNo);
- }
- this.removeById(id);
- //删除响应业务项
- tbBusinessItemService.removeByBusinessId(id);
- //检查是否删除车辆
- List<TbBusinessCar> tbBusinessCarList = tbBusinessCarService.findOtherBusinessCar(id);
- tbBusinessCarList.forEach(tbBusinessCar -> {
- //未入场
- if (tbBusinessCar.getRealInTime() == null) {
- List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessCarId(tbBusinessCar.getId());
- //无关联业务==>删除
- if (relationBusinessCars.size() == 1) {
- tbBusinessCarService.removeById(tbBusinessCar.getId());
- }
- }
- });
- //删除关系
- relationBusinessCarService.removeByBusinessId(id);
- }
- public int checkCarBusinessType(String typeId, String carNo, String operateTime, int before) {
- return tbBusinessMapper.checkCarBusinessType(typeId, carNo, operateTime, before);
- }
- public int checkCarBusinessType(String typeId, String carNo, String timeStart, String timeEnd, String businessId) {
- return tbBusinessMapper.checkCarBusinessTypeByTime(typeId, carNo, timeStart, timeEnd, businessId);
- }
- public void manualConfirmPay(String id, List<TbBusinessCar> cars, String remark) {
- TbBusiness db = this.getById(id);
- if (db == null) {
- throw new BusinessException("业务不存在");
- }
- Date now = new Date();
- db.setPayStatus(3).setPayMoney(db.getItemPrice()).setPayTime(now);
- this.updateById(db);
- cars.forEach(tbBusinessCar -> {
- Date realInTime = tbBusinessCar.getRealInTime();
- Date realOutTime = tbBusinessCar.getRealOutTime();
- if (realInTime != null && realOutTime != null) {
- BigDecimal price = calculationPartMoney(realInTime, realOutTime);
- tbBusinessCar.setMoney(price);
- }
- tbBusinessCar.setPay(1).setPayTime(now);
- tbBusinessCarService.updateById(tbBusinessCar);
- });
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
- items.forEach(tbBusinessItem -> tbBusinessItem
- .setPayStatus(1).setPayTime(now)
- .setRemark(StrUtil.isEmpty(remark) ? "手动确认" : remark)
- );
- tbBusinessItemService.updateBatchById(items);
- }
- public void unBindCar(String id, String businessCarId) {
- QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
- ew.eq("id", id).eq("business_car_id", businessCarId);
- TbBusiness db = getOne(ew);
- if (db == null) {
- throw new BusinessException("业务单不存在");
- }
- tbBusinessMapper.unBindCar(id);
- }
- public TbBusiness addOtherBusiness(OtherBusinessBO otherBusinessBO) {
- List<TbItem> tbItems = otherBusinessBO.getItems();
- if (tbItems.isEmpty()) {
- throw new BusinessException("请选择明细");
- }
- List<TbBusinessCar> cars = otherBusinessBO.getCars();
- if (cars.isEmpty()) {
- throw new BusinessException("作业车辆不能为空");
- }
- Date now = new Date();
- TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
- TbBusiness tbBusiness = new TbBusiness();
- String customerId = otherBusinessBO.getCustomerId();
- tbBusiness.setCreateBy(StpUserUtil.getAdmin().getName());
- tbBusiness.setPayStep(tbGoods.getPayStep());
- TbCostomer tbCostomer = tbCostomerService.getById(customerId);
- if (tbCostomer != null) {
- tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
- }
- BigDecimal price = new BigDecimal("0");
- List<TbBusinessItem> itemList = new ArrayList<>();
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
- int index = 1;
- for (TbItem tbItem : tbItems) {
- TbItem db = tbItemService.getById(tbItem.getId());
- TbBusinessItem item = new TbBusinessItem();
- int num = tbItem.getNum();
- String typeId = tbItem.getTypeId();
- TbItemType tbItemType = tbItemTypeService.getById(typeId);
- BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
- item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
- .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
- item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId())
- .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
- .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
- price = price.add(itemTotalPrice);
- itemList.add(item);
- index++;
- }
- String declareNo = otherBusinessBO.getDeclareNo();
- tbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
- .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
- .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(otherBusinessBO.getGoodsId())
- .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
- tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
- .setItemPrice(price).setTotalMoney(price).setOwner(otherBusinessBO.getOwner());
- tbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
- this.save(tbBusiness);
- Integer chinaCarPay = tbGoods.getChinaCarPay();
- Integer vietnamCarPay = tbGoods.getVietnamCarPay();
- String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
- for (TbBusinessCar car : cars) {
- String carNo = car.getCarNo().trim().toUpperCase();
- String carType = car.getCarType();
- if (StrUtil.isEmpty(carType)) {
- throw new BusinessException(carNo + "类型不能为空");
- }
- List<TbBusinessCar> notOutRecords = tbBusinessCarService.findNotOutCar(carNo);
- if (notOutRecords.size() > 1) {
- throw new BusinessException(carNo + "有多个未出场记录,请先处理");
- }
- //最新一条记录
- TbBusinessCar db = tbBusinessCarService.findTheLastRecord(carNo);
- //不存在,或者已离场记录--->新建记录;
- if (db == null || db.getRealInTime() != null && db.getRealOutTime() != null) {
- db = new TbBusinessCar();
- db.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
- }
- for (TbBusinessItem item : itemList) {
- checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), tbBusiness.getId(), carNo);
- }
- db.setPayType(TbBusinessCar.PayTypeEnum.NO_PAY_TYPE.getType());
- if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- db.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
- }
- TbCar tbCar = tbCarService.findByCardNo(carNo);
- if (tbCar != null) {
- db.setCarCompany(tbCar.getCustomerName());
- if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
- db.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
- }
- }
- db.setCarNo(carNo).setIsLock(0);
- db.setCarSize(car.getCarSize())
- .setTimeUpdate(now).setCarType(car.getCarType())
- .setNetWeight(car.getNetWeight())
- .setCustomerId(customerId)
- .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
- tbBusinessCarService.saveOrUpdate(db);
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
- relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(db.getId());
- relationBusinessCarService.save(relationBusinessCar);
- }
- if (StrUtil.isNotEmpty(declareNo)) {
- TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
- declare.setBusinessId(tbBusiness.getId());
- tbDeclareService.updateById(declare);
- }
- itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
- tbBusinessItemService.saveBatch(itemList);
- return tbBusiness;
- }
- public List<TbBusiness> getOtherBusiness(SoMap startPage) {
- return tbBusinessMapper.getOtherBusiness(startPage);
- }
- public void editOtherBusiness(OtherBusinessBO otherBusinessBO) {
- String id = otherBusinessBO.getId();
- TbBusiness dbBusiness = this.getById(id);
- if (dbBusiness == null) {
- throw new BusinessException("记录不存在");
- }
- List<TbItem> tbItems = otherBusinessBO.getItems();
- if (tbItems.isEmpty()) {
- throw new BusinessException("请选择收费明细");
- }
- List<TbBusinessCar> cars = otherBusinessBO.getCars();
- if (cars.isEmpty()) {
- throw new BusinessException("作业车辆不能为空");
- }
- Date now = new Date();
- List<RelationBusinessCar> relationBusinessCars = relationBusinessCarService.findByBusinessId(id);
- List<String> businessCarIds = cars.stream().filter(tbBusinessCar -> StrUtil.isNotEmpty(tbBusinessCar.getId()))
- .map(TbBusinessCar::getId).collect(Collectors.toList());
- List<String> removeIds = relationBusinessCars.stream()
- .filter(relationBusinessCar -> !businessCarIds.contains(relationBusinessCar.getBusinessCarId()))
- .map(RelationBusinessCar::getId)
- .collect(Collectors.toList());
- if (!removeIds.isEmpty()) {
- relationBusinessCarService.removeByIds(removeIds);
- }
- TbGoods tbGoods = tbGoodsService.getById(otherBusinessBO.getGoodsId());
- Integer chinaCarPay = tbGoods.getChinaCarPay();
- Integer vietnamCarPay = tbGoods.getVietnamCarPay();
- String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
- List<TbBusinessItem> itemList = new ArrayList<>();
- if (TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() != dbBusiness.getPayStatus()) {
- tbBusinessItemService.removeByBusinessId(id);
- BigDecimal price = new BigDecimal("0");
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
- int index = 1;
- for (TbItem tbItem : tbItems) {
- TbItem db = tbItemService.getById(tbItem.getId());
- TbBusinessItem item = new TbBusinessItem();
- int num = tbItem.getNum();
- TbItemType tbItemType = tbItemTypeService.getById(tbItem.getTypeId());
- BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
- item.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
- .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2));
- item.setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId()).setBusinessId(dbBusiness.getId())
- .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
- .setItemTypeId(tbItem.getTypeId()).setItemTypeName(tbItemType.getName())
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
- price = price.add(itemTotalPrice);
- itemList.add(item);
- index++;
- }
- dbBusiness.setItemPrice(price).setTotalMoney(price);
- tbBusinessItemService.saveBatch(itemList);
- }
- for (TbBusinessCar tbBusinessCar : cars) {
- String businessCarId = tbBusinessCar.getId();
- String carNo = tbBusinessCar.getCarNo();
- for (TbBusinessItem item : itemList) {
- checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), dbBusiness.getId(), carNo);
- }
- String carType = tbBusinessCar.getCarType();
- if (StrUtil.isNotEmpty(businessCarId)) {
- //原来已存在的
- TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
- //如果修改了车牌号
- String dbCarNo = dbBusinessCar.getCarNo();
- if (!dbCarNo.equals(carNo)) {
- //把关联删除掉,然后添加新的关联
- relationBusinessCarService.removeByBusinessIdAndCarId(dbBusiness.getId(), businessCarId);
- TbBusinessCar otherCar = tbBusinessCarService.findTheLastRecord(carNo);
- if (otherCar == null ||//不存在或者已离场===>新建
- (otherCar.getRealInTime() != null && otherCar.getRealOutTime() != null)) {
- otherCar = new TbBusinessCar();
- otherCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4))
- .setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
- .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
- .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType());
- if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- otherCar.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
- }
- tbBusinessCarService.save(otherCar);
- } else {
- List<TbBusiness> tbBusinessList = this.findOtherBusinessByCarId(businessCarId);
- if (tbBusinessList.size() == 1 && dbBusinessCar.getRealInTime() == null) {
- tbBusinessCarService.removeById(businessCarId);
- }
- }
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
- relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(otherCar.getId());
- relationBusinessCarService.save(relationBusinessCar);
- } else {
- dbBusinessCar.setNetWeight(tbBusinessCar.getNetWeight()).setNetWeight(tbBusinessCar.getNetWeight())
- .setCarSize(tbBusinessCar.getCarSize()).setCarType(tbBusinessCar.getCarType());
- tbBusinessCarService.updateById(dbBusinessCar);
- }
- } else {
- TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
- if (checkCar == null ||
- (checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
- checkCar = new TbBusinessCar();
- checkCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
- }
- checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
- .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
- .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType());
- if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- checkCar.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
- }
- tbBusinessCarService.saveOrUpdate(checkCar);
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
- relationBusinessCar.setBusinessId(dbBusiness.getId()).setBusinessCarId(checkCar.getId());
- relationBusinessCarService.save(relationBusinessCar);
- }
- }
- if (!StrUtil.equals(dbBusiness.getGoodsId(), otherBusinessBO.getGoodsId())) {
- dbBusiness.setGoodsId(otherBusinessBO.getGoodsId())
- .setGoodsName(tbGoods.getName()).setPayStep(tbGoods.getPayStep());
- }
- String declareNo = otherBusinessBO.getDeclareNo();
- if (!StrUtil.equals(declareNo, dbBusiness.getDeclareNo())) {
- tbDeclareService.rebackDeclareNo(dbBusiness.getDeclareNo());
- TbDeclare tbDeclare = tbDeclareService.findByDeclareNo(declareNo);
- tbDeclare.setBusinessId(dbBusiness.getId());
- tbDeclareService.updateById(tbDeclare);
- }
- dbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
- .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
- .setGoodsId(otherBusinessBO.getGoodsId()).setOwner(otherBusinessBO.getOwner())
- .setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
- dbBusiness.setChinaCarNo(otherBusinessBO.getChinaCarNo());
- this.updateById(dbBusiness);
- }
- public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
- TbBusiness tbBusiness = this.getById(businessId);
- relationBusinessCarService.removeByBusinessId(businessId);
- List<TbBusinessCar> carList = tbBusinessCarService.listByIds(businessCarIdList);
- String chinaCarNo = carList.stream().filter(tbBusinessCar -> {
- String carNo = tbBusinessCar.getCarNo();
- String carStr = StrUtil.sub(carNo, 0, 1);
- return CAR_LIST.contains(carStr);
- }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
- String yueCarNo = carList.stream().filter(tbBusinessCar -> {
- String carNo = tbBusinessCar.getCarNo();
- String carStr = StrUtil.sub(carNo, 0, 1);
- return !CAR_LIST.contains(carStr);
- }).map(TbBusinessCar::getCarNo).collect(Collectors.joining("、"));
- tbBusiness.setChinaCarNo(chinaCarNo);
- tbBusiness.setCardNo(yueCarNo);
- this.updateById(tbBusiness);
- businessCarIdList.forEach(businessCarId -> {
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
- relationBusinessCar.setBusinessCarId(businessCarId).setBusinessId(businessId);
- relationBusinessCarService.save(relationBusinessCar);
- });
- }
- private void checkOtherBusiness(String itemTypeId, String operateTimeStr, String businessId, String carNo) {
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- TbBusinessSort sort = tbBusinessSortService.findByItemTypeId(itemTypeId);
- if (sort == null) {
- return;
- }
- List<TbBusinessSort> sorts = tbBusinessSortService.findByGroupId(sort.getGroupId());
- LocalDateTime operateTime = LocalDateTime.parse(operateTimeStr, formatter);
- int i = 0;
- for (TbBusinessSort tbBusinessSort : sorts) {
- if (i == 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId) && sorts.size() > 1) {
- TbBusinessSort afterItem = sorts.get(i + 1);
- String typeId = afterItem.getTypeId();
- Integer interval = afterItem.getIntervalTime();
- LocalDateTime endTime = operateTime.plusMinutes(interval);
- if (afterItem.getIntervalTime() > 0) {
- int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 1);
- if (count > 0) {
- throw new BusinessException("车辆:[" + carNo + "]" + tbBusinessSort.getTypeName() + "后" + afterItem.getIntervalTime() + "分钟才可以执行" + afterItem.getTypeName());
- }
- }
- }
- if (i > 0 && StrUtil.equals(tbBusinessSort.getTypeId(), itemTypeId)) {
- TbBusinessSort beforeItem = sorts.get(i - 1);
- String typeId = beforeItem.getTypeId();
- Integer interval = tbBusinessSort.getIntervalTime();
- LocalDateTime endTime = operateTime.minusMinutes(interval);
- if (tbBusinessSort.getIntervalTime() > 0) {
- int count = this.checkCarBusinessType(typeId, carNo, endTime.format(formatter), 0);
- if (count > 0) {
- throw new BusinessException("车辆:[" + carNo + "]" + beforeItem.getTypeName() + "后" + tbBusinessSort.getIntervalTime() + "分钟才可以执行" + tbBusinessSort.getTypeName());
- }
- }
- }
- Integer singleIntervalTime = tbBusinessSort.getSingleIntervalTime();
- String timeStart = operateTime.minusHours(singleIntervalTime).format(formatter);
- String timeEnd = operateTime.plusHours(singleIntervalTime).format(formatter);
- int count = this.checkCarBusinessType(itemTypeId, carNo, timeStart, timeEnd, businessId);
- if (count > 0) {
- throw new BusinessException("车辆:[" + carNo + "]" + singleIntervalTime + "小时内已有相同作业");
- }
- i++;
- }
- }
- public TbBusiness findByDeclareNo(String declareNo) {
- QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
- ew.eq("declare_no", declareNo).orderByDesc("id");
- List<TbBusiness> list = this.list(ew);
- return list.isEmpty() ? null : list.get(0);
- }
- /**
- * 选择异常单发送
- *
- * @param errorBusinessBO
- * @param isAdmin 是否管理员
- */
- public void selectErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
- TbBusiness tbBusiness = getById(errorBusinessBO.getId());
- if (tbBusiness == null) {
- throw new AjaxError("业务已被删除");
- }
- String businessId = tbBusiness.getId();
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
- tbBusiness.setPayStatus(errorBusinessBO.getPayStatus())
- .setSupplement(1)
- .setSupplementBy(errorBusinessBO.getSupplementBy())
- .setSupplementTime(new Date())
- .setSupplementReason(errorBusinessBO.getSupplementReason());
- if (TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus()) {
- tbBusiness.setPayMoney(tbBusiness.getItemPrice())
- .setPayTime(errorBusinessBO.getPayTime());
- items.forEach(item -> item.setPayTime(errorBusinessBO.getPayTime()).setPayStatus(1));
- tbBusinessItemService.updateBatchById(items);
- }
- List<TbBusinessCar> tbBusinessCars = errorBusinessBO.getCars();
- tbBusinessCars.forEach(this::handlerCarPay);
- tbBusinessCarService.updateBatchById(tbBusinessCars);
- if (isAdmin) {
- //发起审批
- sendOA(tbBusiness, items, tbBusinessCars, errorBusinessBO.getSupplementBy());
- }
- this.updateById(tbBusiness);
- }
- /**
- * 处理车辆支付
- * @param tbBusinessCar
- */
- private void handlerCarPay(TbBusinessCar tbBusinessCar) {
- String carNo = tbBusinessCar.getCarNo();
- String payType = tbBusinessCar.getPayType();
- Date payTime = tbBusinessCar.getPayTime();
- Date inTime = tbBusinessCar.getRealInTime();
- if (inTime == null) {
- throw new AjaxError(carNo + "入场时间不能为空");
- }
- Date outTime = tbBusinessCar.getRealOutTime();
- if (outTime == null) {
- throw new AjaxError(carNo + "离场时间不能为空");
- }
- if (payType.equals(TbBusinessCar.PayTypeEnum.HAS_PAY_TYPE.getType())) {
- if (payTime == null) {
- throw new AjaxError(carNo + "支付时间不能为空");
- }
- outTime = payTime;
- }
- //计算停车费
- BigDecimal parkMoney = this.calculationPartMoney(inTime, outTime);
- tbBusinessCar.setMoney(parkMoney);
- }
- /**
- * 发起流程审批
- *
- * @param tbBusiness
- * @param items
- * @param tbBusinessCars
- * @param sendBy
- */
- private void sendOA(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars, String sendBy) {
- ParamsBO paramsBO = buildParams(tbBusiness, items, tbBusinessCars);
- String json = JSONUtil.toJsonStr(paramsBO);
- log.info("构建流程表单数据:{}", json);
- String resp = HttpUtil.createPost(oaConfig.getUrl())
- .timeout(2000).setReadTimeout(3000).body(json)
- .execute().body();
- log.info("请求返回:{}", resp);
- OAResultBO oaResultBO = JSONUtil.toBean(resp, OAResultBO.class);
- if (oaResultBO.getSuccess() && oaResultBO.getCode() == 200) {
- tbBusiness.setSendOa(1).setSendTime(new Date()).setSendBy(sendBy)
- .setOaFdId(oaResultBO.getData().getFdId());
- }
- }
- /**
- * 构建表单数据
- *
- * @param tbBusiness
- * @param items
- * @param tbBusinessCars
- * @return
- */
- private ParamsBO buildParams(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars) {
- String operator = tbBusiness.getSupplementBy();
- String reason = tbBusiness.getSupplementReason();
- ParamsBO paramsBO = new ParamsBO();
- paramsBO.setRequestId(System.currentTimeMillis() + "")
- .setBusinessSystemCode(oaConfig.getSystemCode());
- ParamsBO.DataBO dataBO = new ParamsBO.DataBO();
- String project = tbBusiness.getGoodsName();
- JSONObject docCreator = new JSONObject();
- docCreator.set("PersonNo", oaConfig.getPersonNo());
- dataBO.setOperationalProject(project)
- .setOperationalPerson(operator).setOperationalReason(reason)
- .setDocSubject(project + "补单流程").setFdTemplateId(oaConfig.getTemplateId()).setDocCreator(JSONUtil.toJsonStr(docCreator));
- //基础信息
- ParamsBO.DataBO.FormValuesBO formValuesBO = buildFormValues(tbBusiness);
- //车辆信息
- ParamsBO.DataBO.FormValuesBO.VehicleInfoBO vehicleInfoBO = buildCarParams(tbBusinessCars);
- formValuesBO.setVehicleInfo(vehicleInfoBO);
- ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO specificBusinessItemsBO = buildItemPrams(items);
- formValuesBO.setSpecificBusinessItems(specificBusinessItemsBO);
- dataBO.setFormValues(formValuesBO);
- paramsBO.setData(dataBO);
- return paramsBO;
- }
- /**
- * 构建业务项
- *
- * @param items
- * @return
- */
- private ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO buildItemPrams(List<TbBusinessItem> items) {
- ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO specificBusinessItemsBO = new ParamsBO.DataBO.FormValuesBO.SpecificBusinessItemsBO();
- List<String> itemTypeNameList = new ArrayList<>();
- List<String> itemNameList = new ArrayList<>();
- List<String> itemPriceList = new ArrayList<>();
- List<String> unitList = new ArrayList<>();
- List<String> numList = new ArrayList<>();
- List<String> payStatusList = new ArrayList<>();
- List<String> payTimeList = new ArrayList<>();
- List<String> remarkList = new ArrayList<>();
- items.forEach(item -> {
- itemTypeNameList.add(item.getItemTypeName());
- itemNameList.add(item.getItemName());
- itemPriceList.add(item.getItemPrice().toString());
- unitList.add(item.getUnit());
- numList.add(item.getNum());
- payStatusList.add(item.getPayStatus() == 1 ? "已支付" : "未支付");
- payTimeList.add(item.getPayTime()==null?"-":DateUtil.format(item.getPayTime(), "yyyy-MM-dd HH:mm:ss"));
- remarkList.add(StrUtil.isEmpty(item.getRemark()) ? "-" : item.getRemark());
- });
- specificBusinessItemsBO.setChargingItem(itemTypeNameList)
- .setChargeDetail(itemNameList).setUnitPrice(itemPriceList).setChargingStandard(unitList)
- .setQuantity(numList).setPayoutStatus(payStatusList).setPayTime(payTimeList).setNote(remarkList);
- return specificBusinessItemsBO;
- }
- /**
- * 构建基础信息
- *
- * @param tbBusiness
- * @return
- */
- private ParamsBO.DataBO.FormValuesBO buildFormValues(TbBusiness tbBusiness) {
- ParamsBO.DataBO.FormValuesBO formValuesBO = new ParamsBO.DataBO.FormValuesBO();
- String project = tbBusiness.getGoodsName();
- formValuesBO.setOperationalProject(project).setWorkingTime(tbBusiness.getOperateTime())
- .setOperatingOutlay(tbBusiness.getItemPrice()).setAmount(tbBusiness.getItemPrice())
- .setPaymentTime(tbBusiness.getPayTime()).setCargoOwner(tbBusiness.getOwner()).setOperationNo(tbBusiness.getNo())
- .setRecordingTime(tbBusiness.getCreateTime()).setRecorder(tbBusiness.getCreateBy())
- .setIsPay(TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == tbBusiness.getPayStatus() ? "已支付" : "未支付");
- return formValuesBO;
- }
- /**
- * 构建车辆表单
- *
- * @param tbBusinessCars
- * @return
- */
- private ParamsBO.DataBO.FormValuesBO.VehicleInfoBO buildCarParams(List<TbBusinessCar> tbBusinessCars) {
- ParamsBO.DataBO.FormValuesBO.VehicleInfoBO vehicleInfoBO = new ParamsBO.DataBO.FormValuesBO.VehicleInfoBO();
- List<String> carNoList = new ArrayList<>();
- List<String> typeList = new ArrayList<>();
- List<String> loadList = new ArrayList<>();
- List<String> unitsList = new ArrayList<>();
- List<String> payStatusList = new ArrayList<>();
- List<String> carStatusList = new ArrayList<>();
- List<String> feeList = new ArrayList<>();
- List<String> inList = new ArrayList<>();
- List<String> outList = new ArrayList<>();
- tbBusinessCars.forEach(tbBusinessCar -> {
- carNoList.add(tbBusinessCar.getCarNo());
- typeList.add(tbBusinessCar.getCarType());
- loadList.add(tbBusinessCar.getNetWeight());
- Double carSize = tbBusinessCar.getCarSize();
- unitsList.add(carSize == null ? "-" : carSize.toString());
- payStatusList.add(tbBusinessCar.getPayType());
- carStatusList.add(tbBusinessCar.getIsLock() == 1 ? "正常" : "锁定");
- feeList.add(tbBusinessCar.getMoney() == null ? "-" : tbBusinessCar.getMoney().toString());
- inList.add(tbBusinessCar.getRealInTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealInTime(), "yyyy-MM-dd HH:mm:ss"));
- outList.add(tbBusinessCar.getRealOutTime() == null ? "-" : DateUtil.format(tbBusinessCar.getRealOutTime(), "yyyy-MM-dd HH:mm:ss"));
- });
- vehicleInfoBO.setLicenseNo(carNoList).setType(typeList).setLoad(loadList).setSpecifications(unitsList)
- .setPaymentStatus(payStatusList).setVehicleState(carStatusList).setParkingFee(feeList)
- .setEntryTime(inList).setDepartureTime(outList);
- return vehicleInfoBO;
- }
- //添加异常单
- public void addErrorBusiness(ErrorBusinessBO errorBusinessBO) {
- List<TbItem> tbItems = errorBusinessBO.getItems();
- if (tbItems.isEmpty()) {
- throw new BusinessException("请选择明细");
- }
- List<TbBusinessCar> cars = errorBusinessBO.getCars();
- if (cars.isEmpty()) {
- throw new BusinessException("作业车辆不能为空");
- }
- Date now = new Date();
- TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
- TbBusiness tbBusiness = new TbBusiness();
- String customerId = errorBusinessBO.getCustomerId();
- tbBusiness.setCreateBy(StpUserUtil.getAdmin().getNickname());
- tbBusiness.setPayStep(tbGoods.getPayStep());
- TbCostomer tbCostomer = tbCostomerService.getById(customerId);
- if (tbCostomer != null) {
- tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
- }
- boolean businessIsPay=TbBusiness.PayStatus.HAS_PAY_CONFIRM.getCode() == errorBusinessBO.getPayStatus();
- Date businessPayTime=errorBusinessBO.getPayTime();
- BigDecimal price = new BigDecimal("0");
- List<TbBusinessItem> itemList = new ArrayList<>();
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
- int index = 1;
- for (TbItem tbItem : tbItems) {
- TbItem db = tbItemService.getById(tbItem.getId());
- TbBusinessItem tbBusinessItem = new TbBusinessItem();
- int num = tbItem.getNum();
- String typeId = tbItem.getTypeId();
- TbItemType tbItemType = tbItemTypeService.getById(typeId);
- BigDecimal itemTotalPrice = tbItem.getPrice().multiply(new BigDecimal(num));
- tbBusinessItem.setNo(no + "0" + index).setPayTypeName(db.getPayTypeName()).setPayType(db.getPayType())
- .setBusinessType(db.getBusinessType()).setTaxRate(NumberUtil.div(db.getTaxRate().doubleValue(), 100D, 2))
- .setItemCode(db.getItemCode()).setNum(num + "").setItemId(db.getId())
- .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
- .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
- price = price.add(itemTotalPrice);
- if (businessIsPay){
- tbBusinessItem.setPayTime(businessPayTime)
- .setPayStatus(1);
- }
- itemList.add(tbBusinessItem);
- index++;
- }
- String declareNo = errorBusinessBO.getDeclareNo();
- tbBusiness.setCardSize(errorBusinessBO.getCarSize()).setNetWeight(errorBusinessBO.getNetWeight())
- .setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
- .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(errorBusinessBO.getGoodsId())
- .setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(new Date())
- .setSupplementBy(errorBusinessBO.getSupplementBy())
- .setPayStep(tbGoods.getPayStep()).setDeclareNo(declareNo).setCardNo(errorBusinessBO.getCardNo());
- tbBusiness.setCreateTime(now).setCreateByCustomerId(StpUserUtil.getCustomerId())
- .setItemPrice(price).setTotalMoney(price).setOwner(errorBusinessBO.getOwner());
- tbBusiness.setChinaCarNo(errorBusinessBO.getChinaCarNo());
- if (businessIsPay) {//如果已支付
- tbBusiness.setPayMoney(tbBusiness.getItemPrice())
- .setPayTime(businessPayTime);
- }
- this.save(tbBusiness);
- Integer chinaCarPay = tbGoods.getChinaCarPay();
- Integer vietnamCarPay = tbGoods.getVietnamCarPay();
- String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
- for (TbBusinessCar car : cars) {
- String carNo = car.getCarNo().trim().toUpperCase();
- String carType = car.getCarType();
- if (StrUtil.isEmpty(carType)) {
- throw new BusinessException(carNo + "类型不能为空");
- }
-
- car.setCreateTime(now).setNo(carBuseinssNo + RandomUtil.randomNumbers(4));
- if ((TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0)
- || (TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- car.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
- }
- TbCar tbCar = tbCarService.findByCardNo(carNo);
- if (tbCar != null) {
- car.setCarCompany(tbCar.getCustomerName());
- if (!TbCar.CarTypeEnum.BUSINESS_CAR.getType().equals(tbCar.getCarType())) {
- car.setPayType(TbBusinessCar.PayTypeEnum.FEE_TYPE.getType());
- }
- }
- car.setCarNo(carNo).setIsLock(0);
- car.setCarSize(car.getCarSize())
- .setTimeUpdate(now).setCarType(car.getCarType())
- .setNetWeight(car.getNetWeight())
- .setCustomerId(customerId)
- .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
- //新增放行记录
- tbBusinessCarService.save(car);
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
- relationBusinessCar.setBusinessId(tbBusiness.getId()).setBusinessCarId(car.getId());
- relationBusinessCarService.save(relationBusinessCar);
- }
- if (StrUtil.isNotEmpty(declareNo)) {
- TbDeclare declare = tbDeclareService.findByDeclareNo(declareNo);
- declare.setBusinessId(tbBusiness.getId());
- tbDeclareService.updateById(declare);
- }
- itemList.forEach(tbBusinessItem -> tbBusinessItem.setBusinessId(tbBusiness.getId()));
- tbBusinessItemService.saveBatch(itemList);
- }
- /**
- * 单独发起审批
- * @param id
- */
- public void applyOA(String id, String sendBy) {
- TbBusiness tbBusiness = this.getById(id);
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
- List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(id);
- sendOA(tbBusiness, items, tbBusinessCars, sendBy);
- this.updateById(tbBusiness);
- }
- }
|