package com.ld.igds.m; import com.bstek.bdf2.core.model.DefaultDept; import com.ld.igds.check.dto.CheckItemData; import com.ld.igds.common.CoreCommonService; import com.ld.igds.constant.FoodLevel; import com.ld.igds.constant.FoodType; import com.ld.igds.constant.FoodVariety; import com.ld.igds.models.Building; import com.ld.igds.models.Depot; import com.ld.igds.models.DepotStore; import com.ld.igds.models.MQuality; import com.ld.igds.sys.service.SysDeptService; import com.ld.igds.view.service.BuildingService; import com.ld.igds.view.service.HDepotStoreService; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; /** * 打印各种报告单据管理类 */ @Component public class ReportManage { @Autowired private CoreCommonService commonService; @Autowired private SysDeptService sysDeptService; @Autowired private BuildingService buildingService; @Resource private HDepotStoreService depotStoreService; /** * 整车质检报告单据 * * @param data * @return */ public String printQualityBill(MQuality data) { //获取默认模版 String htmlStr = "模板暂未确定!!"; if (data.getFoodVariety().startsWith("111")) { //调用小麦质检报告模版 htmlStr = ReportBill.QUALITY_111; } if (data.getFoodVariety().startsWith("112")) { //调用玉米质检报告模版 htmlStr = ReportBill.QUALITY_112; } if (data.getFoodVariety().startsWith("113")) { //调用稻谷质检报告模版 htmlStr = ReportBill.QUALITY_113; } if (data.getFoodVariety().startsWith("141")) { //调用大豆质检报告模版 htmlStr = ReportBill.QUALITY_141; } if (data.getFoodVariety().startsWith("236")) { //调用稻谷质检报告模版 htmlStr = ReportBill.QUALITY_113; } if (data.getFoodVariety().startsWith("212")) { //调用油脂质检报告模版 htmlStr = ReportBill.QUALITY_212; } //获取单位名称 DefaultDept dept = sysDeptService.getDeptById(data.getCompanyId()); if (null != dept && StringUtils.isNotEmpty(dept.getName())) { htmlStr = htmlStr.replace("dwmc", dept.getName()); } else { htmlStr = htmlStr.replace("dwmc", "-"); } //获取库区名称 dept = sysDeptService.getDeptById(data.getDeptId()); if (null != dept && StringUtils.isNotEmpty(dept.getName())) { htmlStr = htmlStr.replace("deptName", dept.getName()); } else { htmlStr = htmlStr.replace("deptName", "-"); } //获取仓库信息 Depot depot = commonService.getCacheDepot(data.getCompanyId(), data.getDepotId()); String buildingName = "-"; if (depot != null) { htmlStr = htmlStr.replace("depotName", depot.getName() == null ? "-" : depot.getName()); htmlStr = htmlStr.replace("foodLocation", StringUtils.isEmpty(depot.getFoodLocation()) ? "-" : depot.getFoodLocation()); htmlStr = htmlStr.replace("storeKeeperName", StringUtils.isEmpty(depot.getStoreKeeperName()) ? "-" : depot.getStoreKeeperName()); //获取仓房信息 if (StringUtils.isNotEmpty(depot.getBuildingId())) { Building building = buildingService.getCacheBuilding(depot.getCompanyId(), depot.getDeptId(), depot.getBuildingId()); if (null != building) { buildingName = building.getName(); } } } else { htmlStr = htmlStr.replace("depotName", "-"); htmlStr = htmlStr.replace("foodLocation", "-"); htmlStr = htmlStr.replace("storeKeeperName", "-"); } htmlStr = htmlStr.replace("buildingName", buildingName); htmlStr = htmlStr.replace("foodVariety", FoodVariety.getMsg(data.getFoodVariety())); htmlStr = htmlStr.replace("serId", data.getId()); //获取质检时间之前的库存信息 DepotStore lastDepotStore = depotStoreService.getLastData(data.getDepotId(), data.getTime()); String storageReal = "-"; String foodYear = "-"; String foodType = "-"; if(null != lastDepotStore){ if(StringUtils.isNotEmpty(lastDepotStore.getFoodYear())){ foodYear = lastDepotStore.getFoodYear(); } if(null != lastDepotStore.getStorageReal()){ storageReal = lastDepotStore.getStorageReal()/1000 + ""; } if(StringUtils.isNotEmpty(lastDepotStore.getFoodType())){ foodType = FoodType.getMsg(lastDepotStore.getFoodType()); } } htmlStr = htmlStr.replace("storageReal", storageReal); htmlStr = htmlStr.replace("foodYear", foodYear); htmlStr = htmlStr.replace("foodType", foodType); htmlStr = htmlStr.replace("foodNumber", data.getDbsl() == null? "-":data.getDbsl()/1000 + ""); htmlStr = htmlStr.replace("foodLevel", StringUtils.isEmpty(data.getFoodLevel()) ? "-" : FoodLevel.getMsg(data.getFoodLevel())); htmlStr = htmlStr.replace("checkNum", data.getYpsl() == null? "-":data.getYpsl() + ""); htmlStr = htmlStr.replace("unit", StringUtils.isEmpty(data.getUnit()) ? "-" : data.getUnit()); htmlStr = htmlStr.replace("sampleUser", StringUtils.isEmpty(data.getCheckUser()) ? "-" : data.getCheckUser()); htmlStr = htmlStr.replace("checkUser", StringUtils.isEmpty(data.getUser()) ? "-" : data.getUser()); htmlStr = htmlStr.replace("sampleTime", data.getCheckTime() == null ? "-" : DateFormatUtils.format(data.getCheckTime(), "yyyy/MM/dd HH:mm:ss")); htmlStr = htmlStr.replace("checkTime", data.getTime() == null ? "-" : DateFormatUtils.format(data.getTime(), "yyyy/MM/dd HH:mm:ss")); htmlStr = htmlStr.replace("bgcjsj", data.getBgcjsj() == null ? "-" : DateFormatUtils.format(data.getBgcjsj(), "yyyy/MM/dd HH:mm:ss")); htmlStr = htmlStr.replace("remark", StringUtils.isEmpty(data.getRemark()) ? "-" : data.getRemark()); Map checkBillItems = getCheckBillItems(); // 遍历化验结果,存入map集合中 String key; for (CheckItemData item : data.getCheckItems()) { key = item.getStandardId() + "_VAL"; checkBillItems.put(key, item.getValue()); } // 遍历map集合,替换化验单中化验值 String value; for (String str : checkBillItems.keySet()) { value = checkBillItems.get(str); if (StringUtils.isNotEmpty(value)) { htmlStr = htmlStr.replace(str, value); } else { htmlStr = htmlStr.replace(str, "-"); } } return htmlStr; } /** * 封装化验项数值,key-化验项编码,value-放置化验值 * * @return */ private Map getCheckBillItems() { Map map = new HashMap<>(); map.put("C01_VAL", ""); map.put("C02_VAL", ""); map.put("C03_VAL", ""); map.put("C04_VAL", ""); map.put("C05_VAL", ""); map.put("C06_VAL", ""); map.put("C07_VAL", ""); map.put("C08_VAL", ""); map.put("C09_VAL", ""); map.put("C10_VAL", ""); map.put("C11_VAL", ""); map.put("C12_VAL", ""); map.put("C13_VAL", ""); map.put("C14_VAL", ""); map.put("C15_VAL", ""); map.put("C16_VAL", ""); map.put("C17_VAL", ""); map.put("C18_VAL", ""); map.put("C19_VAL", ""); map.put("C20_VAL", ""); map.put("C21_VAL", ""); map.put("C22_VAL", ""); map.put("C23_VAL", ""); map.put("C24_VAL", ""); map.put("C25_VAL", ""); map.put("C26_VAL", ""); map.put("C27_VAL", ""); map.put("C28_VAL", ""); map.put("C29_VAL", ""); map.put("C30_VAL", ""); map.put("C31_VAL", ""); map.put("C32_VAL", ""); map.put("C33_VAL", ""); map.put("C34_VAL", ""); map.put("C35_VAL", ""); return map; } }