123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701 |
- 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());
- }
- 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;
- }
- /**
- * 微信端获取缴费信息
- *
- * @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 (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());
- //如果不需要支付,则过滤掉入场管理费
- // ManagerBO dto = needPayManagerMoney(carNo, businessCarId, items);
- // if (dto.isNeed()) {
- // result.put("manager", dto);
- // }
- items.forEach(item -> {
- String num = item.getNum();
- String itemCode = item.getItemCode();
- IOrderItem iOrderItem = new IOrderItem();
- iOrderItem.setExpenseNum(Integer.parseInt(num)).setUniqExpenseId(itemCode);
- expenses.add(iOrderItem);
- });
- 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 -> {
- 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;
- }
- /**
- * 是否需要交入场管理费
- *
- * @param carNo
- * @return
- */
- public ManagerBO needPayManagerMoney(String carNo, String carId, List<TbBusinessItem> items) {
- ManagerBO dto = new ManagerBO();
- List<String> needItemTypeList = SystemObject.config.getManagerItemType();
- //是否有相关业务,,,没有的话直接不用交入场管理费
- boolean before = items.stream().anyMatch(item -> needItemTypeList.contains(item.getItemTypeName()));
- if (!before) {
- return dto;
- }
- String carPrefix = StrUtil.sub(carNo, 0, 1);
- boolean isvietnamCar = !CAR_LIST.contains(carPrefix);
- List<Integer> managerList = SystemObject.config.getManagerMoney();
- //越南车是否需要支付
- boolean verNeePay = managerList.contains(ManagerEnum.VER_PAY.getType());
- //中国车是否需要支付
- boolean chinaNeePay = managerList.contains(ManagerEnum.CHINA_PAY.getType());
- //是否需要支付入场管理费
- boolean need = isvietnamCar && verNeePay || !isvietnamCar && chinaNeePay;
- dto.setNeed(need);
- if (need) {
- //查询出对应的费项
- TbItem tbItem = tbItemService.findByName(SystemObject.config.getManagerWord());
- if (tbItem != null) {
- List<IOrderItem> itemList = new ArrayList<>();
- IOrderItem iOrderItem = new IOrderItem();
- iOrderItem.setExpenseNum(1).setUniqExpenseId(tbItem.getItemCode());
- itemList.add(iOrderItem);
- IOrderPriceRes managerPriceRes = syncService.orderPriceCal(itemList);
- dto.setCalculateId(managerPriceRes.getCalculateId())
- .setPrice(managerPriceRes.getTotalOrderPrice())
- .setCarNo(carNo).setId(tbItem.getId())
- .setLabel(tbItem.getItemName() + "(入场管理费)")
- .setName(tbItem.getItemName()).setCarId(carId);
- }
- }
- return dto;
- }
- 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();
- for (TbItem tbItem : tbItems) {
- TbItem db = tbItemService.getById(tbItem.getId());
- String itemName = db.getItemName();
- 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()).setCabinetNo(tbItem.getCabinetNo())
- .setItemName(db.getItemName()).setItemPrice(db.getPrice()).setRemark(tbItem.getRemark())
- .setItemTypeId(typeId).setItemTypeName(tbItemType.getName())
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
- 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));
- }
- 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);
- 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 (!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())
- .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");
- 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;
- 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 itemName = db.getItemName();
- 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())
- .setCabinetNo(tbItem.getCabinetNo())
- .setUnit(db.getUnit()).setTotal(itemTotalPrice).setCreateTime(now);
- 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));
- }
- 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);
- }
- if (StrUtil.isNotEmpty(businessCarId)) {
- //原来已存在的
- TbBusinessCar dbBusinessCar = tbBusinessCarService.getById(businessCarId);
- //如果修改了车牌号
- String dbCarNo = dbBusinessCar.getCarNo();
- if (!dbCarNo.equals(carNo)) {
- //把关联删除掉,然后添加新的关联
- relationBusinessCarService.removeByBusinessIdAndCarId(dbBusiness.getId(), businessCarId);
- TbBusinessCar otherCar = tbBusinessCarService.findTheLastRecord(carNo);
- if (otherCar == null ||//不存在或者已离场===>新建
- (otherCar.getRealInTime() != null && otherCar.getRealOutTime() != null)) {
- otherCar = new TbBusinessCar();
- otherCar.setCreateTime(now).setPay(0).setNo(carBuseinssNo + RandomUtil.randomNumbers(4))
- .setCarNo(carNo).setCarType(tbBusinessCar.getCarType()).setCarSize(tbBusinessCar.getCarSize())
- .setNetWeight(tbBusinessCar.getNetWeight()).setCustomerId(dbBusiness.getCustomerId())
- .setTimeUpdate(now).setIsLock(0).setCarType(tbBusinessCar.getCarType())
- .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
- 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())
- .setConfirmJudge(CarEnum.ConfirmJudgeEnum.NO_JUDGE.getCode());
- tbBusinessCarService.updateById(dbBusinessCar);
- }
- } else {
- TbBusinessCar checkCar = tbBusinessCarService.findTheLastRecord(carNo);
- //不存在或者已经离场的
- if (checkCar == null ||
- (checkCar.getRealInTime() != null && checkCar.getRealOutTime() != null)) {
- checkCar = new TbBusinessCar();
- checkCar.setCreateTime(now).setPay(0).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()).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(tbGoods.getName()).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())
- .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()));
- 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) {
- //业务类型是装卸业务管理费且未支付的进行扣款
- 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()));
- //查找越南车--->统计以
- TbBusinessCar tbBusinessCar = tbBusinessCars.stream().filter(car -> !CAR_LIST.contains(car.getCarNo().substring(0, 1)))
- .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()).setPayTime(now);
- 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);
- }
- }
|