package cn.com.lzt.sign.controller; import cn.com.lzt.arrangedutyoperate.dto.UserAndUserPersonnelDto; import cn.com.lzt.duties.entity.DutiesEntity; import cn.com.lzt.sign.entity.*; import cn.com.lzt.sign.service.TBBeforehandService; import cn.com.lzt.sign.service.TBRequestFeedbackService; import cn.com.lzt.sign.service.TBRequestService; import cn.com.lzt.useroptions.entity.TBusUserOptionsEntity; import cn.com.lzt.useroptions.service.TBusUserOptionsServiceI; import cn.com.lzt.warehouse.entity.WarehouseEntity; import java.text.SimpleDateFormat; import java.util.*; import java.util.logging.Logger; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.alibaba.fastjson.JSONObject; import org.jeecgframework.core.common.controller.BaseController; import org.jeecgframework.core.common.exception.BusinessException; import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil; import org.jeecgframework.core.util.ContextHolderUtils; import org.jeecgframework.core.util.LogUtil; import org.jeecgframework.core.util.ResourceUtil; import org.jeecgframework.core.util.StringUtil; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.tag.vo.datatable.SortDirection; import org.jeecgframework.web.cgform.service.config.CgFormFieldServiceI; import org.jeecgframework.web.system.pojo.base.*; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping({"/tBBeforehandController"}) public class TBBeforehandController extends BaseController { private static final Logger logger = Logger.getLogger(String.valueOf(cn.com.lzt.sign.controller.TBBeforehandController.class)); @Autowired private TBBeforehandService tBBeforehandService; @Autowired private TBusUserOptionsServiceI userOptionsService; @Autowired private TBRequestFeedbackService tBRequestFeedbackService; @Autowired private TBRequestService tBRequestService; @Autowired private SystemService systemService; @Autowired private CgFormFieldServiceI cgFormFieldService; @RequestMapping(params = {"list"}) public ModelAndView list(HttpServletRequest request) { /* 38 */ return new ModelAndView("cn/com/lzt/sign/tbbeforehand/tBBeforehandList"); } @RequestMapping(params = {"datagrid"}) public void datagrid(HttpServletRequest request, HttpServletResponse response,DataGrid dataGrid) { StringBuffer queryStr = new StringBuffer(); queryStr.append(" where 1 = 1 "); // 封装请购科室查询条件 if (StringUtil.isNotEmpty(request.getParameter("beforehandDeptId"))) { queryStr.append(" and beforehand_dept_id = \"" + request.getParameter("beforehandDeptId") + "\""); } // 封装接待员工查询条件 if (StringUtil.isNotEmpty(request.getParameter("beforehandReceiveUser"))) { queryStr.append(" and beforehand_receive_user like \"%" + request.getParameter("beforehandReceiveUser") + "%\""); } // 封装接待单位查询条件 if (StringUtil.isNotEmpty(request.getParameter("beforehandReceiveDapt"))) { queryStr.append(" and beforehand_receive_dapt = \"" + request.getParameter("beforehandReceiveDapt") + "\""); } // 封装日期查询条件 if (StringUtil.isNotEmpty(request.getParameter("beforehandStartDate")) && StringUtil.isNotEmpty(request.getParameter("beforehandEndDate"))) { queryStr.append(" and beforehand_start_date between \"" + request.getParameter("beforehandStartDate") + "\" and \"" + request.getParameter("beforehandEndDate") + "\" "); } // 封装接待单位查询条件 if (StringUtil.isNotEmpty(request.getParameter("beforehandApprove"))) { queryStr.append(" and beforehand_approve = \"" + request.getParameter("beforehandApprove") + "\""); } List> dataGridList = this.systemService.toDataGridByDataGrid(" t_b_beforehand ", "beforehand_spare_two", "request_id", "create_date", dataGrid, queryStr.toString()); dataGrid.setResults(dataGridList); TagUtil.datagrid(response, dataGrid); } @RequestMapping(params = "goAdd") public ModelAndView goAdd(HttpServletRequest request) { HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER"); String sql = "SELECT id,departname FROM t_s_depart where id in (select org_id from t_s_user_org where user_id = '"+tuser.getId()+"')"; List infoList = systemService.findListbySql(sql); List tSDepartList = infoList.stream().map(e -> { TSDepart sta = new TSDepart(); if (e[0] != null) { sta.setId(e[0].toString()); } if (e[1] != null) { sta.setDepartname(e[1].toString()); } return sta; }).collect(Collectors.toList()); String departid = ""; String departname = ""; try { if(tSDepartList!=null && tSDepartList.size()>0){ TSDepart dept = tSDepartList.get(0); departid = dept.getId(); departname = dept.getDepartname(); } } catch (Exception e) { e.printStackTrace(); LogUtil.error(e.getMessage()); } request.setAttribute("beforehandDept",departname); request.setAttribute("beforehandDeptId",departid); return new ModelAndView("cn/com/lzt/sign/tbbeforehand/tBBeforehandList-add"); } @RequestMapping(params = {"doAddOrUpdate"}) @ResponseBody public AjaxJson doAddOrUpdate( TBBeforehandEntity tBBeforehand, HttpServletRequest request) { String blog = request.getParameter("blog"); HttpSession session = ContextHolderUtils.getSession(); TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER"); AjaxJson j = new AjaxJson(); String message = "添加成功"; if("1".equals(blog)){ message = "修改成功"; } //审批用的 tBBeforehand.setBeforehandApprove("待提交"); tBBeforehand.setBeforehandSpareTwo(tuser.getId()); //end try { if("1".equals(blog)){ tBBeforehand.setBeforehandSpareTwo(tuser.getId()); this.tBBeforehandService.Update(tBBeforehand); }else{ Date day=new Date(); tBBeforehand.setBeforehandDate(day); tBBeforehand.setBeforehandSpareTwo(tuser.getId()); this.tBBeforehandService.save(tBBeforehand); } } catch (Exception e) { e.printStackTrace(); message = "添加失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 获取当前登录人的审批权限集合 * * @return * @author刘梦祥 * @Date 2021年11月29日00:42:57 */ public Map> getUserRuleMap() { // 获取当前操作人的信息 TSUser user = ResourceUtil.getSessionUser(); TSBaseUser tsBaseUser = this.systemService.getEntity(TSBaseUser.class, user.getId()); DataGrid dataGrid1 = new DataGrid(); CriteriaQuery criteriaQuery1 = new CriteriaQuery(UserAndUserPersonnelDto.class, dataGrid1); criteriaQuery1.eq("userid", user.getId()); criteriaQuery1.add(); List userAndUserPersonnelDtoList = this.systemService.getListByCriteriaQuery(criteriaQuery1, true); Map> ruleMap = new HashMap<>(); // 得到登录人的职位 List departidList = new ArrayList<>(); if (tsBaseUser != null && tsBaseUser.getDepartid() != null) { departidList.add(tsBaseUser.getDepartid()); } // 得到操作人的岗位 List inPostidList = new ArrayList<>(); if (userAndUserPersonnelDtoList != null && userAndUserPersonnelDtoList.size() > 0) { for (UserAndUserPersonnelDto userInfoDto : userAndUserPersonnelDtoList) { if (StringUtil.isNotEmpty(userInfoDto.getInPostid())) { if (!inPostidList.contains(userInfoDto.getInPostid())) { inPostidList.add(userInfoDto.getInPostid()); } } } } ruleMap.put("departId", departidList); ruleMap.put("inPostid", inPostidList); return ruleMap; } @RequestMapping(params = {"goUpdate"}) public ModelAndView goUpdate(TBBeforehandEntity tBBeforehand, HttpServletRequest request) { String id = tBBeforehand.getId(); tBBeforehand = (TBBeforehandEntity) this.tBBeforehandService.getEntity(TBBeforehandEntity.class, id); SimpleDateFormat simpleDateFormatYMD = new SimpleDateFormat("yyyy-MM-dd"); tBBeforehand.setBeforehandStartDateStr(simpleDateFormatYMD.format(tBBeforehand.getBeforehandStartDate())); tBBeforehand.setBeforehandEndDateStr(simpleDateFormatYMD.format(tBBeforehand.getBeforehandEndDate())); TBBeforehandEntityShow tbBeforehandEntityShow = new TBBeforehandEntityShow(); BeanUtils.copyProperties(tBBeforehand, tbBeforehandEntityShow); tbBeforehandEntityShow.setFileNames(Arrays.asList(tBBeforehand.getBeforehandFilename().split(","))); tbBeforehandEntityShow.setFileUrls(Arrays.asList(tBBeforehand.getBeforehandFileUrl().split(","))); request.setAttribute("tBBeforehand", tbBeforehandEntityShow); request.setAttribute("flag", request.getParameter("flag")); return new ModelAndView("cn/com/lzt/sign/tbbeforehand/tBBeforehandList-update"); } @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(TBBeforehandEntity tBBeforehand, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "删除成功"; try{ tBBeforehandService.deleteEntityById(TBBeforehandEntity.class, tBBeforehand.getId()); }catch(Exception e){ e.printStackTrace(); message = "删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = {"goPrint"}) public ModelAndView goPrint(TBBeforehandEntity tBBeforehand,HttpServletRequest request) { String id = request.getParameter("id"); try { //基本数据 tBBeforehand = (TBBeforehandEntity) this.tBBeforehandService.getEntity(TBBeforehandEntity.class, id); if (!tBBeforehand.getBeforehandApprove().equals("已通过")) { throw new BusinessException("未审批通过"); } //审批数据 String requestId = tBBeforehand.getRequestId(); if(null!=requestId&&!"".equals(requestId)){ DataGrid dataGrid = new DataGrid(); CriteriaQuery cq = new CriteriaQuery(TBRequestFeedbackEntity.class, dataGrid); TBRequestFeedbackEntity tBRequestFeedback = new TBRequestFeedbackEntity(); tBRequestFeedback.setRequestId(requestId); HqlGenerateUtil.installHql(cq, tBRequestFeedback, request.getParameterMap()); try{ cq.eq("requestId",requestId); cq.addOrder("createdAt", SortDirection.asc); } catch (Exception e) { throw new BusinessException(e.getMessage()); } cq.add(); this.tBRequestFeedbackService.getDataGridReturn(cq, true); List tBRequestFeedbackList = dataGrid.getResults(); if(null!=tBRequestFeedbackList&&tBRequestFeedbackList.size()>0){ for(int i=0;i infoList = systemService.findListbySql(str); if(infoList!=null && infoList.size()>0){ request.setAttribute("duties",infoList.get(0)); } TSBaseUser baseUser = systemService.get(TSBaseUser.class, tBBeforehand.getBeforehandSpareTwo()); request.setAttribute("username",baseUser.getRealName()); Date now = new Date(); request.setAttribute("nowdate",sdf2.format((now))); request.setAttribute("nowName",tuser.getRealName()); String startDate = sdf.format(tBBeforehand.getBeforehandStartDate()); String endDate = sdf.format(tBBeforehand.getBeforehandEndDate()); request.setAttribute("startDate",startDate); request.setAttribute("endDate",endDate); request.setAttribute("tBBeforehand",tBBeforehand); request.setAttribute("blog", "true"); }catch (Exception e){ request.setAttribute("blog", "请选择已通过的数据"); } return new ModelAndView("cn/com/lzt/sign/tbbeforehand/tBBeforehandList-print"); } }