/***文档注释***********************************************
 * 作者               :                  
 * 创建日期      :                   2019.02.24
 * 描述               :                   物流和质量模块调用的公共接口
 * 注意事项      :                    无
 * 遗留BUG :                     无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/

package market.Api.Lms.impl;

import java.text.SimpleDateFormat;
import java.util.List;

import market.Api.Lms.service.LmsSlmApiService;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Logistics.mapper.SpmDeliveryMapper;
import market.Lms.Logistics.mapper.SpmTransportDetailMapper;
import market.Lms.Logistics.vo.SpmDelivery;
import market.Lms.Logistics.vo.SpmTransportDetail;
import market.Lms.Warehouse.mapper.YdmProductOutlistMapper;
import market.Lms.Warehouse.vo.YdmProductOutlist;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;
import com.hnshituo.core.auth.service.HomeService;

@RemoteService(path="LmsSlmApiService")
public class LmsSlmApiServiceImpl extends BaseServiceImpl<Object,Object> implements LmsSlmApiService {
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2019年2月24日
	 * @parameter [{"objectList":[{"deliveryno":"Y20190408****"}],"startTime":"装车时间，到秒"}]
	 * @return 200 ✔  500✘
	 * @description 修改提货单的装车时间
	 */
	public ResultModel doUpdateLoadTime(CommonPage<SpmDelivery> cp) throws Exception {
		ResultModel rm = new ResultModel();
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list = cp.getObjectList();
		String loadTime = cp.getStartTime();//装车时间
		if (list==null || list.size() <= 0) {
			rm.setState("500");
			rm.setMsgInfo("传入的参数为空");
			return rm;
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for (SpmDelivery sp : list) {
			if (sp.getDeliveryno()!=null && !"".equals(sp.getDeliveryno())) {
				SpmDelivery sd = this.getMapper(SpmDeliveryMapper.class).findById(sp.getDeliveryno());
				if (sd!=null){
					if ("3".equals(sd.getState())||"4".equals(sd.getState())||
							"5".equals(sd.getState())||"6".equals(sd.getState())) {						
						SpmTransportDetail std = new SpmTransportDetail();
						std.setBillNo(sd.getDeliveryno());
						List<SpmTransportDetail> stdList = this.getMapper(SpmTransportDetailMapper.class).find(std, 0, 0);
						if (stdList!=null && stdList.size() > 0) {
							for (SpmTransportDetail STD : stdList) {
								//1.修改装车时间
								STD.setLoaddate(sdf.parse(loadTime));
								STD.setLoadoperator(username);
								this.getMapper(SpmTransportDetailMapper.class).doUpdate(STD);
								//2.修改出库时间
								YdmProductOutlist ypo = new YdmProductOutlist();
								ypo.setStorageattr(STD.getStorageattr());
								ypo.setCoilno(STD.getObjectno());
								List<YdmProductOutlist> ypoList = this.getMapper(YdmProductOutlistMapper.class).find(ypo, 0, 0);
								if (ypoList!=null && ypoList.size()>0) {
									ypo = ypoList.get(0);
									ypo.setOutdate(sdf.parse(loadTime));
									ypo.setOutoperator(username);
									this.getMapper(YdmProductOutlistMapper.class).update(ypo);
								}
								//3.修改库存历史记录数据
								this.getMapper(YdmProductOutlistMapper.class).doDeleteYpdHistory(STD.getObjectno(),STD.getStorageattr(),loadTime);
							}
						}
					}
				}
			}
		}
		rm.setState("200");
		rm.setMsgInfo("修改装车时间成功");
		return rm;
	}
		
	
}

