GoodsController.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. package com.kmall.admin.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.kmall.admin.dto.GoodsDto;
  4. import com.kmall.admin.dto.GoodsPanoramaDto;
  5. import com.kmall.admin.entity.GoodsEntity;
  6. import com.kmall.admin.entity.GoodsGalleryEntity;
  7. import com.kmall.admin.entity.SysOssEntity;
  8. import com.kmall.admin.service.*;
  9. import com.kmall.admin.utils.ParamUtils;
  10. import com.kmall.admin.utils.ShiroUtils;
  11. import com.kmall.common.constant.Dict;
  12. import com.kmall.common.constant.JxlsXmlTemplateName;
  13. import com.kmall.admin.fromcomm.entity.SysUserEntity;
  14. import com.kmall.common.fileserver.util.FileManager;
  15. import com.kmall.common.utils.*;
  16. import com.kmall.common.utils.excel.ExcelExport;
  17. import com.kmall.common.utils.excel.ExcelUtil;
  18. import org.apache.commons.fileupload.FileItem;
  19. import org.apache.commons.fileupload.FileItemFactory;
  20. import org.apache.commons.fileupload.disk.DiskFileItemFactory;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.apache.shiro.authz.annotation.RequiresPermissions;
  23. import org.apache.tools.zip.ZipEntry;
  24. import org.apache.tools.zip.ZipFile;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import org.springframework.web.multipart.commons.CommonsMultipartFile;
  30. import javax.servlet.http.HttpServletRequest;
  31. import javax.servlet.http.HttpServletResponse;
  32. import java.io.*;
  33. import java.util.*;
  34. import java.util.logging.Logger;
  35. /**
  36. * Controller
  37. *
  38. * @author Scott
  39. * @email
  40. * @date 2017-08-21 21:19:49
  41. */
  42. @RestController
  43. @RequestMapping("goods")
  44. public class GoodsController {
  45. @Autowired
  46. private GoodsService goodsService;
  47. @Autowired
  48. private GoodsGalleryService goodsGalleryService;
  49. @Autowired
  50. private OfflineCartService offlineCartService;
  51. @Autowired
  52. private ExcelUtil excelUtil;
  53. @Autowired
  54. private StoreService storeService;
  55. @Autowired
  56. private SysOssService sysOssService;
  57. /**
  58. * 查看列表
  59. */
  60. @RequestMapping("/list")
  61. @RequiresPermissions("goods:list")
  62. public R list(@RequestParam Map<String, Object> params) {
  63. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  64. // ParamUtils.setName(params, "name");
  65. String lastSaleTime = (String) params.get("lastSaleTime");
  66. if(org.apache.commons.lang.StringUtils.isNotEmpty(lastSaleTime)) {
  67. try {
  68. lastSaleTime = new String(lastSaleTime.getBytes("iso-8859-1"), "utf-8");
  69. } catch (Exception e) {
  70. e.printStackTrace();
  71. }
  72. lastSaleTime = DateUtils.getDate(lastSaleTime);
  73. params.put("lastSaleTime", lastSaleTime + " 00:00:00");
  74. }
  75. //查询列表数据
  76. Query query = new Query(params);
  77. query.put("isDelete", 0);
  78. List<GoodsEntity> goodsList = goodsService.queryList(query);
  79. int total = goodsService.queryTotal(query);
  80. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  81. return R.ok().put("page", pageUtil);
  82. }
  83. /**
  84. * 查看信息
  85. */
  86. @RequestMapping("/info/{id}")
  87. @RequiresPermissions("goods:info")
  88. public R info(@PathVariable("id") Integer id) {
  89. GoodsEntity goods = goodsService.queryObject(id);
  90. if(goods != null) {
  91. GoodsGalleryEntity goodsGalleryEntity =goodsGalleryService.queryVideoObjectByGoodId(goods.getId());
  92. if(goodsGalleryEntity != null){
  93. goods.setVideoUrl(goodsGalleryEntity.getImgUrl());
  94. }
  95. }
  96. return R.ok().put("goods", goods);
  97. }
  98. /**
  99. * 查看信息
  100. */
  101. @RequestMapping("/infoByQuery")
  102. public R infoByQuery(@RequestParam Map<String, Object> params) {
  103. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  104. ParamUtils.setName(params, "name");
  105. //查询列表数据
  106. Query query = new Query(params);
  107. query.put("isDelete", 0);
  108. List<GoodsEntity> goodsList = goodsService.queryList(query);
  109. if(goodsList != null && goodsList.size() != 0) {
  110. return R.ok().put("goods", goodsList.get(0));
  111. }
  112. return R.ok().put("goods", new GoodsEntity());
  113. }
  114. /**
  115. * 保存
  116. */
  117. @RequestMapping("/save")
  118. @RequiresPermissions("goods:save")
  119. public R save(@RequestBody GoodsEntity goods) {
  120. goodsService.save(goods);
  121. return R.ok();
  122. }
  123. /**
  124. * 修改
  125. */
  126. @RequestMapping("/update")
  127. @RequiresPermissions("goods:update")
  128. public R update(@RequestBody GoodsEntity goods) {
  129. goodsService.update(goods);
  130. return R.ok();
  131. }
  132. /**
  133. * 删除
  134. */
  135. @RequestMapping("/delete")
  136. @RequiresPermissions("goods:delete")
  137. public R delete(@RequestBody Integer[] ids) {
  138. goodsService.deleteBatch(ids);
  139. return R.ok();
  140. }
  141. /**
  142. * 查看所有列表
  143. */
  144. @RequestMapping("/queryAll")
  145. public R queryAll(@RequestParam Map<String, Object> params) {
  146. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  147. params.put("isDelete", Integer.parseInt(Dict.isDelete.item_0.getItem()));
  148. params.put("isOnSale", Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  149. List<GoodsEntity> list = goodsService.queryList(params);
  150. return R.ok().put("list", list);
  151. }
  152. /**
  153. * 商品回收站
  154. *
  155. * @param params
  156. * @return
  157. */
  158. @RequestMapping("/historyList")
  159. public R historyList(@RequestParam Map<String, Object> params) {
  160. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  161. //查询列表数据
  162. Query query = new Query(params);
  163. query.put("isDelete", 1);
  164. List<GoodsEntity> goodsList = goodsService.queryList(query);
  165. int total = goodsService.queryTotal(query);
  166. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  167. return R.ok().put("page", pageUtil);
  168. }
  169. /**
  170. * 商品从回收站恢复
  171. */
  172. @RequestMapping("/back")
  173. @RequiresPermissions("goods:back")
  174. public R back(@RequestBody Integer[] ids) {
  175. goodsService.back(ids);
  176. return R.ok();
  177. }
  178. /**
  179. * 总计
  180. */
  181. @RequestMapping("/queryTotal")
  182. public R queryTotal(@RequestParam Map<String, Object> params) {
  183. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  184. params.put("isDelete", 0);
  185. int sum = goodsService.queryTotal(params);
  186. return R.ok().put("goodsSum", sum);
  187. }
  188. /**
  189. * 上架
  190. */
  191. @RequestMapping("/enSale")
  192. public R enSale(@RequestBody Integer id) {
  193. goodsService.enSale(id);
  194. return R.ok();
  195. }
  196. /**
  197. * 上架
  198. */
  199. @RequestMapping("/enSaleBatch")
  200. public R enSaleBatch(@RequestBody Integer[] ids) {
  201. goodsService.enSaleBatch(ids);
  202. return R.ok();
  203. }
  204. /**
  205. * 下架
  206. */
  207. @RequestMapping("/unSale")
  208. public R unSale(@RequestBody Integer id) {
  209. goodsService.unSale(id);
  210. return R.ok();
  211. }
  212. /**
  213. * 下架
  214. */
  215. @RequestMapping("/unSaleBatch")
  216. public R unSaleBatch(@RequestBody Integer[] ids) {
  217. goodsService.unSaleBatch(ids);
  218. return R.ok();
  219. }
  220. /**
  221. * 上传文件
  222. */
  223. @RequestMapping("/upload")
  224. @ResponseBody
  225. public R upload(@RequestParam("file") MultipartFile file) {
  226. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  227. try {
  228. Map<String, Object> beans = new HashMap<String, Object>();
  229. beans.put("GoodsDtoList", goodsDtoList);
  230. if (file.isEmpty()) {
  231. return R.error("文件不能为空!");
  232. }
  233. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  234. } catch (Exception e) {
  235. e.printStackTrace();
  236. return R.error("导入失败!");
  237. }
  238. goodsService.uploadExcel(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
  239. //上传文件
  240. return R.ok();
  241. }
  242. /**
  243. * 上传文件(修改库存版)
  244. */
  245. @RequestMapping("/uploadByCover")
  246. @ResponseBody
  247. public R uploadByCover(@RequestParam("file") MultipartFile file) {
  248. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  249. try {
  250. Map<String, Object> beans = new HashMap<String, Object>();
  251. beans.put("GoodsDtoList", goodsDtoList);
  252. if (file.isEmpty()) {
  253. return R.error("文件不能为空!");
  254. }
  255. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  256. } catch (Exception e) {
  257. e.printStackTrace();
  258. return R.error("导入失败!");
  259. }
  260. goodsService.uploadExcelByCover(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
  261. //上传文件
  262. return R.ok();
  263. }
  264. /**
  265. * 上传文件
  266. */
  267. @RequestMapping("/generalGoodsUpload")
  268. @ResponseBody
  269. public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
  270. List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
  271. try {
  272. Map<String, Object> beans = new HashMap<String, Object>();
  273. beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
  274. if (file.isEmpty()) {
  275. return R.error("文件不能为空!");
  276. }
  277. excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
  278. } catch (Exception e) {
  279. e.printStackTrace();
  280. return R.error("导入失败!");
  281. }
  282. goodsService.uploadExcel(generalGoodsDtoList,Integer.parseInt(Dict.exportDataType.item_2.getItem()));
  283. //上传文件
  284. return R.ok();
  285. }
  286. @RequestMapping("/generalGoodsImgUploadByZip")
  287. @ResponseBody
  288. public R batchAddImgByZip(@RequestParam("file") MultipartFile file) throws IOException {
  289. //上传文件
  290. batchAdd(file,2);
  291. return R.ok();
  292. }
  293. @RequestMapping("/generalGoodsImgUpload")
  294. @ResponseBody
  295. public R batchAddImg(@RequestParam("file") MultipartFile file) throws IOException {
  296. //上传文件
  297. batchAdd(file,1);
  298. return R.ok();
  299. }
  300. private Map<String, Object> batchAdd(MultipartFile file, int type) throws IOException {
  301. /*
  302. *创建临时文件夹
  303. * 解压文件
  304. */
  305. String fileName = file.getOriginalFilename();
  306. String path = "/data/project/img/";
  307. File dir = new File(path);
  308. dir.mkdirs();
  309. String filePath = "/data/project/img2/";
  310. File fileDir = new File(filePath);
  311. fileDir.mkdirs();
  312. File saveFile = new File(fileDir, fileName);//将压缩包解析到指定位置
  313. List<String>list = new ArrayList<>();
  314. try {
  315. file.transferTo(saveFile);
  316. String newFilePath = filePath + fileName;
  317. File zipFile = new File(newFilePath);
  318. unZipFiles(zipFile, path,list,type);//解压文件,获取文件路径
  319. System.out.println(JSON.toJSONString(list));
  320. } catch (Exception e) {
  321. e.printStackTrace();
  322. System.out.println("解压执行失败");
  323. throw e ;
  324. }
  325. //程序结束时,删除临时文件
  326. deleteFiles(filePath);//删除压缩包文件夹
  327. deleteFiles(path);//删除解压文件夹**
  328. Map<String, Object> jsonMap = new HashMap<String, Object>();
  329. jsonMap.put("ret",list);
  330. return jsonMap;
  331. }
  332. public void unZipFiles(File srcFile, String destDirPath, List<String> list, int type) throws RuntimeException {
  333. long start = System.currentTimeMillis();
  334. // 判断源文件是否存在
  335. if (!srcFile.exists()) {
  336. throw new RuntimeException(srcFile.getPath() + "所指文件不存在");
  337. }
  338. // 开始解压
  339. ZipFile zipFile = null;
  340. try {
  341. zipFile = new ZipFile(srcFile);
  342. Enumeration<?> entries = zipFile.getEntries();
  343. while (entries.hasMoreElements()) {
  344. ZipEntry entry = (ZipEntry) entries.nextElement();
  345. System.out.println("解压" + entry.getName());
  346. // 如果是文件夹,就创建个文件夹
  347. if (entry.isDirectory()) {
  348. String dirPath = destDirPath + "/" + entry.getName();
  349. File dir = new File(dirPath);
  350. dir.mkdirs();
  351. } else {
  352. // 如果是文件,就先创建一个文件,然后用io流把内容copy过去
  353. File targetFile = new File(destDirPath + "/" + entry.getName());
  354. // 保证这个文件的父文件夹必须要存在
  355. if(!targetFile.getParentFile().exists()){
  356. }
  357. targetFile.createNewFile();
  358. // 将压缩文件内容写入到这个文件中
  359. InputStream is = zipFile.getInputStream(entry);
  360. FileOutputStream fos = new FileOutputStream(targetFile);
  361. int len;
  362. byte[] buf = new byte[1024];
  363. while ((len = is.read(buf)) != -1) {
  364. fos.write(buf, 0, len);
  365. }
  366. MultipartFile mulFileByPath = getMulFileByPath(destDirPath + "/" + entry.getName());
  367. //上传文件
  368. String url = FileManager.upload(mulFileByPath);
  369. list.add(url);
  370. if(type == 1){
  371. String sku = entry.getName().split("/")[1].split("\\.")[0];
  372. GoodsEntity goodsEntity = goodsService.queryBySku(sku);
  373. goodsEntity.setPrimaryPicUrl(url);
  374. goodsEntity.setListPicUrl(url);
  375. goodsService.updateForImgUrl(goodsEntity);
  376. }else if(type == 2){
  377. String barCode = entry.getName().split("/")[1];
  378. GoodsEntity goodsEntity = goodsService.queryByBarcode(barCode);
  379. goodsEntity.setPrimaryPicUrl(url);
  380. goodsEntity.setListPicUrl(url);
  381. goodsService.updateForImgUrl(goodsEntity);
  382. }
  383. //保存文件信息
  384. SysOssEntity ossEntity = new SysOssEntity();
  385. ossEntity.setUrl(url);
  386. ossEntity.setCreateDate(new Date());
  387. sysOssService.save(ossEntity);
  388. // 关流顺序,先打开的后关闭
  389. fos.close();
  390. is.close();
  391. }
  392. }
  393. long end = System.currentTimeMillis();
  394. System.out.println("解压完成,耗时:" + (end - start) +" ms");
  395. } catch (Exception e) {
  396. throw new RuntimeException("unzip error from ZipUtils", e);
  397. } finally {
  398. if(zipFile != null){
  399. try {
  400. zipFile.close();
  401. } catch (IOException e) {
  402. e.printStackTrace();
  403. }
  404. }
  405. }
  406. }
  407. private static MultipartFile getMulFileByPath(String picPath) {
  408. FileItem fileItem = createFileItem(picPath);
  409. MultipartFile mfile = new CommonsMultipartFile(fileItem);
  410. return mfile;
  411. }
  412. private static FileItem createFileItem(String filePath)
  413. {
  414. FileItemFactory factory = new DiskFileItemFactory(16, null);
  415. String textFieldName = "textField";
  416. int num = filePath.lastIndexOf(".");
  417. String extFile = filePath.substring(num);
  418. FileItem item = factory.createItem(textFieldName, "text/plain", true,
  419. "MyFileName" + extFile);
  420. File newfile = new File(filePath);
  421. int bytesRead = 0;
  422. byte[] buffer = new byte[8192];
  423. try
  424. {
  425. FileInputStream fis = new FileInputStream(newfile);
  426. OutputStream os = item.getOutputStream();
  427. while ((bytesRead = fis.read(buffer, 0, 8192))
  428. != -1)
  429. {
  430. os.write(buffer, 0, bytesRead);
  431. }
  432. os.close();
  433. fis.close();
  434. }
  435. catch (IOException e)
  436. {
  437. e.printStackTrace();
  438. }
  439. return item;
  440. }
  441. public void deleteFiles(String filePath) {
  442. File file = new File(filePath);
  443. if ((!file.exists()) || (!file.isDirectory())) {
  444. System.out.println("file not exist");
  445. return;
  446. }
  447. String[] tempList = file.list();
  448. File temp = null;
  449. for (int i = 0; i < tempList.length; i++) {
  450. if (filePath.endsWith(File.separator)) {
  451. temp = new File(filePath + tempList[i]);
  452. }
  453. else {
  454. temp = new File(filePath + File.separator + tempList[i]);
  455. }
  456. if (temp.isFile()) {
  457. temp.delete();
  458. }
  459. if (temp.isDirectory()) {
  460. this.deleteFiles(filePath + "/" + tempList[i]);
  461. }
  462. }
  463. // 空文件的删除
  464. file.delete();
  465. }
  466. /*@RequestMapping("/scannInfo")
  467. @RequiresPermissions("goods:scannInfo")
  468. public R scannInfo(@RequestParam Map<String, Object> params) {
  469. String goodsSn = (String)params.get("goodsSn");
  470. GoodsEntity goods = goodsService.queryObjectByGoodsSnAndBizType(goodsSn);
  471. if(goods == null) {
  472. return R.error("商品信息不存在");
  473. }
  474. List<OfflineCartEntity> cartEntityList = offlineCartService.offlineGoodsCart(goods);
  475. return R.ok().put("cartEntityList", cartEntityList);
  476. }*/
  477. @RequestMapping("/scannInfo/{prodBarcode}")
  478. @RequiresPermissions("goods:scannInfo")
  479. public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
  480. SysUserEntity user = ShiroUtils.getUserEntity();
  481. if(user == null) {
  482. return R.error("用户登录超时,请重新登录");
  483. }
  484. if (!user.getRoleType().equalsIgnoreCase("2")) {
  485. return R.error("该操作只允许店员账户操作");
  486. }
  487. GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode, user.getStoreId());
  488. if(goods == null) {
  489. return R.error("商品信息不存在");
  490. }
  491. return R.ok().put("goods", goods);
  492. }
  493. @RequestMapping("/details/{prodBarcode}/{storeId}")
  494. // @RequiresPermissions("goods:details") http://127.0.0.1:8080/goods/details/11111
  495. public R details(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId) {
  496. SysUserEntity user = ShiroUtils.getUserEntity();
  497. if(user == null) {
  498. return R.error("用户登录超时,请重新登录");
  499. }
  500. if (!user.getRoleType().equalsIgnoreCase("2")) {
  501. return R.error("该操作只允许店员账户操作");
  502. }
  503. Map<String,Object> map = null;
  504. try {
  505. map = goodsService.calculateGoodsDetail(prodBarcode,storeId);
  506. } catch (Exception e) {
  507. return R.error("系统异常,请联系管理员!e:"+e.getMessage());
  508. }
  509. if(map == null){
  510. return R.error("商品信息不存在");
  511. }
  512. return R.ok().put("goodsDetails", map.get("goods")).put("map",map);
  513. }
  514. /**
  515. * 根据商品编码或者条码查询商品信息(17.商品全景图)
  516. * @param keyword
  517. * @return
  518. */
  519. @GetMapping("/search/{keyword}")
  520. public R searchByKeyword(@PathVariable("keyword") String keyword){
  521. if (keyword == null || "".equals(keyword)){
  522. return R.error("请输入商品编码或者条码!");
  523. }
  524. GoodsPanoramaDto goodsPanoramaDto = goodsService.searchGoodsPanoramaDtoByKeyword(keyword);
  525. //GoodsEntity goods = goodsService.searchGoodsByKeyword(keyword);
  526. if (goodsPanoramaDto == null || "".equals(goodsPanoramaDto)) {
  527. return R.error("没有该商品!");
  528. }
  529. return R.ok().put("goodsPanoramaDto",goodsPanoramaDto);
  530. }
  531. /**
  532. * 所有商品模块导出
  533. * @param params 查询参数
  534. * @param response
  535. * @param request
  536. * @return
  537. */
  538. @RequiresPermissions("goods:export")
  539. @RequestMapping(value = "export")
  540. public R export(@RequestParam Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
  541. ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
  542. params.put("isDelete", 0);
  543. String lastSaleTime = (String) params.get("lastSaleTime");
  544. if(org.apache.commons.lang.StringUtils.isNotEmpty(lastSaleTime)) {
  545. try {
  546. lastSaleTime = new String(lastSaleTime.getBytes("iso-8859-1"), "utf-8");
  547. } catch (Exception e) {
  548. e.printStackTrace();
  549. }
  550. lastSaleTime = DateUtils.getDate(lastSaleTime);
  551. params.put("lastSaleTime", lastSaleTime + " 00:00:00");
  552. }
  553. // 根据条件查询出列表
  554. List<GoodsEntity> goodsList = goodsService.queryExportList(params);
  555. ExcelExport ee = new ExcelExport("所有商品信息");
  556. String[] header = new String[]{"商户名称","第三方商户编号","商品编码","SKU","PLU","商品名称","商品英文名称","产品条码","货品业务类型","库存是否共享",
  557. "商品库存","日常价","成本价","是否上架","是否热销","录入日期","商品单位","商品税率","产品品牌","海关备案编号","计量单位","海关商品编码","国检规格型号",
  558. "原产国","海关申报要素","毛重(kg)","净重(kg)"};
  559. List<Map<String, Object>> list = new ArrayList<>();
  560. if (goodsList !=null && goodsList.size()>0){
  561. for (GoodsEntity goodsEntity : goodsList) {
  562. LinkedHashMap<String, Object> map = new LinkedHashMap<>();
  563. map.put("MerchName",goodsEntity.getMerchName());
  564. map.put("ThirdPartyMerchCode",goodsEntity.getThirdPartyMerchCode());
  565. map.put("GoodsSn",goodsEntity.getGoodsSn());
  566. map.put("Sku",goodsEntity.getSku());
  567. map.put("Plu",goodsEntity.getPlu());
  568. map.put("Name",goodsEntity.getName());
  569. map.put("EnglishName",goodsEntity.getEnglishName());
  570. String goodsBizType = goodsEntity.getGoodsBizType();
  571. Integer isStockShare = 0;
  572. if (goodsEntity.getIsStockShare()!=null){
  573. isStockShare = Integer.parseInt(goodsEntity.getIsStockShare());
  574. }
  575. map.put("ProdBarcode",goodsEntity.getProdBarcode());
  576. map.put("GoodsBizType",StringUtils.isEmpty(goodsBizType)?"":Dict.orderBizType.valueOf("item_"+goodsBizType).getItemName());
  577. map.put("IsStockShare",isStockShare==0?"否":"是");
  578. map.put("GoodsNumber",goodsEntity.getGoodsNumber());
  579. map.put("DailyPrice",goodsEntity.getDailyPrice());
  580. map.put("CostPrice",goodsEntity.getCostPrice());
  581. map.put("IsOnSale",goodsEntity.getIsOnSale()==0?"否":"是");
  582. map.put("IsHot",goodsEntity.getIsHot()==0?"否":"是");
  583. map.put("AddTime",goodsEntity.getAddTime());
  584. map.put("GoodsUnit",goodsEntity.getGoodsUnit());
  585. map.put("GoodsRate",goodsEntity.getGoodsRate());
  586. map.put("Brand",goodsEntity.getBrand());
  587. map.put("CusRecCode",goodsEntity.getCusRecCode());
  588. map.put("UnitCode",goodsEntity.getUnitCode());
  589. map.put("CusGoodsCode",goodsEntity.getCusGoodsCode());
  590. map.put("CiqProdModel",goodsEntity.getCiqProdModel());
  591. map.put("OriCntName",goodsEntity.getOriCntName());
  592. map.put("CusDeclEle",goodsEntity.getCusDeclEle());
  593. map.put("GrossWeight",goodsEntity.getGrossWeight());
  594. map.put("NetWeight",goodsEntity.getNetWeight());
  595. list.add(map);
  596. }
  597. }
  598. ee.addSheetByMap("所有商品信息", list, header);
  599. ee.export(response);
  600. return R.ok();
  601. }
  602. }