123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911 |
- package com.kmall.admin.controller;
- import com.alibaba.fastjson.JSON;
- import com.kmall.admin.dto.GoodsDto;
- import com.kmall.admin.dto.GoodsPanoramaDto;
- import com.kmall.admin.entity.GoodsEntity;
- import com.kmall.admin.entity.GoodsGalleryEntity;
- import com.kmall.admin.entity.SysOssEntity;
- import com.kmall.admin.haikong.constant.Constants;
- import com.kmall.admin.service.*;
- import com.kmall.admin.utils.ParamUtils;
- import com.kmall.admin.utils.ShiroUtils;
- import com.kmall.common.constant.Dict;
- import com.kmall.common.constant.JxlsXmlTemplateName;
- import com.kmall.admin.fromcomm.entity.SysUserEntity;
- import com.kmall.common.fileserver.util.FileManager;
- import com.kmall.common.utils.*;
- import com.kmall.common.utils.excel.ExcelExport;
- import com.kmall.common.utils.excel.ExcelUtil;
- import com.kmall.manager.manager.express.sf.ServiceException;
- import com.kmall.manager.manager.redis.JedisUtil;
- import org.apache.commons.fileupload.FileItem;
- import org.apache.commons.fileupload.FileItemFactory;
- import org.apache.commons.fileupload.disk.DiskFileItemFactory;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.apache.tools.zip.ZipEntry;
- import org.apache.tools.zip.ZipFile;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.commons.CommonsMultipartFile;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.sql.rowset.serial.SerialException;
- import java.io.*;
- import java.util.*;
- /**
- * Controller
- *
- * @author Scott
- * @email
- * @date 2017-08-21 21:19:49
- */
- @RestController
- @RequestMapping("goods")
- public class GoodsController {
- private final static Logger log = LoggerFactory.getLogger(GoodsController.class);
- @Autowired
- private GoodsService goodsService;
- @Autowired
- private GoodsGalleryService goodsGalleryService;
- @Autowired
- private OfflineCartService offlineCartService;
- @Autowired
- private ExcelUtil excelUtil;
- @Autowired
- private StoreService storeService;
- @Autowired
- private SysOssService sysOssService;
- /**
- * 查看列表
- */
- @RequestMapping("/list")
- @RequiresPermissions("goods:list")
- public R list(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- String lastSaleTime = (String) params.get("lastSaleTime");
- if(org.apache.commons.lang.StringUtils.isNotEmpty(lastSaleTime)) {
- try {
- lastSaleTime = new String(lastSaleTime.getBytes("iso-8859-1"), "utf-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- lastSaleTime = DateUtils.getDate(lastSaleTime);
- params.put("lastSaleTime", lastSaleTime + " 00:00:00");
- }
- //查询列表数据
- Query query = new Query(params);
- query.put("isDelete", 0);
- List<GoodsEntity> goodsList = goodsService.queryList(query);
- int total = goodsService.queryTotal(query);
- PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
- return R.ok().put("page", pageUtil);
- }
- /**
- * 查看信息
- */
- @RequestMapping("/info/{id}")
- @RequiresPermissions("goods:info")
- public R info(@PathVariable("id") Integer id) {
- GoodsEntity goods = goodsService.queryObject(id);
- if(goods != null) {
- GoodsGalleryEntity goodsGalleryEntity =goodsGalleryService.queryVideoObjectByGoodId(goods.getId());
- if(goodsGalleryEntity != null){
- goods.setVideoUrl(goodsGalleryEntity.getImgUrl());
- }
- }
- return R.ok().put("goods", goods);
- }
- @RequestMapping("/queryGoodsName")
- public R queryGoodsName(@RequestParam String storeId, @RequestParam String goodsName) {
- List<GoodsEntity> goodsList = goodsService.queryByName(storeId, goodsName);
- return R.ok().put("goodsList", goodsList);
- }
- /**
- * 查看信息
- */
- @RequestMapping("/infoByQuery")
- public R infoByQuery(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- ParamUtils.setName(params, "name");
- //查询列表数据
- Query query = new Query(params);
- query.put("isDelete", 0);
- List<GoodsEntity> goodsList = goodsService.queryList(query);
- if(goodsList != null && goodsList.size() != 0) {
- return R.ok().put("goods", goodsList.get(0));
- }
- return R.ok().put("goods", new GoodsEntity());
- }
- /**
- * 保存
- */
- @RequestMapping("/save")
- @RequiresPermissions("goods:save")
- public R save(@RequestBody GoodsEntity goods) {
- goodsService.save(goods);
- return R.ok();
- }
- /**
- * 修改
- */
- @RequestMapping("/update")
- @RequiresPermissions("goods:update")
- public R update(@RequestBody GoodsEntity goods) {
- goodsService.update(goods);
- return R.ok();
- }
- /**
- * 删除
- */
- @RequestMapping("/delete")
- @RequiresPermissions("goods:delete")
- public R delete(@RequestBody Integer[] ids) {
- goodsService.deleteBatch(ids);
- return R.ok();
- }
- /**
- * 查看所有列表
- */
- @RequestMapping("/queryAll")
- public R queryAll(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- params.put("isDelete", Integer.parseInt(Dict.isDelete.item_0.getItem()));
- params.put("isOnSale", Integer.parseInt(Dict.isOnSale.item_1.getItem()));
- List<GoodsEntity> list = goodsService.queryList(params);
- return R.ok().put("list", list);
- }
- /**
- * 商品回收站
- *
- * @param params
- * @return
- */
- @RequestMapping("/historyList")
- public R historyList(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- //查询列表数据
- Query query = new Query(params);
- query.put("isDelete", 1);
- List<GoodsEntity> goodsList = goodsService.queryList(query);
- int total = goodsService.queryTotal(query);
- PageUtils pageUtil = new PageUtils(goodsList, total, query.getLimit(), query.getPage());
- return R.ok().put("page", pageUtil);
- }
- /**
- * 商品从回收站恢复
- */
- @RequestMapping("/back")
- @RequiresPermissions("goods:back")
- public R back(@RequestBody Integer[] ids) {
- goodsService.back(ids);
- return R.ok();
- }
- /**
- * 总计
- */
- @RequestMapping("/queryTotal")
- public R queryTotal(@RequestParam Map<String, Object> params) {
- ParamUtils.setQueryPowerByRoleType(params, "storeKey", "merchSn", "thirdPartyMerchCode");
- params.put("isDelete", 0);
- int sum = goodsService.queryTotal(params);
- return R.ok().put("goodsSum", sum);
- }
- /**
- * 上架
- */
- @RequestMapping("/enSale")
- public R enSale(@RequestBody Integer id) {
- goodsService.enSale(id);
- return R.ok();
- }
- /**
- * 上架
- */
- @RequestMapping("/enSaleBatch")
- public R enSaleBatch(@RequestBody Integer[] ids) {
- goodsService.enSaleBatch(ids);
- return R.ok();
- }
- /**
- * 下架
- */
- @RequestMapping("/unSale")
- public R unSale(@RequestBody Integer id) {
- goodsService.unSale(id);
- return R.ok();
- }
- /**
- * 下架
- */
- @RequestMapping("/unSaleBatch")
- public R unSaleBatch(@RequestBody Integer[] ids) {
- goodsService.unSaleBatch(ids);
- return R.ok();
- }
- /**
- * 上传文件
- */
- @RequestMapping("/upload")
- @ResponseBody
- public R upload(@RequestParam("file") MultipartFile file) {
- List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
- try {
- Map<String, Object> beans = new HashMap<String, Object>();
- beans.put("GoodsDtoList", goodsDtoList);
- if (file.isEmpty()) {
- return R.error("文件不能为空!");
- }
- excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
- } catch (Exception e) {
- e.printStackTrace();
- return R.error("导入失败!");
- }
- goodsService.uploadExcel(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
- //上传文件
- return R.ok();
- }
- /**
- * 上传文件(修改库存版)
- */
- @RequestMapping("/uploadByCover")
- @ResponseBody
- public R uploadByCover(@RequestParam("file") MultipartFile file) {
- List<GoodsDto> goodsDtoList = new ArrayList<>();//商品信息
- try {
- Map<String, Object> beans = new HashMap<String, Object>();
- beans.put("GoodsDtoList", goodsDtoList);
- if (file.isEmpty()) {
- return R.error("文件不能为空!");
- }
- excelUtil.readExcel(JxlsXmlTemplateName.GOODS_DTO_LIST, beans, file.getInputStream());
- } catch (Exception e) {
- e.printStackTrace();
- return R.error("导入失败!");
- }
- goodsService.uploadExcelByCover(goodsDtoList,Integer.parseInt(Dict.exportDataType.item_1.getItem()));
- //上传文件
- return R.ok();
- }
- /**
- * 上传文件
- */
- @RequestMapping("/generalGoodsUpload")
- @ResponseBody
- public R generalGoodsUpload(@RequestParam("file") MultipartFile file) {
- List<GoodsDto> generalGoodsDtoList = new ArrayList<>();//商品信息
- try {
- Map<String, Object> beans = new HashMap<String, Object>();
- beans.put("GeneralGoodsDtoList", generalGoodsDtoList);
- if (file.isEmpty()) {
- return R.error("文件不能为空!");
- }
- excelUtil.readExcel(JxlsXmlTemplateName.GENERAL_GOODS_DTO_LIST, beans, file.getInputStream());
- } catch (Exception e) {
- e.printStackTrace();
- return R.error("导入失败!");
- }
- goodsService.uploadExcel(generalGoodsDtoList,Integer.parseInt(Dict.exportDataType.item_2.getItem()));
- //上传文件
- return R.ok();
- }
- @RequestMapping("/generalGoodsImgUploadByZip")
- @ResponseBody
- public R batchAddImgByZip(@RequestParam("file") MultipartFile file) throws IOException {
- //上传文件
- batchAdd(file,2);
- return R.ok();
- }
- @RequestMapping("/generalGoodsImgUpload")
- @ResponseBody
- public R batchAddImg(@RequestParam("file") MultipartFile file) throws IOException {
- //上传文件
- batchAdd(file,1);
- return R.ok();
- }
- private Map<String, Object> batchAdd(MultipartFile file, int type) throws IOException {
- /*
- *创建临时文件夹
- * 解压文件
- */
- String fileName = file.getOriginalFilename();
- String path = "/data/project/img/";
- File dir = new File(path);
- dir.mkdirs();
- String filePath = "/data/project/img2/";
- File fileDir = new File(filePath);
- fileDir.mkdirs();
- File saveFile = new File(fileDir, fileName);//将压缩包解析到指定位置
- List<String>list = new ArrayList<>();
- try {
- file.transferTo(saveFile);
- String newFilePath = filePath + fileName;
- File zipFile = new File(newFilePath);
- unZipFiles(zipFile, path,list,type);//解压文件,获取文件路径
- } catch (Exception e) {
- e.printStackTrace();
- log.info("解压执行失败");
- throw e;
- }finally {
- //程序结束时,删除临时文件
- deleteFiles(filePath);//删除压缩包文件夹
- deleteFiles(path);//删除解压文件夹**
- }
- log.info(JSON.toJSONString(list));
- Map<String, Object> jsonMap = new HashMap<>();
- jsonMap.put("ret",list);
- return jsonMap;
- }
- public void unZipFiles(File srcFile, String destDirPath, List<String> list, int type) throws RuntimeException {
- long start = System.currentTimeMillis();
- ZipFile zipFile = null;
- try {
- // 判断源文件是否存在
- if (!srcFile.exists()) {
- throw new RuntimeException(srcFile.getPath() + "所指文件不存在");
- }
- // 开始解压
- zipFile = new ZipFile(srcFile);
- zipFile.getEncoding();
- Enumeration<?> entries = zipFile.getEntries();
- List<ZipEntry> entryList = new ArrayList<>();
- while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
- log.info("解压" + entry.getName());
- entryList.add(entry);
- // 如果是文件夹,就创建个文件夹
- }
- if(null==entryList){
- throw new RRException("文件夹内无图片信息,请检查后重试");
- }
- if(entryList.size()>100){
- throw new RRException("最多上传100张图片");
- }
- for(ZipEntry entry : entryList){
- if (entry.isDirectory()) {
- String dirPath = destDirPath + "/" + entry.getName();
- File dir = new File(dirPath);
- dir.mkdirs();
- } else {
- // 如果是文件,就先创建一个文件,然后用io流把内容copy过去
- File targetFile = new File(destDirPath + "/" + entry.getName());
- // 保证这个文件的父文件夹必须要存在
- if(!targetFile.getParentFile().exists()){
- }
- targetFile.createNewFile();
- // 将压缩文件内容写入到这个文件中
- InputStream is = zipFile.getInputStream(entry);
- FileOutputStream fos = new FileOutputStream(targetFile);
- int len;
- byte[] buf = new byte[1024];
- while ((len = is.read(buf)) != -1) {
- fos.write(buf, 0, len);
- }
- MultipartFile mulFileByPath = getMulFileByPath(destDirPath + "/" + entry.getName());
- long fileSize = mulFileByPath.getSize();
- int maxSize = 1 * 1024 * 1024;
- if (fileSize > maxSize) {
- throw new RRException("商品图片过大(最大1M),请检查!");
- }
- //上传文件
- String url = FileManager.upload(mulFileByPath);
- list.add(url);
- if(type == 1){
- String barcode = entry.getName().split("\\.")[0];
- if (null==barcode||"".equals(barcode)) {
- throw new RRException("文件为:" + barcode + "的商品命名格式不正确,请检查!");
- }
- GoodsEntity goodsEntity = goodsService.queryByBarcode(barcode);
- goodsEntity.setPrimaryPicUrl(url);
- goodsEntity.setListPicUrl(url);
- goodsService.updateForImgUrl(goodsEntity);
- }
- //保存文件信息
- SysOssEntity ossEntity = new SysOssEntity();
- ossEntity.setUrl(url);
- ossEntity.setCreateDate(new Date());
- sysOssService.save(ossEntity);
- // 关流顺序,先打开的后关闭
- fos.close();
- is.close();
- }
- }
- long end = System.currentTimeMillis();
- System.out.println("解压完成,耗时:" + (end - start) +" ms");
- }catch (RRException e) {
- throw new RRException(e.getMessage(), e);
- }catch (Exception e) {
- throw new RuntimeException("unzip error from ZipUtils", e);
- } finally {
- if(zipFile != null){
- try {
- zipFile.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- private static MultipartFile getMulFileByPath(String picPath) {
- FileItem fileItem = createFileItem(picPath);
- MultipartFile mfile = new CommonsMultipartFile(fileItem);
- return mfile;
- }
- private static FileItem createFileItem(String filePath)
- {
- FileItemFactory factory = new DiskFileItemFactory(16, null);
- String textFieldName = "textField";
- int num = filePath.lastIndexOf(".");
- String extFile = filePath.substring(num);
- FileItem item = factory.createItem(textFieldName, "text/plain", true,
- "MyFileName" + extFile);
- File newfile = new File(filePath);
- int bytesRead = 0;
- byte[] buffer = new byte[8192];
- try
- {
- FileInputStream fis = new FileInputStream(newfile);
- OutputStream os = item.getOutputStream();
- while ((bytesRead = fis.read(buffer, 0, 8192))
- != -1)
- {
- os.write(buffer, 0, bytesRead);
- }
- os.close();
- fis.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- return item;
- }
- public void deleteFiles(String filePath) {
- File file = new File(filePath);
- if ((!file.exists()) || (!file.isDirectory())) {
- System.out.println("file not exist");
- return;
- }
- String[] tempList = file.list();
- File temp = null;
- for (int i = 0; i < tempList.length; i++) {
- if (filePath.endsWith(File.separator)) {
- temp = new File(filePath + tempList[i]);
- }
- else {
- temp = new File(filePath + File.separator + tempList[i]);
- }
- if (temp.isFile()) {
- temp.delete();
- }
- if (temp.isDirectory()) {
- this.deleteFiles(filePath + "/" + tempList[i]);
- }
- }
- // 空文件的删除
- file.delete();
- }
- @RequestMapping("/scannInfo/{prodBarcode}")
- @RequiresPermissions("goods:scannInfo")
- public R scannInfo(@PathVariable("prodBarcode")String prodBarcode) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- if(user == null) {
- return R.error("用户登录超时,请重新登录");
- }
- if (!user.getRoleType().equalsIgnoreCase("2")) {
- return R.error("该操作只允许店员账户操作");
- }
- GoodsEntity goods = goodsService.queryObjectByProdBarcodeAndBizType(prodBarcode, user.getStoreId());
- if(goods == null) {
- return R.error("商品信息不存在");
- }
- return R.ok().put("goods", goods);
- }
- @RequestMapping("/details/{prodBarcode}/{storeId}/{sku}")
- // @RequiresPermissions("goods:details") http://127.0.0.1:8080/goods/details/11111
- public R details(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId,@PathVariable("sku")String sku) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- if(user == null) {
- return R.error("用户登录超时,请重新登录");
- }
- if (!user.getRoleType().equalsIgnoreCase("2")) {
- return R.error("该操作只允许店员账户操作");
- }
- Map<String,Object> map = null;
- try {
- map = goodsService.calculateGoodsDetail(prodBarcode,storeId,sku);
- } catch (ServiceException e) {
- log.error("查询订单详情出现异常!", e);
- return R.error(e.getMessage());
- } catch (Exception e) {
- log.error("查询条码:【{}】详情出现异常!", prodBarcode, e);
- return R.error("系统异常,请联系管理员!e:"+e.getMessage());
- }
- if(map == null){
- return R.error("商品信息不存在");
- }
- return R.ok().put("goodsDetails", map.get("goods")).put("map",map);
- }
- @RequestMapping("/detailsOld/{prodBarcode}/{storeId}")
- // @RequiresPermissions("goods:details") http://127.0.0.1:8080/goods/details/11111
- public R details(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- if(user == null) {
- return R.error("用户登录超时,请重新登录");
- }
- if (!user.getRoleType().equalsIgnoreCase("2")) {
- return R.error("该操作只允许店员账户操作");
- }
- Map<String,Object> map = null;
- try {
- map = goodsService.calculateGoodsDetail(prodBarcode,storeId,null);
- } catch (ServiceException e) {
- log.error("查询订单详情出现异常!", e);
- return R.error(e.getMessage());
- } catch (Exception e) {
- log.error("查询条码:【{}】价格出现异常!", prodBarcode, e);
- return R.error("系统异常,请联系管理员!e:"+e.getMessage());
- }
- if(map == null){
- return R.error("商品信息不存在");
- }
- return R.ok().put("goodsDetails", map.get("goods")).put("map",map);
- }
- // storeId + sku + prodBarcode
- @RequestMapping(value = "/number/minus/{storeId}/{sku}/{prodBarcode}", method = RequestMethod.GET)
- public R minus(@PathVariable("storeId") String storeId, @PathVariable("sku") String sku, @PathVariable("prodBarcode") String prodBarcode) {
- String key = Constants.WAREHOUSE_STOCK_MAP_KEY + "_" + storeId;
- String itemKey = storeId + sku + prodBarcode;
- try {
- String cartNumber = JedisUtil.hget(key, itemKey);
- int number = Integer.parseInt(cartNumber);
- JedisUtil.hset(key, itemKey, String.valueOf(++number));
- } catch (Exception e) {
- log.error("storeId:【{}】,sku:【{}】,prodBarcode:【{}】,扣减购物篮商品数量失败!", storeId, sku, prodBarcode);
- return R.error("扣减购物篮商品数量失败!请删除购物篮商品后重试!");
- }
- return R.ok();
- }
- @RequestMapping(value = "/number/add/{storeId}/{sku}/{prodBarcode}/{sellVolume}", method = RequestMethod.GET)
- public R add(@PathVariable("storeId") String storeId,
- @PathVariable("sku") String sku,
- @PathVariable("prodBarcode") String prodBarcode,
- @PathVariable("sellVolume") Integer sellVolume) {
- String key = Constants.WAREHOUSE_STOCK_MAP_KEY + "_" + storeId;
- String itemKey = storeId + sku + prodBarcode;
- try {
- GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(prodBarcode, Integer.parseInt(storeId), sku);
- Integer exitRegionNumber = goodsEntity.getExitRegionNumber();
- Integer stockNum = goodsEntity.getStockNum();
- String number = JedisUtil.hget(key, itemKey);
- int cartNumber = Integer.parseInt(number);
- if (stockNum + cartNumber - exitRegionNumber >= sellVolume) {
- JedisUtil.hset(key, itemKey, String.valueOf(--cartNumber));
- } else {
- log.error("增加商品数量失败!保税仓库存不足!storeId:【{}】,sku:【{}】,prodBarcode:【{}】,stockNum:【{}】,exitRegionNumber:【{}】,wareStockNumber:【{}】"
- , storeId, sku, prodBarcode, stockNum, exitRegionNumber, cartNumber);
- return R.error("增加商品数量失败!保税仓库存不足!");
- }
- } catch (Exception e) {
- log.error("storeId:【{}】,sku:【{}】,prodBarcode:【{}】,增加购物篮商品数量失败!", storeId, sku, prodBarcode);
- return R.error("增加购物篮商品数量失败!请删除购物篮商品后重试!");
- }
- return R.ok();
- }
- @RequestMapping(value = "/number/del/{storeId}/{sku}/{prodBarcode}", method = RequestMethod.GET)
- public R del(@PathVariable("storeId") String storeId, @PathVariable("sku") String sku, @PathVariable("prodBarcode") String prodBarcode) {
- String key = Constants.WAREHOUSE_STOCK_MAP_KEY + "_" + storeId;
- String itemKey = storeId + sku + prodBarcode;
- try {
- JedisUtil.hdel(key, itemKey);
- } catch (Exception e) {
- log.error("storeId:【{}】,sku:【{}】,prodBarcode:【{}】,删除购物篮商品失败!", storeId, sku, prodBarcode);
- return R.error("删除购物篮商品失败!请刷新收银端页面!");
- }
- return R.ok();
- }
- @RequestMapping(value = "/number/clear/{storeId}", method = RequestMethod.GET)
- public R clear(@PathVariable("storeId") String storeId) {
- String key = Constants.WAREHOUSE_STOCK_MAP_KEY + "_" + storeId;
- try {
- JedisUtil.del(key);
- } catch (Exception e) {
- log.error("storeId:【{}】,清空购物篮商品失败!", storeId);
- return R.error("清空购物篮商品失败!请刷新收银端页面!");
- }
- return R.ok();
- }
- /**
- * 多sku可选
- * @param prodBarcode
- * @param storeId
- * @return
- */
- @RequestMapping("/selectSkuDetails/{prodBarcode}/{storeId}")
- public R selectSkuDetails(@PathVariable("prodBarcode")String prodBarcode,@PathVariable("storeId")String storeId) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- if(user == null) {
- return R.error("用户登录超时,请重新登录");
- }
- if (!user.getRoleType().equalsIgnoreCase("2")) {
- return R.error("该操作只允许店员账户操作");
- }
- List<Map<String,Object>> mapList = null;
- try {
- mapList = goodsService.selectSkuDetails(prodBarcode,storeId);
- } catch (ServiceException e) {
- log.error("查询sku详情出现异常!", e);
- return R.error(e.getMessage());
- } catch (Exception e) {
- return R.error("系统异常,请联系管理员!e:"+e.getMessage());
- }
- if(mapList == null){
- return R.error("商品信息不存在");
- }
- List<Object> objectList = new ArrayList<>();
- for(Map<String,Object> map : mapList){
- objectList.add(map.get("goods"));
- }
- return R.ok().put("goodsDetails", objectList).put("map",objectList);
- }
- /**
- * 根据商品编码或者条码查询商品信息(17.商品全景图)
- * @param keyword
- * @return
- */
- @GetMapping("/search/{keyword}")
- public R searchByKeyword(@PathVariable("keyword") String keyword){
- if (keyword == null || "".equals(keyword)){
- return R.error("请输入商品编码或者条码!");
- }
- GoodsPanoramaDto goodsPanoramaDto = goodsService.searchGoodsPanoramaDtoByKeyword(keyword);
- //GoodsEntity goods = goodsService.searchGoodsByKeyword(keyword);
- if (goodsPanoramaDto == null || "".equals(goodsPanoramaDto)) {
- return R.error("没有该商品!");
- }
- return R.ok().put("goodsPanoramaDto",goodsPanoramaDto);
- }
- /**
- * 所有商品模块导出
- * @param params 查询参数
- * @param response
- * @param request
- * @return
- */
- @RequiresPermissions("goods:export")
- @RequestMapping(value = "export")
- public R export(@RequestParam Map<String, Object> params, HttpServletResponse response, HttpServletRequest request) {
- ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
- params.put("isDelete", 0);
- String lastSaleTime = (String) params.get("lastSaleTime");
- if(org.apache.commons.lang.StringUtils.isNotEmpty(lastSaleTime)) {
- try {
- lastSaleTime = new String(lastSaleTime.getBytes("iso-8859-1"), "utf-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- lastSaleTime = DateUtils.getDate(lastSaleTime);
- params.put("lastSaleTime", lastSaleTime + " 00:00:00");
- }
- // 根据条件查询出列表
- List<GoodsEntity> goodsList = goodsService.queryExportList(params);
- ExcelExport ee = new ExcelExport("所有商品信息");
- String[] header = new String[]{"商户名称","第三方商户编号","商品编码","SKU","PLU","商品名称","商品英文名称","产品条码","货品业务类型","库存是否共享",
- "商品库存","日常价","成本价","是否上架","是否热销","录入日期","商品单位","商品税率","产品品牌","海关备案编号","计量单位","海关商品编码","国检规格型号",
- "原产国","海关申报要素","毛重(kg)","净重(kg)"};
- List<Map<String, Object>> list = new ArrayList<>();
- if (goodsList !=null && goodsList.size()>0){
- for (GoodsEntity goodsEntity : goodsList) {
- LinkedHashMap<String, Object> map = new LinkedHashMap<>();
- map.put("MerchName",goodsEntity.getMerchName());
- map.put("ThirdPartyMerchCode",goodsEntity.getThirdPartyMerchCode());
- map.put("GoodsSn",goodsEntity.getGoodsSn());
- map.put("Sku",goodsEntity.getSku());
- map.put("Plu",goodsEntity.getPlu());
- map.put("Name",goodsEntity.getName());
- map.put("EnglishName",goodsEntity.getEnglishName());
- String goodsBizType = goodsEntity.getGoodsBizType();
- Integer isStockShare = 0;
- if (goodsEntity.getIsStockShare()!=null){
- isStockShare = Integer.parseInt(goodsEntity.getIsStockShare());
- }
- map.put("ProdBarcode",goodsEntity.getProdBarcode());
- map.put("GoodsBizType",StringUtils.isEmpty(goodsBizType)?"":Dict.orderBizType.valueOf("item_"+goodsBizType).getItemName());
- map.put("IsStockShare",isStockShare==0?"否":"是");
- map.put("GoodsNumber",goodsEntity.getGoodsNumber());
- map.put("DailyPrice",goodsEntity.getDailyPrice());
- map.put("CostPrice",goodsEntity.getCostPrice());
- map.put("IsOnSale",goodsEntity.getIsOnSale()==0?"否":"是");
- map.put("IsHot",goodsEntity.getIsHot()==0?"否":"是");
- map.put("AddTime",goodsEntity.getAddTime());
- map.put("GoodsUnit",goodsEntity.getGoodsUnit());
- map.put("GoodsRate",goodsEntity.getGoodsRate());
- map.put("Brand",goodsEntity.getBrand());
- map.put("CusRecCode",goodsEntity.getCusRecCode());
- map.put("UnitCode",goodsEntity.getUnitCode());
- map.put("CusGoodsCode",goodsEntity.getCusGoodsCode());
- map.put("CiqProdModel",goodsEntity.getCiqProdModel());
- map.put("OriCntName",goodsEntity.getOriCntName());
- map.put("CusDeclEle",goodsEntity.getCusDeclEle());
- map.put("GrossWeight",goodsEntity.getGrossWeight());
- map.put("NetWeight",goodsEntity.getNetWeight());
- list.add(map);
- }
- }
- ee.addSheetByMap("所有商品信息", list, header);
- ee.export(response);
- return R.ok();
- }
- /**
- * 选择同步海关编号和商品税率
- * @return
- */
- @PostMapping("/syncGoodsRate")
- public R syncGoodsRate(@RequestBody Integer[] ids){
- // 先同步海关商品编码,再同步税率
- try {
- goodsService.syncOmsHsCodeGoode(Arrays.asList(ids));
- }catch (Exception e){
- e.printStackTrace();
- return R.error("同步海关商品编码失败,请联系管理员");
- }
- try {
- goodsService.syncGoodsRateGoode(Arrays.asList(ids));
- }catch (Exception e){
- e.printStackTrace();
- return R.error("同步商品税率失败,请联系管理员");
- }
- return R.ok();
- }
- /**
- * 全量同步海关编号和商品税率
- * @return
- */
- @PostMapping("/syncGoodsRateAll")
- public R syncGoodsRateAll(){
- // 先同步海关商品编码,再同步税率
- try {
- goodsService.syncOmsHsCodeTask();
- }catch (Exception e){
- e.printStackTrace();
- return R.error("同步海关商品编码失败,请联系管理员");
- }
- try {
- goodsService.syncGoodsRateTask();
- }catch (Exception e){
- e.printStackTrace();
- return R.error("同步商品税率失败,请联系管理员");
- }
- return R.ok();
- }
- /**
- * 校验系统中的商品价格是否有问题
- * @return
- */
- @RequestMapping("/checkGoodsPrice")
- public R checkGoodsPrice(){
- SysUserEntity user = ShiroUtils.getUserEntity();
- // 先同步海关商品编码,再同步税率
- try {
- goodsService.checkGoodsPrice(user);
- }catch (Exception e){
- e.printStackTrace();
- return R.error("校验失败,请联系管理员");
- }
- return R.ok("校验成功");
- }
- }
|