| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943 |
- 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<BudgetControlEntity> 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<TBGoodsCategoryEntity> 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<TSType> 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<BudgetEntity> 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<String, Object> dataMap = spreadJson.data(1);
- Map<String, Object> dataTable = (Map<String, Object>) dataMap.get("dataTable");
- List<BudgetTempSheetMeasureEntity> tempSheetMeasureEntityList = new ArrayList<>();
- List<String> usedMeasureIdList = new ArrayList<>();
- for(Map.Entry<String,Object> entry :dataTable.entrySet()){
- String row = entry.getKey();
- Map<String, Object> rowCols = (Map<String, Object>) entry.getValue();
- for(Map.Entry<String,Object> rowColsEntry :rowCols.entrySet()) {
- String col = rowColsEntry.getKey();
- Map<String, Object> cellMap = (Map<String, Object>) rowColsEntry.getValue();
- Map<String, Object> cellTag = (Map<String, Object>) 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<String,Object> 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<BudgetTempSheetEntity> 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<String, MultipartFile> fileMap = multipartRequest.getFileMap();
- for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
- MultipartFile file = entity.getValue();// 获取上传文件对象
- ImportParams params = new ImportParams();
- params.setTitleRows(2);
- params.setHeadRows(1);
- params.setNeedSave(true);
- try {
- List<BudgetTempSheetEntity> 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<BudgetTempSheetEntity> list() {
- List<BudgetTempSheetEntity> 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<ConstraintViolation<BudgetTempSheetEntity>> 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<ConstraintViolation<BudgetTempSheetEntity>> 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<String, Object> params = new HashMap<String, Object>();
- 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<String, Object> params) {
- Iterator<XWPFParagraph> iterator = doc.getParagraphsIterator();
- XWPFParagraph para;
- while (iterator.hasNext()) {
- para = iterator.next();
- this.replaceInPara(para, params);
- }
- //处理table
- List<XWPFTable> 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<String, Object> params) {
- List<XWPFRun> runs;
- Matcher matcher;
- if (matcher(para.getParagraphText()).find()) {
- runs = para.getRuns();
- for (int i=0; i<runs.size(); i++) {
- XWPFRun run = runs.get(i);
- String runText = run.toString();
- matcher = matcher(runText);
- if (matcher.find()) {
- while ((matcher = matcher(runText)).find()) {
- runText = matcher.replaceFirst(String.valueOf(params.get(matcher.group(1))));
- }
- para.removeRun(i);
- //重新插入run里内容格式可能与原来模板的格式不一致
- para.insertNewRun(i).setText(runText);
- }
- }
- }
- }
- /**
- * 处理文档替换内容的格式问题(word)
- * @param tempDoc
- * @param doc
- */
- private void setStyle(XWPFDocument tempDoc, XWPFDocument doc) {
- Iterator<XWPFParagraph> iterator = tempDoc.getParagraphsIterator();
- Iterator<XWPFParagraph> 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<XWPFRun> runs;
- List<XWPFRun> runs2;
- Matcher matcher;
- if (matcher(para.getParagraphText()).find()) {
- runs = para.getRuns();
- runs2 = para2.getRuns();
- for (int i=0; i<runs.size(); i++) {
- XWPFRun run = runs.get(i);
- XWPFRun run2 = runs2.get(i);
- String runText = run.toString();
- matcher = matcher(runText);
- if (matcher.find()) {
- //按模板文件格式设置格式
- run2.getCTR().setRPr(run.getCTR().getRPr());
- }
- }
- }
- }
- private Matcher matcher(String str) {
- Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
- Matcher matcher = pattern.matcher(str);
- return matcher;
- }
- @RequestMapping(params = "publish")
- @ResponseBody
- public AjaxJson publish(BudgetTempSheetEntity tempSheet, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "下发成功";
- try{
- tempSheet = systemService.getEntity(BudgetTempSheetEntity.class, tempSheet.getId());
- if(StringUtils.isBlank(tempSheet.getJson())){
- j.setSuccess(false);
- j.setMsg("样表没填写,下发失败.");
- return j;
- }
- String entityIds=request.getParameter("entityIds");
- String[] entityIdArray = StringUtil.splitString(entityIds, ",");
- List<BudgetEntity> 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<BudgetPeriodDetailEntity> 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<TSType> 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;
- }
- }
|