123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- package com.pj.api.service;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.RandomUtil;
- import cn.hutool.core.util.StrUtil;
- import com.pj.api.bo.InOutRecordBO;
- import com.pj.api.bo.SearchBO;
- import com.pj.api.wx.bo.MsgDataBO;
- import com.pj.api.wx.service.WxService;
- import com.pj.constants.UserTypeEnum;
- import com.pj.current.config.MyConfig;
- import com.pj.current.config.WxConfig;
- import com.pj.current.satoken.StpUserUtil;
- import com.pj.project.tb_account.TbAccount;
- import com.pj.project.tb_account.TbAccountService;
- import com.pj.project.tb_business.TbBusiness;
- import com.pj.project.tb_business.TbBusinessService;
- 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_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_record.TbDeductionRecord;
- import com.pj.project.tb_deduction_record.TbDeductionRecordService;
- import com.pj.project.tb_discount.TbDiscount;
- import com.pj.project.tb_discount.TbDiscountService;
- import com.pj.project.tb_disinfect.TbDisinfect;
- import com.pj.project.tb_disinfect.TbDisinfectService;
- import com.pj.project.tb_pass_record.TbPassRecord;
- import com.pj.project.tb_pass_record.TbPassRecordService;
- import com.pj.project4sp.admin.SpAdmin;
- import com.pj.project4sp.admin.SpAdminService;
- import com.pj.project4sp.global.BusinessException;
- import com.pj.utils.cache.RedisUtil;
- import com.pj.utils.sg.AjaxJson;
- import com.pj.utils.so.SoMap;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.nio.charset.Charset;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- *
- */
- @Service
- @Transactional(rollbackFor = Exception.class)
- @Slf4j
- public class ApiService {
- @Resource
- TbCostomerService tbCostomerService;
- @Resource
- @Lazy
- TbBusinessService tbBusinessService;
- @Resource
- TbPassRecordService tbPassRecordService;
- @Resource
- @Lazy
- TbBusinessCarService tbBusinessCarService;
- @Resource
- private TbDeclareService tbDeclareService;
- @Resource
- @Lazy
- private TbDisinfectService tbDisinfectService;
- @Resource
- private TbAccountService accountService;
- @Resource
- private TbDiscountService tbDiscountService;
- @Resource
- private TbBusinessItemService tbBusinessItemService;
- @Resource
- private SpAdminService spAdminService;
- @Resource
- private WxService wxService;
- @Resource
- private WxConfig wxConfig;
- @Resource
- private MyConfig myConfig;
- @Resource
- private TbDeductionRecordService tbDeductionRecordService;
- public List<InOutRecordBO> getInOutRecord(SoMap so) {
- List<TbPassRecord> passRecords = tbPassRecordService.getList(so);
- List<InOutRecordBO> recordList = new ArrayList<>();
- for (TbPassRecord passRecord : passRecords) {
- InOutRecordBO record = new InOutRecordBO();
- BeanUtil.copyProperties(passRecord, record);
- TbCostomer costomer = tbCostomerService.getById(passRecord.getCustomerId());
- record.setCustomerContact(costomer.getPhone()).setDutyPeople(costomer.getDutyPeople());
- recordList.add(record);
- }
- return recordList;
- }
- public List<TbCostomer> getCustomerList(SoMap so) {
- List<TbCostomer> list = tbCostomerService.getList(so);
- return list;
- }
- public void confirmCustomer(Long customerId, String judgeContent) {
- TbCostomer costomer = tbCostomerService.getById(customerId);
- if (costomer != null && costomer.getJudgeStatus() == 1) {
- tbCostomerService.judge(customerId + "", 2, judgeContent);
- }
- }
- public List<SearchBO> searchPartCar(String carNo) {
- if (StrUtil.isEmpty(carNo) || StrUtil.length(carNo) < 3) {
- return Collections.emptyList();
- }
- carNo = carNo.toUpperCase();
- List<TbBusinessCar> businessCarList = tbBusinessCarService.findNotPayByCarNo(carNo);
- return businessCarList.stream().map(tbBusinessCar -> {
- SearchBO searchBO = new SearchBO();
- searchBO.setId(tbBusinessCar.getId()).setCarNo(tbBusinessCar.getCarNo());
- return searchBO;
- }).distinct().collect(Collectors.toList());
- }
- public void confirm(List<String> ids) {
- tbBusinessService.confirm(ids);
- }
- public Map<String, Object> getBusinessMoney(String carId, String state) {
- return tbBusinessService.getBusinessMoney(carId, state);
- }
- public Map<String, Object> getPartCarByChannel(String channel) {
- Map<String, Object> result = new HashMap<>();
- String carNo = RedisUtil.get(channel);
- if (StrUtil.isEmpty(carNo)) {
- return result;
- }
- TbBusinessCar tbBusinessCar = tbBusinessCarService.findTheLastRecord(carNo);
- if (tbBusinessCar == null) {
- return result;
- }
- Date now = new Date();
- Date startTime = tbBusinessCar.getRealInTime();
- if (tbBusinessCar.getPayTime() != null) {
- startTime = tbBusinessCar.getPayTime();
- }
- BigDecimal price = tbBusinessService.calculationPartMoney(startTime, now, tbBusinessCar.getCarSize());
- Map<String, Object> car = new HashMap<>();
- car.put("id", tbBusinessCar.getId());
- car.put("carNo", tbBusinessCar.getCarNo());
- car.put("price", price);
- result.put("total", price);
- result.put("cars", Collections.singleton(car));
- return result;
- }
- public void addDeclare(TbDeclare tbDeclare) {
- if (StpUserUtil.isLogin() && !StrUtil.equals(UserTypeEnum.PLATFORM_ADMIN.getCustomerId(), StpUserUtil.getCustomerId())) {
- String currentCustomerId = StpUserUtil.getCustomerId();
- tbDeclare.setCustomerId(currentCustomerId);
- }
- TbCostomer tbCostomer = tbCostomerService.getById(tbDeclare.getCustomerId());
- tbDeclare.setCustomerName(tbCostomer.getName());
- String chinaCarNo = tbDeclare.getChinaCarNo();
- if (StrUtil.isNotEmpty(chinaCarNo)) {
- chinaCarNo = chinaCarNo.toUpperCase();
- tbDeclare.setChinaCarNo(chinaCarNo);
- }
- String carNo = tbDeclare.getCarNo();
- if (StrUtil.isNotEmpty(carNo)) {
- carNo = carNo.toUpperCase();
- tbDeclare.setCarNo(carNo);
- }
- String nowStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
- tbDeclare.setCreateTime(new Date()).setDeclareNo(nowStr + RandomUtil.randomNumbers(6));
- tbDeclareService.save(tbDeclare);
- }
- public void addDisinfect(TbDisinfect tbDisinfect) {
- if (StpUserUtil.isLogin() && !StrUtil.equals(UserTypeEnum.PLATFORM_ADMIN.getCustomerId(), StpUserUtil.getCustomerId())) {
- String currentCustomerId = StpUserUtil.getCustomerId();
- tbDisinfect.setCustomerId(currentCustomerId);
- }
- TbCostomer tbCostomer = tbCostomerService.getById(tbDisinfect.getCustomerId());
- tbDisinfect.setCustomerName(tbCostomer.getName()).setApplyUnit(tbCostomer.getName());
- String nowStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
- tbDisinfect.setCode(nowStr + RandomUtil.randomNumbers(6)).setApplyTime(DateUtil.now());
- tbDisinfectService.save(tbDisinfect);
- }
- public List<TbDeclare> getDeclareList(SoMap so) {
- return tbDeclareService.getList(so);
- }
- public TbAccount getAccountInfo(String customerId) {
- return accountService.getByCustomerId(customerId);
- }
- public List<TbDiscount> getDiscountInfo(SoMap so) {
- return tbDiscountService.getList(so);
- }
- public TbBusinessItem getBusinessItem(String id) {
- TbBusinessItem item = tbBusinessItemService.getById(id);
- TbBusiness business = tbBusinessService.getById(item.getBusinessId());
- item.setCardNo(business.getCardNo()).setChinaCarNo(business.getChinaCarNo()).setGoodsName(business.getGoodsName());
- return item;
- }
- public AjaxJson pickBusinessItem(String openid, long id) {
- TbBusinessItem tbBusinessItem = tbBusinessItemService.getById(id);
- if (tbBusinessItem == null) {
- return AjaxJson.getError("业务项目或已被删除");
- }
- SpAdmin spAdmin = spAdminService.findByOpenid(openid);
- if (spAdmin == null) {
- return AjaxJson.getError("用户已被删除或解绑");
- }
- if (tbBusinessItem.getPick() == 1) {
- return AjaxJson.getError("您慢了一步,其他用户已接单");
- }
- String adminId = spAdmin.getId() + "";
- String adminName = StrUtil.isNotEmpty(spAdmin.getNickname()) ? spAdmin.getNickname() : spAdmin.getName();
- String customerId = spAdmin.getCustomerId();
- TbCostomer tbCostomer = tbCostomerService.getById(customerId);
- tbBusinessItem.setPick(1).setPickTime(new Date()).setPickCustomerId(tbCostomer.getId()).setPickCustomerName(tbCostomer.getName())
- .setPickBy(adminName).setPickByAdminId(adminId);
- tbBusinessItemService.updateById(tbBusinessItem);
- //更新扣款记录里面的合作伙伴信息
- TbDeductionRecord tbDeductionRecord = tbDeductionRecordService.findByBusinessItemId(tbBusinessItem.getId());
- if (tbDeductionRecord != null) {
- tbDeductionRecord.setPickCustomerName(tbCostomer.getName());
- tbDeductionRecordService.updateById(tbDeductionRecord);
- }
- //todo 通知录入人员 已接单
- List<SpAdmin> spAdminList = spAdminService.findByCustomerId(UserTypeEnum.PLATFORM_ADMIN.getCustomerId());
- TbBusiness tbBusiness = tbBusinessService.getById(tbBusinessItem.getBusinessId());
- MsgDataBO msgDataBO = new MsgDataBO("订单号:" + tbBusinessItem.getNo(), tbCostomer.getName(), DateUtil.now(), tbBusiness.getGoodsName() + "(" + tbBusinessItem.getItemTypeName() + tbBusinessItem.getItemName() + ")");
- spAdminList.stream().filter(admin -> StrUtil.isNotEmpty(admin.getOpenid())).forEach(admin -> {
- String detailUrl = myConfig.getWebDomain() + "/pages/business-order/business-item?id=" + tbBusiness.getId() + "&itemId=" + tbBusinessItem.getId() + "&openid=" + admin.getOpenid();
- log.info("admin confirm business:[{}]", detailUrl);
- wxService.sendTemplateMsg(wxConfig.getBusinessPickTemplate(), admin.getOpenid(), msgDataBO, detailUrl);
- });
- return AjaxJson.getSuccess();
- }
- public void confirmBusinessItem(long id) {
- tbBusinessItemService.confirmBusinessItem(id);
- }
- public List<TbBusinessItem> getPartnerBusinessItem(SoMap startPage) {
- List<TbBusinessItem> list = tbBusinessItemService.getList(startPage);
- list.parallelStream().forEach(tbBusinessItem -> {
- TbBusiness tbBusiness = tbBusinessService.getById(tbBusinessItem.getBusinessId());
- List<TbBusinessCar> businessCars = tbBusinessCarService.findOtherBusinessCar(tbBusiness.getId());
- tbBusinessItem.setCardNo(businessCars.stream().map(TbBusinessCar::getCarNo).collect(Collectors.joining("、")));
- });
- return list;
- }
- public String handlerDesc(String desc) {
- if (desc.getBytes(Charset.forName("utf-8")).length > 128) {
- desc = StrUtil.sub(desc, 0, desc.lastIndexOf("-"));
- handlerDesc(desc);
- }
- return desc;
- }
- }
|