com.clt.sub.service.imp.ShipheadServiceImp.java Source code

Java tutorial

Introduction

Here is the source code for com.clt.sub.service.imp.ShipheadServiceImp.java

Source

package com.clt.sub.service.imp;

import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.stereotype.Service;

import com.clt.common.UserSession;
import com.clt.sub.dao.IArkilometerDao;
import com.clt.sub.dao.ICustomerDao;
import com.clt.sub.dao.IDriverDao;
import com.clt.sub.dao.IOrderDao;
import com.clt.sub.dao.IShipStatusDao;
import com.clt.sub.dao.IShipheadDao;
import com.clt.sub.dao.IShiplineDao;
import com.clt.sub.dao.ISubCarStyleDao;
import com.clt.sub.dao.ISubsuppliersDao;
import com.clt.sub.dao.ITruckDriverDao;
import com.clt.sub.dao.ITruckDriverLinkDao;
import com.clt.sub.model.TCustomer;
import com.clt.sub.model.TDriver;
import com.clt.sub.model.TOrder;
import com.clt.sub.model.TShipStatus;
import com.clt.sub.model.TShiphead;
import com.clt.sub.model.TShipline;
import com.clt.sub.model.TSubCarStyle;
import com.clt.sub.model.TSubsuppliers;
import com.clt.sub.model.TTruckDriver;
import com.clt.sub.model.TTruckDriverLlink;
import com.clt.sub.service.IShipheadService;
import com.clt.systemmanger.dao.IUserDao;
import com.clt.systemmanger.model.TMsgRecord;
import com.clt.systemmanger.model.TUser;
import com.clt.systemmanger.service.IMsgRecordService;
import com.clt.util.DateUtil;
import com.clt.util.HqlHelper;
import com.clt.util.Page;
import com.clt.util.PushUtils;
import com.clt.util.SystemConstants;

@Service
public class ShipheadServiceImp implements IShipheadService {

    @Autowired
    IShipheadDao shipheadDao;
    @Autowired
    ISubsuppliersDao subDao;
    @Autowired
    IOrderDao orderDao;
    @Autowired
    IArkilometerDao arkilomerDao;
    @Autowired
    IShiplineDao shiplineDao;
    @Autowired
    ITruckDriverDao driverDao;
    @Autowired
    IDriverDao iDriverDao;
    @Autowired
    private JdbcTemplate jdbcDao;
    @Autowired
    IUserDao userDao;

    @Autowired
    ITruckDriverLinkDao iTruckDriverLinkDao;

    @Autowired
    IShipStatusDao iShipStatusDao;
    @Autowired
    ICustomerDao iCustomerDao;
    @Autowired
    ISubCarStyleDao iSubCarStyleDao;

    @Autowired
    IMsgRecordService msgService;

    public TShiphead get(Integer id) {
        // TODO Auto-generated method stub
        return shipheadDao.get(id);
    }

    public void update(TShiphead entity) {
        // TODO Auto-generated method stub
        shipheadDao.update(entity);
    }

    public void updateCleanBefore(TShiphead entity) {
        shipheadDao.updateCleanBefore(entity);
    }

    public void save(TShiphead entity) {
        // TODO Auto-generated method stub
        shipheadDao.save(entity);
    }

    public void saveOrUpdate(TShiphead entity) {
        // TODO Auto-generated method stub
        shipheadDao.saveOrUpdate(entity);
    }

    public void delete(TShiphead entity) {
        // TODO Auto-generated method stub
        shipheadDao.delete(entity);
    }

    public void deleteByKey(Integer id) {
        // TODO Auto-generated method stub
        shipheadDao.deleteByKey(id);
    }

    public List<TShiphead> loadAll() {
        // TODO Auto-generated method stub
        return shipheadDao.loadAll();
    }

    public List<TShiphead> findAll(Page page) {
        // TODO Auto-generated method stub
        return shipheadDao.findAll(page);
    }

    public Map<String, Object> findByHelper(HqlHelper hql) {
        return shipheadDao.findAllByHqlHelp(hql);
    }

    /**
     * 
     * @Description: TODO(??)
     * @param msgstrs
     * @param driverID
     * @return
     * @author liuwu
     * @create_date 2015-7-8 ?1:44:22
     */
    @SuppressWarnings("unchecked")
    public String saveshipHead(String[] msgstrs, int driverID) {
        JSONObject msgobj = new JSONObject();
        msgobj.put("resultCode", "ok");
        msgobj.put("errorContent", "??");

        TUser user = (TUser) UserSession.get("user");
        String subno = subDao.get(user.getiArchive()).getVcSubno();
        // 
        TTruckDriver truckDriver = driverDao.get(driverID);
        TShiphead head = new TShiphead();
        head.setNShipType(0);
        head.setNEnable(0);
        head.setDtCreate(new Date());
        head.setVcSubno(subno);
        head.setVcShipno(getMaxShipNo());
        head.setITruckId(driverID);
        head.setVcTruckName(truckDriver.getVcCarNo());
        head.setVcDriverId(getDriverId(truckDriver));

        // ?ID? ???
        TDriver tDriver = findDriverLinkByTruckId(truckDriver.getId());
        String[] properties = { "IArchiveType", "iArchive", "NEnable" };
        Object[] mainValues = { SystemConstants.SYS_TARCHIVE_DRIVER, tDriver.getId(), SystemConstants.SYS_ENABLE };
        List<TUser> users = userDao.findByPropertys(properties, mainValues);
        shipheadDao.save(head);
        String caiStr = "";// ????
        for (int i = 0; i < msgstrs.length; i++) {
            String[] ords = msgstrs[i].split(",");
            TOrder order = orderDao.getOrderByOrderNo(ords[0]);

            if (order == null) {
                msgobj.put("resultCode", "no");
                msgobj.put("errorContent", "??" + ords[0] + "  ????");

                return msgobj.toString();
            }
            if (order.getnLoad() == 1) {
                msgobj.put("resultCode", "no");
                msgobj.put("errorContent", "?" + ords[0] + "?? ");

                return msgobj.toString();
            }

            int count = Integer.parseInt(ords[1]);
            if (count > order.getNTotalCar()) {
                System.out.println("?????");

                msgobj.put("resultCode", "no");
                msgobj.put("errorContent", "?????");

                return msgobj.toString();

            }
            String datestr = DateUtil.getDate("yyyy/MM/dd");
            // and to_char(ark.dtStart,'yyyy-MM-dd') between ? and ?
            String sql = " select getArkilomer('" + subno + "','" + order.getVcStartCity() + "','"
                    + order.getVcDestCity() + "','" + datestr + "') nar from dual ";
            System.out.println("sql" + sql);

            /*float nKilometer = 0;
            try
            {
                   
               List artlist = arkilomerDao.getDateBySQL( sql , null );
               if ( CollectionUtils.isNotEmpty( artlist )
                && artlist.get( 0 ) != null )
               {
                  nKilometer = Float.parseFloat( artlist.get( 0 ) + "" );
               }
               else
               {
                  msgobj.put( "resultCode" , "ok" );
                  msgobj.put( "errorContent" , order.getVcStartCity() + "  "
                   + order.getVcDestCity() + " " );
                      
               }
            }
            catch ( Exception e )
            {
               e.printStackTrace();
               // ??? ? ??  
               msgobj.put( "resultCode" , "no" );
               msgobj.put( "errorContent" , " " + e.getMessage() );
               return msgobj.toString();
            }*/
            if (count < order.getNTotalCar())// ?(???????2??)
            {
                order.setNEnable(SystemConstants.SYS_DISABLE);// ?
                orderDao.saveOrUpdate(order);
                // shipheadDao.save( head );
                for (int i1 = 0; i1 < 2; i1++) {
                    TOrder copyOrder = new TOrder();
                    try {
                        BeanUtils.copyProperties(copyOrder, order);
                        copyOrder.setVcOrderno(copyOrder.getVcOrderno() + "_" + (i1 + 1));
                        copyOrder.setNShipedQty(count);
                        copyOrder.setNEnable(SystemConstants.SYS_ENABLE);
                        System.out.println(count + "--" + order.getNTotalCar());

                        float ratio1 = Float.parseFloat(count + "") / Float.parseFloat(order.getNTotalCar() + "");
                        System.out.println("ratio1 = " + ratio1);
                        if (order.getNTotalPrice() != null) {
                            copyOrder.setNTotalPrice(ratio1 * order.getNTotalPrice());
                        }
                        copyOrder.setnLoad(1);// ?
                        if (i1 == 1) {

                            copyOrder.setNShipedQty(order.getNTotalCar() - count);// ??

                            if (order.getNTotalPrice() != null) {
                                copyOrder.setNTotalPrice((1 - ratio1) * order.getNTotalPrice());

                            }
                            copyOrder.setnLoad(0);// ?
                        }
                        copyOrder.setNTotalCar(copyOrder.getNShipedQty());

                        orderDao.save(copyOrder);
                        if (i1 == 0) {
                            TShipline line = new TShipline();
                            line.setIOrderId(copyOrder.getId());
                            line.setIShiphead(head.getId());
                            line.setVcStartCity(copyOrder.getVcStartCity());
                            line.setVcDestCity(copyOrder.getVcDestCity());
                            line.setDtAdd(new Date());
                            // line.setNQty( count );
                            line.setnShipQty(copyOrder.getNShipedQty());
                            // line.setNApkilometer( nKilometer );
                            shiplineDao.save(line);
                            TShipStatus tShipStatus = new TShipStatus();
                            tShipStatus.setnOrderId(copyOrder.getId());
                            tShipStatus.setnLineId(line.getId());
                            tShipStatus.setVcAddUser(user.getVcAccount());
                            tShipStatus.setVcStatusNote(SystemConstants.VC_LOADING_TRUE);
                            tShipStatus.setVcStatusTag(SystemConstants.VC_LOADING_TRUE_TAG);
                            tShipStatus.setnHeadId(head.getId());
                            iShipStatusDao.saveOrUpdate(tShipStatus);

                            // ??
                            HashMap<String, String> map = new HashMap<String, String>();
                            map.put("vcLineId", line.getId() + "");
                            map.put("msgType", "6");
                            PushUtils pushUtils = new PushUtils("?",
                                    "?" + user.getVcAccount() + "???", users,
                                    "com.unlcn.driver.ordermanagement.DriverOrderArriveDialogActivity", map);
                            pushUtils.run();
                            for (TUser tUser : users) {
                                // ??
                                TMsgRecord tMsgRecord = new TMsgRecord();
                                tMsgRecord.setIUser(user.getId());// ID
                                tMsgRecord.setVcAdduser(user.getVcAccount());// ??
                                tMsgRecord.setIUserAccept(tUser.getId());// id
                                tMsgRecord.setNMsgType(1);// ??
                                tMsgRecord.setVcContent("?" + user.getVcAccount() + "???");
                                tMsgRecord.setVcTitle("??");
                                msgService.save(tMsgRecord);
                            }
                        }
                    } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (Exception e) {
                        // TODO: handle exception
                        e.printStackTrace();
                    }
                }
                caiStr += "?" + order.getVcOrderno() + "?? ";
            } else {
                // shipheadDao.save( head );
                // order.setNShipedQty( order.getNShipedQty() + count );
                order.setnLoad(1);// ???
                order.setNShipedQty(count);
                orderDao.saveOrUpdate(order);
                TShipline line = new TShipline();
                line.setIOrderId(order.getId());
                line.setIShiphead(head.getId());
                line.setVcStartCity(order.getVcStartCity());
                line.setVcDestCity(order.getVcDestCity());
                line.setDtAdd(new Date());
                // line.setNQty( count );
                line.setnShipQty(count);
                // line.setNApkilometer( nKilometer );
                shiplineDao.save(line);

                TShipStatus tShipStatus = new TShipStatus();
                tShipStatus.setnOrderId(order.getId());
                tShipStatus.setnLineId(line.getId());
                tShipStatus.setVcAddUser(user.getVcAccount());
                tShipStatus.setVcStatusNote(SystemConstants.VC_LOADING_TRUE);
                tShipStatus.setVcStatusTag(SystemConstants.VC_LOADING_TRUE_TAG);
                tShipStatus.setnHeadId(head.getId());
                iShipStatusDao.save(tShipStatus);

                // ??
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("vcLineId", line.getId() + "");
                map.put("msgType", "6");
                PushUtils pushUtils = new PushUtils("?",
                        "?" + user.getVcAccount() + "???", users,
                        "com.unlcn.driver.ordermanagement.DriverOrderArriveDialogActivity", map);
                pushUtils.run();
                for (TUser tUser : users) {
                    // ??
                    TMsgRecord tMsgRecord = new TMsgRecord();
                    tMsgRecord.setIUser(user.getId());// ID
                    tMsgRecord.setVcAdduser(user.getVcAccount());// ??
                    tMsgRecord.setIUserAccept(tUser.getId());// id
                    tMsgRecord.setNMsgType(1);// ??
                    tMsgRecord.setVcContent("?" + user.getVcAccount() + "???");
                    tMsgRecord.setVcTitle("??");
                    msgService.save(tMsgRecord);
                }
            }
            truckDriver.setNStatus(1);// ????0
            // truckDriver.setVcShipNo( head.getVcShipno() );
            driverDao.saveOrUpdate(truckDriver);
        }
        if (caiStr != "") {
            msgobj.put("resultCode", "ok");
            msgobj.put("errorContent", caiStr);
        }

        return msgobj.toString();
    }

