/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-09-12
 * 描述            ：异议单表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Pms.Settlement.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Pms.Settlement.mapper.PurExceptionMMapper;
import market.Pms.Settlement.mapper.PurInterfaceInbillMapper;
import market.Pms.Settlement.mapper.PurInterfaceInspectMapper;
import market.Pms.Settlement.mapper.PurInterfaceMeasureMapper;
import market.Pms.Settlement.service.PurExceptionMService;
import market.Pms.Settlement.vo.PurExceptionM;
import market.Pms.Settlement.vo.PurInterfaceInbill;
import market.Pms.Settlement.vo.PurInterfaceInbillMeasure;
import market.Pms.Settlement.vo.PurInterfaceInspect;
import market.Pms.Settlement.vo.PurInterfaceMeasure;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="PurExceptionMService")
public class PurExceptionMServiceImpl extends BaseServiceImpl<PurExceptionM,Object> implements PurExceptionMService {
	/**
	 * 异议单信息查询
	 * 
	 * @param oci
	 * @return
	 */
	public ResultModel doQueryWeb(CommonPage<PurExceptionM> oci){
		ResultModel rm=new ResultModel();
		PurExceptionM  pem=oci.getObject();
		String startTime = oci.getStartTime();
		String endTime = oci.getEndTime();
		String memo1 = oci.getMemo1(); //00：申请界面；10：受理界面：11审批界面
		try {
			String swhere="1=1";
			if (memo1 != null && !"".equals(memo1)) { 
				swhere +=" and validflag > '"+memo1+"' "; 
			}
			if(pem.getException_no()!=null&&!"".equals(pem.getException_no())){
				swhere+=" and  EXCEPTION_NO  like  '%"+pem.getException_no()+"%'";
			}//异议编号
			if(pem.getValidflag()!=null&&!"".equals(pem.getValidflag())){
				swhere+=" and  Validflag  like '%"+pem.getValidflag()+"%'";
			}//数据状态
			if(pem.getStatus()!=null&&!"".equals(pem.getStatus())){
				swhere+=" and  status  like '%"+pem.getStatus()+"%'";
			}//评审状态
			if(pem.getExcep_type_name()!=null&&!"".equals(pem.getExcep_type_name())){
				swhere+=" and  excep_type_name  like '%"+pem.getExcep_type_name()+"%'";
			}//异常类型
			if(pem.getExcep_type_code()!=null&&!"".equals(pem.getExcep_type_code())){
				swhere+=" and  excep_type_code  like '%"+pem.getExcep_type_code()+"%'";
			}//异常类型代码
			if (startTime != null && !"".equals(startTime)) {
				swhere += " and to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') >='"
						+ startTime +" 00:00:00"+ "'";
			}
			if (endTime != null && !"".equals(endTime)) {
				swhere += " and to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') <= '"
						+ endTime +" 23:59:59"+ "'";
			}
			if (!swhere.contains("Validflag")) {
				swhere+=" and  Validflag  > '00'";
			}
			List<PurExceptionM>  list=this.getMapper(PurExceptionMMapper.class).
					findWithCondition(null, swhere, "create_time desc ", 0, 0);
			rm.setData(list);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("错误：" + ex.getMessage());
		}
		return rm;
		
	}
	
