TBAssetsController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. package cn.com.lzt.sign.controller;
  2. import cn.com.lzt.common.util.DateUtil;
  3. import cn.com.lzt.arrangedutyoperate.dto.UserAndUserPersonnelDto;
  4. import cn.com.lzt.sign.entity.*;
  5. import cn.com.lzt.sign.page.TBAssetsPage;
  6. import cn.com.lzt.sign.page.TBMaterialPage;
  7. import cn.com.lzt.sign.service.TBAssetsService;
  8. import cn.com.lzt.useroptions.entity.TBusUserOptionsEntity;
  9. import cn.com.lzt.useroptions.service.TBusUserOptionsServiceI;
  10. import cn.com.lzt.warehouse.entity.WarehouseEntity;
  11. import java.io.IOException;
  12. import java.io.OutputStream;
  13. import java.net.URLEncoder;
  14. import java.text.SimpleDateFormat;
  15. import java.util.Collections;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.*;
  20. import java.util.logging.Logger;
  21. import java.util.stream.Collectors;
  22. import javax.servlet.ServletOutputStream;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;
  26. import com.alibaba.fastjson.JSONObject;
  27. import org.apache.poi.hssf.usermodel.HSSFCell;
  28. import org.apache.poi.hssf.usermodel.HSSFRow;
  29. import org.apache.poi.hssf.usermodel.HSSFSheet;
  30. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  31. import org.apache.poi.ss.util.CellRangeAddress;
  32. import org.jeecgframework.core.common.controller.BaseController;
  33. import org.jeecgframework.core.common.exception.BusinessException;
  34. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  35. import org.jeecgframework.core.common.model.json.AjaxJson;
  36. import org.jeecgframework.core.common.model.json.DataGrid;
  37. import org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil;
  38. import org.jeecgframework.core.util.ContextHolderUtils;
  39. import org.jeecgframework.core.util.LogUtil;
  40. import org.jeecgframework.core.util.ResourceUtil;
  41. import org.jeecgframework.core.util.StringUtil;
  42. import org.jeecgframework.tag.core.easyui.TagUtil;
  43. import org.jeecgframework.tag.vo.datatable.SortDirection;
  44. import org.jeecgframework.web.system.pojo.base.TSBaseUser;
  45. import org.jeecgframework.web.system.pojo.base.TSDepart;
  46. import org.jeecgframework.web.system.pojo.base.TSUser;
  47. import org.jeecgframework.web.system.service.SystemService;
  48. import org.springframework.beans.BeanUtils;
  49. import org.springframework.beans.factory.annotation.Autowired;
  50. import org.springframework.stereotype.Controller;
  51. import org.springframework.ui.ModelMap;
  52. import org.springframework.web.bind.annotation.RequestMapping;
  53. import org.springframework.web.bind.annotation.ResponseBody;
  54. import org.springframework.web.servlet.ModelAndView;
  55. @Controller
  56. @RequestMapping({"/tBAssetsController"})
  57. public class TBAssetsController
  58. extends BaseController {
  59. private static final Logger logger = Logger.getLogger(String.valueOf(cn.com.lzt.sign.controller.TBAssetsController.class));
  60. @Autowired
  61. private TBAssetsService tBAssetsService;
  62. @Autowired
  63. private TBusUserOptionsServiceI userOptionsService;
  64. @Autowired
  65. private SystemService systemService;
  66. @RequestMapping(params = {"list"})
  67. public ModelAndView list(HttpServletRequest request) {
  68. return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList");
  69. }
  70. @RequestMapping(params = {"goAdd"})
  71. public ModelAndView goAdd(HttpServletRequest request) {
  72. HttpSession session = ContextHolderUtils.getSession();
  73. TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER");
  74. TSBaseUser tsBaseUser = this.systemService.getEntity(TSBaseUser.class, tuser.getId());
  75. 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()+"')";
  76. List<Object[]> infoList = systemService.findListbySql(sql);
  77. List<TSDepart> tSDepartList = infoList.stream().map(e -> {
  78. TSDepart sta = new TSDepart();
  79. if (e[0] != null) {
  80. sta.setId(e[0].toString());
  81. }
  82. if (e[1] != null) {
  83. sta.setDepartname(e[1].toString());
  84. }
  85. return sta;
  86. }).collect(Collectors.toList());
  87. String departid = "";
  88. String departname = "";
  89. try {
  90. if(tSDepartList!=null && tSDepartList.size()>0){
  91. TSDepart dept = tSDepartList.get(0);
  92. departid = dept.getId();
  93. departname = dept.getDepartname();
  94. }
  95. } catch (Exception e) {
  96. e.printStackTrace();
  97. LogUtil.error(e.getMessage());
  98. }
  99. request.setAttribute("assetsDept",departname);
  100. request.setAttribute("assetsUsername",tsBaseUser.getRealName());
  101. return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList-add");
  102. }
  103. @RequestMapping(params = {"tBAssetsSonList"})
  104. public ModelAndView tBAssetsSonList(HttpServletRequest request) {
  105. String id0 = request.getParameter("assetsId");
  106. String viewFlag = request.getParameter("viewFlag");
  107. if (StringUtil.isNotEmpty(id0)) {
  108. DataGrid dataGrid = new DataGrid();
  109. CriteriaQuery cq = new CriteriaQuery(TBAssetsInfoEntity.class, dataGrid);
  110. try {
  111. String[] unitstate = {"1", "0"};
  112. cq.eq("assetsId", id0);
  113. } catch (Exception e) {
  114. throw new BusinessException(e.getMessage());
  115. }
  116. cq.add();
  117. this.tBAssetsService.getDataGridReturn(cq, true);
  118. request.setAttribute("tBAssetsInfoList", dataGrid.getResults());
  119. request.setAttribute("viewFlag", viewFlag);
  120. }
  121. return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsSonList");
  122. }
  123. @RequestMapping(params = {"datagrid"})
  124. public void datagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  125. StringBuffer queryStr = new StringBuffer();
  126. queryStr.append(" where 1 = 1 ");
  127. // 封装请购科室查询条件
  128. if (StringUtil.isNotEmpty(request.getParameter("assetsDaptId"))) {
  129. queryStr.append(" and assets_dapt_id = \"" + request.getParameter("assetsDaptId") + "\"");
  130. }
  131. // 封装审批状态查询条件
  132. if (StringUtil.isNotEmpty(request.getParameter("assetsApprove"))) {
  133. queryStr.append(" and assets_approve = \"" + request.getParameter("assetsApprove") + "\"");
  134. }
  135. // 封装请购日期查询条件
  136. if (StringUtil.isNotEmpty(request.getParameter("assetsDate_begin")) && StringUtil.isNotEmpty(request.getParameter("assetsDate_end"))) {
  137. queryStr.append(" and assets_date between \"" + request.getParameter("assetsDate_begin") + "\" and \"" + request.getParameter("assetsDate_end") + "\" ");
  138. }
  139. List<Map<String, Object>> dataGridList = this.systemService.toDataGridByDataGrid(" t_b_assets ", "assets_spare_two", "request_id", "create_date", dataGrid, queryStr.toString());
  140. dataGrid.setResults(dataGridList);
  141. TagUtil.datagrid(response, dataGrid);
  142. }
  143. @RequestMapping(params = {"doAdd"})
  144. @ResponseBody
  145. public AjaxJson doAdd(TBAssetsEntity tBAssets, TBAssetsPage tBAssetsPage, HttpServletRequest request) {
  146. HttpSession session = ContextHolderUtils.getSession();
  147. TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER");
  148. 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()+"')";
  149. List<Object[]> infoList = systemService.findListbySql(sql);
  150. List<TSDepart> tSDepartList = infoList.stream().map(e -> {
  151. TSDepart sta = new TSDepart();
  152. if (e[0] != null) {
  153. sta.setId(e[0].toString());
  154. }
  155. if (e[1] != null) {
  156. sta.setDepartname(e[1].toString());
  157. }
  158. return sta;
  159. }).collect(Collectors.toList());
  160. String departid = "";
  161. String departname = "";
  162. //审批用的
  163. tBAssets.setAssetsApprove("待提交");
  164. tBAssets.setAssetsSpareTwo(tuser.getId());
  165. //end
  166. try {
  167. if(tSDepartList!=null && tSDepartList.size()>0){
  168. TSDepart dept = tSDepartList.get(0);
  169. departid = dept.getId();
  170. departname = dept.getDepartname();
  171. }
  172. } catch (Exception e) {
  173. e.printStackTrace();
  174. LogUtil.error(e.getMessage());
  175. }
  176. tBAssets.setAssetsDept(departname);
  177. tBAssets.setAssetsDaptId(departid);
  178. AjaxJson j = new AjaxJson();
  179. String message = "添加成功";
  180. try {
  181. this.tBAssetsService.addMain(tBAssets, tBAssetsPage.gettBAssetsInfoList());
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. message = "添加失败";
  185. throw new BusinessException(e.getMessage());
  186. }
  187. j.setMsg(message);
  188. return j;
  189. }
  190. /**
  191. * 获取当前登录人的审批权限集合
  192. *
  193. * @return
  194. * @author刘梦祥
  195. * @Date 2021年11月29日00:42:57
  196. */
  197. public Map<String, List<String>> getUserRuleMap() {
  198. // 获取当前操作人的信息
  199. TSUser user = ResourceUtil.getSessionUser();
  200. TSBaseUser tsBaseUser = this.systemService.getEntity(TSBaseUser.class, user.getId());
  201. DataGrid dataGrid1 = new DataGrid();
  202. CriteriaQuery criteriaQuery1 = new CriteriaQuery(UserAndUserPersonnelDto.class, dataGrid1);
  203. criteriaQuery1.eq("userid", user.getId());
  204. criteriaQuery1.add();
  205. List<UserAndUserPersonnelDto> userAndUserPersonnelDtoList = this.systemService.getListByCriteriaQuery(criteriaQuery1, true);
  206. Map<String, List<String>> ruleMap = new HashMap<>();
  207. // 得到登录人的职位
  208. List<String> departidList = new ArrayList<>();
  209. if (tsBaseUser != null && tsBaseUser.getDepartid() != null) {
  210. departidList.add(tsBaseUser.getDepartid());
  211. }
  212. // 得到操作人的岗位
  213. List<String> inPostidList = new ArrayList<>();
  214. if (userAndUserPersonnelDtoList != null && userAndUserPersonnelDtoList.size() > 0) {
  215. for (UserAndUserPersonnelDto userInfoDto : userAndUserPersonnelDtoList) {
  216. if (StringUtil.isNotEmpty(userInfoDto.getInPostid())) {
  217. if (!inPostidList.contains(userInfoDto.getInPostid())) {
  218. inPostidList.add(userInfoDto.getInPostid());
  219. }
  220. }
  221. }
  222. }
  223. ruleMap.put("departId", departidList);
  224. ruleMap.put("inPostid", inPostidList);
  225. return ruleMap;
  226. }
  227. @RequestMapping(params = {"goUpdate"})
  228. public ModelAndView goUpdate(TBAssetsEntity tBAssets, HttpServletRequest request) {
  229. String id = tBAssets.getId();
  230. tBAssets = (TBAssetsEntity) this.tBAssetsService.getEntity(TBAssetsEntity.class, id);
  231. SimpleDateFormat simpleDateFormatYMD = new SimpleDateFormat("yyyy-MM-dd");
  232. tBAssets.setAssetsDateStr(simpleDateFormatYMD.format(tBAssets.getAssetsDate()));
  233. TBAssetsDto tbAssetsDto = new TBAssetsDto();
  234. BeanUtils.copyProperties(tBAssets, tbAssetsDto);
  235. tbAssetsDto.setAssetsDateStr(DateUtil.changeDateTOStr3(tBAssets.getAssetsDate()));
  236. request.setAttribute("tBAssets", tbAssetsDto);
  237. String isView = request.getParameter("viewFlag");
  238. request.setAttribute("viewFlag", isView);
  239. return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList-update");
  240. }
  241. @RequestMapping(params = {"goUpdateView"})
  242. public ModelAndView goUpdateView(TBAssetsEntity tBAssets, HttpServletRequest request) {
  243. String id = tBAssets.getId();
  244. tBAssets = (TBAssetsEntity) this.tBAssetsService.getEntity(TBAssetsEntity.class, id);
  245. TBAssetsDto tbAssetsDto = new TBAssetsDto();
  246. BeanUtils.copyProperties(tBAssets, tbAssetsDto);
  247. tbAssetsDto.setAssetsDateStr(DateUtil.changeDateTOStr3(tBAssets.getAssetsDate()));
  248. request.setAttribute("tBAssets", tbAssetsDto);
  249. //String isView = request.getParameter("viewFlag");
  250. request.setAttribute("viewFlag", "1");
  251. return new ModelAndView("cn/com/lzt/sign/tabssets/tBAssetsList-update");
  252. }
  253. @RequestMapping(params = {"doUpdate"})
  254. @ResponseBody
  255. public AjaxJson doUpdate(TBAssetsEntity tBAssets, TBAssetsPage tBAssetsPage, HttpServletRequest request) {
  256. HttpSession session = ContextHolderUtils.getSession();
  257. TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER");
  258. 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()+"')";
  259. List<Object[]> infoList = systemService.findListbySql(sql);
  260. List<TSDepart> tSDepartList = infoList.stream().map(e -> {
  261. TSDepart sta = new TSDepart();
  262. if (e[0] != null) {
  263. sta.setId(e[0].toString());
  264. }
  265. if (e[1] != null) {
  266. sta.setDepartname(e[1].toString());
  267. }
  268. return sta;
  269. }).collect(Collectors.toList());
  270. String departid = "";
  271. String departname = "";
  272. //审批用的
  273. tBAssets.setAssetsApprove("待提交");
  274. tBAssets.setAssetsSpareTwo(tuser.getId());
  275. //end
  276. try {
  277. if(tSDepartList!=null && tSDepartList.size()>0){
  278. TSDepart dept = tSDepartList.get(0);
  279. departid = dept.getId();
  280. departname = dept.getDepartname();
  281. }
  282. } catch (Exception e) {
  283. e.printStackTrace();
  284. LogUtil.error(e.getMessage());
  285. }
  286. tBAssets.setAssetsDept(departname);
  287. tBAssets.setAssetsDaptId(departid);
  288. AjaxJson j = new AjaxJson();
  289. String message = "修改成功";
  290. try {
  291. this.tBAssetsService.updateMain(tBAssets, tBAssetsPage.gettBAssetsInfoList());
  292. } catch (Exception e) {
  293. e.printStackTrace();
  294. message = "修改失败";
  295. throw new BusinessException(e.getMessage());
  296. }
  297. j.setMsg(message);
  298. return j;
  299. }
  300. @RequestMapping(params = {"exportXlsOrder"})
  301. public void exportXlsOrder(String id, HttpServletRequest request, HttpServletResponse response , ModelMap map) throws IOException {
  302. id = id.replace(",","");
  303. DataGrid dataGrid = new DataGrid();
  304. TBAssetsInfoEntity tBAssetsInfoEntityA = new TBAssetsInfoEntity();
  305. tBAssetsInfoEntityA.setAssetsId(id);
  306. TBAssetsEntity tBAssets = (TBAssetsEntity) this.tBAssetsService.getEntity(TBAssetsEntity.class, id);
  307. CriteriaQuery cq = new CriteriaQuery(TBAssetsInfoEntity.class, dataGrid);
  308. HqlGenerateUtil.installHql(cq, tBAssetsInfoEntityA, request.getParameterMap());
  309. this.tBAssetsService.getDataGridReturn(cq, true);
  310. List<TBAssetsInfoEntity> details = dataGrid.getResults();
  311. HSSFWorkbook wb = new HSSFWorkbook();
  312. HSSFSheet sheet = wb.createSheet("申购表");
  313. HSSFRow row1 = sheet.createRow(0);
  314. HSSFCell cell = row1.createCell(0);
  315. cell.setCellValue("申购表");
  316. sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
  317. HSSFRow row2 = sheet.createRow(1);
  318. row2.createCell(0).setCellValue("货品名称");
  319. row2.createCell(1).setCellValue("计量单位");
  320. row2.createCell(2).setCellValue("规格型号");
  321. row2.createCell(3).setCellValue("数量");
  322. row2.createCell(4).setCellValue("备注");
  323. int i=2;
  324. for ( ; i < details.size() + 2; i++) {
  325. HSSFRow row3 = sheet.createRow(i);
  326. TBAssetsInfoEntity tBAssetsInfoEntity = details.get(i - 2);
  327. row3.createCell(0).setCellValue(tBAssetsInfoEntity.getAssetsInfoGoodsname());
  328. row3.createCell(1).setCellValue(tBAssetsInfoEntity.getAssetsInfoMeasure());
  329. row3.createCell(2).setCellValue(tBAssetsInfoEntity.getAssetsInfoModel());
  330. row3.createCell(3).setCellValue(tBAssetsInfoEntity.getAssetsInfoNum().intValue());
  331. row3.createCell(4).setCellValue(tBAssetsInfoEntity.getAssetsInfoRemarks());
  332. }
  333. HSSFRow row3 = sheet.createRow(i);
  334. row3.createCell(0).setCellValue("请购科室");
  335. row3.createCell(1).setCellValue(tBAssets.getAssetsDept());
  336. row3.createCell(2).setCellValue("请购日期");
  337. SimpleDateFormat simpleDateFormatYMD = new SimpleDateFormat("yyyy-MM-dd");
  338. row3.createCell(3).setCellValue( simpleDateFormatYMD.format(tBAssets.getAssetsDate()));
  339. HSSFRow row4 = sheet.createRow(i+1);
  340. row4.createCell(0).setCellValue("经办人");
  341. row4.createCell(1).setCellValue(tBAssets.getAssetsUsername());
  342. ServletOutputStream servletOutputStream = response.getOutputStream();
  343. response.reset();
  344. response.setHeader("Content-disposition", "attachment; filename="+ URLEncoder.encode("办公室申购单")+".xls");
  345. // response.setHeader("Content-disposition", "attachment; filename=办公室申购单.xls");
  346. response.setContentType("application/octet-stream");
  347. wb.write((OutputStream) servletOutputStream);
  348. servletOutputStream.close();
  349. }
  350. @RequestMapping(params = "doDel")
  351. @ResponseBody
  352. public AjaxJson doDel(TBAssetsEntity tBAssetsEntity, HttpServletRequest request) {
  353. String message = null;
  354. AjaxJson j = new AjaxJson();
  355. message = "删除成功";
  356. try{
  357. tBAssetsService.deleteEntityById(TBAssetsEntity.class, tBAssetsEntity.getId());
  358. }catch(Exception e){
  359. e.printStackTrace();
  360. message = "删除失败";
  361. throw new BusinessException(e.getMessage());
  362. }
  363. j.setMsg(message);
  364. return j;
  365. }
  366. }