| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- package cn.com.lzt.sign.controller;
- import cn.com.lzt.common.util.DateUtil;
- import cn.com.lzt.arrangedutyoperate.dto.UserAndUserPersonnelDto;
- import cn.com.lzt.sign.entity.*;
- import cn.com.lzt.sign.page.TBAssetsPage;
- import cn.com.lzt.sign.page.TBMaterialPage;
- import cn.com.lzt.sign.service.TBAssetsService;
- import cn.com.lzt.useroptions.entity.TBusUserOptionsEntity;
- import cn.com.lzt.useroptions.service.TBusUserOptionsServiceI;
- import cn.com.lzt.warehouse.entity.WarehouseEntity;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.net.URLEncoder;
- import java.text.SimpleDateFormat;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.*;
- import java.util.logging.Logger;
- import java.util.stream.Collectors;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import com.alibaba.fastjson.JSONObject;
- import org.apache.poi.hssf.usermodel.HSSFCell;
- import org.apache.poi.hssf.usermodel.HSSFRow;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.util.CellRangeAddress;
- 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.system.pojo.base.TSBaseUser;
- import org.jeecgframework.web.system.pojo.base.TSDepart;
- import org.jeecgframework.web.system.pojo.base.TSUser;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
- @Controller
- @RequestMapping({"/tBAssetsController"})
- public class TBAssetsController
- extends BaseController {
- private static final Logger logger = Logger.getLogger(String.valueOf(cn.com.lzt.sign.controller.TBAssetsController.class));
- @Autowired
- private TBAssetsService tBAssetsService;
- @Autowired
- private TBusUserOptionsServiceI userOptionsService;
- @Autowired
- private SystemService systemService;
- @RequestMapping(params = {"list"})
- public ModelAndView list(HttpServletRequest request) {
- return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList");
- }
- @RequestMapping(params = {"goAdd"})
- public ModelAndView goAdd(HttpServletRequest request) {
- HttpSession session = ContextHolderUtils.getSession();
- TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER");
- TSBaseUser tsBaseUser = this.systemService.getEntity(TSBaseUser.class, tuser.getId());
- 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<Object[]> infoList = systemService.findListbySql(sql);
- List<TSDepart> 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("assetsDept",departname);
- request.setAttribute("assetsUsername",tsBaseUser.getRealName());
- return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList-add");
- }
- @RequestMapping(params = {"tBAssetsSonList"})
- public ModelAndView tBAssetsSonList(HttpServletRequest request) {
- String id0 = request.getParameter("assetsId");
- String viewFlag = request.getParameter("viewFlag");
- if (StringUtil.isNotEmpty(id0)) {
- DataGrid dataGrid = new DataGrid();
- CriteriaQuery cq = new CriteriaQuery(TBAssetsInfoEntity.class, dataGrid);
- try {
- String[] unitstate = {"1", "0"};
- cq.eq("assetsId", id0);
- } catch (Exception e) {
- throw new BusinessException(e.getMessage());
- }
- cq.add();
- this.tBAssetsService.getDataGridReturn(cq, true);
- request.setAttribute("tBAssetsInfoList", dataGrid.getResults());
- request.setAttribute("viewFlag", viewFlag);
- }
- return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsSonList");
- }
- @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("assetsDaptId"))) {
- queryStr.append(" and assets_dapt_id = \"" + request.getParameter("assetsDaptId") + "\"");
- }
- // 封装审批状态查询条件
- if (StringUtil.isNotEmpty(request.getParameter("assetsApprove"))) {
- queryStr.append(" and assets_approve = \"" + request.getParameter("assetsApprove") + "\"");
- }
- // 封装请购日期查询条件
- if (StringUtil.isNotEmpty(request.getParameter("assetsDate_begin")) && StringUtil.isNotEmpty(request.getParameter("assetsDate_end"))) {
- queryStr.append(" and assets_date between \"" + request.getParameter("assetsDate_begin") + "\" and \"" + request.getParameter("assetsDate_end") + "\" ");
- }
- List<Map<String, Object>> dataGridList = this.systemService.toDataGridByDataGrid(" t_b_assets ", "assets_spare_two", "request_id", "create_date", dataGrid, queryStr.toString());
- dataGrid.setResults(dataGridList);
- TagUtil.datagrid(response, dataGrid);
- }
- @RequestMapping(params = {"doAdd"})
- @ResponseBody
- public AjaxJson doAdd(TBAssetsEntity tBAssets, TBAssetsPage tBAssetsPage, 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<Object[]> infoList = systemService.findListbySql(sql);
- List<TSDepart> 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 = "";
- //审批用的
- tBAssets.setAssetsApprove("待提交");
- tBAssets.setAssetsSpareTwo(tuser.getId());
- //end
- 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());
- }
- tBAssets.setAssetsDept(departname);
- tBAssets.setAssetsDaptId(departid);
- AjaxJson j = new AjaxJson();
- String message = "添加成功";
- try {
- this.tBAssetsService.addMain(tBAssets, tBAssetsPage.gettBAssetsInfoList());
- } 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<String, List<String>> 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<UserAndUserPersonnelDto> userAndUserPersonnelDtoList = this.systemService.getListByCriteriaQuery(criteriaQuery1, true);
- Map<String, List<String>> ruleMap = new HashMap<>();
- // 得到登录人的职位
- List<String> departidList = new ArrayList<>();
- if (tsBaseUser != null && tsBaseUser.getDepartid() != null) {
- departidList.add(tsBaseUser.getDepartid());
- }
- // 得到操作人的岗位
- List<String> 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(TBAssetsEntity tBAssets, HttpServletRequest request) {
- String id = tBAssets.getId();
- tBAssets = (TBAssetsEntity) this.tBAssetsService.getEntity(TBAssetsEntity.class, id);
- SimpleDateFormat simpleDateFormatYMD = new SimpleDateFormat("yyyy-MM-dd");
- tBAssets.setAssetsDateStr(simpleDateFormatYMD.format(tBAssets.getAssetsDate()));
- TBAssetsDto tbAssetsDto = new TBAssetsDto();
- BeanUtils.copyProperties(tBAssets, tbAssetsDto);
- tbAssetsDto.setAssetsDateStr(DateUtil.changeDateTOStr3(tBAssets.getAssetsDate()));
- request.setAttribute("tBAssets", tbAssetsDto);
- String isView = request.getParameter("viewFlag");
- request.setAttribute("viewFlag", isView);
- return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList-update");
- }
- @RequestMapping(params = {"goUpdateView"})
- public ModelAndView goUpdateView(TBAssetsEntity tBAssets, HttpServletRequest request) {
- String id = tBAssets.getId();
- tBAssets = (TBAssetsEntity) this.tBAssetsService.getEntity(TBAssetsEntity.class, id);
- TBAssetsDto tbAssetsDto = new TBAssetsDto();
- BeanUtils.copyProperties(tBAssets, tbAssetsDto);
- tbAssetsDto.setAssetsDateStr(DateUtil.changeDateTOStr3(tBAssets.getAssetsDate()));
- request.setAttribute("tBAssets", tbAssetsDto);
- //String isView = request.getParameter("viewFlag");
- request.setAttribute("viewFlag", "1");
- return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList-update");
- }
- @RequestMapping(params = {"doUpdate"})
- @ResponseBody
- public AjaxJson doUpdate(TBAssetsEntity tBAssets, TBAssetsPage tBAssetsPage, 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<Object[]> infoList = systemService.findListbySql(sql);
- List<TSDepart> 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 = "";
- //审批用的
- tBAssets.setAssetsApprove("待提交");
- tBAssets.setAssetsSpareTwo(tuser.getId());
- //end
- 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());
- }
- tBAssets.setAssetsDept(departname);
- tBAssets.setAssetsDaptId(departid);
- AjaxJson j = new AjaxJson();
- String message = "修改成功";
- try {
- this.tBAssetsService.updateMain(tBAssets, tBAssetsPage.gettBAssetsInfoList());
- } catch (Exception e) {
- e.printStackTrace();
- message = "修改失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params = {"exportXlsOrder"})
- public void exportXlsOrder(String id, HttpServletRequest request, HttpServletResponse response , ModelMap map) throws IOException {
- id = id.replace(",","");
- DataGrid dataGrid = new DataGrid();
- TBAssetsInfoEntity tBAssetsInfoEntityA = new TBAssetsInfoEntity();
- tBAssetsInfoEntityA.setAssetsId(id);
- TBAssetsEntity tBAssets = (TBAssetsEntity) this.tBAssetsService.getEntity(TBAssetsEntity.class, id);
- CriteriaQuery cq = new CriteriaQuery(TBAssetsInfoEntity.class, dataGrid);
- HqlGenerateUtil.installHql(cq, tBAssetsInfoEntityA, request.getParameterMap());
- this.tBAssetsService.getDataGridReturn(cq, true);
- List<TBAssetsInfoEntity> details = dataGrid.getResults();
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("申购表");
- HSSFRow row1 = sheet.createRow(0);
- HSSFCell cell = row1.createCell(0);
- cell.setCellValue("申购表");
- sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
- HSSFRow row2 = sheet.createRow(1);
- row2.createCell(0).setCellValue("货品名称");
- row2.createCell(1).setCellValue("计量单位");
- row2.createCell(2).setCellValue("规格型号");
- row2.createCell(3).setCellValue("数量");
- row2.createCell(4).setCellValue("备注");
- int i=2;
- for ( ; i < details.size() + 2; i++) {
- HSSFRow row3 = sheet.createRow(i);
- TBAssetsInfoEntity tBAssetsInfoEntity = details.get(i - 2);
- row3.createCell(0).setCellValue(tBAssetsInfoEntity.getAssetsInfoGoodsname());
- row3.createCell(1).setCellValue(tBAssetsInfoEntity.getAssetsInfoMeasure());
- row3.createCell(2).setCellValue(tBAssetsInfoEntity.getAssetsInfoModel());
- row3.createCell(3).setCellValue(tBAssetsInfoEntity.getAssetsInfoNum().intValue());
- row3.createCell(4).setCellValue(tBAssetsInfoEntity.getAssetsInfoRemarks());
- }
- HSSFRow row3 = sheet.createRow(i);
- row3.createCell(0).setCellValue("请购科室");
- row3.createCell(1).setCellValue(tBAssets.getAssetsDept());
- row3.createCell(2).setCellValue("请购日期");
- SimpleDateFormat simpleDateFormatYMD = new SimpleDateFormat("yyyy-MM-dd");
- row3.createCell(3).setCellValue( simpleDateFormatYMD.format(tBAssets.getAssetsDate()));
- HSSFRow row4 = sheet.createRow(i+1);
- row4.createCell(0).setCellValue("经办人");
- row4.createCell(1).setCellValue(tBAssets.getAssetsUsername());
- ServletOutputStream servletOutputStream = response.getOutputStream();
- response.reset();
- response.setHeader("Content-disposition", "attachment; filename="+ URLEncoder.encode("办公室申购单")+".xls");
- // response.setHeader("Content-disposition", "attachment; filename=办公室申购单.xls");
- response.setContentType("application/octet-stream");
- wb.write((OutputStream) servletOutputStream);
- servletOutputStream.close();
- }
- @RequestMapping(params = "doDel")
- @ResponseBody
- public AjaxJson doDel(TBAssetsEntity tBAssetsEntity, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "删除成功";
- try{
- tBAssetsService.deleteEntityById(TBAssetsEntity.class, tBAssetsEntity.getId());
- }catch(Exception e){
- e.printStackTrace();
- message = "删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- }
|