ClothingUserController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. package cn.com.lzt.clothing.user.controller;
  2. import cn.com.lzt.arrangeduty.dto.UserOrgDto;
  3. import cn.com.lzt.clothing.base.entity.ClothingEntity;
  4. import cn.com.lzt.clothing.onhand.service.ClothingOnhandServiceI;
  5. import cn.com.lzt.clothing.user.entity.ClothingUserEntity;
  6. import cn.com.lzt.clothing.user.entity.ClothingUserInitPage;
  7. import cn.com.lzt.clothing.user.service.ClothingUserServiceI;
  8. import cn.com.lzt.dialogDeal.service.UserDepartOrgDealServiceI;
  9. import cn.com.lzt.post.entity.PostEntity;
  10. import cn.com.lzt.warehouse.entity.WarehouseEntity;
  11. import org.apache.log4j.Logger;
  12. import org.jeecgframework.core.beanvalidator.BeanValidators;
  13. import org.jeecgframework.core.common.controller.BaseController;
  14. import org.jeecgframework.core.common.exception.BusinessException;
  15. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  16. import org.jeecgframework.core.common.model.json.AjaxJson;
  17. import org.jeecgframework.core.common.model.json.DataGrid;
  18. import org.jeecgframework.core.constant.Globals;
  19. import org.jeecgframework.core.util.ExceptionUtil;
  20. import org.jeecgframework.core.util.MyBeanUtils;
  21. import org.jeecgframework.core.util.ResourceUtil;
  22. import org.jeecgframework.core.util.StringUtil;
  23. import org.jeecgframework.poi.excel.ExcelImportUtil;
  24. import org.jeecgframework.poi.excel.entity.ExportParams;
  25. import org.jeecgframework.poi.excel.entity.ImportParams;
  26. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  27. import org.jeecgframework.tag.core.easyui.TagUtil;
  28. import org.jeecgframework.web.system.pojo.base.TSDepart;
  29. import org.jeecgframework.web.system.pojo.base.TSUser;
  30. import org.jeecgframework.web.system.service.SystemService;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.http.HttpHeaders;
  33. import org.springframework.http.HttpStatus;
  34. import org.springframework.http.MediaType;
  35. import org.springframework.http.ResponseEntity;
  36. import org.springframework.stereotype.Controller;
  37. import org.springframework.ui.ModelMap;
  38. import org.springframework.web.bind.annotation.*;
  39. import org.springframework.web.multipart.MultipartFile;
  40. import org.springframework.web.multipart.MultipartHttpServletRequest;
  41. import org.springframework.web.servlet.ModelAndView;
  42. import org.springframework.web.util.UriComponentsBuilder;
  43. import javax.servlet.http.HttpServletRequest;
  44. import javax.servlet.http.HttpServletResponse;
  45. import javax.validation.ConstraintViolation;
  46. import javax.validation.Validator;
  47. import java.io.IOException;
  48. import java.net.URI;
  49. import java.util.*;
  50. /**
  51. * @Title: Controller
  52. * @Description: 人员服装使用表
  53. * @author onlineGenerator
  54. * @date 2019-10-08 14:43:22
  55. * @version V1.0
  56. *
  57. */
  58. @Controller
  59. @RequestMapping("/clothingUserController")
  60. public class ClothingUserController extends BaseController {
  61. /**
  62. * Logger for this class
  63. */
  64. private static final Logger logger = Logger.getLogger(ClothingUserController.class);
  65. @Autowired
  66. private ClothingUserServiceI clothingUserService;
  67. @Autowired
  68. private SystemService systemService;
  69. @Autowired
  70. private Validator validator;
  71. @Autowired
  72. private ClothingOnhandServiceI onhandService;
  73. @Autowired
  74. private UserDepartOrgDealServiceI userOrgdao;
  75. /**
  76. * 人员服装使用表列表 页面跳转
  77. *
  78. * @return
  79. */
  80. @RequestMapping(params = "list")
  81. public ModelAndView list(HttpServletRequest request) {
  82. String userid = request.getParameter("userid");
  83. request.setAttribute("userid", userid);
  84. return new ModelAndView("cn/com/lzt/clothing/user/clothingUserList");
  85. }
  86. /**
  87. * easyui AJAX请求数据
  88. *
  89. * @param request
  90. * @param response
  91. * @param dataGrid
  92. * @param user
  93. */
  94. @RequestMapping(params = "datagrid")
  95. public void datagrid(ClothingUserEntity clothingUser,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  96. CriteriaQuery cq = new CriteriaQuery(ClothingUserEntity.class, dataGrid);
  97. //查询条件组装器
  98. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, clothingUser, request.getParameterMap());
  99. try{
  100. //自定义追加查询条件
  101. }catch (Exception e) {
  102. throw new BusinessException(e.getMessage());
  103. }
  104. cq.add();
  105. this.clothingUserService.getDataGridReturn(cq, true);
  106. TagUtil.datagrid(response, dataGrid);
  107. }
  108. /**
  109. * 删除人员服装使用表
  110. *
  111. * @return
  112. */
  113. @RequestMapping(params = "doDel")
  114. @ResponseBody
  115. public AjaxJson doDel(ClothingUserEntity clothingUser, HttpServletRequest request) {
  116. String message = null;
  117. AjaxJson j = new AjaxJson();
  118. clothingUser = systemService.getEntity(ClothingUserEntity.class, clothingUser.getId());
  119. message = "人员服装使用表删除成功";
  120. try{
  121. clothingUserService.delete(clothingUser);
  122. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  123. }catch(Exception e){
  124. e.printStackTrace();
  125. message = "人员服装使用表删除失败";
  126. throw new BusinessException(e.getMessage());
  127. }
  128. j.setMsg(message);
  129. return j;
  130. }
  131. /**
  132. * 批量删除人员服装使用表
  133. *
  134. * @return
  135. */
  136. @RequestMapping(params = "doBatchDel")
  137. @ResponseBody
  138. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  139. String message = null;
  140. AjaxJson j = new AjaxJson();
  141. message = "人员服装使用表删除成功";
  142. try{
  143. for(String id:ids.split(",")){
  144. ClothingUserEntity clothingUser = systemService.getEntity(ClothingUserEntity.class,
  145. id
  146. );
  147. clothingUserService.delete(clothingUser);
  148. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  149. }
  150. }catch(Exception e){
  151. e.printStackTrace();
  152. message = "人员服装使用表删除失败";
  153. throw new BusinessException(e.getMessage());
  154. }
  155. j.setMsg(message);
  156. return j;
  157. }
  158. /**
  159. * 添加人员服装使用表
  160. *
  161. * @param ids
  162. * @return
  163. */
  164. @RequestMapping(params = "doAdd")
  165. @ResponseBody
  166. public AjaxJson doAdd(ClothingUserEntity clothingUser, HttpServletRequest request) {
  167. String message = null;
  168. AjaxJson j = new AjaxJson();
  169. message = "人员服装使用表添加成功";
  170. try{
  171. clothingUser.setQuantitykeeping(clothingUser.getQuantity());
  172. clothingUser.setQuantitystoped(0);
  173. clothingUserService.save(clothingUser);
  174. onhandService.updateOnhand4Use(clothingUser.getWarehouseid(), clothingUser.getClothingid(), clothingUser.getQuantity(), clothingUser.getStartdate(), "2");
  175. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  176. }catch(Exception e){
  177. e.printStackTrace();
  178. message = "人员服装使用表添加失败";
  179. throw new BusinessException(e.getMessage());
  180. }
  181. j.setMsg(message);
  182. return j;
  183. }
  184. /**
  185. * 更新人员服装使用表
  186. *
  187. * @param ids
  188. * @return
  189. */
  190. @RequestMapping(params = "doUpdate")
  191. @ResponseBody
  192. public AjaxJson doUpdate(ClothingUserEntity clothingUser, HttpServletRequest request) {
  193. String message = null;
  194. AjaxJson j = new AjaxJson();
  195. message = "人员服装使用表更新成功";
  196. ClothingUserEntity t = clothingUserService.get(ClothingUserEntity.class, clothingUser.getId());
  197. try {
  198. MyBeanUtils.copyBeanNotNull2Bean(clothingUser, t);
  199. clothingUserService.saveOrUpdate(t);
  200. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  201. } catch (Exception e) {
  202. e.printStackTrace();
  203. message = "人员服装使用表更新失败";
  204. throw new BusinessException(e.getMessage());
  205. }
  206. j.setMsg(message);
  207. return j;
  208. }
  209. /**
  210. * 人员服装使用表新增页面跳转
  211. *
  212. * @return
  213. */
  214. @RequestMapping(params = "goAdd")
  215. public ModelAndView goAdd(ClothingUserEntity clothingUser, HttpServletRequest req) {
  216. if (StringUtil.isNotEmpty(clothingUser.getId())) {
  217. clothingUser = clothingUserService.getEntity(ClothingUserEntity.class, clothingUser.getId());
  218. }
  219. req.setAttribute("clothingUserPage", clothingUser);
  220. return new ModelAndView("cn/com/lzt/clothing/user/clothingUser-add");
  221. }
  222. /**
  223. * 人员服装使用表编辑页面跳转
  224. *
  225. * @return
  226. */
  227. @RequestMapping(params = "goUpdate")
  228. public ModelAndView goUpdate(ClothingUserEntity clothingUser, HttpServletRequest req) {
  229. if (StringUtil.isNotEmpty(clothingUser.getId())) {
  230. clothingUser = clothingUserService.getEntity(ClothingUserEntity.class, clothingUser.getId());
  231. req.setAttribute("clothingUserPage", clothingUser);
  232. }
  233. return new ModelAndView("cn/com/lzt/clothing/user/clothingUser-update");
  234. }
  235. /**
  236. * 导入功能跳转
  237. *
  238. * @return
  239. */
  240. @RequestMapping(params = "upload")
  241. public ModelAndView upload(HttpServletRequest req) {
  242. req.setAttribute("controller_name","clothingUserController");
  243. return new ModelAndView("common/upload/pub_excel_upload");
  244. }
  245. /**
  246. * 导出excel
  247. *
  248. * @param request
  249. * @param response
  250. */
  251. @RequestMapping(params = "exportXls")
  252. public String exportXls(ClothingUserEntity clothingUser,HttpServletRequest request,HttpServletResponse response
  253. , DataGrid dataGrid,ModelMap modelMap) {
  254. CriteriaQuery cq = new CriteriaQuery(ClothingUserEntity.class, dataGrid);
  255. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, clothingUser, request.getParameterMap());
  256. List<ClothingUserEntity> clothingUsers = this.clothingUserService.getListByCriteriaQuery(cq,false);
  257. modelMap.put(NormalExcelConstants.FILE_NAME,"人员服装使用表");
  258. modelMap.put(NormalExcelConstants.CLASS,ClothingUserEntity.class);
  259. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("人员服装使用表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  260. "导出信息"));
  261. modelMap.put(NormalExcelConstants.DATA_LIST,clothingUsers);
  262. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  263. }
  264. /**
  265. * 导出excel 使模板
  266. *
  267. * @param request
  268. * @param response
  269. */
  270. @RequestMapping(params = "exportXlsByT")
  271. public String exportXlsByT(ClothingUserEntity clothingUser,HttpServletRequest request,HttpServletResponse response
  272. , DataGrid dataGrid,ModelMap modelMap) {
  273. modelMap.put(NormalExcelConstants.FILE_NAME,"人员服装使用表");
  274. modelMap.put(NormalExcelConstants.CLASS,ClothingUserEntity.class);
  275. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("人员服装使用表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  276. "导出信息"));
  277. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  278. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  279. }
  280. @SuppressWarnings("unchecked")
  281. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  282. @ResponseBody
  283. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  284. AjaxJson j = new AjaxJson();
  285. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  286. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  287. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  288. MultipartFile file = entity.getValue();// 获取上传文件对象
  289. ImportParams params = new ImportParams();
  290. params.setTitleRows(2);
  291. params.setHeadRows(1);
  292. params.setNeedSave(true);
  293. try {
  294. List<ClothingUserEntity> listClothingUserEntitys = ExcelImportUtil.importExcel(file.getInputStream(),ClothingUserEntity.class,params);
  295. for (ClothingUserEntity clothingUser : listClothingUserEntitys) {
  296. clothingUserService.save(clothingUser);
  297. }
  298. j.setMsg("文件导入成功!");
  299. } catch (Exception e) {
  300. j.setMsg("文件导入失败!");
  301. logger.error(ExceptionUtil.getExceptionMessage(e));
  302. }finally{
  303. try {
  304. file.getInputStream().close();
  305. } catch (IOException e) {
  306. e.printStackTrace();
  307. }
  308. }
  309. }
  310. return j;
  311. }
  312. @RequestMapping(method = RequestMethod.GET)
  313. @ResponseBody
  314. public List<ClothingUserEntity> list() {
  315. List<ClothingUserEntity> listClothingUsers=clothingUserService.getList(ClothingUserEntity.class);
  316. return listClothingUsers;
  317. }
  318. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  319. @ResponseBody
  320. public ResponseEntity<?> get(@PathVariable("id") String id) {
  321. ClothingUserEntity task = clothingUserService.get(ClothingUserEntity.class, id);
  322. if (task == null) {
  323. return new ResponseEntity(HttpStatus.NOT_FOUND);
  324. }
  325. return new ResponseEntity(task, HttpStatus.OK);
  326. }
  327. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  328. @ResponseBody
  329. public ResponseEntity<?> create(@RequestBody ClothingUserEntity clothingUser, UriComponentsBuilder uriBuilder) {
  330. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  331. Set<ConstraintViolation<ClothingUserEntity>> failures = validator.validate(clothingUser);
  332. if (!failures.isEmpty()) {
  333. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  334. }
  335. //保存
  336. try{
  337. clothingUserService.save(clothingUser);
  338. } catch (Exception e) {
  339. e.printStackTrace();
  340. return new ResponseEntity(HttpStatus.NO_CONTENT);
  341. }
  342. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  343. String id = clothingUser.getId();
  344. URI uri = uriBuilder.path("/rest/clothingUserController/" + id).build().toUri();
  345. HttpHeaders headers = new HttpHeaders();
  346. headers.setLocation(uri);
  347. return new ResponseEntity(headers, HttpStatus.CREATED);
  348. }
  349. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  350. public ResponseEntity<?> update(@RequestBody ClothingUserEntity clothingUser) {
  351. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  352. Set<ConstraintViolation<ClothingUserEntity>> failures = validator.validate(clothingUser);
  353. if (!failures.isEmpty()) {
  354. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  355. }
  356. //保存
  357. try{
  358. clothingUserService.saveOrUpdate(clothingUser);
  359. } catch (Exception e) {
  360. e.printStackTrace();
  361. return new ResponseEntity(HttpStatus.NO_CONTENT);
  362. }
  363. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  364. return new ResponseEntity(HttpStatus.NO_CONTENT);
  365. }
  366. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  367. @ResponseStatus(HttpStatus.NO_CONTENT)
  368. public void delete(@PathVariable("id") String id) {
  369. clothingUserService.deleteEntityById(ClothingUserEntity.class, id);
  370. }
  371. // 归还
  372. @RequestMapping(params = "doReturn")
  373. @ResponseBody
  374. public AjaxJson doReturn(ClothingUserEntity clothingUser, HttpServletRequest request) {
  375. //carOnlineClientService.getAccessToken();
  376. String message = null;
  377. AjaxJson j = new AjaxJson();
  378. clothingUser = systemService.getEntity(ClothingUserEntity.class, clothingUser.getId());
  379. message = "人员服装退还成功";
  380. try{
  381. // ClothingUserEntity returnEntity = new ClothingUserEntity();
  382. // MyBeanUtils.copyBeanNotNull2Bean(clothingUser, returnEntity);
  383. // returnEntity.setId(null);
  384. // returnEntity.setQuantity(returnEntity.getQuantity());
  385. // returnEntity.setCreateDate(null);
  386. // returnEntity.setCreateBy(null);
  387. // returnEntity.setCreateName(null);
  388. // returnEntity.setStatus("");
  389. // returnEntity.setSourcetype("3");
  390. // clothingUserService.save(returnEntity);
  391. clothingUser.setQuantitykeeping(0);
  392. clothingUser.setQuantitystoped(clothingUser.getQuantity());
  393. clothingUser.setReturndate(new Date());
  394. clothingUser.setStatus("0");
  395. clothingUserService.saveOrUpdate(clothingUser);
  396. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  397. //更新现存量
  398. onhandService.updateOnhand4Use(clothingUser.getWarehouseid(), clothingUser.getClothingid(), clothingUser.getQuantity(), clothingUser.getStartdate(), "3");
  399. }catch(Exception e){
  400. e.printStackTrace();
  401. message = "人员服装退还失败";
  402. throw new BusinessException(e.getMessage());
  403. }
  404. j.setMsg(message);
  405. return j;
  406. }
  407. @RequestMapping(params = "initList")
  408. public ModelAndView initList(HttpServletRequest request) {
  409. String userid = request.getParameter("userid");
  410. String postid = request.getParameter("postid");
  411. //找员工所属部门
  412. UserOrgDto userOrgDto = new UserOrgDto();
  413. userOrgDto.setUserId(userid);
  414. List<UserOrgDto> dtos = userOrgdao.getUserOrgDtoByUserId(userOrgDto , null);
  415. String departStr = "";
  416. for (UserOrgDto userOrg : dtos) {
  417. if(userOrg.getIfpluralism().equals("0")) {
  418. TSDepart dept = systemService.get(TSDepart.class, userOrg.getOrgId());
  419. if(dept.getOrgCode().length() == 6) {
  420. departStr = dept.getId();
  421. }else {
  422. departStr = dept.getTSPDepart().getId();
  423. }
  424. break;
  425. }
  426. }
  427. request.setAttribute("userid", userid);
  428. request.setAttribute("departid", departStr);
  429. request.setAttribute("postid", postid);
  430. return new ModelAndView("cn/com/lzt/clothing/user/clothingUserInit");
  431. }
  432. @RequestMapping(params = "initDetail")
  433. public ModelAndView initDetail(HttpServletRequest request) {
  434. String userid = request.getParameter("userid");
  435. String postid = request.getParameter("postid");
  436. String departid = request.getParameter("departid");
  437. PostEntity post = systemService.get(PostEntity.class,postid);
  438. List<WarehouseEntity> warehouseList = systemService.findHql("From WarehouseEntity where projectId=? ",departid);
  439. String warehouseid = "";
  440. if(warehouseList.size() > 0) {
  441. warehouseid = warehouseList.get(0).getId();
  442. }
  443. TSUser user = systemService.get(TSUser.class, userid);
  444. //性别,0 男 1 女
  445. String gender = user.getGender();
  446. String clothingtype = null;
  447. //根据员工性别、岗位,规范可以领取服装的范围
  448. if(post.getPostName().indexOf("保安") > -1) {
  449. if(post.getPostName().indexOf("礼仪") > -1) {
  450. clothingtype = "pbf";//普保女
  451. }else {
  452. clothingtype = "pbm_tb";//普保男
  453. }
  454. }else if(post.getPostName().indexOf("保洁") > -1) {
  455. clothingtype = "bj";//保洁
  456. if(post.getPostName().indexOf("主管") > -1)
  457. clothingtype +="_bgsf";
  458. }else if(post.getPostName().indexOf("工程") > -1 || post.getPostName().indexOf("电梯工") > -1) {
  459. clothingtype = "gc";//工程
  460. }else if(post.getPostName().indexOf("会务") > -1) {
  461. if(gender.equals("0")) {
  462. clothingtype = "hwm";//会务男
  463. }else {
  464. clothingtype = "hwf";//会务女
  465. }
  466. }else if(post.getPostName().indexOf("绿化") > -1) {
  467. clothingtype = "yh";
  468. }else if(post.getPostName().indexOf("宿管") > -1 || post.getPostName().indexOf("票务") > -1) {
  469. clothingtype = "sg";
  470. }else {
  471. if(gender.equals("0")) {
  472. clothingtype = "bgsm";
  473. }else {
  474. clothingtype = "bgsf";
  475. }
  476. }
  477. String clothingSql = "'"+clothingtype.replace("_", "','")+"'";
  478. List<ClothingEntity> clothings = systemService.findHql("From ClothingEntity where type in ("+clothingSql+")");
  479. List<ClothingUserEntity> clothingUserList = new ArrayList<ClothingUserEntity>();
  480. for (ClothingEntity clothing : clothings) {
  481. ClothingUserEntity cu = new ClothingUserEntity();
  482. cu.setUserid(userid);
  483. cu.setClothingid(clothing.getId());
  484. cu.setClothingname(clothing.getName());
  485. cu.setQuantity(0);
  486. cu.setSourcetype("4");
  487. cu.setUnit(clothing.getUnit());
  488. cu.setWarehouseid(warehouseid);
  489. cu.setType(clothing.getType());
  490. clothingUserList.add(cu);
  491. }
  492. request.setAttribute("departid", departid);
  493. request.setAttribute("clothingUserDetailList", clothingUserList);
  494. return new ModelAndView("cn/com/lzt/clothing/user/clothingUserDetailList");
  495. }
  496. @RequestMapping(params = "doInitAdd")
  497. @ResponseBody
  498. public AjaxJson doInitAdd(ClothingUserInitPage page, HttpServletRequest request) {
  499. String message = null;
  500. AjaxJson j = new AjaxJson();
  501. message = "人员服装使用表初始化添加成功";
  502. try{
  503. if(page.getClothingUserDetailList().size() > 0) {
  504. //先删除原初始化数据,在重新插入,不做update处理
  505. String sql = "delete from t_b_clothing_user where userid = ?" ;
  506. systemService.executeSql(sql, page.getClothingUserDetailList().get(0).getUserid());
  507. String wid = "",wname = "";
  508. for (ClothingUserEntity clothingUser : page.getClothingUserDetailList()) {
  509. if(clothingUser.getQuantity() != null && clothingUser.getQuantity() > 0) {
  510. if(!wid.equals(clothingUser.getWarehouseid())) {
  511. wid = clothingUser.getWarehouseid();
  512. wname = systemService.get(WarehouseEntity.class,wid).getWarehouseName();
  513. }
  514. clothingUser.setWarehousename(wname);
  515. clothingUser.setQuantitykeeping(clothingUser.getQuantity());
  516. clothingUser.setQuantitystoped(0);
  517. clothingUserService.save(clothingUser);
  518. onhandService.updateOnhand4Use(clothingUser.getWarehouseid(), clothingUser.getClothingid(), clothingUser.getQuantity(), clothingUser.getStartdate(), "1");
  519. }
  520. }
  521. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  522. }
  523. }catch(Exception e){
  524. e.printStackTrace();
  525. message = "人员服装使用情况初始化添加失败";
  526. throw new BusinessException(e.getMessage());
  527. }
  528. j.setMsg(message);
  529. return j;
  530. }
  531. }