0cb922df0ebedc98fc002a94fffd8adc8869f75b.svn-base 3.33 KB
/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.ycsl.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.ycsl.entity.YcslJbxx;
import com.thinkgem.jeesite.modules.ycsl.entity.YcslSj;
import com.thinkgem.jeesite.modules.ycsl.entity.YcslSjcl;
import com.thinkgem.jeesite.modules.reg.web.httprest.httpRestService.HttpactivityService;
import com.thinkgem.jeesite.modules.ycsl.dao.YcslSjDao;
import com.thinkgem.jeesite.modules.ycsl.dao.YcslSjclDao;

/**
 * 一窗受理-收件材料Service
 * @author lzj
 * @version 2020-12-26
 */
@Service
@Transactional(readOnly = true)
public class YcslSjService extends CrudService<YcslSjDao, YcslSj> {
    
	@Autowired
	private YcslSjclDao ycslSjclDao;
	@Lazy
	@Autowired
	private YcslJbxxService ycslJbxxService;
	@Autowired
	private HttpactivityService httpactivityService;
	
	public YcslSj get(String id) {
		YcslSj ycslSj = super.get(id);
		ycslSj.setYcslSjclList(ycslSjclDao.findList(new YcslSjcl(ycslSj)));
		return super.get(id);
	}
	
	public List<YcslSj> findList(YcslSj ycslSj) {
		return super.findList(ycslSj);
	}
	
	public Page<YcslSj> findPage(Page<YcslSj> page, YcslSj ycslSj) {
		return super.findPage(page, ycslSj);
	}
	
	@Transactional(readOnly = false)
	public void save(YcslSj ycslSj) {
		super.save(ycslSj);
		for (YcslSjcl ycslSjcl : ycslSj.getYcslSjclList()){
			if (ycslSjcl.getId() == null){
				continue;
			}
			if (ycslSjcl.DEL_FLAG_NORMAL.equals(ycslSjcl.getDelFlag())){
				if (StringUtils.isBlank(ycslSjcl.getId())){
					ycslSjcl.setSjId(ycslSj);
					ycslSjcl.setProid(ycslSj.getProid());
					ycslSjcl.preInsert();
					ycslSjclDao.insert(ycslSjcl);
				}else{
					ycslSjcl.preUpdate();
					ycslSjclDao.update(ycslSjcl);
				}
			}else{
				ycslSjclDao.delete(ycslSjcl);
			}
		}
	}
	
		public void savesjmain(YcslSj ycslSj) {
			super.save(ycslSj);
		}
		
		public void savesjchild(YcslSjcl ycslSjcl) {
			if (StringUtils.isBlank(ycslSjcl.getId())){
				ycslSjcl.preInsert();
				ycslSjclDao.insertsjcl(ycslSjcl);
			}else{
				ycslSjcl.preUpdate();
				ycslSjclDao.update(ycslSjcl);
			}
		}
		
	@Transactional(readOnly = false)
	public void delete(YcslSj ycslSj) {
		super.delete(ycslSj);
		ycslSjclDao.delete(new YcslSjcl(ycslSj));
	}

	public YcslSj getByProid(String proid) {
		// TODO Auto-generated method stub
		return dao.getByProid(proid);
	}

	@Transactional(readOnly = false)
	public void saveSj(YcslSj ycslSj) {
		YcslJbxx jbxx = ycslJbxxService.get(ycslSj.getProid());
		Map map = Maps.newHashMap();
		if(StringUtils.isNotBlank(jbxx.getZt())) {
			map = ycslJbxxService.getMap(jbxx);
			try {
				Map json = httpactivityService.postRequest(map,"updateSL");
				jbxx.setZt("true");
				ycslJbxxService.save(jbxx);
			} catch (Exception e) {
				jbxx.setZt("false");
				ycslJbxxService.save(jbxx);
				e.printStackTrace();
			}
		}
		save(ycslSj);
	}
	
}