Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/dev' into dev

linbl 2 rokov pred
rodič
commit
6df903ddf2

+ 13 - 0
sp-core/sp-base/src/main/java/com/pj/current/dto/APPLoginUserInfo.java

@@ -0,0 +1,13 @@
+package com.pj.current.dto;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+@Data
+@Accessors(chain = true)
+public class APPLoginUserInfo implements Serializable {
+    private Long loginId;
+    private String loginName;
+}

+ 24 - 0
sp-core/sp-base/src/main/java/com/pj/current/satoken/StpAPPUserUtil.java

@@ -4,6 +4,11 @@ import cn.dev33.satoken.SaManager;
 import cn.dev33.satoken.stp.SaTokenInfo;
 import cn.dev33.satoken.stp.StpLogic;
 import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.pj.current.dto.APPLoginUserInfo;
+import com.pj.current.dto.PCLoginUserInfo;
+import com.pj.utils.cache.RedisUtil;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -44,5 +49,24 @@ public class StpAPPUserUtil {
     public static boolean isLogin() {
         return stpLogic.isLogin();
     }
+    /**
+     * 缓存登录用户信息
+     * @param info
+     */
+    public static void cachePcLoginInfo(PCLoginUserInfo info){
+        String loginId= StpUtil.getLoginIdAsString();
+        RedisUtil.set("app:"+loginId, JSONUtil.toJsonStr(info));
+    }
+
+    /**
+     * 获取登录信息
+     * @return
+     */
+    public static APPLoginUserInfo getAPPLoginInfo(){
+        String key="app:"+StpUtil.getLoginIdAsString();
+        String info=RedisUtil.get(key);
+        return StrUtil.isNotEmpty(info)?new APPLoginUserInfo():JSONUtil.toBean(info,APPLoginUserInfo.class);
+    }
+
 
 }

+ 55 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_goods_transit/GoodsTransitAppController.java

@@ -0,0 +1,55 @@
+package com.pj.tb_goods_transit;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.pj.project4sp.SP;
+import com.pj.tb_goods_transit.param.TransactionGoodsParam;
+import com.pj.utils.sg.AjaxJson;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * app端用户添加/上架/下架商品
+ * @Author Mechrevo
+ * @Date 2023 07 27 09 31
+ **/
+@RestController
+@RequestMapping("/app/TbGoodsTransit/")
+public class GoodsTransitAppController {
+
+    @Autowired
+    private TbGoodsTransitService tbGoodsTransitService;
+
+
+    /** app端用户添加商品 */
+    @RequestMapping("transactionGoods")
+//    @SaCheckPermission(TbGoodsTransit.PERMISSION_CODE_ADD)
+    public AjaxJson transactionGoods(@Validated @RequestBody TransactionGoodsParam t){
+        boolean goods = tbGoodsTransitService.transactionGoods(t);
+        if(goods) return AjaxJson.getSuccess("商品添加成功!");
+        return AjaxJson.getError("商品添加失败!");
+    }
+
+    /** app端用户上架/下架商品 */
+    @RequestMapping("UpOrDownGoods")
+//    @SaCheckPermission(TbGoodsTransit.PERMISSION_CODE_ADD)
+    public AjaxJson UpOrDownGoods(@RequestParam("goodsTransitId")Long goodsTransitId,
+                                  @RequestParam("goodsStatus")Integer goodsStatus){
+        boolean goods = tbGoodsTransitService.UpOrDownGoods(goodsTransitId,goodsStatus);
+        if(goods){
+            if(!goodsStatus.toString().trim().equals("")){
+                if(goodsStatus == 1){
+                    return AjaxJson.getSuccess("商品上架成功!");
+                }
+                return AjaxJson.getSuccess("商品下架成功!");
+            }
+        }
+        return AjaxJson.getError("商品操作失败!");
+    }
+
+
+
+}

+ 31 - 23
sp-service/level-one-server/src/main/java/com/pj/tb_goods_transit/MethodGoodsTransitService.java

