285154c6364401301d5246a81c89b3e44c3d1431.svn-base 8.79 KB
package com.thinkgem.jeesite.modules.reg.service.pjxt;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;

import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.reg.dao.ywpjxt.YwpjDao;
import com.thinkgem.jeesite.modules.reg.entity.ywpjxt.Ywpj;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

/**
 * 评价系统service
 * @author Administrator
 *
 */

@Service
@Transactional(readOnly=true)
public class YwpjService extends CrudService<YwpjDao, Ywpj>  {
	
	/**
	 * 新增评价信息
	 * @param ywpj
	 * @return
	 */
	public int addYwpj(Ywpj ywpj){
		return dao.addYwpj(ywpj);
	}

	/**
	 * 更新待评价业务状态
	 * @param ywh
	 * @return
	 */
	public int updatePjslzt(Map map){
		return dao.updatePjslzt(map);
	}
	
	/**
	 * 通过业务号获取ywpj防止重复添加
	 * @param ywh
	 * @return
	 */
	public String getYwpjIdByYwh(String ywh){
		return dao.getYwpjIdByYwh(ywh);
	}
	
	/**
	 * 更新评价分数
	 * @param ywpj
	 * @return
	 */
	public int updatePjmycd(Ywpj ywpj){
		return dao.updatePjmycd(ywpj);
	}
	
	/**
	 * 获取所有UserId
	 * @return
	 */
	public List<String> getAllUserId(){
		return dao.getAllUserId();
	}
	
	/**
	 * 获取评价分数
	 * @param ywpjMap
	 * @return
	 */
	public int getPjfsByUserId(Map ywpjMap){
		return dao.getPjfsByUserId(ywpjMap);
	}
	
	/**
	 * 获取ywpjList
	 */
	public List<Ywpj> findList(Ywpj ywpj){
		return dao.findList(ywpj);
	}
	
