package com.ld.igds.inout.view; import java.io.File; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import com.bstek.bdf2.core.business.IUser; import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.annotation.DataResolver; import com.bstek.dorado.annotation.Expose; import com.bstek.dorado.data.provider.Page; import com.bstek.dorado.uploader.UploadFile; import com.bstek.dorado.uploader.annotation.FileResolver; import com.ld.igds.file.CoreFileService; import com.ld.igds.inout.InoutConstant; import com.ld.igds.inout.dto.InoutData; import com.ld.igds.inout.dto.InoutParam; import com.ld.igds.inout.manager.InoutManager; import com.ld.igds.inout.manager.InoutReportManager; import com.ld.igds.inout.service.InoutService; import com.ld.igds.models.DicTrigger; import com.ld.igds.util.ContextUtil; import com.ld.igds.util.RedisUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateFormatUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; /** * 出入库详单页面管理 * * @author: andy.jia * @description: * @version: * @data:2020年3月30日 */ @Component public class InoutDataPR { @Resource private InoutService inoutService; @Resource private InoutReportManager inoutReportManager; @Resource private InoutManager inoutManager; @Autowired private CoreFileService fileService; @Autowired private RedisUtil redisUtil; // ${dorado.getDataProvider("inoutDataPR#triggerRecordStatus1").getResult()} @DataProvider public List triggerRecordStatus1() { List list = new ArrayList(); list.add(new DicTrigger(InoutConstant.RECORD_STATUS_DEL, "作废单")); list.add(new DicTrigger(InoutConstant.RECORD_STATUS_NORMAL, "正常单")); return list; } // ${dorado.getDataProvider("inoutDataPR#triggerResult").getResult()} @DataProvider public List triggerResult() { List list = new ArrayList(); list.add(new DicTrigger(InoutConstant.RESULT_1, "合格")); list.add(new DicTrigger(InoutConstant.RESULT_0, "不合格")); return list; } // ${dorado.getDataProvider("inoutDataPR#triggerSampleType").getResult()} @DataProvider public List triggerSampleType() { List list = new ArrayList(); list.add(new DicTrigger(InoutConstant.SAMPLE_TYPE_MANUAL, "人工")); list.add(new DicTrigger(InoutConstant.SAMPLE_TYPE_AUTOMATIC, "自动")); list.add(new DicTrigger(InoutConstant.SAMPLE_TYPE_RANDOM, "智能随机")); return list; } /** * inoutDataPR#pageInoutData * * @param page * @param param * @throws Exception */ @DataProvider public void pageInoutData(Page page, InoutParam param) throws Exception { // 调用核心包中方法,需要做对象转换 param.setPage(page.getPageNo()); param.setLimit(page.getPageSize()); param.setCustomerName(null); com.baomidou.mybatisplus.plugins.Page batisPage = inoutService.pageRecordData(param); // 封装转换 page.setEntities(batisPage.getRecords()); page.setEntityCount(Integer.valueOf(batisPage.getTotal() + "")); } /** * 保存出入库数据 inoutDataPR#saveInoutData */ @DataResolver public String saveInoutData(InoutData data) throws Exception { if (StringUtils.isEmpty(data.getId())) { return inoutManager.addInoutData(data); } else { return inoutManager.updateInoutData(data); } } /** * inoutDataPR#errorInoutData 出入库数据执行 异常终止 * * @param data * @return * @throws Exception */ @DataResolver @Transactional public String errorInoutData(InoutData data) throws Exception { return inoutManager.errorInoutData(data); } /** * inoutDataPR#completeInoutData 出入库数据执行 正常结束 *

* 执行逻辑:先判断页面数据与实际数据状态是否相符,如果不相符说明页面数据有延迟 * * @param data * @return * @throws Exception */ @DataResolver @Transactional public String completeInoutData(InoutData data) throws Exception { return inoutManager.completeInoutData(data); } /** * inoutDataPR#printWeightBill 获取打印单信息 * * @param data * @return * @throws Exception */ @Expose public String printWeightBill(InoutData data) throws Exception { if (InoutConstant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) { return "删除的数据不支持打印!"; } if (!InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { return "未完成的数据不支持打印!"; } if (InoutConstant.TYPE_IN.equals(data.getType())) { return inoutReportManager.inWeightBill(data); } else { return inoutReportManager.outWeightBill(data); } } /** * inoutDataPR#printShipBill 获取打印单信息 * * @param data * @return * @throws Exception */ @Expose public List printShipBill(InoutData data) throws Exception { if (InoutConstant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) { return null; } if (!InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { return null; } //打印船运过磅单 return inoutReportManager.shipWeightBill2(data); } /** * inoutDataPR#printCheckBill 打印化验单 * * @param data * @return * @throws Exception */ @Expose public String printCheckBill(InoutData data) throws Exception { if (InoutConstant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) { return "删除的数据不支持打印!"; } return inoutReportManager.inCheckBill(data); } /** * inoutDataPR#initAddData 新增 * * @return */ @Expose public InoutData initAddData(String type) { IUser user = ContextUtil.getLoginUser(); InoutData data = new InoutData(); data.setCompanyId(user.getCompanyId()); data.setRegisterTime(new Date()); data.setCompleteTime(new Date()); data.setType(type); data.setIntelCard("0000"); data.setRegisterUser(user.getCname()); data.setDeptId(ContextUtil.subDeptId(user)); data.setCheckUser(user.getCname()); data.setProgress(InoutConstant.PROGRESS_RECORD); data.setRecordStatus(InoutConstant.RECORD_STATUS_ADD); return data; } /** * inoutDataPR#initDataByHand 新增 * * @return */ @DataProvider public InoutData initDataByHand(String type) { IUser user = ContextUtil.getLoginUser(); InoutData data = new InoutData(); data.setCompanyId(user.getCompanyId()); data.setRegisterTime(new Date()); data.setType(type); data.setRegisterUser(user.getCname()); data.setDeptId(ContextUtil.subDeptId(user)); data.setCheckUser(user.getCname()); data.setBzw("1"); data.setProgress(InoutConstant.PROGRESS_RECORD); data.setRecordStatus(InoutConstant.RECORD_STATUS_ADD); return data; } /** * inoutDataPR#uploadImage * * @param file * @param parameter * @return */ @FileResolver public String uploadImage(UploadFile file, Map parameter) { //车牌 String plateNum = (String) parameter.get("plateNum"); //流程 String bizTag = (String) parameter.get("bizTag"); String newFileName = null; try { String basePath = fileService.getInoutFilePath(new Date()); // 获取新的ID newFileName = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"); if(StringUtils.isNotEmpty(bizTag)){ newFileName = bizTag + "_" + newFileName; } // 文件后缀名 String suffixName = file.getFileName().substring(file.getFileName().lastIndexOf(".")); // 合成新的文件名 newFileName = newFileName + suffixName; file.transferTo(new File(basePath + newFileName)); } catch (Exception e) { e.printStackTrace(); } return newFileName; } /** * inoutDataPR#delImage * * @param parameter * @return */ @Expose public String delImage(Map parameter) throws Exception { String fileName = (String) parameter.get("fileName"); Date createTime = (Date) parameter.get("createTime"); if (null == createTime) createTime = new Date(); fileName = URLDecoder.decode(fileName, "UTF-8"); File file = new File(fileService.getInoutFilePath(createTime), fileName); if (!file.exists()) { return "删除失败,系统未找到当前附件"; } file.delete(); return null; } }