@@ -63,56 +63,64 @@ public class MethodGoodsTransitService {
 
             HSSFCell cell6 = row.getCell(6);
             if (cell6 != null && (cell6.getCellType() == CellType.NUMERIC || cell6.getCellType() == CellType.FORMULA))
-                tbGoodsTransit.setPrice(cell6.getNumericCellValue());
+                tbGoodsTransit.setNetWeight(cell6.getNumericCellValue());
 
-            if(row.getCell(7) != null && !row.getCell(7).toString().trim().equals(""))
-                tbGoodsTransit.setDeclareOdd(row.getCell(7).getStringCellValue());
+            HSSFCell cell7 = row.getCell(7);
+            if (cell7 != null && (cell7.getCellType() == CellType.NUMERIC || cell7.getCellType() == CellType.FORMULA))
+                tbGoodsTransit.setGrossWeight(cell7.getNumericCellValue());
 
-            if(row.getCell(8) != null && !row.getCell(8).toString().trim().equals(""))
-                tbGoodsTransit.setPlaceOrigin(row.getCell(8).getStringCellValue());
+            HSSFCell cell8 = row.getCell(8);
+            if (cell8 != null && (cell8.getCellType() == CellType.NUMERIC || cell8.getCellType() == CellType.FORMULA))
+                tbGoodsTransit.setPrice(cell8.getNumericCellValue());
 
             if(row.getCell(9) != null && !row.getCell(9).toString().trim().equals(""))
-                tbGoodsTransit.setDescription(row.getCell(9).getStringCellValue()   );
+                tbGoodsTransit.setDeclareOdd(row.getCell(9).getStringCellValue());
 
-            HSSFCell cell9 = row.getCell(10);
+            if(row.getCell(10) != null && !row.getCell(10).toString().trim().equals(""))
+                tbGoodsTransit.setPlaceOrigin(row.getCell(10).getStringCellValue());
+
+            if(row.getCell(11) != null && !row.getCell(11).toString().trim().equals(""))
+                tbGoodsTransit.setDescription(row.getCell(11).getStringCellValue()   );
+
+            HSSFCell cell9 = row.getCell(12);
             if (cell9 != null && (cell9.getCellType() == CellType.NUMERIC || cell9.getCellType() == CellType.FORMULA))
                 tbGoodsTransit.setStock((int)cell9.getNumericCellValue());
 
-            HSSFCell cell10 = row.getCell(11);
+            HSSFCell cell10 = row.getCell(13);
             if (cell10 != null && (cell10.getCellType() == CellType.NUMERIC || cell10.getCellType() == CellType.FORMULA))
                 tbGoodsTransit.setGoodsStatus((int)cell10.getNumericCellValue());
 
-            HSSFCell cell11 = row.getCell(12);
+            HSSFCell cell11 = row.getCell(14);
             if (cell11 != null && (cell11.getCellType() == CellType.NUMERIC || cell11.getCellType() == CellType.FORMULA))
                 tbGoodsTransit.setAuditStatus((int) cell11.getNumericCellValue());
 
-            HSSFCell cell2 = row.getCell(13);
+            HSSFCell cell2 = row.getCell(15);
             if (cell2 != null && cell2.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell2))
-                if(row.getCell(13) != null && !row.getCell(13).toString().trim().equals(""))
+                if(row.getCell(15) != null && !row.getCell(15).toString().trim().equals(""))
                     tbGoodsTransit.setAuditTime(cell2.getDateCellValue());
 
-            if(row.getCell(14) != null && !row.getCell(14).toString().trim().equals(""))
-                tbGoodsTransit.setRemark(row.getCell(14).getStringCellValue());
+            if(row.getCell(16) != null && !row.getCell(16).toString().trim().equals(""))
+                tbGoodsTransit.setRemark(row.getCell(16).getStringCellValue());
 
             //公共字段
-            HSSFCell cell4 = row.getCell(15);
+            HSSFCell cell4 = row.getCell(17);
             if (cell4 != null && cell4.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell4)) {
                 tbGoodsTransit.setCreateTime(cell4.getDateCellValue());
             }
 
-            if(row.getCell(16) != null && !row.getCell(16).toString().trim().equals(""))
-                tbGoodsTransit.setCreateBy(row.getCell(16).getStringCellValue());
-
-            if(row.getCell(17) != null && !row.getCell(17).toString().trim().equals(""))
-                tbGoodsTransit.setCreateName(row.getCell(17).getStringCellValue());
-
             if(row.getCell(18) != null && !row.getCell(18).toString().trim().equals(""))
