|
@@ -0,0 +1,345 @@
|
|
|
+package com.miaxis.car.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.miaxis.car.domain.CarParameterData;
|
|
|
+import com.miaxis.car.domain.UsedCarFile;
|
|
|
+import com.miaxis.car.domain.UsedCarInfo;
|
|
|
+import com.miaxis.car.dto.ExamineUsedCarDto;
|
|
|
+import com.miaxis.car.dto.UsedCarInfoDto;
|
|
|
+import com.miaxis.car.mapper.CarParameterDataMapper;
|
|
|
+import com.miaxis.car.mapper.UsedCarFileMapper;
|
|
|
+import com.miaxis.car.mapper.UsedCarInfoMapper;
|
|
|
+import com.miaxis.car.service.IUsedCarInfoService;
|
|
|
+import com.miaxis.car.vo.UsedCarInfoVo;
|
|
|
+import com.miaxis.common.core.domain.Response;
|
|
|
+import com.miaxis.common.core.domain.entity.SysDictData;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
+import com.miaxis.common.utils.bean.BeanUtils;
|
|
|
+import com.miaxis.customer.domain.CustomerInfo;
|
|
|
+import com.miaxis.file.domain.FileInfo;
|
|
|
+import com.miaxis.file.service.IFileInfoService;
|
|
|
+import com.miaxis.system.mapper.SysDictDataMapper;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static java.util.stream.Collectors.toList;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 二手车Service业务层处理
|
|
|
+ * @author wwl
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2021/5/26 13:43
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class UsedCarInfoServiceImpl extends ServiceImpl<UsedCarInfoMapper, UsedCarInfo> implements IUsedCarInfoService {
|
|
|
+
|
|
|
+ private final UsedCarInfoMapper usedCarInfoMapper;
|
|
|
+
|
|
|
+ private final UsedCarFileMapper usedCarFileMapper;
|
|
|
+
|
|
|
+ private final IFileInfoService fileInfoService;
|
|
|
+
|
|
|
+ private final CarParameterDataMapper carParameterDataMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * pc
|
|
|
+ * 查询二手车列表
|
|
|
+ *
|
|
|
+ * @param usedCarInfo 二手车
|
|
|
+ * @return 二手车
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<UsedCarInfo> selectUsedCarInfoList(UsedCarInfo usedCarInfo){
|
|
|
+ return usedCarInfoMapper.selectUsedCarInfoList(usedCarInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * applet
|
|
|
+ * 新增二手车
|
|
|
+ * @param usedCarInfoDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response saveUsedCarInfo(UsedCarInfoDto usedCarInfoDto) {
|
|
|
+ try{
|
|
|
+ UsedCarInfo usedCarInfo = new UsedCarInfo();
|
|
|
+ BeanUtils.copyProperties(usedCarInfoDto,usedCarInfo);
|
|
|
+ //保存二手车信息
|
|
|
+ this.save(usedCarInfo);
|
|
|
+ //保存二手车图片关联表
|
|
|
+ List<Long> pictureIds = usedCarInfoDto.getPictureIds();
|
|
|
+ if (!pictureIds.isEmpty()){
|
|
|
+ for (Long pictureId : pictureIds) {
|
|
|
+ UsedCarFile usedCarFile = new UsedCarFile();
|
|
|
+ usedCarFile.setUsedCarId(usedCarInfo.getId());
|
|
|
+ usedCarFile.setFileId(pictureId);
|
|
|
+ //主图标识
|
|
|
+ if (pictureId.equals(usedCarInfoDto.getMainSignId())){
|
|
|
+ usedCarFile.setSign("main");
|
|
|
+ }
|
|
|
+ usedCarFileMapper.insert(usedCarFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Response.success();
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * pc
|
|
|
+ * 修改二手车
|
|
|
+ * @param usedCarInfoDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response updateUsedCarById(UsedCarInfoDto usedCarInfoDto) {
|
|
|
+ try{
|
|
|
+ UsedCarInfo usedCarInfo = new UsedCarInfo();
|
|
|
+ BeanUtils.copyProperties(usedCarInfoDto,usedCarInfo);
|
|
|
+ //修改二手车
|
|
|
+ usedCarInfoMapper.updateById(usedCarInfo);
|
|
|
+
|
|
|
+ //修改二手车图片关联表
|
|
|
+ List<UsedCarFile> usedCarFiles = usedCarFileMapper.selectByMap(new HashMap<String, Object>() {{
|
|
|
+ put("used_car_id", usedCarInfoDto.getId());
|
|
|
+ }});
|
|
|
+
|
|
|
+ //删除图片ids
|
|
|
+ List<Long> fileIds = usedCarFiles.parallelStream()
|
|
|
+ .map(u -> u.getFileId()).collect(toList())
|
|
|
+ .stream()
|
|
|
+ .filter(item -> !usedCarInfoDto.getPictureIds().contains(item))
|
|
|
+ .collect(toList());
|
|
|
+ if (!fileIds.isEmpty()){
|
|
|
+ for (Long fileId : fileIds) {
|
|
|
+ usedCarFileMapper.deleteByMap(new HashMap<String, Object>(){{
|
|
|
+ put("used_car_id",usedCarInfoDto.getId());
|
|
|
+ put("file_id",fileId);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新主图
|
|
|
+ List<Long> mainFileId = usedCarFiles.stream()
|
|
|
+ .filter(u -> "main".equals(u.getSign()))
|
|
|
+ .map(m -> m.getFileId())
|
|
|
+ .collect(toList());
|
|
|
+
|
|
|
+ if (fileIds.contains(mainFileId.get(0))){
|
|
|
+ UsedCarFile usedCarFile = new UsedCarFile();
|
|
|
+ usedCarFile.setSign("main");
|
|
|
+ usedCarFileMapper.update(usedCarFile,new UpdateWrapper<UsedCarFile>()
|
|
|
+ .eq("used_car_id",usedCarInfoDto.getId())
|
|
|
+ .eq("file_id",mainFileId.get(0)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!usedCarInfoDto.getMainSignId().equals(mainFileId.get(0))){
|
|
|
+ UsedCarFile mainUsedCarFile = new UsedCarFile();
|
|
|
+ mainUsedCarFile.setSign("main");
|
|
|
+ usedCarFileMapper.update(mainUsedCarFile,new UpdateWrapper<UsedCarFile>()
|
|
|
+ .eq("used_car_id",usedCarInfoDto.getId())
|
|
|
+ .eq("file_id",usedCarInfoDto.getMainSignId()));
|
|
|
+
|
|
|
+ if (!fileIds.contains(mainFileId.get(0))){
|
|
|
+ UsedCarFile usedCarFile = new UsedCarFile();
|
|
|
+ usedCarFile.setSign("1");
|
|
|
+ usedCarFileMapper.update(usedCarFile,new UpdateWrapper<UsedCarFile>()
|
|
|
+ .eq("used_car_id",usedCarInfoDto.getId())
|
|
|
+ .eq("file_id",mainFileId.get(0)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Response.success();
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询二手车参数列表
|
|
|
+ * @param parameterType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response selectDictDataCarList(String[] parameterType) {
|
|
|
+ HashMap<String, List<CarParameterData>> map = new HashMap<>();
|
|
|
+ for (String parameter : parameterType) {
|
|
|
+ map.put(parameter,carParameterDataMapper.selectByMap(new HashMap<String, Object>(){{
|
|
|
+ put("parameter_type",parameter);
|
|
|
+ }}));
|
|
|
+ }
|
|
|
+ return Response.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取二手车详细信息
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response getUsedCarById(Long id) {
|
|
|
+
|
|
|
+ //返回值
|
|
|
+ UsedCarInfoVo usedCarInfoVo = new UsedCarInfoVo();
|
|
|
+
|
|
|
+ UsedCarInfo usedCarInfo = usedCarInfoMapper.selectById(id);
|
|
|
+ BeanUtils.copyProperties(usedCarInfo,usedCarInfoVo);
|
|
|
+
|
|
|
+ List<UsedCarFile> usedCarFiles = usedCarFileMapper.selectByMap(new HashMap<String, Object>() {{
|
|
|
+ put("used_car_id", id);
|
|
|
+ }});
|
|
|
+ List<Long> fileIds = usedCarFiles.stream().map(m -> m.getFileId()).collect(toList());
|
|
|
+
|
|
|
+ ArrayList<Map<String, String>> listMaps = new ArrayList<>();
|
|
|
+ List<FileInfo> fileInfos = fileInfoService.list(new QueryWrapper<FileInfo>().in("file_id", fileIds));
|
|
|
+ for (FileInfo fileInfo : fileInfos) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("id",fileInfo.getFileId().toString());
|
|
|
+ map.put("fileUrl",fileInfo.getFileUrl());
|
|
|
+ listMaps.add(map);
|
|
|
+ }
|
|
|
+ usedCarInfoVo.setMainSignId(usedCarFiles.stream().filter(u -> "main".equals(u.getSign())).collect(toList()).get(0).getFileId());
|
|
|
+ usedCarInfoVo.setPictureUrlList(listMaps);
|
|
|
+ return Response.success(usedCarInfoVo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * applet
|
|
|
+ * 编辑二手车
|
|
|
+ * @param usedCarInfoDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response editUsedCarById(UsedCarInfoDto usedCarInfoDto) {
|
|
|
+ try{
|
|
|
+ UsedCarInfo usedCarInfo = new UsedCarInfo();
|
|
|
+ BeanUtils.copyProperties(usedCarInfoDto,usedCarInfo);
|
|
|
+ //修改二手车
|
|
|
+ usedCarInfoMapper.updateById(usedCarInfo);
|
|
|
+
|
|
|
+ //修改二手车图片关联表
|
|
|
+ List<UsedCarFile> usedCarFiles = usedCarFileMapper.selectByMap(new HashMap<String, Object>() {{
|
|
|
+ put("used_car_id", usedCarInfoDto.getId());
|
|
|
+ }});
|
|
|
+
|
|
|
+ //原主图id
|
|
|
+ List<Long> mainFileId = usedCarFiles.stream()
|
|
|
+ .filter(u -> "main".equals(u.getSign()))
|
|
|
+ .map(m -> m.getFileId())
|
|
|
+ .collect(toList());
|
|
|
+
|
|
|
+ //删除图片ids
|
|
|
+ List<Long> delFileIds = usedCarFiles.parallelStream()
|
|
|
+ .map(u -> u.getFileId()).collect(toList())
|
|
|
+ .stream()
|
|
|
+ .filter(item -> !usedCarInfoDto.getPictureIds().contains(item))
|
|
|
+ .collect(toList());
|
|
|
+
|
|
|
+ //新增图片ids
|
|
|
+ List<Long> addfileIds = usedCarInfoDto.getPictureIds()
|
|
|
+ .parallelStream()
|
|
|
+ .filter(item ->
|
|
|
+ !usedCarFiles.parallelStream()
|
|
|
+ .map(u -> u.getFileId()).collect(toList()).contains(item))
|
|
|
+ .collect(toList());
|
|
|
+
|
|
|
+ if (!delFileIds.isEmpty()){
|
|
|
+ for (Long fileId : delFileIds) {
|
|
|
+ usedCarFileMapper.deleteByMap(new HashMap<String, Object>(){{
|
|
|
+ put("used_car_id",usedCarInfoDto.getId());
|
|
|
+ put("file_id",fileId);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!addfileIds.isEmpty()){
|
|
|
+ //保存新增图片id
|
|
|
+ for (Long addfileId : addfileIds) {
|
|
|
+ UsedCarFile addUsedCarFile = new UsedCarFile();
|
|
|
+ addUsedCarFile.setFileId(addfileId);
|
|
|
+
|
|
|
+ addUsedCarFile.setUsedCarId(usedCarInfoDto.getId());
|
|
|
+ if (addfileId.equals(usedCarInfoDto.getMainSignId())){
|
|
|
+ addUsedCarFile.setSign("main");
|
|
|
+ }
|
|
|
+ usedCarFileMapper.insert(addUsedCarFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断主图是否被修改
|
|
|
+ if (!usedCarInfoDto.getMainSignId().equals(mainFileId.get(0))){
|
|
|
+
|
|
|
+ if (!delFileIds.contains(mainFileId.get(0))){
|
|
|
+ //更新原主图
|
|
|
+ UsedCarFile usedCarFile = new UsedCarFile();
|
|
|
+ usedCarFile.setSign("1");
|
|
|
+ usedCarFileMapper.update(usedCarFile,new UpdateWrapper<UsedCarFile>()
|
|
|
+ .eq("used_car_id",usedCarInfoDto.getId())
|
|
|
+ .eq("file_id",mainFileId.get(0)));
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是新增主图还是修改主图
|
|
|
+ if (!addfileIds.contains(usedCarInfoDto.getMainSignId())){
|
|
|
+ UsedCarFile mainUsedCarFile = new UsedCarFile();
|
|
|
+ mainUsedCarFile.setSign("main");
|
|
|
+ usedCarFileMapper.update(mainUsedCarFile,new UpdateWrapper<UsedCarFile>()
|
|
|
+ .eq("used_car_id",usedCarInfoDto.getId())
|
|
|
+ .eq("file_id",usedCarInfoDto.getMainSignId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Response.success();
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 二手车审核
|
|
|
+ * @param examineUsedCarDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response usedCarExamine(ExamineUsedCarDto examineUsedCarDto) {
|
|
|
+ UsedCarInfo usedCarInfo = new UsedCarInfo();
|
|
|
+ BeanUtils.copyProperties(examineUsedCarDto,usedCarInfo);
|
|
|
+ usedCarInfoMapper.updateById(usedCarInfo);
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除二手车(伪删除)
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response removeUsedCarByIds(Long[] ids) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ this.update(new UpdateWrapper<UsedCarInfo>().set("status",1).eq("id",id));
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|