1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822 |
- 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.ManagerBO;
- 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_deduction_record.TbDeductionRecord;
- 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_invoice_order.TbInvoiceOrder;
- import com.pj.project.tb_invoice_order.TbInvoiceOrderService;
- 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.aspectj.weaver.loadtime.Aj;
- 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 TbInvoiceOrderService tbInvoiceOrderService;
- @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);
- if (hours == 0) {
- hours = 0.1D;
- }
- 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 = 12D;
- res.setCarDesc(PartFeeEnum.BIG_CAR.getDesc());
- }
- if (hours > 24) {
- res.setOver24Hour(1);
- res.setHourDesc(PartFeeEnum.OUT_24_HOURS.getDesc());
- }
- TbItem partItem = tbItemService.findByAliasName(SystemObject.config.getPartItemAlias());
- if (partItem == null) {
- throw new AjaxError("未配置停车费规则");
- }
- List<TbItemFac> list = tbItemFacService.getByItemId(partItem.getId());
- 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;
- }
- /**
- * 微信端获取缴费信息
- *
- * @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);
- //是否需要交停车费---->业务车都要交
- // boolean needPayPartMoney = !businessList.isEmpty();
- TbBusinessCar tbBusinessCar = tbBusinessCarService.getById(businessCarId);
- String carNo = tbBusinessCar.getCarNo();
- 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);
- long judgeCount = businessList.stream().filter(tbBusiness -> tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()).count();
- int size = businessList.size();
- result.put("showPay", true);
- result.put("businessId", businessIds);
- result.put("noJudgeCount", judgeCount == size ? 0 : 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 (inTime != null) {
- Date outTime = tbBusinessCar.getRealOutTime();
- String cacheCarNo = RedisUtil.get(channel);
- if (outTime == null && StrUtil.isNotEmpty(cacheCarNo) && StrUtil.equals(carNo.trim().toUpperCase(), cacheCarNo.trim().toUpperCase())) {
- outTime = new Date();
- }
- if (outTime != null) {
- //默认需要缴费--->
- BigDecimal partMoney = new BigDecimal("1");
- if (StrUtil.isNotEmpty(tbBusinessCar.getColor()) && tbBusinessCar.getCarSize() != null) {
- String freeColor = partConfig.getFreeColor();
- //4.2米以下蓝色车辆
- if (tbBusinessCar.getColor().contains(freeColor)) {
- partMoney = new BigDecimal("0");
- }
- }
- if (CarEnum.PayTypeEnum.FEE_TYPE.getType().equals(tbBusinessCar.getPayType())) {
- partMoney = new BigDecimal("0");
- }
- if (CarEnum.PayTypeEnum.HAS_PAY_TYPE.getType().equals(tbBusinessCar.getPayType())) {
- inTime = tbBusinessCar.getPayTime();
- }
- 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());
- List<PriceDetailItem> detailItemList = partPriceRes.getFireResult().get(0)
- .getPriceDetail();
- detailItemList.forEach(obj -> carMap.put(obj.getKey(), obj.getValue()));
- }
- //todo 计算停车费
- }
- 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 = items.stream().filter(item -> item.getPayStatus() == 0).collect(Collectors.toList());
- for (TbBusinessItem businessItem : items) {
- String num = businessItem.getNum();
- String itemCode = businessItem.getItemCode();
- IOrderItem iOrderItem = new IOrderItem();
- String itemAlias = businessItem.getItemAlias();
- Date startTime = businessItem.getColdStartTime();
- Date endTime = businessItem.getColdEndTime();
- iOrderItem.setExpenseNum(Integer.parseInt(num)).setUniqExpenseId(itemCode);
- if (StrUtil.equals(itemAlias, SystemObject.config.getColdItemAlias())) {
- tbBusinessItemService.buildColdFceItem(businessItem, iOrderItem, startTime, endTime);
- //充电打冷--->按小时计费
- } else if (StrUtil.equals(itemAlias, SystemObject.config.getHeavyStoreItemAlias())
- || StrUtil.equals(itemAlias, SystemObject.config.getEmptyStoreItemAlias())) {
- //空柜堆存、重箱堆存--->按天算
- //如果存柜的话则不收费
- if (businessItem.getCabinetType() == 0) {
- continue;
- }
- tbBusinessItemService.buildDaysFceItem(businessItem, iOrderItem, startTime, endTime);
- } else if (StrUtil.equals(itemAlias, SystemObject.config.getBigHeadCar())
- || StrUtil.equals(itemAlias, SystemObject.config.getCabinetCar())) {
- //大车头、柜车、栏车
- tbBusinessItemService.buildDaysFceItem(businessItem, iOrderItem, startTime, endTime);
- //不收停车费
- carMap.put("price", 0);
- }
- expenses.add(iOrderItem);
- }
- result.put("carList", Collections.singleton(carMap));
- if (!expenses.isEmpty()) {
- 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 -> {
- BigDecimal price = priceItem.getFirePrice().multiply(new BigDecimal(item.getNum()));
- //柜车、栏车只有离场才知道多少钱
- if (StrUtil.equals(item.getItemAlias(),SystemObject.config.getCabinetCar())){
- TbBusiness tbBusiness = this.getById(item.getBusinessId());
- tbBusiness.setItemPrice(price);
- item.setTotal(price);
- tbBusinessItemService.updateById(item);
- this.updateById(tbBusiness);
- }
- itemMap.put("price", price);
- });
- 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);
- }
- 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);
- String pickCustomerId = otherBusinessBO.getPickCustomerId();
- TbCostomer partner = null;
- if (StrUtil.isNotEmpty(pickCustomerId)) {
- partner = tbCostomerService.getById(pickCustomerId);
- tbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName());
- }
- int index = 1;
- int size = cars.size();
- String goodsName = tbGoods.getName();
- for (TbItem tbItem : tbItems) {
- TbItem db = tbItemService.getById(tbItem.getId());
- String itemName = db.getItemName();
- goodsName = goodsName + "—" + itemName;
- String alaisName = db.getItemAlias();
- String startImage = tbItem.getStartImage();
- if (StrUtil.equals(SystemObject.config.getColdItemAlias(), alaisName) && StrUtil.isEmpty(startImage)) {
- throw new AjaxError("请上传开始时间图片");
- }
- TbBusinessItem item = new TbBusinessItem();
- int cabinetType = tbItem.getCabinetType();
- if (!SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
- && !SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
- cabinetType = -1;
- }
- int num = tbItem.getNum();
- String typeId = tbItem.getTypeId();
- TbItemType tbItemType = tbItemTypeService.getById(typeId);
- BigDecimal unitPrice = db.getPrice();
- unitPrice = StrUtil.equals(db.getPattern(), "RULES") ? BigDecimal.ZERO : unitPrice;
- BigDecimal itemTotalPrice = unitPrice.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()).setCabinetType(cabinetType)
- .setCabinetNo(tbItem.getCabinetNo()).setColdStartTime(tbItem.getColdStartTime())
- .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
- .setItemTypeId(typeId).setItemTypeName(tbItemType.getName()).setItemAlias(tbItem.getItemAlias())
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now)
- .setColdStartTime(tbItem.getColdStartTime()).setStartImage(startImage);
- if (partner != null) {
- item.setPick(1).setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName())
- .setPickBy(StpUserUtil.getCreateBy()).setPickTime(now);
- }
- if (SystemObject.config.getEveryCarPay().contains(itemName)) {
- itemTotalPrice = itemTotalPrice.multiply(BigDecimal.valueOf(size));
- }
- //堆存业务
- if (SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
- || SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
- //取柜--->根据柜号查询上一个存柜时间
- TbBusinessItem tbBusinessItem = tbBusinessItemService.findTheLastRecordByCabinetNo(tbItem.getCabinetNo());
- //堆存---》取柜
- if (cabinetType == 1) {
- goodsName = goodsName + "(取柜)";
- if (tbBusinessItem == null) {
- throw new AjaxError("根据柜号" + tbItem.getCabinetNo() + "找不到堆存记录");
- }
- //已经取走
- if (tbBusinessItem.getCabinetStatus() == 1) {
- throw new AjaxError("柜号" + tbItem.getCabinetNo() + "已取走");
- }
- Date endTime = tbItem.getColdStartTime();
- if (endTime == null) {
- throw new AjaxError("请输入取柜时间");
- }
- item.setColdStartTime(tbBusinessItem.getColdStartTime())
- .setParentCabinetId(tbBusinessItem.getId())
- .setColdEndTime(endTime)
- .setCabinetStatus(1);
- tbBusinessItem.setColdEndTime(endTime)
- .setCabinetStatus(1);
- //计算金额
- Date startTime = tbBusinessItem.getColdStartTime();
- if (startTime != null) {
- List<IOrderItem> expenses = new ArrayList<>();
- tbBusinessItemService.buildExpenses(Collections.singletonList(item), expenses);
- if (!expenses.isEmpty()) {
- IOrderPriceRes res = syncService.orderPriceCal(expenses);
- BigDecimal itemPrice = res.getTotalOrderPrice();
- item.setTotal(itemPrice);
- itemTotalPrice = itemPrice;
- }
- }
- tbBusinessItemService.updateById(tbBusinessItem);
- } else {
- goodsName = goodsName + "(存柜)";
- //存柜
- if (tbBusinessItem != null && tbBusinessItem.getCabinetStatus() == 0) {
- throw new AjaxError("柜号" + tbItem.getCabinetNo() + "已存柜未取柜");
- }
- Date endTime = tbItem.getColdStartTime();
- if (endTime == null) {
- throw new AjaxError("请输入存柜时间");
- }
- //业务费xxx都为0;
- BigDecimal zero = BigDecimal.ZERO;
- item.setColdStartTime(endTime).setItemPrice(zero)
- .setTotal(zero).setPayStatus(1);
- //无需支付
- item.setPayStatus(3);
- itemTotalPrice = zero;
- }
- }
- Date startTime = item.getColdStartTime();
- Date endTime = item.getColdEndTime();
- if (startTime != null && endTime != null) {
- List<IOrderItem> expenses = new ArrayList<>();
- tbBusinessItemService.buildExpenses(Collections.singletonList(item), expenses);
- IOrderPriceRes res = syncService.orderPriceCal(expenses);
- item.setTotal(res.getTotalOrderPrice());
- }
- 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(goodsName).setGoodsId(otherBusinessBO.getGoodsId()).setGoodsCode(tbGoods.getCode())
- .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);
- 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 (!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());
- 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())
- .setDriverName(car.getDriverName()).setDriverPhone(car.getDriverPhone())
- .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 AjaxError("记录不存在");
- }
- if (dbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
- throw new AjaxError("业务已审核,请驳回后修改");
- }
- List<TbItem> tbItems = otherBusinessBO.getItems();
- if (tbItems.isEmpty()) {
- throw new AjaxError("请选择收费明细");
- }
- List<TbBusinessCar> cars = otherBusinessBO.getCars();
- if (cars.isEmpty()) {
- throw new AjaxError("作业车辆不能为空");
- }
- 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());
- String carBuseinssNo = DateUtil.format(now, "yyyyMMddHHmm");
- String goodsName = tbGoods.getName();
- List<TbBusinessItem> itemList = new ArrayList<>();
- if (PayEnum.PayStatusEnum.HAS_PAY_CONFIRM.getCode() != dbBusiness.getPayStatus()) {
- List<TbBusinessItem> businessItemList = tbBusinessItemService.findByBusinessId(id);
- //变成未取柜状态
- businessItemList.stream().filter(item -> item.getParentCabinetId() != null).forEach(item -> {
- TbBusinessItem tbBusinessItem = tbBusinessItemService.getById(item.getParentCabinetId());
- tbBusinessItem.setCabinetStatus(0).setColdEndTime(null);
- tbBusinessItemService.updateById(tbBusinessItem);
- });
- tbBusinessItemService.removeByBusinessId(id);
- BigDecimal price = new BigDecimal("0");
- String no = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4);
- int index = 1;
- String pickCustomerId = otherBusinessBO.getPickCustomerId();
- TbCostomer partner = null;
- if (StrUtil.isNotEmpty(pickCustomerId)) {
- partner = tbCostomerService.getById(pickCustomerId);
- dbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName());
- }
- int size = cars.size();
- for (TbItem tbItem : tbItems) {
- TbItem db = tbItemService.getById(tbItem.getId());
- String alaisName = db.getItemAlias();
- String itemName = db.getItemName();
- goodsName = goodsName + "—" + itemName;
- String endImage = tbItem.getEndImage();
- if (StrUtil.equals(SystemObject.config.getColdItemAlias(), alaisName) && StrUtil.isEmpty(endImage)) {
- throw new AjaxError("请上传结束时间图片");
- }
- int cabinetType = tbItem.getCabinetType();
- //如果不是正面吊--->则取/存操作设置为-1
- if (!SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
- && !SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
- cabinetType = -1;
- }
- TbBusinessItem item = new TbBusinessItem();
- int num = tbItem.getNum();
- TbItemType tbItemType = tbItemTypeService.getById(tbItem.getTypeId());
- BigDecimal unitPrice = db.getPrice();
- unitPrice = StrUtil.equals(db.getPattern(), "RULES") ? BigDecimal.ZERO : unitPrice;
- BigDecimal itemTotalPrice = unitPrice.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())
- .setCabinetNo(tbItem.getCabinetNo()).setItemAlias(tbItem.getItemAlias())
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now)
- .setCabinetType(cabinetType).setEndImage(endImage).setStartImage(tbItem.getStartImage())
- .setColdStartTime(tbItem.getColdStartTime()).setColdEndTime(tbItem.getColdEndTime());
- if (partner != null) {
- item.setPick(1).setPickCustomerId(pickCustomerId).setPickCustomerName(partner.getName())
- .setPickBy(StpUserUtil.getCreateBy()).setPickTime(now);
- }
- //装卸-->x车辆数量
- if (SystemObject.config.getEveryCarPay().contains(itemName)) {
- itemTotalPrice = itemTotalPrice.multiply(BigDecimal.valueOf(size));
- item.setTotal(itemTotalPrice);
- }
- Date startTime = item.getColdStartTime();
- Date endTime = item.getColdEndTime();
- if (startTime != null && endTime != null) {
- List<IOrderItem> expenses = new ArrayList<>();
- tbBusinessItemService.buildExpenses(Collections.singletonList(item), expenses);
- if (!expenses.isEmpty()) {
- IOrderPriceRes res = syncService.orderPriceCal(expenses);
- BigDecimal itemPrice = res.getTotalOrderPrice();
- item.setTotal(itemPrice);
- itemTotalPrice = itemPrice;
- }
- }
- //正面吊堆存业务
- if (SystemObject.config.getEmptyStoreItemAlias().equals(alaisName)
- || SystemObject.config.getHeavyStoreItemAlias().equals(alaisName)) {
- //取柜--->根据柜号查询上一个存柜时间
- TbBusinessItem tbBusinessItem = tbBusinessItemService.findTheLastRecordByCabinetNo(tbItem.getCabinetNo());
- //堆存
- if (cabinetType == 1) {//取柜
- if (tbBusinessItem == null) {
- throw new AjaxError("根据柜号" + tbItem.getCabinetNo() + "找不到堆存记录");
- }
- if (endTime == null) {
- throw new AjaxError("请输入取柜时间");
- }
- goodsName = goodsName + "(取柜)";
- item.setColdStartTime(tbBusinessItem.getColdStartTime())
- .setParentCabinetId(tbBusinessItem.getId())
- .setColdEndTime(endTime);
- tbBusinessItem.setColdEndTime(endTime)
- .setCabinetStatus(1);
- tbBusinessItemService.updateById(tbBusinessItem);
- } else {
- if (startTime == null) {
- throw new AjaxError("请输入存柜时间");
- }
- String businessItemId = tbItem.getBusinessItemId();
- if (StrUtil.isNotEmpty(businessItemId)
- && tbBusinessItem != null
- && !StrUtil.equals(businessItemId, tbBusinessItem.getId() + "")
- && tbBusinessItem.getColdEndTime() == null) {
- throw new AjaxError("箱规未取走,不能存入");
- }
- goodsName = goodsName + "(存柜)";
- //业务费xxx都为0;
- BigDecimal zero = BigDecimal.ZERO;
- item.setColdStartTime(endTime).setItemPrice(zero)
- .setTotal(zero).setPayStatus(1).setPayTime(now);
- itemTotalPrice = zero;
- item.setColdStartTime(startTime);
- //无需支付
- item.setPayStatus(3);
- }
- }
- 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();
- 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) {
- throw new AjaxError("车辆【" + carNo + "】未入场");
- } 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())
- .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
- tbBusinessCarService.updateById(dbBusinessCar);
- }
- } else {
- TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
- //不存在或者已经离场的
- if (checkCar == null) {
- throw new AjaxError("车辆【" + carNo + "】未入场");
- }
- checkCar.setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
- .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
- .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType()).setBusinessType(1)
- .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
- 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(goodsName).setPayStep(tbGoods.getPayStep());
- }
- String customerId = otherBusinessBO.getCustomerId();
- if (StrUtil.isNotEmpty(customerId)) {
- TbCostomer tbCostomer = tbCostomerService.getById(customerId);
- dbBusiness.setCustomerId(customerId).setCustomerName(tbCostomer.getName());
- }
- String pickCustomerId = otherBusinessBO.getPickCustomerId();
- if (StrUtil.isNotEmpty(pickCustomerId)) {
- TbCostomer tbCostomer = tbCostomerService.getById(pickCustomerId);
- dbBusiness.setPickCustomerId(pickCustomerId).setPickCustomerName(tbCostomer.getName());
- }
- dbBusiness.setCardSize(otherBusinessBO.getCarSize()).setNetWeight(otherBusinessBO.getNetWeight())
- .setOperator(otherBusinessBO.getOperator()).setOperateTime(otherBusinessBO.getOperateTime())
- .setGoodsId(otherBusinessBO.getGoodsId()).setGoodsCode(tbGoods.getCode()).setGoodsName(goodsName)
- .setOwner(otherBusinessBO.getOwner()).setBusinessGoodsName(otherBusinessBO.getBusinessGoodsName())
- .setBusinessGoodsNum(otherBusinessBO.getBusinessGoodsNum())
- .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);
- if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
- throw new AjaxError("业务已审核,请先驳回");
- }
- List<TbBusinessCar> list = tbBusinessCarService.findOtherBusinessCar(businessId);
- 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;
- }
- //计算停车费
- IOrderPriceRes parkMoney = this.getPartMoney(inTime, outTime, tbBusinessCar.getCarNo(), tbBusinessCar.getColor());
- tbBusinessCar.setMoney(parkMoney.getTotalOrderPrice());
- }
- /**
- * 发起流程审批
- *
- * @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);
- 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));
- 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);
- }
- /**
- * 额外添加车牌
- *
- * @param tbBusinessCar
- */
- public void addBusinessCar(TbBusinessCar tbBusinessCar) {
- String businessId = tbBusinessCar.getBusinessId();
- TbBusiness tbBusiness = this.getById(businessId);
- if (tbBusiness.getConfirmJudge() == CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode()) {
- throw new AjaxError("业务已审核,不能绑定新车辆");
- }
- String carNo = tbBusinessCar.getCarNo().trim().toUpperCase();
- TbBusinessCar lastRecord = tbBusinessCarService.findTheLastRecord(carNo);
- String businessCarId;
- Date now = new Date();
- if (lastRecord == null || lastRecord.getRealOutTime() != null) {
- //不存在或者已经离场
- tbBusinessCar
- .setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType())
- .setCarNo(carNo).setPay(0).setIsLock(0).setPayUnloadMoney(0)
- .setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType()).setPay(0)
- .setCreateTime(now).setCarType(CarEnum.CarTypeEnum.EMPTY_TYPE.getType())
- .setTimeUpdate(now)
- .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_NEED_JUDGE.getCode())
- .setNo(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")) + RandomUtil.randomNumbers(4));
- tbBusinessCarService.save(tbBusinessCar);
- businessCarId = tbBusinessCar.getId();
- } else {
- businessCarId = lastRecord.getId();
- lastRecord.setPayType(CarEnum.PayTypeEnum.NO_PAY_TYPE.getType())
- .setCustomerId(tbBusiness.getCustomerId())
- .setCarNo(carNo).setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode())
- .setPayUnloadMoney(lastRecord.getPayUnloadMoney())
- .setTimeUpdate(now)
- .setBusinessType(CarEnum.BusinessTypeEnum.BUSINESS_CAR.getType());
- tbBusinessCarService.updateById(lastRecord);
- }
- tbBusiness.setCardNo(tbBusiness.getCardNo() + "、" + carNo);
- this.updateById(tbBusiness);
- RelationBusinessCar relationBusinessCar = new RelationBusinessCar();
- relationBusinessCar.setBusinessId(businessId).setBusinessCarId(businessCarId);
- relationBusinessCarService.save(relationBusinessCar);
- }
- /**
- * 删除业务车
- *
- * @param carId
- * @param businessId
- */
- public void deleteBusinessCar(String carId, String businessId) {
- relationBusinessCarService.removeByBusinessIdAndCarId(businessId, carId);
- List<RelationBusinessCar> list = relationBusinessCarService.findByBusinessCarId(carId);
- if (list.isEmpty()) {
- TbBusinessCar db = tbBusinessCarService.getById(carId);
- if (db.getRealInTime() == null) {
- tbBusinessCarService.removeById(carId);
- }
- }
- }
- /**
- * 审核通过
- *
- * @param id
- */
- public void confirmJudgePass(String id) {
- TbBusiness tbBusiness = this.getById(id);
- if (tbBusiness == null) {
- throw new AjaxError("业务不存在");
- }
- Date now = new Date();
- List<TbBusinessCar> tbBusinessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
- //审核
- List<TbBusinessItem> tbBusinessItems = tbBusinessItemService.findByBusinessId(tbBusiness.getId());
- String customerId = tbBusiness.getPickCustomerId();
- TbAccount tbAccount = tbAccountService.getAccountByCustomerId(customerId);
- for (TbBusinessCar tbBusinessCar : tbBusinessCars) {
- for (TbBusinessItem item : tbBusinessItems) {
- String itemName = item.getItemName();
- // todo 扣除 人工、机械装卸车辆---->每辆车都要支付----->
- if (SystemObject.config.getEveryCarPay().contains(itemName) && tbBusinessCar.getPayUnloadMoney() == 0) {
- List<IOrderItem> expenses = new ArrayList<>();
- IOrderItem orderItem = new IOrderItem();
- orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
- .setUniqExpenseId(item.getItemCode());
- expenses.add(orderItem);
- IOrderPriceRes res = syncService.orderPriceCal(expenses);
- BigDecimal price = res.getTotalOrderPrice();
- BigDecimal balance = tbAccount.getTotalMoney();
- if (price.compareTo(balance) > 0) {
- throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
- } else {
- tbBusinessCar.setPayUnloadMoney(1);
- tbBusinessCarService.updateById(tbBusinessCar);
- item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
- .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
- tbBusinessItemService.updateById(item);
- tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney())).setPayTime(now);
- BigDecimal afterBalance = balance.subtract(price);
- tbAccount.setTotalMoney(afterBalance);//增加累计扣款
- tbAccountService.updateById(tbAccount);
- TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
- tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
- TbDeductionRecord record = automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
- addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(), details, record);
- }
- }
- }
- }
- //其他费项 装卸业务管理费” 进行预存款扣除
- for (TbBusinessItem item : tbBusinessItems) {
- String aliasName = item.getItemAlias();
- //充电打冷,正面吊(取柜)必须得有开始时间+结束时间
- if (StrUtil.equals(aliasName, SystemObject.config.getColdItemAlias())
- || (StrUtil.equals(aliasName, SystemObject.config.getEmptyStoreItemAlias())
- && item.getCabinetType() == 1)
- || (StrUtil.equals(aliasName, SystemObject.config.getHeavyStoreItemAlias())
- && item.getCabinetType() == 1)
- ) {
- if (item.getColdStartTime() == null || item.getColdEndTime() == null) {
- throw new AjaxError("请先点击【修改】,然后录入业务开始/结束时间");
- }
- }
- //业务类型是装卸业务管理费且未支付的进行扣款
- if (item.getPayStatus() == 0 && SystemObject.config.getUnLoadItem().contains(item.getItemTypeName())) {
- List<IOrderItem> expenses = new ArrayList<>();
- IOrderItem orderItem = new IOrderItem();
- orderItem.setExpenseNum(Integer.parseInt(item.getNum()))
- .setUniqExpenseId(item.getItemCode());
- expenses.add(orderItem);
- IOrderPriceRes res = syncService.orderPriceCal(expenses);
- BigDecimal price = res.getTotalOrderPrice();
- BigDecimal balance = tbAccount.getTotalMoney();
- if (price.compareTo(balance) > 0) {
- throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());
- } else {
- BigDecimal afterBalance = balance.subtract(price);
- tbAccount.setTotalMoney(afterBalance);//增加累计扣款
- tbAccountService.updateById(tbAccount);
- item.setPayTime(now).setPayStatus(1).setPayType(PayEnum.PayType.PER_PAY.getCode())
- .setPayTypeName(PayEnum.PayType.PER_PAY.getDesc());
- tbBusinessItemService.updateById(item);
- tbBusiness.setPayMoney(price.add(tbBusiness.getPayMoney())).setPayTime(now);
- //查找越南车--->统计以--->重车对集装箱吊装 (重 柜 ) =====空车 vs 集装箱吊装 (空 柜 )
- String itemAlias = item.getItemAlias();
- TbBusinessCar tbBusinessCar = tbBusinessCars.stream().filter(car -> car.getCarType().equals(CarEnum.CarTypeEnum.EMPTY_TYPE.getType()))
- .findAny().orElse(tbBusinessCars.get(0));
- if (StrUtil.equals(itemAlias, SystemObject.config.getHeavyCondoleItemAlias())) {
- tbBusinessCar = tbBusinessCars.stream().filter(car -> car.getCarType().equals(CarEnum.CarTypeEnum.WEIGHT_TYPE.getType()))
- .findAny().orElse(tbBusinessCars.get(0));
- }
- TbFeeDetails details = tbFeeDetailsService.savePrePayDetails(res, item, tbBusinessCar, tbBusiness, FeeTypeEnum.STEVEDORE_FEE);
- tbFeeStatisticsService.addOrUpdateStatistic(now, PayEnum.PayType.PER_PAY.getCode());//更新当前日期的日统计
- TbDeductionRecord record = automaticPay.createTbDeductionRecord(details, balance, afterBalance, tbBusiness.getPickCustomerId(), tbBusiness.getPickCustomerName(), tbBusinessCar.getCarNo(), tbBusinessCar.getId(), FeeTypeEnum.STEVEDORE_FEE);
- addInvoiceOrder(tbBusiness, res.getTotalOrderPrice(), details, record);
- }
- }
- }
- tbBusiness.setConfirmJudgeTime(now).setConfirmJudgeContent("审核通过")
- .setConfirmJudge(CarEnum.ConfirmJudgeEnum.JUDGE_PASS.getCode())
- .setJudgeBy(StpUserUtil.getCreateBy());
- this.updateById(tbBusiness);
- }
- /**
- * 添加开票订单
- *
- * @param tbBusiness
- * @param billMoney
- */
- private void addInvoiceOrder(TbBusiness tbBusiness, BigDecimal billMoney, TbFeeDetails details, TbDeductionRecord record) {
- TbInvoiceOrder t = new TbInvoiceOrder();
- t.setBusinessName(tbBusiness.getGoodsName())
- .setBusinessNo(tbBusiness.getNo())
- .setCarNo(tbBusiness.getCarNoStr())
- .setBusinessId(tbBusiness.getId())
- .setCustomerId(tbBusiness.getCustomerId())
- .setBillMoney(billMoney).setDetailId(details.getId())
- .setPreOrderNum(details.getPreOrderNum())
- .setDeductionRecordId(record.getId())
- .setStatus(0).setCreateTime(new Date());
- tbInvoiceOrderService.save(t);
- }
- /**
- * 审核驳回
- *
- * @param id
- * @param judgeContent
- */
- public void callback(String id, String judgeContent) {
- TbBusiness db = this.getById(id);
- db.setConfirmJudge(CarEnum.ConfirmJudgeEnum.CALL_BACK.getCode())
- .setConfirmJudgeContent(judgeContent).setConfirmJudgeTime(new Date())
- .setJudgeBy(StpUserUtil.getCreateBy());
- this.updateById(db);
- }
- }
|