/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-09-04
 * 描述            ：采购单评标人员清单
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Pms.Quote.impl;
import java.util.Date;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Pms.Quote.mapper.PurPurchaseFMapper;
import market.Pms.Quote.mapper.PurPurchaseMMapper;
import market.Pms.Quote.service.PurPurchaseFService;
import market.Pms.Quote.vo.PurPurchaseF;
import market.Pms.Quote.vo.PurPurchaseM;

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

@RemoteService(path="PurPurchaseFService")
public class PurPurchaseFServiceImpl extends BaseServiceImpl<PurPurchaseF,Object> implements PurPurchaseFService {
	/**
	 *评标人信息查询
	 * 
	 * @param oci
	 * @return
	 */
	public ResultModel doQueryWeb(CommonPage<PurPurchaseF> oci) {
		ResultModel rm = new ResultModel();
		PurPurchaseF ppf = oci.getObject();
		PurPurchaseF ppf2=new PurPurchaseF();
		ppf2.setPurchase_no(ppf.getPurchase_no());
		try {
			List<PurPurchaseF> list = this.getMapper(PurPurchaseFMapper.class)
					.find(ppf2, 0, 0);
			rm.setData(list);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败，请联系管理员");
			throw ex;
		}
		return rm;
	}
	/**
	 *评标人信息新增
	 * 
	 * @param oci
	 * @return
	 * @throws Exception 
	 */
	public ResultModel doAddWeb(CommonPage<PurPurchaseF> oci) throws Exception {
		ResultModel rm = new ResultModel();
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		List<PurPurchaseF> ppflist = oci.getObjectList();
		String purchase_no=oci.getMemo1();
		String bid_no=oci.getMemo2();
		User user2=this.getMapper(UserMapper.class).findById(userId);
		try {
			PurPurchaseM ppm = this.getMapper(PurPurchaseMMapper.class)
					.findById(purchase_no);// 查询采购单号，并判断状态
			//采购单为草稿状态下，并且未提报评审可操作
			if ("10".equals(ppm.getValidflag()) || "00".equals(ppm.getStatus())) {
			for (PurPurchaseF ppf : ppflist) {
				ppf.setDept_code(user2.getDept_id());//设置部门
				ppf.setDept_desc(user2.getDept_name());
				ppf.setPurchase_no(purchase_no);//采购单号
				ppf.setBid_no(bid_no);//标段号
				ppf.setCreate_userid(userId);
				ppf.setCreate_name(userName);
				ppf.setCreate_time(new Date());
				PurPurchaseF ppf2=new PurPurchaseF();
				ppf2.setPurchase_no(purchase_no);//采购单号
				ppf2.setBid_no(bid_no);//标段号
				ppf2.setEva_user_id(ppf.getEva_user_id()); // 评标人ID
				ppf2.setEva_user_name(ppf.getEva_user_name()); // 评标人
				int  count=this.getMapper(PurPurchaseFMapper.class).countWithCondition(ppf2, null);
				if(count!=0){
					throw new Exception("当前评标人["+ppf.getEva_user_name()+"]已存在当前评标标准");
				}
				this.getMapper(PurPurchaseFMapper.class).insert(ppf);			
			}
			rm.setMsgInfo("新增成功");
			rm.setState("200");
			} else {
				rm.setState("500");
				rm.setMsgInfo("当前数据状态不可新增");
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("新增失败，请联系管理员");
//			throw ex;
			throw new Exception(ex.getMessage());
		}
		return rm;
	}
	/**
	 *评标人信息删除
	 * 
	 * @param oci
	 * @return
	 */
	public ResultModel doDeleteWeb(CommonPage<PurPurchaseF> oci) {
		ResultModel rm = new ResultModel();
		List<PurPurchaseF> ppflist = oci.getObjectList();
		try {
			PurPurchaseM ppm = this.getMapper(PurPurchaseMMapper.class)
					.findById(ppflist.get(0).getPurchase_no());// 查询采购单号，并判断状态
			//采购单为草稿状态下，并且未提报评审可操作
			if ("10".equals(ppm.getValidflag()) || "00".equals(ppm.getStatus())) {
			for (PurPurchaseF ppf : ppflist) {
				this.getMapper(PurPurchaseFMapper.class).deletePurPurchaseF(ppf);			
			}
			rm.setState("200");
			rm.setMsgInfo("删除成功！");
			} else {
				rm.setState("500");
				rm.setMsgInfo("当前数据状态不可删除");
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("删除失败，请联系管理员");
			throw ex;
		}
		return rm;
	}
}
