package cn.com.lzt.budget.tempsheet.controller; import cn.com.lzt.budget.control.entity.BudgetControlEntity; import cn.com.lzt.budget.data.dto.BudgetDimMatchDto; import cn.com.lzt.budget.data.service.BudgetDataService; import cn.com.lzt.budget.data.util.BudgetConstant; import cn.com.lzt.budget.data.util.BudgetUtils; import cn.com.lzt.budget.data.util.SpreadJson; import cn.com.lzt.budget.dimfunction.entity.BudgetDimFunctionEntity; import cn.com.lzt.budget.entity.entity.BudgetEntity; import cn.com.lzt.budget.measure.entity.BudgetMeasureEntity; import cn.com.lzt.budget.period.entity.BudgetPeriodEntity; import cn.com.lzt.budget.perioddetail.entity.BudgetPeriodDetailEntity; import cn.com.lzt.budget.perioddetail.service.BudgetPeriodDetailServiceI; import cn.com.lzt.budget.tempsheet.entity.BudgetTempSheetEntity; import cn.com.lzt.budget.tempsheet.service.BudgetTempSheetServiceI; import cn.com.lzt.budget.tempsheetentity.entity.BudgetTempSheetEntityMap; import cn.com.lzt.budget.tempsheetmeasure.entity.BudgetTempSheetMeasureEntity; import cn.com.lzt.budget.tempsheetmeasure.service.BudgetTempSheetMeasureServiceI; import cn.com.lzt.budget.writeback.service.BudgetWriteBackServiceI; import cn.com.lzt.common.util.DictUtil; import cn.com.lzt.goodscategory.entity.TBGoodsCategoryEntity; import org.apache.commons.lang.xwork.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.log4j.Logger; import org.apache.poi.xwpf.usermodel.*; import org.codehaus.jackson.map.ObjectMapper; import org.jeecgframework.core.beanvalidator.BeanValidators; import org.jeecgframework.core.common.controller.BaseController; import org.jeecgframework.core.common.exception.BusinessException; import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.*; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.web.system.pojo.base.TSType; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.UriComponentsBuilder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.ConstraintViolation; import javax.validation.Validator; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.math.BigDecimal; import java.net.URI; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @Title: Controller * @Description: 预算样表 * @author onlineGenerator * @date 2020-07-04 13:51:06 * @version V1.0 * */ @Controller @RequestMapping("/budgetTempSheetController") public class BudgetTempSheetController extends BaseController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(BudgetTempSheetController.class); @Autowired private BudgetTempSheetServiceI budgetTempSheetService; @Autowired private BudgetTempSheetMeasureServiceI budgetTempSheetMeasureService; @Autowired private SystemService systemService; @Autowired private Validator validator; @Autowired private BudgetDataService budgetDataService; @Autowired private BudgetPeriodDetailServiceI budgetPeriodDetailService; /** * 预算样表列表 页面跳转 * * @return */ @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheetList"); } @RequestMapping(params = "goMeasure") public ModelAndView goMeasure(HttpServletRequest request) { String id = request.getParameter("id"); BudgetTempSheetEntity tempSheet = systemService.getEntity(BudgetTempSheetEntity.class, id); request.setAttribute("tempSheet", tempSheet); setGoMeasure(tempSheet,request); String type = tempSheet.getType(); String periodYear = tempSheet.getPeriodYear(); Integer actual = tempSheet.getActual(); if(actual==1){ /*List controlEntityList =systemService.getList(BudgetControlEntity.class); request.setAttribute("controlEntityList", controlEntityList);*/ } if(StringUtils.startsWith(type, BudgetConstant.TEMPSHEET_TYPE_NORMAL)){ return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-measure"); }else if(StringUtils.equals(type, BudgetConstant.TEMPSHEET_TYPE_ORDERS)){ String orderKind = tempSheet.getOrdersKind(); String ordersKindTxt = DictUtil.formatToTypeName(orderKind,"budget_orders_kind"); request.setAttribute("ordersKindTxt", ordersKindTxt); BudgetConstant.OrdersKindType ordersKindType=tempSheet.getOrdersKindType(); if(ordersKindType==BudgetConstant.OrdersKindType.dizhi){ List subCategoryList =budgetDataService.getGoodsCategoryByParent(tempSheet.getOrdersCategoryCode()); request.setAttribute("subCategoryList", subCategoryList); } BudgetPeriodDetailEntity defaultPeriodDetailEntity = budgetPeriodDetailService.findMaxDataDetail(periodYear); request.setAttribute("defaultPeriodDetailEntity", defaultPeriodDetailEntity); return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-measure4Orders"); }else if(StringUtils.equals(type, BudgetConstant.TEMPSHEET_TYPE_HR)){ BudgetPeriodDetailEntity defaultPeriodDetailEntity = budgetPeriodDetailService.findMaxDataDetail(periodYear); request.setAttribute("defaultPeriodDetailEntity", defaultPeriodDetailEntity); List postTypeList =systemService.getTypesByGroupcodeFromCache("budget_cost_post_type"); request.setAttribute("postTypeList",postTypeList ); return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-measure4Hr"); }else if(StringUtils.equals(type, BudgetConstant.TEMPSHEET_TYPE_ACTUAL_STA)){//执行统计表 if(StringUtils.isBlank(tempSheet.getJson())){ List entityList = systemService.findHql("from BudgetEntity where id<>? order by entityName",BudgetConstant.COMPANY_ENTITY_ID); request.setAttribute("entityList", entityList); } if(StringUtils.equals(tempSheet.getActualStaKind(),BudgetConstant.TEMPSHEET_TYPE_LEADER)){ return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-leader"); } return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-measure4ActualSta"); } return null; } @RequestMapping(params = "doAddMeasure") @ResponseBody public AjaxJson doAddMeasure(BudgetTempSheetEntity tempSheet, BudgetTempSheetEntityMap tempSheetDept, HttpServletRequest request) { AjaxJson j = new AjaxJson(); String message = "保存成功"; try { String tempSheetId = tempSheet.getId(); // Integer headRowCount = tempSheet.getHeadRowCount(); // Integer goalsColIndex =tempSheet.getGoalsColIndex(); String json = request.getParameter("json"); BudgetTempSheetEntity entity = systemService.getEntity(BudgetTempSheetEntity.class, tempSheetId); BudgetPeriodEntity periodEntity = systemService.findUniqueByProperty(BudgetPeriodEntity.class, "periodYear", entity.getPeriodYear()); String periodId = periodEntity.getId(); //预算指标 String deltempSheetMeasureSql = " truncate "+entity.getTempsheetMeasureTable(); systemService.executeSql(deltempSheetMeasureSql); SpreadJson spreadJson = new SpreadJson(json); Map dataMap = spreadJson.data(1); Map dataTable = (Map) dataMap.get("dataTable"); List tempSheetMeasureEntityList = new ArrayList<>(); List usedMeasureIdList = new ArrayList<>(); for(Map.Entry entry :dataTable.entrySet()){ String row = entry.getKey(); Map rowCols = (Map) entry.getValue(); for(Map.Entry rowColsEntry :rowCols.entrySet()) { String col = rowColsEntry.getKey(); Map cellMap = (Map) rowColsEntry.getValue(); Map cellTag = (Map) cellMap.get("tag"); if(cellTag==null) continue; Boolean dataCell = (Boolean) cellTag.get("dataCell"); if(dataCell== null ||!dataCell) continue; Object value = cellMap.get("value"); Object formula = cellMap.get("formula"); String measureDataType = oConvertUtils.getString(cellTag.get("datatype")); boolean isFormula = formula!=null; BudgetTempSheetMeasureEntity tempSheetMeasureEntity = new BudgetTempSheetMeasureEntity(); String entityId = oConvertUtils.getString(cellTag.get("entityId")); tempSheetMeasureEntity.setEntityId(entityId); String effectCell = oConvertUtils.getString(cellTag.get("effectCell")); tempSheetMeasureEntity.setEffectCell(effectCell); String showType = oConvertUtils.getString(cellTag.get("showType")); tempSheetMeasureEntity.setShowType(showType); tempSheetMeasureEntity.setTempSheetId(tempSheetId); if(StringUtils.equals(measureDataType,"txt")){//文本说明保存到txt字段 tempSheetMeasureEntity.setDataTxt(value==null?null:value.toString()); }else { if(value!=null){ if(NumberUtils.isNumber(value.toString())){ tempSheetMeasureEntity.setDataValue(BudgetUtils.measureShowValueToDb(new BigDecimal(value.toString()),measureDataType,showType)); }else {//非空非数字 cellMap.put("value", null); } } } tempSheetMeasureEntity.setDataFormula(formula==null?null:formula.toString()); String measureId = oConvertUtils.getString(cellTag.get("measureId")); String measureName = oConvertUtils.getString(cellTag.get("measureName")); if(StringUtils.isNotBlank(measureId)) { tempSheetMeasureEntity.setMeasureId(measureId); tempSheetMeasureEntity.setMeasureName(measureName); usedMeasureIdList.add(measureId); } tempSheetMeasureEntity.setPeriodId(periodEntity.getId()); tempSheetMeasureEntity.setPeriodType(periodEntity.getPeriodType()); tempSheetMeasureEntity.setPeriodYear(periodEntity.getPeriodYear()); String periodDetailId = oConvertUtils.getString(cellTag.get("periodDetailId")); if(StringUtils.isNotBlank(periodDetailId)) { BudgetPeriodDetailEntity periodDetail = systemService.getEntity(BudgetPeriodDetailEntity.class, periodDetailId); tempSheetMeasureEntity.setPeriodDetailId(periodDetail.getId()); tempSheetMeasureEntity.setPeriodDetailStart(periodDetail.getStart()); tempSheetMeasureEntity.setPeriodDetailEnd(periodDetail.getEnd()); } String periodDetailName = oConvertUtils.getString(cellTag.get("periodDetailName")); tempSheetMeasureEntity.setPeriodDetailName(periodDetailName); String includeTax = oConvertUtils.getString(cellTag.get("includeTax"),Globals.YES); if(StringUtils.isNotBlank(includeTax)) tempSheetMeasureEntity.setIncludeTax(Integer.valueOf(includeTax)); Integer expect = oConvertUtils.getInt(cellTag.get("expect"), BudgetConstant.EXPECT_YES); cellTag.put("expect", expect); tempSheetMeasureEntity.setExpect(expect); /*if(isFormula) { measureDataType="formula"; cellTag.put("datatype", measureDataType); }*/ String functionId = oConvertUtils.getString(cellTag.get("functionId")); if(StringUtils.isNotBlank(functionId)) { tempSheetMeasureEntity.setFunctionId(functionId); isFormula=true;//维度公式必须是公式 BudgetDimFunctionEntity dimFunctionEntity = systemService.getEntity(BudgetDimFunctionEntity.class, functionId); dimFunctionEntity.setFunctionFrom("tempsheet"); dimFunctionEntity.setCurrentMeasureId(measureId); dimFunctionEntity.setCurrentPeriodDetailId(periodDetailId); dimFunctionEntity.setTempsheetId(tempSheetId); dimFunctionEntity.setRow(Integer.valueOf(row)); dimFunctionEntity.setCol(Integer.valueOf(col)); systemService.updateEntitie(dimFunctionEntity); } if(StringUtils.isNotBlank(measureDataType)) tempSheetMeasureEntity.setDataType(measureDataType); //goalsDataTypeName String controlFlag = oConvertUtils.getString(cellTag.get("controlFlag")); if(StringUtils.isNotBlank(controlFlag)) tempSheetMeasureEntity.setControlFlag(controlFlag); String readOnly = oConvertUtils.getString(cellTag.get("readOnly")); if(isFormula){ readOnly = "1"; cellTag.put("readOnly",1); } Map dataRules = new HashMap<>(); if(StringUtils.isNotBlank(readOnly)) dataRules.put("readOnly", readOnly); ObjectMapper mapper = new ObjectMapper(); tempSheetMeasureEntity.setDataRules(mapper.writeValueAsString(dataRules)); tempSheetMeasureEntity.setRow(Integer.valueOf(row)); tempSheetMeasureEntity.setCol(Integer.valueOf(col)); tempSheetMeasureEntity.setSheetIndex(1); String findKey = oConvertUtils.getString(cellTag.get("findKey")); tempSheetMeasureEntity.setFindKey(findKey); tempSheetMeasureEntityList.add(tempSheetMeasureEntity); } } budgetTempSheetMeasureService.batchSave(tempSheetMeasureEntityList); ObjectMapper mapper = new ObjectMapper(); String alterJson=mapper.writeValueAsString(spreadJson.getJsonMap()); entity.setJson(alterJson); systemService.saveOrUpdate(entity); //标志指标已被使用 for(String measureId:usedMeasureIdList){ BudgetMeasureEntity measureEntity = systemService.getEntity(BudgetMeasureEntity.class,measureId); systemService.saveOrUpdate(measureEntity); } }catch (Exception e){ e.printStackTrace(); j.setSuccess(false); message="保存失败"; } j.setMsg(message); return j; } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "datagrid") public void datagrid(BudgetTempSheetEntity tempSheet, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(BudgetTempSheetEntity.class, dataGrid); //查询条件组装器 if(StringUtils.isNotBlank(tempSheet.getName())){ cq.like("name","%"+tempSheet.getName()+"%"); tempSheet.setName(null); } if(StringUtils.isNotBlank(tempSheet.getOfficeName())){ cq.like("officeName","%"+tempSheet.getOfficeName()+"%"); tempSheet.setOfficeName(null); } org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tempSheet, request.getParameterMap()); try{ //自定义追加查询条件 }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); this.budgetTempSheetService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } /** * 删除预算样表 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(BudgetTempSheetEntity tempSheet, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); tempSheet = systemService.getEntity(BudgetTempSheetEntity.class, tempSheet.getId()); message = "预算样表删除成功"; try{ budgetTempSheetService.delete(tempSheet); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); }catch(Exception e){ e.printStackTrace(); message = "预算样表删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 批量删除预算样表 * * @return */ @RequestMapping(params = "doBatchDel") @ResponseBody public AjaxJson doBatchDel(String ids,HttpServletRequest request){ String message = null; AjaxJson j = new AjaxJson(); message = "预算样表删除成功"; try{ for(String id:ids.split(",")){ BudgetTempSheetEntity tempSheet = systemService.getEntity(BudgetTempSheetEntity.class, id ); budgetTempSheetService.delete(tempSheet); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); } }catch(Exception e){ e.printStackTrace(); message = "预算样表删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 添加预算样表 * * @return */ @RequestMapping(params = "doAdd") @ResponseBody public AjaxJson doAdd(BudgetTempSheetEntity tempSheet, HttpServletRequest request) { if(StringUtils.isNotBlank(tempSheet.getId())){ return doUpdate(tempSheet,request); } String message = null; AjaxJson j = new AjaxJson(); message = "预算样表添加成功"; try{ Integer actual = tempSheet.getActual(); String type = tempSheet.getType(); String periodYear = tempSheet.getPeriodYear(); if(actual==1 &&StringUtil.equals(type,BudgetConstant.TEMPSHEET_TYPE_ACTUAL_STA)){//执行统计表 判断唯一性 String sql = "select 1 from t_b_budget_tempsheet where period_year=? and actual=? and actual_sta_kind=? "; List list = systemService.findForJdbc(sql,periodYear,1,tempSheet.getActualStaKind()); if(!list.isEmpty()){ j.setSuccess(false); j.setMsg("已存在同类型统计表"); return j; } } tempSheet.setStatus(BudgetTempSheetEntity.STATUS_UNPUBLISH); BudgetPeriodEntity periodEntity = systemService.findUniqueByProperty(BudgetPeriodEntity.class, "periodYear",periodYear); if(periodEntity==null){ j.setMsg(periodYear+"年无预算周期设置"); j.setSuccess(false); return j; } tempSheet.setPeriodId(periodEntity.getId()); budgetTempSheetService.save(tempSheet); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); }catch(Exception e){ e.printStackTrace(); message = "预算样表添加失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 更新预算样表 * * @return */ @RequestMapping(params = "doUpdate") @ResponseBody public AjaxJson doUpdate(BudgetTempSheetEntity tempSheet, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "预算样表更新成功"; Integer oldWriteback = tempSheet.getWriteBack(); BudgetTempSheetEntity t = budgetTempSheetService.get(BudgetTempSheetEntity.class, tempSheet.getId()); Integer newWriteback = t.getWriteBack(); try { MyBeanUtils.copyBeanNotNull2Bean(tempSheet, t); budgetTempSheetService.saveOrUpdate(t); if(newWriteback!=null&&(oldWriteback==null || !newWriteback.equals(oldWriteback))){ budgetTempSheetService.changeMeasureInstMap(t); } systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); message = "预算样表更新失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 预算样表新增页面跳转 * * @return */ @RequestMapping(params = "goAdd") public ModelAndView goAdd(BudgetTempSheetEntity tempSheet, HttpServletRequest req) { if (StringUtil.isNotEmpty(tempSheet.getId())) { tempSheet = budgetTempSheetService.getEntity(BudgetTempSheetEntity.class, tempSheet.getId()); req.setAttribute("tempSheetPage", tempSheet); } return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-add"); } /** * 预算样表编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(BudgetTempSheetEntity tempSheet, HttpServletRequest req) { if (StringUtil.isNotEmpty(tempSheet.getId())) { tempSheet = budgetTempSheetService.getEntity(BudgetTempSheetEntity.class, tempSheet.getId()); req.setAttribute("entity", tempSheet); } return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-add"); } /** * 导入功能跳转 * * @return */ @RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name","budgetTempSheetController"); return new ModelAndView("common/upload/pub_excel_upload"); } /** * 导出excel * * @param request * @param response */ @RequestMapping(params = "exportXls") public String exportXls(BudgetTempSheetEntity tempSheet, HttpServletRequest request, HttpServletResponse response , DataGrid dataGrid, ModelMap modelMap) { CriteriaQuery cq = new CriteriaQuery(BudgetTempSheetEntity.class, dataGrid); org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tempSheet, request.getParameterMap()); List tempSheets = this.budgetTempSheetService.getListByCriteriaQuery(cq,false); modelMap.put(NormalExcelConstants.FILE_NAME,"预算样表"); modelMap.put(NormalExcelConstants.CLASS, BudgetTempSheetEntity.class); modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("预算样表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST,tempSheets); return NormalExcelConstants.JEECG_EXCEL_VIEW; } /** * 导出excel 使模板 * * @param request * @param response */ @RequestMapping(params = "exportXlsByT") public String exportXlsByT(BudgetTempSheetEntity tempSheet, HttpServletRequest request, HttpServletResponse response , DataGrid dataGrid, ModelMap modelMap) { modelMap.put(NormalExcelConstants.FILE_NAME,"预算样表"); modelMap.put(NormalExcelConstants.CLASS, BudgetTempSheetEntity.class); modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("预算样表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList()); return NormalExcelConstants.JEECG_EXCEL_VIEW; } @SuppressWarnings("unchecked") @RequestMapping(params = "importExcel", method = RequestMethod.POST) @ResponseBody public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) { AjaxJson j = new AjaxJson(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { MultipartFile file = entity.getValue();// 获取上传文件对象 ImportParams params = new ImportParams(); params.setTitleRows(2); params.setHeadRows(1); params.setNeedSave(true); try { List listBudgetTempSheetEntities = ExcelImportUtil.importExcel(file.getInputStream(), BudgetTempSheetEntity.class,params); for (BudgetTempSheetEntity tempSheet : listBudgetTempSheetEntities) { budgetTempSheetService.save(tempSheet); } j.setMsg("文件导入成功!"); } catch (Exception e) { j.setMsg("文件导入失败!"); logger.error(ExceptionUtil.getExceptionMessage(e)); }finally{ try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return j; } @RequestMapping(method = RequestMethod.GET) @ResponseBody public List list() { List listtempSheets=budgetTempSheetService.getList(BudgetTempSheetEntity.class); return listtempSheets; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { BudgetTempSheetEntity task = budgetTempSheetService.get(BudgetTempSheetEntity.class, id); if (task == null) { return new ResponseEntity(HttpStatus.NOT_FOUND); } return new ResponseEntity(task, HttpStatus.OK); } @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResponseEntity create(@RequestBody BudgetTempSheetEntity tempSheet, UriComponentsBuilder uriBuilder) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(tempSheet); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ budgetTempSheetService.save(tempSheet); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象. String id = tempSheet.getId(); URI uri = uriBuilder.path("/rest/budgetTempSheetController/" + id).build().toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uri); return new ResponseEntity(headers, HttpStatus.CREATED); } @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity update(@RequestBody BudgetTempSheetEntity tempSheet) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(tempSheet); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ budgetTempSheetService.saveOrUpdate(tempSheet); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码. return new ResponseEntity(HttpStatus.NO_CONTENT); } @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) public void delete(@PathVariable("id") String id) { budgetTempSheetService.deleteEntityById(BudgetTempSheetEntity.class, id); } @RequestMapping(params = "budgetactualdemo") public ModelAndView budgetactualdemo(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetActualspreadjsdemo"); } @RequestMapping(params = "budgetSubDemo") public ModelAndView budgetSubDemo(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetSubspreadjsdemo"); } @RequestMapping(params = "budgetActualSubspreadjsdemo") public ModelAndView budgetActualSubspreadjsdemo(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetActualSubspreadjsdemo"); } @RequestMapping(params = "budgetToolsDemo") public ModelAndView budgetToolsDemo(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetToolsDemo"); } @RequestMapping(params = "downloadword") public void downloadword(HttpServletRequest request,HttpServletResponse response)throws Exception { String fileName ="项目管理方案.docx"; fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1"); response.setHeader("Content-disposition", "attachment; filename="+fileName); response.setContentType("application/msword"); String path = request.getSession().getServletContext().getRealPath("/userfiles/files/demoTemplate.docx");//获取模板路径 String tempPath = request.getSession().getServletContext().getRealPath("/userfiles/files/demoTemplate1.docx");//获取模板路径 OutputStream outputStream = null; try { FileInputStream is = new FileInputStream(path);//读入流中 FileInputStream tempIs = new FileInputStream(tempPath); XWPFDocument xdf; xdf = new XWPFDocument(is); //新建一个word文档 XWPFDocument tempXdf = new XWPFDocument(tempIs); //变量 Map params = new HashMap(); params.put("year", request.getParameter("year")); params.put("manangercount", request.getParameter("manangercount")); params.put("totalcount", request.getParameter("totalcount")); params.put("sucuritycount", request.getParameter("sucuritycount")); params.put("cleanercount", request.getParameter("cleanercount")); params.put("maintenancecount", request.getParameter("maintenancecount")); params.put("meetingcount", request.getParameter("meetingcount")); params.put("totalwageclass", request.getParameter("totalwageclass")); params.put("wageclassmemo", request.getParameter("wageclassmemo")); params.put("apartcount", request.getParameter("apartcount")); params.put("totalwage", request.getParameter("totalwage")); params.put("sucuritywage", request.getParameter("sucuritywage")); params.put("cleanerwage", request.getParameter("cleanerwage")); params.put("maintenancewage", request.getParameter("maintenancewage")); params.put("meetingwage", request.getParameter("meetingwage")); params.put("apartwage", request.getParameter("apartwage")); params.put("managerwage", request.getParameter("managerwage")); this.replaceText(xdf,params);//替换word中的变量。 this.setStyle(tempXdf,xdf);//tempXdf-模板的格式,xdf-模板 outputStream = response.getOutputStream(); xdf.write(outputStream); response.flushBuffer(); } catch (Exception e) { logger.info("--通过流的方式获取文件异常--" + e.getMessage()); }finally{ if(outputStream != null){ outputStream.close(); } } } /** * 替换文档中的参数(word) * @param doc * @param params */ private void replaceText(XWPFDocument doc, Map params) { Iterator iterator = doc.getParagraphsIterator(); XWPFParagraph para; while (iterator.hasNext()) { para = iterator.next(); this.replaceInPara(para, params); } //处理table List tableList = doc.getTables(); if(tableList.size()>0) { for (XWPFTable xwpfTable : tableList) { for (XWPFTableRow row : xwpfTable.getRows()) { for(XWPFTableCell cell : row.getTableCells() ) { for(XWPFParagraph cellPara : cell.getParagraphs()) { this.replaceInPara(cellPara, params); } } } } } } /** * 替换段落中的参数(word) * @param para * @param params */ private void replaceInPara(XWPFParagraph para, Map params) { List runs; Matcher matcher; if (matcher(para.getParagraphText()).find()) { runs = para.getRuns(); for (int i=0; i iterator = tempDoc.getParagraphsIterator(); Iterator iterator2 = doc.getParagraphsIterator(); XWPFParagraph para ; XWPFParagraph para2; while (iterator.hasNext()&&iterator2.hasNext()) { para = iterator.next(); para2 = iterator2.next(); this.setStyleInPara(para,para2); } } /** * 处理段落替换内容的格式问题(word) * @param para * @param para2 */ private void setStyleInPara(XWPFParagraph para, XWPFParagraph para2) { List runs; List runs2; Matcher matcher; if (matcher(para.getParagraphText()).find()) { runs = para.getRuns(); runs2 = para2.getRuns(); for (int i=0; i entityList = new ArrayList<>(entityIdArray.length); for(String entityId:entityIdArray){ BudgetEntity budgetEntity = systemService.getEntity(BudgetEntity.class,entityId); if(StringUtil.equals(tempSheet.getDirection(),"up" )){ if(budgetEntity.getEntityUserId()==null) { j.setSuccess(false); j.setMsg("请填写预算实体:"+budgetEntity.getEntityName()+"的负责人。"); return j; } } entityList.add(budgetEntity); } budgetTempSheetService.publish(tempSheet,entityList); }catch(Exception e){ e.printStackTrace(); message = "下发失败"; j.setSuccess(false); // throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "cancel") @ResponseBody public AjaxJson cancel(BudgetTempSheetEntity tempSheet, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "撤销成功"; try{ String entityIds=request.getParameter("entityIds"); budgetTempSheetService.cancel(tempSheet.getId(),entityIds); }catch(Exception e){ e.printStackTrace(); message = "撤销失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } private void setGoMeasure(BudgetTempSheetEntity tempSheet, HttpServletRequest request){ String tempSheetId = tempSheet.getId(); String periodYear = tempSheet.getPeriodYear(); BudgetPeriodEntity periodEntity = systemService.findUniqueByProperty(BudgetPeriodEntity.class, "periodYear", periodYear); request.setAttribute("periodEntity", periodEntity); List periodDetailList = systemService.findByProperty(BudgetPeriodDetailEntity.class, "periodId", periodEntity.getId()); request.setAttribute("periodDetailList", periodDetailList); String tempSheetDepSql = "select group_concat(dept.entity_name) as entityNames,group_concat(dept.id) as entityIds from t_b_budget_tempsheet_entity dd ,t_b_budget_entity dept " + " where dd.entity_id=dept.id and dd.tempsheet_id=? "; Map tempSheetEntity =systemService.findOneForJdbc(tempSheetDepSql,tempSheetId); request.setAttribute("tempSheetEntity",tempSheetEntity ); List measureDataTypeList =systemService.getTypesByGroupcodeFromCache("budget_measure_datatype"); request.setAttribute("measureDataTypeList",measureDataTypeList ); } @RequestMapping(params = "select") public ModelAndView select(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-select"); } @RequestMapping(params = "selectDatagrid") public void selectDatagrid(BudgetTempSheetEntity tempSheet, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(BudgetTempSheetEntity.class, dataGrid); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tempSheet, request.getParameterMap()); try{ cq.isNotNull("json"); //自定义追加查询条件 }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); this.budgetTempSheetService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } @RequestMapping(params = "goAuth") public ModelAndView goAuth(BudgetTempSheetEntity tempSheet, HttpServletRequest req) { if (StringUtil.isNotEmpty(tempSheet.getId())) { tempSheet = budgetTempSheetService.getEntity(BudgetTempSheetEntity.class, tempSheet.getId()); req.setAttribute("entity", tempSheet); } return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-auth"); } @RequestMapping(params = "doSaveAuth") @ResponseBody public AjaxJson doSaveAuth(BudgetTempSheetEntity tempSheet, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "预算样表权限更新成功"; BudgetTempSheetEntity t = budgetTempSheetService.get(BudgetTempSheetEntity.class, tempSheet.getId()); try { MyBeanUtils.copyBeanNotNull2Bean(tempSheet, t); budgetTempSheetService.saveOrUpdate(t); systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); message = "预算样表权限更新失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "dimMatch") @ResponseBody public AjaxJson dimMatch(BudgetDimMatchDto dto, HttpServletRequest request) { AjaxJson j = new AjaxJson(); try { budgetDataService.dimMatch(dto); j.setObj(dto); }catch (Exception e){ j.setSuccess(false); e.printStackTrace(); } return j; } }