    /**
     * @Description: TODO(?ID?)
     * @param id
     * @return TDriver ??
     * @author liuwu
     * @create_date 2015-6-25 ?4:35:49
     */
    private TDriver findDriverLinkByTruckId(Integer id) {
        String[] propertyNames = { "NEnable", "ITruckID", "NPositionType" };
        Object[] values = { SystemConstants.SYS_ENABLE, id, 1 };
        List<TTruckDriverLlink> truckDriverLlinks = iTruckDriverLinkDao.findByPropertys(propertyNames, values);
        TDriver tDriver = iDriverDao.get(truckDriverLlinks.get(0).getIDriverID());
        return tDriver;
    }

    /**
     * @Description: TODO(ID?ID)
     * @param truckDriver
     * @return String ??
     * @author liuwu
     * @create_date 2015-6-3 ?5:03:27
     */
    private String getDriverId(TTruckDriver truckDriver) {
        String[] propertyNames = { "NEnable", "ITruckID" };
        Object[] values = { SystemConstants.SYS_ENABLE, truckDriver.getId() };
        List<TTruckDriverLlink> truckDriverLlinks = iTruckDriverLinkDao.findByPropertys(propertyNames, values);
        List<TDriver> tDrivers = new ArrayList<TDriver>();
        for (TTruckDriverLlink tLlink : truckDriverLlinks) {
            TDriver tDriver = iDriverDao.get(tLlink.getIDriverID());
            tDrivers.add(tDriver);
        }
        String strIds = "";
        for (TDriver tDriver : tDrivers) {
            strIds += tDriver.getId() + "" + ",";
        }
        System.out.println("strIds = " + strIds);
        return strIds;
    }

    /**
     * @Description: ??? Z+yyMMdd+4???
     * @return String ??
     * @author chenbin
     * @create_date 2014-7-19 ?3:26:33
     */
    public synchronized String getMaxShipNo() {

        List<TShiphead> orderlist = shipheadDao.findAllAndOrderByProperty("id", false);
        String shipNo = "Z";
        String datestr = DateUtil.getDate("yyMMdd");
        DecimalFormat df = new DecimalFormat("0000");
        String str2 = "";
        if (orderlist.size() == 0) {
            str2 = df.format(Integer.parseInt("1"));

        } else {
            TShiphead shead = orderlist.get(0);
            String str = shead.getVcShipno().substring(7, shead.getVcShipno().length());
            str2 = df.format(Integer.parseInt(str) + 1);
        }

        shipNo += datestr + str2;
        System.out.println("Max ShipNo " + shipNo);
        return shipNo;
    }

    /**
     * 
     * @Description:  ???
     * @param lineid
     *            void ??
     * @author chenbin
     * @create_date 2014-7-19 ?6:09:32
     */
    public void EntranceByShipLineID(int[] lineids) {
        TUser user = (TUser) UserSession.get("user");
        for (int lineid : lineids) {
            TShipline line = shiplineDao.get(lineid);
            /*line.setNEntrance( 0 );
            line.setDtEntrance( new Date() );
            line.setIEntranceUser( user.getId() );*/
            shiplineDao.update(line);
        }

    }

    /**
     * @Description:  ???
     * @param lineids
     *            void ??
     * @author chenbin
     * @create_date 2014-7-19 ?6:14:11
     */
    public void LoadByShipLineID(int[] lineids) {
        TUser user = (TUser) UserSession.get("user");
        for (int lineid : lineids) {
            TShipline line = shiplineDao.get(lineid);
            /*line.setNLoad( 0 );
            line.setDtLoad( new Date() );
            line.setILoadUser( user.getId() );*/
            shiplineDao.update(line);
        }

    }

    /**
     * @Description: ? ???
     * @param lineids
     *            void ??
     * @author chenbin
     * @create_date 2014-7-19 ?6:14:11
     */
    public void SendByShipLineID(int[] lineids) {
        TUser user = (TUser) UserSession.get("user");
        for (int lineid : lineids) {
            TShipline line = shiplineDao.get(lineid);
            /*line.setNShip( 0 );
            line.setDtShip( new Date() );
            line.setIShipUser( user.getId() );*/
            shiplineDao.update(line);
        }
        TShipline line = shiplineDao.get(lineids[0]);
        TShiphead head = shipheadDao.get(line.getIShiphead());

        String sql = " select count(*)  coun from TShipline line where line.IShiphead=" + head.getId()
                + " and line.NShip=0 ";
        int count1 = shiplineDao.getCountSQL(sql);

        sql = " select count(*)  coun from TShipline line where line.IShiphead=" + head.getId() + "  ";
        int count2 = shiplineDao.getCountSQL(sql);
        // ????? ????
        if (count1 == count2) {
            TTruckDriver driver = driverDao.get(head.getITruckId());
            driver.setNStatus(1);
            driverDao.update(driver);

        }

    }

