/*     */ package com.picc.grab.service.impl;
/*     */ 
/*     */ import com.baomidou.mybatisplus.mapper.EntityWrapper;
/*     */ import com.baomidou.mybatisplus.mapper.Wrapper;
/*     */ import com.baomidou.mybatisplus.service.impl.ServiceImpl;
/*     */ import com.picc.grab.common.constants.CarinfoStatus;
/*     */ import com.picc.grab.common.constants.ZbgzStatusEnum;
/*     */ import com.picc.grab.domain.Bjdfsjl;
/*     */ import com.picc.grab.domain.Carbjd;
/*     */ import com.picc.grab.domain.Carimg;
/*     */ import com.picc.grab.domain.Carinfo;
/*     */ import com.picc.grab.domain.Carzxx;
/*     */ import com.picc.grab.domain.User;
/*     */ import com.picc.grab.domain.Zbwt;
/*     */ import com.picc.grab.domain.Zbwtjl;
/*     */ import com.picc.grab.entity.grab.dto.CarCjjlDTO;
/*     */ import com.picc.grab.exception.BusinessException;
/*     */ import com.picc.grab.mapper.BjdfsjlMapper;
/*     */ import com.picc.grab.mapper.CarimgMapper;
/*     */ import com.picc.grab.mapper.CarinfoMapper;
/*     */ import com.picc.grab.mapper.CarzxxMapper;
/*     */ import com.picc.grab.mapper.UserMapper;
/*     */ import com.picc.grab.mapper.ZbwtMapper;
/*     */ import com.picc.grab.mapper.ZbwtjlMapper;
/*     */ import com.picc.grab.service.ICarinfoService;
/*     */ import com.picc.grab.service.IInterfaceRequestService;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import org.apache.commons.collections.CollectionUtils;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Service;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ 
/*     */ @Transactional
/*     */ @Service
/*     */ public class CarinfoServiceImpl extends ServiceImpl<CarinfoMapper, Carinfo> implements ICarinfoService {
/*     */   @Autowired
/*     */   private CarinfoMapper carinfoMapper;
/*     */   @Autowired
/*     */   private CarimgMapper carimgMapper;
/*     */   @Autowired
/*     */   private ZbwtMapper zbwtMapper;
/*     */   @Autowired
/*     */   private IInterfaceRequestService iInterfaceRequestService;
/*     */   @Autowired
/*     */   private BjdfsjlMapper bjdfsjlMapper;
/*     */   @Autowired
/*     */   private UserMapper userMapper;
/*     */   @Autowired
/*     */   private ZbwtjlMapper zbwtjlMapper;
/*     */   @Autowired
/*     */   private CarzxxMapper carzxxService;
/*  56 */   private static final Logger logger = LoggerFactory.getLogger(CarinfoServiceImpl.class);
/*     */ 
/*     */   
/*     */   public boolean saveZq(Carinfo carinfo, String userId, String createUserId) {
/*  60 */     carinfo.setCreateTime(new Date());
/*  61 */     carinfo.setUpdateTime(carinfo.getCreateTime());
/*  62 */     carinfo.setCreateUserId(createUserId);
/*  63 */     carinfo.setUserId(userId);
/*     */     
/*  65 */     int id = getMaxCarId();
/*  66 */     carinfo.setId(id + "");
/*     */     
/*  68 */     carinfo.setExbz(isExist(carinfo.getCjh()));
/*  69 */     boolean bo = insert(carinfo);
/*  70 */     if (bo)
/*     */     {
/*  72 */       if (CollectionUtils.isNotEmpty(carinfo.getImgList()) && carinfo.getImgList() != null) {
/*  73 */         for (Carimg img : carinfo.getImgList()) {
/*  74 */           img.setCarid(carinfo.getId());
/*  75 */           img.setCreateTime(carinfo.getCreateTime());
/*  76 */           this.carimgMapper.insert(img);
/*     */         } 
/*     */       } else {
/*  79 */         throw new BusinessException("图片信息为空");
/*     */       } 
/*     */     }
/*  82 */     return bo;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private synchronized int getMaxCarId() {
/*  91 */     Integer maxId = this.carinfoMapper.getMaxCarId();
/*  92 */     if (maxId == null) {
/*  93 */       return 1;
/*     */     }
/*  95 */     return maxId.intValue() + 1;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String isExist(String cjh) {
/* 105 */     StringBuffer res = new StringBuffer();
/* 106 */     if (cjh.contains("*")) {
/* 107 */       return "";
/*     */     }
/* 109 */     List<String> carIds = this.carinfoMapper.findCaridByCjh(cjh);
/* 110 */     if (carIds != null && carIds.size() > 0) {
/* 111 */       StringBuffer str = new StringBuffer("【此车之前有过询价,报价ID为:");
/* 112 */       for (String s : carIds) {
/* 113 */         str.append(s + ",");
/*     */       }
/* 115 */       res.append(str.toString().substring(0, str.length() - 1) + "】");
/*     */     } 
/* 117 */     CarCjjlDTO cjjl = this.carinfoMapper.findCjjlByCjh(cjh);
/* 118 */     if (cjjl != null) {
/* 119 */       String strCjjl = "【此车之前在路宝有过询价,出价时间为:" + cjjl.getCjsj() + ",委托方为:" + cjjl.getWtf() + ",委托价为:" + cjjl.getWtj() + ",合手价为:" + cjjl.getHsj() + "】";
/* 120 */       res.append(strCjjl);
/*     */     } 
/* 122 */     return res.toString();
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean fsbjdEmail(String carid, String userid) {
/* 128 */     if (StringUtils.isNotBlank(carid)) {
/*     */       
/* 130 */       EntityWrapper<Zbwt> zbwtEw = new EntityWrapper();
/* 131 */       zbwtEw.eq("carid", carid);
/* 132 */       int count = this.zbwtMapper.selectCount((Wrapper)zbwtEw).intValue();
/* 133 */       if (count > 0) {
/* 134 */         throw new BusinessException("邮件已发送，不能再次发送，请刷新列表！");
/*     */       }
/* 136 */       String uid = userid;
/* 137 */       updateCarinfoStatus(carid, CarinfoStatus.YFSBJD.code);
/* 138 */       Date now = new Date();
/*     */       
/* 140 */       Zbwt zbwt = new Zbwt();
/* 141 */       zbwt.setCarid(carid);
/* 142 */       zbwt.setZbgzstatus(Integer.valueOf(1));
/* 143 */       zbwt.setFsr(uid);
/* 144 */       zbwt.setFsbjdsj(now);
/* 145 */       zbwt.setLastgztime(now);
/* 146 */       zbwt.setCreateTime(now);
/* 147 */       this.zbwtMapper.insert(zbwt);
/* 148 */       String fjUrl = "";
/*     */       
/* 150 */       EntityWrapper<Carbjd> ew = new EntityWrapper();
/* 151 */       ew.eq("carid", carid);
/* 152 */       ew.orderBy("create_time", false);
/*     */ 
/*     */       
/* 155 */       Bjdfsjl bjdfsjl = new Bjdfsjl();
/* 156 */       bjdfsjl.setCarid(carid);
/* 157 */       bjdfsjl.setFsrid(uid);
/* 158 */       bjdfsjl.setJsrxm("");
/* 159 */       bjdfsjl.setJsrdh("");
/* 160 */       bjdfsjl.setJsryx("");
/* 161 */       bjdfsjl.setStatus(Integer.valueOf(1));
/* 162 */       bjdfsjl.setCreateTime(now);
/* 163 */       this.bjdfsjlMapper.insert(bjdfsjl);
/* 164 */       return true;
/*     */     } 
/* 166 */     return false;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void updateCarinfoStatus(String carid, int status) {
/* 176 */     Carinfo updateStatusCarInfo = new Carinfo();
/* 177 */     updateStatusCarInfo.setId(carid);
/* 178 */     updateStatusCarInfo.setStatus(Integer.valueOf(status));
/* 179 */     this.carinfoMapper.updateById(updateStatusCarInfo);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean zbcar(String carid, String pric, String zbCompanyName, String bxptName) {
/*     */     try {
/* 190 */       Integer status = Integer.valueOf(3);
/* 191 */       if (zbCompanyName.equals(bxptName)) {
/* 192 */         status = Integer.valueOf(2);
/*     */       }
/* 194 */       Zbwt zbwt = this.zbwtMapper.GetZbwtByCarid(carid);
/* 195 */       Zbwtjl zbwtjl = new Zbwtjl();
/* 196 */       User user = this.userMapper.findByName("topadmin");
/* 197 */       zbwtjl.setZbwtid(zbwt.getId());
/* 198 */       zbwtjl.setType(status);
/* 199 */       zbwtjl.setCzrName(user.getUserName());
/* 200 */       zbwtjl.setMemo("中标公司：" + zbCompanyName + ",中标价格：" + pric);
/* 201 */       zbwtjl.setCzr(user.getId());
/* 202 */       zbwtjl.setCreateTime(new Date());
/* 203 */       int num = this.zbwtjlMapper.insert(zbwtjl).intValue();
/* 204 */       if (num > 0) {
/*     */         
/* 206 */         if (zbwtjl.getType().intValue() == ZbgzStatusEnum.YZB.code) {
/* 207 */           zbwt.setZbgzstatus(Integer.valueOf(ZbgzStatusEnum.WTGZ.code));
/*     */         } else {
/* 209 */           zbwt.setZbgzstatus(zbwtjl.getType());
/*     */         } 
/* 211 */         zbwt.setLastgztime(zbwtjl.getCreateTime());
/* 212 */         this.zbwtMapper.updateById(zbwt);
/* 213 */         return true;
/*     */       } 
/* 215 */       return false;
/* 216 */     } catch (Exception ex) {
/* 217 */       logger.error("中标维护错误：" + carid + ex.toString());
/* 218 */       return false;
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   public boolean wtPaMai(String carid, String result) {
/* 224 */     Integer type = Integer.valueOf(6);
/* 225 */     if (result.equals("委托拍卖")) {
/* 226 */       type = Integer.valueOf(5);
/*     */     }
/* 228 */     Zbwt zbwt = this.zbwtMapper.GetZbwtByCarid(carid);
/* 229 */     if (type.intValue() == ZbgzStatusEnum.YWT.code) {
/*     */       
/* 231 */       EntityWrapper<Zbwt> zbwtEntityWrapper = new EntityWrapper();
/* 232 */       zbwtEntityWrapper.eq("carid", zbwt.getCarid());
/* 233 */       zbwtEntityWrapper.eq("zbgzstatus", Integer.valueOf(ZbgzStatusEnum.YWT.code));
/* 234 */       int ywtCount = this.zbwtMapper.selectCount((Wrapper)zbwtEntityWrapper).intValue();
/* 235 */       if (ywtCount > 0) throw new BusinessException("数据异常，请刷新列表！"); 
/*     */     } 
/* 237 */     Zbwtjl zbwtjl = new Zbwtjl();
/* 238 */     User user = this.userMapper.findByName("topadmin");
/* 239 */     zbwtjl.setZbwtid(zbwt.getId());
/* 240 */     zbwtjl.setType(type);
/* 241 */     zbwtjl.setCzrName(user.getUserName());
/* 242 */     zbwtjl.setCzr(user.getId());
/* 243 */     zbwtjl.setCreateTime(new Date());
/* 244 */     int num = this.zbwtjlMapper.insert(zbwtjl).intValue();
/* 245 */     if (num > 0) {
/*     */       
/* 247 */       zbwt.setZbgzstatus(zbwtjl.getType());
/* 248 */       zbwt.setLastgztime(zbwtjl.getCreateTime());
/* 249 */       this.zbwtMapper.updateById(zbwt);
/*     */       
/* 251 */       if (zbwt.getZbgzstatus().intValue() == ZbgzStatusEnum.YWT.code) {
/*     */         
/* 253 */         Carzxx carzxx = new Carzxx();
/* 254 */         carzxx.setCarzname("同凯");
/* 255 */         carzxx.setCarzdh("13552928547");
/* 256 */         carzxx.setDsyname("同凯");
/* 257 */         carzxx.setDsydh("13552928547");
/* 258 */         carzxx.setCarid(zbwt.getCarid());
/* 259 */         carzxx.setCzrid(user.getId());
/* 260 */         carzxx.setCzrname(user.getUserName());
/* 261 */         carzxx.setCzsj(zbwtjl.getCreateTime());
/* 262 */         this.carzxxService.insert(carzxx);
/*     */ 
/*     */ 
/*     */ 
/*     */         
/* 267 */         this.iInterfaceRequestService.syncKgCarxx();
/*     */         
/* 269 */         logger.info("syncSxglcarData   -------  start ！");
/*     */         try {
/* 271 */           this.carinfoMapper.syncSxglcarData(zbwt.getCarid());
/* 272 */         } catch (Exception e) {
/* 273 */           logger.info("syncSxglcarData error: " + e.getMessage() + "请求异常！");
/*     */         } 
/* 275 */         logger.info("syncSxglcarData   -------  end ");
/*     */       } 
/* 277 */       return true;
/*     */     } 
/* 279 */     logger.info(carid + ":车维护委托失败");
/* 280 */     return false;
/*     */   }
    /*     */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\grab\service\impl\CarinfoServiceImpl.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */