ClothingApplyController.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. package cn.com.lzt.clothing.apply.controller;
  2. import cn.com.lzt.clothing.apply.entity.ClothingApplyEntity;
  3. import cn.com.lzt.clothing.apply.page.ClothingApplyPage;
  4. import cn.com.lzt.clothing.apply.service.ClothingApplyServiceI;
  5. import cn.com.lzt.clothing.applydetail.entity.ClothingApplyDetailEntity;
  6. import cn.com.lzt.clothing.user.entity.ClothingUserEntity;
  7. import cn.com.lzt.common.controller.BaseLztController;
  8. import cn.com.lzt.common.util.DictUtil;
  9. import cn.com.lzt.common.util.LztUtil;
  10. import cn.com.lzt.common.util.UserUtil;
  11. import cn.com.lzt.common.view.JsonDataModelAndView;
  12. import cn.com.lzt.useractiviti.data.util.ActivitiPdfExport;
  13. import cn.com.lzt.useractiviti.data.util.ActivitiTools;
  14. import cn.com.lzt.warehouse.entity.WarehouseEntity;
  15. import cn.com.lzt.workflow.service.WorkflowServiceI;
  16. import com.lowagie.text.pdf.PdfPTable;
  17. import com.xcgl.weixin.entity.WXAjaxJson;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.apache.log4j.Logger;
  20. import org.jeecgframework.core.beanvalidator.BeanValidators;
  21. import org.jeecgframework.core.common.exception.BusinessException;
  22. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  23. import org.jeecgframework.core.common.model.json.AjaxJson;
  24. import org.jeecgframework.core.common.model.json.DataGrid;
  25. import org.jeecgframework.core.constant.Globals;
  26. import org.jeecgframework.core.util.*;
  27. import org.jeecgframework.poi.excel.ExcelImportUtil;
  28. import org.jeecgframework.poi.excel.entity.ExportParams;
  29. import org.jeecgframework.poi.excel.entity.ImportParams;
  30. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  31. import org.jeecgframework.tag.core.easyui.TagUtil;
  32. import org.jeecgframework.web.system.pojo.base.TSDepart;
  33. import org.jeecgframework.web.system.pojo.base.TSUser;
  34. import org.jeecgframework.web.system.service.SystemService;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.http.HttpHeaders;
  37. import org.springframework.http.HttpStatus;
  38. import org.springframework.http.MediaType;
  39. import org.springframework.http.ResponseEntity;
  40. import org.springframework.stereotype.Controller;
  41. import org.springframework.ui.ModelMap;
  42. import org.springframework.web.bind.annotation.*;
  43. import org.springframework.web.multipart.MultipartFile;
  44. import org.springframework.web.multipart.MultipartHttpServletRequest;
  45. import org.springframework.web.servlet.ModelAndView;
  46. import org.springframework.web.util.UriComponentsBuilder;
  47. import javax.servlet.http.HttpServletRequest;
  48. import javax.servlet.http.HttpServletResponse;
  49. import javax.validation.ConstraintViolation;
  50. import javax.validation.Validator;
  51. import java.io.IOException;
  52. import java.math.BigDecimal;
  53. import java.net.URI;
  54. import java.util.*;
  55. /**
  56. * @Title: Controller
  57. * @Description: 服装申请
  58. * @author onlineGenerator
  59. * @date 2019-10-10 09:26:47
  60. * @version V1.0
  61. *
  62. */
  63. @Controller
  64. @RequestMapping("/clothingApplyController")
  65. public class ClothingApplyController extends BaseLztController {
  66. /**
  67. * Logger for this class
  68. */
  69. private static final Logger logger = Logger.getLogger(ClothingApplyController.class);
  70. @Autowired
  71. private ClothingApplyServiceI clothingApplyService;
  72. @Autowired
  73. private SystemService systemService;
  74. @Autowired
  75. private Validator validator;
  76. @Autowired
  77. WorkflowServiceI workflowService ;
  78. /**
  79. * 服装申请列表 页面跳转
  80. *
  81. * @return
  82. */
  83. @RequestMapping(params = "list")
  84. public ModelAndView list(HttpServletRequest request) {
  85. String userid = ResourceUtil.getSessionUser().getId();
  86. String hql1 = "from WarehouseEntity where responsiblePerson=? ";
  87. List<WarehouseEntity> warehouseList = systemService.findHql(hql1, userid);
  88. if (warehouseList.size() > 1)
  89. request.setAttribute("isMultiWarehouse", "1");
  90. else
  91. request.setAttribute("isMultiWarehouse", "0");
  92. return new ModelAndView("cn/com/lzt/clothing/apply/clothingApplyList");
  93. }
  94. @RequestMapping(params = "listQry")
  95. public ModelAndView listQry(HttpServletRequest request) {
  96. return new ModelAndView("cn/com/lzt/clothing/apply/clothingApplyQryList");
  97. }
  98. /**
  99. * easyui AJAX请求数据
  100. *
  101. * @param request
  102. * @param response
  103. * @param dataGrid
  104. */
  105. @RequestMapping(params = "datagrid")
  106. public void datagrid(ClothingApplyEntity clothingApply,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  107. CriteriaQuery cq = new CriteriaQuery(ClothingApplyEntity.class, dataGrid);
  108. TSUser user = ResourceUtil.getSessionUser();
  109. boolean isproject = UserUtil.isProjectUser(user.getId());
  110. if(isproject) {
  111. String sql_wh = "select distinct id from t_b_warehouse ware "
  112. + " where ware.responsible_person = '"+ user.getId()+"'";
  113. List<String> wh_ids = systemService.findListbySql(sql_wh);
  114. if(wh_ids != null && wh_ids.size()>0) {
  115. cq.in("warehouseid",wh_ids.toArray(new String[]{}));
  116. }else {
  117. //没有仓库,则查不出数据
  118. cq.eq("warehouseid", "1");
  119. }
  120. }
  121. if(StringUtils.isNotEmpty(clothingApply.getWarehousename())) {
  122. cq.like("warehousename", "%"+clothingApply.getWarehousename()+"%");
  123. clothingApply.setWarehousename(null);
  124. }
  125. //查询条件组装器
  126. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, clothingApply);
  127. cq.add();
  128. this.clothingApplyService.getDataGridReturn(cq, true);
  129. TagUtil.datagrid(response, dataGrid);
  130. }
  131. /**
  132. * 删除服装申请
  133. *
  134. * @return
  135. */
  136. @RequestMapping(params = "doDel")
  137. @ResponseBody
  138. public AjaxJson doDel(ClothingApplyEntity clothingApply, HttpServletRequest request) {
  139. AjaxJson j = new AjaxJson();
  140. clothingApply = systemService.getEntity(ClothingApplyEntity.class, clothingApply.getId());
  141. String message = "服装申请删除成功";
  142. try{
  143. clothingApplyService.delMain(clothingApply);
  144. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  145. }catch(Exception e){
  146. e.printStackTrace();
  147. message = "服装申请删除失败";
  148. throw new BusinessException(e.getMessage());
  149. }
  150. j.setMsg(message);
  151. return j;
  152. }
  153. @RequestMapping(params = "doGrant")
  154. @ResponseBody
  155. public AjaxJson doGrant(String ids, HttpServletRequest request) {
  156. AjaxJson j = new AjaxJson();
  157. String message = "服装发放成功";
  158. try{
  159. String[] idList = ids.split(",");
  160. for (String id : idList) {
  161. ClothingApplyEntity clothingApply = systemService.getEntity(ClothingApplyEntity.class, id);
  162. clothingApply.setGrantstatus("1");
  163. systemService.saveOrUpdate(clothingApply);
  164. }
  165. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  166. }catch(Exception e){
  167. e.printStackTrace();
  168. message = "服装发放失败";
  169. throw new BusinessException(e.getMessage());
  170. }
  171. j.setMsg(message);
  172. return j;
  173. }
  174. /**
  175. * 批量删除服装申请
  176. *
  177. * @return
  178. */
  179. @RequestMapping(params = "doBatchDel")
  180. @ResponseBody
  181. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  182. AjaxJson j = new AjaxJson();
  183. String message = "服装申请删除成功";
  184. try{
  185. for(String id:ids.split(",")){
  186. ClothingApplyEntity clothingApply = systemService.getEntity(ClothingApplyEntity.class,
  187. id
  188. );
  189. clothingApplyService.delMain(clothingApply);
  190. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  191. }
  192. }catch(Exception e){
  193. e.printStackTrace();
  194. message = "服装申请删除失败";
  195. throw new BusinessException(e.getMessage());
  196. }
  197. j.setMsg(message);
  198. return j;
  199. }
  200. /**
  201. * 添加服装申请
  202. *
  203. * @return
  204. */
  205. @RequestMapping(params = "doAdd")
  206. @ResponseBody
  207. public AjaxJson doAdd(ClothingApplyEntity clothingApply,ClothingApplyPage clothingApplyPage, HttpServletRequest request) {
  208. List<ClothingApplyDetailEntity> clothingApplyDetailList = clothingApplyPage.getClothingApplyDetailList();
  209. AjaxJson j = new AjaxJson();
  210. String message = "添加成功";
  211. try{
  212. clothingApply.setGrantstatus("0");
  213. clothingApplyService.addMain(clothingApply, clothingApplyDetailList);
  214. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  215. }catch(Exception e){
  216. e.printStackTrace();
  217. message = "服装申请添加失败";
  218. throw new BusinessException(e.getMessage());
  219. }
  220. j.setMsg(message);
  221. return j;
  222. }
  223. /**
  224. * 更新服装申请
  225. *
  226. * @return
  227. */
  228. @RequestMapping(params = "doUpdate")
  229. @ResponseBody
  230. public AjaxJson doUpdate(ClothingApplyEntity clothingApply,ClothingApplyPage clothingApplyPage, HttpServletRequest request) {
  231. List<ClothingApplyDetailEntity> clothingApplyDetailList = clothingApplyPage.getClothingApplyDetailList();
  232. AjaxJson j = new AjaxJson();
  233. String message = "更新成功";
  234. try{
  235. clothingApplyService.updateMain(clothingApply, clothingApplyDetailList);
  236. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  237. }catch(Exception e){
  238. e.printStackTrace();
  239. message = "更新服装申请失败";
  240. throw new BusinessException(e.getMessage());
  241. }
  242. j.setMsg(message);
  243. return j;
  244. }
  245. /**
  246. * 服装申请新增页面跳转
  247. *
  248. * @return
  249. */
  250. @RequestMapping(params = "goAdd")
  251. public ModelAndView goAdd(ClothingApplyEntity clothingApply, HttpServletRequest req) {
  252. String warehouseid = req.getParameter("warehouseid");
  253. TSUser user = ResourceUtil.getSessionUser();
  254. if(StringUtils.isEmpty(warehouseid)) {
  255. String sql_wh = "select distinct id from t_b_warehouse ware "
  256. + " where ware.responsible_person = '"+ user.getId()+"'";
  257. List<String> wh_ids = systemService.findListbySql(sql_wh);
  258. if(wh_ids.size() == 0) {
  259. req.setAttribute("ex", new BusinessException("登录人没有库管员权限,不能办理物料领用业务,请联系管理员。"));
  260. return new ModelAndView("common/error");
  261. }else {
  262. warehouseid = wh_ids.get(0);
  263. }
  264. }
  265. clothingApply = new ClothingApplyEntity();
  266. WarehouseEntity wh = systemService.get(WarehouseEntity.class, warehouseid);
  267. TSDepart dept = systemService.get(TSDepart.class, wh.getProjectId());
  268. clothingApply.setWarehouseid(wh.getId());
  269. clothingApply.setWarehousename(wh.getWarehouseName());
  270. clothingApply.setDepartid(wh.getProjectId());
  271. clothingApply.setProjectid(dept.getProjectid());
  272. clothingApply.setApplydate(DateUtils.date_sdf.format(new Date()));
  273. req.setAttribute("clothingApplyPage", clothingApply);
  274. return new ModelAndView("cn/com/lzt/clothing/apply/clothingApply-add");
  275. }
  276. /**
  277. * 服装申请编辑页面跳转
  278. *
  279. * @return
  280. */
  281. @RequestMapping(params = "goUpdate")
  282. public ModelAndView goUpdate(ClothingApplyEntity clothingApply, HttpServletRequest req) {
  283. if (StringUtil.isNotEmpty(clothingApply.getId())) {
  284. clothingApply = clothingApplyService.getEntity(ClothingApplyEntity.class, clothingApply.getId());
  285. req.setAttribute("clothingApplyPage", clothingApply);
  286. }
  287. return new ModelAndView("cn/com/lzt/clothing/apply/clothingApply-update");
  288. }
  289. @RequestMapping(params = "goUpdateMobile")
  290. public ModelAndView goUpdateMobile(ClothingApplyEntity clothingApply, HttpServletRequest req) {
  291. if (StringUtil.isNotEmpty(clothingApply.getId())) {
  292. clothingApply = clothingApplyService.getEntity(ClothingApplyEntity.class, clothingApply.getId());
  293. String hql0 = "from ClothingApplyDetailEntity where 1 = 1 AND aPPLYID =? ";
  294. List<ClothingApplyDetailEntity> clothingApplyDetailEntityList = systemService.findHql(hql0,clothingApply.getId());
  295. double quantity = 0;
  296. for (ClothingApplyDetailEntity detail : clothingApplyDetailEntityList) {
  297. quantity += detail.getQuantity();
  298. }
  299. req.setAttribute("totalquantity", quantity);
  300. req.setAttribute("entity", clothingApply);
  301. }
  302. Map<String, Object> data = LztUtil.copyReqAttributes(new String[]{
  303. "totalquantity", "entity"});
  304. return new JsonDataModelAndView(WXAjaxJson.success(data));
  305. }
  306. /**
  307. * 加载明细列表[服装申请明细]
  308. *
  309. * @return
  310. */
  311. @RequestMapping(params = "clothingApplyDetailList")
  312. public ModelAndView clothingApplyDetailList(ClothingApplyEntity clothingApply, HttpServletRequest req) {
  313. //===================================================================================
  314. //获取参数
  315. Object id0 = clothingApply.getId();
  316. //===================================================================================
  317. //查询-服装申请明细
  318. String hql0 = "from ClothingApplyDetailEntity where 1 = 1 AND aPPLYID =? ";
  319. try{
  320. List<ClothingApplyDetailEntity> clothingApplyDetailEntityList = systemService.findHql(hql0,id0);
  321. for (ClothingApplyDetailEntity detail : clothingApplyDetailEntityList) {
  322. String sql = "select sum(quantity) quantity from t_b_clothing_user where userid = '"
  323. +detail.getUserid()+"' and clothingid = '"+detail.getClothingid()+"'";
  324. List<BigDecimal> quantity = systemService.findListbySql(sql);
  325. if(quantity != null && quantity.size() > 0 && quantity.get(0) != null) {
  326. detail.setQuantityexist(quantity.get(0).intValue());
  327. }else {
  328. detail.setQuantityexist(0);
  329. }
  330. }
  331. req.setAttribute("clothingApplyDetailList", clothingApplyDetailEntityList);
  332. }catch(Exception e){
  333. logger.info(e.getMessage());
  334. }
  335. return new ModelAndView("cn/com/lzt/clothing/applydetail/clothingApplyDetailList");
  336. }
  337. /**
  338. * 导出excel
  339. *
  340. * @param request
  341. * @param response
  342. */
  343. @RequestMapping(params = "exportXls")
  344. public String exportXls(ClothingApplyEntity clothingApply,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) {
  345. CriteriaQuery cq = new CriteriaQuery(ClothingApplyEntity.class, dataGrid);
  346. //查询条件组装器
  347. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, clothingApply);
  348. try{
  349. //自定义追加查询条件
  350. }catch (Exception e) {
  351. throw new BusinessException(e.getMessage());
  352. }
  353. cq.add();
  354. List<ClothingApplyEntity> list=this.clothingApplyService.getListByCriteriaQuery(cq, false);
  355. List<ClothingApplyPage> pageList=new ArrayList<ClothingApplyPage>();
  356. if(list!=null&&list.size()>0){
  357. for(ClothingApplyEntity entity:list){
  358. try{
  359. ClothingApplyPage page=new ClothingApplyPage();
  360. MyBeanUtils.copyBeanNotNull2Bean(entity,page);
  361. Object id0 = entity.getId();
  362. String hql0 = "from ClothingApplyDetailEntity where 1 = 1 AND aPPLYID =? ";
  363. List<ClothingApplyDetailEntity> clothingApplyDetailEntityList = systemService.findHql(hql0,id0);
  364. page.setClothingApplyDetailList(clothingApplyDetailEntityList);
  365. pageList.add(page);
  366. }catch(Exception e){
  367. logger.info(e.getMessage());
  368. }
  369. }
  370. }
  371. map.put(NormalExcelConstants.FILE_NAME,"服装申请");
  372. map.put(NormalExcelConstants.CLASS,ClothingApplyPage.class);
  373. map.put(NormalExcelConstants.PARAMS,new ExportParams("服装申请列表", "导出人:Jeecg",
  374. "导出信息"));
  375. map.put(NormalExcelConstants.DATA_LIST,pageList);
  376. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  377. }
  378. /**
  379. * 通过excel导入数据
  380. * @param request
  381. * @param
  382. * @return
  383. */
  384. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  385. @ResponseBody
  386. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  387. AjaxJson j = new AjaxJson();
  388. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  389. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  390. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  391. MultipartFile file = entity.getValue();// 获取上传文件对象
  392. ImportParams params = new ImportParams();
  393. params.setTitleRows(2);
  394. params.setHeadRows(2);
  395. params.setNeedSave(true);
  396. try {
  397. List<ClothingApplyPage> list = ExcelImportUtil.importExcel(file.getInputStream(), ClothingApplyPage.class, params);
  398. ClothingApplyEntity entity1=null;
  399. for (ClothingApplyPage page : list) {
  400. entity1=new ClothingApplyEntity();
  401. MyBeanUtils.copyBeanNotNull2Bean(page,entity1);
  402. clothingApplyService.addMain(entity1, page.getClothingApplyDetailList());
  403. }
  404. j.setMsg("文件导入成功!");
  405. } catch (Exception e) {
  406. j.setMsg("文件导入失败!");
  407. logger.error(ExceptionUtil.getExceptionMessage(e));
  408. }finally{
  409. try {
  410. file.getInputStream().close();
  411. } catch (IOException e) {
  412. e.printStackTrace();
  413. }
  414. }
  415. }
  416. return j;
  417. }
  418. /**
  419. * 导出excel 使模板
  420. */
  421. @RequestMapping(params = "exportXlsByT")
  422. public String exportXlsByT(ModelMap map) {
  423. map.put(NormalExcelConstants.FILE_NAME,"服装申请");
  424. map.put(NormalExcelConstants.CLASS,ClothingApplyPage.class);
  425. map.put(NormalExcelConstants.PARAMS,new ExportParams("服装申请列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
  426. "导出信息"));
  427. map.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  428. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  429. }
  430. /**
  431. * 导入功能跳转
  432. *
  433. * @return
  434. */
  435. @RequestMapping(params = "upload")
  436. public ModelAndView upload(HttpServletRequest req) {
  437. req.setAttribute("controller_name", "clothingApplyController");
  438. return new ModelAndView("common/upload/pub_excel_upload");
  439. }
  440. @RequestMapping(method = RequestMethod.GET)
  441. @ResponseBody
  442. public List<ClothingApplyEntity> list() {
  443. List<ClothingApplyEntity> listClothingApplys=clothingApplyService.getList(ClothingApplyEntity.class);
  444. return listClothingApplys;
  445. }
  446. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  447. @ResponseBody
  448. public ResponseEntity<?> get(@PathVariable("id") String id) {
  449. ClothingApplyEntity task = clothingApplyService.get(ClothingApplyEntity.class, id);
  450. if (task == null) {
  451. return new ResponseEntity(HttpStatus.NOT_FOUND);
  452. }
  453. return new ResponseEntity(task, HttpStatus.OK);
  454. }
  455. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  456. @ResponseBody
  457. public ResponseEntity<?> create(@RequestBody ClothingApplyPage clothingApplyPage, UriComponentsBuilder uriBuilder) {
  458. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  459. Set<ConstraintViolation<ClothingApplyPage>> failures = validator.validate(clothingApplyPage);
  460. if (!failures.isEmpty()) {
  461. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  462. }
  463. //保存
  464. List<ClothingApplyDetailEntity> clothingApplyDetailList = clothingApplyPage.getClothingApplyDetailList();
  465. ClothingApplyEntity clothingApply = new ClothingApplyEntity();
  466. try{
  467. MyBeanUtils.copyBeanNotNull2Bean(clothingApply,clothingApplyPage);
  468. }catch(Exception e){
  469. logger.info(e.getMessage());
  470. }
  471. clothingApplyService.addMain(clothingApply, clothingApplyDetailList);
  472. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  473. String id = clothingApplyPage.getId();
  474. URI uri = uriBuilder.path("/rest/clothingApplyController/" + id).build().toUri();
  475. HttpHeaders headers = new HttpHeaders();
  476. headers.setLocation(uri);
  477. return new ResponseEntity(headers, HttpStatus.CREATED);
  478. }
  479. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  480. public ResponseEntity<?> update(@RequestBody ClothingApplyPage clothingApplyPage) {
  481. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  482. Set<ConstraintViolation<ClothingApplyPage>> failures = validator.validate(clothingApplyPage);
  483. if (!failures.isEmpty()) {
  484. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  485. }
  486. //保存
  487. List<ClothingApplyDetailEntity> clothingApplyDetailList = clothingApplyPage.getClothingApplyDetailList();
  488. ClothingApplyEntity clothingApply = new ClothingApplyEntity();
  489. try{
  490. MyBeanUtils.copyBeanNotNull2Bean(clothingApply,clothingApplyPage);
  491. }catch(Exception e){
  492. logger.info(e.getMessage());
  493. }
  494. clothingApplyService.updateMain(clothingApply, clothingApplyDetailList);
  495. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  496. return new ResponseEntity(HttpStatus.NO_CONTENT);
  497. }
  498. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  499. @ResponseStatus(HttpStatus.NO_CONTENT)
  500. public void delete(@PathVariable("id") String id) {
  501. ClothingApplyEntity clothingApply = clothingApplyService.get(ClothingApplyEntity.class, id);
  502. clothingApplyService.delMain(clothingApply);
  503. }
  504. @SuppressWarnings({ "unchecked", "rawtypes" })
  505. @RequestMapping(params = "getClothingUserInfo", method = RequestMethod.POST)
  506. @ResponseBody
  507. public Object getClothingUserInfo(String userid,String clothingid){
  508. Map reJson = new HashMap<String, Object>();
  509. String startdate = "";
  510. String lastdate = "";
  511. if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(clothingid)){
  512. try{
  513. List<ClothingUserEntity> cuList = systemService.findHql(
  514. " From ClothingUserEntity where userid =? and clothingid =? order by createDate desc", userid,clothingid);
  515. if(cuList.size() > 0) {
  516. startdate = DateUtils.date_sdf.format(cuList.get(0).getStartdate());
  517. lastdate = DateUtils.date_sdf.format(cuList.get(0).getCreateDate());
  518. }
  519. }catch (Exception e) {
  520. reJson.put("status", "fail");
  521. logger.info(e.getMessage());
  522. return reJson;
  523. }
  524. reJson.put("status", "success");
  525. reJson.put("startdate", startdate);
  526. reJson.put("lastdate", lastdate);
  527. }else{
  528. reJson.put("status", "fail");
  529. reJson.put("msg", "员工、服装信息未找到,查询不到启用日期、上次申领日期");
  530. }
  531. return reJson;
  532. }
  533. @RequestMapping(params = "goView")
  534. public ModelAndView goView(ClothingApplyEntity clothingApply, HttpServletRequest request) {
  535. String taskId = request.getParameter("taskId");
  536. //【我发起的流程】-【详情】中查看业务数据时,只看单据信息,不预览审批流程
  537. if(StringUtils.isEmpty(taskId)) {
  538. clothingApply = clothingApplyService.getEntity(ClothingApplyEntity.class, clothingApply.getId());
  539. request.setAttribute("clothingApplyPage", clothingApply);
  540. request.setAttribute("viewFlag", "1");
  541. return new ModelAndView("cn/com/lzt/clothing/apply/clothingApply-update");
  542. }
  543. // if(StringUtils.isNotEmpty(request.getParameter("flag"))){
  544. // //驳回重填表单
  545. // request.setAttribute("url", "contractController.do?goUpdate&return=1&id="+workflowService.getBpmDataId(taskId));
  546. // }else {
  547. // request.setAttribute("url", "contractController.do?goUpdate&load=detail&audit=1&id="+workflowService.getBpmDataId(taskId));
  548. // }
  549. request.setAttribute("url", "clothingApplyController.do?goUpdate&load=detail&id="+workflowService.getBpmDataId(taskId));
  550. Map<String, Object> taskDetails = workflowService.getTaskDetails(taskId);
  551. request.setAttribute("busititle", "服装申领详细信息");
  552. request.setAttribute("id", workflowService.getBpmDataId(taskId));
  553. request.setAttribute("bpmLogList", taskDetails.get("bpmLogList"));
  554. request.setAttribute("taskId", taskDetails.get("taskId"));
  555. request.setAttribute("taskName", taskDetails.get("taskName"));
  556. request.setAttribute("task", taskDetails.get("task"));
  557. request.setAttribute("transitionList", taskDetails.get("transitionList"));
  558. request.setAttribute("nextCodeCount", taskDetails.get("nextCodeCount"));
  559. request.setAttribute("bpmLogListCount", taskDetails.get("bpmLogListCount"));
  560. request.setAttribute("bpmLogNewList", taskDetails.get("bpmLogNewList"));
  561. request.setAttribute("bpmLogNewListCount", taskDetails.get("bpmLogNewListCount"));
  562. request.setAttribute("histListNode", taskDetails.get("histListNode"));
  563. request.setAttribute("histListSize", taskDetails.get("histListSize"));
  564. request.setAttribute("turnbackTaskId", taskDetails.get("turnbackTaskId"));
  565. request.setAttribute("height", "750px");
  566. return new ModelAndView("cn/com/lzt/workflow/task-option");
  567. }
  568. @RequestMapping(params="exportDetailPdf4Mobile")
  569. public void exportDetailPdf4Mobile(@RequestParam("procInstId") String procInstId, HttpServletResponse response){
  570. ActivitiTools tools = ActivitiTools.getInstance(procInstId,true);
  571. tools.setTitle("服装申领明细");
  572. tools.setProcInstId(null);
  573. ActivitiPdfExport pdfExport = tools.getPdfExport();
  574. String id = tools.getBusId();
  575. ClothingApplyEntity clothingApply = clothingApplyService.getEntity(ClothingApplyEntity.class, id);
  576. String hql0 = "from ClothingApplyDetailEntity where 1 = 1 AND aPPLYID =? ";
  577. List<ClothingApplyDetailEntity> clothingApplyDetailEntityList = systemService.findHql(hql0,clothingApply.getId());
  578. double quantity = 0;
  579. for (ClothingApplyDetailEntity detail : clothingApplyDetailEntityList) {
  580. quantity += detail.getQuantity();
  581. }
  582. BigDecimal totalMoney = clothingApply.getTotalMoney();
  583. pdfExport.table()
  584. .cell("领料点",clothingApply.getWarehousename())
  585. .cell("申请日期",clothingApply.getApplydate())
  586. .cell("申请总数",String.valueOf(quantity))
  587. .cell("总金额",totalMoney==null?"":totalMoney.toPlainString());
  588. try{
  589. pdfExport.cell("");
  590. PdfPTable detailTableHeader = pdfExport.createTable(12);
  591. detailTableHeader.setWidthPercentage(100);
  592. pdfExport.cell(detailTableHeader, "员工姓名", false);
  593. pdfExport.cell(detailTableHeader, "服装名称", false);
  594. pdfExport.cell(detailTableHeader, "服装类型", false);
  595. pdfExport.cell(detailTableHeader, "入职日期", false);
  596. pdfExport.cell(detailTableHeader, "上次申领日期", false);
  597. pdfExport.cell(detailTableHeader, "启用日期", false);
  598. pdfExport.cell(detailTableHeader, "申请原因", false);
  599. pdfExport.cell(detailTableHeader, "单价", false);
  600. pdfExport.cell(detailTableHeader, "申请数量", false);
  601. pdfExport.cell(detailTableHeader, "金额", false);
  602. pdfExport.cell(detailTableHeader, "已有数量", false);
  603. pdfExport.cell(detailTableHeader, "尺寸", false);
  604. pdfExport.cell(detailTableHeader);
  605. int i = 0;
  606. for(ClothingApplyDetailEntity detailEntity:clothingApplyDetailEntityList){
  607. String sql = "select sum(quantity) quantity from t_b_clothing_user where userid = '"
  608. +detailEntity.getUserid()+"' and clothingid = '"+detailEntity.getClothingid()+"'";
  609. List<BigDecimal> quantityList = systemService.findListbySql(sql);
  610. if(quantityList != null && quantityList.size() > 0 && quantityList.get(0) != null) {
  611. detailEntity.setQuantityexist(quantityList.get(0).intValue());
  612. }else {
  613. detailEntity.setQuantityexist(0);
  614. }
  615. i++;
  616. PdfPTable detailTable = pdfExport.createTable(12);
  617. BigDecimal price = detailEntity.getPrice();
  618. BigDecimal money = detailEntity.getMoney();
  619. pdfExport.cell(detailTable,detailEntity.getRealname(),false);
  620. pdfExport.cell(detailTable, detailEntity.getClothingname(), false);
  621. pdfExport.cell(detailTable, DictUtil.formatToTypeName(detailEntity.getType(),"clothingtype") , false);
  622. pdfExport.cell(detailTable, DateUtils.formatDate(detailEntity.getEntrydate(),"yyyy-MM-dd"), false);
  623. pdfExport.cell(detailTable, DateUtils.formatDate(detailEntity.getLastdate(),"yyyy-MM-dd"), false);
  624. pdfExport.cell(detailTable, DateUtils.formatDate(detailEntity.getStartdate(),"yyyy-MM-dd"), false);
  625. pdfExport.cell(detailTable, DictUtil.formatToTypeName(detailEntity.getApplyreason(),"applyreason"), false);
  626. pdfExport.cell(detailTable, price ==null?"":price.toPlainString(), false);
  627. pdfExport.cell(detailTable, String.valueOf(detailEntity.getQuantity()), false);
  628. pdfExport.cell(detailTable, money ==null?"":money.toPlainString(), false);
  629. pdfExport.cell(detailTable, String.valueOf(detailEntity.getQuantityexist()), false);
  630. pdfExport.cell(detailTable, String.valueOf(detailEntity.getSize()), false);
  631. pdfExport.cell("明细"+i,true);
  632. pdfExport.cell(detailTable);
  633. }
  634. }catch(Exception e){
  635. e.printStackTrace();
  636. logger.info(e.getMessage());
  637. }
  638. tools.exportToResponse(response);
  639. }
  640. }