    // ???
    public void saveDespatchInfo(String partype, String shipnos, int usid) {
        String[] strs = shipnos.split(",");
        TUser tUser = userDao.get(usid);
        // 
        if (partype.equals("parEntrance")) {
            for (String str : strs) {
                TShiphead head = shipheadDao.getShipHeadByshipNo(str);
                List<TShipline> shiplist = shiplineDao.findByProperty("IShiphead", head.getId());
                for (TShipline ship : shiplist) {
                    /*ship.setDtEntrance( new Date() );
                    ship.setIEntranceUser( usid );
                    ship.setNEntrance( 0 );*/

                    ship.setNCurrentStatus(SystemConstants.SYS_SUB_PARENTRANCE);
                    TShipStatus tShipStatus = new TShipStatus();
                    tShipStatus.setDtStatus(new Date());
                    tShipStatus.setnHeadId(ship.getIShiphead());
                    tShipStatus.setnLineId(ship.getId());
                    tShipStatus.setnOrderId(ship.getIOrderId());
                    tShipStatus.setVcAddUser(tUser.getVcAccount());
                    tShipStatus.setVcStatusNote(SystemConstants.VC_ENTRANCE_TRUE);// 
                    tShipStatus.setVcStatusTag(SystemConstants.VC_ENTRANCE_TRUE_TAG);
                    iShipStatusDao.saveOrUpdate(tShipStatus);
                }
                shiplineDao.saveOrUpdateAll(shiplist);
            }
        }
        // 
        else if (partype.equals("parload")) {
            for (String str : strs) {
                TShiphead head = shipheadDao.getShipHeadByshipNo(str);
                List<TShipline> shiplist = shiplineDao.findByProperty("IShiphead", head.getId());
                for (TShipline ship : shiplist) {
                    /*ship.setNLoad( 0 );
                    ship.setDtLoad( new Date() );
                    ship.setILoadUser( usid );*/
                    ship.setNCurrentStatus(SystemConstants.SYS_SUB_PARLOAD);
                    TShipStatus tShipStatus = new TShipStatus();
                    tShipStatus.setDtStatus(new Date());
                    tShipStatus.setnHeadId(ship.getIShiphead());
                    tShipStatus.setnLineId(ship.getId());
                    tShipStatus.setnOrderId(ship.getIOrderId());
                    tShipStatus.setVcAddUser(tUser.getVcAccount());
                    tShipStatus.setVcStatusNote(SystemConstants.VC_LOAD_TRUE);// 
                    tShipStatus.setVcStatusTag(SystemConstants.VC_LOAD_TRUE_TAG);
                    iShipStatusDao.saveOrUpdate(tShipStatus);
                }
                shiplineDao.saveOrUpdateAll(shiplist);
            }

        }
        // ??
        else if (partype.equals("parship")) {
            for (String str : strs) {
                TShiphead head = shipheadDao.getShipHeadByshipNo(str);
                List<TShipline> shiplist = shiplineDao.findByProperty("IShiphead", head.getId());
                for (TShipline ship : shiplist) {
                    /*ship.setNShip( 0 );
                    ship.setDtShip( new Date() );
                    ship.setIShipUser( usid );*/
                    ship.setNCurrentStatus(SystemConstants.SYS_SUB_PARSHIP);
                    TShipStatus tShipStatus = new TShipStatus();
                    tShipStatus.setDtStatus(new Date());
                    tShipStatus.setnHeadId(ship.getIShiphead());
                    tShipStatus.setnLineId(ship.getId());
                    tShipStatus.setnOrderId(ship.getIOrderId());
                    tShipStatus.setVcAddUser(tUser.getVcAccount());
                    tShipStatus.setVcStatusNote(SystemConstants.VC_SHIP_TRUE);// ??
                    tShipStatus.setVcStatusTag(SystemConstants.VC_SHIP_TRUE_TAG);
                    iShipStatusDao.saveOrUpdate(tShipStatus);

                }
                shiplineDao.saveOrUpdateAll(shiplist);
                // ??
                TTruckDriver driver = driverDao.get(head.getITruckId());
                driver.setNStatus(1);
                driverDao.update(driver);
            }
        }
        // ?
        else if (partype.equals("parArrived")) {
            for (String str : strs) {
                TShiphead head = shipheadDao.getShipHeadByshipNo(str);
                List<TShipline> shiplist = shiplineDao.findByProperty("IShiphead", head.getId());
                for (TShipline ship : shiplist) {
                    /*   ship.setNArrived( 0 );
                       ship.setDtArrived( new Date() );
                       ship.setIArrivedUser( usid );*/
                    ship.setNCurrentStatus(SystemConstants.SYS_SUB_PARARRIVED);
                    TShipStatus tShipStatus = new TShipStatus();
                    tShipStatus.setDtStatus(new Date());
                    tShipStatus.setnHeadId(ship.getIShiphead());
                    tShipStatus.setnLineId(ship.getId());
                    tShipStatus.setnOrderId(ship.getIOrderId());
                    tShipStatus.setVcAddUser(tUser.getVcAccount());
                    tShipStatus.setVcStatusNote(SystemConstants.VC_ARRIVED_TRUE);// ?
                    tShipStatus.setVcStatusTag(SystemConstants.VC_ARRIVED_TRUE_TAG);
                    iShipStatusDao.saveOrUpdate(tShipStatus);
                }
                shiplineDao.saveOrUpdateAll(shiplist);
            }

        }
        // ?
        else if (partype.equals("parReturn")) {
            strs = shipnos.split(";");

            for (String str : strs) {
                String[] shipstr = str.split(",");
                TShipline ship = shiplineDao.get(Integer.parseInt(shipstr[0]));

                /*ship.setNReturn( 0 );
                ship.setDtReturn( new Date() );
                ship.setIReturnUser( usid );*/
                ship.setNQty(Integer.parseInt(shipstr[1]));
                ship.setNCurrentStatus(SystemConstants.SYS_SUB_PARRETURN);

                shiplineDao.update(ship);
                TShiphead head = shipheadDao.get(ship.getIShiphead());
                // ?
                TTruckDriver driver = driverDao.get(head.getITruckId());
                if (driver.getNStatus() != 0) {
                    driver.setNStatus(0);
                    driverDao.update(driver);
                }
                TShipStatus tShipStatus = new TShipStatus();
                tShipStatus.setDtStatus(new Date());
                tShipStatus.setnHeadId(ship.getIShiphead());
                tShipStatus.setnLineId(ship.getId());
                tShipStatus.setnOrderId(ship.getIOrderId());
                tShipStatus.setVcAddUser(tUser.getVcAccount());
                tShipStatus.setVcStatusNote(SystemConstants.VC_RETURN_TRUE);// ?
                tShipStatus.setVcStatusTag(SystemConstants.VC_RETURN_TRUE_TAG);
                iShipStatusDao.saveOrUpdate(tShipStatus);
                // ??????
                TOrder order = orderDao.get(ship.getIOrderId());
                if (order.getNTotalCar() > 0) {
                    float ratio1 = Float.parseFloat(ship.getNQty() + "")
                            / Float.parseFloat(order.getNTotalCar() + "");
                    if (order.getNPayType().equals(0))// 
                    {
                        order.setNTotalPrice(ratio1 * order.getNTotalPrice());
                        orderDao.update(order);
                    }
                }

            }

        }
    }

    /**
     * @Description: ? ???
     * @param lineids
     *            void ??
     * @author chenbin
     * @create_date 2014-7-19 ?6:14:11
     */
    public void ReturnByShipLineID(String shipNo) {
        TUser user = (TUser) UserSession.get("user");

        List<TShiphead> headlist = shipheadDao.findByProperty("vcShipno", shipNo);
        if (headlist.size() > 1) {
            System.out.println("?? 1   ");
        }
        TShiphead head = headlist.get(0);
        List<TShipline> linelist = shiplineDao.findByProperty("IShiphead", head.getId());

        for (TShipline ship : linelist) {
            /*   line.setNReturn( 0 );
               line.setDtReturn( new Date() );
               line.setIReturnUser( user.getId() );*/
            shiplineDao.update(ship);
            TShipStatus tShipStatus = new TShipStatus();
            tShipStatus.setDtStatus(new Date());
            tShipStatus.setnHeadId(ship.getIShiphead());
            tShipStatus.setnLineId(ship.getId());
            tShipStatus.setnOrderId(ship.getIOrderId());
            tShipStatus.setVcAddUser(user.getVcUsername());
            tShipStatus.setVcStatusNote(SystemConstants.VC_RETURN_TRUE);// ?
            tShipStatus.setVcStatusTag(SystemConstants.VC_RETURN_TRUE_TAG);
            iShipStatusDao.saveOrUpdate(tShipStatus);
        }
        // ?? ??
        TTruckDriver driver = driverDao.get(head.getITruckId());
        driver.setNStatus(0);
        driverDao.update(driver);
    }

    /**
     * 
     * @Description: ??? 
     * @param subno
     * @return List ??
     * @author chenbin
     * @create_date 2014-7-19 ?6:57:22
     */
    public List getAllShipdetailBySubno(String subno) {
        int status = 0;
        String partype = "";

        String sql = "  select head.id,head.vc_shipno,ord.vc_orderno,head.dt_create,d.vc_car_no,d.vc_driver_name,line.vc_start_city,line.vc_dest_city,line.n_ship_qty,sty.vc_car_style "
                + " from t_shiphead head,t_shipline line,t_truck_driver d,t_order ord,t_sub_car_style sty "
                + " where head.id=line.i_shiphead and head.i_truck_id = d.id and line.i_order_id=ord.id and ord.i_car_style=sty.id and line."
                + partype + "=1 order by head.vc_shipno";
        List<String[]> dateslist = shipheadDao.getDateBySQL(sql, null);
        return dateslist;
    }

    /**
     * @Description: ?????
     * @param shipno
     * @return
     * @author chenbin
     * @create_date 2014-7-21 ?2:08:15
     */
    public List getAllReturnShip(String subno) {
        String sql = " select head.vcShipno,head.dtCreate,dri.vcCarNo,dri.vcDriverName,dri.vcDriverTel,line.id,line.vcStartCity,line.vcDestCity,line.NShipQty,line.NApkilometer "
                + "      from TShiphead  head ,TShipline line,TTruckDriver dri where head.id=line.IShiphead  and head.ITruckId=dri.id and line.NReturn=1 and head.vcSubno="
                + subno;
        List<String[]> dateslist = shipheadDao.getDateBySQL(sql, null);

        return dateslist;
    }

    public Map<String, Object> getSpringSQL(String sql, Page page) {

        return shipheadDao.getSpringSQL(sql, page);
    }