-                tbGoodsTransit.setUpdateBy(row.getCell(18).getStringCellValue());
+                tbGoodsTransit.setCreateBy(row.getCell(18).getStringCellValue());
 
             if(row.getCell(19) != null && !row.getCell(19).toString().trim().equals(""))
-                tbGoodsTransit.setUpdateName(row.getCell(19).getStringCellValue());
+                tbGoodsTransit.setCreateName(row.getCell(19).getStringCellValue());
+
+            if(row.getCell(20) != null && !row.getCell(20).toString().trim().equals(""))
+                tbGoodsTransit.setUpdateBy(row.getCell(20).getStringCellValue());
+
+            if(row.getCell(21) != null && !row.getCell(21).toString().trim().equals(""))
+                tbGoodsTransit.setUpdateName(row.getCell(21).getStringCellValue());
 
-            HSSFCell cell3 = row.getCell(20);
+            HSSFCell cell3 = row.getCell(22);
             if (cell3 != null && cell3.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell3)) {
                 tbGoodsTransit.setUpdateTime(cell3.getDateCellValue());
             }

+ 17 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_goods_transit/TbGoodsTransit.java

@@ -74,7 +74,23 @@ public class TbGoodsTransit extends Model<TbGoodsTransit> implements Serializabl
 	/**
 	 * 商品单位(吨、kg、个、柜) 
 	 */
-	private String goodsUnits;	
+	private String goodsUnits;
+
+	/** 互市区名称 */
+	private String tradeAreaName;
+
+	/** 互市区ID */
+	private Long tradeAreaId;
+
+	/**
+	 * 净重
+	 */
+	private Double netWeight;
+
+	/**
+	 * 毛重
+	 */
+	private Double grossWeight;
 
 	/**
 	 * 商品价格 

+ 104 - 17
sp-service/level-one-server/src/main/java/com/pj/tb_goods_transit/TbGoodsTransitService.java

@@ -7,18 +7,30 @@ import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.List;
 
+import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.pj.api.client.admin.AdminInterface;
+import com.pj.api.dto.AppUserDto;
+import com.pj.current.dto.APPLoginUserInfo;
+import com.pj.current.dto.PCLoginUserInfo;
+import com.pj.current.satoken.StpAPPUserUtil;
+import com.pj.current.satoken.StpUserUtil;
 import com.pj.enummj.AuditStatus;
 import com.pj.enummj.DeleteStatus;
 import com.pj.enummj.GoodsStatus;
 import com.pj.tb_enterprise.TbEnterprise;
 import com.pj.tb_goods.TbGoods;
+import com.pj.tb_goods.TbGoodsMapper;
 import com.pj.tb_goods_transit.param.JudgeTransitParam;
+import com.pj.tb_goods_transit.param.TransactionGoodsParam;
+import com.pj.tb_trade_area.TbTradeArea;
+import com.pj.tb_trade_area.TbTradeAreaMapper;
 import com.pj.utils.so.SoMap;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -40,9 +52,17 @@ public class TbGoodsTransitService extends ServiceImpl<TbGoodsTransitMapper, TbG
 	/** 底层 Mapper 对象 */
 	@Autowired
 	TbGoodsTransitMapper tbGoodsTransitMapper;
-
+	/** 方法抽取,代码优化 */
 	@Autowired
 	private MethodGoodsTransitService methodGoodsTransitService;
+	/** 监管产品mapper */
+	@Autowired
+	private TbGoodsMapper tbGoodsMapper;
+	@Autowired
+	private AdminInterface adminInterface;
+	/** 互市区mapper */
+	@Autowired
+	private TbTradeAreaMapper tbTradeAreaMapper;
 
 	/** 增 */
 	void add(TbGoodsTransit t){
@@ -113,6 +133,69 @@ public class TbGoodsTransitService extends ServiceImpl<TbGoodsTransitMapper, TbG
 		return "已完成 " + count + "条 数据审核!";
 	}
 
