1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627 |
- 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.DateUnit;
- 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.pj.api.open.bo.ItemPriceBO;
- import com.pj.api.pushfee.oa.CallbackBO;
- import com.pj.api.wx.bo.MsgDataBO;
- import com.pj.api.wx.bo.PriceBO;
- import com.pj.api.wx.service.WxService;
- import com.pj.constants.UserTypeEnum;
- import com.pj.constants.business.*;
- 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.sync.SyncService;
- import com.pj.project.sync.request.IOrderPriceReq;
- import com.pj.project.sync.request.item.IFactorItem;
- import com.pj.project.sync.request.item.IOrderItem;
- import com.pj.project.sync.response.IOrderPriceRes;
- import com.pj.project.sync.response.item.IExpenseItem;
- import com.pj.project.sync.response.item.PriceDetailItem;
- import com.pj.project.tb_account.AutomaticPay;
- import com.pj.project.tb_account.TbAccount;
- import com.pj.project.tb_account.TbAccountService;
- 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_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_deduction_bind.TbDeductionBind;
- import com.pj.project.tb_deduction_bind.TbDeductionBindService;
- import com.pj.project.tb_driver.TbDriver;
- import com.pj.project.tb_driver.TbDriverService;
- import com.pj.project.tb_fee_details.TbFeeDetails;
- import com.pj.project.tb_fee_details.TbFeeDetailsService;
- import com.pj.project.tb_fee_statistics.TbFeeStatisticsService;
- 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_fac.TbItemFac;
- import com.pj.project.tb_item_fac.TbItemFacService;
- import com.pj.project.tb_item_type.TbItemType;
- import com.pj.project.tb_item_type.TbItemTypeService;
- import com.pj.project.tb_mild_car.TbMildCar;
- import com.pj.project.tb_mild_car.TbMildCarService;
- 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.AesUtil;
- import com.pj.utils.cache.RedisUtil;
- import com.pj.utils.sg.AjaxJson;
- import com.pj.utils.so.SoMap;
- 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
- private PartConfig partConfig;
- @Resource
- private TbNoticesService tbNoticesService;
- @Resource
- private TbAccountService tbAccountService;
- @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;
- @Autowired
- @Lazy
- private AutomaticPay automaticPay;
- @Resource
- private OAConfig oaConfig;
- @Resource
- private PushfeeConfig pushfeeConfig;
- @Resource
- private TbFeeDetailsService tbFeeDetailsService;
- @Resource
- private TbDeductionBindService tbDeductionBindService;
- @Resource
- @Lazy
- private TbFeeStatisticsService tbFeeStatisticsService;
- @Resource
- private SyncService syncService;
- @Resource
- private TbItemFacService tbItemFacService;
- @Resource
- private TbMildCarService tbMildCarService;
- private final List<String> CAR_LIST = StrUtil.splitTrim("浙,粤,京,津,冀,晋,蒙,辽,黑,沪,吉,苏,皖,赣,鲁,豫,鄂,湘,桂,琼,渝,川,贵,云,藏, 陕, 甘, 青, 宁", ",");
- 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);
- }
- }
- /**
- * 查集合 - 根据条件(参数为空时代表忽略指定条件)
- */
- 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);
- SpAdmin currAdmin = StpUserUtil.getAdmin();
- String adminName = StrUtil.isNotEmpty(currAdmin.getNickname()) ? currAdmin.getNickname() : currAdmin.getName();
- business.setConfirmInput(1).setAdminConfirmInput(1)
- .setConfirmInputTime(new Date())
- .setConfirmInputBy(StpUserUtil.getAdmin().getName())
- .setConfirmBy(adminName).setConfirmByAdminId(currAdmin.getId() + "");
- 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);
- List<TbFeeDetails> feeDetailsList = tbFeeDetailsService.getByBusinessItemId(item.getId() + "");//重复交费会存在多个businessItemId
- if (feeDetailsList != null) {
- for (TbFeeDetails feeDetails : feeDetailsList) {
- feeDetails.setPickCustomerName(item.getPickCustomerName());
- tbFeeDetailsService.updateById(feeDetails);
- }
- }
- 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);
- });
- }
- }
- });
- TbGoods tbGoods = tbGoodsService.getById(business.getGoodsId());
- //只有改业务是在确认后扣费才需要执行自动扣费
- if (GoodsEnum.DeductionTypeEnum.BUSINESS_OK.getCode().equals(tbGoods.getAutoDeductionType())) {
- //automaticPay.run(business.getId(), null, 2);
- }
- });
- }
- 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);
- });
- }
- /**
- * 计费系统计算停车费
- *
- * @param iTime 入场时间
- * @param oTime 离场时间
- * @return
- */
- public IOrderPriceRes getPartMoney(Date iTime, Date oTime, String carNo, String carColor) {
- long minutes = DateUtil.between(iTime, oTime, DateUnit.MINUTE);
- double hours = NumberUtil.div(minutes, 60, 1);
- List<IOrderItem> expenses = new ArrayList<>();
- TbMildCar tbMildCar = tbMildCarService.findByCarNo(carNo);
- IOrderPriceRes res = new IOrderPriceRes();
- double carSize = 8D;
- res.setCarDesc(PartFeeEnum.MIDDLER_CAR.getDesc());
- res.setHourDesc(PartFeeEnum.IN_24_HOURS.getDesc());
- if (tbMildCar == null) {
- // 9.6以上
- carSize = 13D;
- res.setCarDesc(PartFeeEnum.BIG_CAR.getDesc());
- }
- if (hours > 24) {
- res.setOver24Hour(1);
- res.setHourDesc(PartFeeEnum.OUT_24_HOURS.getDesc());
- }
- List<TbItemFac> list = tbItemFacService.list();
- if (list.isEmpty()) {
- throw new AjaxError("未配置停车费规则");
- }
- TbItemFac itemFac = list.get(0);
- IOrderItem orderItem = new IOrderItem();
- String uniqueExpenseId=itemFac.getUniqueExpenseId();
- orderItem.setUniqExpenseId(uniqueExpenseId).setExpenseNum(1);
- List<IFactorItem> factors = new ArrayList<>();
- for (TbItemFac fac : list) {
- String operator = fac.getOperator();
- if (StrUtil.equals(operator, "carSize")) {
- IFactorItem iFactorItem = new IFactorItem();
- iFactorItem.setFacId(fac.getFacId() + "");
- iFactorItem.setFacParams(carSize + "");
- factors.add(iFactorItem);
- } else if (StrUtil.equals(operator, "hour")) {
- IFactorItem iFactorItem = new IFactorItem();
- iFactorItem.setFacId(fac.getFacId() + "");
- iFactorItem.setFacParams(hours + "");
- factors.add(iFactorItem);
- } else if (StrUtil.equals(operator, "carColor")) {
- IFactorItem iFactorItem = new IFactorItem();
- iFactorItem.setFacId(fac.getFacId() + "");
- iFactorItem.setFacParams(carColor);
- factors.add(iFactorItem);
- }
- }
- orderItem.setFactors(factors);
- expenses.add(orderItem);
- IOrderPriceRes orderPriceRes = syncService.orderPriceCal(expenses);
- res.setCalculateId(orderPriceRes.getCalculateId())
- .setUniqueExpenseId(uniqueExpenseId)
- .setFireResult(orderPriceRes.getFireResult())
- .setTotalOrderPrice(orderPriceRes.getTotalOrderPrice());
- log.info("part money resp:{}",JSONUtil.toJsonStr(res));
- return res;
- }
- /**
- * 停车费因子构建
- * qzyReal:
- * 时长---hour;车长--carSize
- * qzyReal:
- * 颜色--carColor
- *
- * @param iTime
- * @param oTime
- * @param carSize
- * @return
- */
- public List<IOrderItem> getPartExpenses(Date iTime, Date oTime, double carSize) {
- long minutes = DateUtil.between(iTime, oTime, DateUnit.MINUTE);
- double hours = NumberUtil.div(minutes, 60, 1);
- List<IOrderItem> expenses = new ArrayList<>();
- TbItem tbItem = tbItemService.getPartItem();
- if (tbItem == null) {
- throw new AjaxError("未配置停车费规则");
- }
- IOrderItem orderItem = new IOrderItem();
- orderItem.setUniqExpenseId(tbItem.getItemCode()).setExpenseNum(1);
- List<TbItemFac> facList = tbItemFacService.getByItemId(tbItem.getId());
- List<IFactorItem> factors = new ArrayList<>();
- facList.forEach(tbItemFac -> {
- String operator = tbItemFac.getOperator();
- IFactorItem iFactorItem = new IFactorItem();
- iFactorItem.setFacId(tbItemFac.getId());
- if (StrUtil.equals(operator, "carSize")) {
- iFactorItem.setFacParams(carSize + "");
- } else if (StrUtil.equals(operator, "hour")) {
- iFactorItem.setFacParams(hours + "");
- }
- factors.add(iFactorItem);
- });
- orderItem.setFactors(factors);
- return expenses;
- }
- public BigDecimal calculationPartMoney(Date iTime, Date oTime, double carSize) {
- 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 || minutes < partConfig.getFreeMinutes()) {
- return zero;
- }
- BigDecimal extraPrice = partConfig.getExtraPrice();
- BigDecimal basePrice = partConfig.getBasePrice();
- BigDecimal uniPrice = basePrice.add(extraPrice);//超过24小时之后每24个小时收费金额
- //4.2~9.6
- if (carSize <= partConfig.getMildCarLength() && carSize > partConfig.getFreeCarLength()) {
- basePrice = partConfig.getMildCarBasePrice();
- uniPrice = basePrice.add(extraPrice);
- }
- //间隔小时
- long hours = ChronoUnit.HOURS.between(inDayTime, outDayTime);
- final int hoursOf24 = 24;
- //24小时内只用交20或者30元
- if (hours < hoursOf24) {
- return basePrice;
- }
- //24小时个数
- long count = hours / hoursOf24;
- //超过24小时总停车费
- BigDecimal price = new BigDecimal(count).multiply(uniPrice);
- return price.add(basePrice);
- }
- /**
- * 微信端获取缴费信息
- *
- * @param businessCarId
- * @param channel
- * @return
- */
- public Map<String, Object> getBusinessMoney(String businessCarId, String channel) {
- Map<String, Object> result = new HashMap<>();
- //对应的业务
- List<TbBusiness> businessList = this.findOtherBusinessByCarId(businessCarId);
- TbBusinessCar tbBusinessCar = tbBusinessCarService.getById(businessCarId);
- //越南车是否需要支付
- 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;
- }
- businessList = businessList.stream().filter(tbBusiness -> {
- TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
- Integer payStep = tbGoods.getPayStep();
- //确认订单后方可缴费
- return GoodsEnum.PayStep.AFTER_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() == 1
- //或者下单后可缴费
- || GoodsEnum.PayStep.BEFORE_CONFIRM.getCode().equals(payStep) && tbBusiness.getAdminConfirmInput() >= 0;
- }).collect(Collectors.toList());
- List<String> businessIdList = businessList.stream().map(TbBusiness::getId).collect(Collectors.toList());
- String businessIds = StrUtil.join(",", businessIdList);
- result.put("showPay", true);
- result.put("businessId", businessIds);
- result.put("noJudgeCount", 0);
- if (CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType().equals(tbBusinessCar.getBusinessType())) {
- if (tbBusinessCar.getConfirmJudge() != CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
- result.put("noJudgeCount", 1);
- }
- }
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessIdList(businessIdList);
- Date inTime = tbBusinessCar.getRealInTime();
- int pay = tbBusinessCar.getPay();
- Map<String, Object> carMap = new HashMap<>();
- carMap.put("price", 0);
- List<String> carCalculateIds = new ArrayList<>();
- //停车费
- if (pay == 0 && inTime != null) {
- Date outTime = tbBusinessCar.getRealOutTime();
- String cacheCarNo = RedisUtil.get(channel);
- if (outTime == null && StrUtil.isNotEmpty(cacheCarNo)) {
- outTime = new Date();
- }
- if (outTime != null) {
- String carType = tbBusinessCar.getCarType();
- if (StrUtil.isEmpty(carType)) {
- carType = CarEnum.CarTypeEnum.EMPTY_TYPE.getType();
- }
- //默认需要缴费--->
- BigDecimal partMoney = new BigDecimal("1");
- if (StrUtil.isNotEmpty(tbBusinessCar.getColor()) && tbBusinessCar.getCarSize() != null) {
- String freeColor = partConfig.getFreeColor();
- //4.2米以下蓝色车辆
- if (tbBusinessCar.getColor().contains(freeColor) && tbBusinessCar.getCarSize() <= partConfig.getFreeCarLength()) {
- partMoney = new BigDecimal("0");
- }
- }
- //越南车牌,是否免费
- if (CarEnum.CarTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0) {
- partMoney = new BigDecimal("0");
- }
- //中国车,是否免费
- if (CarEnum.CarTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) {
- partMoney = new BigDecimal("0");
- }
- if (CarEnum.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
- partMoney = new BigDecimal("0");
- }
- if (partMoney.doubleValue() == 1) {
- IOrderPriceRes partPriceRes = getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(), tbBusinessCar.getColor());
- BigDecimal partPrice = partPriceRes.getTotalOrderPrice();
- carCalculateIds.add(partPriceRes.getCalculateId());
- partMoney = partPrice;
- if (partPrice.doubleValue() > 0) {
- carMap.put("uniqExpenseId", partPriceRes.getFireResult().get(0).getUniqExpenseId());
- carMap.put("carDesc", partPriceRes.getCarDesc());
- carMap.put("calculateId;", partPriceRes.getCalculateId());
- carMap.put("hourDesc", partPriceRes.getHourDesc());
- carMap.put("over24Hour", partPriceRes.getOver24Hour());
- partPriceRes.getFireResult().get(0)
- .getPriceDetail().forEach(obj->carMap.put(obj.getKey(), obj.getValue()));
- }
- //todo 计算停车费
- }
- // partMoney = calculationPartMoney(inTime, outTime, tbBusinessCar.getCarSize());
- carMap.put("price", partMoney);
- }
- }
- carMap.put("id", tbBusinessCar.getId());
- carMap.put("carNo", tbBusinessCar.getCarNo());
- carMap.put("pay", pay);
- carMap.put("no", tbBusinessCar.getNo());
- result.put("carList", Collections.singleton(carMap));
- BigDecimal itemsPrice = new BigDecimal("0");
- List<Map<String, Object>> itemList = new ArrayList<>();
- if (!items.isEmpty()) {
- //未支付的
- List<IOrderItem> expenses = new ArrayList<>();
- items.stream().filter(item -> item.getPayStatus() == 0)
- .forEach(item -> {
- String num = item.getNum();
- String itemCode = item.getItemCode();
- IOrderItem iOrderItem = new IOrderItem();
- iOrderItem.setExpenseNum(Integer.parseInt(num)).setUniqExpenseId(itemCode);
- expenses.add(iOrderItem);
- });
- IOrderPriceRes orderPriceRes = syncService.orderPriceCal(expenses);
- BigDecimal totalPrice = orderPriceRes.getTotalOrderPrice();
- carCalculateIds.add(orderPriceRes.getCalculateId());
- for (TbBusinessItem item : items) {
- BigDecimal itemPrice = item.getItemPrice().multiply(new BigDecimal(item.getNum()));
- 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());
- orderPriceRes.getFireResult().stream().filter(priceItem -> StrUtil.equals(item.getItemCode(), priceItem.getUniqExpenseId()))
- .findAny().ifPresent(priceItem -> {
- itemMap.put("price", priceItem.getFirePrice().multiply(new BigDecimal(item.getNum())));
- });
- 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", totalPrice);
- }
- result.put("itemList", itemList);
- result.put("calculateId", String.join(",", carCalculateIds));
- 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 TbBusiness getZxBusinessById(String id) {
- TbBusiness tbBusiness = this.getById(id);
- List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findZxByBusinessId(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);
- }
- /**
- * 线下收费
- *
- * @param id
- * @param cars
- * @param remark
- * @param payTime
- * @param payChannelType
- * @param payType
- * @param transactionId
- */
- public void manualConfirmPay(String id, List<TbBusinessCar> cars, String remark, Date payTime, int payChannelType, int payType, String transactionId) {
- TbBusiness db = this.getById(id);
- if (db == null) {
- throw new BusinessException("业务不存在");
- }
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
- TbDeductionBind bind = null;
- BigDecimal partMoney = new BigDecimal(0);
- String plate = null;
- List<PriceBO> priceBOList = new ArrayList<>();
- TbGoods tbGoods = tbGoodsService.getById(db.getGoodsId());
- //该确认确未确认
- if (tbGoods.getPayStep().equals(GoodsEnum.PayStep.AFTER_CONFIRM.getCode()) && db.getAdminConfirmInput() == 0) {
- throw new AjaxError("该业务需要确认后才能收费");
- }
- for (TbBusinessCar tbBusinessCar : cars) {
- String carNo = tbBusinessCar.getCarNo().toUpperCase();
- String prefix = StrUtil.sub(carNo, 0, 1);
- if (CAR_LIST.contains(prefix) && tbGoods.getChinaCarPay() == 1
- || !CAR_LIST.contains(prefix) && tbGoods.getVietnamCarPay() == 1) {
- Date realInTime = tbBusinessCar.getRealInTime();
- Date realOutTime = tbBusinessCar.getRealOutTime();
- if (realInTime != null && realOutTime != null) {
- BigDecimal price = calculationPartMoney(realInTime, realOutTime, tbBusinessCar.getCarSize());
- if (price.doubleValue() > 0) {
- PriceBO priceBO = new PriceBO();
- priceBO.setId(tbBusinessCar.getId()).setP(price);
- priceBOList.add(priceBO);
- }
- partMoney = partMoney.add(price);
- tbBusinessCar.setMoney(price);
- }
- }
- tbBusinessCar.setPay(1).setPayTime(payTime)
- .setPayType(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType());
- if (payType == PayEnum.PayType.PER_PAY.getCode()) {
- TbDeductionBind deductionBind = tbDeductionBindService.getBindCarByPlate(carNo);
- if (deductionBind != null) {
- plate = carNo;
- bind = deductionBind;
- }
- }
- }
- BigDecimal itemPrice = db.getItemPrice();
- BigDecimal money = itemPrice.add(partMoney);
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
- if (payType == PayEnum.PayType.PER_PAY.getCode()) {
- if (bind == null) {
- throw new AjaxError("车辆未绑定预支付款,无法完成收费");
- }
- TbAccount tbAccount = tbAccountService.getByCustomerId(bind.getCustomerId());
- String key = AesUtil.reverse(tbAccount.getAccSalt());
- BigDecimal balance = new BigDecimal(tbAccount.getTotalMoney());
- if (balance.compareTo(money) < 0) {
- throw new AjaxError("车辆绑定账户余额不足,无法完成收费");
- }
- balance = balance.subtract(money);
- tbAccount.setTotalMoney(AesUtil.encryptECB(balance.toString(), key));
- tbAccountService.updateById(tbAccount);
- //生成扣款记录
- if (partMoney.doubleValue() > 0 && !priceBOList.isEmpty()) {
- //车辆的扣费记录
- List<TbFeeDetails> parkFeeDetailsList = tbFeeDetailsService.chargeParkFee(
- priceBOList, null, null, payTime, PayEnum.PayType.PER_PAY);
- automaticPay.createTbDeductionRecord(parkFeeDetailsList, tbAccount, plate, bind.getCustomerName(), no);
- }
- //生成收费明细
- List<TbFeeDetails> tbFeeDetailsList = tbFeeDetailsService.chargeBusinessFee(
- items, null, null, payTime, PayEnum.PayType.PER_PAY);
- //生成扣费记录
- automaticPay.createTbDeductionRecord(tbFeeDetailsList, tbAccount, plate, bind.getCustomerName(), no);
- automaticPay.unbindRun(plate);
- } else if (payType == PayEnum.PayType.OFF_LINE_PAY.getCode()) {
- //车辆的扣费记录
- if (partMoney.doubleValue() > 0) {
- tbFeeDetailsService.chargeParkFee(
- priceBOList, null, null, payTime, PayEnum.PayType.OFF_LINE_PAY);
- }
- //生成收费明细
- tbFeeDetailsService.chargeBusinessFee(
- items, null, null, payTime, PayEnum.PayType.OFF_LINE_PAY);
- }
- db.setPayStatus(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode())
- .setPayMoney(db.getItemPrice())
- .setPayType(payType).setPayChannelType(payChannelType)
- .setTransactionId(transactionId)
- .setPayTime(payTime);
- items.forEach(tbBusinessItem -> tbBusinessItem
- .setPayStatus(1).setPayTime(payTime)
- .setRemark(StrUtil.isEmpty(remark) ? "手动确认" : remark)
- );
- this.updateById(db);
- tbBusinessCarService.updateBatchById(cars);
- tbBusinessItemService.updateBatchById(items);
- tbFeeStatisticsService.addOrUpdateStatistic(payTime);//更新当前日期的日统计
- }
- 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.setAutoDeductionType(tbGoods.getAutoDeductionType());
- 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())
- .setBusinessGoodsName(otherBusinessBO.getBusinessGoodsName()).setBusinessGoodsNum(otherBusinessBO.getBusinessGoodsNum())
- .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 (car.getCarSize() == null || car.getCarSize() <= 0) {
- throw new AjaxError(carNo + "规格不正确");
- }
- 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.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode() && db.getRealOutTime() == null) {
- throw new BusinessException("车辆【" + carNo + "】已审核,请驳回再录入业务");
- }
- if (!tbGoods.getName().contains("整车")) {
- //记录不存在或者已离场
- if (db == null || db.getRealOutTime() != null) {
- throw new BusinessException("车辆【" + 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) {
- if (StrUtil.isNotEmpty(otherBusinessBO.getOperateTime())) {
- checkOtherBusiness(item.getItemTypeId(), otherBusinessBO.getOperateTime(), tbBusiness.getId(), carNo);
- }
- }
- db.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType());
- if ((CarEnum.CarTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0)
- || (CarEnum.CarTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- db.setPayType(CarEnum.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(CarEnum.PayTypeEnum.FEE_TYPE.getType());
- }
- }
- db.setCarNo(carNo).setIsLock(0).setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType());
- db.setCarSize(car.getCarSize()).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())//业务车都是未审核状态
- .setTimeUpdate(now).setCarType(car.getCarType())
- .setNetWeight(car.getNetWeight()).setColor(car.getColor())
- .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 (PayEnum.PayStatusEnum.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);
- if (dbBusinessCar.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
- throw new BusinessException("车辆【" + carNo + "】已审核,请驳回再录入业务");
- }
- //如果修改了车牌号
- 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 ((CarEnum.CarTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (CarEnum.CarTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- otherCar.setPayType(CarEnum.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.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()
- && checkCar.getRealOutTime() == null) {
- throw new BusinessException("车辆【" + carNo + "】已审核,请驳回再录入业务");
- }
- //不存在或者已经离场的
- if (checkCar == null ||
- (checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
- checkCar = new TbBusinessCar();
- checkCar.setCreateTime(now).setPay(0).setBusinessType(1)
- .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())
- .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 ((CarEnum.CarTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0) || (CarEnum.CarTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- checkCar.setPayType(CarEnum.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()).setBusinessGoodsName(otherBusinessBO.getBusinessGoodsName())
- .setBusinessGoodsNum(otherBusinessBO.getBusinessGoodsNum())
- .setDeclareNo(declareNo).setCardNo(otherBusinessBO.getCardNo());
- String chinaCar = cars.stream().filter(tbBusinessCar -> CAR_LIST.contains(StrUtil.sub(tbBusinessCar.getCarNo(), 0, 1)))
- .map(TbBusinessCar::getCarNo).collect(Collectors.joining("、")).toUpperCase();
- dbBusiness.setChinaCarNo(chinaCar);
- this.updateById(dbBusiness);
- if (dbBusiness.getConfirmInput() == 1) {
- this.confirm(Collections.singletonList(dbBusiness.getId()));
- }
- }
- public void bindOtherBusinessCar(String businessId, List<String> businessCarIdList) {
- TbBusiness tbBusiness = this.getById(businessId);
- List<TbBusinessCar> list = tbBusinessCarService.findOtherBusinessCar(businessId);
- long count = list.stream().filter(tbBusinessCar -> tbBusinessCar.getConfirmJudge() == 1).count();
- if (count > 0) {
- throw new AjaxError("业务已审核,请先驳回审核");
- }
- list.stream().filter(tbBusinessCar -> !businessCarIdList.contains(tbBusinessCar.getId()) && tbBusinessCar.getRealInTime() == null)
- .forEach(tbBusinessCar -> tbBusinessCarService.removeById(tbBusinessCar.getId()));
- 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) {
- log.info("is admin :{}", 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 (PayEnum.PayStatusEnum.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(CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType())) {
- if (payTime == null) {
- throw new AjaxError(carNo + "支付时间不能为空");
- }
- outTime = payTime;
- }
- //计算停车费
- BigDecimal parkMoney = this.calculationPartMoney(inTime, outTime, tbBusinessCar.getCarSize());
- tbBusinessCar.setMoney(parkMoney);
- }
- /**
- * 发起流程审批
- *
- * @param tbBusiness
- * @param items
- * @param tbBusinessCars
- * @param sendBy
- */
- private void sendOA(TbBusiness tbBusiness, List<TbBusinessItem> items, List<TbBusinessCar> tbBusinessCars, String sendBy) {
- if (!oaConfig.isEnable()) {
- return;
- }
- 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) {
- String fdId = oaResultBO.getData().getFdId();
- if (StrUtil.isEmpty(fdId)) {
- throw new BusinessException("流程发起失败");
- }
- tbBusiness.setSendOa(1).setOaResult(OAResultEnum.JUDGE_ING.getCode())
- .setSendTime(new Date()).setSendBy(sendBy)
- .setOaFdId(fdId);
- this.updateById(tbBusiness);
- } else {
- throw new BusinessException(oaResultBO.getMessage());
- }
- }
- /**
- * 构建表单数据
- *
- * @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));
- //基础信息
- JSONObject formValues = buildFormValues(tbBusiness);
- //车辆信息
- buildCarParams(tbBusinessCars, formValues);
- //业务项信息
- buildItemPrams(items, formValues);
- dataBO.setFormValues(formValues.toJSONString(0));
- paramsBO.setData(dataBO);
- return paramsBO;
- }
- /**
- * 构建业务项
- *
- * @param items
- * @return
- */
- private void buildItemPrams(List<TbBusinessItem> items, JSONObject formValues) {
- 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<>();
- double total = items.stream().collect(Collectors.summarizingDouble(item -> item.getItemPrice().doubleValue())).getSum();
- 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());
- });
- formValues
- .set("specificBusinessItems.chargingItem", itemTypeNameList)
- .set("specificBusinessItems.chargeDetail", itemNameList)
- .set("specificBusinessItems.unitPrice", itemPriceList)
- .set("specificBusinessItems.chargingStandard", unitList)
- .set("specificBusinessItems.quantity", numList)
- .set("specificBusinessItems.payoutStatus", payStatusList)
- .set("specificBusinessItems.payTime", payTimeList)
- .set("specificBusinessItems.total", Collections.singleton(total))
- .set("specificBusinessItems.note", remarkList);
- }
- /**
- * 构建基础信息
- *
- * @param tbBusiness
- * @return
- */
- private JSONObject buildFormValues(TbBusiness tbBusiness) {
- ParamsBO.DataBO.FormValuesBO formValuesBO = new ParamsBO.DataBO.FormValuesBO();
- String project = tbBusiness.getGoodsName();
- formValuesBO.setOperationalProject(project).setWorkingTime(tbBusiness.getOperateTime()).setCustomerName(tbBusiness.getCustomerName())
- .setOperatingOutlay(tbBusiness.getItemPrice().toString()).setAmount(tbBusiness.getItemPrice())
- .setPaymentTime(tbBusiness.getPayTime() == null ? "" : DateUtil.format(tbBusiness.getPayTime(), "yyyy-MM-dd HH:mm:ss")).setCargoOwner(tbBusiness.getOwner()).setOperationNo(tbBusiness.getNo())
- .setRecordingTime(DateUtil.format(tbBusiness.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setRecorder(tbBusiness.getCreateBy())
- .setIsPay(PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() == tbBusiness.getPayStatus() ? "已支付" : "未支付");
- return JSONUtil.parseObj(formValuesBO);
- }
- /**
- * 构建车辆表单
- *
- * @param tbBusinessCars
- * @return
- */
- private void buildCarParams(List<TbBusinessCar> tbBusinessCars, JSONObject jsonObject) {
- 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"));
- });
- jsonObject
- .set("vehicleInfo.licenseNo", carNoList)
- .set("vehicleInfo.type", typeList)
- .set("vehicleInfo.load", loadList)
- .set("vehicleInfo.specifications", unitsList)
- .set("vehicleInfo.paymentStatus", payStatusList)
- .set("vehicleInfo.vehicleState", carStatusList)
- .set("vehicleInfo.parkingFee", feeList)
- .set("vehicleInfo.entryTime", inList)
- .set("vehicleInfo.departureTime", outList);
- }
- //添加异常单
- public void addErrorBusiness(ErrorBusinessBO errorBusinessBO, boolean isAdmin) {
- 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();
- if (errorBusinessBO.getCreateTime() != null) {
- now = errorBusinessBO.getCreateTime();
- }
- TbGoods tbGoods = tbGoodsService.getById(errorBusinessBO.getGoodsId());
- TbBusiness tbBusiness = new TbBusiness();
- String customerId = errorBusinessBO.getCustomerId();
- tbBusiness.setCreateBy(StpUserUtil.getCreateBy())
- .setPayStep(tbGoods.getPayStep());
- TbCostomer tbCostomer = tbCostomerService.getById(customerId);
- if (tbCostomer != null) {
- tbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
- }
- boolean businessIsPay = PayEnum.PayStatusEnum.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);
- if (StrUtil.isNotEmpty(errorBusinessBO.getNo())) {
- no = errorBusinessBO.getNo();
- }
- 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()).setTransactionId(errorBusinessBO.getTransactionId())
- .setOperator(errorBusinessBO.getOperator()).setOperateTime(errorBusinessBO.getOperateTime())
- .setNo(no).setGoodsName(tbGoods.getName()).setGoodsId(errorBusinessBO.getGoodsId())
- .setSupplementReason(errorBusinessBO.getSupplementReason()).setSupplementTime(now)
- .setSupplementBy(errorBusinessBO.getSupplementBy()).setSupplement(1).setPayStatus(errorBusinessBO.getPayStatus())
- .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 ((CarEnum.CarTypeEnum.EMPTY_TYPE.getType().equals(carType) && chinaCarPay == 0)
- || (CarEnum.CarTypeEnum.WEIGHT_TYPE.getType().equals(carType) && vietnamCarPay == 0)) {
- car.setPayType(CarEnum.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(CarEnum.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);
- if (isAdmin) {
- sendOA(tbBusiness, itemList, cars, errorBusinessBO.getSupplementBy());
- }
- }
- /**
- * 单独发起审批
- *
- * @param id
- */
- public void applyOA(String id, String sendBy) {
- log.info("发起流程:{},{}", id, 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);
- }
- /**
- * 编辑异常单
- *
- * @param errorBusinessBO
- */
- public void editErrorBusiness(ErrorBusinessBO errorBusinessBO) {
- String id = errorBusinessBO.getId();
- TbBusiness dbBusiness = this.getById(id);
- if (dbBusiness == null) {
- throw new BusinessException("记录不存在");
- }
- if (!(dbBusiness.getSendOa() == 0 || OAResultEnum.NO_PASS.getCode().equals(dbBusiness.getOaResult()))) {
- throw new BusinessException("业务单正在审核,无法修改");
- }
- List<TbItem> tbItems = errorBusinessBO.getItems();
- if (tbItems.isEmpty()) {
- throw new BusinessException("请选择收费明细");
- }
- List<TbBusinessCar> cars = errorBusinessBO.getCars();
- if (cars.isEmpty()) {
- throw new BusinessException("作业车辆不能为空");
- }
- this.removeById(id);
- tbBusinessItemService.removeByBusinessId(id);
- tbBusinessCarService.removeByBusinessId(id);
- relationBusinessCarService.removeByBusinessId(id);
- errorBusinessBO.setNo(dbBusiness.getNo()).setCreateTime(dbBusiness.getCreateTime());
- this.addErrorBusiness(errorBusinessBO, false);
- }
- /**
- * oa审批回调
- *
- * @param callbackBO
- */
- public void approveCallback(CallbackBO callbackBO) {
- String fdId = callbackBO.getFdId();
- TbBusiness tbBusiness = this.findByFdId(fdId);
- if (tbBusiness == null) {
- throw new AjaxError("流程不存在");
- }
- String result = callbackBO.getAuditResult();
- tbBusiness.setOaResult(callbackBO.getAuditResult()).setOaContent(callbackBO.getRefuseReason())
- .setOaJudgeTime(new Date());
- this.updateById(tbBusiness);
- String businessId = tbBusiness.getId();
- if (StrUtil.contains(result, "通过") && pushfeeConfig.isEnable()) {
- //todo 审批通过-==>已支付的生成明细===>推送订单到计费系统
- List<TbBusinessCar> cars = tbBusinessCarService.findOtherBusinessCar(businessId);
- String transactionId = tbBusiness.getTransactionId();
- Date payTime = tbBusiness.getPayTime();
- String outTradeNo = "of" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + RandomUtil.randomNumbers(4);
- //已经支付了的
- List<PriceBO> priceBOList = cars.stream().filter(tbBusinessCar -> tbBusinessCar.getPayTime() != null).
- map(tbBusinessCar -> {
- PriceBO priceBO = new PriceBO();
- priceBO.setId(tbBusinessCar.getId()).setP(tbBusinessCar.getMoney());
- return priceBO;
- }).
- collect(Collectors.toList());
- if (!priceBOList.isEmpty()) {
- tbFeeDetailsService.chargeParkFee(priceBOList, transactionId, outTradeNo, payTime, PayEnum.PayType.OFF_LINE_PAY);//添加cars的收费明细
- }
- if (tbBusiness.getPayStatus() == PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode()) {
- List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(businessId);
- tbFeeDetailsService.chargeBusinessFee(items, transactionId, outTradeNo, payTime, PayEnum.PayType.OFF_LINE_PAY);//添加items的收费明细
- }
- }
- }
- /**
- * 根据流程ID查询
- *
- * @param fdId
- * @return
- */
- private TbBusiness findByFdId(String fdId) {
- QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
- ew.lambda().eq(TbBusiness::getOaFdId, fdId);
- return getOne(ew);
- }
- public TbBusiness findByNo(String no) {
- QueryWrapper<TbBusiness> ew = new QueryWrapper<>();
- ew.eq("no", no);
- return this.getOne(ew);
- }
- }
|