diff --git a/.gitignore b/.gitignore index 28fb35fc..b8080da1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ */*.iml /.gradle/ /application.pid -*.log \ No newline at end of file +*.log +logs/* \ No newline at end of file diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java index 2abfebf2..78af6b89 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/CacheKey.java @@ -22,6 +22,8 @@ package cn.ysk.cashier.utils; */ public interface CacheKey { + String ONLINE_ADMIN = "ONLINE_ADMIN:"; + /** * 激活码 */ diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java index 0f2fcacc..ae33d9f2 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/FileUtil.java @@ -17,14 +17,19 @@ package cn.ysk.cashier.utils; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.poi.excel.BigExcelWriter; import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; import cn.ysk.cashier.exception.BadRequestException; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.streaming.SXSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFSheet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.multipart.MultipartFile; + import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -32,6 +37,7 @@ import java.io.*; import java.security.MessageDigest; import java.text.DecimalFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; @@ -153,7 +159,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { /** * inputStream 转 File */ - static File inputStreamToFile(InputStream ins, String name){ + static File inputStreamToFile(InputStream ins, String name) { File file = new File(SYS_TEM_DIR + name); if (file.exists()) { return file; @@ -214,7 +220,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { BigExcelWriter writer = ExcelUtil.getBigWriter(file); // 一次性写出内容,使用默认样式,强制输出标题 writer.write(list, true); - SXSSFSheet sheet = (SXSSFSheet)writer.getSheet(); + SXSSFSheet sheet = (SXSSFSheet) writer.getSheet(); //上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法 sheet.trackAllColumnsForAutoSizing(); //列宽自适应 @@ -231,6 +237,79 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { IoUtil.close(out); } + /** + * 输入标题到excel + * + * @param writer excel对象 + * @param column 当前列位置 + * @param cellValue 标题内容 + * @param requiredFlag 是否标红 + */ + private static void writeCell(ExcelWriter writer, int column, int row, String cellValue, boolean requiredFlag) { + // 根据x,y轴设置单元格内容 + if (StrUtil.isNotBlank(cellValue)) { + writer.writeCellValue(column, row, cellValue); + } + Font font = writer.createFont(); + font.setColor(Font.COLOR_RED); + if (requiredFlag) { + // 根据x,y轴获取当前单元格样式 + CellStyle cellStyle = writer.createCellStyle(column, row); + // 内容水平居中 + cellStyle.setAlignment(HorizontalAlignment.CENTER); + // 内容垂直居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 设置边框 + cellStyle.setBorderBottom(BorderStyle.THIN); + cellStyle.setBorderLeft(BorderStyle.THIN); + cellStyle.setBorderRight(BorderStyle.THIN); + // 字体颜色标红 +// cellStyle.setFont(font); + cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + } + } + + public static void downloadExcelAndMerge(List> list, int colSize, HttpServletResponse response, ArrayList mergeRowIndex) throws IOException { + String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; + File file = new File(tempPath); + ExcelWriter writer = ExcelUtil.getWriter(file); + for (int i = 0; i < mergeRowIndex.size(); i++) { + + int start = i == 0 ? 1 : mergeRowIndex.get(i - 1) + 1; + for (int i1 = 0; i1 < colSize; i1++) { + + if (start != mergeRowIndex.get(i)) { + writer.merge(i == 0 ? 1 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true); + } + } + } + + // 一次性写出内容,使用默认样式,强制输出标题 + writer.write(list, true); + + XSSFSheet sheet = (XSSFSheet) writer.getSheet(); + // 设置列宽 + for (int i = 0; i < colSize + 2; i++) { + sheet.setColumnWidth(i, 4000); // 200个字符宽度 + } + //上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法 +// sheet.trackAllColumnsForAutoSizing(); + //列宽自适应 +// writer.autoSizeColumnAll(); + //response为HttpServletResponse对象 + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); + // 将写入的Excel作为文件流写出到response + ServletOutputStream out = response.getOutputStream(); + // 终止后删除临时文件 + file.deleteOnExit(); + writer.flush(out, true); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + } + public static String getFileType(String type) { String documents = "txt doc pdf ppt pps xlsx xls docx"; String music = "mp3 wav wma mpa ram ra aac aif m4a"; @@ -263,7 +342,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { public static boolean check(File file1, File file2) { String img1Md5 = getMd5(file1); String img2Md5 = getMd5(file2); - if(img1Md5 != null){ + if (img1Md5 != null) { return img1Md5.equals(img2Md5); } return false; @@ -353,4 +432,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { public static String getMd5(File file) { return getMd5(getByte(file)); } + + } diff --git a/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java b/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java index 7e6e2f1d..32095301 100644 --- a/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java +++ b/eladmin-logging/src/main/java/cn/ysk/cashier/service/impl/LogServiceImpl.java @@ -96,6 +96,26 @@ public class LogServiceImpl implements LogService { String value = SpelUtil.generateKeyBySpEL(split[1], joinPoint); // 描述 log.setDescription(split[0] + ":" + value); + } + if (split.length == 3) { +// String v1 = SpelUtil.generateKeyBySpEL(split[1], joinPoint); + String v2 = SpelUtil.generateKeyBySpEL(split[2], joinPoint); + if (methodName.contains("createOutAndONOperate")) { + //subType 1入库 -1出库 + if ("purchase".equals(v2) || "purveyor".equals(v2)) { + v2 = "入库"; + } else { + v2 = "出库"; + } + }else if(methodName.contains("stockInOut")){ + if (("in".equals(v2) || "purveyor".equals(v2))) { + v2 = "入库"; + } else { + v2 = "出库"; + } + } + // 描述 + log.setDescription(split[0] + ":" + v2 ); }else { log.setDescription(split[0]); } diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 8984287d..1acadac4 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -19,6 +19,7 @@ + cn.ysk.cashier @@ -39,6 +40,11 @@ 2.6 + + org.apache.poi + poi + 5.2.1 + org.springframework.boot diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java index fc8f93f5..250da238 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java @@ -150,6 +150,7 @@ public class AuthorizationController { put("user", jwtUserDto); if (byAccount != null) { put("shopId", byAccount.getId()); + put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?authUser.getLoginType():"merchant"); put("shopName", byAccount.getShopName()); put("logo", byAccount.getLogo()); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java index 69eb8171..20105559 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/domain/TbConsSuppFlow.java @@ -59,8 +59,7 @@ public class TbConsSuppFlow implements Serializable { @ApiModelProperty(value = "productId") private Integer productId; - @Column(name = "`supplier_id`",nullable = false) - @NotNull + @Column(name = "`supplier_id`") @ApiModelProperty(value = "supplierId") private Integer supplierId; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java index 7c50ba9a..e9928425 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/rest/TbConsInfoController.java @@ -71,7 +71,7 @@ public class TbConsInfoController { } @PostMapping(value = "stockInOut") - @Log("耗材出入库") + @Log("耗材::#resources.type") @ApiOperation("耗材出入库") public ResponseEntity stockInOut(@Validated @RequestBody SuppFlow resources) throws Exception { diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java index a5c50c38..4ced9a06 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConCheckServiceImpl.java @@ -2,6 +2,8 @@ package cn.ysk.cashier.cons.service.impl; import cn.ysk.cashier.cons.domain.TbConCheck; import cn.ysk.cashier.cons.domain.TbConsInfo; +import cn.ysk.cashier.cons.domain.TbConsInfoFlow; +import cn.ysk.cashier.cons.repository.TbConsInfoFlowRepository; import cn.ysk.cashier.cons.repository.TbConsInfoRepository; import cn.ysk.cashier.utils.FileUtil; import cn.ysk.cashier.utils.PageUtil; @@ -39,6 +41,8 @@ public class TbConCheckServiceImpl implements TbConCheckService { private final TbConsInfoRepository tbConsInfoRepository; + public final TbConsInfoFlowRepository tbConsInfoFlowRepository; + @Override public Map queryAll(TbConCheckQueryCriteria criteria, Pageable pageable){ Page page = tbConCheckRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); @@ -65,20 +69,46 @@ public class TbConCheckServiceImpl implements TbConCheckService { if(Objects.isNull(consInfo)){ throw new Exception("耗材信息不存在"); } + TbConsInfoFlow flow=new TbConsInfoFlow(); - BigDecimal stonum=consInfo.getStockNumber().subtract(consInfo.getStockConsume()); + if(consInfo.getStockNumber().compareTo(resources.getStockNumber())>=0){ + flow.setBizCode("checkStockOut"); + flow.setBizName("盘点出库"); + flow.setBizType("-"); + }else { + flow.setBizCode("checkStockIn"); + flow.setBizName("盘点入库"); + flow.setBizType("+"); + } - consInfo.setStockConsume(consInfo.getStockConsume().add(resources.getLpNum().negate())); + + consInfo.setStockConsume(BigDecimal.ZERO); + consInfo.setStockNumber(resources.getStockNumber()); consInfo.setUpdateTime(new Timestamp(System.currentTimeMillis())); tbConsInfoRepository.save(consInfo); + + + + + flow.setConsId(consInfo.getId()); + flow.setShopId(consInfo.getShopId()); + flow.setConName(consInfo.getConName()); + flow.setAmount(consInfo.getStockNumber()); + flow.setBalance(consInfo.getStockNumber()); + + flow.setCreateTime(new Timestamp(System.currentTimeMillis())); + tbConsInfoFlowRepository.save(flow); + + + TbConCheck conCheck=new TbConCheck(); conCheck.setConInfoId(consInfo.getId()); conCheck.setConName(consInfo.getConName()); conCheck.setPrice(consInfo.getPrice()); - conCheck.setAcStockNumber(consInfo.getStockNumber().subtract(consInfo.getStockConsume())); - conCheck.setStockNumber(stonum); + conCheck.setAcStockNumber(resources.getStockNumber()); + conCheck.setStockNumber(resources.getStockNumber()); conCheck.setLpNum(resources.getLpNum()); conCheck.setLpAmount(consInfo.getPrice().multiply(resources.getLpNum())); conCheck.setCreateTime(new Timestamp(System.currentTimeMillis())); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java index acdb3836..5a9b7e8c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/cons/service/impl/TbConsInfoServiceImpl.java @@ -184,13 +184,17 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { if (Objects.isNull(tbShopInfo)) { throw new Exception("店铺信息不存在"); } - TbShopPurveyor purveyor = tbShopPurveyorRepository.getById(resources.getSupplierId()); - if (Objects.isNull(purveyor)) { - throw new Exception("不存在的供应商"); + + TbShopPurveyor purveyor=null; + TbProductStockOperate stockOperate = new TbProductStockOperate(); + if(Objects.nonNull(resources.getSupplierId())){ + purveyor = tbShopPurveyorRepository.getById(resources.getSupplierId()); + if (Objects.nonNull(purveyor)) { + stockOperate.setPurveyorId(resources.getSupplierId().toString()); + stockOperate.setPurveyorName(purveyor.getPurveyorName()); + } } - - TbProductStockOperate stockOperate = new TbProductStockOperate(); stockOperate.setShopId(tbShopInfo.getId().toString()); stockOperate.setStockSnap(""); stockOperate.setType(resources.getType().equals("in")?"cons_in":"cons_out"); @@ -204,8 +208,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { stockOperate.setCreatedAt(System.currentTimeMillis()); stockOperate.setUpdatedAt(System.currentTimeMillis()); stockOperate.setStatus("normal"); - stockOperate.setPurveyorId(resources.getSupplierId().toString()); - stockOperate.setPurveyorName(purveyor.getPurveyorName()); + JSONArray array=new JSONArray(); @@ -224,15 +227,15 @@ public class TbConsInfoServiceImpl implements TbConsInfoService { TbShopPurveyorTransact purveyorTransact = new TbShopPurveyorTransact(); purveyorTransact.setShopId(tbShopInfo.getId().toString()); - purveyorTransact.setPurveyorName(purveyor.getPurveyorName()); - purveyorTransact.setPurveyorId(purveyor.getId().toString()); - purveyorTransact.setRemark(""); + purveyorTransact.setPurveyorName(Objects.isNull(purveyor)?"":purveyor.getPurveyorName()); + purveyorTransact.setPurveyorId(Objects.isNull(purveyor)?"":purveyor.getId().toString()); + purveyorTransact.setRemark(resources.getRemark()); purveyorTransact.setCreatedAt(System.currentTimeMillis()); purveyorTransact.setUpdatedAt(System.currentTimeMillis()); suppFlow.setConInfoId(info.getConTypeId()); suppFlow.setShopId(resources.getShopId()); - suppFlow.setSupplierId(resources.getSupplierId()); + suppFlow.setSupplierId(Objects.isNull(resources.getSupplierId())?0: resources.getSupplierId()); suppFlow.setType(resources.getType()); suppFlow.setStockNumber(conInfos.getStockNumber()); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java index 8326bb57..a41c8e77 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/StockController.java @@ -1,15 +1,11 @@ package cn.ysk.cashier.controller.product; import cn.hutool.core.util.StrUtil; -import cn.ysk.cashier.annotation.AnonymousAccess; import cn.ysk.cashier.annotation.Log; -import cn.ysk.cashier.annotation.rest.AnonymousPostMapping; import cn.ysk.cashier.dto.product.StockQueryDto; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.service.product.StockService; import cn.ysk.cashier.utils.BeanUtil; -import cn.ysk.cashier.utils.SecurityUtils; -import cn.ysk.cashier.vo.StockPageImpl; import cn.ysk.cashier.vo.StockUpdateValueVO; import cn.ysk.cashier.vo.StockUpdateWarnLineVO; import cn.ysk.cashier.vo.StockV2Vo; @@ -18,15 +14,12 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; import java.io.IOException; import java.util.Map; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java index 5e78001a..134e1799 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java @@ -39,8 +39,8 @@ public class TbProductController { } @GetMapping("/isHot") - public ResponseEntity updateIsHot(@RequestParam String shopId, @RequestParam Integer id){ - tbProductService.updateIsHot(id,shopId); + public ResponseEntity updateIsHot(@RequestParam Integer isHot, @RequestParam Integer id){ + tbProductService.updateIsHot(id,isHot); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java index 3e222c74..b8ea5c2d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductStockOperateController.java @@ -61,7 +61,7 @@ public class TbProductStockOperateController { @PostMapping("/outAndOn") @ApiOperation("新增/product/StockOperate") - @Log("出入库") + @Log("商品::#outAndOnDto.type") // @PreAuthorize("@el.check('tbProductStockOperate:add')") public ResponseEntity createOutAndONOperate(@RequestBody OutAndOnDto outAndOnDto){ return new ResponseEntity<>(tbProductStockOperateService.createOutAndONOperate(outAndOnDto),HttpStatus.CREATED); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java index 6607c755..480ff91c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbPlussShopStaffController.java @@ -1,25 +1,9 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ package cn.ysk.cashier.controller.shop; import cn.ysk.cashier.annotation.Log; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; import cn.ysk.cashier.service.shop.TbPlussShopStaffService; import cn.ysk.cashier.dto.shop.TbPlussShopStaffQueryCriteria; -import io.swagger.models.auth.In; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -91,4 +75,15 @@ public class TbPlussShopStaffController { tbPlussShopStaffService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } + +// @ApiOperation("修改个人密码") +// @PostMapping(value = "/upPass") +// @AnonymousPostMapping +// public ResponseEntity upshopStaffPass(HttpServletRequest request, @RequestBody Map map){ +// tbShopInfoService.upShopPass(map.get("username"),map.get("password")); +// //根据token踢出用户 +// onlineUserService.logout(tokenProvider.getToken(request)); +// log.info("修改商户密码成功。"); +// return new ResponseEntity<>(HttpStatus.OK); +// } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java index 48a51f9b..a6980d50 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java @@ -72,7 +72,7 @@ public class TbShopInfoController { public ResponseEntity upShopPass(HttpServletRequest request, @RequestBody Map map) throws Exception { tbShopInfoService.upShopPass(map.get("username"),map.get("password")); //根据token踢出用户 -// onlineUserService.logout(tokenProvider.getToken(request)); + onlineUserService.logout(tokenProvider.getToken(request)); log.info("修改商户密码成功。"); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopOpenId.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopOpenId.java new file mode 100644 index 00000000..72c687f3 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopOpenId.java @@ -0,0 +1,59 @@ +package cn.ysk.cashier.mybatis.entity; + +import java.io.Serializable; +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 商家openid信息表 + * @TableName tb_shop_open_id + */ +@Table(name="tb_shop_open_id") +@Data +@EqualsAndHashCode +public class TbShopOpenId implements Serializable { + /** + * + */ + @Id + private Integer id; + + /** + * 店铺id + */ + private Integer shopId; + + /** + * 已经订阅消息的商家微信号 + */ + private String openId; + + /** + * + */ + private Integer status; + + /** + * + */ + private LocalDateTime createTime; + + /** + * + */ + private LocalDateTime updateTime; + + /** + * 类型 -1 任意消息 0库存预警 + */ + private Integer type; + + private static final long serialVersionUID = 1L; + + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopOpenIdMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopOpenIdMapper.java new file mode 100644 index 00000000..3e088ed0 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopOpenIdMapper.java @@ -0,0 +1,18 @@ +package cn.ysk.cashier.mybatis.mapper; + +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author Administrator +* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Mapper +* @createDate 2024-08-02 10:00:27 +* @Entity cn.ysk.cashier.mybatis.entity.TbShopOpenId +*/ +public interface TbShopOpenIdMapper extends BaseMapper { + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopOpenIdService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopOpenIdService.java new file mode 100644 index 00000000..554107d5 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopOpenIdService.java @@ -0,0 +1,13 @@ +package cn.ysk.cashier.mybatis.service; + +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author Administrator +* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Service +* @createDate 2024-08-02 10:00:27 +*/ +public interface TbShopOpenIdService extends IService { + +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopOpenIdServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopOpenIdServiceImpl.java new file mode 100644 index 00000000..bf99c448 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopOpenIdServiceImpl.java @@ -0,0 +1,22 @@ +package cn.ysk.cashier.mybatis.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import cn.ysk.cashier.mybatis.service.TbShopOpenIdService; +import cn.ysk.cashier.mybatis.mapper.TbShopOpenIdMapper; +import org.springframework.stereotype.Service; + +/** +* @author Administrator +* @description 针对表【tb_shop_open_id(商家openid信息表)】的数据库操作Service实现 +* @createDate 2024-08-02 10:00:27 +*/ +@Service +public class TbShopOpenIdServiceImpl extends ServiceImpl + implements TbShopOpenIdService{ + +} + + + + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java index e8cdda21..dc5a9597 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java @@ -3,6 +3,7 @@ package cn.ysk.cashier.repository.order; import cn.ysk.cashier.dto.product.StockCountDTO; import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.vo.TbOrderPayCountVo; +import cn.ysk.cashier.vo.TbOrderSaleVO; import cn.ysk.cashier.vo.TbOrderSalesCountByDayVo; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Page; @@ -14,6 +15,8 @@ import org.springframework.data.jpa.repository.Query; import javax.persistence.Tuple; +import java.sql.Time; +import java.sql.Timestamp; import java.util.Date; import java.util.List; @@ -82,7 +85,9 @@ public interface TbOrderDetailRepository extends JpaRepository queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + @Query(value = "SELECT " + + "new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status)\n" + + "FROM\n" + + "TbOrderInfo oi\n" + + "LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" + + "WHERE\n" + + "od.shopId = :shopId \n" + + "AND ( od.status = 'closed' OR od.status = 'refund' ) \n" + + "AND od.createTime > :startTime \n" + + "AND od.createTime < :endTime \n" + + "AND (:productId is null or od.productId = :productId)\n" + + "AND (:productId is null or od.productSkuId = :productSkuId)") + List querySaleOrderInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productId") Integer productId, @Param("productSkuId") Integer productSkuId, @Param("shopId") Integer shopId); + @Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" + "COALESCE(CAST(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as long),0), " + "COALESCE(CAST(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END) as long),0))" + @@ -145,4 +164,5 @@ public interface TbOrderDetailRepository extends JpaRepository findOrderIdsByProductNameLike(@Param("productName") String productName, @Param("shop_id") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java index 01e2ae64..1da35b54 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java @@ -25,9 +25,9 @@ public interface TbProductRepository extends JpaRepository, @Query(value = "update tb_product set status = -1 where id in :productIds",nativeQuery = true) @Modifying void updateByStatus(List productIds); - @Query(value = "update tb_product set is_hot=1 where id = :id",nativeQuery = true) + @Query(value = "update tb_product set is_hot=:isHot where id = :id",nativeQuery = true) @Modifying - void updateIsHot(@Param("id") Integer id); + void updateIsHot(@Param("id") Integer id,@Param("isHot")Integer isHot); @Query(value = "update tb_product set is_stock=:isStock where id = :proId and shop_id=:shopId",nativeQuery = true) @Modifying @@ -62,4 +62,6 @@ public interface TbProductRepository extends JpaRepository, @Query("select product from TbProduct product where product.shopId=:shopId") List selectByShopId(String shopId); + @Query(value = "select b.* from tb_product_sku as a left join tb_product as b on a.product_id=b.id where a.id=:skuId", nativeQuery = true) + TbProduct selectBySkuId(@Param("skuId") Integer skuId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java index 7cf13c48..7996d6a6 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductSkuRepository.java @@ -63,7 +63,7 @@ public interface TbProductSkuRepository extends JpaRepository 0 THEN true ELSE false END as isGrounding) " + "from " + "TbProduct pro " + "LEFT JOIN TbProductSku sku on pro.id = sku.productId " + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java index f8429d07..00876641 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbPlussShopStaffRepository.java @@ -1,18 +1,3 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ package cn.ysk.cashier.repository.shop; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; @@ -21,8 +6,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -import java.util.List; - /** * @website https://eladmin.vip * @author lyf @@ -42,6 +25,10 @@ public interface TbPlussShopStaffRepository extends JpaRepository> list = new ArrayList<>(); +// ConcurrentLinkedQueue> list = new ConcurrentLinkedQueue(); if(StringUtils.isBlank(summaryDto.getCateId())){ summaryDto.setCateId(null); } + + ArrayList mergeRowIndex = new ArrayList<>(); if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额 Long start = 1704038400000L; Long end = Instant.now().toEpochMilli(); @@ -430,23 +435,39 @@ public class SummaryServiceImpl implements SummaryService { summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L))); summaryDto.setEndTime(new Date()); } - List tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime()); - for (TbOrderSalesCountByDayVo all : tbOrderSalesCountByDayVos) { - Map map = new LinkedHashMap<>(); - map.put("商品分类", all.getCateName()); - map.put("商品名称", all.getProductName()); - map.put("单 位", all.getUnitName()); - map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName()); - map.put("销 售 额", all.getSalesAmount()); - map.put("销 量", all.getSalesNum()); - map.put("单 价", all.getPrice()); - map.put("退 单 量", all.getRefNum()); - map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO)==0?all.getRefAmount():"-"+all.getRefAmount()); - map.put("总 量", all.getNum()-all.getRefNum()); - list.add(map); - } + List tbOrderSalesCountByDayVos = detailRepository + .queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime()); + tbOrderSalesCountByDayVos.forEach(all -> { + List tbOrderSaleVOS = detailRepository.querySaleOrderInfo(new Timestamp(summaryDto.getStartTime().getTime()), + new Timestamp(summaryDto.getEndTime().getTime()), all.getProductId(), all.getProductSkuId(), Integer.valueOf(summaryDto.getShopId())); + for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) { + Map map = new LinkedHashMap<>(); + map.put("商品分类", all.getCateName()); + map.put("商品名称", all.getProductName()); + map.put("单 位", all.getUnitName()); + map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName()); + map.put("销 售 额", all.getSalesAmount()); + map.put("销 量", all.getSalesNum()); + map.put("单 价", all.getPrice()); + map.put("退 单 量", all.getRefNum()); + map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO)==0?all.getRefAmount():"-"+all.getRefAmount()); + map.put("总 量", all.getNum()-all.getRefNum()); + map.put("订单编号", tbOrderSaleVO.getOrderNo()); + map.put("售出数量", tbOrderSaleVO.getNum()); + list.add(map); + } + if (!tbOrderSaleVOS.isEmpty()) { + if (mergeRowIndex.isEmpty()) { + mergeRowIndex.add(tbOrderSaleVOS.size()); + }else { + mergeRowIndex.add(mergeRowIndex.get(mergeRowIndex.size() - 1) + tbOrderSaleVOS.size()); + } + } + + }); + } - FileUtil.downloadExcel(list, response); + FileUtil.downloadExcelAndMerge(list, 10, response, mergeRowIndex); } @Override diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java index 25363231..4511db70 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/StockServiceImpl.java @@ -17,10 +17,7 @@ import cn.ysk.cashier.repository.shop.TbShopUnitRepository; import cn.ysk.cashier.service.TbProductStockOperateService; import cn.ysk.cashier.service.product.StockService; import cn.ysk.cashier.service.product.TbProductService; -import cn.ysk.cashier.utils.CacheKey; -import cn.ysk.cashier.utils.FileUtil; -import cn.ysk.cashier.utils.RedisUtils; -import cn.ysk.cashier.utils.StringUtils; +import cn.ysk.cashier.utils.*; import cn.ysk.cashier.vo.StockUpdateValueVO; import cn.ysk.cashier.vo.StockUpdateWarnLineVO; import cn.ysk.cashier.vo.StockV2Vo; @@ -62,6 +59,7 @@ public class StockServiceImpl implements StockService { private final TbShopUnitRepository shopUnitRepository; private final TbProductStockDetailRepository tbProductStockDetailRepository; private final TbProductRepository tbProductRepository; + private final WxMsgUtils wxMsgUtils; @PersistenceContext private EntityManager em; @@ -349,6 +347,15 @@ public class StockServiceImpl implements StockService { Query nativeQuery = em.createNativeQuery(String.valueOf(sqlQuery)); nativeQuery.executeUpdate(); + + TbProduct product = tbProductRepository.selectBySkuId(Integer.valueOf(updateValueVO.getTargetId())); + TbProductSku tbProductSku = tbProductSkuRepository.findById(Integer.valueOf(updateValueVO.getTargetId())).orElse(null); + // 推送微信操作消息 + if (product != null && tbProductSku != null) { + wxMsgUtils.aboardOperationMsg(("0".equals(updateValueVO.getUpdateValue()) ? "关闭sku售罄: " : "开启sku售罄: ") + product.getName() + "/"+ tbProductSku.getSpecSnap()); + }else { + log.warn("推送微信操作消息失败,未查询到商品信息,skuId: {}", updateValueVO.getTargetId()); + } return; case "stock": sqlQuery.append(" set is_stock = ").append(updateValueVO.getUpdateValue()); @@ -358,6 +365,13 @@ public class StockServiceImpl implements StockService { break; case "pauseSale": sqlQuery.append(" set is_pause_sale = ").append(updateValueVO.getUpdateValue()); + TbProduct product1 = tbProductRepository.selectBySkuId(Integer.valueOf(updateValueVO.getTargetId())); + // 推送微信操作消息 + if (product1 != null) { + wxMsgUtils.aboardOperationMsg(("0".equals(updateValueVO.getUpdateValue()) ? "关闭售罄: " : "开启售罄: ") + product1.getName()); + }else { + log.warn("推送微信操作消息失败,未查询到商品信息,skuId: {}", updateValueVO.getTargetId()); + } break; default: throw new BadRequestException("无效更新类型"); @@ -393,7 +407,10 @@ public class StockServiceImpl implements StockService { if (tbProductSku == null) { throw new BadRequestException("商品不存在,skuId: " + skuId); } + TbProduct product = tbProductRepository.selectByShopIdAndId(Integer.parseInt(tbProductSku.getProductId()), String.valueOf(shopId)); + // 推送微信操作消息 + wxMsgUtils.aboardOperationMsg((isGrounding ? "上架商品: " : "下架商品: ") + product.getName()); // 共享库存下架所有sku if (product.getIsDistribute().equals(1)) { tbProductSkuRepository.updateGroundingByProId(product.getId().toString(), isGrounding ? 1 : 0); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java index 89bbc6cc..bb84510a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java @@ -46,6 +46,7 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { private final TbProductGroupRepository tbProductGroupRepository; private final TbProductGroupMapper tbProductGroupMapper; private final TbProductRepository tbProductRepository; + private final WxMsgUtils wxMsgUtils; @Resource private OnlineUserService onlineUserService; @@ -104,6 +105,9 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { ValidationUtil.isNull( tbProductGroup.getId(),"TbProductGroup","id",resources.getId()); tbProductGroup.copy(resources); tbProductGroupRepository.save(tbProductGroup); + + // 推送微信操作消息 + wxMsgUtils.aboardOperationMsg((resources.getIsShow() == 0 ? "关闭分组: " : "开启分组: ") + tbProductGroup.getName()); } @Transactional(rollbackFor = Exception.class) @@ -224,4 +228,4 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { -} \ No newline at end of file +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java index 9e181f3d..7edab52c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java @@ -521,9 +521,8 @@ public class TbProductServiceImpl implements TbProductService { @Transactional(rollbackFor = Exception.class) @Override - public void updateIsHot(Integer id, String shopId) { - tbProductRepository.updateNullHot(shopId); - tbProductRepository.updateIsHot(id); + public void updateIsHot(Integer id,Integer isHot) { + tbProductRepository.updateIsHot(id,isHot); } @Transactional(rollbackFor = Exception.class) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java index 2f953ab9..ed5c51ce 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductStocktakinServiceImpl.java @@ -160,6 +160,7 @@ public class TbProductStocktakinServiceImpl implements TbProductStocktakinServic round = (int) Math.floor( productSku.getStockNumber()); + productStockDetail.setSpecSnap(productSku.getSpecSnap()); productStockDetail.setSubType(productStocktakinDTO.getStocktakinNum() > productSku.getStockNumber() ? 1 : -1); stockOperate.setType(productStocktakinDTO.getStocktakinNum() > productSku.getStockNumber() ? "盘点入库" : "盘点出库"); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbPlussShopStaffServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbPlussShopStaffServiceImpl.java index 853f1d1a..5a91a088 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbPlussShopStaffServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbPlussShopStaffServiceImpl.java @@ -203,7 +203,7 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService { Set sysUserIds=new HashSet<>(); for (Integer id : ids) { TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffRepository.findById(id).get(); - User sysUser = userRepository.findByUsername(tbPlussShopStaff.getAccount()); + User sysUser = userRepository.findByUsername(tbPlussShopStaff.getShopId()+"@"+tbPlussShopStaff.getAccount()); tbPlussShopStaffRepository.deleteById(id); sysUserIds.add(sysUser.getId()); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java index d9e55502..3ee7c092 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java @@ -85,7 +85,7 @@ public interface TbProductService { */ void download(List all, HttpServletResponse response) throws IOException; - void updateIsHot(Integer id, String shopId); + void updateIsHot(Integer id,Integer isStock); void updateIsStock(Integer proId, String shopId, Integer isStock); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java index 625c0271..31bdb4aa 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/system/domain/vo/UserPassVo.java @@ -1,18 +1,3 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package cn.ysk.cashier.system.domain.vo; import lombok.Data; @@ -25,6 +10,9 @@ import lombok.Data; @Data public class UserPassVo { + //staff + private String loginType; + private String oldPass; private String newPass; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java index f54b9107..208f1418 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/system/rest/UserController.java @@ -1,26 +1,15 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package cn.ysk.cashier.system.rest; import cn.hutool.core.collection.CollectionUtil; +import cn.ysk.cashier.config.security.security.TokenProvider; +import cn.ysk.cashier.config.security.service.OnlineUserService; +import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository; import cn.ysk.cashier.system.domain.Dept; import cn.ysk.cashier.system.domain.User; import cn.ysk.cashier.system.domain.vo.UserPassVo; import cn.ysk.cashier.system.service.dto.UserDto; import cn.ysk.cashier.system.service.dto.UserQueryCriteria; +import cn.ysk.cashier.utils.MD5Utils; import cn.ysk.cashier.utils.PageUtil; import cn.ysk.cashier.utils.RsaUtils; import cn.ysk.cashier.utils.SecurityUtils; @@ -37,16 +26,20 @@ import cn.ysk.cashier.system.service.dto.RoleSmallDto; import cn.ysk.cashier.system.service.VerifyService; import cn.ysk.cashier.system.service.UserService; import cn.ysk.cashier.utils.enums.CodeEnum; +import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; @@ -68,6 +61,9 @@ public class UserController { private final DeptService deptService; private final RoleService roleService; private final VerifyService verificationCodeService; + private final OnlineUserService onlineUserService; + private final TbPlussShopStaffRepository shopStaffRepository; + private final TokenProvider tokenProvider; @ApiOperation("导出用户数据") @GetMapping(value = "/download") @@ -155,17 +151,27 @@ public class UserController { @ApiOperation("修改密码") @PostMapping(value = "/updatePass") - public ResponseEntity updateUserPass(@RequestBody UserPassVo passVo) throws Exception { - String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getOldPass()); - String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getNewPass()); - UserDto user = userService.findByName(SecurityUtils.getCurrentUsername()); - if(!passwordEncoder.matches(oldPass, user.getPassword())){ + @Transactional + public ResponseEntity updateUserPass(HttpServletRequest request, @RequestBody UserPassVo passVo) throws Exception { + String currentUsername = SecurityUtils.getCurrentUsername(); + UserDto user = userService.findByName(currentUsername); + String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, passVo.getOldPass()); + if (!passwordEncoder.matches(oldPass, user.getPassword())) { throw new BadRequestException("修改失败,旧密码错误"); } - if(passwordEncoder.matches(newPass, user.getPassword())){ + System.out.println(oldPass); + if (passwordEncoder.matches(passVo.getNewPass(), user.getPassword())) { throw new BadRequestException("新密码不能与旧密码相同"); } - userService.updatePass(user.getUsername(),passwordEncoder.encode(newPass)); + String encPass = MD5Utils.encrypt( passVo.getNewPass()); + if (StringUtils.isNotBlank(passVo.getLoginType()) && passVo.getLoginType().equals("staff")) { + String[] split = currentUsername.split("@"); + shopStaffRepository.updatePassAndShopId(split[1],split[0],encPass,System.currentTimeMillis()); + }else { + shopStaffRepository.updatePass(currentUsername,encPass,System.currentTimeMillis()); + } + userService.updatePass(user.getUsername(),passwordEncoder.encode(passVo.getNewPass())); + onlineUserService.logout(tokenProvider.getToken(request)); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java new file mode 100644 index 00000000..409d60ed --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxAccountUtil.java @@ -0,0 +1,126 @@ +package cn.ysk.cashier.utils; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpUtil; +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Data +@Slf4j +@Component +public class WxAccountUtil { + @Value("${wx.ysk.appId}") + private String appId = "wx212769170d2c6b2a"; + @Value("${wx.ysk.secrete}") + private String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0"; + @Value("${wx.ysk.operationMsgTmpId}") + private String operationMsgTmpId ; + + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); + + static { + + linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID"); + linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口"); + linkedHashMap.put("40037","不合法的 template_id"); + linkedHashMap.put("43101","用户未订阅消息"); + linkedHashMap.put("43107","订阅消息能力封禁"); + linkedHashMap.put("43108","并发下发消息给同一个粉丝"); + linkedHashMap.put("45168","命中敏感词"); + linkedHashMap.put("47003","参数错误"); + + } + + public static void main(String[] args) { +// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI"); + } + + public String getRadarQrCode(Integer shopId) { + HashMap req = new HashMap<>(); + req.put("expire_seconds", 300); + req.put("action_name", "QR_STR_SCENE"); + HashMap actionInfo = new HashMap<>(); + HashMap scene = new HashMap<>(); + scene.put("scene_str", "msg" + shopId); + actionInfo.put("scene", scene); + req.put("action_info", actionInfo); + log.info("开始获取公众号二维码, 请求数据: {}", req); + String resp = HttpUtil.post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getAccessToken(), JSONObject.toJSONString(req)); + JSONObject respInfo = JSONObject.parseObject(resp); + log.warn("获取微信公众号二维码结束,响应: {}", resp); + if (!respInfo.containsKey("url")) { + log.warn("获取微信公众号二维码失败,响应: {}", resp); + throw new RuntimeException(resp); + } + return respInfo.getString("url"); + } + + + public String getAccessToken() { + String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete)); + JSONObject respInfo = JSONObject.parseObject(resp); + if (!respInfo.containsKey("access_token")) { + log.warn("公众号获取token失败, 响应内容: {}", resp); + throw new RuntimeException(resp); + } + return respInfo.getString("access_token"); + } + + public JSONObject sendTemplateMsg(String templateId, String toUserOpenId, Map data) { + log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data); + String accessToken = getAccessToken(); + + JSONObject object1=new JSONObject(); + + object1.put("template_id", templateId); + object1.put("touser", toUserOpenId); + object1.put("data",data); + + String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body(); + log.info("微信模板消息发送成功,响应内容:{}",response); + JSONObject resObj=JSONObject.parseObject(response); + if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){ + return resObj; + } + + throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); + } + + @Async + public void sendOperationMsg(List openIds, String userName, String operationDesc) { + openIds.forEach(item -> { + Map data = new HashMap() {{ + put("thing19", new HashMap(){{ + put("value", userName); + }}); + put("thing8", new HashMap(){{ + put("value", operationDesc); + }}); + put("time21", new HashMap(){{ + put("value", DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss")); + }}); + }}; + log.info("开始发送敏感操作消息, 接收用户openId: {}, 操作用户: {}, 操作描述: {}", item.getOpenId(), userName, operationDesc); + try { + sendTemplateMsg(operationMsgTmpId, item.getOpenId(), data); + }catch (Exception e) { + log.error("发送失败, openId: {}, 响应: {}", item.getOpenId(), e.getMessage()); + } + }); + + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMsgUtils.java b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMsgUtils.java new file mode 100644 index 00000000..79d74135 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/utils/WxMsgUtils.java @@ -0,0 +1,58 @@ +package cn.ysk.cashier.utils; + +import cn.ysk.cashier.mybatis.entity.TbShopOpenId; +import cn.ysk.cashier.mybatis.service.TbShopOpenIdService; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@Component +@Slf4j +public class WxMsgUtils { + + private final TbShopOpenIdService tbShopOpenIdService; + + private final RedisUtils redisUtils; + + private final WxAccountUtil wxAccountUtil; + + public WxMsgUtils(TbShopOpenIdService tbShopOpenIdService, RedisUtils redisUtils, WxAccountUtil wxAccountUtil) { + this.tbShopOpenIdService = tbShopOpenIdService; + this.redisUtils = redisUtils; + this.wxAccountUtil = wxAccountUtil; + } + + public void aboardOperationMsg(String operationDesc) { + HttpServletRequest request = RequestHolder.getHttpServletRequest(); + + Object o = redisUtils.get("online-token-"+getToken(request)); + JSONObject jsonObject; + Integer shopId; + String nickName; + if (o != null) { + String jsonString = JSON.toJSONString(o); + jsonObject = JSONObject.parseObject(jsonString); + shopId = (Integer) jsonObject.get("shopId"); + nickName = jsonObject.get("nickName") == null ? "" : jsonObject.get("nickName").toString(); + List openIds = tbShopOpenIdService.lambdaQuery().eq(TbShopOpenId::getShopId, shopId).list(); + log.info("即将开始推送敏感操作消息, 接收推送openId列表: {}", openIds); + String finalNickName = nickName; + wxAccountUtil.sendOperationMsg(openIds, finalNickName, operationDesc); + }else { + log.warn("发送敏感操作预警失败,未获取到登录信息"); + } + } + + public String getToken(HttpServletRequest request) { + final String requestHeader = request.getHeader("Authorization"); + if (requestHeader != null && requestHeader.startsWith("Bearer")) { + return requestHeader.substring(7); + } + return null; + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSaleVO.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSaleVO.java new file mode 100644 index 00000000..667e3ebe --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSaleVO.java @@ -0,0 +1,17 @@ +package cn.ysk.cashier.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TbOrderSaleVO { + private String orderNo; + private Integer num; + private BigDecimal price; + private String status; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java index f2644496..c35b2dbe 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java @@ -14,6 +14,24 @@ public class TbOrderSalesCountByDayVo { private BigDecimal salesAmount; private BigDecimal refAmount; private Long num; + private Integer productId; + private Integer productSkuId; + + public Integer getProductId() { + return productId; + } + + public void setProductId(Integer productId) { + this.productId = productId; + } + + public Integer getProductSkuId() { + return productSkuId; + } + + public void setProductSkuId(Integer productSkuId) { + this.productSkuId = productSkuId; + } public String getProductName() { return productName; @@ -116,6 +134,25 @@ public class TbOrderSalesCountByDayVo { count(); } + public TbOrderSalesCountByDayVo(String productName, String productSkuName, String cateName,String unitName,BigDecimal price, + Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount, Integer productId, Integer productSkuId) { + this.productName = productName; + this.productSkuName = productSkuName; + this.cateName = cateName; + this.unitName = unitName; + this.price = price; + this.salesNum = salesNum; + this.refNum = refNum; + this.salesAmount = salesAmount; + this.refAmount = refAmount; + this.num = num; + this.productId = productId; + this.productSkuId = productSkuId; + count(); + } + + + public void count(){ salesNum=salesNum-refNum; salesAmount=salesAmount.subtract(refAmount); diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index 79bfa777..752a7fc8 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -78,3 +78,9 @@ aliyun: oss: bucketname: cashier-oss endpoint: oss-cn-beijing.aliyuncs.com + +wx: + ysk: + appId: wx212769170d2c6b2a + secrete: 8492a7e8d55bbb1b57f5c8276ea1add0 + operationMsgTmpId: wFdoUG-dUT7bDRHq8bMJD9CF5TjyH9x_uJQgQByZqHg diff --git a/eladmin-system/src/main/resources/mapper/TbShopOpenIdMapper.xml b/eladmin-system/src/main/resources/mapper/TbShopOpenIdMapper.xml new file mode 100644 index 00000000..131b90c7 --- /dev/null +++ b/eladmin-system/src/main/resources/mapper/TbShopOpenIdMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + id,shop_id,open_id, + status,create_time,update_time, + type + + diff --git a/pom.xml b/pom.xml index dc2e1007..4e5d59af 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,8 @@ + + org.springframework.boot