    /**
     * @Description: ?
     * @param headids
     *            shipheadID , 
     * @return
     * @author chenbin
     * @create_date 2014-9-15 ?2:18:41
     */
    public String saveShipInfoCancel(String headids) {
        String msgstr = "ok";
        TShiphead head = shipheadDao.get(Integer.parseInt(headids));

        String sql = "select head.id from t_shiphead head, t_shipline line where head.id=line.i_shiphead and head.id= "
                + headids + " group by line.n_current_status,head.id having  line.n_current_status < "
                + SystemConstants.SYS_SUB_PARSHIP;

        int count1 = shiplineDao.getCountSQL(sql);
        if (count1 > 0) {
            List<TShipline> linelist = shiplineDao.findByProperty("IShiphead", head.getId());
            for (TShipline line : linelist) {
                TOrder ord = orderDao.get(line.getIOrderId());
                ord.setNShipedQty(0);
                ord.setnLoad(0);// ??
                orderDao.update(ord);
            }

            head.setNEnable(SystemConstants.SYS_DISABLE);
            shipheadDao.update(head);
            // 
            int truckId = head.getITruckId();
            TTruckDriver truck = driverDao.get(truckId);
            truck.setNStatus(0);
            driverDao.updateCleanBefore(truck);
        } else {
            //  ????
            msgstr = "shiperror";
            return msgstr;
        }
        return msgstr;
    }

    /**
     * @Description: TODO(????)
     * @param sql
     * @param page
     * @return
     * @author chenbin
     * @create_date 2014-9-22 ?2:14:24
     */
    public List<String[]> getDateBySQL(String sql, Page page) {
        // TODO Auto-generated method stub
        return shipheadDao.getDateBySQL(sql, page);
    }

    /**
     * 
     * @Description: TODO(?)
     * @param strs
     * @param driveID
     * @param iHeadId
     * @return
     * @author liuwu
     * @create_date 2015-7-8 ?1:56:20
     */
    public String saveUpdateShipHead(String[] strs, int driveID, int iHeadId) {
        JSONObject msgobj = new JSONObject();
        msgobj.put("resultCode", "ok");
        msgobj.put("errorContent", "??");

        TUser user = (TUser) UserSession.get("user");
        String subno = subDao.get(user.getiArchive()).getVcSubno();
        // 
        TTruckDriver truckDriver = driverDao.get(driveID);
        TShiphead head = shipheadDao.get(iHeadId);
        /*head.setNShipType( 0 );
        head.setNEnable( 0 );
        head.setDtCreate( new Date() );
        head.setVcSubno( subno );
        head.setVcShipno( getMaxShipNo() );
        head.setITruckId( driveID );
        head.setVcTruckName( truckDriver.getVcCarNo() );
        head.setVcDriverId( getDriverId( truckDriver ) );*/

        // ?ID? ???
        TDriver tDriver = findDriverLinkByTruckId(truckDriver.getId());
        String[] properties = { "IArchiveType", "iArchive", "NEnable" };
        Object[] mainValues = { SystemConstants.SYS_TARCHIVE_DRIVER, tDriver.getId(), SystemConstants.SYS_ENABLE };
        List<TUser> users = userDao.findByPropertys(properties, mainValues);

        String caiStr = "";// ????
        for (int i = 0; i < strs.length; i++) {
            String[] ords = strs[i].split(",");
            TOrder order = orderDao.getOrderByOrderNo(ords[0]);
            if (order == null) {
                msgobj.put("resultCode", "no");
                msgobj.put("errorContent", "??" + ords[0] + "  ????");

                return msgobj.toString();
            }
            int count = Integer.parseInt(ords[1]);
            if (count > order.getNTotalCar()) {
                System.out.println("?????");

                msgobj.put("resultCode", "no");
                msgobj.put("errorContent", "?????");

                return msgobj.toString();

            }
            String datestr = DateUtil.getDate("yyyy/MM/dd");
            // and to_char(ark.dtStart,'yyyy-MM-dd') between ? and ?
            String sql = " select getArkilomer('" + subno + "','" + order.getVcStartCity() + "','"
                    + order.getVcDestCity() + "','" + datestr + "') nar from dual ";
            System.out.println("sql" + sql);

            float nKilometer = 0;
            try {

                List artlist = arkilomerDao.getDateBySQL(sql, null);
                nKilometer = Float.parseFloat(artlist.get(0) + "");
            } catch (Exception e) {
                // TODO: handle exception
                System.out.println("???  ? ??    ...");
                msgobj.put("resultCode", "ok");
                msgobj.put("errorContent",
                        order.getVcStartCity() + "  " + order.getVcDestCity() + " ");

            }
            if (count < order.getNTotalCar())// ?(???????2??)
            {
                order.setNEnable(SystemConstants.SYS_DISABLE);// ?
                orderDao.saveOrUpdate(order);

                for (int i1 = 0; i1 < 2; i1++) {
                    TOrder copyOrder = new TOrder();
                    try {
                        BeanUtils.copyProperties(copyOrder, order);
                        copyOrder.setVcOrderno(copyOrder.getVcOrderno() + "_" + (i1 + 1));
                        copyOrder.setNShipedQty(count);
                        copyOrder.setNEnable(SystemConstants.SYS_ENABLE);
                        System.out.println(count + "--" + order.getNTotalCar());

                        float ratio1 = Float.parseFloat(count + "") / Float.parseFloat(order.getNTotalCar() + "");
                        System.out.println("ratio1 = " + ratio1);
                        if (order.getNTotalPrice() != null) {
                            copyOrder.setNTotalPrice(ratio1 * order.getNTotalPrice());
                        }

                        if (i1 == 1) {

                            copyOrder.setNShipedQty(order.getNTotalCar() - count);// ??

                            if (order.getNTotalPrice() != null) {
                                copyOrder.setNTotalPrice((1 - ratio1) * order.getNTotalPrice());

                            }
                        }
                        copyOrder.setNTotalCar(copyOrder.getNShipedQty());
                        copyOrder.setnLoad(1);// ?
                        orderDao.save(copyOrder);
                        shipheadDao.save(head);
                        TShipline line = new TShipline();
                        line.setIOrderId(copyOrder.getId());
                        line.setIShiphead(head.getId());
                        line.setVcStartCity(copyOrder.getVcStartCity());
                        line.setVcDestCity(copyOrder.getVcDestCity());
                        line.setDtAdd(new Date());
                        // line.setNQty( count );
                        line.setnShipQty(copyOrder.getNShipedQty());
                        line.setNApkilometer(nKilometer);
                        shiplineDao.save(line);
                        TShipStatus tShipStatus = new TShipStatus();
                        tShipStatus.setnOrderId(copyOrder.getId());
                        tShipStatus.setnLineId(line.getId());
                        tShipStatus.setVcAddUser(user.getVcUsername());
                        tShipStatus.setVcStatusNote(SystemConstants.VC_LOADING_TRUE);
                        tShipStatus.setVcStatusTag(SystemConstants.VC_LOADING_TRUE_TAG);
                        tShipStatus.setnHeadId(head.getId());
                        iShipStatusDao.saveOrUpdate(tShipStatus);

                        // ??
                        HashMap<String, String> map = new HashMap<String, String>();
                        map.put("vcLineId", line.getId() + "");
                        PushUtils pushUtils = new PushUtils("",
                                "", users,
                                "com.unlcn.driver.ordermanagement.DriverOrderArriveDialogActivity", map);
                        pushUtils.run();

                    } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (Exception e) {
                        // TODO: handle exception
                        e.printStackTrace();
                    }
                }
                caiStr += "?" + order.getVcOrderno() + "?? ";
            } else {
                // shipheadDao.save( head );
                // order.setNShipedQty( order.getNShipedQty() + count );
                order.setnLoad(1);// ???
                order.setNShipedQty(count);
                orderDao.saveOrUpdate(order);
                TShipline line = new TShipline();
                line.setIOrderId(order.getId());
                line.setIShiphead(head.getId());
                line.setVcStartCity(order.getVcStartCity());
                line.setVcDestCity(order.getVcDestCity());
                line.setDtAdd(new Date());
                // line.setNQty( count );
                line.setnShipQty(count);
                line.setNApkilometer(nKilometer);
                shiplineDao.save(line);

                TShipStatus tShipStatus = new TShipStatus();
                tShipStatus.setnOrderId(order.getId());
                tShipStatus.setnLineId(line.getId());
                tShipStatus.setVcAddUser(user.getVcUsername());
                tShipStatus.setVcStatusNote(SystemConstants.VC_LOADING_TRUE);
                tShipStatus.setVcStatusTag(SystemConstants.VC_LOADING_TRUE_TAG);
                tShipStatus.setnHeadId(head.getId());
                iShipStatusDao.save(tShipStatus);

                // ??
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("vcLineId", line.getId() + "");
                PushUtils pushUtils = new PushUtils("",
                        "", users,
                        "com.unlcn.driver.ordermanagement.DriverOrderArriveDialogActivity", map);
                pushUtils.run();
            }
            // truckDriver.setNStatus( 1 );// ????0
            // truckDriver.setVcShipNo( head.getVcShipno() );
            driverDao.saveOrUpdate(truckDriver);
        }
        if (caiStr != "") {
            msgobj.put("resultCode", "ok");
            msgobj.put("errorContent", caiStr);
        }

        return msgobj.toString();
    }

    public List<TShiphead> findByProperty(String propertyName, Object value) {
        return shipheadDao.findByProperty(propertyName, value);
    }

    /**
     * @Description: TODO(???)
     * @param properties
     * @param values
     * @param orderByParam
     * @return
     * @author liuwu
     * @create_date 2015-9-8 ?4:46:34
     */
    public List<TShiphead> findByPropertysOrderBy(String[] properties, Object[] values, String orderByParam) {
        // TODO Auto-generated method stub
        return shipheadDao.findByPropertysOrderBy(properties, values, orderByParam);
    }

    public List<TShiphead> findByPropertys(String[] propertyNames, Object[] values) {
        return shipheadDao.findByPropertys(propertyNames, values);
    }

