LjzController.java 4.1 KB
package com.thinkgem.jeesite.modules.title.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseC;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseH;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseLjz;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZrz;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseCService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseHService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseLjzService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseZrzService;

@Controller
@RequestMapping(value = "${adminPath}/title/web/ljzController")
public class LjzController {
	 protected Logger logger = Logger.getLogger(getClass());
		
	@Autowired
	private RegBaseZrzService regBaseZrzService;
	@Autowired
	private RegBaseHService hService;
	@Autowired
	private RegBaseCService cService;
	@Autowired
	private RegBaseLjzService ljzService;
	
	@RequiresPermissions("title:web:titleController:view")
	@RequestMapping(value = "Ljz")
	@ResponseBody
    public ModelMap getZrz(HttpServletRequest request, HttpServletResponse response, Model model) {
	    ModelMap modelmap = new ModelMap();
		List<RegBaseZrz> zrzList = new ArrayList<RegBaseZrz>();
	    RegBaseZrz regBaseZrz = new RegBaseZrz();
	    if(StringUtils.isNotBlank(request.getParameter("zddm"))){
	    	regBaseZrz.setZddm(request.getParameter("zddm"));
	    }
	    	zrzList = regBaseZrzService.findList(regBaseZrz);
	    	if(zrzList.size()>0) {
	    		for(int i=0;i<zrzList.size();i++) {
	    		    RegBaseH h = new RegBaseH();
	    		    h.setBdcdyh(zrzList.get(i).getBdcdyh().substring(0, 24));
	    		    h.setZddm(zrzList.get(i).getZddm());
	    		    List<RegBaseH> hlist = hService.findList(h);
	    		    if(hlist.size()>0) {
	    		    	Double scjzmj = 0.0;
	    		    	for(int j=0;j<hlist.size();j++) {
	    		    		h = hlist.get(j);
	    		    		RegBaseLjz ljz = new RegBaseLjz();
	    		    		ljz.setFwyt1(h.getFwyt1());
	    		    		ljz.setZrzh(h.getZrzh());
	    		    		List<RegBaseLjz> ljzlist = ljzService.findList(ljz);
	    		    		if(ljzlist.size()>0) {
	    		    			ljz = ljzlist.get(0);
	    		    			RegBaseC c = cService.get(h.getCid());
	    		    			if(StringUtils.isBlank(c.getLjzh())) {
	    		    				c.setZrzh(h.getZrzh());
	    		    				c.setLjzh(ljzlist.get(0).getLjzh());
	    		    				   ljz.setZcs(Integer.parseInt(ljz.getZcs())+1+"");
	    		    				if(c.getIsnegativelayer().equals("0")) {
	    		    				  ljz.setDscs(Integer.parseInt(ljz.getDscs())+1+"");
	    		    				}else {
	    		    					ljz.setDscs(Integer.parseInt(ljz.getDxcs())+1+"");
	    		    				}
	    		    			}
	    		    			cService.save(c);
	    		    			ljzService.save(ljz);
	    		    		}else {
	    		    			scjzmj = scjzmj + h.getScjzmj();
	    		    			ljz.setLjzh(h.getBdcdyh().substring(4, 24).replace("F", "")+nextZh(h.getZrzh()));
	    		    			logger.debug(ljz.getLjzh());
	    		    			ljz.setJgrq(zrzList.get(i).getJgrq());
	    		    			ljz.setYtmc(h.getFwyt1());
	    		    			ljz.setZcs("0");
	    		    			ljz.setDscs("0");
	    		    			ljz.setDxcs("0");
	    		    			ljzService.save(ljz);
	    		    		}
	    		    	}
	    		    }
	    		    
	    		}
	    	}
	    	return modelmap;
	    }

	private String nextZh(String zrzh) {
		String maxZh = ljzService.MaxZh(zrzh);
		int ljzh = 1;
		String zh ="01";
		if(StringUtils.isNotBlank(maxZh) ) {
			ljzh = Integer.parseInt(maxZh)+1;
		}else {
			ljzh = ljzh;
		}
		if(ljzh <10) {
			zh = "0"+ljzh;
		}else {
			zh = ljzh+"";
		}
		return zh;
	}
	
}