| | |
| | | package com.jilongda.manage.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.jilongda.common.basic.PageInfo; |
| | | import com.jilongda.manage.mapper.SecSettingMapper; |
| | | import com.jilongda.manage.mapper.TFrameGoodsMapper; |
| | | import com.jilongda.manage.mapper.TLensGoodsMapper; |
| | | import com.jilongda.manage.model.SecSetting; |
| | | import com.jilongda.manage.model.TFrameGoods; |
| | | import com.jilongda.manage.model.TLensGoods; |
| | | import com.jilongda.manage.query.TFrameGoodsQuery; |
| | | import com.jilongda.manage.query.TLensGoodsQuery; |
| | | import com.jilongda.manage.service.TFrameGoodsService; |
| | | import com.jilongda.manage.service.TLensGoodsService; |
| | | import com.jilongda.manage.vo.TFrameGoodsVO; |
| | | import com.jilongda.manage.vo.TLensGoodsVO; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public class TLensGoodsServiceImpl extends ServiceImpl<TLensGoodsMapper, TLensGoods> implements TLensGoodsService { |
| | | |
| | | |
| | | @Resource |
| | | private SecSettingMapper secSettingMapper; |
| | | private Map<String, Map<String, JSONObject>> cachedSphereMaps = new ConcurrentHashMap<>(); |
| | | @Override |
| | | public PageInfo<TLensGoodsVO> lensReceiptList(TLensGoodsQuery query) { |
| | | PageInfo<TLensGoodsVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TLensGoodsVO> list = this.baseMapper.lensReceiptList(query, pageInfo); |
| | | SecSetting secSetting = secSettingMapper.selectOne(null); |
| | | for (TLensGoodsVO tFrameGoodsVO : list) { |
| | | if (tFrameGoodsVO.getTotal() < secSetting.getLensThreshold()) { |
| | | tFrameGoodsVO.setIsWarning(1); |
| | | } |
| | | String sphere = null; |
| | | switch (tFrameGoodsVO.getLensType()) { |
| | | case 1: |
| | | sphere = tFrameGoodsVO.getSphere(); |
| | | break; |
| | | case 2: |
| | | sphere = tFrameGoodsVO.getAsphericSurface(); |
| | | break; |
| | | case 3: |
| | | sphere = tFrameGoodsVO.getDoubleNon(); |
| | | break; |
| | | } |
| | | |
| | | if (sphere != null && sphere.contains("cost")) { |
| | | updateSaleAndCost(tFrameGoodsVO, sphere); |
| | | } |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | private void updateSaleAndCost(TLensGoodsVO tFrameGoodsVO, String sphere) { |
| | | Map<String, JSONObject> costMap = cachedSphereMaps.get(sphere); |
| | | if (costMap == null) { |
| | | costMap = new HashMap<>(); |
| | | JSONArray objects = JSONObject.parseArray(sphere); |
| | | for (Object object : objects) { |
| | | JSONObject jsonObject = (JSONObject) object; |
| | | costMap.put(jsonObject.getString("refractiveIndex"), jsonObject); |
| | | } |
| | | cachedSphereMaps.put(sphere, costMap); |
| | | } |
| | | |
| | | JSONObject matchingObject = costMap.get(tFrameGoodsVO.getRefractiveIndex()); |
| | | if (matchingObject != null) { |
| | | tFrameGoodsVO.setSale(matchingObject.getString("sales")); |
| | | tFrameGoodsVO.setCost(matchingObject.getString("cost")); |
| | | } |
| | | } |
| | | |
| | | } |