123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- package com.pj.project.tb_item;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.util.NumberUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.json.JSONUtil;
- 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.constants.business.CarEnum;
- import com.pj.constants.business.SyncTypeEnum;
- import com.pj.project.relation_type_item.RelationTypeItem;
- import com.pj.project.relation_type_item.RelationTypeItemService;
- import com.pj.project.sync.HelpService;
- import com.pj.project.sync.bo.ItemTypeBO;
- import com.pj.project.sync.response.item.IExpenseItem;
- import com.pj.project.sync.response.item.IrulesItem;
- import com.pj.project.tb_costomer.TbCostomer;
- import com.pj.project.tb_fee_item.TbFeeItem;
- import com.pj.project.tb_fee_item.TbFeeItemService;
- 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.utils.so.SoMap;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.util.Date;
- import java.util.List;
- /**
- * Service: tb_item -- 作业配置项
- *
- * @author qzy
- */
- @Service
- @Slf4j
- @Transactional
- public class TbItemService extends ServiceImpl<TbItemMapper, TbItem> implements IService<TbItem> {
- /**
- * 底层 Mapper 对象
- */
- @Autowired
- TbItemMapper tbItemMapper;
- @Resource
- private HelpService helpService;
- @Resource
- RelationTypeItemService relationTypeItemService;
- @Resource
- private TbItemTypeService tbItemTypeService;
- @Resource
- private TbItemFacService tbItemFacService;
- @Resource
- private TbFeeItemService tbFeeItemService;
- /**
- * 删
- */
- void delete(Long id) {
- this.removeById(id);
- }
- /**
- * 查集合 - 根据条件(参数为空时代表忽略指定条件)
- */
- List<TbItem> getList(SoMap so) {
- return tbItemMapper.getList(so);
- }
- public List<TbItem> getTypeItemList(SoMap soMap) {
- return tbItemMapper.getTypeItemList(soMap);
- }
- public List<TbItem> getItemTypeById(String typeId) {
- return tbItemMapper.getItemTypeById(typeId);
- }
- public TbItem findByCode(String code) {
- QueryWrapper<TbItem> ew = new QueryWrapper<>();
- ew.eq("item_code", code);
- List<TbItem> list = list(ew);
- return list.isEmpty() ? null : list.get(0);
- }
- /**
- * 费项详情
- *
- * @param request
- */
- public void receive(String request) {
- IExpenseItem iExpenseItem = helpService.deCrypte(request, IExpenseItem.class);
- TbItemType tbItemType = tbItemTypeService.findByCode(iExpenseItem.getBizTypeNo());
- log.info("detail:{}", JSONUtil.toJsonStr(iExpenseItem));
- if (tbItemType == null) {
- log.error("类型不存在");
- return;
- }
- String uniqueExpenseId = iExpenseItem.getUniqueExpenseId();
- String syncType = iExpenseItem.getSyncType();
- if (StrUtil.equals(syncType, SyncTypeEnum.DELETE.getCode())) {
- TbItem db = findByCode(uniqueExpenseId);
- if (db != null) {
- this.removeById(db.getId());
- relationTypeItemService.removeByItemId(db.getId());
- tbItemFacService.removeByItemId(db.getId());
- }
- } else {
- TbItem tbItem = handlerItem(tbItemType, iExpenseItem, new Date());
- //多规格费项因子
- if (StrUtil.equals(iExpenseItem.getPattern(), "RULES")) {
- handlerFac(iExpenseItem, tbItem, iExpenseItem.getUniqueExpenseId());
- }
- }
- }
- /**
- * 处理费项详情
- *
- * @param tbItemType
- * @param item
- * @param now
- * @return
- */
- private TbItem handlerItem(TbItemType tbItemType, IExpenseItem item, Date now) {
- String name = item.getExpenseName();
- String code = item.getUniqueExpenseId();
- TbItem tbItem = this.findByCode(code.trim());
- if (tbItem == null) {
- tbItem = new TbItem();
- }
- String payType = tbItemType.getPayType();
- tbItem.setPayType(Integer.parseInt(payType))
- .setPayTypeName(tbItemType.getPayTypeName());
- String typeId = tbItemType.getId();
- tbItem.setItemCode(code).setItemName(name).setUnit(item.getExpenseUnit()).setStatus(1)
- .setInc(1).setNeedRemark(0).setPrice(item.getFixedPrice()).setMinLength(0).setCarLength(25)
- .setMinWeight(0).setMaxWeight(999999).setTaxRate(item.getTaxRate().doubleValue())
- .setTypeId(typeId)
- .setTypeName(tbItemType.getName())
- .setItemType(CarEnum.CarTypeEnum.EMPTY_TYPE.getDesc() + "," + CarEnum.CarTypeEnum.WEIGHT_TYPE.getDesc());
- String businessType = tbItemType.getBusinessType();
- if (StrUtil.isEmpty(businessType) || StrUtil.equals("0", businessType)) {
- tbItem.setBusinessType(TbCostomer.CustomerEnum.BUSINESS_TYPE.getType())
- .setBusinessTypeName("默认");
- } else {
- tbItem.setBusinessType(businessType).setBusinessTypeName(tbItemType.getPayTypeName());
- }
- this.saveOrUpdate(tbItem);
- RelationTypeItem relationTypeItem = relationTypeItemService.findByTypeIdAndItemId(typeId, tbItem.getId());
- if (relationTypeItem == null) {
- relationTypeItem = new RelationTypeItem();
- relationTypeItem.setInc(1).setNeedRemark(0).setMustRemark(0);
- }
- relationTypeItem.setTypeId(typeId).setItemId(tbItem.getId())
- .setTypeName(tbItemType.getName());
- relationTypeItemService.saveOrUpdate(relationTypeItem);
- return tbItem;
- }
- /**
- * 费项因子
- *
- * @param item
- * @param tbItem
- */
- private void handlerFac(IExpenseItem item, TbItem tbItem, String uniqueExpenseId) {
- List<IrulesItem> rules = item.getRules();
- doHanlder(rules, tbItem, uniqueExpenseId);
- }
- private void doHanlder(List<IrulesItem> rules, TbItem tbItem, String uniqueExpenseId) {
- rules.forEach(irulesItem -> {
- Long facId = irulesItem.getFacId();
- TbItemFac tbItemFac = tbItemFacService.getByFaceId(facId);
- if (tbItemFac == null) {
- tbItemFac = new TbItemFac();
- }
- String rangeVal = irulesItem.getPriceFactor().getRangeVal();
- List<String> rangeVals = StrUtil.splitTrim(rangeVal, "$$");
- String minVal = rangeVals.get(0);
- if (NumberUtil.isNumber(minVal)) {
- tbItemFac.setMinRange(Double.valueOf(minVal));
- }
- String maxVal = rangeVals.get(1);
- if (NumberUtil.isNumber(maxVal)) {
- tbItemFac.setMaxRange(Double.valueOf(maxVal));
- }
- tbItemFac.setName(irulesItem.getPriceFactor().getFacName()).setOperator(irulesItem.getPriceFactor().getAliasName())
- .setTextType(irulesItem.getPriceFactor().getTextType())
- .setFacId(facId).setRangeVal(rangeVal).setUniqueExpenseId(uniqueExpenseId)
- .setUnit(irulesItem.getPriceFactor().getUnit());
- tbItemFac.setItemId(tbItem.getId());
- tbItemFacService.saveOrUpdate(tbItemFac);
- List<IrulesItem> children = irulesItem.getChildren();
- if (children != null) {
- doHanlder(children, tbItem, uniqueExpenseId);
- }
- });
- }
- /**
- * 停车费规则
- *
- * @return
- */
- public TbItem getPartItem() {
- QueryWrapper<TbItem> ew = new QueryWrapper<>();
- ew.lambda().like(TbItem::getItemName, "停车费");
- List<TbItem> list = this.list(ew);
- return list.isEmpty() ? null : list.get(0);
- }
- /**
- * 根据code删除
- *
- * @param uniqueExpenseId
- */
- private void removeByCode(String uniqueExpenseId) {
- QueryWrapper<TbItem> ew = new QueryWrapper<>();
- ew.lambda().eq(TbItem::getItemCode, uniqueExpenseId);
- this.remove(ew);
- }
- /**
- * 查找停车费项
- *
- * @param itemTypeNameKeyword
- * @param itemNameKeyword
- * @return
- */
- public TbItem findByTypeNameAndItemName(String itemTypeNameKeyword, String itemNameKeyword) {
- QueryWrapper<TbItem> ew = new QueryWrapper<>();
- ew.lambda().like(TbItem::getTypeName, itemTypeNameKeyword).like(TbItem::getItemName, itemNameKeyword);
- List<TbItem> list = list(ew);
- return list.isEmpty() ? null : list.get(0);
- }
- /**
- * 仅仅入场管理费可用
- *
- * @param itemName
- * @return
- */
- public TbItem findByName(String itemName) {
- QueryWrapper<TbItem> ew = new QueryWrapper<>();
- ew.lambda().eq(TbItem::getItemName, itemName);
- List<TbItem> list = list(ew);
- return list.isEmpty() ? null : list.get(0);
- }
- }
|