+	/** app端 - 添加需要交易的商品 */
+	public boolean transactionGoods(TransactionGoodsParam transactionGoodsParam){
+		//判断商品的净重毛重
+		Double netWeight = transactionGoodsParam.getNetWeight();
+		Double grossWeight = transactionGoodsParam.getGrossWeight();
+		if(netWeight > grossWeight){
+			throw new RuntimeException("净重超过了毛重,请检查输入。");
+		}
+		//获取当前登录人 todo:生产阶段需打开该注释
+//		StpUserUtil.checkLogin();
+//		long loginIdAsLong = StpUserUtil.getLoginIdAsLong();
+		Long loginIdAsLong = 4L;//测试阶段,写死appUser的id
+		AppUserDto appUserById = adminInterface.getAppUserById(loginIdAsLong);
+		if(appUserById == null)throw new RuntimeException("账户登录信息已失效!请重新登录");
+		//取出申报商品ID
+		Long id = transactionGoodsParam.getId();
+		//查询监管产品
+		TbGoods tbGoods = tbGoodsMapper.selectById(id);
+		if(tbGoods == null)throw new RuntimeException("该产品暂未录入监管列表!");
+		//查询互市区
+		TbTradeArea tbTradeArea = tbTradeAreaMapper.selectById(transactionGoodsParam.getTradeAreaId());
+		if(tbTradeArea == null)throw new RuntimeException("互市区不存在!");
+		//执行保存
+		TbGoodsTransit tbGoodsTransit = new TbGoodsTransit();
+		BeanUtils.copyProperties(transactionGoodsParam,tbGoodsTransit);
+		//获取并保存当前商品基本信息
+		tbGoodsTransit.setTradeAreaName(tbTradeArea.getName());
+		tbGoodsTransit.setGoodsName(tbGoods.getName());
+		tbGoodsTransit.setDescription(tbGoods.getRemark());
+		tbGoodsTransit.setPlaceOrigin(tbGoods.getSource());
+		tbGoodsTransit.setGoodsUnits(tbGoods.getUnit());
+		tbGoodsTransit.setGoodsType(tbGoods.getTypeNames());
+		//设置默认信息
+		tbGoodsTransit.setAuditStatus(1);//默认已过审
+		tbGoodsTransit.setGoodsStatus(1);//默认已上架
+		//设置基本信息
+		tbGoodsTransit.setCreateTime(new Date());
+		tbGoodsTransit.setCreateBy(loginIdAsLong + "");
+		tbGoodsTransit.setCreateName(appUserById.getName());
+		tbGoodsTransit.setDeleteStatus(1);
+		//执行保存
+		int insert = tbGoodsTransitMapper.insert(tbGoodsTransit);
+		if(insert == 1)return true;
+		return false;
+	}
+
+	/** app端 - 商户自行选择上架/下架商品 */
+	boolean UpOrDownGoods(Long goodsTransitId , Integer goodsStatus){
+		//获取当前登陆人
+		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
+		if(appLoginInfo == null)throw new RuntimeException("当前登陆人不存在!");
+		TbGoodsTransit tbGoodsTransit = tbGoodsTransitMapper.selectById(goodsTransitId);
+		if(tbGoodsTransit == null)throw new RuntimeException("该商品状态异常或不存在!");
+		tbGoodsTransit.setGoodsStatus(goodsStatus == null? 0 : goodsStatus);
+		//设置基本属性
+		tbGoodsTransit.setUpdateTime(new Date());
+		tbGoodsTransit.setUpdateBy(appLoginInfo.getLoginId() + "");
+		tbGoodsTransit.setUpdateName(appLoginInfo.getLoginName());
+		//执行保存
+		int updateById = tbGoodsTransitMapper.updateById(tbGoodsTransit);
+		if(updateById == 1)return true;
+		return false;
+	}
 
 	/**
 	 * 导入
@@ -169,22 +252,24 @@ public class TbGoodsTransitService extends ServiceImpl<TbGoodsTransitMapper, TbG
 		row.createCell(3).setCellValue("商品类型");
 		row.createCell(4).setCellValue("商品名称");
 		row.createCell(5).setCellValue("商品单位");
-		row.createCell(6).setCellValue("商品价格");
-		row.createCell(7).setCellValue("海关申报单号");
-		row.createCell(8).setCellValue("产地(国家)");
-		row.createCell(9).setCellValue("商品描述");
-		row.createCell(10).setCellValue("库存数量");
-		row.createCell(11).setCellValue("商品状态");
-		row.createCell(12).setCellValue("审核状态");
-		row.createCell(13).setCellValue("审核时间");
-		row.createCell(14).setCellValue("审核意见");
-		row.createCell(15).setCellValue("创建时间");
-		row.createCell(16).setCellValue("创建人编号");
-		row.createCell(17).setCellValue("创建人名称");
-		row.createCell(18).setCellValue("更新时间");
-		row.createCell(19).setCellValue("更新人编号");
-		row.createCell(20).setCellValue("更新人名称");
-		row.createCell(21).setCellValue("删除状态");
+		row.createCell(6).setCellValue("净重");
+		row.createCell(7).setCellValue("毛重");
+		row.createCell(8).setCellValue("商品价格");
+		row.createCell(9).setCellValue("海关申报单号");
+		row.createCell(10).setCellValue("产地(国家)");
+		row.createCell(11).setCellValue("商品描述");
+		row.createCell(12).setCellValue("库存数量");
+		row.createCell(13).setCellValue("商品状态");
+		row.createCell(14).setCellValue("审核状态");
+		row.createCell(15).setCellValue("审核时间");
+		row.createCell(16).setCellValue("审核意见");
+		row.createCell(17).setCellValue("创建时间");
+		row.createCell(18).setCellValue("创建人编号");
+		row.createCell(19).setCellValue("创建人名称");
+		row.createCell(20).setCellValue("更新时间");
+		row.createCell(21).setCellValue("更新人编号");
+		row.createCell(22).setCellValue("更新人名称");
+		row.createCell(23).setCellValue("删除状态");
 
 		//定义计数器
 		int count = 0;
@@ -197,6 +282,8 @@ public class TbGoodsTransitService extends ServiceImpl<TbGoodsTransitMapper, TbG
 			sheetRow.createCell(3).setCellValue((selectedList.get(i).getGoodsType() + "").equals("null")? "": selectedList.get(i).getGoodsType() + "");
 			sheetRow.createCell(4).setCellValue((selectedList.get(i).getGoodsName() + "").equals("null")? "": selectedList.get(i).getGoodsName() + "");
 			sheetRow.createCell(5).setCellValue((selectedList.get(i).getGoodsUnits() + "").equals("null")? "": selectedList.get(i).getGoodsUnits() + "");
+			sheetRow.createCell(5).setCellValue((selectedList.get(i).getNetWeight() + "").equals("null")? "": selectedList.get(i).getNetWeight() + "");
+			sheetRow.createCell(5).setCellValue((selectedList.get(i).getGrossWeight() + "").equals("null")? "": selectedList.get(i).getGrossWeight() + "");
 			sheetRow.createCell(6).setCellValue((selectedList.get(i).getPrice() + "").equals("null")? "": selectedList.get(i).getPrice() + "");
 			sheetRow.createCell(6).setCellValue((selectedList.get(i).getDeclareOdd() + "").equals("null")? "": selectedList.get(i).getDeclareOdd() + "");
 			sheetRow.createCell(7).setCellValue((selectedList.get(i).getPlaceOrigin() + "").equals("null")? "": selectedList.get(i).getPlaceOrigin() + "");

+ 50 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_goods_transit/param/TransactionGoodsParam.java

@@ -0,0 +1,50 @@
+package com.pj.tb_goods_transit.param;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @Author Mechrevo
+ * @Date 2023 07 27 09 35
+ **/
+@AllArgsConstructor
+@Data
+@NoArgsConstructor
+public class TransactionGoodsParam {
+
+    /** 海关申报单号 */
+    private String declareOdd;
+
+    /** 互市区ID */
+    @NotNull
+    private Long tradeAreaId;
+
+    /** 价格 */
+    private Double price;
+
+    /** 净重 */
+    private Double netWeight;
+
+    /** 毛重 */
+    private Double grossWeight;
+
+    /** 数量 */
+    private Integer stock;
+
+    /** 监管商品的ID */
+    @NotNull
+    private Long id;
+
+    /** 当前添加商品的商户id */
+    private String merchantId;
+
+    /** 当前添加商品的商户名称 */
+    private String merchantName;
+
+
+
+}