|  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.doumee.core.constants.ResponseStatus; | 
 |  |  | import com.doumee.core.exception.BusinessException; | 
 |  |  | import com.doumee.core.model.LoginUserInfo; | 
 |  |  | import com.doumee.core.model.PageData; | 
 |  |  | import com.doumee.core.model.PageWrap; | 
 |  |  | import com.doumee.core.utils.Constants; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.business.CateParamMapper; | 
 |  |  | import com.doumee.dao.business.CateParamSelectMapper; | 
 |  |  | import com.doumee.dao.business.GoodsParamMapper; | 
 |  |  | import com.doumee.dao.business.model.CateParam; | 
 |  |  | import com.doumee.dao.business.model.CateParamSelect; | 
 |  |  | import com.doumee.dao.business.model.Goods; | 
 |  |  | import com.doumee.dao.business.model.GoodsParam; | 
 |  |  | import com.doumee.service.CateParamSelectService; | 
 |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.apache.shiro.SecurityUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
 |  |  | import org.springframework.scheduling.annotation.Async; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private CateParamSelectMapper cateParamSelectMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private GoodsParamMapper goodsParamMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer create(CateParamSelect cateParamSelect) { | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Async | 
 |  |  |     public void dealCateParamSelect() { | 
 |  |  |     public  void dealCateParamSelect() { | 
 |  |  |         dealCateParamSelectDo(); | 
 |  |  |     } | 
 |  |  |     @Override | 
 |  |  |     @Transactional | 
 |  |  |     public  void dealCateParamSelectDo() { | 
 |  |  |         LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         Boolean  isGrouping = (Boolean)redisTemplate.opsForValue().get(loginUserInfo.getCompanyId()+Constants.CATE_PARAM_OPEN); | 
 |  |  |         if(isGrouping!=null && isGrouping ){ | 
 |  |  |             return; | 
 |  |  |            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"企业参数选项初始化正在执行,请稍后重试!"); | 
 |  |  |         } | 
 |  |  |         redisTemplate.opsForValue().set(loginUserInfo.getCompanyId()+Constants.CATE_PARAM_OPEN,true); | 
 |  |  |         try { | 
 |  |  | 
 |  |  |             cateParamSelectMapper.delete(new QueryWrapper<CateParamSelect>().exists(" select 1 from category c where c.id = cate_param_select.category_id and  c.company_id = "+loginUserInfo.getCompanyId()+"   ")); | 
 |  |  |             //新增当前企业可以使用的数据 | 
 |  |  |             cateParamSelectMapper.insertBatch(loginUserInfo.getCompanyId(),loginUserInfo.getId()); | 
 |  |  |             /*List<CateParamSelect> list = new ArrayList<>(); | 
 |  |  |             List<GoodsParam> params = goodsParamMapper.selectJoinList(GoodsParam.class,new MPJLambdaWrapper<GoodsParam>() | 
 |  |  |                     .select( GoodsParam::getPramaId) | 
 |  |  |                     .select( "TRIM(REPLACE(t.val,' ','')) as val,CONCAT(TRIM(REPLACE(t.val,' ','')),t.PRAMA_ID,t1.CATEGORY_ID ) as uky") | 
 |  |  |                     .selectAs(Goods::getCategoryId,CateParamSelect::getCategoryId) | 
 |  |  |                     .innerJoin(Goods.class,Goods::getId,GoodsParam::getGoodsId) | 
 |  |  |                     .isNotNull(GoodsParam::getPramaId) | 
 |  |  |                     .isNotNull(GoodsParam::getVal) | 
 |  |  |                     .ne(GoodsParam::getVal,"") | 
 |  |  |                     .eq(Goods::getIsdeleted,Constants.ZERO ) | 
 |  |  |                     .eq(Goods::getStatus,Constants.ZERO ) | 
 |  |  |                     .eq(Goods::getCompanyId,loginUserInfo.getCompanyId()) | 
 |  |  |                     .groupBy("uky") | 
 |  |  |             ); | 
 |  |  |             if(params.size()>0){ | 
 |  |  |                 Date date = new Date(); | 
 |  |  |                 for(GoodsParam p : params){ | 
 |  |  |                     if(StringUtils.isBlank(p.getVal()) || StringUtils.equals(p.getVal().trim(),"")){ | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     if(repeatValParam(p,list)){ | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     p.setVal(p.getVal().trim()); | 
 |  |  |                     CateParamSelect cp = new CateParamSelect(); | 
 |  |  |                     cp.setCategoryId(p.getCategoryId()); | 
 |  |  |                     cp.setName(p.getVal()); | 
 |  |  |                     cp.setIsdeleted(Constants.ZERO); | 
 |  |  |                     cp.setCreateDate(date); | 
 |  |  |                     cp.setParamId(p.getPramaId()); | 
 |  |  |                     cp.setStatus(Constants.ZERO); | 
 |  |  |                     cp.setCreator(loginUserInfo.getId()); | 
 |  |  | //                    cateParamSelectMapper.insert(cp); | 
 |  |  |                     list.add(cp); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if(list.size()>0){ | 
 |  |  |                 cateParamSelectMapper.insert(list); | 
 |  |  |             }*/ | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         }finally { | 
 |  |  |             redisTemplate.opsForValue().set(loginUserInfo.getCompanyId()+Constants.CATE_PARAM_OPEN,false); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private boolean repeatValParam(GoodsParam p, List<CateParamSelect> list) { | 
 |  |  |         for(CateParamSelect cp :list){ | 
 |  |  |             if(StringUtils.equals(cp.getName(),p.getVal()) | 
 |  |  |                     && Constants.equalsInteger(cp.getParamId(),p.getPramaId()) | 
 |  |  |                     && Constants.equalsInteger(cp.getCategoryId(),p.getCategoryId())){ | 
 |  |  |                 return true; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return false; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } |