package cn.com.lzt.orders.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.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.orderproducts.entity.OrderProductsEntity; import cn.com.lzt.orders.dao.OrdersDao; import cn.com.lzt.orders.entity.OrderMonthsEntity; import cn.com.lzt.orders.entity.OrdersEntity; import cn.com.lzt.orders.entity.OrdersFlowDto; import cn.com.lzt.orders.entity.ProductSpecificationLimitEntity; import cn.com.lzt.orders.page.OrdersPage; import cn.com.lzt.orders.service.OrdersServiceI; 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.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.hibernate.criterion.Disjunction; import org.hibernate.criterion.Restrictions; 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.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.TSUser; import org.jeecgframework.web.system.service.SystemService; 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; /** * @author onlineGenerator * @version V1.0 * @Title: Controller * @Description: 订单表 * @date 2017-06-07 17:15:24 */ @Controller @RequestMapping("/ordersController") public class OrdersController extends BaseLztController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(OrdersController.class); @Autowired private OrdersServiceI ordersService; @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 OrdersDao orderdao; @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; /** * 订单表列表 页面跳转 * * @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 String userid = ResourceUtil.getSessionUser().getId(); // 仓库查询语句(状态为可用0) String status = "0"; String hql1 = "from WarehouseEntity where status = ?"; List warehouseList = systemService.findHql(hql1, status); request.setAttribute("userid", userid); // 查询可用仓库 if (warehouseList.size() > 1) request.setAttribute("isMultiWarehouse", "1"); else { request.setAttribute("isMultiWarehouse", "0"); if (warehouseList.size() == 1) { request.setAttribute("wareHouse", warehouseList.get(0)); } } String orderType = request.getParameter("orderType"); if (StringUtils.isEmpty(orderType)) orderType = "1"; request.setAttribute("orderType", orderType); ModelAndView mv = new ModelAndView("cn/com/lzt/orders/ordersListByWarehouse"); // delete-刘梦祥-2021年11月17日13:14:19(物料申购暂时只有一种,所以删除原本的收购类型判断) // if(orderType.equals("1"))//月度申购 // mv = new ModelAndView("cn/com/lzt/orders/ordersListByWarehouse"); // else if (orderType.equals("2"))//临时申购 // mv = new ModelAndView("cn/com/lzt/orders/ordersListByWarehouse-temp"); // else if (orderType.equals("3"))//代业主申购 // mv = new ModelAndView("cn/com/lzt/orders/ordersListByWarehouse-representOwner"); return mv; } /** * 请购单审批页面 * * @return */ @RequestMapping(params = "ordersList_task") public ModelAndView list_orderstask(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/orders/ordersList_task"); } /** * 请购单审批页面加载 * * @return */ @RequestMapping(params = "datagrid_orderstask") public void datagrid_orderstask(OrdersEntity orders, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(OrdersEntity.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); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.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 = ordersService.getListByCriteriaQuery(cq, false); if (list == null || list.size() == 0) { return; } List result = new ArrayList(); HashMap hm_id2obj = new HashMap<>(); for (OrdersEntity 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 < taskList.size(); i++) { TSBaseBusQuery busobj = (TSBaseBusQuery) taskList.get(i); String id = activitiService.getBusinessKeyByTask(busobj.getProcess().getTask().getId()); OrdersEntity order = hm_id2obj.get(id); if (order != null) { result.add(order); order.setProcessObject(busobj); } } dataGrid.setResults(result); dataGrid.setFooter("totalMoney,baojieSum,gongchengSum,bangongSum"); TagUtil.datagrid(response, dataGrid); } @RequestMapping(params = {"popDealOption"}) public ModelAndView popDealOption(DealOptionDto dto, HttpServletRequest request) { request.setAttribute("dealParam", dto); return new ModelAndView("cn/com/lzt/orders/dealOrderFlowWriteOption"); } public Task getTask(String taskId) { return (Task) this.taskService.createTaskQuery().taskId(taskId).singleResult(); } /** * 获取任务下一步节点的id * * @param taskId * @param transName 通过或者驳回 * @return */ private String getTaskNextNodeId(String taskId, String transName) { List outTransitions = null; ArrayList trans = new ArrayList(); Task task = this.getTask(taskId); ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) this.repositoryService).getDeployedProcessDefinition(task.getProcessDefinitionId()); List activitiList = def.getActivities(); String excId = task.getExecutionId(); ExecutionEntity execution = (ExecutionEntity) this.runtimeService.createExecutionQuery().executionId(excId).singleResult(); String activitiId = execution.getActivityId(); Iterator arg10 = activitiList.iterator(); while (arg10.hasNext()) { ActivityImpl activityImpl = (ActivityImpl) arg10.next(); String id = activityImpl.getId(); if (activitiId.equals(id)) { outTransitions = activityImpl.getOutgoingTransitions(); Iterator arg13 = outTransitions.iterator(); while (arg13.hasNext()) { PvmTransition tr = (PvmTransition) arg13.next(); if (tr.getId() != null) { String name = (String) (oConvertUtils.isNotEmpty(tr.getProperty("name")) ? tr.getProperty("name") : tr.getId()); if (transName.equals(name)) { return tr.getDestination().getId(); } } } return null; } } return null; } private List 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 < taskids.length; i++) { String nextNode = getTaskNextNodeId(taskids[i], transName); OrdersFlowDto dto = new OrdersFlowDto(); dto.setDealOption(dealOption); dto.setModel("1"); dto.setNextnode(nextNode); dto.setTaskId(taskids[i]); dto.setOperateType(transName); result.add(dto); } return result; } /** * 批量审批 * * @param request * @param var * @return * @throws Exception */ @RequestMapping(params = {"processComplete"}) @ResponseBody public AjaxJson processComplete(HttpServletRequest request, Variable var) throws Exception { List 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(OrdersEntity orders, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(OrdersEntity.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); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.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 = ordersService.getListByCriteriaQuery(cq, false); dataGrid.setResults(list); // this.ordersService.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(OrdersEntity orders, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(OrdersEntity.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); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, orders); try { //自定义追加查询条件 if (StringUtils.isNotBlank(orderDateBegin)) { cq.ge("orderDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderDateBegin + " 00:00:00")); } if (StringUtils.isNotBlank(orderDateEnd)) { 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(); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER"); 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() + "' and delete_flag = 0"; if (dtos != null && dtos.size() > 0) { for (int i = 0; i < dtos.size(); i++) { if (i > 0) { sb.append(","); } sb.append("'"); sb.append(dtos.get(i).getOrgId()); sb.append("'"); } sql += " or project_id in(" + sb.toString() + ")"; } List tsDList = systemService.findListbySql(sql); if (tsDList != null && tsDList.size() > 0) { cq.in("warehouseId", tsDList.toArray()); cq.add(); List ordersList = ordersService.getListByCriteriaQuery(cq, false); if (ordersList == null || ordersList.size() == 0) { dataGrid.setResults(new ArrayList()); TagUtil.datagrid(response, dataGrid); } List result = new ArrayList(); HashMap hm_id2obj = new HashMap<>(); for (OrdersEntity oe : ordersList) { hm_id2obj.put(oe.getId(), oe); } TSUser user = ResourceUtil.getSessionUser(); List taskList = this.activitiService.findPriTodoTasks(user.getUserName(), request); for (int i = 0; i < taskList.size(); i++) { TSBaseBusQuery busobj = (TSBaseBusQuery) taskList.get(i); String id = activitiService.getBusinessKeyByTask(busobj.getProcess().getTask().getId()); OrdersEntity order = hm_id2obj.get(id); if (order != null) { result.add(order); order.setProcessObject(busobj); } } dataGrid.setResults(ordersList); TagUtil.datagrid(response, dataGrid); } else { dataGrid.setResults(new ArrayList()); TagUtil.datagrid(response, dataGrid); } } /** * 删除订单表 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(OrdersEntity orders, HttpServletRequest request) { AjaxJson j = new AjaxJson(); orders = systemService.getEntity(OrdersEntity.class, orders.getId()); String message = "订单表删除成功"; try { ordersService.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(",")) { OrdersEntity orders = systemService.getEntity(OrdersEntity.class, id ); ordersService.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(OrdersEntity orders, OrdersPage ordersPage, HttpServletRequest request) { List orderProductsList = ordersPage.getOrderProductsList(); AjaxJson j = new AjaxJson(); String message = "添加成功"; try { String months = orders.getOrderMonths(); String warehouseid = orders.getWarehouseId(); if ("1".equals(orders.getOrderType())) { // 月度申购类型 String sql = "select id from t_b_orders where order_months='" + months + "' and warehouse_id='" + warehouseid + "' and order_type =? "; List tsDList = systemService.findListbySql(sql, "1"); if (tsDList != null && tsDList.size() > 0) { j.setSuccess(false); j.setMsg("不能重复进行月度申购,如需临时申购,请联系行政部开发临时申购权限。"); return j; } } 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);// 未审批状态 //代业主申购时,没有双月信息,需要补充双月信息 if (StringUtils.isEmpty(orders.getOrderMonths())) { createOrderMonths(orders); } ordersService.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; } private void createOrderMonths(OrdersEntity order) { String sql = "select id from t_b_ordermonths where id like '%" + DateUtils.formatDate(order.getOrderDate()).substring(0, 7) + "%'"; List> rets = systemService.findForJdbc(sql); if (rets.size() > 0) { order.setOrderMonths(rets.get(0).get("id").toString()); } } /** * 更新订单表 * * @return */ @RequestMapping(params = "doUpdate") @ResponseBody public AjaxJson doUpdate(OrdersEntity orders, OrdersPage 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"); String months = orders.getOrderMonths(); if ("1".equals(orders.getOrderType())) { // 月度申购类型 String sql = "select id from t_b_orders where order_months='" + months + "' and warehouse_id='" + warehouseid + "' and order_type =? "; List tsDList = systemService.findListbySql(sql, "1"); if (tsDList != null && tsDList.size() > 0 && !tsDList.get(0).equals(orders.getId())) { j.setSuccess(false); j.setMsg("不能重复进行月度申购,如需临时申购,请联系行政部开发临时申购权限。"); return j; } } WarehouseEntity wh = systemService.get(WarehouseEntity.class, warehouseid); orders.setWarehouseName(wh.getWarehouseName()); orders.setHandlerPersonId(tuser.getId()); orders.setHandlerPersonName(tuser.getRealName()); ordersService.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(OrdersEntity orders, HttpServletRequest req) { HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER"); req.setAttribute("userid", tuser.getId()); String orderType = orders.getOrderType(); if (StringUtils.isEmpty(orderType)) orderType = "1"; orders.setOrderType(orderType); ModelAndView mv = new ModelAndView("cn/com/lzt/orders/ordersListByWarehouse"); if (orderType.equals("1"))//月度申购 mv = new ModelAndView("cn/com/lzt/orders/orders-add"); else if (orderType.equals("2"))//临时申购 mv = new ModelAndView("cn/com/lzt/orders/orders-add"); else if (orderType.equals("3"))//代业主申购 mv = new ModelAndView("cn/com/lzt/orders/orders-add-representOwner"); if (StringUtil.isNotEmpty(orders.getId())) { orders = ordersService.getEntity(OrdersEntity.class, orders.getId()); dealRoundHalfUpValue(orders); req.setAttribute("ordersPage", orders); } else { //新增时,首先选择仓库(如果此人负责多仓库) if (StringUtil.isNotEmpty(req.getParameter("warehouseid"))) { String hql1 = "from WarehouseEntity where id=? "; List warehouseList = systemService.findHql(hql1, req.getParameter("warehouseid").toString()); if (warehouseList.size() > 0) { orders.setWarehouseId(warehouseList.get(0).getId()); } } else { List tsDList = systemService.findListbySql("select id from t_b_warehouse where responsible_person = '" + tuser.getId() + "' and delete_flag = 0"); if (tsDList != null && tsDList.size() > 0) { orders.setWarehouseId(tsDList.get(0)); } } //req.setAttribute("type", req.getParameter("type")); } req.setAttribute("ordersPage", orders); Date now = new Date(); Calendar begin = Calendar.getInstance(); begin.setTime(now); begin.add(Calendar.MONTH, -6); Calendar end = Calendar.getInstance(); end.setTime(now); end.add(Calendar.MONTH, 6); 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 ((orderType.equals("1") || orderType.equals("2")) && ome != null && ome.size() > 0) { orders.setOrderMonths(ome.get(0)); } if (orderType.equals("3")) { orders.setOrderDate(new Date()); } return mv; } /** * 订单表编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdateWithProcess") public ModelAndView goUpdateWithProcess(OrdersEntity 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 = ordersService.getEntity(OrdersEntity.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() + "' and delete_flag = 0"); 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/orders/orders-proc-update"); } @RequestMapping(params = "goUpdateWithProcessMobile") public ModelAndView goUpdateWithProcessMobile(OrdersEntity 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 = ordersService.getEntity(OrdersEntity.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() + "' and delete_flag = 0"); 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(OrdersEntity orders, HttpServletRequest req) { String isView = req.getParameter("viewFlag"); req.setAttribute("viewFlag", isView); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER"); req.setAttribute("userid", tuser.getId()); if (StringUtil.isNotEmpty(orders.getId())) { orders = ordersService.getEntity(OrdersEntity.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, -6); Calendar end = Calendar.getInstance(); end.setTime(now); end.add(Calendar.MONTH, 6); 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)); // } String orderType = orders.getOrderType(); ModelAndView mv = new ModelAndView("cn/com/lzt/orders/orders-update"); if (orderType.equals("3"))//代业主申购 mv = new ModelAndView("cn/com/lzt/orders/orders-update-representOwner"); return mv; } @RequestMapping(params = "goView") public ModelAndView goView(OrdersEntity orders, HttpServletRequest request) { if (LztUtil.isApiRequest()) return goViewMobile(orders, 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 = ordersService.getEntity(OrdersEntity.class, orders.getId()); // idandname(req, orders); dealRoundHalfUpValue(orders); request.setAttribute("ordersPage", orders); } request.setAttribute("load", "detail"); return new ModelAndView("cn/com/lzt/orders/orders-View"); } @RequestMapping(params = "goViewMobile") public ModelAndView goViewMobile(OrdersEntity 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 = ordersService.getEntity(OrdersEntity.class, orders.getId()); // idandname(req, orders); dealRoundHalfUpValue(orders); request.setAttribute("entity", orders); } String monthsSql = "select ordermonths_name from t_b_ordermonths where id = '" + orders.getOrderMonths() + "'"; List monthsNames = systemService.findListbySql(monthsSql); if (monthsNames.size() > 0) { orders.setOrderMonths(monthsNames.get(0)); } request.setAttribute("load", "detail"); Map data = LztUtil.copyReqAttributes(new String[]{ "entity", "viewFlag", "taskId", "load"}); return new JsonDataModelAndView(WXAjaxJson.success(data)); } // public void idandname(HttpServletRequest req, OrdersEntity 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(OrdersEntity orders, HttpServletRequest req) { // String type = req.getParameter("type"); //=================================================================================== //获取参数 Object id0 = orders.getId(); if (id0.toString().length() == 0) { List orderProductsEntityList = new ArrayList<>(); //月度申购才查询已申购的明细 if (orders.getOrderType().equals("1")) { String warehouseid = req.getParameter("warehouseid"); if (!StringUtils.isNotEmpty(warehouseid)) { HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER"); List tsDList = systemService.findListbySql("select id from t_b_warehouse where responsible_person = '" + tuser.getId() + "' and delete_flag = 0"); if (tsDList != null && tsDList.size() > 0) { warehouseid = tsDList.get(0); } } orderProductsEntityList = orderdao.getLastOrderProducts(warehouseid); //取采购价 if (!orderProductsEntityList.isEmpty()) { for (OrderProductsEntity productsEntity : orderProductsEntityList) { // TBGoodsInfoEntity goodsInfoEntity = systemService.get(, ) String goodsId = productsEntity.getGoodsId(); String hql = "from TBPriceInfoEntity where goodsId=? and meteringUnit=? "; List priceList = systemService.findHql(hql, goodsId, productsEntity.getMeasureUnit()); if (priceList != null && !priceList.isEmpty()) { productsEntity.setPurchasePrice(priceList.get(0).getRetailPrice()); } TBGoodsInfoEntity goodsInfoEntity = systemService.getEntity(TBGoodsInfoEntity.class, goodsId); String supplierId = goodsInfoEntity.getDefaultProvider(); productsEntity.setSupplierId(supplierId); if (StringUtils.isNotBlank(supplierId)) { RelatedUnitsEntity entity = systemService.get(RelatedUnitsEntity.class, goodsInfoEntity.getDefaultProvider()); if (entity != null) { productsEntity.setSupplierName(entity.getUnitName()); } } } } } req.setAttribute("orderProductsList", orderProductsEntityList); String load = (String) req.getAttribute("load"); req.setAttribute("load", load); } else { orders = ordersService.get(OrdersEntity.class, (String) id0); //=================================================================================== //查询-采购商品 String hql0 = "from OrderProductsEntity where 1 = 1 AND fK_ID =? "; try { List orderProductsEntityList = systemService.findHql(hql0, id0); addOnhandInfo2OrderProdunctsList(orders, orderProductsEntityList); req.setAttribute("orderProductsList", orderProductsEntityList); String load = (String) req.getAttribute("load"); req.setAttribute("load", load); } catch (Exception e) { logger.info(e.getMessage()); } } return new ModelAndView("cn/com/lzt/orderproducts/orderProductsList"); } /** * 加载审批明细列表[采购商品] * * @return */ @RequestMapping(params = "orderProductsViewList") public ModelAndView orderProductsViewList(OrdersEntity orders, HttpServletRequest req) { //=================================================================================== //获取参数 Object id0 = orders.getId(); orders = ordersService.get(OrdersEntity.class, (String) id0); //=================================================================================== //查询-采购商品 String hql0 = "from OrderProductsEntity where 1 = 1 AND fK_ID =? "; try { List orderProductsEntityList = systemService.findHql(hql0, id0); addOnhandInfo2OrderProdunctsList(orders, orderProductsEntityList); req.setAttribute("orderProductsList", orderProductsEntityList); 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(OrdersEntity 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 = ordersService.queryGoodsOnhandDataForOrderAudit(busiDate, warehouseid, list); if (onHandMap != null) { for (OrderProductsEntity 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(OrdersEntity orders, HttpServletRequest req) { //=================================================================================== //获取参数 Object id0 = orders.getId(); orders = ordersService.get(OrdersEntity.class, (String) id0); //=================================================================================== //查询-采购商品 try { List orderProductsEntityList = orderdao.getOrderProductsOrderByCategory((String) id0); addOnhandInfo2OrderProdunctsList(orders, orderProductsEntityList); req.setAttribute("orderProductsList", orderProductsEntityList); 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(OrdersEntity orders, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, ModelMap map) { CriteriaQuery cq = new CriteriaQuery(OrdersEntity.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 + "*"); } //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.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.ordersService.getListByCriteriaQuery(cq, false); List listResult = null; List pageList = new ArrayList(); List orderProductsEntityListResult = null; if (list != null && list.size() > 0) { Class clsOrder = MyClassLoader.getClassByScn("cn.com.lzt.orders.entity.OrdersEntity"); try { listResult = systemService.dealResultShowText4Entities(list, clsOrder); } catch (Exception e1) { logger.info(e1.getMessage()); } for (OrdersEntity entity : listResult) { try { OrdersPage page = new OrdersPage(); MyBeanUtils.copyBeanNotNull2Bean(entity, page); Object id0 = entity.getId(); String hql0 = "from OrderProductsEntity where 1 = 1 AND fK_ID =? "; List orderProductsEntityList = systemService.findHql(hql0, id0); Class cls = MyClassLoader.getClassByScn("cn.com.lzt.orderproducts.entity.OrderProductsEntity"); orderProductsEntityListResult = systemService.dealResultShowText4Entities(orderProductsEntityList, cls); page.setOrderProductsList(orderProductsEntityListResult); pageList.add(page); } catch (Exception e) { logger.info(e.getMessage()); } } } map.put(NormalExcelConstants.FILE_NAME, "订单表"); map.put(NormalExcelConstants.CLASS, OrdersPage.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(); OrdersEntity order = systemService.get(OrdersEntity.class, orderid); List details = systemService.findByProperty(OrderProductsEntity.class, "fkId", orderid); String fileName = "申购单-" + order.getWarehouseName() + "-" + order.getOrderMonths(); if (order.getOrderType().equals("3")) { fileName = "代业主申购单-" + order.getWarehouseName() + "-" + DateUtils.formatDate(order.getOrderDate(), "yyyy-MM-dd"); } map.put(NormalExcelConstants.FILE_NAME, fileName); map.put(NormalExcelConstants.CLASS, OrderProductsEntity.class); ExportParams param = new ExportParams("申购单-" + order.getWarehouseName() + "-" + order.getOrderMonths(), "总金额:" + order.getTotalMoney() + "元 保洁类金额:" + order.getBaojieSum() + "元 工程类金额:" + order.getGongchengSum() + "元 办公类金额:" + order.getBangongSum() + "元", "导出信息"); 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(), OrdersPage.class, params); OrdersEntity entity1 = null; for (OrdersPage page : list) { entity1 = new OrdersEntity(); MyBeanUtils.copyBeanNotNull2Bean(page, entity1); ordersService.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, OrdersPage.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 = ordersService.getList(OrdersEntity.class); return listOrderss; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { OrdersEntity task = ordersService.get(OrdersEntity.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 OrdersPage 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(); OrdersEntity orders = new OrdersEntity(); try { MyBeanUtils.copyBeanNotNull2Bean(orders, ordersPage); } catch (Exception e) { logger.info(e.getMessage()); } ordersService.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 OrdersPage 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(); OrdersEntity orders = new OrdersEntity(); try { MyBeanUtils.copyBeanNotNull2Bean(orders, ordersPage); } catch (Exception e) { logger.info(e.getMessage()); } ordersService.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) { OrdersEntity orders = ordersService.get(OrdersEntity.class, id); ordersService.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()); String hql1 = "from ProductSpecificationLimitEntity where 1 = 1 AND GOODS_ID = ?"; List lists = systemService.findHql(hql1, goodInfo.getId()); if (lists != null && lists.size() > 0) { boolean a = false; 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; i < lists.size(); i++) { if (!purchaseUnit.equals(lists.get(i).getSpecification())) { if (i > 0) { sb.append("/"); } sb.append(map.get(lists.get(i).getSpecification())); } else { a = true; break; } } sb.append("】"); if (!a) { reJson.put("msg", sb.toString()); } else { if (tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0) { for (TBPriceInfoEntity price : tBPriceInfoEntityList) { unitlist.add(price.getMeteringUnit()); if (purchaseUnit.equals(price.getMeteringUnit())) { tBPriceInfoEntityResult = price; } } } } } else { 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; i < unitlist.size(); i++) { if (i > 0) { 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 request * @param response * @param dataGrid * @throws ClassNotFoundException */ @SuppressWarnings({"rawtypes"}) @RequestMapping(params = "selRefDatagridUnits") public void selRefDatagridUnits(String classname, RelatedUnitsEntity relatedUnitsEntity, 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()); //cq.eq("unitType", Globals.AGRICULTURAL_SUPPLIERS);// 供应商 // 检索用 供应商编码 if (StringUtils.isNotBlank(relatedUnitsEntity.getUnitCode())) { cq.like("unitCode", "%" + relatedUnitsEntity.getUnitCode() + "%"); relatedUnitsEntity.setUnitCode(null); } // 检索用 供应商名称 if (StringUtils.isNotBlank(relatedUnitsEntity.getUnitName())) { cq.like("unitName", "%" + relatedUnitsEntity.getUnitName() + "%"); relatedUnitsEntity.setUnitName(null); } 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 = "selectReferUnits") public ModelAndView selectReferUnits(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cn/com/lzt/orders/selectUnitsInfo"); 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 = "selRefDatagridGoods") public void selRefDatagridGoods(String classname, TBGoodsInfoEntity tBGoodsInfoEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws Exception { String warehouseid = request.getParameter("warehouseid"); Class cls = MyClassLoader.getClassByScn(classname); CriteriaQuery cq = new CriteriaQuery(cls, dataGrid); //如果有仓库信息传入,则只查询此仓库有的货品 if (StringUtils.isNotEmpty(warehouseid)) { List goodsIDList = systemService.findListbySql("select goods_id from t_b_onhand where warehouse_id = '" + warehouseid + "' and quantity > 0"); if (goodsIDList.size() > 0) { cq.in("id", goodsIDList.toArray()); } else { cq.eq("id", "1"); } } //查询条件组装器 //自定义追加查询条件 String status = request.getParameter("status"); String[] unitstate; if (StringUtils.isNotBlank(status)) { unitstate = StringUtils.split(status, ","); } else { unitstate = new String[]{Globals.Enable_Normal}; } cq.in("status", unitstate); cq.eq("deleteFlag", Globals.Delete_Normal.toString()); String initCategoryCodes = request.getParameter("initCategoryCode"); if (StringUtils.isNotBlank(initCategoryCodes)) { //模糊查询 String[] initCategoryCodesArray = initCategoryCodes.split(","); Disjunction dis = Restrictions.disjunction(); for (String initCategoryCode : initCategoryCodesArray) { dis.add(Restrictions.like("belongCategoryCode", initCategoryCode + "%")); } cq.add(dis); } // 检索用货品分类编码 if (StringUtils.isNotBlank(tBGoodsInfoEntity.getBelongCategoryCode())) { //模糊查询 cq.like("belongCategoryCode", "%" + tBGoodsInfoEntity.getBelongCategoryCode() + "%"); } // 检索用货品名称 if (StringUtils.isNotBlank(tBGoodsInfoEntity.getGoodsName())) { //模糊查询 cq.like("goodsName", "%" + tBGoodsInfoEntity.getGoodsName() + "%"); } String goodsNameEq = request.getParameter("goodsNameEq"); if (StringUtils.isNotBlank(goodsNameEq)) { //模糊查询 cq.eq("goodsName", goodsNameEq); } // 检索用货品名称 if (StringUtils.isNotBlank(tBGoodsInfoEntity.getSpecification())) { //模糊查询 cq.like("specification", "%" + tBGoodsInfoEntity.getSpecification() + "%"); } org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cls.newInstance()); commonDao.getDataGridReturn(cq, true); List result = dataGrid.getResults(); if (result != null && result.size() > 0) { Collections.sort(result); TBGoodsInfoEntity goodsInfoEntity = null; TBPriceInfoEntity tBPriceInfoEntity = null; for (int i = 0; i < result.size(); i++) { goodsInfoEntity = (TBGoodsInfoEntity) result.get(i); if (StringUtils.isNotEmpty(goodsInfoEntity.getDefaultProvider()) && cq.getField().indexOf("supplierName") > -1) { RelatedUnitsEntity entity = systemService.get(RelatedUnitsEntity.class, goodsInfoEntity.getDefaultProvider()); if (entity != null) { goodsInfoEntity.setSupplierName(entity.getUnitName()); } } goodsInfoEntity.setGoodsDesc(""); //获取参数 Object id0 = goodsInfoEntity.getId(); String cateID = goodsInfoEntity.getBelongCategory(); TBGoodsCategoryEntity cate = systemService.get(TBGoodsCategoryEntity.class, cateID); goodsInfoEntity.setBelongCategoryName(dealCateName(cate.getCategoryCode(), cate.getCategoryName())); String hql0 = "from TBPriceInfoEntity where 1 = 1 AND GOODS_ID =? "; List tBPriceInfoEntityList = systemService.findHql(hql0, id0); if (tBPriceInfoEntityList != null && tBPriceInfoEntityList.size() > 0) { for (int j = 0; j < tBPriceInfoEntityList.size(); j++) { tBPriceInfoEntity = new TBPriceInfoEntity(); tBPriceInfoEntity = tBPriceInfoEntityList.get(j); if (goodsInfoEntity.getSalesUnit() != null && tBPriceInfoEntity.getMeteringUnit() != null && goodsInfoEntity.getSalesUnit().equals(tBPriceInfoEntity.getMeteringUnit())) { goodsInfoEntity.setGoodsDesc(tBPriceInfoEntity.getRetailPrice().toString()); goodsInfoEntity.setCostPrice(tBPriceInfoEntity.getRetailPrice()); break; } } } } } try { //result =systemService.dealResultShowText4Entities(dataGrid.getResults(), cls); } catch (Exception e) { throw new BusinessException(e); } dataGrid.setResults(result); TagUtil.datagrid(response, dataGrid); } /** * @param categoryName * @param categoryName * @return */ private String dealCateName(String categoryCode, String categoryName) { if (categoryCode.contains("rootA01")) { categoryName = "工程类-" + categoryName; } else if (categoryCode.contains("rootA02")) { categoryName = "保洁类-" + categoryName; } else if (categoryCode.contains("rootA03")) { categoryName = "办公类-" + categoryName; } return categoryName; } /** * 选择会员跳转页面 * * @return */ @RequestMapping(params = "selectReferGoods") public ModelAndView selectReferGoods(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cn/com/lzt/orders/selectGoodsInfo"); 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("warehouseid", oConvertUtils.getString(request.getParameter("warehouseid"))); mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield"))); mv.addObject("categoryfield", oConvertUtils.getString(request.getParameter("categoryfield"))); mv.addObject("categoryNamefield", oConvertUtils.getString(request.getParameter("categoryNamefield"))); mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield"))); mv.addObject("purchaseUnit", oConvertUtils.getString(request.getParameter("purchaseUnit"))); mv.addObject("specification", oConvertUtils.getString(request.getParameter("specification"))); mv.addObject("goodsDesc", oConvertUtils.getString(request.getParameter("goodsDesc"))); mv.addObject("supplierName", oConvertUtils.getString(request.getParameter("supplierName"))); mv.addObject("strEmpty", oConvertUtils.getString(request.getParameter("strEmpty"))); return mv; } /** * 仓库弹出框 * * @param request * @param response * @param dataGrid * @throws ClassNotFoundException */ @SuppressWarnings({"rawtypes"}) @RequestMapping(params = "selRefDatagridWareHouse") public void selRefDatagridWareHouse(String classname, WarehouseEntity warehouse, 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()); String scope = oConvertUtils.getString(request.getParameter("scope")); if ("part".equals(scope)) { HttpSession session = ContextHolderUtils.getSession(); TSUser user = (TSUser) session.getAttribute("LOCAL_CLINET_USER"); cq.eq("responsiblePerson", user.getId()); } // 检索用仓库编码 if (StringUtils.isNotBlank(warehouse.getWarehouseCode())) { cq.eq("warehouseCode", warehouse.getWarehouseCode()); } // 检索用仓库名称 if (StringUtils.isNotBlank(warehouse.getWarehouseName())) { cq.eq("warehouseName", warehouse.getWarehouseName()); } 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 = "selectReferWareHouse") public ModelAndView selectReferWareHouse(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cn/com/lzt/orders/selectWareHouseInfo"); String ids = oConvertUtils.getString(request.getParameter("ids")); mv.addObject("ids", ids); String scope = oConvertUtils.getString(request.getParameter("scope")); mv.addObject("scope", scope); // 需要将前端的类路径传递到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 = "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/orders/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()); } 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 = "selectReferLogistics") public ModelAndView selectReferLogistics(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cn/com/lzt/orders/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; OrdersEntity orders = ordersService.getEntity(OrdersEntity.class, id); try { // 未审批和已经审批的可以取消 if (orders.getOrderStatus() != null && (orders.getOrderStatus().equals(Globals.UNAPPROVED) || orders.getOrderStatus().equals(Globals.APPROVED))) { orders.setOrderStatus(Globals.CANCELED);//订单状态: 取消 ordersService.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(OrdersEntity entity) { BigDecimal baojie = entity.getBaojieSum() == null ? BigDecimal.ZERO : new BigDecimal(entity.getBaojieSum()); entity.setBaojieSum(baojie.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); BigDecimal bangong = entity.getBangongSum() == null ? BigDecimal.ZERO : new BigDecimal(entity.getBangongSum()); entity.setBangongSum(bangong.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); BigDecimal gongcheng = entity.getGongchengSum() == null ? BigDecimal.ZERO : new BigDecimal(entity.getGongchengSum()); entity.setGongchengSum(gongcheng.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; OrdersEntity orders = ordersService.getEntity(OrdersEntity.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);//订单状态: 取消 // ordersService.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; OrdersEntity orders = ordersService.getEntity(OrdersEntity.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); } // 采购单审核状态更新 ordersService.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() + "' and delete_flag = 0"); 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, HttpServletResponse response) { ActivitiTools tools = ActivitiTools.getInstance(procInstId, true); tools.setProcInstId(null); ActivitiPdfExport pdfExport = tools.getPdfExport(); String id = tools.getBusId(); OrdersEntity orders = ordersService.getEntity(OrdersEntity.class, id); String monthsSql = "select ordermonths_name from t_b_ordermonths where id = '" + orders.getOrderMonths() + "'"; List monthsNames = systemService.findListbySql(monthsSql); String orderMonths = orders.getOrderMonths(); if (monthsNames.size() > 0) { // orders.setOrderMonths(monthsNames.get(0)); orderMonths = monthsNames.get(0); } pdfExport.table() .cell("领料点", orders.getWarehouseName()) .cell("申购月份", orderMonths) .cell("总金额", orders.getTotalMoney() == null ? "0" : orders.getTotalMoney().toString()) .cell("保洁类金额", orders.getBaojieSum() == null ? "0" : orders.getBaojieSum().toString()) .cell("工程类金额", orders.getGongchengSum() == null ? "0" : orders.getGongchengSum().toString()) .cell("办公类金额", orders.getBangongSum() == null ? "0" : orders.getBangongSum().toString()) .cell("备注说明", orders.getDescription()) ; String hql0 = "from OrderProductsEntity where 1 = 1 AND fK_ID =? "; try { List orderProductsEntityList = systemService.findHql(hql0, id); // addOnhandInfo2OrderProdunctsList(orders,orderProductsEntityList); pdfExport.cell(""); PdfPTable detailTableHeader = pdfExport.createTable(7); detailTableHeader.setWidthPercentage(100); pdfExport.cell(detailTableHeader, "货品名称", true); pdfExport.cell(detailTableHeader, "规格型号", true); pdfExport.cell(detailTableHeader, "计量单位", true); pdfExport.cell(detailTableHeader, "数量", true); pdfExport.cell(detailTableHeader, "采购单价(元)", true); pdfExport.cell(detailTableHeader, "金额(元)", true); pdfExport.cell(detailTableHeader, "备注", true); pdfExport.cell(detailTableHeader); int i = 0; for (OrderProductsEntity detailEntity : orderProductsEntityList) { i++; PdfPTable detailTable = pdfExport.createTable(7); pdfExport.cell(detailTable, detailEntity.getPname(), false); pdfExport.cell(detailTable, detailEntity.getSpecType(), false); pdfExport.cell(detailTable, DictUtil.formatToTypeName(detailEntity.getMeasureUnit(), "metering_calcu_unit"), false); pdfExport.cell(detailTable, detailEntity.getQuantity().toString(), false); 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 = "selectReferGoodsBySameName") public ModelAndView selectReferGoodsBySameName(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cn/com/lzt/orders/selectGoodsInfo-samename"); 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("warehouseid", oConvertUtils.getString(request.getParameter("warehouseid"))); mv.addObject("codefield", oConvertUtils.getString(request.getParameter("codefield"))); mv.addObject("categoryfield", oConvertUtils.getString(request.getParameter("categoryfield"))); mv.addObject("categoryNamefield", oConvertUtils.getString(request.getParameter("categoryNamefield"))); mv.addObject("namefield", oConvertUtils.getString(request.getParameter("namefield"))); mv.addObject("purchaseUnit", oConvertUtils.getString(request.getParameter("purchaseUnit"))); mv.addObject("specification", oConvertUtils.getString(request.getParameter("specification"))); mv.addObject("goodsDesc", oConvertUtils.getString(request.getParameter("goodsDesc"))); mv.addObject("supplierName", oConvertUtils.getString(request.getParameter("supplierName"))); mv.addObject("strEmpty", oConvertUtils.getString(request.getParameter("strEmpty"))); return mv; } }