package com.palmnest.service.washcar.service.impl;

import com.palmnest.application.core.util.FileUploadUtils;
import com.palmnest.application.dto.input.EvaluateInputDto;
import com.palmnest.model.washcar.UserEvaluate;
import com.palmnest.service.estateserve.AppUserManager;
import com.palmnest.service.washcar.manager.UserEvaluateManager;
import com.palmnest.service.washcar.service.UserEvaluateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.util.Date;

@Slf4j
@Service("userEvaluateService")
public class UserEvaluateServiceImpl implements UserEvaluateService {


	@Autowired
	private UserEvaluateManager userEvaluateManager;
	@Autowired
	private AppUserManager      appUserManager;

	@Override
	public UserEvaluate saveEvaluate(EvaluateInputDto dto, String type, String userId, MultipartHttpServletRequest request)
			throws Exception {
		UserEvaluate ue = new UserEvaluate();

		ue.setCreateTime(new Date());
		ue.setType(type);
		ue.setCreator(userId);
		ue.setOpenId(dto.getOpenId());
		ue.setOrderId(dto.getOrderId());
		ue.setComment(dto.getComment());
		ue.setService_impression(dto.getImpressions());
		ue.setStar(dto.getStar());

		if ("2".equals(type)) {
			FileUploadUtils fileUploadUtils = new FileUploadUtils();
			fileUploadUtils.init();
			log.info("saveEvaluate/upload   begin " + System.currentTimeMillis());
			String imagesUrl = fileUploadUtils.getPicture(request) + ";";
			log.info("saveEvaluate/upload   end " + System.currentTimeMillis());
			ue.setEvaluateImages(imagesUrl);
		}

		return userEvaluateManager.save(ue);
	}

}
