From 14f55cd77189bae10627277a2a3dab9cec5fcada Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 14 十月 2025 18:43:01 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java | 207 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 187 insertions(+), 20 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java
index 14a8778..8f28916 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysGoodsController.java
@@ -6,21 +6,29 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BaseModel;
+import com.ruoyi.common.core.domain.BasePage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.framework.web.service.TokenService;
+import com.ruoyi.system.dto.ExchangeGoodsDto;
import com.ruoyi.system.dto.TErpGoodsUpdateStatusDto;
import com.ruoyi.system.model.*;
+import com.ruoyi.system.query.ExchangeGoodsRecordQuery;
import com.ruoyi.system.query.TSysGoodsExchangeQuery;
import com.ruoyi.system.query.TSysGoodsQuery;
import com.ruoyi.system.service.*;
+import com.ruoyi.system.vo.ExchangeGoodsRecordDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
+import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -40,21 +48,28 @@
private final TokenService tokenService;
private final TCrmSupplierService crmSupplierService;
private final TSysGoodsExchangeService sysGoodsExchangeService;
+ private final TCrmClinicService crmClinicService;
+ private final TCrmClinicPointsService crmClinicPointsService;
+ private final TCrmChangePointsService crmChangePointsService;
@Autowired
- public TSysGoodsController(TokenService tokenService, TSysGoodsService sysGoodsService, TCrmSupplierService crmSupplierService, TSysGoodsExchangeService sysGoodsExchangeService) {
+ public TSysGoodsController(TokenService tokenService, TSysGoodsService sysGoodsService, TCrmSupplierService crmSupplierService, TSysGoodsExchangeService sysGoodsExchangeService, TCrmClinicService crmClinicService, TCrmClinicPointsService crmClinicPointsService, TCrmChangePointsService crmChangePointsService) {
this.sysGoodsService = sysGoodsService;
this.tokenService = tokenService;
this.crmSupplierService = crmSupplierService;
this.sysGoodsExchangeService = sysGoodsExchangeService;
+ this.crmClinicService = crmClinicService;
+ this.crmClinicPointsService = crmClinicPointsService;
+
+ this.crmChangePointsService = crmChangePointsService;
}
/**
* 获取积分商品列表
*/
- @ApiOperation(value = "获取积分商品列表")
+ @ApiOperation(value = "获取积分商品列表--供应商")
@PostMapping(value = "/pageList")
public R<PageInfo<TSysGoods>> pageList(@RequestBody TSysGoodsQuery query) {
@@ -92,8 +107,7 @@
}
-
- @ApiOperation(value = "添加积分商品")
+ @ApiOperation(value = "添加积分商品--供应商")
@PostMapping(value = "/add")
public R<String> add(@RequestBody TSysGoods goods) {
SysUser user = tokenService.getLoginUser().getUser();
@@ -110,7 +124,7 @@
return R.ok();
}
- @ApiOperation(value = "编辑积分商品")
+ @ApiOperation(value = "编辑积分商品--供应商")
@PostMapping(value = "/update")
public R<String> update(@RequestBody TSysGoods goods) {
SysUser user = tokenService.getLoginUser().getUser();
@@ -118,7 +132,7 @@
List<TSysGoodsExchange> list = sysGoodsExchangeService.list(new LambdaQueryWrapper<TSysGoodsExchange>().eq(TSysGoodsExchange::getGoodsId, goods.getId()));
int sum = list.stream().mapToInt(TSysGoodsExchange::getGoodsCount).sum();
- if(goods.getGoodsTotal()< sum){
+ if (goods.getGoodsTotal() < sum) {
return R.fail("商品总数不能小于已兑换数量");
}
if (roleType == 4) {
@@ -134,8 +148,7 @@
}
-
- @ApiOperation(value = "删除积分商品")
+ @ApiOperation(value = "删除积分商品--供应商")
@DeleteMapping(value = "/delete/{id}")
public R<String> delete(@PathVariable String id) {
SysUser user = tokenService.getLoginUser().getUser();
@@ -146,9 +159,9 @@
.eq(TCrmSupplier::getUserId, user.getUserId())
.last("LIMIT 1"));
TSysGoods goods = sysGoodsService.getById(id);
- if(goods.getSupplierId().equals(crmSupplier.getId())){
+ if (goods.getSupplierId().equals(crmSupplier.getId())) {
sysGoodsService.removeById(id);
- }else {
+ } else {
return R.fail("没有权限");
}
}
@@ -156,7 +169,7 @@
}
- @ApiOperation(value = "积分商品 上下架")
+ @ApiOperation(value = "积分商品 上下架--供应商")
@PostMapping(value = "/updateStatus")
public R<String> updateStatus(@RequestBody @Valid TErpGoodsUpdateStatusDto dto) {
SysUser user = tokenService.getLoginUser().getUser();
@@ -167,10 +180,10 @@
.eq(TCrmSupplier::getUserId, user.getUserId())
.last("LIMIT 1"));
TSysGoods goods = sysGoodsService.getById(dto.getId());
- if(goods.getSupplierId().equals(crmSupplier.getId())){
+ if (goods.getSupplierId().equals(crmSupplier.getId())) {
goods.setStatus(dto.getState());
sysGoodsService.updateById(goods);
- }else {
+ } else {
return R.fail("没有权限");
}
}
@@ -179,18 +192,18 @@
// 获取兑换记录
- @ApiOperation(value = "获取兑换记录")
+ @ApiOperation(value = "获取兑换记录--供应商")
@PostMapping(value = "/getExchangeRecord")
public R<PageInfo<TSysGoodsExchange>> getExchangeRecord(@RequestBody @Valid TSysGoodsExchangeQuery query) {
PageInfo<TSysGoodsExchange> page = new PageInfo<>(query.getPageNum(), query.getPageSize());
LambdaQueryWrapper<TSysGoodsExchange> wrapper = new LambdaQueryWrapper<TSysGoodsExchange>().eq(TSysGoodsExchange::getGoodsId, query.getId());
- if(query.getClinicName()!=null && !query.getClinicName().isEmpty()){
+ if (query.getClinicName() != null && !query.getClinicName().isEmpty()) {
wrapper.like(TSysGoodsExchange::getClinicName, query.getClinicName());
}
- if(query.getTime()!=null && !query.getTime().isEmpty()){
- wrapper.between(TSysGoodsExchange::getCreateTime, query.getTime().split(" - ")[0]+ " 00:00:00", query.getTime().split(" - ")[1]+ " 23:59:59");
+ if (query.getTime() != null && !query.getTime().isEmpty()) {
+ wrapper.between(TSysGoodsExchange::getCreateTime, query.getTime().split(" - ")[0] + " 00:00:00", query.getTime().split(" - ")[1] + " 23:59:59");
}
- if(query.getStatus()!=null){
+ if (query.getStatus() != null) {
wrapper.eq(TSysGoodsExchange::getStatus, query.getStatus());
}
wrapper.orderByDesc(BaseModel::getCreateTime);
@@ -199,11 +212,11 @@
}
// 获取兑换记录
- @ApiOperation(value = "发货")
+ @ApiOperation(value = "发货--供应商")
@PostMapping(value = "/sendGoods")
public R<?> sendGoods(@RequestBody @Valid TSysGoodsExchange exchange) {
TSysGoodsExchange exchange1 = sysGoodsExchangeService.getById(exchange.getId());
- if(exchange1.getStatus()==2){
+ if (exchange1.getStatus() == 2) {
return R.fail("该订单已发货");
}
exchange1.setStatus(2);
@@ -212,5 +225,159 @@
return R.ok();
}
+
+ /**
+ * 获取积分商品列表
+ */
+ @ApiOperation(value = "获取积分商品列表--诊所")
+ @PostMapping(value = "/pageListClinic")
+ public R<HashMap<String, Object>> pageListClinic(@RequestBody TSysGoodsQuery query) {
+ PageInfo<TSysGoods> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
+ LambdaQueryWrapper<TSysGoods> tSysGoodsLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ tSysGoodsLambdaQueryWrapper.eq(TSysGoods::getStatus, 1);
+ if (query.getGoodsName() != null && !query.getGoodsName().isEmpty()) {
+ tSysGoodsLambdaQueryWrapper.like(TSysGoods::getGoodsName, query.getGoodsName());
+ }
+ tSysGoodsLambdaQueryWrapper.orderByDesc(BaseModel::getCreateTime);
+
+ Page<TSysGoods> page = sysGoodsService.page(pageInfo, tSysGoodsLambdaQueryWrapper);
+ List<TSysGoods> records = page.getRecords();
+ if (!records.isEmpty()) {
+ List<TSysGoodsExchange> list = sysGoodsExchangeService.list(new LambdaQueryWrapper<TSysGoodsExchange>().in(TSysGoodsExchange::getGoodsId, records.stream().map(TSysGoods::getId).collect(Collectors.toList())));
+ records.forEach(item -> {
+ item.setExchangeQuantity(list.stream().filter(item1 -> item1.getGoodsId().equals(item.getId())).mapToInt(TSysGoodsExchange::getGoodsCount).sum());
+ item.setSurplusQuantity(item.getGoodsTotal() - item.getExchangeQuantity());
+ });
+ }
+ pageInfo.setRecords(records);
+ HashMap<String, Object> map = new HashMap<>();
+ map.put("data", pageInfo);
+
+ // 获取我的可用积分
+ map.put("total", sysGoodsService.count(tSysGoodsLambdaQueryWrapper));
+ SysUser user = tokenService.getLoginUser().getUser();
+ Integer roleType = user.getRoleType();
+ if (roleType == 5) {
+ // 诊所
+ TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+ .eq(TCrmClinic::getUserId, user.getUserId())
+ .last("LIMIT 1"));
+ List<TCrmClinicPoints> list = crmClinicPointsService.list(new LambdaQueryWrapper<TCrmClinicPoints>().eq(TCrmClinicPoints::getClinicId, crmClinic.getId()).ge(TCrmClinicPoints::getExpireTime, new Date()).last(" and points > use_points"));
+ map.put("myPoints", list.stream().mapToInt(item -> item.getPoints() - item.getUsePoints()).sum());
+ }
+ return R.ok(map);
+ }
+
+ /**
+ * 获取积分商品详情
+ */
+ @ApiOperation(value = "获取积分商品列表--详情")
+ @GetMapping(value = "/detail/{id}")
+ public R<TSysGoods> detail(@PathVariable String id) {
+ TSysGoods goods = sysGoodsService.getById(id);
+ return R.ok(goods);
+ }
+
+
+ /**
+ * 兑换商品
+ */
+ @ApiOperation(value = "兑换商品--诊所")
+ @PostMapping(value = "/exchangeGoods")
+ public R<?> exchangeGoods(@RequestBody @Valid ExchangeGoodsDto dto) {
+ SysUser user = tokenService.getLoginUser().getUser();
+ Integer roleType = user.getRoleType();
+ if (roleType == 5) {
+ // 诊所
+ TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+ .eq(TCrmClinic::getUserId, user.getUserId())
+ .last("LIMIT 1"));
+ sysGoodsService.exchangeGoods(crmClinic, dto);
+ return R.ok();
+ }
+ return R.fail("请选择正确的角色");
+ }
+
+
+ /**
+ * 兑换商品记录
+ */
+ @ApiOperation(value = "兑换商品记录--诊所")
+ @PostMapping(value = "/exchangeGoodsRecord")
+ public R<?> exchangeGoodsRecord(@RequestBody ExchangeGoodsRecordQuery query) {
+ SysUser user = tokenService.getLoginUser().getUser();
+ Integer roleType = user.getRoleType();
+ if (roleType == 5) {
+ // 诊所
+ TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+ .eq(TCrmClinic::getUserId, user.getUserId())
+ .last("LIMIT 1"));
+
+ LambdaQueryWrapper<TSysGoodsExchange> eq = new LambdaQueryWrapper<TSysGoodsExchange>().eq(TSysGoodsExchange::getClinicId, crmClinic.getId());
+ if (query.getName() != null && !query.getName().isEmpty()) {
+ eq.like(TSysGoodsExchange::getGoodsName, query.getName());
+ }
+ eq.orderByDesc(BaseModel::getCreateTime);
+
+
+ PageInfo<TSysGoodsExchange> page = sysGoodsExchangeService.page(new PageInfo<>(query.getPageNum(), query.getPageSize()), eq);
+ return R.ok(page);
+ }
+ return R.fail("请选择正确的角色");
+ }
+
+ /**
+ * 兑换商品记录
+ */
+ @ApiOperation(value = "兑换商品记录详情--诊所")
+ @GetMapping(value = "/exchangeGoodsRecordDetail/{id}")
+ public R<ExchangeGoodsRecordDetailVo> exchangeGoodsRecord(@PathVariable String id) {
+ SysUser user = tokenService.getLoginUser().getUser();
+ Integer roleType = user.getRoleType();
+ if (roleType == 5) {
+ // 诊所
+ TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+ .eq(TCrmClinic::getUserId, user.getUserId())
+ .last("LIMIT 1"));
+ TSysGoodsExchange exchangeServiceById = sysGoodsExchangeService.getById(id);
+ if (exchangeServiceById.getClinicId().equals(crmClinic.getId())) {
+ ExchangeGoodsRecordDetailVo vo = new ExchangeGoodsRecordDetailVo();
+ BeanUtils.copyProperties(exchangeServiceById, vo);
+
+ String goodsId = vo.getGoodsId();
+ TSysGoods sysGoods = sysGoodsService.getById(goodsId);
+ vo.setGoodsDetail(sysGoods.getGoodsDetail());
+ vo.setGoodsCover(sysGoods.getGoodsCover());
+
+
+ return R.ok(vo);
+ }
+ }
+ return R.fail("请选择正确的角色");
+ }
+
+
+ /**
+ * 兑换商品记录
+ */
+ @ApiOperation(value = "积分变更记录--诊所")
+ @PostMapping(value = "/pointsRecordDetail")
+ public R<PageInfo<TCrmChangePoints>> pointsRecordDetail(@RequestBody BasePage page) {
+ SysUser user = tokenService.getLoginUser().getUser();
+ Integer roleType = user.getRoleType();
+ if (roleType == 5) {
+ // 诊所
+ TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+ .eq(TCrmClinic::getUserId, user.getUserId())
+ .last("LIMIT 1"));
+
+ PageInfo<TCrmChangePoints> page1 = crmChangePointsService.page(new PageInfo<>(page.getPageNum(), page.getPageSize()), new LambdaQueryWrapper<TCrmChangePoints>().eq(TCrmChangePoints::getBranchSalespersonId, crmClinic.getId()).eq(TCrmChangePoints::getUserType, 3).orderByDesc(BaseModel::getCreateTime));
+
+ return R.ok(page1);
+ }
+ return R.fail("请选择正确的角色");
+ }
+
+
}
--
Gitblit v1.7.1