package cn.com.lzt.ordersfixasset.controller; import cn.com.lzt.arrangeduty.dao.UserOrgMinidao; import cn.com.lzt.arrangeduty.dto.UserOrgDto; import cn.com.lzt.common.controller.BaseLztController; import cn.com.lzt.common.util.DictUtil; import cn.com.lzt.common.util.LztUtil; import cn.com.lzt.common.util.UserUtil; import cn.com.lzt.common.view.JsonDataModelAndView; import cn.com.lzt.goodscategory.entity.TBGoodsCategoryEntity; import cn.com.lzt.goodsinfo.entity.TBGoodsInfoEntity; import cn.com.lzt.logistics.entity.TBLogisticsEntity; import cn.com.lzt.orders.entity.OrderMonthsEntity; import cn.com.lzt.orders.entity.OrdersFlowDto; import cn.com.lzt.ordersfixasset.dao.OrdersFixAssetDao; import cn.com.lzt.ordersfixasset.entity.OrderFixAssetProductsEntity; import cn.com.lzt.ordersfixasset.entity.OrdersFixAssetEntity; import cn.com.lzt.ordersfixasset.page.OrdersFixAssetPage; import cn.com.lzt.ordersfixasset.service.OrdersFixAssetServiceI; import cn.com.lzt.priceinfo.entity.TBPriceInfoEntity; import cn.com.lzt.relatedunits.entity.RelatedUnitsEntity; import cn.com.lzt.relatedunits.service.RelatedUnitsServiceI; import cn.com.lzt.tools.OrderNumTools; import cn.com.lzt.tools.SCMConsole; import cn.com.lzt.useractiviti.data.dao.UseractivitiDataDao; import cn.com.lzt.useractiviti.data.util.ActivitiPdfExport; import cn.com.lzt.useractiviti.data.util.ActivitiTools; import cn.com.lzt.warehouse.entity.WarehouseEntity; import com.lowagie.text.pdf.PdfPTable; import com.jeecg.qianbao.util.FormProcUtil; import com.xcgl.utils.XcglDateUtils; import com.xcgl.weixin.entity.WXAjaxJson; import com.xcgl.weixin.service.WXServiceI; import org.activiti.engine.HistoryService; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.impl.RepositoryServiceImpl; import org.activiti.engine.impl.persistence.entity.ExecutionEntity; import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity; import org.activiti.engine.impl.pvm.PvmTransition; import org.activiti.engine.impl.pvm.process.ActivityImpl; import org.activiti.engine.task.Task; import org.apache.commons.lang.CommonRandomUtil; import org.apache.commons.lang.xwork.StringUtils; import org.apache.log4j.Logger; import org.jeecgframework.core.beanvalidator.BeanValidators; import org.jeecgframework.core.common.dao.ICommonDao; 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.extend.hqlsearch.HqlGenerateUtil; 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.tag.vo.datatable.SortDirection; import org.jeecgframework.web.system.dao.JeecgDictDao; import org.jeecgframework.web.system.pojo.base.DictEntity; import org.jeecgframework.web.system.pojo.base.TSBaseUser; import org.jeecgframework.web.system.pojo.base.TSDepart; import org.jeecgframework.web.system.pojo.base.TSUser; import org.jeecgframework.web.system.service.SystemService; import org.jeecgframework.web.system.service.UserService; import org.jeecgframework.workflow.common.WorkFlowGlobals; import org.jeecgframework.workflow.dto.DealOptionDto; import org.jeecgframework.workflow.model.activiti.ProcessHandle; import org.jeecgframework.workflow.model.activiti.Variable; import org.jeecgframework.workflow.pojo.activiti.ActRuTask; import org.jeecgframework.workflow.pojo.activiti.ActRuVariable; import org.jeecgframework.workflow.pojo.base.TPBpmLog; import org.jeecgframework.workflow.pojo.base.TSBaseBusQuery; import org.jeecgframework.workflow.service.ActivitiService; import org.jeecgframework.workflow.service.impl.TaskJeecgService; import org.jeecgframework.workflow.user.entity.TPTaskCcEntity; 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.servlet.http.HttpSession; import javax.validation.ConstraintViolation; import javax.validation.Validator; import java.io.IOException; import java.math.BigDecimal; import java.net.URI; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; //import cn.com.lzt.weixin.service.WXServiceI; /** * @Title: Controller * @Description: 订单表 * @author onlineGenerator * @date 2017-06-07 17:15:24 * @version V1.0 * */ @Controller @RequestMapping("/ordersFixAssetController") public class OrdersFixAssetController extends BaseLztController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(OrdersFixAssetController.class); @Autowired private OrdersFixAssetServiceI ordersFixAssetService; @Autowired private SystemService systemService; @Autowired private Validator validator; @Autowired public ICommonDao commonDao = null; // @Autowired // private PaymentMiddleServiceI paymentMiddleService; @Autowired private RelatedUnitsServiceI relatedUnitsService; // @Autowired // private CollectMiddleServiceI collectMiddleService; @Autowired private OrdersFixAssetDao ordersFixAssetDao; @Autowired private JeecgDictDao jeecgDictDao; @Autowired private UserOrgMinidao userOrgdao; @Autowired private ActivitiService activitiService; @Autowired private TaskJeecgService taskJeecgService; @Autowired private TaskService taskService; @Autowired private RuntimeService runtimeService; @Autowired protected HistoryService historyService; @Autowired protected RepositoryService repositoryService; @Autowired protected WXServiceI wxservice; @Autowired protected UseractivitiDataDao useractivitiDataDao; @Autowired protected UserService userService; /** * 订单表列表 页面跳转 * * @return */ @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/orders/ordersList"); } /** * 订单表列表 页面跳转 * * @return */ @RequestMapping(params = "listByWarehouse") public ModelAndView listByWarehouse(HttpServletRequest request) { // 当前登录用户ID TSUser tsuser = ResourceUtil.getSessionUser(); String userid = tsuser.getId(); String orderFor = request.getParameter("orderFor"); boolean isProjectUser = UserUtil.isProjectUser(userid); request.setAttribute("isProjectUser", isProjectUser); if(isProjectUser) { String hql1 = "from WarehouseEntity where responsiblePerson=? and deleteFlag=0"; List warehouseList = systemService.findHql(hql1, userid); request.setAttribute("userid", userid); if (warehouseList.size() > 1) request.setAttribute("isMultiWarehouse", "1"); else if(warehouseList.size()==1){ request.setAttribute("isMultiWarehouse", "0"); request.setAttribute("warehouseid", warehouseList.get(0).getId()); }else { request.setAttribute("isMultiWarehouse", "0"); } } String role = userService.getUserRole(tsuser); request.setAttribute("fjl",StringUtils.contains(role, Globals.POSITION_TYPE_XZBFJL)); request.setAttribute("createByUserName",tsuser.getUserName()); ModelAndView mv = new ModelAndView("cn/com/lzt/ordersfixasset/ordersListByWarehouse"); if(StringUtils.isNotEmpty(orderFor) && orderFor.equals("1")) { //自行申购签报 mv = new ModelAndView("cn/com/lzt/ordersfixasset/ordersListByWarehouse-own"); request.setAttribute("orderFor", orderFor); }else { //固定物料申购(办公室) request.setAttribute("orderFor", "0"); } return mv; } /** * 请购单审批页面 * * @return */ @RequestMapping(params = "ordersList_task") public ModelAndView list_orderstask(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/ordersfixasset/ordersList_task"); } /** * 请购单审批页面加载 * * @return */ @RequestMapping(params = "datagrid_orderstask") public void datagrid_orderstask(OrdersFixAssetEntity orders,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(OrdersFixAssetEntity.class, dataGrid); String orderDateBegin = request.getParameter("orderDate_begin"); String orderDateEnd = request.getParameter("orderDate_end"); String orderOnumber = orders.getOrderOnumber(); if(StringUtils.isNotBlank(orderOnumber)){ orders.setOrderOnumber("*" +orderOnumber +"*"); } cq.addOrder("createDate", SortDirection.desc); //查询条件组装器 HqlGenerateUtil.installHql(cq, orders); try{ //自定义追加查询条件 if(StringUtils.isNotBlank(orderDateBegin) && StringUtils.isNotBlank(orderDateEnd)){ cq.ge("createDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateBegin + " 00:00:00")); cq.le("createDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateEnd + " 23:59:59")); } }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.notEq("bpmStatus", "1"); cq.add(); List list = ordersFixAssetService.getListByCriteriaQuery(cq, false); if(list == null || list.size()==0) { return; } List result = new ArrayList(); HashMap hm_id2obj = new HashMap<>(); for(OrdersFixAssetEntity oe : list) { hm_id2obj.put(oe.getId(), oe); } TSUser user = ResourceUtil.getSessionUser(); List taskList = this.activitiService.findPriTodoTasks(user.getUserName(), request); for(int i=0 ; i getWorkflowParam(HttpServletRequest request){ List result = new ArrayList<>(); String taskIdsInReq = oConvertUtils.getString(request.getParameter("taskId")); String dealOption = oConvertUtils.getString(request.getParameter("dealOption")); String transName = oConvertUtils.getString(request.getParameter("nextNodeName")); if("agree".equals(transName)) { transName = "通过"; }else { transName = "驳回"; } if(StringUtils.isEmpty(taskIdsInReq)) { return result; } String[] taskids = taskIdsInReq.split(","); for(int i=0 ; i dtos = getWorkflowParam(request); AjaxJson j = new AjaxJson(); String nextUser = oConvertUtils.getString(request.getParameter("id")); try { for(OrdersFlowDto dto : dtos) { ProcessHandle processHandle = this.activitiService.getProcessHandle(dto.getTaskId()); if(oConvertUtils.isEmpty(processHandle)) { j.setSuccess(false); j.setMsg(MutiLangUtil.getMutiLangInstance().getLang("process.task.notexist")); return j; } else { Map map = var.getVariableMap(processHandle.getTpProcesspros()); Task task = this.activitiService.getTask(dto.getTaskId()); String processInstanceId = task.getProcessInstanceId(); String ccUserNames=""; if("1".equals(dto.getModel())) { if("end".equals(dto.getNextnode())) { this.taskJeecgService.goProcessTaskNode(dto.getTaskId(), dto.getNextnode(), map); } else { this.taskJeecgService.goProcessTaskNode(dto.getTaskId(), dto.getNextnode(), map); ccUserNames = this.taskJeecgService.getTaskIdByProins(processInstanceId, dto.getNextnode()); } } //ccUserNames = oConvertUtils.getString(request.getParameter("ccUserNames")); this.taskCc(ccUserNames, task); TPBpmLog arg30 = new TPBpmLog(); TSUser arg31 = ResourceUtil.getSessionUser(); arg30.setBpm_id(task.getProcessInstanceId()); arg30.setTask_name(processHandle.getTpProcess().getProcessname()); arg30.setTask_node(processHandle.getTpProcessnode().getProcessnodename()); arg30.setOp_code(arg31.getUserKey()); arg30.setOp_name(arg31.getRealName()); arg30.setOp_time(DataUtils.gettimestamp()); // arg30.setLinename(nextNodeName); arg30.setTaskId(dto.getTaskId()); arg30.setMemo(dto.getDealOption()); String tableName = null; String busId = null; boolean hastep_name = false; String curttentstep = null; List actRuVariables = this.systemService.findByProperty(ActRuVariable.class, "actRuExecutionByProcInstId.id", processInstanceId); for(int list = 0; list < actRuVariables.size(); ++list) { ActRuVariable item = (ActRuVariable)actRuVariables.get(list); if(WorkFlowGlobals.BPM_FORM_KEY.equals(item.getName())) { tableName = item.getText(); } if(WorkFlowGlobals.BPM_DATA_ID.equals(item.getName())) { busId = item.getText(); } if("step_name".equals(item.getName())) { hastep_name = true; } } List arg32 = this.systemService.findByProperty(ActRuTask.class, "actRuExecutionByProcInstId.id", processInstanceId); if(oConvertUtils.isNotEmpty(arg32) && arg32.size() > 0) { curttentstep = ((ActRuTask)arg32.get(0)).getName(); } if(hastep_name) { this.activitiService.updateBusStepname(tableName, busId, curttentstep); } if("end".equals(dto.getNextnode())) { this.activitiService.updateBusStepname(tableName, busId, MutiLangUtil.getMutiLangInstance().getLang("process.complete")); } this.systemService.save(arg30); } } j.setMsg("审批成功!"); j.setObj(dtos); } catch (BusinessException arg28) { j.setSuccess(false); j.setMsg(MutiLangUtil.getMutiLangInstance().getLang("process.do.fail") + ":" + MutiLangUtil.getMutiLangInstance().getLang("process.nextnode.unknownerror")); arg28.printStackTrace(); } catch (Exception arg29) { j.setSuccess(false); j.setMsg(MutiLangUtil.getMutiLangInstance().getLang("process.do.fail") + ":" + MutiLangUtil.getMutiLangInstance().getLang("nextnode.nopersion.error")); arg29.printStackTrace(); } return j; } private void taskCc(String ccUserNames, Task task) { if(!CommonRandomUtil.isEmpty(ccUserNames)) { TSUser user = ResourceUtil.getSessionUser(); String[] ccUserNameArr = ccUserNames.split(","); TPTaskCcEntity taskCcEntity = null; String[] arg8 = ccUserNameArr; int arg7 = ccUserNameArr.length; for(int arg6 = 0; arg6 < arg7; ++arg6) { String ccUserName = arg8[arg6]; taskCcEntity = new TPTaskCcEntity(); taskCcEntity.setProcDefId(task.getProcessDefinitionId()); taskCcEntity.setProcInstId(task.getProcessInstanceId()); taskCcEntity.setExecutionId(task.getExecutionId()); taskCcEntity.setTaskDefKey(task.getTaskDefinitionKey()); taskCcEntity.setTaskId(task.getId()); taskCcEntity.setTaskName(task.getName()); taskCcEntity.setFromUserName(user.getUserName()); taskCcEntity.setCcUserName(ccUserName); this.systemService.save(taskCcEntity); } } } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "datagrid") public void datagrid(OrdersFixAssetEntity orders,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(OrdersFixAssetEntity.class, dataGrid); String orderDateBegin = request.getParameter("orderDate_begin"); String orderDateEnd = request.getParameter("orderDate_end"); String orderOnumber = orders.getOrderOnumber(); if(StringUtils.isNotBlank(orderOnumber)){ orders.setOrderOnumber("*" +orderOnumber +"*"); } String warehouseName = orders.getWarehouseName(); if(StringUtils.isNotBlank(warehouseName)){ orders.setWarehouseName("*" +warehouseName +"*"); } cq.addOrder("createDate", SortDirection.desc); //查询条件组装器 HqlGenerateUtil.installHql(cq, orders); try{ //自定义追加查询条件 if(StringUtils.isNotBlank(orderDateBegin) && StringUtils.isNotBlank(orderDateEnd)){ cq.ge("createDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateBegin + " 00:00:00")); cq.le("createDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateEnd + " 23:59:59")); } }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.notEq("bpmStatus", "1"); cq.add(); List list = ordersFixAssetService.getListByCriteriaQuery(cq, false); dataGrid.setResults(list); // this.ordersFixAssetService.getDataGridReturn(cq, false); dataGrid.setFooter("totalMoney,baojieSum,gongchengSum,bangongSum"); TagUtil.datagrid(response, dataGrid); } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "datagridByWarehouse") public void datagridByWarehouse(OrdersFixAssetEntity orders,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(OrdersFixAssetEntity.class, dataGrid); String orderDateBegin = request.getParameter("orderDate_begin"); String orderDateEnd = request.getParameter("orderDate_end"); String orderOnumber = orders.getOrderOnumber(); if(StringUtils.isNotBlank(orderOnumber)){ orders.setOrderOnumber("*" +orderOnumber +"*"); } cq.addOrder("createDate", SortDirection.desc); TSUser user = ResourceUtil.getSessionUser(); String role = userService.getUserRole(user); if(!StringUtils.contains(role, Globals.POSITION_TYPE_XZBFJL)){ orders.setCreateBy(user.getUserName()); } //查询条件组装器 HqlGenerateUtil.installHql(cq, orders); try{ //自定义追加查询条件 if(StringUtils.isNotBlank(orderDateBegin) && StringUtils.isNotBlank(orderDateEnd)){ cq.ge("createDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateBegin + " 00:00:00")); cq.le("createDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateEnd + " 23:59:59")); } }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); ordersFixAssetService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } protected List getUserWarehouse(){ TSUser tuser = ResourceUtil.getSessionUser(); UserOrgDto userOrgDto = new UserOrgDto(); userOrgDto.setUserId(tuser.getId()); List dtos = userOrgdao.getUserOrgDtoByUserId(userOrgDto , null); StringBuffer sb = new StringBuffer(); String sql = "select id from t_b_warehouse where responsible_person = '"+tuser.getId()+"'"; if(dtos != null && dtos.size()>0) { for(int i=0 ; i0) { sb.append(","); } sb.append("'"); sb.append(dtos.get(i).getOrgId()); sb.append("'"); } sql += " or project_id in("+sb.toString()+")"; } List tsDList = systemService.findListbySql(sql); boolean isProjectUser = UserUtil.isProjectUser(tuser.getId()); if(!isProjectUser) {//职能部门能看见总仓 tsDList.add("ff808081665bfece0166a8ebaa7f2738"); } return tsDList; } /** * 删除订单表 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(OrdersFixAssetEntity orders, HttpServletRequest request) { AjaxJson j = new AjaxJson(); orders = systemService.getEntity(OrdersFixAssetEntity.class, orders.getId()); String message = "订单表删除成功"; try{ ordersFixAssetService.delMain(orders); 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){ AjaxJson j = new AjaxJson(); String message = "订单表删除成功"; try{ for(String id:ids.split(",")){ OrdersFixAssetEntity orders = systemService.getEntity(OrdersFixAssetEntity.class, id ); ordersFixAssetService.delMain(orders); 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(OrdersFixAssetEntity orders,OrdersFixAssetPage ordersPage, HttpServletRequest request) { if(StringUtils.isNotBlank(orders.getId())){ return doUpdate(orders,ordersPage,request); } List orderProductsList = ordersPage.getOrderProductsList(); AjaxJson j = new AjaxJson(); String message = "添加成功"; try{ String warehouseid = orders.getWarehouseId(); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); WarehouseEntity wh = systemService.get(WarehouseEntity.class, warehouseid); orders.setWarehouseName(wh.getWarehouseName()); orders.setHandlerPersonId(tuser.getId()); orders.setHandlerPersonName(tuser.getRealName()); orders.setOrderOnumber(OrderNumTools.generate18OrderNum());// 采购单好 orders.setOrderStatus(Globals.UNAPPROVED);// 未审批状态 ordersFixAssetService.addMain(orders, orderProductsList); 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(OrdersFixAssetEntity orders, OrdersFixAssetPage ordersPage, HttpServletRequest request) { List orderProductsList = ordersPage.getOrderProductsList(); AjaxJson j = new AjaxJson(); String message = "更新成功"; try{ String warehouseid = orders.getWarehouseId(); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); WarehouseEntity wh = systemService.get(WarehouseEntity.class, warehouseid); orders.setWarehouseName(wh.getWarehouseName()); orders.setHandlerPersonId(tuser.getId()); orders.setHandlerPersonName(tuser.getRealName()); ordersFixAssetService.updateMain(orders, orderProductsList); 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(OrdersFixAssetEntity orders, HttpServletRequest req) { HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); req.setAttribute("userid", tuser.getId()); if (StringUtil.isNotEmpty(orders.getId())) { orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, orders.getId()); dealRoundHalfUpValue(orders); req.setAttribute("ordersPage", orders); }else{ String wareHourseId = req.getParameter("warehouseid"); String userId = tuser.getId(); boolean isProjectUser = UserUtil.isProjectUser(userId); WarehouseEntity warehouseEntity =null; if(StringUtils.isNotBlank(wareHourseId)) { warehouseEntity = systemService.getEntity(WarehouseEntity.class, wareHourseId); }else {//如果没有warehouseid 判断是否职能部门 if(!isProjectUser){//职能部门 默认公司本部 wareHourseId = "ff808081665bfece0166a8ebaa7f2738"; warehouseEntity = systemService.getEntity(WarehouseEntity.class, wareHourseId); }else{ return null; } } orders.setWarehouseId(wareHourseId); orders.setWarehouseName(warehouseEntity.getWarehouseName()); TSDepart userDepart ; if(isProjectUser) { String departId= warehouseEntity.getProjectId(); userDepart = systemService.getEntity(TSDepart.class,departId ); }else{ userDepart = useractivitiDataDao.getUserDep(userId); } orders.setDepartId(userDepart.getId()); orders.setDepName(userDepart.getGlcName()); orders.setOrderFor(req.getParameter("orderFor")); } req.setAttribute("ordersPage", orders); ModelAndView mv = new ModelAndView("cn/com/lzt/ordersfixasset/orders-add"); if(StringUtils.isNotEmpty(orders.getOrderFor()) && orders.getOrderFor().equals("1")) { mv = new ModelAndView("cn/com/lzt/ordersfixasset/orders-own-add"); } return mv; } /** * 订单表编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdateWithProcess") public ModelAndView goUpdateWithProcess(OrdersFixAssetEntity orders, HttpServletRequest req) { if(LztUtil.isApiRequest()) { return goUpdateWithProcessMobile(orders, req); } String isView = req.getParameter("viewFlag"); req.setAttribute("viewFlag", isView); String taskId = oConvertUtils.getString(req.getParameter("taskId")); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); req.setAttribute("userid", tuser.getId()); if(oConvertUtils.isNotEmpty(taskId)){ FormProcUtil.initWorkflowParam(req); req.setAttribute("taskId",taskId); } if (StringUtil.isNotEmpty(orders.getId())) { orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, orders.getId()); dealRoundHalfUpValue(orders); req.setAttribute("ordersPage", orders); }else{ List tsDList = systemService.findListbySql("select id from t_b_warehouse where responsible_person = '"+tuser.getId()+"'"); if(tsDList != null && tsDList.size()>0) { orders.setWarehouseId(tsDList.get(0)); } req.setAttribute("ordersPage", orders); } // Date now = new Date(); // Calendar begin = Calendar.getInstance(); // begin.setTime(now); // begin.add(Calendar.MONTH, -2); // // Calendar end = Calendar.getInstance(); // end.setTime(now); // end.add(Calendar.MONTH, 2); // // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // // req.setAttribute("ref_date_begin", sdf.format(begin.getTime())); // req.setAttribute("ref_date_end", sdf.format(end.getTime())); // // Calendar defaultdate = Calendar.getInstance(); // defaultdate.setTime(now); // int month = defaultdate.get(Calendar.MONTH); // if(month%2 == 0) { // //单月 // month += 1; // } // defaultdate.set(Calendar.MONTH, month); // defaultdate.set(Calendar.DATE, 1); // List ome = systemService.findListbySql("select id from t_b_ordermonths where ref_date='"+sdf.format(defaultdate.getTime())+"'"); // if(ome != null && ome.size()>0) { // orders.setOrderMonths(ome.get(0)); // } return new ModelAndView("cn/com/lzt/ordersfixasset/orders-proc-update"); } @RequestMapping(params = "goUpdateWithProcessMobile") public ModelAndView goUpdateWithProcessMobile(OrdersFixAssetEntity orders, HttpServletRequest req) { String isView = req.getParameter("viewFlag"); req.setAttribute("viewFlag", isView); String taskId = oConvertUtils.getString(req.getParameter("taskId")); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); req.setAttribute("userid", tuser.getId()); if(oConvertUtils.isNotEmpty(taskId)){ FormProcUtil.initWorkflowParam(req); req.setAttribute("taskId",taskId); } if (StringUtil.isNotEmpty(orders.getId())) { orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, orders.getId()); dealRoundHalfUpValue(orders); req.setAttribute("entity", orders); }else{ List tsDList = systemService.findListbySql("select id from t_b_warehouse where responsible_person = '"+tuser.getId()+"'"); if(tsDList != null && tsDList.size()>0) { orders.setWarehouseId(tsDList.get(0)); } req.setAttribute("entity", orders); } Map data = LztUtil.copyReqAttributes(new String[]{ "entity","viewFlag","taskId","userid"}); return new JsonDataModelAndView(WXAjaxJson.success(data)); } /** * 订单表编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(OrdersFixAssetEntity orders, HttpServletRequest req) { req.setAttribute("goUpdate", true); return goAdd(orders,req); } @RequestMapping(params = "goView") public ModelAndView goView(OrdersFixAssetEntity orders, HttpServletRequest request) { if(LztUtil.isApiRequest()) return goViewMobile(orders, request); String taskId = oConvertUtils.getString(request.getParameter("taskId")); if(oConvertUtils.isNotEmpty(taskId)){ FormProcUtil.initWorkflowParam(request); request.setAttribute("taskId",taskId); } if (StringUtil.isNotEmpty(orders.getId())) { orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, orders.getId()); // idandname(req, orders); dealRoundHalfUpValue(orders); request.setAttribute("ordersPage", orders); } request.setAttribute("in_process",true); // return new ModelAndView("cn/com/lzt/ordersfixasset/orders-View"); ModelAndView mv = new ModelAndView("cn/com/lzt/ordersfixasset/orders-add"); if(orders.getOrderFor().equals("1")) { mv = new ModelAndView("cn/com/lzt/ordersfixasset/orders-own-add"); } return mv; } @RequestMapping(params = "goViewMobile") public ModelAndView goViewMobile(OrdersFixAssetEntity orders, HttpServletRequest request) { request.setAttribute("viewFlag", "1"); String taskId = oConvertUtils.getString(request.getParameter("taskId")); if(oConvertUtils.isNotEmpty(taskId)){ FormProcUtil.initWorkflowParam(request); request.setAttribute("taskId",taskId); } if (StringUtil.isNotEmpty(orders.getId())) { orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, orders.getId()); dealRoundHalfUpValue(orders); request.setAttribute("entity", orders); } Map data = LztUtil.copyReqAttributes(new String[]{ "entity","viewFlag","taskId","load"}); data.put("flag", request.getParameter("flag")); return new JsonDataModelAndView(WXAjaxJson.success(data)); } // public void idandname(HttpServletRequest req, OrdersFixAssetEntity orders) { // WarehouseEntity warehouseEntity = systemService.findUniqueByProperty(WarehouseEntity.class, "id", orders.getWarehouseId()); // RelatedUnitsEntity relatedUnitsEntity = systemService.findUniqueByProperty(RelatedUnitsEntity.class, "id", orders.getSupplierName()); // TSBaseUser user = systemService.findUniqueByProperty(TSBaseUser.class, "id", orders.getHandlerPerson()); // // 经手人 // String handlerPersonName=""; // // 仓库 // String wareHouseName = ""; // // 供应商名 // String unitName = ""; // if (warehouseEntity != null) { // wareHouseName= warehouseEntity.getWarehouseName(); // req.setAttribute("wareHouseIdName", wareHouseName); // } // if (relatedUnitsEntity != null) { // unitName= relatedUnitsEntity.getUnitName(); // req.setAttribute("textUnitName", unitName); // } // // if (user != null) { // handlerPersonName= user.getRealName(); // req.setAttribute("realName", handlerPersonName); // } // } /** * 加载明细列表[采购商品] * * @return */ @RequestMapping(params = "orderProductsList") public ModelAndView orderProductsList(OrdersFixAssetEntity orders, HttpServletRequest req) { //=================================================================================== //获取参数 Object id0 = orders.getId(); orders = ordersFixAssetService.get(OrdersFixAssetEntity.class, (String)id0); //=================================================================================== //查询-采购商品 String hql0 = "from OrderFixAssetProductsEntity where 1 = 1 AND fK_ID =? "; try{ List OrderFixAssetProductsEntityList = systemService.findHql(hql0,id0); // addOnhandInfo2OrderProdunctsList(orders,OrderFixAssetProductsEntityList); req.setAttribute("orderProductsList", OrderFixAssetProductsEntityList); String load = (String)req.getAttribute("load"); req.setAttribute("load", load); }catch(Exception e){ logger.info(e.getMessage()); } String orderFor = req.getParameter("orderFor"); if(StringUtils.equals(orderFor, "1")){ return new ModelAndView("cn/com/lzt/ordersfixasset/orderProductsList-own"); } return new ModelAndView("cn/com/lzt/ordersfixasset/orderProductsList"); } /** * 加载审批明细列表[采购商品] * * @return */ @RequestMapping(params = "orderProductsViewList") public ModelAndView orderProductsViewList(OrdersFixAssetEntity orders, HttpServletRequest req) { //=================================================================================== //获取参数 Object id0 = orders.getId(); orders = ordersFixAssetService.get(OrdersFixAssetEntity.class, (String)id0); //=================================================================================== //查询-采购商品 String hql0 = "from OrderFixAssetProductsEntity where 1 = 1 AND fK_ID =? "; try{ List OrderFixAssetProductsEntityList = systemService.findHql(hql0,id0); addOnhandInfo2OrderProdunctsList(orders,OrderFixAssetProductsEntityList); req.setAttribute("orderProductsList", OrderFixAssetProductsEntityList); String load = (String)req.getAttribute("load"); req.setAttribute("load", load); }catch(Exception e){ logger.info(e.getMessage()); } return new ModelAndView("cn/com/lzt/orderproducts/orderProductsViewList"); } private void addOnhandInfo2OrderProdunctsList(OrdersFixAssetEntity orders, List list) { if(orders != null && list != null && list.size()>0) { String ordermonths = orders.getOrderMonths(); OrderMonthsEntity ordermonthsEntity = systemService.get(OrderMonthsEntity.class, ordermonths); String warehouseid = orders.getWarehouseId(); DateFormat format = new SimpleDateFormat("yyyy-MM"); String busiDate = format.format(ordermonthsEntity.getRefDate()); //暂时使用旧接口,带新功能启用后,再使用新接口 HashMap> onHandMap = ordersFixAssetService.queryGoodsOnhandDataForOrderAudit(busiDate,warehouseid, list); if(onHandMap != null) { for(OrderFixAssetProductsEntity entity : list) { String goodsid = entity.getGoodsId(); String unit = entity.getMeasureUnit(); HashMap result = onHandMap.get(goodsid+unit); if(result != null) { Double onhand = result.get(SCMConsole.ONHAND); Double last2MonthOutQuantity = result.get(SCMConsole.LAST2MONTHOUTQUANTITY); entity.setLastMonthUsedAmount(last2MonthOutQuantity); entity.setOnHandAmount(onhand); } } } } } /** * 加载审批明细可修改列表[采购商品] * * @return */ @RequestMapping(params = "orderProductsProcUpdateList") public ModelAndView orderProductsProcUpdateList(OrdersFixAssetEntity orders, HttpServletRequest req) { //=================================================================================== //获取参数 Object id0 = orders.getId(); orders = ordersFixAssetService.get(OrdersFixAssetEntity.class, (String)id0); //=================================================================================== //查询-采购商品 try{ List OrderFixAssetProductsEntityList = ordersFixAssetDao.getOrderProductsOrderByCategory((String)id0); addOnhandInfo2OrderProdunctsList(orders,OrderFixAssetProductsEntityList); req.setAttribute("orderProductsList", OrderFixAssetProductsEntityList); String load = (String)req.getAttribute("load"); req.setAttribute("load", load); }catch(Exception e){ logger.info(e.getMessage()); } return new ModelAndView("cn/com/lzt/orderproducts/orderProductsProcUpdateList"); } /** * 导出excel * * @param request * @param response */ @SuppressWarnings({ "rawtypes", "unchecked" }) @RequestMapping(params = "exportXls") public String exportXls(OrdersFixAssetEntity orders,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) { CriteriaQuery cq = new CriteriaQuery(OrdersFixAssetEntity.class, dataGrid); String orderDateBegin = request.getParameter("orderDate_begin"); String orderDateEnd = request.getParameter("orderDate_end"); // 模糊查询 String orderOnumber = orders.getOrderOnumber(); if(StringUtils.isNotBlank(orderOnumber)){ orders.setOrderOnumber("*" +orderOnumber +"*"); } //查询条件组装器 HqlGenerateUtil.installHql(cq, orders); try{ //自定义追加查询条件 if(StringUtils.isNotBlank(orderDateBegin) && StringUtils.isNotBlank(orderDateEnd)){ cq.ge("orderDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateBegin + " 00:00:00")); cq.le("orderDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateEnd + " 23:59:59")); } }catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); List list=this.ordersFixAssetService.getListByCriteriaQuery(cq, false); List listResult = null; List pageList=new ArrayList(); List OrderFixAssetProductsEntityListResult = null; if(list!=null&&list.size()>0){ Class clsOrder = MyClassLoader.getClassByScn("cn.com.lzt.orders.entity.OrdersFixAssetEntity"); try { listResult =systemService.dealResultShowText4Entities(list, clsOrder); } catch (Exception e1) { logger.info(e1.getMessage()); } for(OrdersFixAssetEntity entity:listResult){ try{ OrdersFixAssetPage page=new OrdersFixAssetPage(); MyBeanUtils.copyBeanNotNull2Bean(entity,page); Object id0 = entity.getId(); String hql0 = "from OrderFixAssetProductsEntity where 1 = 1 AND fK_ID =? "; List OrderFixAssetProductsEntityList = systemService.findHql(hql0,id0); Class cls = MyClassLoader.getClassByScn("cn.com.lzt.orderproducts.entity.OrderFixAssetProductsEntity"); OrderFixAssetProductsEntityListResult =systemService.dealResultShowText4Entities(OrderFixAssetProductsEntityList, cls); page.setOrderProductsList(OrderFixAssetProductsEntityListResult); pageList.add(page); }catch(Exception e){ logger.info(e.getMessage()); } } } map.put(NormalExcelConstants.FILE_NAME,"订单表"); map.put(NormalExcelConstants.CLASS,OrdersFixAssetPage.class); map.put(NormalExcelConstants.PARAMS,new ExportParams("订单表列表", "导出人:Jeecg", "导出信息")); map.put(NormalExcelConstants.DATA_LIST,pageList); return NormalExcelConstants.JEECG_EXCEL_VIEW; } /** * 导出excel * * @param request * @param response */ @SuppressWarnings({ "rawtypes", "unchecked" }) @RequestMapping(params = "exportXlsOrder") public String exportXlsOrder(String orderid,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) { TSUser user = ResourceUtil.getSessionUser(); OrdersFixAssetEntity order = systemService.get(OrdersFixAssetEntity.class, orderid); List details = systemService.findByProperty(OrderFixAssetProductsEntity.class, "fkId", orderid); map.put(NormalExcelConstants.FILE_NAME,"申购单-"+order.getWarehouseName()); map.put(NormalExcelConstants.CLASS,OrderFixAssetProductsEntity.class); ExportParams param = new ExportParams("申购单-"+order.getWarehouseName() ,"导出信息"); param.setAddIndex(true); map.put(NormalExcelConstants.PARAMS,param); map.put(NormalExcelConstants.DATA_LIST,details); return NormalExcelConstants.JEECG_EXCEL_VIEW; } /** * 通过excel导入数据 * @param request * @param * @return */ @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(2); params.setNeedSave(true); try { List list = ExcelImportUtil.importExcel(file.getInputStream(), OrdersFixAssetPage.class, params); OrdersFixAssetEntity entity1=null; for (OrdersFixAssetPage page : list) { entity1=new OrdersFixAssetEntity(); MyBeanUtils.copyBeanNotNull2Bean(page,entity1); ordersFixAssetService.addMain(entity1, page.getOrderProductsList()); } j.setMsg("文件导入成功!"); } catch (Exception e) { j.setMsg("文件导入失败!"); logger.error(ExceptionUtil.getExceptionMessage(e)); }finally{ try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return j; } /** * 导出excel 使模板 */ @RequestMapping(params = "exportXlsByT") public String exportXlsByT(ModelMap map) { map.put(NormalExcelConstants.FILE_NAME,"订单表"); map.put(NormalExcelConstants.CLASS,OrdersFixAssetPage.class); map.put(NormalExcelConstants.PARAMS,new ExportParams("订单表列表", "导出人:"+ ResourceUtil.getSessionUserName().getRealName(), "导出信息")); map.put(NormalExcelConstants.DATA_LIST,new ArrayList()); return NormalExcelConstants.JEECG_EXCEL_VIEW; } /** * 导入功能跳转 * * @return */ @RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name", "ordersController"); return new ModelAndView("common/upload/pub_excel_upload"); } @RequestMapping(method = RequestMethod.GET) @ResponseBody public List list() { List listOrderss=ordersFixAssetService.getList(OrdersFixAssetEntity.class); return listOrderss; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { OrdersFixAssetEntity task = ordersFixAssetService.get(OrdersFixAssetEntity.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 OrdersFixAssetPage ordersPage, UriComponentsBuilder uriBuilder) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(ordersPage); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 List orderProductsList = ordersPage.getOrderProductsList(); OrdersFixAssetEntity orders = new OrdersFixAssetEntity(); try{ MyBeanUtils.copyBeanNotNull2Bean(orders,ordersPage); }catch(Exception e){ logger.info(e.getMessage()); } ordersFixAssetService.addMain(orders, orderProductsList); //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象. String id = ordersPage.getId(); URI uri = uriBuilder.path("/rest/ordersController/" + 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 OrdersFixAssetPage ordersPage) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(ordersPage); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 List orderProductsList = ordersPage.getOrderProductsList(); OrdersFixAssetEntity orders = new OrdersFixAssetEntity(); try{ MyBeanUtils.copyBeanNotNull2Bean(orders,ordersPage); }catch(Exception e){ logger.info(e.getMessage()); } ordersFixAssetService.updateMain(orders, orderProductsList); //按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) { OrdersFixAssetEntity orders = ordersFixAssetService.get(OrdersFixAssetEntity.class, id); ordersFixAssetService.delMain(orders); } /** * 解析SQL,返回字段集 支持多数据源 * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(params = "getProductInfo", method = RequestMethod.POST) @ResponseBody public Object getSqlFields(String goodsCode){ TBGoodsInfoEntity goodInfo = null; TBPriceInfoEntity tBPriceInfoEntity = null; TBPriceInfoEntity tBPriceInfoEntityResult = null; Map reJson = new HashMap(); try{ //goodInfo = systemService.findUniqueByProperty(TBGoodsInfoEntity.class, "goodsCode",goodsCode); String hql_Goods = "from TBGoodsInfoEntity where 1 = 1 AND GOODS_CODE =? AND STATUS = 0 AND DELETE_FLAG = 0"; List tBGoodsInfoEntityList = systemService.findHql(hql_Goods,goodsCode); if(tBGoodsInfoEntityList != null && tBGoodsInfoEntityList.size() > 0){ goodInfo = tBGoodsInfoEntityList.get(0); }else{ reJson.put("status", "false"); return reJson; } String categoryHql = " FROM TBGoodsCategoryEntity where categoryCode =? or categoryCode =? order by categoryCode"; List categoryList = systemService.findHql(categoryHql,goodInfo.getBelongCategoryCode().substring(0,7),goodInfo.getBelongCategoryCode().substring(0,10)); if(categoryList != null && categoryList.size() == 2) { goodInfo.setCategoryname(categoryList.get(0).getCategoryName()+"-"+categoryList.get(1).getCategoryName()); }else { reJson.put("status", "false"); return reJson; } //获取参数 Object id0 = goodInfo.getId(); String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID =? "; List tBPriceInfoEntityList = systemService.findHql(hql0,id0); if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){ for(int i = 0 ;i < tBPriceInfoEntityList.size();i++){ tBPriceInfoEntity = new TBPriceInfoEntity(); tBPriceInfoEntity = tBPriceInfoEntityList.get(i); if(goodInfo.getPurchaseUnit() != null && tBPriceInfoEntity.getMeteringUnit() != null && goodInfo.getPurchaseUnit().equals(tBPriceInfoEntity.getMeteringUnit())){ tBPriceInfoEntityResult = tBPriceInfoEntity; break; } } } }catch (Exception e) { logger.info(e.getMessage()); } reJson.put("status", "success"); reJson.put("datainfo", goodInfo); reJson.put("pricinfo", tBPriceInfoEntityResult); return reJson; } /** * 解析SQL,返回字段集 支持多数据源 * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(params = "getPurchasePriceInfo", method = RequestMethod.POST) @ResponseBody public Object getPurchasePriceInfo(String goodsCode,String purchaseUnit){ Map reJson = new HashMap(); TBGoodsInfoEntity goodInfo = null; if(StringUtils.isNotBlank(goodsCode) && StringUtils.isNotBlank(purchaseUnit)){ TBPriceInfoEntity tBPriceInfoEntityResult = null; List unitlist = new ArrayList(); try{ goodInfo = systemService.findUniqueByProperty(TBGoodsInfoEntity.class, "goodsCode",goodsCode); String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID = ?"; List tBPriceInfoEntityList = systemService.findHql(hql0,goodInfo.getId()); if(tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0){ for(TBPriceInfoEntity price : tBPriceInfoEntityList) { unitlist.add(price.getMeteringUnit()); if(purchaseUnit.equals(price.getMeteringUnit())) { tBPriceInfoEntityResult = price; } } } if(tBPriceInfoEntityResult == null) { List dictList = jeecgDictDao.querySystemDict("metering_calcu_unit"); HashMap map = new HashMap<>(); for(DictEntity dic : dictList) { map.put(dic.getTypecode(), dic.getTypename()); } StringBuffer sb = new StringBuffer(); sb.append("可选择的计量单位:【"); for(int i=0 ; i0) { sb.append("/"); } sb.append(map.get(unitlist.get(i))); } sb.append("】"); reJson.put("msg", sb.toString()); } }catch (Exception e) { reJson.put("status", "fail"); logger.info(e.getMessage()); return reJson; } reJson.put("status", "success"); reJson.put("pricinfo", tBPriceInfoEntityResult); }else{ reJson.put("status", "success"); reJson.put("pricinfo", null); } return reJson; } /** * @param categoryName * @param categoryName * @return */ private String dealCateName(String categoryCode, String categoryName) { if(categoryCode.contains("rootA04")) { categoryName = "固定资产类-" + categoryName; }else if(categoryCode.contains("rootA05")) { categoryName = "应急采购类-" + categoryName; }else if(categoryCode.contains("rootA06")) { categoryName = "其他类-" + categoryName; } return categoryName; } /** * 经手人弹出框 * @param request * @param response * @param dataGrid * @throws ClassNotFoundException */ @SuppressWarnings({"rawtypes" }) @RequestMapping(params = "selRefDatagridHandlerPerson") public void selRefDatagridHandlerPerson(String classname,TSBaseUser tSBaseUser,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception { // Class cls = MyClassLoader.getClassByScn(classname); // CriteriaQuery cq = new CriteriaQuery(cls, dataGrid); // //自定义追加查询条件 // Short[] status = new Short[]{Globals.ONLINE,Globals.OFFLINE}; // cq.in("status", status); // cq.eq("deleteFlag", Globals.Delete_Normal); // // 检索用仓库编码 // if(StringUtils.isNotBlank(tSBaseUser.getUserName())){ // cq.eq("userName", tSBaseUser.getUserName()); // } // // 检索用仓库名称 // if(StringUtils.isNotBlank(tSBaseUser.getRealName())){ // cq.eq("realName", tSBaseUser.getRealName()); // } // org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cls.newInstance()); // commonDao.getDataGridReturn(cq, true); // List result = dataGrid.getResults(); // try { // //result =systemService.dealResultShowText4Entities(dataGrid.getResults(), cls); // } catch (Exception e) { // throw new BusinessException(e); // } // dataGrid.setResults(result); // TagUtil.datagrid(response, dataGrid); } /** * 经手人弹出框 * @return */ @RequestMapping(params = "selectReferHandlerPerson") public ModelAndView selectReferHandlerPerson(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cn/com/lzt/ordersfixasset/selectHandlerPersonInfo"); String ids = oConvertUtils.getString(request.getParameter("ids")); mv.addObject("ids", ids); // 需要将前端的类路径传递到refer页面 String clsname = oConvertUtils.getString(request.getParameter("classname")); mv.addObject("classname", clsname); mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield"))); mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield"))); return mv; } /** * 物流弹出框 * @param request * @param response * @param dataGrid * @throws ClassNotFoundException */ @SuppressWarnings({"rawtypes" }) @RequestMapping(params = "selRefDatagridLogistics") public void selRefDatagridLogistics(String classname,TBLogisticsEntity tBLogisticsEntity,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception { Class cls = MyClassLoader.getClassByScn(classname); CriteriaQuery cq = new CriteriaQuery(cls, dataGrid); //自定义追加查询条件 String[] unitstate = new String[]{Globals.Enable_Normal}; cq.in("status", unitstate); cq.eq("deleteFlag", Globals.Delete_Normal.toString()); // 检索用仓库编码 if(StringUtils.isNotBlank(tBLogisticsEntity.getCompanyCode())){ cq.eq("companyCode", tBLogisticsEntity.getCompanyCode()); } // 检索用仓库名称 if(StringUtils.isNotBlank(tBLogisticsEntity.getCompanyName())){ cq.eq("companyName", tBLogisticsEntity.getCompanyName()); } HqlGenerateUtil.installHql(cq, cls.newInstance()); commonDao.getDataGridReturn(cq, true); List result = dataGrid.getResults(); try { //result =systemService.dealResultShowText4Entities(dataGrid.getResults(), cls); } catch (Exception e) { throw new BusinessException(e); } dataGrid.setResults(result); TagUtil.datagrid(response, dataGrid); } /** * 物流弹出框 * @return */ @RequestMapping(params = "selectReferLogistics") public ModelAndView selectReferLogistics(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cn/com/lzt/ordersfixasset/selectLogisticsInfo"); String ids = oConvertUtils.getString(request.getParameter("ids")); mv.addObject("ids", ids); // 需要将前端的类路径传递到refer页面 String clsname = oConvertUtils.getString(request.getParameter("classname")); mv.addObject("classname", clsname); mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield"))); mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield"))); return mv; } /** * 取消采购单 * * @author guoqing.yan */ @RequestMapping(params = "doCancel") @ResponseBody public AjaxJson doCancel(String id, HttpServletRequest req) { AjaxJson j = new AjaxJson(); String message = null; OrdersFixAssetEntity orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, id); try{ // 未审批和已经审批的可以取消 if(orders.getOrderStatus() != null &&(orders.getOrderStatus().equals(Globals.UNAPPROVED) || orders.getOrderStatus().equals(Globals.APPROVED))){ orders.setOrderStatus(Globals.CANCELED);//订单状态: 取消 ordersFixAssetService.updateEntitie(orders); message = "单号:" + orders.getOrderOnumber() + "取消成功!"; systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); }else{ message = "该单不能取消,请确认!"; } }catch(Exception e){ message = "操作失败!"; } j.setMsg(message); return j; } private void dealRoundHalfUpValue(OrdersFixAssetEntity entity) { BigDecimal guding = entity.getGudingSum() == null ? BigDecimal.ZERO : new BigDecimal(entity.getGudingSum()); entity.setGudingSum(guding.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); BigDecimal yingji = entity.getYingjiSum() == null ? BigDecimal.ZERO : new BigDecimal(entity.getYingjiSum()); entity.setYingjiSum(yingji.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); BigDecimal qita = entity.getQitaSum() == null ? BigDecimal.ZERO : new BigDecimal(entity.getQitaSum()); entity.setQitaSum(qita.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); } /** * 取消采购单 * * @author guoqing.yan */ @RequestMapping(params = "doCancelAuditOrder") @ResponseBody public AjaxJson doCancelAuditOrder(String id,String refundvalue, HttpServletRequest req) { AjaxJson j = new AjaxJson(); String message = null; OrdersFixAssetEntity orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, id); // try{ // // 首先判断该订单是否入库,如果入库则不能取消 // Long godownOrderCount = systemService.getCountForJdbc("select count(1) from t_b_godown_entry where purchase_order_no='" + orders.getOrderOnumber() + "'"); // // 未入库时候 // if(godownOrderCount <=0){ // if(StringUtils.isNotBlank(refundvalue)){ // // 退的预付定金额 // Double refundMoney = Double.parseDouble(refundvalue); // CollectMiddleEntity collectMiddleEntity = new CollectMiddleEntity(); // collectMiddleEntity.setUnitId(orders.getSupplierId());// 供应商ID // collectMiddleEntity.setCollectionOrderOnumber(orders.getOrderOnumber());//订单号 // collectMiddleEntity.setCollectionType(Globals.DEPOSIT_REFUND);// 预付定金退款 // collectMiddleEntity.setAmountReceivable(refundMoney); // collectMiddleService.saveOrUpdate(collectMiddleEntity); // // 更新 往来单位表中的 应收余额 // RelatedUnitsEntity relatedUnitsEntity = relatedUnitsService.get(RelatedUnitsEntity.class, orders.getSupplierId()); // if(relatedUnitsEntity.getAmountReceivable() != null){ // relatedUnitsEntity.setPrepaidBalance(refundMoney + relatedUnitsEntity.getAmountReceivable());// 预付余额 // }else{ // relatedUnitsEntity.setPrepaidBalance(refundMoney);// 预付余额 // } // relatedUnitsService.updateEntitie(relatedUnitsEntity); // } // // 未审批和已经审批的可以取消 // if(orders.getOrderStatus() != null && !orders.getOrderStatus().equals(Globals.CANCELED)){ // orders.setOrderStatus(Globals.CANCELED);//订单状态: 取消 // ordersFixAssetService.updateEntitie(orders); // message = "单号:" + orders.getOrderOnumber() + "取消成功!"; // systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); // }else{ // message = "该单已经取消,请确认!"; // } // // 已经入库的时候 // }else{ // message = "该订单已经入库,不能取消,请确认!"; // } // // }catch(Exception e){ // message = "操作失败!"; // } j.setMsg(message); return j; } /** * 审核通过 采购单 * * @author guoqing.yan */ @RequestMapping(params = "doAudit") @ResponseBody public AjaxJson doAudit(String id, HttpServletRequest req) { AjaxJson j = new AjaxJson(); String message = null; OrdersFixAssetEntity orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, id); try{ // 未审批和已经审批的可以取消 if(orders.getOrderStatus() != null &&orders.getOrderStatus().equals(Globals.UNAPPROVED)){ // 预付定金 不为空的时候 if(orders.getPrepaidMoney() != null && orders.getPrepaidMoney() >0){ // 更新 付款明细中间表 // PaymentMiddleEntity paymentMiddleEntity = new PaymentMiddleEntity(); // paymentMiddleEntity.setUnitId(orders.getSupplierId());// 供应商ID // paymentMiddleEntity.setPaymentDate(new Date());// 应付款发生日期 // paymentMiddleEntity.setPaymentOrderOnumber(orders.getOrderOnumber());// 应付款单据编号 // paymentMiddleEntity.setPaymentType(Globals.PURCHASE_ADVANCE_PAYMENT);// 应付款类型 采购预付款 // paymentMiddleEntity.setHandlerPerson(orders.getHandlerPersonId());// 经手人 // paymentMiddleEntity.setAmountPayable(orders.getPrepaidMoney());// 应付定金 // paymentMiddleService.save(paymentMiddleEntity); // 更新 往来单位表中的 预付余额 RelatedUnitsEntity relatedUnitsEntity = relatedUnitsService.get(RelatedUnitsEntity.class, orders.getSupplierId()); if(relatedUnitsEntity.getPrepaidBalance() != null){ relatedUnitsEntity.setPrepaidBalance(orders.getPrepaidMoney() + relatedUnitsEntity.getPrepaidBalance());// 预付余额 }else{ relatedUnitsEntity.setPrepaidBalance(orders.getPrepaidMoney());// 预付余额 } relatedUnitsService.updateEntitie(relatedUnitsEntity); } // 采购单审核状态更新 ordersFixAssetService.updateEntitie(orders); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER"); orders.setAuditDate(new Date()); orders.setOrderAuditor(tuser.getRealName()); orders.setOrderStatus(Globals.APPROVED);//订单状态: 已审批 message = "单号:" + orders.getOrderOnumber() + "已生效!"; systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); }else{ message = "该单已经取消或者已生效,不能提交生效,请确认!"; } }catch(Exception e){ message = "操作失败!"; } j.setMsg(message); return j; } @RequestMapping(params = "doCheckNotSubnitWarehouse") @ResponseBody public AjaxJson doCheckNotSubnitWarehouse(String id,String refundvalue, HttpServletRequest req) { AjaxJson j = new AjaxJson(); String message = null; try { String monthSql = "select id from t_b_ordermonths where ref_date = ?"; String monthFirstDay = DateUtils.date_sdf.format(new Date()).substring(0, 7)+"-01"; if (monthFirstDay.substring(5, 7).equals("01") || monthFirstDay.substring(5, 7).equals("03") ||monthFirstDay.substring(5, 7).equals("05") || monthFirstDay.substring(5, 7).equals("07") ||monthFirstDay.substring(5, 7).equals("09") ||monthFirstDay.substring(5, 7).equals("11")) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.MONTH, -1); Date lastMonthDate = cal.getTime(); monthFirstDay = DateUtils.date_sdf.format(lastMonthDate).substring(0, 7)+"-01"; } List> res = systemService.findForJdbc(monthSql, monthFirstDay); if(res.size() == 0) return j; wxservice.sendMsgToWXForOrdersNotSubmit(res.get(0).get("id").toString()); message = "消息发送成功,请行政经理查看美都环卫微管理"; }catch (Exception e) { logger.error(e.getMessage()); message = "操作失败,请联系系统管理员查看失败原因。"; } j.setMsg(message); return j; } @RequestMapping(params = "checkGoAdd") @ResponseBody public AjaxJson checkGoAdd(String warehouseid, HttpServletRequest request) { AjaxJson j = new AjaxJson(); //暂时取消校验,待物料二期正式使用时,在启用此校验 // if(true) // return j; TSUser tuser = ResourceUtil.getSessionUser(); if(StringUtils.isEmpty(warehouseid)){ List tsDList = systemService.findListbySql("select id from t_b_warehouse where responsible_person = '"+tuser.getId()+"'"); if(tsDList != null && tsDList.size()>0) { warehouseid = tsDList.get(0); } } String message = ""; String lastMonth = XcglDateUtils.addDateMonth(new Date(), -1, DateUtils.date_sdf).substring(0,7); //查询上个月出库单 String noStorageOutSql = "select * from t_b_storage_out where warehouseid =? and left(outdate,7) =? "; String onhandSql = "select * from t_b_onhandreport where warehouse_id =? and order_date =? "; String hasPorderSql = "select id from t_b_porders where warehouse_id = '"+warehouseid+"' and left(order_date,4) > '2019' order by order_date desc LIMIT 1"; String orderstotalSql = "select count(*) as totalrows from t_b_orders where warehouse_id =? "; //新建领料点,可以直接申请物料 List> ordersCount = systemService.findForJdbc(orderstotalSql, warehouseid); if(Integer.parseInt(ordersCount.get(0).get("totalrows").toString()) == 0) return j; List idList = systemService.findListbySql(hasPorderSql); //查询上一个采购单的核对单 String noStorageInSql = "select * from t_b_storage_in where porderid in ( select id from ( " + "select id from t_b_porders where warehouse_id =? order by order_date desc LIMIT 1 )as t)" ; List> retout = systemService.findForJdbc(noStorageOutSql, warehouseid,lastMonth); List> retOnhand = systemService.findForJdbc(onhandSql, warehouseid,lastMonth); List> retin = systemService.findForJdbc(noStorageInSql, warehouseid); //如果上个月库存上报单及领料出库单都没有,则提示,保障系统初始运行时无错误逻辑 if(retOnhand.size() == 0 && retout.size() == 0 ){ message = lastMonth+"未进行领料出库,请填写领料出库后再进行物料申购"; } //如果有采购单,并且采购单没有进行核对,则提示 if(idList.size() > 0 && retin.size() == 0){ message = "此领料点上次采购单未进行采购核对,请填写采购单核对后再进行物料申购"; } if(StringUtils.isNotEmpty(message)) { j.setSuccess(false); j.setMsg(message); } return j; } @RequestMapping(params="exportDetailPdf4Mobile") public void exportDetailPdf4Mobile( @RequestParam("procInstId") String procInstId ,@RequestParam(value = "flag",required = false,defaultValue = "2") Integer flag ,HttpServletRequest request, HttpServletResponse response){ ActivitiTools tools = ActivitiTools.getInstance(procInstId,true); tools.setProcInstId(null); ActivitiPdfExport pdfExport = tools.getPdfExport(); String id = tools.getBusId(); OrdersFixAssetEntity orders = ordersFixAssetService.getEntity(OrdersFixAssetEntity.class, id); String orderFor= orders.getOrderFor(); String orderForTxt; if(orderFor.equals("0")){ orderForTxt="公司采购"; }else{ orderForTxt="自行采购"; } boolean showMoney = (flag>=3 || orderFor.equals("1")); pdfExport.table() .cell("领料点",orders.getWarehouseName()).cell("采购方式",orderForTxt).cell("组织机构",orders.getDepName()); if(showMoney) { pdfExport.cell("总金额", orders.getTotalMoney() == null ? "0" : orders.getTotalMoney().toString()); /*.cell("固定资产类金额", orders.getGudingSum() == null ? "0" : orders.getGudingSum().toString()) .cell("应急采购类金额", orders.getYingjiSum() == null ? "0" : orders.getYingjiSum().toString()) .cell("其他类金额", orders.getQitaSum() == null ? "0" : orders.getQitaSum().toString());*/ } pdfExport.cell("备注说明",orders.getDescription()); String hql0 = "from OrderFixAssetProductsEntity where 1 = 1 AND fK_ID =? "; try{ List OrderFixAssetProductsEntityList = systemService.findHql(hql0,id); pdfExport.cell(""); int detailColumnNum =showMoney?7:5; PdfPTable detailTableHeader = pdfExport.createTable(detailColumnNum); detailTableHeader.setWidthPercentage(100); pdfExport.cell(detailTableHeader, "货品名称", true); pdfExport.cell(detailTableHeader, "货品分类", true); pdfExport.cell(detailTableHeader, "计量单位", true); pdfExport.cell(detailTableHeader, "数量", true); if(showMoney) { pdfExport.cell(detailTableHeader, "采购单价(元)", true); pdfExport.cell(detailTableHeader, "金额(元)", true); } pdfExport.cell(detailTableHeader, "备注", true); pdfExport.cell(detailTableHeader); int i = 0; for(OrderFixAssetProductsEntity detailEntity:OrderFixAssetProductsEntityList){ i++; PdfPTable detailTable = pdfExport.createTable(detailColumnNum); pdfExport.cell(detailTable,detailEntity.getPname(),false); pdfExport.cell(detailTable, detailEntity.getBelongCategoryName(), false); pdfExport.cell(detailTable, DictUtil.formatToTypeName(detailEntity.getMeasureUnit(),"metering_calcu_unit") , false); pdfExport.cell(detailTable, detailEntity.getQuantity().toString(), false); if(showMoney) { pdfExport.cell(detailTable, detailEntity.getPurchasePrice().toString(), false); pdfExport.cell(detailTable, detailEntity.getMoney().toString(), false); } pdfExport.cell(detailTable,detailEntity.getRemark(), false); pdfExport.cell("明细"+i,true); pdfExport.cell(detailTable); } }catch(Exception e){ e.printStackTrace(); logger.info(e.getMessage()); } tools.exportToResponse(response); } /** * 选择物料签报单 员工报销 * @return */ @RequestMapping(params = "ordersFixAssetSelect4CostPay") public String ordersFixAssetSelect4CostPay(){ return "cn/com/lzt/ordersfixasset/select_orders_fix_asset_cost_pay"; } @RequestMapping(params = "ordersFixAssetSelect4CostPayDatagrid") public void ordersFixAssetSelect4CostPayDatagrid(OrdersFixAssetEntity entity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid){ TSUser user = ResourceUtil.getSessionUser(); boolean projectUser = UserUtil.isProjectUser(user.getId()); // List warehouseIdList = getUserWarehouse(); String role = userService.getUserRole(user); if(!StringUtils.contains(role, Globals.POSITION_TYPE_XZBFJL)){ entity.setCreateBy(user.getUserName()); entity.setOrderFor("1"); } List ordersList =ordersFixAssetDao.getOrders4CostPay(entity,user.getId(),projectUser,null); dataGrid.setResults(ordersList); dataGrid.setTotal(ordersList.size()); TagUtil.datagrid(response, dataGrid); } /** * 选择物料签报详情单 对外付款 * @return */ @RequestMapping(params = "ordersFixAssetDetailSelect4CostPay") public String ordersFixAssetDetailSelect4CostPay(){ return "cn/com/lzt/ordersfixasset/select_orders_fix_asset_detail_cost_pay"; } @RequestMapping(params = "ordersFixAssetDetailSelect4CostPayDatagrid") public void ordersFixAssetDetailSelect4CostPayDatagrid(OrderFixAssetProductsEntity entity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid){ TSUser user = ResourceUtil.getSessionUser(); boolean projectUser = UserUtil.isProjectUser(user.getId()); // List warehouseIdList = getUserWarehouse(); entity.setId(request.getParameter("updateId")); String role = userService.getUserRole(user); if(!StringUtils.contains(role, Globals.POSITION_TYPE_XZBFJL)){ entity.setCreateBy(user.getUserName()); entity.setOrderFor("1"); } List ordersList =ordersFixAssetDao.getOrderProducts4CostPay(entity,user.getId(),projectUser,null); dataGrid.setResults(ordersList); dataGrid.setTotal(ordersList.size()); TagUtil.datagrid(response, dataGrid); } }