/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2019-05-07
 * 描述            ：客户付款方式映射表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Slm.ContractManagement.impl;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.ContractManagement.mapper.SlmContractPaymentConfigMapper;
import market.Slm.ContractManagement.service.SlmContractPaymentConfigService;
import market.Slm.ContractManagement.vo.SlmContractPaymentConfig;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="SlmContractPaymentConfigService")
public class SlmContractPaymentConfigServiceImpl extends BaseServiceImpl<SlmContractPaymentConfig,Object> implements SlmContractPaymentConfigService {
	/**
	 * 新增
	 * 
	 * @throws Exception
	 */
	public ResultModel doAddWeb(CommonPage<SlmContractPaymentConfig> sum) 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);
		try {
			List<SlmContractPaymentConfig> list = sum.getObjectList();
			for (SlmContractPaymentConfig config : list) {
				SlmContractPaymentConfig temp = new SlmContractPaymentConfig();
				temp.setCustomer_no(config.getCustomer_no());
				temp.setPlan_no(config.getPlan_no());
				if (this.getMapper(SlmContractPaymentConfigMapper.class).count(temp) > 0) {
					continue;
				}
				config.setCreate_man_name(userId);
				config.setCreate_man_no(userName);
				config.setCreate_time(new Date());
				config.setSeq(UUID.randomUUID().toString());
				this.getMapper(SlmContractPaymentConfigMapper.class).insert(config);
			}
			rm.setState("200");
		} catch (Exception e) {
			throw new Exception("客户付款控制映射新增失败！" + e.getMessage());
		}
		return rm;
	}

	/**
	 * 删除
	 * @throws Exception 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doDeleteWeb(CommonPage<SlmContractPaymentConfig> sum) throws Exception {
		ResultModel rm = new ResultModel();
		try {
			List<SlmContractPaymentConfig> list = sum.getObjectList();
			for (SlmContractPaymentConfig config : list) {
				SlmContractPaymentConfig temp = new SlmContractPaymentConfig();
				temp.setSeq(config.getSeq());
				if (this.getMapper(SlmContractPaymentConfigMapper.class).count(temp) == 0) {
					rm.setState("500");
					rm.setMsgInfo("该数据不存在！");
					return rm;
				}
				this.getMapper(SlmContractPaymentConfigMapper.class).delete(config.getSeq());
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("删除失败！" + e.getMessage());
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 查询
	 */
	public ResultModel doQueryWeb(CommonPage<SlmContractPaymentConfig> sum) {
		ResultModel rm = new ResultModel();
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize();
		PageModel<SlmContractPaymentConfig> pm=new PageModel<>(pageIndex, pageSize);
		try {
			SlmContractPaymentConfig config = sum.getObject();
			List<SlmContractPaymentConfig> list=this.getMapper(SlmContractPaymentConfigMapper.class).find(config, 0, 0);
			int total=this.getMapper(SlmContractPaymentConfigMapper.class).count(config);
			pm.setRows(list);
			pm.setTotal(total);
			rm.setData(pm);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！" + e.getMessage());
		}
		return rm;
	}
}