	/***
	 * 
	 * @author 赵淋支
	 * @date   2018年10月11日
	 * @parameter memo1:(1,'入库单';2,'计量单';3,'检验单') 
	 *     PurInterfaceInbillMeasure：
	 * @return 
	 * @description 创建异议单
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public  ResultModel addPurExceptionM(CommonPage<PurInterfaceInbillMeasure> oci) throws Exception{
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		ResultModel rm=new ResultModel();
		PurInterfaceInbillMeasure  pifim=oci.getObject();
		String  flag=oci.getMemo1();
		if (pifim==null || pifim.getInstock_no()==null) {
			rm.setState("500");
			rm.setMsgInfo("请选择数据！");
			return rm;
		}
		try 
		{
			PurExceptionM pem=new PurExceptionM();
			String exception_no = "YY"
					+ new SimpleDateFormat("yyyyMMdd").format(new Date());
			String maxD = this.getMapper(PurExceptionMMapper.class)
					.findExceptionNO(exception_no);
			if (maxD != null && maxD.length() > 4) {
				String seq = maxD.substring(maxD.length() - 4);
				int iseq = Integer.parseInt(seq) + 1;
				exception_no+= String.format("%04d", iseq);
			} else {
				exception_no+= "0001";
			}
			Date now=new Date(); 
			pem.setException_no(exception_no);//异议单号
			//界面编辑的字段
			pem.setExcep_qty(pifim.getExcep_qty());//异议数量
			pem.setExcep_type_desc(pifim.getExcep_type_desc());//异议描述
			pem.setExcep_type_code(pifim.getExcep_type_code());//6031 异议类型
			pem.setExcep_type_name(pifim.getExcep_type_name());
			pem.setApply_mark(pifim.getApply_mark());//异议申请备注
			//pem.setExcep_with_tax_amt(pifim.getRefe_with_tax_amt());//异议含税金额
			//pem.setExcep_with_tax_price(pifim.getRefe_with_tax_price());//异议含税单价
			 
			//创建人信息
			pem.setCreate_name(userName);
			pem.setCreate_userid(userId);
			pem.setCreate_time(now);
			//状态
			pem.setValidflag("10");//默认草稿
			pem.setStatus("00");//默认待提报
			
		if(flag != null && !"".equals(flag)){
			if("1".equals(flag)){ //入库单
				String instock_no=pifim.getInstock_no();//入库单号
				PurInterfaceInbill  pifib=this.getMapper(PurInterfaceInbillMapper.class).findById(instock_no);
				if (pifib != null) {
					pem.setOrder_pk(pifib.getOrder_pk());
					pem.setOrder_no(pifib.getOrder_no());//订单号
					pem.setContract_pk(pifib.getContract_pk());//合同号主键
					pem.setContract_no(pifib.getContract_no());//合同号
					pem.setRefe_no(pifib.getInstock_no());//参考单号为入库单号
					pem.setSupp_code(pifib.getSupp_code());//供应商代码
					pem.setSupp_name(pifib.getSupp_name());//供应商
					//加入物料信息
					pem.setMat_class_code(pifib.getMat_class_code());//物料分类
					pem.setMat_class_name(pifib.getMat_class_name());
					pem.setItem_code(pifib.getItem_code());//物料编码
					pem.setItem_name(pifib.getItem_name());
					pem.setItem_desc(pifib.getItem_desc());//物料描述
					pem.setItem_desc_e(pifib.getItem_desc_e());
					pem.setItem_idx(pifib.getItem_idx());
					pem.setStandards_code(pifib.getStandards_code());//标准代码
					pem.setStandards_name(pifib.getStandards_name());
					pem.setSpec_name(pifib.getSpec_name());//规格
					pem.setSteel_code(pifib.getSteel_code());//钢种牌号
					pem.setSteel_name(pifib.getSteel_name());
					pem.setAttr_code(pifib.getAttr_code());//属性
					pem.setAttr_name(pifib.getAttr_name());
					pem.setDelivery_state_code(pifib.getDelivery_state_code());//交货状态
					pem.setDelivery_state_name(pifib.getDelivery_state_name());			
					pem.setRefe_time(pifib.getCreate_time());//参考单日期
					pem.setRefe_qty(pifib.getIn_num());//参考单数量
					pem.setRefe_with_tax_price(pifib.getBug_price());//参考单含税单价 (预算价)
	                pem.setRefe_with_tax_amt(pifib.getPrimary_amount());;//参考单含税金额(原币金额)
					//修改入库接口的数据
					pifib.setValidflag("20");//设置成“结算锁定”
					this.getMapper(PurInterfaceInbillMapper.class).update(pifib);
				}  
                pem.setRefe_type_code("603001");//参考单类别
                pem.setRefe_type_name("入库单");//参考单名称 
                this.getMapper(PurExceptionMMapper.class).insert(pem);
			}			
			if("2".equals(flag)){ //计量单
				String measure_no=pifim.getMeasure_no();//计量单号
				PurInterfaceMeasure pifm=this.getMapper(PurInterfaceMeasureMapper.class).findById(measure_no);
				if (pifm != null) {
					pem.setContract_no(pifm.getContract_no());//合同号
					pem.setContract_pk(pifm.getContract_pk());//合同号主键
					pem.setOrder_no(pifm.getOrder_no());//订单号
					pem.setOrder_pk(pifm.getOrder_pk()); 
				}
				pem.setRefe_type_code("603002");//参考单类别
				pem.setRefe_type_name("计量单");//参考单名称
				pem.setRefe_no(pifm.getMeasure_no());//参考单号为计量单号
				pem.setUom_name(pifm.getItem_uom());//计量单位
				pem.setRefe_qty(pifm.getNet_weight());//参考单数量
				pem.setRefe_time(pifm.getMeasure_date());//计量时间
				pem.setRefe_with_tax_price(pifim.getRefe_with_tax_price());//结算含税单价        
	            pem.setRefe_with_tax_amt(pifim.getRefe_with_tax_amt());;//含税总额	               
				this.getMapper(PurExceptionMMapper.class).insert(pem); 
			}
			if("3".equals(flag)){//检验单
				String inspect_no=pifim.getInspect_no();//检验单号
				PurInterfaceInspect pii=this.getMapper(PurInterfaceInspectMapper.class).findById(inspect_no);
				if (pii != null) {
					pem.setContract_no(pii.getContract_no());//合同号
					pem.setContract_pk(pii.getContract_pk());//合同号主键
					pem.setOrder_no(pii.getOrder_no());//订单号
					pem.setOrder_pk(pii.getOrder_pk());	
					pem.setSupp_code(pii.getSupp_code());//供应商代码
					pem.setSupp_name(pii.getSupp_name());//供应商
					//加入物料信息
					pem.setMat_class_code(pii.getMat_class_code());//物料分类
					pem.setMat_class_name(pii.getMat_class_name());
					pem.setItem_code(pii.getItem_code());//物料编码
					pem.setItem_name(pii.getItem_name());
					pem.setItem_desc(pii.getItem_desc());
					pem.setItem_idx(pii.getItem_idx());
					pem.setStandards_code(pii.getStandards_code());//标准代码
					pem.setStandards_name(pii.getStandards_name());
					pem.setSpec_name(pii.getSpec_name());//规格
					pem.setSteel_code(pii.getSteel_code());//钢种牌号
					pem.setSteel_name(pii.getSteel_name());
					pem.setAttr_code(pii.getAttr_code());//属性
					pem.setAttr_name(pii.getAttr_name());
					pem.setDelivery_state_code(pii.getDelivery_state_code());//交货状态
					pem.setDelivery_state_name(pii.getDelivery_state_name());
				} 
                pem.setRefe_type_code("603003");//参考单类别
                pem.setRefe_type_name("检验单");//参考单名称
    			pem.setRefe_no(pii.getInspect_no());//检验单号为入库单号
    			pem.setRefe_qty(pii.getAdd_subt_qty());//参考单数量
				pem.setRefe_with_tax_amt(pii.getAdd_subt_value());//参考单税额
				pem.setRefe_time(pii.getInspect_date());//参考单日期
				this.getMapper(PurExceptionMMapper.class).insert(pem);
			}
		}
		    rm.setState("200");
		   rm.setMsgInfo("新增成功！");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("创建异议单失败:"+ex.getMessage()); 
		}
		return rm; 
	}
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年10月11日
	 * @parameter List<PurExceptionM>:applyRenark:申请备注；exceptionNo:Id
	 * @return 
	 * @description 异议申请
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel applyPurExceptionM(CommonPage<PurExceptionM> oci)
			throws Exception {
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		String deptId = (String) this.getSession().getAttribute(
				HomeService.SESSION_DEPT_ID);
		String deptName = (String) this.getSession().getAttribute(
				HomeService.SESSION_DEPT_NAME);
		ResultModel rm = new ResultModel();
		if (oci.getObjectList() == null || oci.getObjectList().size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请选择数据！");
			return rm;
		}
		try {
			Date now=new Date();
			for (PurExceptionM ppm : oci.getObjectList()) {
				PurExceptionM ppm2=this.getMapper(PurExceptionMMapper.class).findById(ppm.getException_no());				 
				if (ppm2!=null && "10".equals(ppm2.getValidflag()) && 
				("00".equals(ppm2.getStatus()) || "40".equals(ppm2.getStatus()))) {
					ppm2.setApply_name(userName);//申请人
					ppm2.setApply_userid(userId);
					ppm2.setApply_unit_code(deptId);//申请单位
					ppm2.setApply_unit_desc(deptName);
					ppm2.setApply_time(now);//申请时间
					ppm2.setApply_mark(ppm.getApply_mark());//申请备注 
					ppm2.setValidflag("11"); // 申请状态
					
					ppm2.setUpdate_userid(userId);
					ppm2.setUpdate_name(userName);
					ppm2.setUpdate_time(now);
					this.getMapper(PurExceptionMMapper.class).update(ppm2);
				}else {
					rm.setState("500");
					rm.setMsgInfo("当前数据不能申请！");
					return rm;
				}
			}
			//TODO  设计上的？等待确认
			//2、UPDATE PUR_PURCHASE_M SET STATUS='10' WHERE PURCHASE_NO =?；
			//UPDATEUE PUR_PURCHASE_C SET STATUS='10' WHERE PURCHASE_NO=? ;
			//刷新操作的数据并定位。
			rm.setState("200");
			rm.setMsgInfo("申请成功！");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("申请失败:"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年10月11日
	 * @parameter List<PurExceptionM> exceptionNo:主键
	 * @return 
	 * @description 撤销异议申请
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel disApplyPurExceptionM(CommonPage<PurExceptionM> oci)
			throws Exception {
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		ResultModel rm = new ResultModel();
		if (oci.getObjectList() == null || oci.getObjectList().size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请选择数据！");
			return rm;
		}
		try {
			for (PurExceptionM ppm : oci.getObjectList()) {
				PurExceptionM ppm2=this.getMapper(PurExceptionMMapper.class).findById(ppm.getException_no());			
				if (ppm2!=null && "11".equals(ppm2.getValidflag())
				&& ("00".equals(ppm2.getStatus()) || "40".equals(ppm2.getStatus()))) {
					ppm2.setApply_name("");//申请人
					ppm2.setApply_userid("");
					ppm2.setApply_unit_code("");//申请单位
					ppm2.setApply_unit_desc("");
					//ppm2.setApply_time(null);//申请时间
					ppm2.setApply_mark("");//申请备注
					
					ppm2.setValidflag("10"); // 置为草稿状态
					
					ppm2.setUpdate_userid(userId);
					ppm2.setUpdate_name(userName);
					ppm2.setUpdate_time(new Date());
					this.getMapper(PurExceptionMMapper.class).update(ppm2); 
				} else {
					rm.setState("500");
					rm.setMsgInfo("当前数据不能撤销申请！");
					return rm;
				}
			}

			rm.setState("200");
			rm.setMsgInfo("申请撤销成功！");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("申请撤销失败:"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年10月11日
	 * @parameter List<PurExceptionM> exceptionNo:主键
	 * @return 
	 * @description 删除异议申请
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel deletePurExceptionM(CommonPage<PurExceptionM> oci)
			throws Exception {
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		ResultModel rm = new ResultModel();
		if (oci.getObjectList() == null || oci.getObjectList().size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请选择数据！");
			return rm;
		}
		try {
			for (PurExceptionM ppm : oci.getObjectList()) {
				PurExceptionM ppm2=this.getMapper(PurExceptionMMapper.class).findById(ppm.getException_no());				 
				if (ppm2!=null && "10".equals(ppm2.getValidflag())
				&& ("00".equals(ppm2.getStatus()) || "40".equals(ppm2.getStatus()))) {
					ppm2.setApply_name("");//申请人
					ppm2.setApply_userid("");
					ppm2.setApply_unit_code("");//申请单位
					ppm2.setApply_unit_desc("");
					//ppm2.setApply_time(null);//申请时间
					ppm2.setApply_mark("");//申请备注
					
					ppm2.setValidflag("00"); //无效状态
					
					ppm2.setUpdate_userid(userId);
					ppm2.setUpdate_name(userName);
					ppm2.setUpdate_time(new Date());
					this.getMapper(PurExceptionMMapper.class).update(ppm2);
					
					if ("603001".equals(ppm2.getRefe_type_code())) {
						PurInterfaceInbill pii = this.getMapper(PurInterfaceInbillMapper.class).findById(ppm2.getRefe_no());
						if (pii!=null) {
							pii.setValidflag("00");
							this.getMapper(PurInterfaceInbillMapper.class).update(pii);
						}
					}
				}else {
					rm.setState("500");
					rm.setMsgInfo("当前数据不能删除！");
					return rm;
				}
			}

			rm.setState("200");
			rm.setMsgInfo("删除成功！");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("删除异议申请失败:"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年10月12日
	 * @parameter List<PurExceptionM> exceptionNo:主键，受理备注，必填(异议单价,处置方式)
	 * @return 
	 * @description 异议单信息提报
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel upPurExceptionM(CommonPage<PurExceptionM> oci)
			throws Exception {
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		String deptId = (String) this.getSession().getAttribute(
				HomeService.SESSION_DEPT_ID);
		String deptName = (String) this.getSession().getAttribute(
				HomeService.SESSION_DEPT_NAME);
		ResultModel rm = new ResultModel();
		if (oci.getObjectList() == null || oci.getObjectList().size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请选择数据！");
			return rm;
		}
		try {
			Date now = new Date();
			for (PurExceptionM ppm : oci.getObjectList()) {
				PurExceptionM ppm2=this.getMapper(PurExceptionMMapper.class).findById(ppm.getException_no());							
				
				if (ppm2!=null && "11".equals(ppm2.getValidflag())
			&& ("00".equals(ppm2.getStatus()) || "40".equals(ppm2.getStatus()))) {								
					//受理人信息
					ppm2.setAccep_name(userName);
					ppm2.setAccept_userid(userId);
					ppm2.setAccep_unit_code(deptId);
					ppm2.setAccep_unit_desc(deptName);
					ppm2.setAccep_time(now);
					ppm2.setAccep_mark(ppm.getAccep_mark());//异议受理备注
					//受理编辑
					ppm2.setExcep_qty(ppm.getExcep_qty());//异议数量
					ppm2.setExcep_with_tax_price(ppm.getExcep_with_tax_price());//异议含税单价
					//含税金额计算
					BigDecimal bd = new BigDecimal(ppm.getExcep_with_tax_price()*ppm2.getExcep_qty());
					double tax_amt =  bd.setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue();
					ppm2.setExcep_with_tax_amt(tax_amt);//异议含税金额
					
					ppm2.setHandle_type_code(ppm.getHandle_type_code());//异议处置方式代码
					ppm2.setHandle_type_name(ppm.getHandle_type_name());//异议处置方式
					
					ppm2.setValidflag("12"); // 受理状态
					ppm2.setStatus("10");//待审批状态
					ppm2.setUpdate_userid(userId);
					ppm2.setUpdate_name(userName);
					ppm2.setUpdate_time(now);
					this.getMapper(PurExceptionMMapper.class).update(ppm2);
				}else {
					rm.setState("500");
					rm.setMsgInfo("当前数据不能提报！");
					return rm;
				}
			}

			rm.setState("200");
			rm.setMsgInfo("提报成功！");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("提报失败:"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年10月12日
	 * @parameter List<PurExceptionM> exceptionNo:主键
	 * @return 
	 * @description 异议提报撤销
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel disPurExceptionM(CommonPage<PurExceptionM> oci)
			throws Exception {
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		ResultModel rm = new ResultModel();
		if (oci.getObjectList() == null || oci.getObjectList().size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请选择数据！");
			return rm;
		}
		try {
			Date now =new Date();
			for (PurExceptionM ppm : oci.getObjectList()) {
				PurExceptionM ppm2=this.getMapper(PurExceptionMMapper.class).findById(ppm.getException_no());
				if (ppm2!=null && "12".equals(ppm2.getValidflag())
				&& ("10".equals(ppm2.getStatus()) || "40".equals(ppm2.getStatus()))) {	
					//受理人信息清除
					ppm2.setAccep_name("");
					ppm2.setAccept_userid("");
					ppm2.setAccep_unit_code("");
					ppm2.setAccep_unit_desc("");
					//ppm2.setAccep_time(now);
					ppm2.setAccep_mark("");//异议受理备注
					ppm2.setExcep_with_tax_price(0.0);//异议含税单价					
					ppm2.setExcep_with_tax_amt(0.0);//异议含税金额
					
					ppm2.setHandle_type_code("");//异议处置方式
					ppm2.setHandle_type_name("");
								
					ppm2.setValidflag("11"); // 置为申请状态
					ppm2.setStatus("00");//待提报状态
					
					ppm2.setUpdate_userid(userId);
					ppm2.setUpdate_name(userName);
					ppm2.setUpdate_time(now);
					this.getMapper(PurExceptionMMapper.class).update(ppm2);
					
				} else {
					rm.setState("500");
					rm.setMsgInfo("当前数据不能撤销提报！");
					return rm;
				}
			}

			rm.setState("200");
			rm.setMsgInfo("异议提报撤销成功！");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("异议提报撤销失败:"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年10月12日
	 * @parameter List<PurExceptionM> exceptionNo:主键 memo1:(1审批通过 2审批退回 3审批拒绝)
	 * @return 
	 * @description 异议审批操作(通过，退回，拒绝)
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel appPurExceptionM(CommonPage<PurExceptionM> oci)
			throws Exception {
		String userId = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(
				HomeService.SESSION_USER_NAME);
		ResultModel rm = new ResultModel();
		if (oci.getObjectList() == null || oci.getObjectList().size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请选择数据！");
			return rm;
		}
		String memo1=oci.getMemo1();
		if(memo1==null || "".equals(memo1)){
			rm.setState("500");
			rm.setMsgInfo("请选择操作！");
			return rm;
		}
		try {
			Date now =new Date();
			for (PurExceptionM ppm2 : oci.getObjectList()) {
				PurExceptionM pdm=this.getMapper(PurExceptionMMapper.class).findById(ppm2.getException_no());
				pdm.setRemark(ppm2.getRemark());
				if (pdm!=null && "12".equals(pdm.getValidflag())
						&& "10".equals(pdm.getStatus())) {//受理+待审批
					if ("1".equals(memo1)) { // 审批通过
						pdm.setStatus("50"); 
						pdm.setValidflag("20");// 暂时生效
						pdm.setUpdate_userid(userId);
						pdm.setUpdate_name(userName);
						pdm.setUpdate_time(now);
						this.getMapper(PurExceptionMMapper.class).update(pdm);
					}
					if("2".equals(memo1)){ //审批退回
						pdm.setStatus("40"); 
						pdm.setUpdate_userid(userId);
						pdm.setUpdate_name(userName);
						pdm.setUpdate_time(now);
						this.getMapper(PurExceptionMMapper.class).update(pdm);						
					}
					 if("3".equals(memo1)){ //审批拒绝
						pdm.setStatus("30"); 
						pdm.setUpdate_userid(userId);
						pdm.setUpdate_name(userName);
						pdm.setUpdate_time(now);
						this.getMapper(PurExceptionMMapper.class).update(pdm);						
				    }
				} else {
					rm.setState("500");
					rm.setMsgInfo("数据状态不为待审批，请刷新界面！");
					return rm;
				}
			}

			rm.setState("200");
			rm.setMsgInfo("审批成功！");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("审批失败:"+ex.getMessage());
		}
		return rm;
	}
}
