GoodsController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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. @RequestMapping("/queryGoodsName")
  99. public R queryGoodsName(@RequestParam String storeId, @RequestParam String goodsName) {
  100. List<GoodsEntity> goodsList = goodsService.queryByName(storeId, goodsName);
  101. return R.ok().put("goodsList", goodsList);
  102. }
  103. /**
  104. * 查看信息
  105. */
  106. @RequestMapping("/infoByQuery")
  107. public R infoByQuery(@RequestParam Map<String, Object> params) {
  108. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  109. ParamUtils.setName(params, "name");
  110. //查询列表数据
  111. Query query = new Query(params);
  112. query.put("isDelete", 0);
  113. List<GoodsEntity> goodsList = goodsService.queryList(query);
  114. if(goodsList != null && goodsList.size() != 0) {
  115. return R.ok().put("goods", goodsList.get(0));
  116. }
  117. return R.ok().put("goods", new GoodsEntity());
  118. }
  119. /**
  120. * 保存
  121. */
  122. @RequestMapping("/save")
  123. @RequiresPermissions("goods:save")
  124. public R save(@RequestBody GoodsEntity goods) {
  125. goodsService.save(goods);
  126. return R.ok();
  127. }
  128. /**
  129. * 修改
  130. */
  131. @RequestMapping("/update")
  132. @RequiresPermissions("goods:update")
  133. public R update(@RequestBody GoodsEntity goods) {
  134. goodsService.update(goods);
  135. return R.ok();
  136. }
  137. /**
  138. * 删除
  139. */
  140. @RequestMapping("/delete")
  141. @RequiresPermissions("goods:delete")
  142. public R delete(@RequestBody Integer[] ids) {
  143. goodsService.deleteBatch(ids);
  144. return R.ok();
  145. }
  146. /**
  147. * 查看所有列表
  148. */
  149. @RequestMapping("/queryAll")
  150. public R queryAll(@RequestParam Map<String, Object> params) {
  151. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  152. params.put("isDelete", Integer.parseInt(Dict.isDelete.item_0.getItem()));
  153. params.put("isOnSale", Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  154. List<GoodsEntity> list = goodsService.queryList(params);
  155. return R.ok().put("list", list);
  156. }
  157. /**
  158. * 商品回收站
  159. *
  160. * @param params
  161. * @return
  162. */
  163. @RequestMapping("/historyList")
  164. public R historyList(@RequestParam Map<String, Object> params) {
  165. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  166. //查询列表数据
  167. Query query = new Query(params);
  168. query.put("isDelete", 1);
  169. List<GoodsEntity> goodsList = goodsService.queryList(query);
  170. int total = goodsService.queryTotal(query);
  171. PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
  172. return R.ok().put("page", pageUtil);
  173. }
  174. /**
  175. * 商品从回收站恢复
  176. */
  177. @RequestMapping("/back")
  178. @RequiresPermissions("goods:back")
  179. public R back(@RequestBody Integer[] ids) {
  180. goodsService.back(ids);
  181. return R.ok();
  182. }
  183. /**
  184. * 总计
  185. */
  186. @RequestMapping("/queryTotal")
  187. public R queryTotal(@RequestParam Map<String, Object> params) {
  188. ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
  189. params.put("isDelete", 0);
  190. int sum = goodsService.queryTotal(params);
  191. return R.ok().put("goodsSum", sum);
  192. }
  193. /**
  194. * 上架
  195. */
  196. @RequestMapping("/enSale")
  197. public R enSale(@RequestBody Integer id) {
  198. goodsService.enSale(id);
  199. return R.ok();
  200. }
  201. /**
  202. * 上架
  203. */
  204. @RequestMapping("/enSaleBatch")
  205. public R enSaleBatch(@RequestBody Integer[] ids) {
  206. goodsService.enSaleBatch(ids);
  207. return R.ok();
  208. }
  209. /**
  210. * 下架
  211. */
  212. @RequestMapping("/unSale")
  213. public R unSale(@RequestBody Integer id) {
  214. goodsService.unSale(id);
  215. return R.ok();
  216. }
  217. /**
  218. * 下架
  219. */
  220. @RequestMapping("/unSaleBatch")
  221. public R unSaleBatch(@RequestBody Integer[] ids) {
  222. goodsService.unSaleBatch(ids);
  223. return R.ok();
  224. }
  225. /**
  226. * 上传文件
  227. */
  228. @RequestMapping("/upload")
  229. @ResponseBody
  230. public R upload(@RequestParam("file") MultipartFile file) {
  231. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  232. try {
  233. Map<String, Object> beans = new HashMap<String, Object>();
  234. beans.put("GoodsDtoList", goodsDtoList);
  235. if (file.isEmpty()) {
  236. return R.error("文件不能为空!");
  237. }
  238. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  239. } catch (Exception e) {
  240. e.printStackTrace();
  241. return R.error("导入失败!");
  242. }
  243. goodsService.uploadExcel(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
  244. //上传文件
  245. return R.ok();
  246. }
  247. /**
  248. * 上传文件(修改库存版)
  249. */
  250. @RequestMapping("/uploadByCover")
  251. @ResponseBody
  252. public R uploadByCover(@RequestParam("file") MultipartFile file) {
  253. List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
  254. try {
  255. Map<String, Object> beans = new HashMap<String, Object>();
  256. beans.put("GoodsDtoList", goodsDtoList);
  257. if (file.isEmpty()) {
  258. return R.error("文件不能为空!");
  259. }
  260. excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
  261. } catch (Exception e) {
  262. e.printStackTrace();
  263. return R.error("导入失败!");
  264. }
  265. goodsService.uploadExcelByCover(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
  266. //上传文件
  267. return R.ok();
  268. }
  269. /**
  270. * 上传文件
  271. */
  272. @RequestMapping("/generalGoodsUpload")
  273. @ResponseBody
  274. public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
  275. List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
  276. try {
  277. Map<String, Object> beans = new HashMap<String, Object>();
  278. beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
  279. if (file.isEmpty()) {
  280. return R.error("文件不能为空!");
  281. }
  282. excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
  283. } catch (Exception e) {
  284. e.printStackTrace();
  285. return R.error("导入失败!");
  286. }
  287. goodsService.uploadExcel(generalGoodsDtoList,Integer.parseInt(Dict.exportDataType.item_2.getItem()));
  288. //上传文件
  289. return R.ok();
  290. }
  291. @RequestMapping("/generalGoodsImgUploadByZip")
  292. @ResponseBody
  293. public R batchAddImgByZip(@RequestParam("file") MultipartFile file) throws IOException {
  294. //上传文件
  295. batchAdd(file,2);
  296. return R.ok();
  297. }
  298. @RequestMapping("/generalGoodsImgUpload")
  299. @ResponseBody
  300. public R batchAddImg(@RequestParam("file") MultipartFile file) throws IOException {
  301. //上传文件
  302. batchAdd(file,1);
  303. return R.ok();
  304. }
  305. private Map<String, Object> batchAdd(MultipartFile file, int type) throws IOException {
  306. /*
  307. *创建临时文件夹
  308. * 解压文件
  309. */
  310. String fileName = file.getOriginalFilename();
  311. String path = "/data/project/img/";
  312. File dir = new File(path);
  313. dir.mkdirs();
  314. String filePath = "/data/project/img2/";
  315. File fileDir = new File(filePath);
  316. fileDir.mkdirs();
  317. File saveFile = new File(fileDir, fileName);//将压缩包解析到指定位置
  318. List<String>list = new ArrayList<>();
  319. try {
  320. file.transferTo(saveFile);
  321. String newFilePath = filePath + fileName;
  322. File zipFile = new File(newFilePath);
  323. unZipFiles(zipFile, path,list,type);//解压文件,获取文件路径
  324. System.out.println(JSON.toJSONString(list));
  325. } catch (Exception e) {
  326. e.printStackTrace();
  327. System.out.println("解压执行失败");
  328. throw e ;
  329. }
  330. //程序结束时,删除临时文件
  331. deleteFiles(filePath);//删除压缩包文件夹
  332. deleteFiles(path);//删除解压文件夹**
  333. Map<String, Object> jsonMap = new HashMap<String, Object>();
  334. jsonMap.put("ret",list);
  335. return jsonMap;
  336. }
  337. public void unZipFiles(File srcFile, String destDirPath, List<String> list, int type) throws RuntimeException {
  338. long start = System.currentTimeMillis();
  339. // 判断源文件是否存在
  340. if (!srcFile.exists()) {
  341. throw new RuntimeException(srcFile.getPath() + "所指文件不存在");
  342. }
  343. // 开始解压
  344. ZipFile zipFile = null;
  345. try {
  346. zipFile = new ZipFile(srcFile);
  347. Enumeration<?> entries = zipFile.getEntries();
  348. while (entries.hasMoreElements()) {
  349. ZipEntry entry = (ZipEntry) entries.nextElement();
  350. System.out.println("解压" + entry.getName());
  351. // 如果是文件夹,就创建个文件夹
  352. if (entry.isDirectory()) {
  353. String dirPath = destDirPath + "/" + entry.getName();
  354. File dir = new File(dirPath);
  355. dir.mkdirs();
  356. } else {
  357. // 如果是文件,就先创建一个文件,然后用io流把内容copy过去
  358. File targetFile = new File(destDirPath + "/" + entry.getName());
  359. // 保证这个文件的父文件夹必须要存在
  360. if(!targetFile.getParentFile().exists()){
  361. }
  362. targetFile.createNewFile();
  363. // 将压缩文件内容写入到这个文件中
  364. InputStream is = zipFile.getInputStream(entry);
  365. FileOutputStream fos = new FileOutputStream(targetFile);
  366. int len;
  367. byte[] buf = new byte[1024];
  368. while ((len = is.read(buf)) != -1) {
  369. fos.write(buf, 0, len);
  370. }
  371. MultipartFile mulFileByPath = getMulFileByPath(destDirPath + "/" + entry.getName());
  372. //上传文件
  373. String url = FileManager.upload(mulFileByPath);
  374. list.add(url);
  375. if(type == 1){
  376. String sku = entry.getName().split("/")[1].split("\\.")[0];
  377. GoodsEntity goodsEntity = goodsService.queryBySku(sku);
  378. goodsEntity.setPrimaryPicUrl(url);
  379. goodsEntity.setListPicUrl(url);
  380. goodsService.updateForImgUrl(goodsEntity);
  381. }else if(type == 2){
  382. String barCode = entry.getName().split("/")[1];
  383. GoodsEntity goodsEntity = goodsService.queryByBarcode(barCode);
  384. goodsEntity.setPrimaryPicUrl(url);
  385. goodsEntity.setListPicUrl(url);
  386. goodsService.updateForImgUrl(goodsEntity);
  387. }
  388. //保存文件信息
  389. SysOssEntity ossEntity = new SysOssEntity();
  390. ossEntity.setUrl(url);
  391. ossEntity.setCreateDate(new Date());
  392. sysOssService.save(ossEntity);
  393. // 关流顺序,先打开的后关闭
  394. fos.close();
  395. is.close();
  396. }
  397. }
  398. long end = System.currentTimeMillis();
  399. System.out.println("解压完成,耗时:" + (end - start) +" ms");
  400. } catch (Exception e) {
  401. throw new RuntimeException("unzip error from ZipUtils", e);
  402. } finally {
  403. if(zipFile != null){
  404. try {
  405. zipFile.close();
  406. } catch (IOException e) {
  407. e.printStackTrace();
  408. }
  409. }
  410. }
  411. }
  412. private static MultipartFile getMulFileByPath(String picPath) {
  413. FileItem fileItem = createFileItem(picPath);
  414. MultipartFile mfile = new CommonsMultipartFile(fileItem);
  415. return mfile;
  416. }
  417. private static FileItem createFileItem(String filePath)
  418. {
  419. FileItemFactory factory = new DiskFileItemFactory(16, null);
  420. String textFieldName = "textField";
  421. int num = filePath.lastIndexOf(".");
  422. String extFile = filePath.substring(num);
  423. FileItem item = factory.createItem(textFieldName, "text/plain", true,
  424. "MyFileName" + extFile);
  425. File newfile = new File(filePath);
  426. int bytesRead = 0;
  427. byte[] buffer = new byte[8192];
  428. try
  429. {
  430. FileInputStream fis = new FileInputStream(newfile);
  431. OutputStream os = item.getOutputStream();
  432. while ((bytesRead = fis.read(buffer, 0, 8192))
  433. != -1)
  434. {
  435. os.write(buffer, 0, bytesRead);
  436. }
  437. os.close();
  438. fis.close();
  439. }
  440. catch (IOException e)
  441. {
  442. e.printStackTrace();
  443. }
  444. return item;
  445. }
  446. public void deleteFiles(String filePath) {
  447. File file = new File(filePath);
  448. if ((!file.exists()) || (!file.isDirectory())) {
  449. System.out.println("file not exist");
  450. return;
  451. }
  452. String[] tempList = file.list();
  453. File temp = null;
  454. for (int i = 0; i < tempList.length; i++) {
  455. if (filePath.endsWith(File.separator)) {
  456. temp = new File(filePath + tempList[i]);
  457. }
  458. else {
  459. temp = new File(filePath + File.separator + tempList[i]);
  460. }
  461. if (temp.isFile()) {
  462. temp.delete();
  463. }
  464. if (temp.isDirectory()) {
  465. this.deleteFiles(filePath + "/" + tempList[i]);
  466. }
  467. }
  468. // 空文件的删除
  469. file.delete();
  470. }
  471. /*@RequestMapping("/scannInfo")
  472. @RequiresPermissions("goods:scannInfo")
  473. public R scannInfo(@RequestParam Map<String, Object> params) {
  474. String goodsSn = (String)params.get("goodsSn");
  475. GoodsEntity goods = goodsService.queryObjectByGoodsSnAndBizType(goodsSn);
  476. if(goods == null) {
  477. return R.error("商品信息不存在");
  478. }
  479. List<OfflineCartEntity> cartEntityList = offlineCartService.offlineGoodsCart(goods);
  480. return R.ok().put("cartEntityList", cartEntityList);
  481. }*/
  482. @RequestMapping("/scannInfo/{prodBarcode}")
  483. @RequiresPermissions("goods:scannInfo")
  484. public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
  485. SysUserEntity user = ShiroUtils.getUserEntity();
  486. if(user == null) {
  487. return R.error("用户登录超时,请重新登录");
  488. }
  489. if (!user.getRoleType().equalsIgnoreCase("2")) {
  490. return R.error("该操作只允许店员账户操作");
  491. }
  492. GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode, user.getStoreId());
  493. if(goods == null) {
  494. return R.error("商品信息不存在");
  495. }
  496. return R.ok().put("goods", goods);
  497. }
  498. @RequestMapping("/details/{prodBarcode}/{storeId}/{sku}")
  499. // @RequiresPermissions("goods:details") http://127.0.0.1:8080/goods/details/11111
  500. public R details(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId,@PathVariable("sku")String sku) {
  501. SysUserEntity user = ShiroUtils.getUserEntity();
  502. if(user == null) {
  503. return R.error("用户登录超时,请重新登录");
  504. }
  505. if (!user.getRoleType().equalsIgnoreCase("2")) {
  506. return R.error("该操作只允许店员账户操作");
  507. }
  508. Map<String,Object> map = null;
  509. try {
  510. map = goodsService.calculateGoodsDetail(prodBarcode,storeId,sku);
  511. } catch (Exception e) {
  512. return R.error("系统异常,请联系管理员!e:"+e.getMessage());
  513. }
  514. if(map == null){
  515. return R.error("商品信息不存在");
  516. }
  517. return R.ok().put("goodsDetails", map.get("goods")).put("map",map);
  518. }
  519. @RequestMapping("/detailsOld/{prodBarcode}/{storeId}")
  520. // @RequiresPermissions("goods:details") http://127.0.0.1:8080/goods/details/11111
  521. public R details(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId) {
  522. SysUserEntity user = ShiroUtils.getUserEntity();
  523. if(user == null) {
  524. return R.error("用户登录超时,请重新登录");
  525. }
  526. if (!user.getRoleType().equalsIgnoreCase("2")) {
  527. return R.error("该操作只允许店员账户操作");
  528. }
  529. Map<String,Object> map = null;
  530. try {
  531. map = goodsService.calculateGoodsDetail(prodBarcode,storeId,null);
  532. } catch (Exception e) {
  533. return R.error("系统异常,请联系管理员!e:"+e.getMessage());
  534. }
  535. if(map == null){
  536. return R.error("商品信息不存在");
  537. }
  538. return R.ok().put("goodsDetails", map.get("goods")).put("map",map);
  539. }
  540. /**
  541. * 多sku可选
  542. * @param prodBarcode
  543. * @param storeId
  544. * @return
  545. */
  546. @RequestMapping("/selectSkuDetails/{prodBarcode}/{storeId}")
  547. public R selectSkuDetails(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId) {
  548. SysUserEntity user = ShiroUtils.getUserEntity();
  549. if(user == null) {
  550. return R.error("用户登录超时,请重新登录");
  551. }
  552. if (!user.getRoleType().equalsIgnoreCase("2")) {
  553. return R.error("该操作只允许店员账户操作");
  554. }
  555. List<Map<String,Object>> mapList = null;
  556. try {
  557. mapList = goodsService.selectSkuDetails(prodBarcode,storeId);
  558. } catch (Exception e) {
  559. return R.error("系统异常,请联系管理员!e:"+e.getMessage());
  560. }
  561. if(mapList == null){
  562. return R.error("商品信息不存在");
  563. }
  564. List<Object> objectList = new ArrayList<>();
  565. for(Map<String,Object> map : mapList){
  566. objectList.add(map.get("goods"));
  567. }
  568. return R.ok().put("goodsDetails", objectList).put("map",objectList);
  569. }
  570. /**
  571. * 根据商品编码或者条码查询商品信息(17.商品全景图)
  572. * @param keyword
  573. * @return
  574. */
  575. @GetMapping("/search/{keyword}")
  576. public R searchByKeyword(@PathVariable("keyword") String keyword){
  577. if (keyword == null || "".equals(keyword)){
  578. return R.error("请输入商品编码或者条码!");
  579. }
  580. GoodsPanoramaDto goodsPanoramaDto = goodsService.searchGoodsPanoramaDtoByKeyword(keyword);
  581. //GoodsEntity goods = goodsService.searchGoodsByKeyword(keyword);
  582. if (goodsPanoramaDto == null || "".equals(goodsPanoramaDto)) {
  583. return R.error("没有该商品!");
  584. }
  585. return R.ok().put("goodsPanoramaDto",goodsPanoramaDto);
  586. }
  587. /**
  588. * 所有商品模块导出
  589. * @param params 查询参数
  590. * @param response
  591. * @param request
  592. * @return
  593. */
  594. @RequiresPermissions("goods:export")
  595. @RequestMapping(value = "export")
  596. public R export(@RequestParam Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
  597. ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
  598. params.put("isDelete", 0);
  599. String lastSaleTime = (String) params.get("lastSaleTime");
  600. if(org.apache.commons.lang.StringUtils.isNotEmpty(lastSaleTime)) {
  601. try {
  602. lastSaleTime = new String(lastSaleTime.getBytes("iso-8859-1"), "utf-8");
  603. } catch (Exception e) {
  604. e.printStackTrace();
  605. }
  606. lastSaleTime = DateUtils.getDate(lastSaleTime);
  607. params.put("lastSaleTime", lastSaleTime + " 00:00:00");
  608. }
  609. // 根据条件查询出列表
  610. List<GoodsEntity> goodsList = goodsService.queryExportList(params);
  611. ExcelExport ee = new ExcelExport("所有商品信息");
  612. String[] header = new String[]{"商户名称","第三方商户编号","商品编码","SKU","PLU","商品名称","商品英文名称","产品条码","货品业务类型","库存是否共享",
  613. "商品库存","日常价","成本价","是否上架","是否热销","录入日期","商品单位","商品税率","产品品牌","海关备案编号","计量单位","海关商品编码","国检规格型号",
  614. "原产国","海关申报要素","毛重(kg)","净重(kg)"};
  615. List<Map<String, Object>> list = new ArrayList<>();
  616. if (goodsList !=null && goodsList.size()>0){
  617. for (GoodsEntity goodsEntity : goodsList) {
  618. LinkedHashMap<String, Object> map = new LinkedHashMap<>();
  619. map.put("MerchName",goodsEntity.getMerchName());
  620. map.put("ThirdPartyMerchCode",goodsEntity.getThirdPartyMerchCode());
  621. map.put("GoodsSn",goodsEntity.getGoodsSn());
  622. map.put("Sku",goodsEntity.getSku());
  623. map.put("Plu",goodsEntity.getPlu());
  624. map.put("Name",goodsEntity.getName());
  625. map.put("EnglishName",goodsEntity.getEnglishName());
  626. String goodsBizType = goodsEntity.getGoodsBizType();
  627. Integer isStockShare = 0;
  628. if (goodsEntity.getIsStockShare()!=null){
  629. isStockShare = Integer.parseInt(goodsEntity.getIsStockShare());
  630. }
  631. map.put("ProdBarcode",goodsEntity.getProdBarcode());
  632. map.put("GoodsBizType",StringUtils.isEmpty(goodsBizType)?"":Dict.orderBizType.valueOf("item_"+goodsBizType).getItemName());
  633. map.put("IsStockShare",isStockShare==0?"否":"是");
  634. map.put("GoodsNumber",goodsEntity.getGoodsNumber());
  635. map.put("DailyPrice",goodsEntity.getDailyPrice());
  636. map.put("CostPrice",goodsEntity.getCostPrice());
  637. map.put("IsOnSale",goodsEntity.getIsOnSale()==0?"否":"是");
  638. map.put("IsHot",goodsEntity.getIsHot()==0?"否":"是");
  639. map.put("AddTime",goodsEntity.getAddTime());
  640. map.put("GoodsUnit",goodsEntity.getGoodsUnit());
  641. map.put("GoodsRate",goodsEntity.getGoodsRate());
  642. map.put("Brand",goodsEntity.getBrand());
  643. map.put("CusRecCode",goodsEntity.getCusRecCode());
  644. map.put("UnitCode",goodsEntity.getUnitCode());
  645. map.put("CusGoodsCode",goodsEntity.getCusGoodsCode());
  646. map.put("CiqProdModel",goodsEntity.getCiqProdModel());
  647. map.put("OriCntName",goodsEntity.getOriCntName());
  648. map.put("CusDeclEle",goodsEntity.getCusDeclEle());
  649. map.put("GrossWeight",goodsEntity.getGrossWeight());
  650. map.put("NetWeight",goodsEntity.getNetWeight());
  651. list.add(map);
  652. }
  653. }
  654. ee.addSheetByMap("所有商品信息", list, header);
  655. ee.export(response);
  656. return R.ok();
  657. }
  658. /**
  659. * 选择同步海关编号和商品税率
  660. * @return
  661. */
  662. @PostMapping("/syncGoodsRate")
  663. public R syncGoodsRate(@RequestBody Integer[] ids){
  664. // 先同步海关商品编码,再同步税率
  665. try {
  666. goodsService.syncOmsHsCodeGoode(Arrays.asList(ids));
  667. }catch (Exception e){
  668. e.printStackTrace();
  669. return R.error("同步海关商品编码失败,请联系管理员");
  670. }
  671. try {
  672. goodsService.syncGoodsRateGoode(Arrays.asList(ids));
  673. }catch (Exception e){
  674. e.printStackTrace();
  675. return R.error("同步商品税率失败,请联系管理员");
  676. }
  677. return R.ok();
  678. }
  679. /**
  680. * 全量同步海关编号和商品税率
  681. * @return
  682. */
  683. @PostMapping("/syncGoodsRateAll")
  684. public R syncGoodsRateAll(){
  685. // 先同步海关商品编码,再同步税率
  686. try {
  687. goodsService.syncOmsHsCodeTask();
  688. }catch (Exception e){
  689. e.printStackTrace();
  690. return R.error("同步海关商品编码失败,请联系管理员");
  691. }
  692. try {
  693. goodsService.syncGoodsRateTask();
  694. }catch (Exception e){
  695. e.printStackTrace();
  696. return R.error("同步商品税率失败,请联系管理员");
  697. }
  698. return R.ok();
  699. }
  700. /**
  701. * 校验系统中的商品价格是否有问题
  702. * @return
  703. */
  704. @RequestMapping("/checkGoodsPrice")
  705. public R checkGoodsPrice(){
  706. SysUserEntity user = ShiroUtils.getUserEntity();
  707. // 先同步海关商品编码,再同步税率
  708. try {
  709. goodsService.checkGoodsPrice(user);
  710. }catch (Exception e){
  711. e.printStackTrace();
  712. return R.error("校验失败,请联系管理员");
  713. }
  714. return R.ok("校验成功");
  715. }
  716. }