    // id????
    public List<Map<String, Object>> getOrdersByTruckId(int truckId) {
        Map<String, Object> map = getLatestShiphead(truckId);
        if (map == null) {
            return null;
        }
        int headId = Integer.parseInt(map.get("ID").toString());
        String sql = "select o.ID,o.VC_ORDERNO,o.VC_CAR_NAME,o.N_TOTAL_CAR,o.VC_START_CITY "
                + " from t_shipline l,t_order o where " + " l.I_ORDER_ID=o.id and o.N_LOADING=1 "
                + " and l.I_SHIPHEAD=" + headId;
        List<Map<String, Object>> result = jdbcDao.queryForList(sql);
        return result;
    }

    // ??
    public Map<String, Object> getLoadedTrucks(int userId, String vcCarNo) {
        String sql = "select t.ID,t.VC_CAR_NO,d.VC_DRIVER_NAME,d.VC_DRIVER_TEL from t_truck_driver t,t_driver d,"
                + "t_truck_driver_link l where l.I_DRIVER=d.id and l.I_TRUCK=t.id and "
                + " l.N_POSITION_TYPE=1 and t.N_STATUS=1 and d.I_USERID=" + userId;
        if (StringUtils.isNotBlank(vcCarNo)) {
            sql += " and t.VC_CAR_NO like '%" + vcCarNo + "%'";
        }
        Map<String, Object> result = shipheadDao.getSpringSQL(sql, null);
        return result;
    }

    // headId???
    public Map<String, Object> getOrdersByHid(int headId) {

        String sql = "select o.ID,o.VC_ORDERNO,o.VC_START_CITY,o.VC_DEST_CITY,o.VC_RECEIVE_CONTACT,"
                + "o.VC_RECEIVE_ADDRESS,o.Vc_Receive_Tel,o.VC_CAR_NAME,o.N_SHIPEDQTY,o.N_TOTAL_CAR"
                + " from t_shipline l,t_order o where l.I_ORDER_ID=o.id and o.N_ENABLE="
                + SystemConstants.SYS_ENABLE + "  and o.N_LOADING=1 and l.i_shiphead=" + headId;
        Map<String, Object> result = shipheadDao.getSpringSQL(sql, null);
        return result;
    }

    // truckId???
    public Map<String, Object> getLatestShiphead(int truckId) {
        String sql = "select ID,VC_SHIPNO,DT_CREATE,VC_SUBNO from t_shiphead h where N_ENABLE="
                + SystemConstants.SYS_ENABLE + " and N_CURRENT_STATUS<15 and I_TRUCK_ID=" + truckId
                + " order by DT_CREATE desc";
        List<Map<String, Object>> result = jdbcDao.queryForList(sql);
        if (CollectionUtils.isNotEmpty(result)) {
            return result.get(0);
        }
        return null;
    }

