//package com.huigou.topsun.controller;
//
//import com.huigou.cache.DictUtil;
//import com.huigou.uasp.annotation.ControllerMapping;
//import com.huigou.uasp.client.CommonController;
//import com.huigou.util.ClassHelper;
//import com.huigou.util.SDO;
//import com.huigou.util.StringUtil;
//import org.springframework.stereotype.Controller;
//import org.springframework.util.CollectionUtils;
//
//import java.lang.reflect.Field;
//import java.lang.reflect.InvocationTargetException;
//import java.lang.reflect.Method;
//import java.math.BigDecimal;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@Controller
//@ControllerMapping("print")
//public class PrintController extends CommonController {
//
//	/**
//	 * 打印工程验收申请单
//	 *
//	 * @return pdf 路径必须放在template/print/目录下
//	 */
//	public String printAcceptanceApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getId();
//		ApplyAcceptance applyAcceptance = acceptanceApplication.loadApplyAcceptance(id);
//		PurchaseContract purchaseContract = contractApplication.findContractById(applyAcceptance.getPurchaseContractId());
//		Map<String, Object> gridData = new HashMap<>();
//		List<Integer> list = new ArrayList<>();
//		list.add(3);
//		List<PurchaseMoneyApply> moneyApplyList = moneyApplyApplication.findByContractId(purchaseContract.getId(), list);
//		if (!CollectionUtils.isEmpty(moneyApplyList)){
//			for (PurchaseMoneyApply moneyApply : moneyApplyList) {
//				if (moneyApply.getChangeType() == 0){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}else if (moneyApply.getChangeType() == 3 && StringUtil.isNotBlank(moneyApply.getIdOld())){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}
//			}
//		}
//		Map<String, Object> bizData = ClassHelper.toMap(applyAcceptance);
//
//		List<Map<String, Object>> maps = (List<Map<String, Object>>) gridData.get("Rows");
//		for (Map<String, Object> item : maps) {
//			BigDecimal frozen = ClassHelper.convert(item.get("frozenValue"), BigDecimal.class, BigDecimal.ZERO);
//			BigDecimal cost = ClassHelper.convert(item.get("costValue"), BigDecimal.class, BigDecimal.ZERO);
//			String frozenValue = StringUtil.formatToCurrency(frozen);
//			String costValue = StringUtil.formatToCurrency(cost);
//			item.put("frozenValue", frozenValue);
//			item.put("costValue", costValue);
//		}
//		String purchaseApprovalId = applyAcceptance.getPurchaseApprovalId();
//		Purchase hxPurchaseApproval = purchaseApplication.loadPurchaseApproval(purchaseApprovalId);
//
//		List<DevelopMembers> researchers = developMembersApplication.queryDevelopMembersItems(id);
//
//		bizData.put("gridData", maps);
//
//		bizData.put("researchers", researchers);
//
//		bizData.put("standardKindText",
//				DictUtil.getDictionaryDetailText("StandardKind", applyAcceptance.getStandardKind()));
//		bizData.put("isPrototype", DictUtil.getDictionaryDetailText("yesorno", applyAcceptance.getIsPrototype()));
//		bizData.put("purchaseChannel",
//				DictUtil.getDictionaryDetailText("purchaseChannel", applyAcceptance.getPurchaseChannel()));
//		bizData.put("isBatch", DictUtil.getDictionaryDetailText("yesorno", applyAcceptance.getIsBatch()));
//		bizData.put("monetaryUnitType",
//				DictUtil.getDictionaryDetailText("monetaryUnitType", applyAcceptance.getMonetaryUnitType()));
//		bizData.put("acceptanceMethod",
//				DictUtil.getDictionaryDetailText("acceptanceMethod", applyAcceptance.getAcceptanceMethod()));
//		bizData.put("printTime", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(LocalDateTime.now()));
//		bizData.put("deviceType",
//				DictUtil.getDictionaryDetailText("deviceType", applyAcceptance.getDeviceType()));
//		if (hxPurchaseApproval.getProjectCode().equals("SHINE-Y")) {
//			//return outputPDF("/print/ssrf/printHXAcceptanceApply.ftl", bizData);
//			String printPage = String.format("/print/ssrf/printHXAcceptanceApply.ftl");
//			return outputAndProcUnitHandlerPDF(printPage, id, bizData);
//		}
//
//		//return outputPDF("/print/ssrf/printAcceptanceApply.ftl", bizData);
//		String printPage = String.format("/print/ssrf/printAcceptanceApply.ftl");
//		return outputAndProcUnitHandlerPDF(printPage, id, bizData);
//	}
//
//	/**
//	 * 打印硬线重大专项验收申请
//	 *
//	 * @return
//	 */
//	public String printHXAcceptanceApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getId();
//		ApplyAcceptance applyAcceptance = acceptanceApplication.loadApplyAcceptance(id);
//		PurchaseContract purchaseContract = contractApplication.findContractById(applyAcceptance.getPurchaseContractId());
//		Map<String, Object> gridData = new HashMap<>();
//		List<Integer> list = new ArrayList<>();
//		list.add(3);
//		List<PurchaseMoneyApply> moneyApplyList = moneyApplyApplication.findByContractId(purchaseContract.getId(), list);
//		if (!CollectionUtils.isEmpty(moneyApplyList)){
//			for (PurchaseMoneyApply moneyApply : moneyApplyList) {
//				if (moneyApply.getChangeType() == 0){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}else if (moneyApply.getChangeType() == 3 && StringUtil.isNotBlank(moneyApply.getIdOld())){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}
//			}
//		}
//		Map<String, Object> bizData = ClassHelper.toMap(applyAcceptance);
//
//		List<Map<String, Object>> maps = (List<Map<String, Object>>) gridData.get("Rows");
//		for (Map<String, Object> item : maps) {
//			BigDecimal frozen = ClassHelper.convert(item.get("frozenValue"), BigDecimal.class, BigDecimal.ZERO);
//			BigDecimal cost = ClassHelper.convert(item.get("costValue"), BigDecimal.class, BigDecimal.ZERO);
//			String frozenValue = StringUtil.formatToCurrency(frozen);
//			String costValue = StringUtil.formatToCurrency(cost);
//			item.put("frozenValue", frozenValue);
//			item.put("costValue", costValue);
//		}
//
//		bizData.put("gridData", maps);
//
//		bizData.put("standardKindText",
//				DictUtil.getDictionaryDetailText("StandardKind", applyAcceptance.getStandardKind()));
//		bizData.put("isPrototype", DictUtil.getDictionaryDetailText("yesorno", applyAcceptance.getIsPrototype()));
//		bizData.put("purchaseChannel",
//				DictUtil.getDictionaryDetailText("purchaseChannel", applyAcceptance.getPurchaseChannel()));
//		bizData.put("isBatch", DictUtil.getDictionaryDetailText("yesorno", applyAcceptance.getIsBatch()));
//		bizData.put("monetaryUnitType",
//				DictUtil.getDictionaryDetailText("monetaryUnitType", applyAcceptance.getMonetaryUnitType()));
//		bizData.put("acceptanceMethod",
//				DictUtil.getDictionaryDetailText("acceptanceMethod", applyAcceptance.getAcceptanceMethod()));
//		bizData.put("printTime", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(LocalDateTime.now()));
//
//		//return outputPDF("/print/ssrf/printAcceptanceApply.ftl", bizData);
//		String printPage = String.format("/print/ssrf/printHXAcceptanceApply.ftl");
//		return outputAndProcUnitHandlerPDF(printPage, id, bizData);
//	}
//
//	/**
//	 * 打印工程验收结果单
//	 *
//	 * @return pdf
//	 */
//	public String printAcceptanceReport() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		ApplyAcceptance applyAcceptance = acceptanceApplication.loadApplyAcceptance(id);
//		return outputPDF("/print/ssrf/printAcceptanceReport.ftl", printEntityToMap(applyAcceptance));
//	}
//
//	/**
//	 * 打印工程设备单个验收单
//	 * @return
//     */
//	public String printAcceptanceApproval() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getId();
//		Map<String,Object> map = acceptanceApprovalApplication.loadAcceptanceApprovalDetail(id);
//		//AcceptanceApproval acceptanceApproval = acceptanceApprovalApplication.loadAcceptanceApproval(id);
//		//return outputPDF("/print/ssrf/printAcceptanceApproval.ftl", printEntityToMap(map));
//		String purchaseApprovalId = (String) map.get("purchaseApprovalId");
//		// 获取Grid数据
//		PurchaseContract purchaseContract = contractApplication.findContractById((String) map.get("purchaseContractId"));
//		Map<String, Object> gridData = new HashMap<>();
//		List<Integer> list = new ArrayList<>();
//		list.add(3);
//		List<PurchaseMoneyApply> moneyApplyList = moneyApplyApplication.findByContractId(purchaseContract.getId(), list);
//		if (!CollectionUtils.isEmpty(moneyApplyList)){
//			for (PurchaseMoneyApply moneyApply : moneyApplyList) {
//				if (moneyApply.getChangeType() == 0){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}else if (moneyApply.getChangeType() == 3 && StringUtil.isNotBlank(moneyApply.getIdOld())){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}
//			}
//		}
//		// 预算金额、价值 金额转换
//		List<Map<String, Object>> maps = (List<Map<String, Object>>) gridData.get("Rows");
//		for (Map<String, Object> item : maps) {
//			BigDecimal frozen = ClassHelper.convert(item.get("frozenValue"), BigDecimal.class, BigDecimal.ZERO);
//			BigDecimal cost = ClassHelper.convert(item.get("costValue"), BigDecimal.class, BigDecimal.ZERO);
//			String frozenValue = StringUtil.formatToCurrency(frozen);
//			String costValue = StringUtil.formatToCurrency(cost);
//			item.put("frozenValue", frozenValue);
//			item.put("costValue", costValue);
//		}
//		map.put("printTime", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(LocalDateTime.now()));
//		Purchase hxPurchaseApproval = purchaseApplication.loadPurchaseApproval(purchaseApprovalId);
//
//		map.put("gridData", maps);
//		if (hxPurchaseApproval.getProjectCode().equals("SHINE-Y")) {
//			String printPage = String.format("/print/ssrf/printHXAcceptanceApproval.ftl");
//			return outputAndProcUnitHandlerPDF(printPage, id, map);
//		}
//		String pintPage = String.format("/print/ssrf/printAcceptanceApproval.ftl");
//		return outputAndProcUnitHandlerPDF(pintPage, id, map);
//	}
//
//	/**
//	 * 打印批量设备验收单
//	 * @return
//     */
//	public String printAcceptanceBatch(){
//		SDO sdo = this.getSDO();
//		String id = sdo.getId();
//		Map<String,Object> map = batchAcceptanceApprovalAppl.loadBatchAcceptanceApprovalDetail(id);
//		//AcceptanceApproval acceptanceApproval = acceptanceApprovalApplication.loadAcceptanceApproval(id);
//		//return outputPDF("/print/ssrf/printAcceptanceApproval.ftl", printEntityToMap(map));
//		String purchaseApprovalId = (String) map.get("purchaseApprovalId");
//		// 获取Grid数据
//		PurchaseContract purchaseContract = contractApplication.findContractById((String) map.get("purchaseContractId"));
//		Map<String, Object> gridData = new HashMap<>();
//		List<Integer> list = new ArrayList<>();
//		list.add(3);
//		List<PurchaseMoneyApply> moneyApplyList = moneyApplyApplication.findByContractId(purchaseContract.getId(), list);
//		if (!CollectionUtils.isEmpty(moneyApplyList)){
//			for (PurchaseMoneyApply moneyApply : moneyApplyList) {
//				if (moneyApply.getChangeType() == 0){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}else if (moneyApply.getChangeType() == 3 && StringUtil.isNotBlank(moneyApply.getIdOld())){
//					gridData = moneyApplyApplication.queryPurchaseMoneyUseds(moneyApply.getId());
//				}
//			}
//		}
//		// 预算金额、价值 金额转换
//		List<Map<String, Object>> maps = (List<Map<String, Object>>) gridData.get("Rows");
//		for (Map<String, Object> item : maps) {
//			BigDecimal frozen = ClassHelper.convert(item.get("frozenValue"), BigDecimal.class, BigDecimal.ZERO);
//			BigDecimal cost = ClassHelper.convert(item.get("costValue"), BigDecimal.class, BigDecimal.ZERO);
//			String frozenValue = StringUtil.formatToCurrency(frozen);
//			String costValue = StringUtil.formatToCurrency(cost);
//			item.put("frozenValue", frozenValue);
//			item.put("costValue", costValue);
//		}
//		map.put("gridData", maps);
//		map.put("printTime", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(LocalDateTime.now()));
//		Purchase hxPurchaseApproval = purchaseApplication.loadPurchaseApproval(purchaseApprovalId);
//		if (hxPurchaseApproval.getProjectCode().equals("SHINE-Y")) {
//			String printPage = String.format("/print/ssrf/printHXAcceptanceBatch.ftl");
//			return outputAndProcUnitHandlerPDF(printPage, id, map);
//		}
//
//		String pintPage = String.format("/print/ssrf/printAcceptanceBatch.ftl");
//		return outputAndProcUnitHandlerPDF(pintPage, id, map);
//	}
//
//	/**
//	 * 打印采购申请单
//	 *
//	 * @return pdf
//	 */
//	public String printPurchaseApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		Purchase purchase = purchaseApplication.loadPurchaseApproval(id);
//		return outputPDF("/print/ssrf/printPurchaseApply.ftl", printEntityToMap(purchase));
//	}
//
//	/**
//	 * 打印招标申请单
//	 *
//	 * @return pdf
//	 */
//	public String printBiddingApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		Purchase purchase = purchaseApplication.loadPurchaseApproval(id);
//		return outputPDF("/print/ssrf/printBiddingApply.ftl", printEntityToMap(purchase));
//	}
//
//	/**
//	 * 打印采购合同申请单
//	 *
//	 * @return pdf
//	 */
//	public String printContractApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		Map<String, Object> map = contractApplication.loadPurchaseContract(id);
//		return outputPDF("/print/ssrf/printContractApply.ftl", map);
//	}
//
//	/**
//	 * 打印预算外采购申请单
//	 *
//	 * @return pdf
//	 */
//	public String printExtraPurchaseApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		Purchase purchase = purchaseApplication.loadPurchaseApproval(id);
//		return outputPDF("/print/ssrf/printExtraPurchaseApply.ftl", printEntityToMap(purchase));
//	}
//
//	/**
//	 * 打印用款申请单
//	 *
//	 * @return pdf
//	 */
//	public String printMoneyApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		PurchaseMoneyApply moneyApply = moneyApplyApplication.findMoneyApply(id);
//		return outputPDF("/print/ssrf/printMoneyApply.ftl", printEntityToMap(moneyApply));
//	}
//
//	/**
//	 * 打印运行费采购申请单
//	 *
//	 * @return pdf
//	 */
//	public String printRunningCostPurchaseApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		Purchase purchase = purchaseApplication.loadPurchaseApproval(id);
//		return outputPDF("/print/ssrf/printRunningCostPurchaseApply.ftl", printEntityToMap(purchase));
//	}
//
//	/**
//	 * 打印运行费招标申请单
//	 *
//	 * @return pdf
//	 */
//	public String printRunningCostBiddingApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		Purchase purchase = purchaseApplication.loadPurchaseApproval(id);
//		return outputPDF("/print/ssrf/printRunningCostBiddingApply.ftl", printEntityToMap(purchase));
//	}
//
//	/**
//	 * 打印预算外运行费采购申请单
//	 *
//	 * @return pdf
//	 */
//	public String printExtraRunningCostPurchaseApply() {
//		SDO sdo = this.getSDO();
//		String id = sdo.getBizId();
//		Purchase purchase = purchaseApplication.loadPurchaseApproval(id);
//		return outputPDF("/print/ssrf/printExtraRunningCostPurchaseApply.ftl", printEntityToMap(purchase));
//	}
//
//    /**
//     * 打印采购申请终止单
//     *
//     * @return pdf
//     */
//    public String printPurchaseAborted() {
//        SDO sdo = this.getSDO();
//        String id = sdo.getString("id");
//
//        // 获取业务数据
//        Map<String, Object> bizData = purchaseAbortedApplication.loadHxPurchaseAborted(id);
//		bizData.put("monetaryUnitTypeView", DictUtil.getDictionaryDetailText("MonetaryUnitType", bizData.get("monetaryUnitType")));
//        bizData.put("printTime", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(LocalDateTime.now()));
//		bizData.put("taskHandledDate", ClassHelper.convert(sdo.getProperty("needTime"), Boolean.class, true));
//
//        // 跳转打印界面
//        String pintPage = String.format("/print/ssrf/purchaseAborted.ftl");
//        return outputAndProcUnitHandlerPDF(pintPage, id, bizData);
//    }
//
//	/**
//	 * 将对象转化为Map
//	 *
//	 * @param object
//	 *            目标对象
//	 * @return Map对象
//	 */
//	private <T> Map<String, Object> printEntityToMap(T object) {
//		Map<String, Object> map = new HashMap<>();
//		if (object != null) {
//			try {
//				Class<?> clazz = object.getClass();
//				Field[] fields = clazz.getDeclaredFields();
//				for (Field f : fields) {
//					f.setAccessible(true);
//					/* map.put(f.getName(),f.get(object)); */
//					Method method = clazz.getMethod(
//							"get" + f.getName().substring(0, 1).toUpperCase().concat(f.getName().substring(1)));
//					Object invoke = method.invoke(object);
//					if (invoke != null) {
//						if (invoke.getClass() == String.class) {
//							String string = invoke.toString();
//							map.put(f.getName(), string.length() > 31
//									? string.substring(0, 30).concat("\n").concat(string.substring(30)) : string);
//						} else
//							map.put(f.getName(), invoke);
//					}
//				}
//			} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
//				e.printStackTrace();
//			}
//		}
//		map.put("printTime", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(LocalDateTime.now()));
//		return map;
//	}
//}
