
/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-30
 * 描述            ：质量设计状态主表(合同行/订单行)
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/

package market.Qms.slmord.impl;
import java.util.ArrayList;
import java.util.List;

import market.Com.vo.ResultModel;
import market.Qms.slmord.mapper.SlmOrdDesignMscMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStsTklgMapper;
import market.Qms.slmord.service.SlmOrdDesignStsTklgService;
import market.Qms.slmord.vo.SlmOrdDesignMsc;
import market.Qms.slmord.vo.SlmOrdDesignStsTklg;

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

@RemoteService(path="SlmOrdDesignStsTklgService")
public class SlmOrdDesignStsTklgServiceImpl extends BaseServiceImpl<SlmOrdDesignStsTklg,Object> implements SlmOrdDesignStsTklgService {

	/**
	 * 转换设计结果
	 * @param flag
	 * @return
	 */
	private String ConvertSts(String flag){
		switch(flag){
			case "S":
				return "通过";
			case "F":
				return "失败";
			default:
				return "等待";
		}
	}
	
	/**
	 * 转换评审结果
	 * @param flag
	 * @return
	 */
	private String ConvertResult(String flag){
		switch(flag){
			case "0":
				return "评审中";
			case "1":
				return "评审通过";
			default:
				return "评审失败";
		}
	}
	
	@Override
	public ResultModel GetOrdDesignStsTklgInfo(List<String> list) {
		ResultModel rm=new ResultModel();
		SlmOrdDesignStsTklgMapper mapper=this.getMapper(SlmOrdDesignStsTklgMapper.class);
		SlmOrdDesignMscMapper mscMapper=this.getMapper(SlmOrdDesignMscMapper.class);
		try{
			if(list.size()<1){
				rm.setState("404");
				rm.setMsgInfo("请求数据为空，未找到设计状态数据");
			}else{
				List<SlmOrdDesignStsTklg> listTklg=new ArrayList<>();
				//参数过长一次性请求会报错所以......
				if(list.size()>80){
					int count=list.size()/80+(list.size()%80>0?1:0);
					for(int i=0;i<count;i++){
						String condition=" validflag='1' and CONTRACT_LINE_NO in (";
						for(int index=i*80;index<(i+1)*80;index++){
							try{
								condition+="'"+list.get(index)+"',";
							}catch(Exception ex){
								break;
							}
						}
						condition=condition.substring(0,condition.length()-1)+")";
						List<SlmOrdDesignStsTklg> _listTklg=mapper.findWithCondition(null, condition, "CONTRACT_LINE_NO", 0, 0);
						List<SlmOrdDesignMsc> listMsc=mscMapper.findWithCondition(null, condition, "CONTRACT_LINE_NO", 0, 0);
						for (SlmOrdDesignStsTklg _tklg : _listTklg) {
							for(int index=0;index<listMsc.size();index++){
								if(_tklg.getOrd_ln_pk().equals(listMsc.get(index).getContract_line_no())){
									_tklg.setDesign_result(listMsc.get(index).getDesign_result());
									listMsc.remove(index);
									index--;
								}
							}
						}
						listTklg.addAll(_listTklg);
					}
				}else{
					String condition=" validflag='1' and CONTRACT_LINE_NO in (";
					for (String orderLineNo : list) {
						condition+="'"+orderLineNo+"',";
					}
					condition=condition.substring(0,condition.length()-1)+")";
					listTklg=mapper.findWithCondition(null, condition, "CONTRACT_LINE_NO", 0, 0);
					List<SlmOrdDesignMsc> listMsc=mscMapper.findWithCondition(null, condition, "CONTRACT_LINE_NO", 0, 0);
					for (SlmOrdDesignStsTklg _tklg : listTklg) {
						for(int index=0;index<listMsc.size();index++){
							if(_tklg.getOrd_ln_pk().equals(listMsc.get(index).getContract_line_no())){
								_tklg.setDesign_result(listMsc.get(index).getDesign_result());
								listMsc.remove(index);
								index--;
							}
						}
					}
				}
				for (SlmOrdDesignStsTklg slmOrdDesignStsTklg : listTklg) {
					slmOrdDesignStsTklg.setDesign_sts(ConvertSts(slmOrdDesignStsTklg.getDesign_sts()));
					slmOrdDesignStsTklg.setDesign_result(ConvertResult(slmOrdDesignStsTklg.getDesign_result()));
				}
				rm.setData(listTklg);
				rm.setState("200");
			}
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("获取设计状态数据出错："+ex.getMessage());
		}
		return rm;
	}
}