    /**
     * @Description: TODO(????)
     * @param iheadId
     * @return
     * @author liuwu
     * @create_date 2015-9-21 ?3:14:42
     */
    public String saveShipHeadFromErp(int iheadId) {
        String message = "success";

        String sql = "SELECT * FROM v_shiphead_erp@link_erp.unlcn.com head where head.ILINEID = " + iheadId;
        List<Map<String, Object>> arList = shipheadDao.excuteSql(sql);
        try {

            if (arList != null && arList.size() > 0) {

                String vcShipNo = (String) arList.get(0).get("VCSHIPNO");// ?
                System.out.println("vcShipNo = " + vcShipNo);
                /**
                 * ??
                 */
                String[] propertyNames1 = { "vcShipno", "NEnable" };
                Object[] values1 = { vcShipNo, SystemConstants.SYS_ENABLE };
                List<TShiphead> tShipheads = shipheadDao.findByPropertys(propertyNames1, values1);
                if (tShipheads != null && tShipheads.size() > 0) {
                    message = "?" + vcShipNo + "??";
                    return message;
                } else {
                    int mainDriverId = Integer.parseInt(arList.get(0).get("IDRIVERID").toString());// ???
                    int viceDriverId = Integer.parseInt(arList.get(0).get("IDRIVERID2").toString());// ???
                    int truckId = Integer.parseInt(arList.get(0).get("IVEHICLEID").toString());// ???
                    String vcLicence = arList.get(0).get("VCLICENSE").toString();// ?
                    /**
                     * 
                     */
                    TShiphead tShiphead = new TShiphead();
                    tShiphead.setVcShipno(vcShipNo);// ???
                    tShiphead.setDtCreate(new Date());// ?
                    tShiphead.setVcTruckName(vcLicence);// ???
                    /**
                     * ?? 
                     */
                    TTruckDriver truckDriver = createTruck(vcLicence);
                    truckDriver.setVcShipNo(vcShipNo);
                    driverDao.update(truckDriver);
                    tShiphead.setITruckId(truckDriver.getId());
                    tShiphead.setVcTruckName(truckDriver.getVcCarNo());
                    /**
                     *  ?
                     */
                    TSubsuppliers tSubsuppliers = getZhongLian();// ?
                    String[] properties = { "IArchiveType", "iArchive" };
                    Object[] values = { SystemConstants.SYS_TARCHIVE_SUB, tSubsuppliers.getId() };
                    TUser tUser = userDao.findByPropertys(properties, values).get(0);// ?ID

                    String sql2 = "SELECT * FROM  v_driver_erp@link_erp.unlcn.com where ilineid = " + mainDriverId;
                    List<Map<String, Object>> arList2 = shipheadDao.excuteSql(sql2);
                    String mainDriverName = "";
                    String mainDriverTel = "";
                    if (arList2.get(0).get("VCNAME") != null) {
                        mainDriverName = arList2.get(0).get("VCNAME").toString();// ???
                    }

                    if (arList2.get(0).get("VCMOBILE") != null) {
                        mainDriverTel = arList2.get(0).get("VCMOBILE").toString();// 
                    }

                    TDriver tDriver = checkTheSameDriver(mainDriverTel);
                    TDriver mainDriver = new TDriver();
                    List<TUser> driverUsers = new ArrayList<TUser>();// ??
                    if (tDriver == null) {
                        mainDriver.setVcDriverName(mainDriverName);
                        mainDriver.setVcDriverTel(mainDriverTel);
                        mainDriver.setVcSubno(tSubsuppliers.getVcSubno());
                        mainDriver.setiUserId(tUser.getId());
                        iDriverDao.save(mainDriver);
                        // 
                        TUser driverUser = new TUser();
                        driverUser.setIArchiveType(SystemConstants.SYS_TARCHIVE_DRIVER);
                        driverUser.setVcUsername(mainDriverName);
                        driverUser.setVcAccount(mainDriverTel);
                        org.springframework.security.authentication.encoding.Md5PasswordEncoder t = new Md5PasswordEncoder();
                        String tt = t.encodePassword("123456", driverUser.getVcAccount());
                        driverUser.setiArchive(mainDriver.getId());
                        driverUser.setVcPassword(tt);
                        userDao.save(driverUser);
                        driverUsers.add(driverUser);
                    }

                    /**
                     * ?
                     */
                    int driverId = 0;
                    if (tDriver == null) {
                        tShiphead.setVcDriverId(mainDriver.getId() + "," + 0);
                        driverId = mainDriver.getId();
                    } else {
                        tShiphead.setVcDriverId(tDriver.getId() + "," + 0);
                        driverId = tDriver.getId();
                    }

                    tShiphead.setVcSubno(tSubsuppliers.getVcSubno());// ?
                    tShiphead.setnCurrentStatus(0);// ??0?
                    shipheadDao.save(tShiphead);
                    /**
                     * ??
                     */
                    createTruckDriverLink(driverId, truckDriver.getId());

                    /**
                     * 
                     */

                    String sql4 = "SELECT * FROM   v_shipline_erp@link_erp.unlcn.com where ISHIPID = " + iheadId;
                    List<Map<String, Object>> arList4 = shipheadDao.excuteSql(sql4);
                    for (int i = 0; i < arList4.size(); i++)

                    {
                        TShipline tShipline = new TShipline();
                        int erpOrderId = Integer.parseInt(arList4.get(i).get("IORDERID").toString());// ?ID
                        /**
                         * ?ERP????
                         */
                        TOrder tOrder = createOrder(erpOrderId, tShiphead);
                        tShipline.setIOrderId(tOrder.getId());// ?ID
                        tShipline.setIShiphead(tShiphead.getId());// ID
                        if (arList4.get(i).get("DCQTY") != null) {
                            tShipline.setNQty(Integer.parseInt(arList4.get(i).get("DCQTY").toString()));// ?
                        }
                        if (arList4.get(i).get("DCSHIPQTY") != null) {
                            tShipline.setnShipQty(Integer.parseInt(arList4.get(i).get("DCSHIPQTY").toString()));// ??
                        }
                        if (arList4.get(i).get("VCSTARTCITYNAME") != null) {
                            tShipline.setVcStartCity(arList4.get(i).get("VCSTARTCITYNAME").toString());// 
                        }
                        if (arList4.get(i).get("VCENDCITYNAME") != null) {
                            tShipline.setVcDestCity(arList4.get(i).get("VCENDCITYNAME").toString());// ??
                        }
                        tShipline.setDtAdd(new Date());
                        if (arList4.get(i).get("DCARKILOMETER") != null)// 
                        {
                            tShipline.setNApkilometer(
                                    Float.parseFloat(arList4.get(i).get("DCARKILOMETER").toString()));
                        }
                        tShipline.setNCurrentStatus(0);
                        tShipline.setNarorder(1);
                        shiplineDao.save(tShipline);
                        /**
                         * ??
                         */
                        TShipStatus tShipStatus = new TShipStatus();
                        tShipStatus.setnOrderId(tOrder.getId());
                        tShipStatus.setnLineId(tShipline.getId());
                        tShipStatus.setVcAddUser(tUser.getVcAccount());
                        tShipStatus.setVcStatusNote(SystemConstants.VC_LOADING_TRUE);
                        tShipStatus.setVcStatusTag(SystemConstants.VC_LOADING_TRUE_TAG);
                        tShipStatus.setnHeadId(tShiphead.getId());
                        iShipStatusDao.save(tShipStatus);

                        /**
                         * ??
                         */

                        HashMap<String, String> map = new HashMap<String, String>();
                        map.put("vcLineId", tShipline.getId() + "");
                        map.put("msgType", "6");
                        PushUtils pushUtils = new PushUtils("?",
                                "?" + tUser.getVcAccount() + "???", driverUsers,
                                "com.unlcn.driver.ordermanagement.DriverOrderArriveDialogActivity", map);
                        pushUtils.run();
                        for (TUser tuser : driverUsers) {
                            // ??
                            TMsgRecord tMsgRecord = new TMsgRecord();
                            tMsgRecord.setIUser(tUser.getId());// ID
                            tMsgRecord.setVcAdduser(tUser.getVcAccount());// ??
                            tMsgRecord.setIUserAccept(tuser.getId());// id
                            tMsgRecord.setNMsgType(1);// ??
                            tMsgRecord.setVcContent("?" + tUser.getVcAccount() + "???");
                            tMsgRecord.setVcTitle("??");
                            msgService.save(tMsgRecord);
                        }
                    }

                }

            } else {
                return "??";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }

        return message;

    }

    /**
     * @Description: TODO(????)
     * @param driverId
     * @param truckId
     *            void ??
     * @author liuwu
     * @create_date 2015-9-23 ?6:34:38
     */
    private void createTruckDriverLink(int driverId, int truckId) {
        String[] propertyNames = { "IDriverID", "NPositionType" };
        Object[] values = { driverId, 1 };
        List<TTruckDriverLlink> links = iTruckDriverLinkDao.findByPropertys(propertyNames, values);
        if (links != null && links.size() > 0) {
            TTruckDriverLlink truckDriverLlink = links.get(0);
            truckDriverLlink.setITruckID(truckId);
            iTruckDriverLinkDao.update(truckDriverLlink);
        } else {
            TTruckDriverLlink newDriverLlink = new TTruckDriverLlink();
            newDriverLlink.setIDriverID(driverId);
            newDriverLlink.setITruckID(truckId);
            newDriverLlink.setNEnable(SystemConstants.SYS_ENABLE);
            newDriverLlink.setNPositionType(1);
            iTruckDriverLinkDao.save(newDriverLlink);
        }

    }

    /**
     * @Description: TODO(?ERP????)
     * @param erpOrderId
     * @return TOrder ??
     * @author liuwu
     * @param tShiphead
     * @create_date 2015-9-22 ?2:50:10
     */
    private TOrder createOrder(int erpOrderId, TShiphead tShiphead) {

        String sql4 = "SELECT * FROM   v_order_erp@link_erp.unlcn.com where ilineid = " + erpOrderId;
        List<Map<String, Object>> torderList = shipheadDao.excuteSql(sql4);
        TOrder tOrder = new TOrder();
        if (torderList != null && torderList.size() > 0) {

            int customerId = Integer.parseInt(torderList.get(0).get("ICUSTOMERID").toString());// erp
            TCustomer tCustomer = createCustomer(customerId);// 
            int carId = Integer.parseInt(torderList.get(0).get("ISTYLEID").toString());
            TSubCarStyle tSubCarStyle = createCarStyle(carId);// ?
            TSubsuppliers tSubsuppliers = getZhongLian();// ?
            tOrder.setICarStyle(carId);
            tOrder.setVcCarName(tSubCarStyle.getVcCarStyle());
            tOrder.setVcSubno(tSubsuppliers.getVcSubno());
            if (torderList.get(0).get("VCADDRESS") != null) {
                tOrder.setVcLoadAddress(torderList.get(0).get("VCADDRESS").toString());// ?
            }
            if (torderList.get(0).get("VCCONTACT2") != null) {
                tOrder.setVcLoadContact(torderList.get(0).get("VCCONTACT2").toString());// ?
            }
            if (torderList.get(0).get("VCTEL") != null) {
                tOrder.setVcLoadTel(torderList.get(0).get("VCTEL").toString());// ??
            }
            if (torderList.get(0).get("DTSHIPDATE") != null) {
                tOrder.setDtShip((Date) torderList.get(0).get("DTSHIPDATE"));// ???
            }
            if (torderList.get(0).get("DTCOMEDATE") != null) {
                tOrder.setDtArrive((Date) torderList.get(0).get("DTCOMEDATE"));// ?
            }
            if (torderList.get(0).get("VCSTARTCITY") != null) {
                tOrder.setVcStartCity(torderList.get(0).get("VCSTARTCITY").toString());// ?
            }
            if (torderList.get(0).get("VCCITYNAME") != null) {
                tOrder.setVcDestCity(torderList.get(0).get("VCCITYNAME").toString());// 
            }
            if (torderList.get(0).get("VCADDRESS2") != null) {
                tOrder.setVcReceiveAddress(torderList.get(0).get("VCADDRESS2").toString());// ?
            }
            if (torderList.get(0).get("VCCONTACT2") != null) {
                tOrder.setVcReceiveContact(torderList.get(0).get("VCCONTACT2").toString());// ?
            }
            if (torderList.get(0).get("VCTEL2") != null) {
                tOrder.setVcReceiveTel(torderList.get(0).get("VCTEL2").toString());// ?
            }
            if (torderList.get(0).get("DCQTY") != null) {
                tOrder.setNTotalCar(Integer.parseInt(torderList.get(0).get("DCQTY").toString()));// ?
            }
            if (torderList.get(0).get("DCSHIPEDQTY") != null) {
                tOrder.setNShipedQty(Integer.parseInt(torderList.get(0).get("DCSHIPEDQTY").toString()));// ???
            }
            if (torderList.get(0).get("VCORDERNO") != null) {
                if (tCustomer.getNSecondHandCar() == 0) {

                    tOrder.setVcOrderno(torderList.get(0).get("VCORDERNO").toString() + "*");// ??
                } else {
                    tOrder.setVcOrderno(torderList.get(0).get("VCORDERNO").toString());// ??
                }
            }
            if (torderList.get(0).get("IPAYID") != null) {
                tOrder.setNPayType(Integer.parseInt(torderList.get(0).get("IPAYID").toString()));// ?(0  1)
            }
            if (torderList.get(0).get("DCPAY") != null) {
                tOrder.setNTotalPrice(Float.parseFloat(torderList.get(0).get("DCPAY").toString()));// ?
            }
            if (tCustomer != null) {
                tOrder.setICustomerId(tCustomer.getId());// ID
            }
            if (torderList.get(0).get("VCCUSTORDERNO") != null) {
                tOrder.setVcCustOrderNo(torderList.get(0).get("VCCUSTORDERNO").toString());// ??()
            }
            if (torderList.get(0).get("DTDATE") != null) {
                tOrder.setDtCreateDate((Date) torderList.get(0).get("DTDATE"));// 
            }
            tOrder.setnLoad(1);// ??0?[]1?
            tOrder.setiTruckId(tShiphead.getITruckId());// ID
            orderDao.save(tOrder);
        }

        return tOrder;
    }

    /**
     * @Description: TODO( ?)
     * @param carId
     * @return TCarStyle ??
     * @author liuwu
     * @create_date 2015-9-22 ?4:05:59
     */
    private TSubCarStyle createCarStyle(int carId) {
        String sql = "SELECT * FROM  v_carstyle_erp@link_erp.unlcn.com where ilineid = " + carId;
        List<Map<String, Object>> carStyles = shipheadDao.excuteSql(sql);
        String vcCarStyle = carStyles.get(0).get("VCSTYLENAME").toString();
        TSubCarStyle tSubCarStyle = new TSubCarStyle();
        TSubsuppliers tSubsuppliers = getZhongLian();
        String[] properties = { "vcCarStyle", "NEnable", "vcSubno" };
        Object[] values = { vcCarStyle, SystemConstants.SYS_ENABLE, tSubsuppliers.getVcSubno() };
        List<TSubCarStyle> tSubCarStyles = iSubCarStyleDao.findByPropertys(properties, values);

        if (tSubCarStyles != null && tSubCarStyles.size() > 0) {
            return tSubCarStyles.get(0);

        } else {
            tSubCarStyle.setVcCarStyle(vcCarStyle);
            tSubCarStyle.setVcSubno(tSubsuppliers.getVcSubno());
            iSubCarStyleDao.saveOrUpdate(tSubCarStyle);
            return tSubCarStyle;
        }

    }

    /**
     * @Description: TODO()
     * @param customerId
     * @return TCustomer ??
     * @author liuwu
     * @create_date 2015-9-22 ?3:16:14
     */
    private TCustomer createCustomer(int customerId) {
        String sql = "SELECT * FROM  v_customer_erp@link_erp.unlcn.com where ilineid = " + customerId;
        List<Map<String, Object>> tCustomers = shipheadDao.excuteSql(sql);
        String vcCustomer = tCustomers.get(0).get("VCCUSTOMERNAME").toString();
        TCustomer tCustomer = new TCustomer();
        List<TCustomer> tCustomerList = iCustomerDao.findByProperty("vcShortName", vcCustomer);
        TSubsuppliers tSubsuppliers = getZhongLian();

        if (tCustomerList != null && tCustomerList.size() > 0) {
            return tCustomerList.get(0);
        } else {
            tCustomer.setVcCustomerNo(tCustomers.get(0).get("VCCUSTOMERNO").toString());// ?
            tCustomer.setVcShortName(tCustomers.get(0).get("VCCUSTOMERNAME").toString());// 
            if (tCustomers.get(0).get("VCCONTACT") != null) {
                tCustomer.setVcLinkman(tCustomers.get(0).get("VCCONTACT").toString());// ?
            }
            if (tCustomers.get(0).get("VCTEL") != null) {

                tCustomer.setVcPhone(tCustomers.get(0).get("VCTEL").toString());// ??
            }
            if (tCustomers.get(0).get("VCADDRESS") != null) {
                tCustomer.setVcRegAddress(tCustomers.get(0).get("VCADDRESS").toString());// ??
            }
            if (tCustomers.get(0).get("VCPROVINCE").toString() != null) {
                tCustomer.setVcProvince(tCustomers.get(0).get("VCPROVINCE").toString());
            }
            if (tCustomers.get(0).get("VCCITYNAME").toString() != null) {
                tCustomer.setVcCity(tCustomers.get(0).get("VCCITYNAME").toString());
            }
            tCustomer.setVcSubno(tSubsuppliers.getVcSubno());// ?
            if (tCustomers.get(0).get("ITYPE").toString() != null) {
                if (tCustomers.get(0).get("ITYPE").toString().equals("4")) {
                    tCustomer.setNSecondHandCar(0);// ?erp?01?
                } else {
                    tCustomer.setNSecondHandCar(1);// ?erp?01?
                }

            }
            // tCustomer.setNSecondHandCar( 0 );// ?erp?01?
            iCustomerDao.saveOrUpdate(tCustomer);
            return tCustomer;
        }

    }

    /**
     * @Description: TODO(????)
     * @return TSubsuppliers ??
     * @author liuwu
     * @create_date 2015-9-22 ?4:22:43
     */
    private TSubsuppliers getZhongLian() {
        TSubsuppliers tSubsuppliers = subDao.get(SystemConstants.ZHONGLIANID);
        return tSubsuppliers;
    }

    /**
     * @Description: TODO(???)
     * @param mainDriverTel
     * @return TDriver ??
     * @author liuwu
     * @create_date 2015-9-22 ?2:10:34
     */
    private TDriver checkTheSameDriver(String mainDriverTel) {
        List<TDriver> tDrivers = iDriverDao.findByProperty("vcDriverTel", mainDriverTel);
        if (tDrivers != null && tDrivers.size() > 0) {
            return tDrivers.get(0);
        }
        return null;
    }

    /**
     * @Description: TODO(??)
     * @param vcLicence
     * @return boolean ??
     * @author liuwu
     * @create_date 2015-9-22 ?1:44:38
     */
    private TTruckDriver createTruck(String vcLicence) {
        List<TTruckDriver> truckDrivers = driverDao.findByProperty("vcCarNo", vcLicence);
        if (truckDrivers != null && truckDrivers.size() > 0) {
            return truckDrivers.get(0);
        } else {
            TTruckDriver truckDriver = new TTruckDriver();
            truckDriver.setVcCarNo(vcLicence);
            truckDriver.setNStatus(1);
            driverDao.save(truckDriver);
            return truckDriver;
        }

    }

    /**
     * @Description: TODO(????)
     * @param sql
     * @return
     * @author liuwu
     * @create_date 2015-9-24 ?10:17:59
     */
    public List<Map<String, Object>> excuteSql(String sql) {
        List<Map<String, Object>> arlist = shipheadDao.excuteSql(sql);
        return arlist;
    }

    /**
     * @Description: TODO(????)
     * @param iheadId
     * @return
     * @author liuwu
     * @create_date 2015-9-24 ?2:22:40
     */
    public String updateCancelShipHead(int iheadId) {
        String message = "success";

        String sql = "SELECT * FROM v_shiphead_erp@link_erp.unlcn.com head where head.ILINEID = " + iheadId;
        List<Map<String, Object>> arList = shipheadDao.excuteSql(sql);

        try {
            if (arList != null && arList.size() > 0) {
                String vcShipNo = (String) arList.get(0).get("VCSHIPNO");// ?
                String[] propertyNames = { "vcShipno", "NEnable" };
                Object[] values = { vcShipNo, SystemConstants.SYS_ENABLE };
                List<TShiphead> tShipheads = shipheadDao.findByPropertys(propertyNames, values);
                if (tShipheads != null && tShipheads.size() > 0) {
                    TShiphead tShiphead = tShipheads.get(0);
                    tShiphead.setNEnable(SystemConstants.SYS_DISABLE);
                    shipheadDao.update(tShiphead);
                    cancelShipLine(tShiphead.getId());
                }

            } else {
                message = "??";
            }
        } catch (Exception e) {
            message = "?" + e.getMessage();
        }
        return message;
    }

    /**
     * @Description: TODO(?)
     * @param id
     *            void ??
     * @author liuwu
     * @create_date 2015-9-24 ?2:38:48
     */
    private void cancelShipLine(Integer id) {

        String[] propertyNames = { "IShiphead", "NEnable" };
        Object[] values = { id, SystemConstants.SYS_ENABLE };
        List<TShipline> tShiplines = shiplineDao.findByPropertys(propertyNames, values);
        for (TShipline tShipline : tShiplines) {
            tShipline.setNEnable(SystemConstants.SYS_DISABLE);
            shiplineDao.update(tShipline);
            TOrder tOrder = orderDao.get(tShipline.getIOrderId());
            tOrder.setNEnable(SystemConstants.SYS_DISABLE);
            orderDao.update(tOrder);
        }

    }

    /**
     * @Description: TODO(????)
     * @param iheadId
     * @param itruckId
     * @param idriverId
     * @return
     * @author liuwu
     * @create_date 2015-9-24 ?3:05:19
     */
    public String updateShipHeadTruckAndDriver(int iheadId, int itruckId, int idriverId) {
        String message = "success";

        String sql = "SELECT * FROM v_shiphead_erp@link_erp.unlcn.com head where head.ILINEID = " + iheadId;
        List<Map<String, Object>> arList = shipheadDao.excuteSql(sql);

        try {
            if (arList != null && arList.size() > 0) {
                String vcShipNo = (String) arList.get(0).get("VCSHIPNO");// ?
                String[] propertyNames = { "vcShipno", "NEnable" };
                Object[] values = { vcShipNo, SystemConstants.SYS_ENABLE };
                List<TShiphead> tShipheads = shipheadDao.findByPropertys(propertyNames, values);
                if (tShipheads != null && tShipheads.size() > 0) {
                    TShiphead tShiphead = tShipheads.get(0);

                    String sql2 = "select * from V_VEHICLE_ERP@link_erp.unlcn.com t where t.ILINEID =" + itruckId;
                    List<Map<String, Object>> arList2 = shipheadDao.excuteSql(sql2);
                    if (arList2 != null && arList2.size() > 0) {
                        String vcLicence = arList.get(0).get("VCLICENSE").toString();// ?

                        /**
                         * ?? 
                         */
                        TTruckDriver truckDriver = createTruck(vcLicence);
                        tShiphead.setVcTruckName(truckDriver.getVcCarNo());
                        tShiphead.setITruckId(truckDriver.getId());
                        /**
                         * ??
                         */

                        TDriver driver = createDriver(idriverId);
                        tShiphead.setVcDriverId(driver.getId() + "," + 0);
                        shipheadDao.update(tShiphead);
                    } else {
                        message = "?";
                    }
                } else {
                    message = "???";
                }

            } else {
                message = "erp??";
            }
        } catch (Exception e) {
            message = "?" + e.getMessage();
        }
        return message;
    }

    /**
     * @Description: TODO(?)
     * @return TDriver ??
     * @author liuwu
     * @create_date 2015-9-24 ?3:36:51
     */
    private TDriver createDriver(int idriverId) {
        String sql3 = "SELECT * FROM  v_driver_erp@link_erp.unlcn.com where ilineid = " + idriverId;
        List<Map<String, Object>> arList = shipheadDao.excuteSql(sql3);
        String mainDriverTel = "";
        String mainDriverName = "";
        TSubsuppliers tSubsuppliers = getZhongLian();
        String[] properties = { "IArchiveType", "iArchive" };
        Object[] value = { SystemConstants.SYS_TARCHIVE_SUB, tSubsuppliers.getId() };
        TUser tUser = userDao.findByPropertys(properties, value).get(0);// ?ID
        if (arList.get(0).get("VCMOBILE") != null) {
            mainDriverTel = arList.get(0).get("VCMOBILE").toString();// 
        }

        if (arList.get(0).get("VCNAME") != null) {
            mainDriverName = arList.get(0).get("VCNAME").toString();// ??
        }

        String[] propertyNames = { "vcDriverTel", "NEnable", "vcSubno" };
        Object[] values = { mainDriverTel, SystemConstants.SYS_ENABLE, tSubsuppliers.getVcSubno() };
        List<TDriver> tDrivers = iDriverDao.findByPropertys(propertyNames, values);

        if (tDrivers != null && tDrivers.size() > 0) {
            return tDrivers.get(0);
        } else {
            TDriver mainDriver = new TDriver();
            mainDriver.setVcDriverName(mainDriverName);
            mainDriver.setVcDriverTel(mainDriverTel);
            mainDriver.setVcSubno(tSubsuppliers.getVcSubno());
            mainDriver.setiUserId(tUser.getId());
            iDriverDao.save(mainDriver);
            // 
            TUser driverUser = new TUser();
            driverUser.setIArchiveType(SystemConstants.SYS_TARCHIVE_DRIVER);
            driverUser.setVcUsername(mainDriverName);
            driverUser.setVcAccount(mainDriverTel);
            org.springframework.security.authentication.encoding.Md5PasswordEncoder t = new Md5PasswordEncoder();
            String tt = t.encodePassword("123456", driverUser.getVcAccount());
            driverUser.setiArchive(mainDriver.getId());
            driverUser.setVcPassword(tt);
            userDao.save(driverUser);
            return mainDriver;
        }

    }

    /**
     * 
     * @Description: TODO(??)
     * @param iheadId
     * @param type
     * @param orderIds
     * @return
     * @author liuwu
     * @create_date 2015-9-25 ?10:57:43
     */
    public String updateChangeOrderQtysFromErp(int iheadId, String type, String orderIds) {
        String message = "success";
        /**
         * ?
         */
        if (type.equalsIgnoreCase("add")) {
            String sql = "SELECT * FROM v_shiphead_erp@link_erp.unlcn.com head where head.ILINEID = " + iheadId;
            List<Map<String, Object>> arList = shipheadDao.excuteSql(sql);

            if (arList != null && arList.size() > 0) {
                String vcShipNo = (String) arList.get(0).get("VCSHIPNO");// ?
                System.out.println("vcShipNo = " + vcShipNo);
                /**
                 * ??
                 */
                String[] propertyNames1 = { "vcShipno", "NEnable" };
                Object[] values1 = { vcShipNo, SystemConstants.SYS_ENABLE };
                List<TShiphead> tShipheads = shipheadDao.findByPropertys(propertyNames1, values1);
                if (tShipheads != null && tShipheads.size() > 0) {
                    TShiphead tShiphead = tShipheads.get(0);
                    String[] ids = orderIds.split(",");
                    for (String id : ids) {
                        int erpOrderId = Integer.parseInt(id);
                        TOrder tOrder = createOrder(erpOrderId, tShiphead);

                    }
                } else {
                    message = "???";
                }

            } else {
                message = "erp?!";
            }

        } else if (type.equalsIgnoreCase("delete")) {
            String[] ids = orderIds.split(",");
            for (String id : ids) {
                int erpOrderId = Integer.parseInt(id);
                message = disableOrder(erpOrderId);
                if (message.equalsIgnoreCase("success")) {
                    continue;
                } else {
                    break;
                }
            }
        }

        return message;
    }

    /**
     * @Description: TODO()
     * @param erpOrderId
     *            void ??
     * @author liuwu
     * @create_date 2015-9-25 ?1:56:15
     */
    private String disableOrder(int erpOrderId) {
        String message = "success";
        String sql4 = "SELECT * FROM   v_order_erp@link_erp.unlcn.com where ilineid = " + erpOrderId;
        List<Map<String, Object>> torderList = shipheadDao.excuteSql(sql4);
        if (torderList != null && torderList.size() > 0) {
            int customerId = Integer.parseInt(torderList.get(0).get("ICUSTOMERID").toString());// erp
            TCustomer tCustomer = createCustomer(customerId);// 
            if (torderList.get(0).get("VCORDERNO") != null) {
                if (tCustomer.getNSecondHandCar() == 0) {

                    String vcOrderNo = torderList.get(0).get("VCORDERNO").toString() + "*";// ??
                    String[] propertyNames = { "NEnable", "vcOrderno" };
                    Object[] values = { SystemConstants.SYS_ENABLE, vcOrderNo };
                    List<TOrder> tOrders = orderDao.findByPropertys(propertyNames, values);
                    if (tOrders != null && tOrders.size() > 0) {
                        for (TOrder tOrder : tOrders) {
                            tOrder.setNEnable(SystemConstants.SYS_DISABLE);
                            orderDao.update(tOrder);
                        }
                    } else {
                        message = "????" + vcOrderNo + "??";
                    }
                } else {
                    String vcOrderNo = torderList.get(0).get("VCORDERNO").toString();// ??
                    String[] propertyNames = { "NEnable", "vcOrderno" };
                    Object[] values = { SystemConstants.SYS_ENABLE, vcOrderNo };
                    List<TOrder> tOrders = orderDao.findByPropertys(propertyNames, values);
                    if (tOrders != null && tOrders.size() > 0) {
                        for (TOrder tOrder : tOrders) {
                            tOrder.setNEnable(SystemConstants.SYS_DISABLE);
                            orderDao.update(tOrder);
                        }
                    } else {
                        message = "????" + vcOrderNo + "??";
                    }

                }
            } else {
                message = "??????";
            }
        } else {
            message = "ERP???";
        }

        return message;
    }

    /**
     * 
     * @Description: TODO(????)
     * @param iheadId
     * @param iorderId
     * @return
     * @author liuwu
     * @create_date 2015-9-25 ?2:55:02
     */
    public String updateOrderDetialsFromErp(int iorderId) {
        String message = "";
        String sql4 = "SELECT * FROM   v_order_erp@link_erp.unlcn.com where ilineid = " + iorderId;
        List<Map<String, Object>> torderList = shipheadDao.excuteSql(sql4);
        if (torderList != null && torderList.size() > 0) {
            int customerId = Integer.parseInt(torderList.get(0).get("ICUSTOMERID").toString());// erp
            TCustomer tCustomer = createCustomer(customerId);// 
            if (torderList.get(0).get("VCORDERNO") != null) {
                String vcOrderNo = "";
                if (tCustomer.getNSecondHandCar() == 0) {
                    vcOrderNo = torderList.get(0).get("VCORDERNO").toString() + "*";// ??
                } else {
                    vcOrderNo = torderList.get(0).get("VCORDERNO").toString();// ??
                }
                String[] propertyNames = { "NEnable", "vcOrderno" };
                Object[] values = { SystemConstants.SYS_ENABLE, vcOrderNo };
                List<TOrder> tOrders = orderDao.findByPropertys(propertyNames, values);
                if (tOrders != null && tOrders.size() > 0) {
                    TOrder tOrder = tOrders.get(0);

                    int carId = Integer.parseInt(torderList.get(0).get("ISTYLEID").toString());
                    TSubCarStyle tSubCarStyle = createCarStyle(carId);// ?
                    TSubsuppliers tSubsuppliers = getZhongLian();// ?
                    tOrder.setICarStyle(carId);
                    tOrder.setVcCarName(tSubCarStyle.getVcCarStyle());
                    tOrder.setVcSubno(tSubsuppliers.getVcSubno());
                    if (torderList.get(0).get("VCADDRESS") != null) {
                        tOrder.setVcLoadAddress(torderList.get(0).get("VCADDRESS").toString());// ?
                    }
                    if (torderList.get(0).get("VCCONTACT2") != null) {
                        tOrder.setVcLoadContact(torderList.get(0).get("VCCONTACT2").toString());// ?
                    }
                    if (torderList.get(0).get("VCTEL") != null) {
                        tOrder.setVcLoadTel(torderList.get(0).get("VCTEL").toString());// ??
                    }
                    if (torderList.get(0).get("DTSHIPDATE") != null) {
                        tOrder.setDtShip((Date) torderList.get(0).get("DTSHIPDATE"));// ???
                    }
                    if (torderList.get(0).get("DTCOMEDATE") != null) {
                        tOrder.setDtArrive((Date) torderList.get(0).get("DTCOMEDATE"));// ?
                    }
                    if (torderList.get(0).get("VCSTARTCITY") != null) {
                        tOrder.setVcStartCity(torderList.get(0).get("VCSTARTCITY").toString());// ?
                    }
                    if (torderList.get(0).get("VCCITYNAME") != null) {
                        tOrder.setVcDestCity(torderList.get(0).get("VCCITYNAME").toString());// 
                    }
                    if (torderList.get(0).get("VCADDRESS2") != null) {
                        tOrder.setVcReceiveAddress(torderList.get(0).get("VCADDRESS2").toString());// ?
                    }
                    if (torderList.get(0).get("VCCONTACT2") != null) {
                        tOrder.setVcReceiveContact(torderList.get(0).get("VCCONTACT2").toString());// ?
                    }
                    if (torderList.get(0).get("VCTEL2") != null) {
                        tOrder.setVcReceiveTel(torderList.get(0).get("VCTEL2").toString());// ?
                    }
                    if (torderList.get(0).get("DCQTY") != null) {
                        tOrder.setNTotalCar(Integer.parseInt(torderList.get(0).get("DCQTY").toString()));// ?
                    }
                    if (torderList.get(0).get("DCSHIPEDQTY") != null) {
                        tOrder.setNShipedQty(Integer.parseInt(torderList.get(0).get("DCSHIPEDQTY").toString()));// ???
                    }
                    if (torderList.get(0).get("VCORDERNO") != null) {
                        if (tCustomer.getNSecondHandCar() == 0) {

                            tOrder.setVcOrderno(torderList.get(0).get("VCORDERNO").toString() + "*");// ??
                        } else {
                            tOrder.setVcOrderno(torderList.get(0).get("VCORDERNO").toString());// ??
                        }
                    }
                    if (torderList.get(0).get("IPAYID") != null) {
                        tOrder.setNPayType(Integer.parseInt(torderList.get(0).get("IPAYID").toString()));// ?(0
                        // 
                        // 1)
                    }
                    if (torderList.get(0).get("DCPAY") != null) {
                        tOrder.setNTotalPrice(Float.parseFloat(torderList.get(0).get("DCPAY").toString()));// ?
                    }
                    if (tCustomer != null) {
                        tOrder.setICustomerId(tCustomer.getId());// ID
                    }
                    if (torderList.get(0).get("VCCUSTORDERNO") != null) {
                        tOrder.setVcCustOrderNo(torderList.get(0).get("VCCUSTORDERNO").toString());// ??()
                    }
                    if (torderList.get(0).get("DTDATE") != null) {
                        tOrder.setDtCreateDate((Date) torderList.get(0).get("DTDATE"));// 
                    }
                    orderDao.update(tOrder);
                } else {
                    message = "??????";
                }

            } else {
                message = "???";
            }
        } else {
            return "ERP???";
        }
        return message;

    }

    /** 
     * @Description:???? 
     * @param strs
     * @param headId
     * @return
     * @throws IllegalAccessException
     * @throws InvocationTargetException 
     * @author hjx
     * @create_date 2015928 ?4:02:24
     */
    public Map<String, Object> saveAppendLoading(String[] strs, int headId)
            throws IllegalAccessException, InvocationTargetException {
        // TODO Auto-generated method stub
        return null;
    }

}