TBGoodsInfoController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. package cn.com.lzt.goodsinfo.controller;
  2. import java.io.IOException;
  3. import java.net.URI;
  4. import java.util.*;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import javax.servlet.http.HttpSession;
  8. import javax.validation.ConstraintViolation;
  9. import javax.validation.Validator;
  10. import org.apache.commons.lang3.StringUtils;
  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.*;
  20. import org.jeecgframework.minidao.pojo.MiniDaoPage;
  21. import org.jeecgframework.poi.excel.ExcelImportUtil;
  22. import org.jeecgframework.poi.excel.entity.ExportParams;
  23. import org.jeecgframework.poi.excel.entity.ImportParams;
  24. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  25. import org.jeecgframework.tag.core.easyui.TagUtil;
  26. import org.jeecgframework.web.system.pojo.base.TSUser;
  27. import org.jeecgframework.web.system.service.SystemService;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.http.HttpHeaders;
  30. import org.springframework.http.HttpStatus;
  31. import org.springframework.http.MediaType;
  32. import org.springframework.http.ResponseEntity;
  33. import org.springframework.stereotype.Controller;
  34. import org.springframework.ui.ModelMap;
  35. import org.springframework.web.bind.annotation.PathVariable;
  36. import org.springframework.web.bind.annotation.RequestBody;
  37. import org.springframework.web.bind.annotation.RequestMapping;
  38. import org.springframework.web.bind.annotation.RequestMethod;
  39. import org.springframework.web.bind.annotation.ResponseBody;
  40. import org.springframework.web.bind.annotation.ResponseStatus;
  41. import org.springframework.web.multipart.MultipartFile;
  42. import org.springframework.web.multipart.MultipartHttpServletRequest;
  43. import org.springframework.web.servlet.ModelAndView;
  44. import org.springframework.web.util.UriComponentsBuilder;
  45. import cn.com.lzt.goodscategory.entity.TBGoodsCategoryEntity;
  46. import cn.com.lzt.goodsinfo.dao.TBGoodsDao;
  47. import cn.com.lzt.goodsinfo.entity.TBGoodsInfoEntity;
  48. import cn.com.lzt.goodsinfo.entity.TBGoodsRelatedUnitPriceEntity;
  49. import cn.com.lzt.goodsinfo.page.TBGoodsInfoPage;
  50. import cn.com.lzt.goodsinfo.service.TBGoodsInfoServiceI;
  51. import cn.com.lzt.priceinfo.entity.TBPriceInfoEntity;
  52. import cn.com.lzt.relatedunits.entity.RelatedUnitsEntity;
  53. import cn.com.lzt.stockinfo.entity.TBStockInfoEntity;
  54. import cn.com.lzt.tools.SaltUtil;
  55. /**
  56. * @author onlineGenerator
  57. * @version V1.0
  58. * @Title: Controller
  59. * @Description: 货品信息
  60. * @date 2017-06-08 20:42:39
  61. */
  62. @Controller
  63. @RequestMapping("/tBGoodsInfoController")
  64. public class TBGoodsInfoController extends BaseController {
  65. /**
  66. * Logger for this class
  67. */
  68. private static final Logger logger = Logger.getLogger(TBGoodsInfoController.class);
  69. @Autowired
  70. private TBGoodsInfoServiceI tBGoodsInfoService;
  71. @Autowired
  72. private SystemService systemService;
  73. @Autowired
  74. private Validator validator;
  75. @Autowired
  76. private TBGoodsDao goodsDao;
  77. /**
  78. * 货品信息列表 页面跳转
  79. *
  80. * @return
  81. */
  82. @RequestMapping(params = "list")
  83. public ModelAndView list(HttpServletRequest request) {
  84. return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfoList");
  85. }
  86. /**
  87. * easyui AJAX请求数据
  88. *
  89. * @param request
  90. * @param response
  91. * @param dataGrid
  92. */
  93. @RequestMapping(params = "datagrid")
  94. public void datagrid(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  95. String sqlString = JeecgDataAutorUtils.loadDataSearchConditonSQLString();
  96. if(StringUtils.isNotEmpty(sqlString)){
  97. String[] sqlSplit =sqlString.split("'");
  98. String belongCategorySql = sqlSplit[1];
  99. tBGoodsInfo.setBelongCategory(belongCategorySql);
  100. if(sqlString.contains("!=")){
  101. sqlString = belongCategorySql;
  102. tBGoodsInfo.setBelongCategory(null);
  103. }else{
  104. sqlString = null;
  105. }
  106. }
  107. MiniDaoPage<TBGoodsInfoEntity> page = null;
  108. page = goodsDao.getGoodsInfoList(tBGoodsInfo, dataGrid.getPage(), dataGrid.getRows(), sqlString);
  109. dataGrid.setResults(page.getResults());
  110. dataGrid.setTotal(page.getTotal());
  111. TagUtil.datagrid(response, dataGrid);
  112. }
  113. /**
  114. * 删除货品信息
  115. *
  116. * @return
  117. */
  118. @RequestMapping(params = "doDel")
  119. @ResponseBody
  120. public AjaxJson doDel(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request) {
  121. AjaxJson j = new AjaxJson();
  122. tBGoodsInfo = systemService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
  123. String message = "货品信息 删除成功";
  124. try {
  125. tBGoodsInfoService.delMain(tBGoodsInfo);
  126. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  127. } catch (Exception e) {
  128. e.printStackTrace();
  129. message = "货品信息 删除失败";
  130. throw new BusinessException(e.getMessage());
  131. }
  132. j.setMsg(message);
  133. return j;
  134. }
  135. /**
  136. * 逻辑删除物流
  137. *
  138. * @return
  139. */
  140. @RequestMapping(params = "logicDel")
  141. @ResponseBody
  142. public AjaxJson logicDel(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request) {
  143. String message = null;
  144. AjaxJson j = new AjaxJson();
  145. tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
  146. message = "货品信息 删除成功";
  147. try {
  148. tBGoodsInfo.setDeleteFlag(Globals.Delete_Forbidden.toString());
  149. tBGoodsInfoService.logicDelMain(tBGoodsInfo);
  150. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  151. } catch (Exception e) {
  152. e.printStackTrace();
  153. message = "货品信息 删除失败";
  154. throw new BusinessException(e.getMessage());
  155. }
  156. j.setMsg(message);
  157. return j;
  158. }
  159. /**
  160. * 批量删除货品信息
  161. *
  162. * @return
  163. */
  164. @RequestMapping(params = "doBatchDel")
  165. @ResponseBody
  166. public AjaxJson doBatchDel(String ids, HttpServletRequest request) {
  167. AjaxJson j = new AjaxJson();
  168. String message = "货品信息删除成功";
  169. try {
  170. for (String id : ids.split(",")) {
  171. TBGoodsInfoEntity tBGoodsInfo = systemService.getEntity(TBGoodsInfoEntity.class,
  172. id
  173. );
  174. tBGoodsInfo.setDeleteFlag("1");
  175. tBGoodsInfoService.updateEntitie(tBGoodsInfo);
  176. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  177. }
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. message = "货品信息删除失败";
  181. throw new BusinessException(e.getMessage());
  182. }
  183. j.setMsg(message);
  184. return j;
  185. }
  186. /**
  187. * 添加货品信息
  188. *
  189. * @return
  190. */
  191. @RequestMapping(params = "doAdd")
  192. @ResponseBody
  193. public AjaxJson doAdd(TBGoodsInfoEntity tBGoodsInfo) {
  194. AjaxJson j = new AjaxJson();
  195. String message;
  196. // TODO (测试阶段:刘梦祥-2021年11月24日23:00:23)
  197. try {
  198. // 首先判断是否是新增操作(即存在id为编辑操作)
  199. HttpSession session = ContextHolderUtils.getSession();
  200. TSUser tuser = (TSUser) session.getAttribute("LOCAL_CLINET_USER");
  201. // 添加默认属性(即使数据库有默认字段填充也不行)
  202. tBGoodsInfo.setStatus("0");
  203. tBGoodsInfo.setDeleteFlag("0");
  204. if (tBGoodsInfo.getId() != null && !"".equals(tBGoodsInfo.getId())) {
  205. // 编辑操作
  206. tBGoodsInfo.setUpdateName(tuser.getRealName());
  207. tBGoodsInfo.setUpdateDate(new Date());
  208. tBGoodsInfo.setUpdateBy(tuser.getUserName());
  209. this.tBGoodsInfoService.updateEntitie(tBGoodsInfo);
  210. message = "编辑成功";
  211. } else {
  212. // 新增操作
  213. tBGoodsInfo.setId(UUID.randomUUID().toString());
  214. tBGoodsInfo.setCreateName(tuser.getRealName());
  215. tBGoodsInfo.setCreateDate(new Date());
  216. tBGoodsInfo.setCreateBy(tuser.getUserName());
  217. this.tBGoodsInfoService.save(tBGoodsInfo);
  218. message = "添加成功";
  219. }
  220. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  221. } catch (Exception e) {
  222. j.setSuccess(false);
  223. e.printStackTrace();
  224. message = "货品信息添加或修改失败";
  225. throw new BusinessException(e.getMessage());
  226. }
  227. j.setMsg(message);
  228. return j;
  229. }
  230. /**
  231. * 更新货品信息
  232. *
  233. * @return
  234. */
  235. @RequestMapping(params = "doUpdate")
  236. @ResponseBody
  237. public AjaxJson doUpdate(TBGoodsInfoEntity tBGoodsInfo, TBGoodsInfoPage tBGoodsInfoPage, HttpServletRequest request) {
  238. List<TBStockInfoEntity> tBStockInfoList = tBGoodsInfoPage.getTBStockInfoList();
  239. List<TBPriceInfoEntity> tBPriceInfoList = tBGoodsInfoPage.getTBPriceInfoList();
  240. List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoList = tBGoodsInfoPage.getTBRelatedUnitPriceInfoList();
  241. AjaxJson j = new AjaxJson();
  242. String message = "更新成功";
  243. try {
  244. if (tBGoodsInfo.getBelongCategory() == null || "".equals(tBGoodsInfo.getBelongCategory())) {
  245. message = "请选择所属分类!";
  246. j.setMsg(message);
  247. j.setSuccess(false);
  248. return j;
  249. }
  250. if (tBPriceInfoList == null || tBPriceInfoList.size() <= 0) {
  251. message = "请确认价格信息是否修改后,再提交页面。";
  252. j.setMsg(message);
  253. j.setSuccess(false);
  254. return j;
  255. }
  256. int baseUnitCount = 0;
  257. Map<String, TBPriceInfoEntity> map = new HashMap<String, TBPriceInfoEntity>();
  258. for (int i = 0; i < tBPriceInfoList.size(); i++) {
  259. TBPriceInfoEntity priceInfo = tBPriceInfoList.get(i);
  260. if (priceInfo.getMeteringUnit() != null && !"".equals(priceInfo.getMeteringUnit())) {
  261. map.put(priceInfo.getMeteringUnit(), priceInfo);
  262. //必须填入一条基本单位的价格信息
  263. if (priceInfo.getMeteringUnit().equals(tBGoodsInfo.getBaseUnit())) {
  264. baseUnitCount++;
  265. }
  266. }
  267. }
  268. if (tBPriceInfoList.size() != map.size()) {
  269. message = "计量单位不能重复,请重新选择!";
  270. j.setMsg(message);
  271. j.setSuccess(false);
  272. return j;
  273. }
  274. if (!map.containsKey(tBGoodsInfo.getSalesUnit())) {
  275. message = "申购时默认计量单位未在价格信息里定义,请重新选择!";
  276. j.setMsg(message);
  277. j.setSuccess(false);
  278. return j;
  279. }
  280. if (!map.containsKey(tBGoodsInfo.getPurchaseUnit())) {
  281. message = "采购时默认计量单位未在价格信息里定义,请重新选择!";
  282. j.setMsg(message);
  283. j.setSuccess(false);
  284. return j;
  285. }
  286. if (baseUnitCount == 0) {
  287. message = "必须填入一条基本单位的价格信息!";
  288. j.setMsg(message);
  289. j.setSuccess(false);
  290. return j;
  291. }
  292. if (baseUnitCount > 1) {
  293. message = "只能填入一条基本单位的价格信息!";
  294. j.setMsg(message);
  295. j.setSuccess(false);
  296. return j;
  297. }
  298. Map<String, TBGoodsRelatedUnitPriceEntity> rumap = new HashMap<String, TBGoodsRelatedUnitPriceEntity>();
  299. boolean relatedUnitRepetitionflag = false;
  300. for (int i = 0; i < tBRelatedUnitPriceInfoList.size(); i++) {
  301. TBGoodsRelatedUnitPriceEntity priceInfo = tBRelatedUnitPriceInfoList.get(i);
  302. if (priceInfo.getMeteringUnit() != null && !"".equals(priceInfo.getMeteringUnit())) {
  303. rumap.put(priceInfo.getRelatedunitid(), priceInfo);
  304. } else {
  305. relatedUnitRepetitionflag = true;
  306. break;
  307. }
  308. }
  309. if (relatedUnitRepetitionflag) {
  310. message = "供应商价格不能重复,请修改后再保存";
  311. j.setMsg(message);
  312. j.setSuccess(false);
  313. return j;
  314. }
  315. if (tBGoodsInfo.getBelongCategory() != null) {
  316. TBGoodsCategoryEntity category = systemService.get(TBGoodsCategoryEntity.class, tBGoodsInfo.getBelongCategory());
  317. if (category != null) {
  318. tBGoodsInfo.setBelongCategoryCode(category.getCategoryCode());
  319. }
  320. }
  321. tBGoodsInfo.setStatus(Globals.Enabled.toString());
  322. tBGoodsInfo.setDeleteFlag(Globals.Delete_Normal.toString());
  323. tBGoodsInfoService.updateMain(tBGoodsInfo, tBStockInfoList, tBPriceInfoList, tBRelatedUnitPriceInfoList);
  324. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  325. } catch (Exception e) {
  326. e.printStackTrace();
  327. message = "更新货品信息失败";
  328. throw new BusinessException(e.getMessage());
  329. }
  330. j.setMsg(message);
  331. return j;
  332. }
  333. /**
  334. * 货品信息新增页面跳转
  335. *
  336. * @return
  337. */
  338. @RequestMapping(params = "goAdd")
  339. public ModelAndView goAdd(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
  340. if (StringUtil.isNotEmpty(tBGoodsInfo.getId())) {
  341. tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
  342. req.setAttribute("tBGoodsInfoPage", tBGoodsInfo);
  343. }
  344. return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfo-AUD");
  345. }
  346. /**
  347. * 未知型号商品添加
  348. */
  349. @RequestMapping(params = "goUnknownAdd")
  350. public ModelAndView goUnknownAdd(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
  351. if (StringUtil.isNotEmpty(tBGoodsInfo.getId())) {
  352. tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
  353. req.setAttribute("tBGoodsInfoPage", tBGoodsInfo);
  354. }
  355. return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfo-unknown-add");
  356. }
  357. /**
  358. * 货品信息编辑页面跳转
  359. *
  360. * @return
  361. */
  362. @RequestMapping(params = "goUpdate")
  363. public ModelAndView goUpdate(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
  364. if (StringUtil.isNotEmpty(tBGoodsInfo.getId())) {
  365. tBGoodsInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, tBGoodsInfo.getId());
  366. req.setAttribute("entity", tBGoodsInfo);
  367. }
  368. return new ModelAndView("cn/com/lzt/goodsinfo/tBGoodsInfo-AUD");
  369. }
  370. /**
  371. * 加载明细列表[库存信息]
  372. *
  373. * @return
  374. */
  375. @RequestMapping(params = "tBStockInfoList")
  376. public ModelAndView tBStockInfoList(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
  377. //===================================================================================
  378. //获取参数
  379. Object id0 = tBGoodsInfo.getId();
  380. //===================================================================================
  381. //查询-库存信息
  382. String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? ";
  383. try {
  384. List<TBStockInfoEntity> tBStockInfoEntityList = systemService.findHql(hql0, id0);
  385. req.setAttribute("tBStockInfoList", tBStockInfoEntityList);
  386. } catch (Exception e) {
  387. logger.info(e.getMessage());
  388. }
  389. return new ModelAndView("cn/com/lzt/stockinfo/tBStockInfoList");
  390. }
  391. /**
  392. * 加载明细列表[价格信息]
  393. *
  394. * @return
  395. */
  396. @RequestMapping(params = "tBPriceInfoList")
  397. public ModelAndView tBPriceInfoList(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
  398. //===================================================================================
  399. //获取参数
  400. Object id1 = tBGoodsInfo.getId();
  401. //===================================================================================
  402. //查询-价格信息
  403. String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? ";
  404. try {
  405. List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql1, id1);
  406. req.setAttribute("tBPriceInfoList", tBPriceInfoEntityList);
  407. } catch (Exception e) {
  408. logger.info(e.getMessage());
  409. }
  410. return new ModelAndView("cn/com/lzt/priceinfo/tBPriceInfoList");
  411. }
  412. @RequestMapping(params = "tBRelatedUnitPriceInfoList")
  413. public ModelAndView tBRelatedUnitPriceInfoList(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
  414. //===================================================================================
  415. //获取参数
  416. Object id1 = tBGoodsInfo.getId();
  417. //===================================================================================
  418. //查询-价格信息
  419. String hql1 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? ";
  420. try {
  421. List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoEntityList = systemService.findHql(hql1, id1);
  422. req.setAttribute("tBRelatedUnitPriceInfoList", tBRelatedUnitPriceInfoEntityList);
  423. } catch (Exception e) {
  424. logger.info(e.getMessage());
  425. }
  426. return new ModelAndView("cn/com/lzt/goodsinfo/tBRelatedUnitPriceInfoList");
  427. }
  428. /**
  429. * 导出excel
  430. *
  431. * @param request
  432. * @param response
  433. */
  434. @RequestMapping(params = "exportXls")
  435. public String exportXls(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, ModelMap map) {
  436. CriteriaQuery cq = new CriteriaQuery(TBGoodsInfoEntity.class, dataGrid);
  437. //查询条件组装器
  438. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBGoodsInfo);
  439. try {
  440. //自定义追加查询条件
  441. } catch (Exception e) {
  442. throw new BusinessException(e.getMessage());
  443. }
  444. cq.add();
  445. List<TBGoodsInfoEntity> list = this.tBGoodsInfoService.getListByCriteriaQuery(cq, false);
  446. List<TBGoodsInfoPage> pageList = new ArrayList<TBGoodsInfoPage>();
  447. if (list != null && list.size() > 0) {
  448. for (TBGoodsInfoEntity entity : list) {
  449. try {
  450. TBGoodsInfoPage page = new TBGoodsInfoPage();
  451. MyBeanUtils.copyBeanNotNull2Bean(entity, page);
  452. Object id0 = entity.getId();
  453. String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? ";
  454. List<TBStockInfoEntity> tBStockInfoEntityList = systemService.findHql(hql0, id0);
  455. page.setTBStockInfoList(tBStockInfoEntityList);
  456. Object id1 = entity.getId();
  457. String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? ";
  458. List<TBPriceInfoEntity> tBPriceInfoEntityList = systemService.findHql(hql1, id1);
  459. page.setTBPriceInfoList(tBPriceInfoEntityList);
  460. pageList.add(page);
  461. } catch (Exception e) {
  462. logger.info(e.getMessage());
  463. }
  464. }
  465. }
  466. map.put(NormalExcelConstants.FILE_NAME, "货品信息");
  467. map.put(NormalExcelConstants.CLASS, TBGoodsInfoPage.class);
  468. map.put(NormalExcelConstants.PARAMS, new ExportParams("货品信息列表", "导出人:Jeecg",
  469. "导出信息"));
  470. map.put(NormalExcelConstants.DATA_LIST, pageList);
  471. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  472. }
  473. /**
  474. * 通过excel导入数据
  475. *
  476. * @param request
  477. * @param
  478. * @return
  479. */
  480. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  481. @ResponseBody
  482. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  483. AjaxJson j = new AjaxJson();
  484. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  485. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  486. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  487. MultipartFile file = entity.getValue();// 获取上传文件对象
  488. ImportParams params = new ImportParams();
  489. params.setTitleRows(2);
  490. params.setHeadRows(2);
  491. params.setNeedSave(true);
  492. try {
  493. List<TBGoodsInfoPage> list = ExcelImportUtil.importExcel(file.getInputStream(), TBGoodsInfoPage.class, params);
  494. TBGoodsInfoEntity entity1 = null;
  495. for (TBGoodsInfoPage page : list) {
  496. entity1 = new TBGoodsInfoEntity();
  497. MyBeanUtils.copyBeanNotNull2Bean(page, entity1);
  498. tBGoodsInfoService.addMain(entity1, page.getTBStockInfoList(), page.getTBPriceInfoList(), page.getTBRelatedUnitPriceInfoList());
  499. }
  500. j.setMsg("文件导入成功!");
  501. } catch (Exception e) {
  502. j.setMsg("文件导入失败!");
  503. logger.error(ExceptionUtil.getExceptionMessage(e));
  504. } finally {
  505. try {
  506. file.getInputStream().close();
  507. } catch (IOException e) {
  508. e.printStackTrace();
  509. }
  510. }
  511. }
  512. return j;
  513. }
  514. /**
  515. * 导出excel 使模板
  516. */
  517. @RequestMapping(params = "exportXlsByT")
  518. public String exportXlsByT(ModelMap map) {
  519. map.put(NormalExcelConstants.FILE_NAME, "货品信息");
  520. map.put(NormalExcelConstants.CLASS, TBGoodsInfoPage.class);
  521. map.put(NormalExcelConstants.PARAMS, new ExportParams("货品信息列表", "导出人:" + ResourceUtil.getSessionUserName().getRealName(),
  522. "导出信息"));
  523. map.put(NormalExcelConstants.DATA_LIST, new ArrayList());
  524. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  525. }
  526. /**
  527. * 导入功能跳转
  528. *
  529. * @return
  530. */
  531. @RequestMapping(params = "upload")
  532. public ModelAndView upload(HttpServletRequest req) {
  533. req.setAttribute("controller_name", "tBGoodsInfoController");
  534. return new ModelAndView("common/upload/pub_excel_upload");
  535. }
  536. @RequestMapping(method = RequestMethod.GET)
  537. @ResponseBody
  538. public List<TBGoodsInfoEntity> list() {
  539. List<TBGoodsInfoEntity> listTBGoodsInfos = tBGoodsInfoService.getList(TBGoodsInfoEntity.class);
  540. return listTBGoodsInfos;
  541. }
  542. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  543. @ResponseBody
  544. public ResponseEntity<?> get(@PathVariable("id") String id) {
  545. TBGoodsInfoEntity task = tBGoodsInfoService.get(TBGoodsInfoEntity.class, id);
  546. if (task == null) {
  547. return new ResponseEntity(HttpStatus.NOT_FOUND);
  548. }
  549. return new ResponseEntity(task, HttpStatus.OK);
  550. }
  551. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  552. @ResponseBody
  553. public ResponseEntity<?> create(@RequestBody TBGoodsInfoPage tBGoodsInfoPage, UriComponentsBuilder uriBuilder) {
  554. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  555. Set<ConstraintViolation<TBGoodsInfoPage>> failures = validator.validate(tBGoodsInfoPage);
  556. if (!failures.isEmpty()) {
  557. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  558. }
  559. //保存
  560. List<TBStockInfoEntity> tBStockInfoList = tBGoodsInfoPage.getTBStockInfoList();
  561. List<TBPriceInfoEntity> tBPriceInfoList = tBGoodsInfoPage.getTBPriceInfoList();
  562. TBGoodsInfoEntity tBGoodsInfo = new TBGoodsInfoEntity();
  563. try {
  564. MyBeanUtils.copyBeanNotNull2Bean(tBGoodsInfo, tBGoodsInfoPage);
  565. } catch (Exception e) {
  566. logger.info(e.getMessage());
  567. }
  568. tBGoodsInfoService.addMain(tBGoodsInfo, tBStockInfoList, tBPriceInfoList, tBGoodsInfoPage.getTBRelatedUnitPriceInfoList());
  569. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  570. String id = tBGoodsInfoPage.getId();
  571. URI uri = uriBuilder.path("/rest/tBGoodsInfoController/" + id).build().toUri();
  572. HttpHeaders headers = new HttpHeaders();
  573. headers.setLocation(uri);
  574. return new ResponseEntity(headers, HttpStatus.CREATED);
  575. }
  576. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  577. public ResponseEntity<?> update(@RequestBody TBGoodsInfoPage tBGoodsInfoPage) {
  578. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  579. Set<ConstraintViolation<TBGoodsInfoPage>> failures = validator.validate(tBGoodsInfoPage);
  580. if (!failures.isEmpty()) {
  581. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  582. }
  583. //保存
  584. List<TBStockInfoEntity> tBStockInfoList = tBGoodsInfoPage.getTBStockInfoList();
  585. List<TBPriceInfoEntity> tBPriceInfoList = tBGoodsInfoPage.getTBPriceInfoList();
  586. TBGoodsInfoEntity tBGoodsInfo = new TBGoodsInfoEntity();
  587. try {
  588. MyBeanUtils.copyBeanNotNull2Bean(tBGoodsInfo, tBGoodsInfoPage);
  589. } catch (Exception e) {
  590. logger.info(e.getMessage());
  591. }
  592. tBGoodsInfoService.updateMain(tBGoodsInfo, tBStockInfoList, tBPriceInfoList, tBGoodsInfoPage.getTBRelatedUnitPriceInfoList());
  593. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  594. return new ResponseEntity(HttpStatus.NO_CONTENT);
  595. }
  596. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  597. @ResponseStatus(HttpStatus.NO_CONTENT)
  598. public void delete(@PathVariable("id") String id) {
  599. TBGoodsInfoEntity tBGoodsInfo = tBGoodsInfoService.get(TBGoodsInfoEntity.class, id);
  600. tBGoodsInfoService.delMain(tBGoodsInfo);
  601. }
  602. /**
  603. * 启用
  604. *
  605. * @author zhijia.wang
  606. */
  607. @RequestMapping(params = "enableGoodInfo")
  608. @ResponseBody
  609. public AjaxJson enableGoodInfo(String id, HttpServletRequest req) {
  610. AjaxJson j = new AjaxJson();
  611. String message = null;
  612. TBGoodsInfoEntity goodInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, id);
  613. try {
  614. goodInfo.setStatus(Globals.Enabled.toString());
  615. tBGoodsInfoService.updateEntitie(goodInfo);
  616. message = "货品信息:" + goodInfo.getGoodsName() + "启用成功!";
  617. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  618. } catch (Exception e) {
  619. message = "操作失败!";
  620. }
  621. j.setMsg(message);
  622. return j;
  623. }
  624. /**
  625. * 停用
  626. *
  627. * @author zhijia.wang
  628. */
  629. @RequestMapping(params = "disableGoodInfo")
  630. @ResponseBody
  631. public AjaxJson disableGoodInfo(String id, HttpServletRequest req) {
  632. AjaxJson j = new AjaxJson();
  633. String message = null;
  634. TBGoodsInfoEntity goodInfo = tBGoodsInfoService.getEntity(TBGoodsInfoEntity.class, id);
  635. try {
  636. goodInfo.setStatus(Globals.Disabled.toString());
  637. tBGoodsInfoService.updateEntitie(goodInfo);
  638. message = "货品信息:" + goodInfo.getGoodsName() + "停用成功!";
  639. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  640. } catch (Exception e) {
  641. message = "操作失败!";
  642. }
  643. j.setMsg(message);
  644. return j;
  645. }
  646. @RequestMapping(params = "selectRelatedUnit")
  647. public ModelAndView selectRelatedUnit(TBGoodsInfoEntity tBGoodsInfo, HttpServletRequest req) {
  648. return new ModelAndView("cn/com/lzt/goodsinfo/selectRelatedUnit");
  649. }
  650. @RequestMapping(params = "selectRelatedUnitDatagrid")
  651. public void selectRelatedUnitDatagrid(TBGoodsInfoEntity goodsInfoEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  652. String hql1 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? ";
  653. List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoEntityList = systemService.findHql(hql1, goodsInfoEntity.getId());
  654. dataGrid.setResults(tBRelatedUnitPriceInfoEntityList);
  655. dataGrid.setTotal(tBRelatedUnitPriceInfoEntityList.size());
  656. TagUtil.datagrid(response, dataGrid);
  657. }
  658. }