package com.dcsoft.system.car.service.impl;

import com.dcsoft.system.car.domain.TbCar;
import com.dcsoft.system.car.service.ISysPmsService;
import com.dcsoft.system.utils.HttpUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户管理 服务层处理
 *
 * @author xueyi
 */
@Service
public class SysPmsServiceImpl implements ISysPmsService {


    @Value("${pms.url}")
    private String pmsUrl;

    @Value("${pms.password}")
    private String pmsPassword;



    @Override
    public String addInnerVehicle(TbCar tbCar) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strMD5Pwd= DigestUtils.md5Hex(pmsPassword).toUpperCase();
        String strSign= DigestUtils.md5Hex((tbCar.getCarNo()+strMD5Pwd)).toUpperCase();
        String url=pmsUrl+"/addInnerVehicle";
        Map<String, Object> paramMap=new HashMap<String, Object>();
        paramMap.put("plateNo", tbCar.getCarNo());
        paramMap.put("startTime", sdf.format(tbCar.getStruStartTime()));
        paramMap.put("endTime", sdf.format(tbCar.getStruStopTime()));
        paramMap.put("ownerName", tbCar.getOwnerName());
        paramMap.put("ownerPhone", tbCar.getOwnerPhone());
        paramMap.put("createTime", sdf.format(new Date()));
        paramMap.put("sign", strSign);
        String response= HttpUtil.postData(url,paramMap);
        return response;
    }

    @Override
    public String delInnerVehicle(TbCar tbCar) {
        String strMD5Pwd= DigestUtils.md5Hex(pmsPassword).toUpperCase();
        String strSign= DigestUtils.md5Hex((tbCar.getCarNo()+strMD5Pwd)).toUpperCase();
        String url=pmsUrl+"/delInnerVehicle";
        Map<String, Object> paramMap=new HashMap<String, Object>();
        paramMap.put("plateNo", tbCar.getCarNo());
        paramMap.put("sign", strSign);
        String response= HttpUtil.postData(url,paramMap);
        return response;
    }



}
