package io.hmit.modules.serviceOrder.dto;

import io.hmit.modules.serviceOrder.service.RoleService;
import io.hmit.modules.serviceOrder.service.RoleUserService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;


/**
 * 订单及相关图片附件关联表
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2021-03-11
 */
@Data
@ApiModel(value = "订单及相关图片附件关联表")
public class PensionOrderDocumentDTO implements Serializable {
	@Autowired
	private RoleService roleService;

    private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "")
	private Long id;

	@ApiModelProperty(value = "订单id")
	private Long orderId;

	@ApiModelProperty(value = "文件id")
	private Long docId;

	@ApiModelProperty(value = "文件名")
	private String fileName;

	@ApiModelProperty(value = "文件链接")
	private String filePath;

	@ApiModelProperty(value = "备注 1 服务人员图片；2 服务人员录音； 3 老人/子女评价图片")
	private String remark;

	@ApiModelProperty(value = "创建者")
	private Long creator;

	@ApiModelProperty(value = "创建时间")
	private Date createDate;

	@ApiModelProperty(value = "更新者")
	private Long updater;

	@ApiModelProperty(value = "更新时间")
	private Date updateDate;

	public PensionOrderDocumentDTO assemblePensionOrder(Map<String, Object> fileMap,Long orderId,Long roleId) {
		PensionOrderDocumentDTO dto = new PensionOrderDocumentDTO();
		if (null != fileMap) {
			dto.setCreateDate(new Date());
			dto.setOrderId(orderId);
			dto.setDocId(Long.parseLong(fileMap.get("docId").toString()));
			dto.setFileName(fileMap.get("fileName").toString());
			dto.setFilePath(fileMap.get("filePath").toString());
			RoleDTO roleDTO = roleService.get(roleId);
			if(roleDTO != null && roleDTO.getName().contains("老人")){
				dto.setRemark("3");
			}

			if(roleDTO != null && roleDTO.getName().contains("服务")){
				String fileName = fileMap.get("filePath").toString().toLowerCase();
				dto.setRemark("1");
				if (fileName.endsWith(".mp3")) {
					dto.setRemark("2");
				}

			}

		}

		return dto;
	}
}