	public Model getYwpjtj(HttpServletRequest request, HttpServletResponse response, Model model){
		String qssj1 = request.getParameter("StartDate");
		System.out.println(qssj1);
		qssj1 = qssj1.substring(0, 4) + qssj1.substring(5, 7);
		System.out.println(qssj1);
		String qssj = qssj1.substring(0, 4)+" 年 "+qssj1.substring(4, 6)+" 月";
		System.out.println(qssj);
		String jssj1 = request.getParameter("EndDate");
		System.out.println(jssj1);
		jssj1 = jssj1.substring(0, 4) + jssj1.substring(5, 7);
		System.out.println(jssj1);
		String jssj = jssj1.substring(0, 4)+" 年 "+jssj1.substring(4, 6)+" 月";
		System.out.println(jssj);
		
		List<Map<String, Object>> userList1 = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> userList2 = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> userList3 = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> userList4 = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> userList5 = new ArrayList<Map<String, Object>>();
		
		List<String> userIdList = getAllUserId();
		User user = new User();
		Map<String, Object> ywpjMap = new HashMap<String, Object>();
		
//		int qsrqyf = Integer.parseInt(qssj1.substring(4, 6)) - 1;
//		String qsrq;
//		if (qsrqyf <= 9 && qsrqyf > 0) {
//			qsrq = qssj1.substring(0, 4)+"-0"+qsrqyf;
//		} else if (qsrqyf == 0) {
//			qsrq = Integer.parseInt(qssj1.substring(0, 4))-1 + "-12";
//		} else {
//			qsrq = qssj1.substring(0, 4)+"-"+qsrqyf;
//		}
		int jsrqyf = 0;  //起始  
		String jsrq;
		if (Integer.parseInt(jssj1.substring(4, 6)) == 12) {
			jsrqyf = Integer.parseInt(jssj1.substring(0, 4)) + 1;
			jsrq = jsrqyf+"-01";
		} else {
			jsrqyf = Integer.parseInt(jssj1.substring(4, 6)) + 1;
			jsrq = jssj1.substring(0, 4)+"-"+jsrqyf;
		}
		
//		ywpjMap.put("qssj", qsrq);
//		ywpjMap.put("jssj", jsrq);
		ywpjMap.put("qssj", qssj1);
		ywpjMap.put("jssj", jsrq);
		for (int i=0; i<userIdList.size(); i++) {
			Map<String, Object> userMap = new HashMap<String, Object>();
			String userId = userIdList.get(i);
			
			user.setId(userId);
			user = UserUtils.get(userId);
			String officeName = user.getOffice().getName();

			ywpjMap.put("userId",userId);
			
			if ("权证受理".equals(officeName)) {
				userMap.put("userId", userId);
				userMap.put("username", user.getName());
				
				ywpjMap.put("mycd","1");
				int myCount = getPjfsByUserId(ywpjMap);
				System.out.println(myCount);
				userMap.put("myCount", myCount);
				
				ywpjMap.put("mycd","2");
				int ybCount = getPjfsByUserId(ywpjMap);
				userMap.put("ybCount", ybCount);
				
				ywpjMap.put("mycd","3");
				int bmyCount = getPjfsByUserId(ywpjMap);
				userMap.put("bmyCount", bmyCount);
				
				int total = myCount + ybCount + bmyCount;
				userMap.put("total", total);
				
				if (total != 0) {
					double myd = total;  //转一下类型  要不计算会出错  会按照int类型计算
					myd = myCount / myd * 100;
					DecimalFormat df = new DecimalFormat("#.0");
					String myl = df.format(myd) + "%";
					userMap.put("myl", myl);
				} else {
					userMap.put("myl", "0%");
				}
				
				userList1.add(userMap);
			}
			
			if ("抵押受理".equals(officeName)) {
				userMap.put("userId", userId);
				userMap.put("username", user.getName());
				
				ywpjMap.put("mycd","1");
				int myCount = getPjfsByUserId(ywpjMap);
				userMap.put("myCount", myCount);
				
				ywpjMap.put("mycd","2");
				int ybCount = getPjfsByUserId(ywpjMap);
				userMap.put("ybCount", ybCount);
				
				ywpjMap.put("mycd","3");
				int bmyCount = getPjfsByUserId(ywpjMap);
				userMap.put("bmyCount", bmyCount);
				
				int total = myCount + ybCount + bmyCount;
				userMap.put("total", total);
				
				if (total != 0) {
					double myd = total;
					myd = myCount / myd * 100;
					DecimalFormat df = new DecimalFormat("#.0");
					String myl = df.format(myd) + "%";
					userMap.put("myl", myl);
				} else {
					userMap.put("myl", "0%");
				}
				
				userList2.add(userMap);
			}

			if ("预告受理".equals(officeName)) {
				userMap.put("userId", userId);
				userMap.put("username", user.getName());
				
				ywpjMap.put("mycd","1");
				int myCount = getPjfsByUserId(ywpjMap);
				userMap.put("myCount", myCount);
				
				ywpjMap.put("mycd","2");
				int ybCount = getPjfsByUserId(ywpjMap);
				userMap.put("ybCount", ybCount);
				
				ywpjMap.put("mycd","3");
				int bmyCount = getPjfsByUserId(ywpjMap);
				userMap.put("bmyCount", bmyCount);
				
				int total = myCount + ybCount + bmyCount;
				userMap.put("total", total);
				
				if (total != 0) {
					double myd = total; 
					myd = myCount / myd * 100;
					DecimalFormat df = new DecimalFormat("#.0");
					String myl = df.format(myd) + "%";
					userMap.put("myl", myl);
				} else {
					userMap.put("myl", "0%");
				}
				
				userList3.add(userMap);
			}
			
			if ("邮储银行汉中市分行营业部".equals(officeName) || "建设银行".equals(officeName) || "长安银行汉中分行营业部".equals(officeName)) {
				userMap.put("userId", userId);
				userMap.put("username", user.getName());
				
				ywpjMap.put("mycd","1");
				int myCount = getPjfsByUserId(ywpjMap);
				userMap.put("myCount", myCount);
				
				ywpjMap.put("mycd","2");
				int ybCount = getPjfsByUserId(ywpjMap);
				userMap.put("ybCount", ybCount);
				
				ywpjMap.put("mycd","3");
				int bmyCount = getPjfsByUserId(ywpjMap);
				userMap.put("bmyCount", bmyCount);
				
				int total = myCount + ybCount + bmyCount;
				userMap.put("total", total);
				
				if (total != 0) {
					double myd = total;
					myd = myCount / myd * 100;
					DecimalFormat df = new DecimalFormat("#.0");
					String myl = df.format(myd) + "%";
					userMap.put("myl", myl);
				} else {
					userMap.put("myl", "0%");
				}
				
				userList4.add(userMap);
			}
			
			if ("更正、异议查封受理".equals(officeName)) {
				userMap.put("userId", userId);
				userMap.put("username", user.getName());
				
				ywpjMap.put("mycd","1");
				int myCount = getPjfsByUserId(ywpjMap);
				userMap.put("myCount", myCount);
				
				ywpjMap.put("mycd","2");
				int ybCount = getPjfsByUserId(ywpjMap);
				userMap.put("ybCount", ybCount);
				
				ywpjMap.put("mycd","3");
				int bmyCount = getPjfsByUserId(ywpjMap);
				userMap.put("bmyCount", bmyCount);
				
				int total = myCount + ybCount + bmyCount;
				userMap.put("total", total);
				
				if (total != 0) {
					double myd = total;
					myd = myCount / myd * 100;
					DecimalFormat df = new DecimalFormat("#.0");
					String myl = df.format(myd) + "%";
					userMap.put("myl", myl);
				} else {
					userMap.put("myl", "0%");
				}
				
				userList5.add(userMap);
			}
		}
		
		if (qssj1.equals(jssj1)) {
			model.addAttribute("flag", 1);
			model.addAttribute("qssj", qssj);
		} else {
			model.addAttribute("flag", 2);
			model.addAttribute("qssj", qssj);
			model.addAttribute("jssj", jssj);
		}
		
		model.addAttribute("userList1", userList1);
		model.addAttribute("userList2", userList2);
		model.addAttribute("userList3", userList3);
		model.addAttribute("userList4", userList4);
		model.addAttribute("userList5", userList5);
		
		return model;
	}
}