浏览代码

feat:商品进销存

Joburgess 4 年之前
父节点
当前提交
ebd654142c

+ 17 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsProcurementDao.java

@@ -0,0 +1,17 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.ym.mec.biz.dal.entity.GoodsProcurement;
+import com.ym.mec.common.dal.BaseDAO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+public interface GoodsProcurementDao extends BaseDAO<Long, GoodsProcurement> {
+
+    int batchInsert(@Param("goodsProcurements") List<GoodsProcurement> goodsProcurements);
+
+    List<GoodsProcurement> queryGoodsProcurements(Map<String, Object> params);
+    int countGoodsProcurements(Map<String, Object> params);
+
+}

+ 147 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/GoodsProcurement.java

@@ -0,0 +1,147 @@
+package com.ym.mec.biz.dal.entity;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+/**
+ * 对应数据库表(goods_procurement):
+ */
+public class GoodsProcurement {
+
+	/**  */
+	private Long id;
+	
+	/** 商品编号 */
+	private Integer goodsId;
+	
+	/** 商品分类 */
+	private Integer goodsCategoryId;
+	
+	/** 进货渠道 */
+	private String supplyChannel;
+	
+	/** 采购价一 */
+	private java.math.BigDecimal discountPrice;
+	
+	/** 采购价二 */
+	private java.math.BigDecimal agreeCostPrice;
+	
+	/** 总进货数量 */
+	private Integer totalQuantity;
+	
+	/** 税务数量 */
+	private Integer taxQuantity;
+	
+	/** 进货人编号 */
+	private Integer operatorId;
+
+	/** 批次号 */
+	private String batchNo;
+	
+	/**  */
+	private java.util.Date createTime;
+	
+	/**  */
+	private java.util.Date updateTime;
+	
+	public void setId(Long id){
+		this.id = id;
+	}
+	
+	public Long getId(){
+		return this.id;
+	}
+			
+	public void setGoodsId(Integer goodsId){
+		this.goodsId = goodsId;
+	}
+	
+	public Integer getGoodsId(){
+		return this.goodsId;
+	}
+			
+	public void setGoodsCategoryId(Integer goodsCategoryId){
+		this.goodsCategoryId = goodsCategoryId;
+	}
+	
+	public Integer getGoodsCategoryId(){
+		return this.goodsCategoryId;
+	}
+			
+	public void setSupplyChannel(String supplyChannel){
+		this.supplyChannel = supplyChannel;
+	}
+	
+	public String getSupplyChannel(){
+		return this.supplyChannel;
+	}
+			
+	public void setDiscountPrice(java.math.BigDecimal discountPrice){
+		this.discountPrice = discountPrice;
+	}
+	
+	public java.math.BigDecimal getDiscountPrice(){
+		return this.discountPrice;
+	}
+			
+	public void setAgreeCostPrice(java.math.BigDecimal agreeCostPrice){
+		this.agreeCostPrice = agreeCostPrice;
+	}
+	
+	public java.math.BigDecimal getAgreeCostPrice(){
+		return this.agreeCostPrice;
+	}
+			
+	public void setTotalQuantity(Integer totalQuantity){
+		this.totalQuantity = totalQuantity;
+	}
+	
+	public Integer getTotalQuantity(){
+		return this.totalQuantity;
+	}
+			
+	public void setTaxQuantity(Integer taxQuantity){
+		this.taxQuantity = taxQuantity;
+	}
+	
+	public Integer getTaxQuantity(){
+		return this.taxQuantity;
+	}
+			
+	public void setOperatorId(Integer operatorId){
+		this.operatorId = operatorId;
+	}
+	
+	public Integer getOperatorId(){
+		return this.operatorId;
+	}
+
+	public String getBatchNo() {
+		return batchNo;
+	}
+
+	public void setBatchNo(String batchNo) {
+		this.batchNo = batchNo;
+	}
+
+	public void setCreateTime(java.util.Date createTime){
+		this.createTime = createTime;
+	}
+	
+	public java.util.Date getCreateTime(){
+		return this.createTime;
+	}
+			
+	public void setUpdateTime(java.util.Date updateTime){
+		this.updateTime = updateTime;
+	}
+	
+	public java.util.Date getUpdateTime(){
+		return this.updateTime;
+	}
+			
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this);
+	}
+
+}

+ 42 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/GoodsProcurementQueryInfo.java

@@ -0,0 +1,42 @@
+package com.ym.mec.biz.dal.page;
+
+import com.ym.mec.common.page.QueryInfo;
+
+import java.util.Date;
+
+/**
+ * @Author Joburgess
+ * @Date 2020.10.09
+ */
+public class GoodsProcurementQueryInfo extends QueryInfo {
+
+    private Integer goodsId;
+
+    private String enterStorageStartTime;
+
+    private String enterStorageEndTime;
+
+    public String getEnterStorageStartTime() {
+        return enterStorageStartTime;
+    }
+
+    public void setEnterStorageStartTime(String enterStorageStartTime) {
+        this.enterStorageStartTime = enterStorageStartTime;
+    }
+
+    public String getEnterStorageEndTime() {
+        return enterStorageEndTime;
+    }
+
+    public void setEnterStorageEndTime(String enterStorageEndTime) {
+        this.enterStorageEndTime = enterStorageEndTime;
+    }
+
+    public Integer getGoodsId() {
+        return goodsId;
+    }
+
+    public void setGoodsId(Integer goodsId) {
+        this.goodsId = goodsId;
+    }
+}

+ 29 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsProcurementService.java

@@ -0,0 +1,29 @@
+package com.ym.mec.biz.service;
+
+import com.ym.mec.biz.dal.entity.GoodsProcurement;
+import com.ym.mec.biz.dal.page.GoodsProcurementQueryInfo;
+import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.QueryInfo;
+import com.ym.mec.common.service.BaseService;
+
+public interface GoodsProcurementService extends BaseService<Long, GoodsProcurement> {
+
+    /**
+     * @describe 分页查询进货清单
+     * @author Joburgess
+     * @date 2020.10.09
+     * @param queryInfo:
+     * @return com.ym.mec.common.page.PageInfo<com.ym.mec.biz.dal.entity.GoodsProcurement>
+     */
+    PageInfo<GoodsProcurement> queryGoodsProcurements(GoodsProcurementQueryInfo queryInfo);
+
+    /**
+     * @describe 修改进货清单
+     * @author Joburgess
+     * @date 2020.10.09
+     * @param goodsProcurement:
+     * @return void
+     */
+    void updateGoodsProcurements(GoodsProcurement goodsProcurement);
+
+}

+ 2 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -51,5 +51,5 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @param file:
      * @return java.util.List<com.ym.mec.biz.dal.entity.Goods>
      */
-    List<Goods> importGoods(MultipartFile file) throws Exception;
-}
+    List<Goods> importGoods(MultipartFile file, Integer operatorId) throws Exception;
+}

+ 61 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsProcurementServiceImpl.java

@@ -0,0 +1,61 @@
+package com.ym.mec.biz.service.impl;
+
+import java.util.*;
+
+import com.ym.mec.biz.dal.page.GoodsProcurementQueryInfo;
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.QueryInfo;
+import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.util.collection.MapUtil;
+import org.apache.poi.ss.formula.functions.T;
+import org.springframework.beans.factory.annotation.Autowired;
+import com.ym.mec.biz.dal.entity.GoodsProcurement;
+import com.ym.mec.biz.service.GoodsProcurementService;
+import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
+import org.springframework.stereotype.Service;
+
+@Service
+public class GoodsProcurementServiceImpl extends BaseServiceImpl<Long, GoodsProcurement> implements GoodsProcurementService {
+	
+	@Autowired
+	private GoodsProcurementDao goodsProcurementDao;
+
+	@Override
+	public BaseDAO<Long, GoodsProcurement> getDAO() {
+		return goodsProcurementDao;
+	}
+
+	@Override
+	public PageInfo<GoodsProcurement> queryGoodsProcurements(GoodsProcurementQueryInfo queryInfo) {
+		PageInfo<GoodsProcurement> pageInfo = new PageInfo(queryInfo.getPage(), queryInfo.getRows());
+		Map<String, Object> params = new HashMap<String, Object>();
+		MapUtil.populateMap(params, queryInfo);
+
+		List<GoodsProcurement> dataList = null;
+		int count = goodsProcurementDao.countGoodsProcurements(params);
+		if (count > 0) {
+			pageInfo.setTotal(count);
+			params.put("offset", pageInfo.getOffset());
+			dataList = goodsProcurementDao.queryGoodsProcurements(params);
+		}
+		if (count == 0) {
+			dataList = new ArrayList();
+		}
+		pageInfo.setRows(dataList);
+		return pageInfo;
+	}
+
+	@Override
+	public void updateGoodsProcurements(GoodsProcurement goodsProcurement) {
+		if(Objects.isNull(goodsProcurement.getId())){
+			throw new BizException("请指定进货清单");
+		}
+		GoodsProcurement existsGoodsProcurement = goodsProcurementDao.get(goodsProcurement.getId());
+		if(Objects.isNull(existsGoodsProcurement)){
+			throw new BizException("进货清单不存在");
+		}
+
+	}
+}

+ 29 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -2,7 +2,9 @@ package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.biz.dal.dao.GoodsDao;
+import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
 import com.ym.mec.biz.dal.entity.Goods;
+import com.ym.mec.biz.dal.entity.GoodsProcurement;
 import com.ym.mec.biz.dal.enums.GoodsType;
 import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
 import com.ym.mec.biz.service.GoodsService;
@@ -10,6 +12,7 @@ import com.ym.mec.biz.service.UploadFileService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.entity.UploadReturnBean;
 import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.excel.IniFileUtil;
 import com.ym.mec.util.excel.POIUtil;
@@ -41,6 +44,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	private GoodsDao goodsDao;
 	@Autowired
 	private UploadFileService uploadFileService;
+	@Autowired
+	private IdGeneratorService idGeneratorService;
+	@Autowired
+	private GoodsProcurementDao goodsProcurementDao;
 
 	@Override
 	public BaseDAO<Integer, Goods> getDAO() {
@@ -68,7 +75,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 	@Override
 	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-	public List<Goods> importGoods(MultipartFile file) throws Exception {
+	public List<Goods> importGoods(MultipartFile file, Integer operatorId) throws Exception {
 		Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
 		InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
 		Map<String,String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.GOODS.getMsg());
@@ -160,6 +167,27 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 			goodsDao.batchInsert(newGoods);
 		}
 
+		String batchNo = idGeneratorService.generatorId("payment") + "";
+		Map<String, Integer> existsSnIdMap = existsGoods.stream().collect(Collectors.toMap(Goods::getSn, g -> g.getId()));
+		Map<String, Integer> newSnIdMap = newGoods.stream().collect(Collectors.toMap(Goods::getSn, g -> g.getId()));
+		existsSnIdMap.putAll(newSnIdMap);
+
+		List<GoodsProcurement> goodsProcurements = new ArrayList<>();
+		for (Goods goods : goodsList) {
+			GoodsProcurement gp = new GoodsProcurement();
+			gp.setGoodsId(existsSnIdMap.get(goods.getSn()));
+			gp.setGoodsCategoryId(goods.getGoodsCategoryId());
+			gp.setSupplyChannel(goods.getSupplyChannel());
+			gp.setDiscountPrice(goods.getDiscountPrice());
+			gp.setAgreeCostPrice(goods.getAgreeCostPrice());
+			gp.setTotalQuantity(goods.getStockCount());
+			gp.setTaxQuantity(goods.getTaxStockCount());
+			gp.setOperatorId(operatorId);
+			gp.setBatchNo(batchNo);
+			goodsProcurements.add(gp);
+		}
+		goodsProcurementDao.batchInsert(goodsProcurements);
+
 		return goodsList;
 	}
 }

+ 127 - 0
mec-biz/src/main/resources/config/mybatis/GoodsProcurementMapper.xml

@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<!--
+这个文件是自动生成的。
+不要修改此文件。所有改动将在下次重新自动生成时丢失。
+-->
+<mapper namespace="com.ym.mec.biz.dal.dao.GoodsProcurementDao">
+	
+	<resultMap type="com.ym.mec.biz.dal.entity.GoodsProcurement" id="GoodsProcurement">
+		<result column="id_" property="id" />
+		<result column="goods_id_" property="goodsId" />
+		<result column="goods_category_id_" property="goodsCategoryId" />
+		<result column="supply_channel_" property="supplyChannel" />
+		<result column="discount_price_" property="discountPrice" />
+		<result column="agree_cost_price_" property="agreeCostPrice" />
+		<result column="total_quantity_" property="totalQuantity" />
+		<result column="tax_quantity_" property="taxQuantity" />
+		<result column="operator_id_" property="operatorId" />
+		<result column="batch_no_" property="batchNo" />
+		<result column="create_time_" property="createTime" />
+		<result column="update_time_" property="updateTime" />
+	</resultMap>
+	
+	<!-- 根据主键查询一条记录 -->
+	<select id="get" resultMap="GoodsProcurement" >
+		SELECT * FROM goods_procurement WHERE id_ = #{id} 
+	</select>
+	
+	<!-- 全查询 -->
+	<select id="findAll" resultMap="GoodsProcurement">
+		SELECT * FROM goods_procurement ORDER BY id_
+	</select>
+	
+	<!-- 向数据库增加一条记录 -->
+	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.GoodsProcurement" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+		INSERT INTO goods_procurement (goods_id_,goods_category_id_,supply_channel_,discount_price_,agree_cost_price_,total_quantity_,tax_quantity_,operator_id_,batch_no_,create_time_,update_time_)
+		VALUES(#{goodsId},#{goodsCategoryId},#{supplyChannel},#{discountPrice},#{agreeCostPrice},#{totalQuantity},#{taxQuantity},#{operatorId},#{batchNo},NOW(),NOW())
+	</insert>
+
+	<insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.GoodsProcurement" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+		INSERT INTO goods_procurement (goods_id_,goods_category_id_,supply_channel_,discount_price_,agree_cost_price_,total_quantity_,tax_quantity_,operator_id_,batch_no_,create_time_,update_time_)
+		VALUE
+		<foreach collection="goodsProcurements" item="gp" separator=",">
+			(#{gp.goodsId},#{gp.goodsCategoryId},#{gp.supplyChannel},#{gp.discountPrice},#{gp.agreeCostPrice},#{gp.totalQuantity},#{gp.taxQuantity},#{gp.operatorId},#{gp.batchNo},NOW(),NOW())
+		</foreach>
+	</insert>
+	
+	<!-- 根据主键查询一条记录 -->
+	<update id="update" parameterType="com.ym.mec.biz.dal.entity.GoodsProcurement">
+		UPDATE goods_procurement
+		<set>
+			<if test="operatorId != null">
+				operator_id_ = #{operatorId},
+			</if>
+			<if test="agreeCostPrice != null">
+				agree_cost_price_ = #{agreeCostPrice},
+			</if>
+			<if test="id != null">
+				id_ = #{id},
+			</if>
+			<if test="goodsCategoryId != null">
+				goods_category_id_ = #{goodsCategoryId},
+			</if>
+			<if test="taxQuantity != null">
+				tax_quantity_ = #{taxQuantity},
+			</if>
+			<if test="supplyChannel != null">
+				supply_channel_ = #{supplyChannel},
+			</if>
+			<if test="discountPrice != null">
+				discount_price_ = #{discountPrice},
+			</if>
+			<if test="totalQuantity != null">
+				total_quantity_ = #{totalQuantity},
+			</if>
+			<if test="goodsId != null">
+				goods_id_ = #{goodsId},
+			</if>
+			<if test="batchNo != null">
+				batch_no_ = #{batchNo},
+			</if>
+				update_time_ = NOW(),
+		</set> WHERE id_ = #{id}
+	</update>
+	
+	<!-- 根据主键删除一条记录 -->
+	<delete id="delete" >
+		DELETE FROM goods_procurement WHERE id_ = #{id} 
+	</delete>
+
+	<sql id="queryCondition">
+		<where>
+			1=1
+			<if test="goodsId!=null">
+				AND goods_id_ = #{goodsId}
+			</if>
+			<if test="enterStorageStartTime!=null AND enterStorageEndTime!=null">
+				AND DATE_FORMAT(create_time_, '%Y-%m-%d') BETWEEN #{enterStorageStartTime} AND #{enterStorageEndTime}
+			</if>
+			<if test="search!=null and search!=''">
+				AND supply_channel_ LIKE CONCAT('%', #{search}, '%')
+			</if>
+		</where>
+	</sql>
+
+	<select id="queryGoodsProcurements" resultMap="GoodsProcurement" parameterType="map">
+		SELECT * FROM goods_procurement
+		<include refid="queryCondition"></include>
+		ORDER BY id_ <include refid="global.limit"/>
+	</select>
+
+	<select id="countGoodsProcurements" resultType="int">
+		SELECT COUNT(*) FROM goods_procurement
+		<include refid="queryCondition"></include>
+	</select>
+	
+	<!-- 分页查询 -->
+	<select id="queryPage" resultMap="GoodsProcurement" parameterType="map">
+		SELECT * FROM goods_procurement
+		ORDER BY id_ <include refid="global.limit"/>
+	</select>
+	
+	<!-- 查询当前表的总记录数 -->
+	<select id="queryCount" resultType="int">
+		SELECT COUNT(*) FROM goods_procurement
+	</select>
+</mapper>

+ 30 - 0
mec-web/src/main/java/com/ym/mec/web/controller/GoodsProcurementContrller.java

@@ -0,0 +1,30 @@
+package com.ym.mec.web.controller;
+
+import com.ym.mec.biz.dal.page.GoodsProcurementQueryInfo;
+import com.ym.mec.biz.service.GoodsProcurementService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Author Joburgess
+ * @Date 2020.10.09
+ */
+@RestController
+@RequestMapping("goodsProcurement")
+public class GoodsProcurementContrller extends BaseController {
+
+    @Autowired
+    private GoodsProcurementService goodsProcurementService;
+
+    @GetMapping("queryGoodsProcurements")
+    public HttpResponseResult queryGoodsProcurements(GoodsProcurementQueryInfo queryInfo){
+        return succeed(goodsProcurementService.queryGoodsProcurements(queryInfo));
+    }
+
+
+
+}

+ 9 - 1
mec-web/src/main/java/com/ym/mec/web/controller/ImportController.java

@@ -1,5 +1,7 @@
 package com.ym.mec.web.controller;
 
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.entity.FinancialExpenditure;
 import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
@@ -33,12 +35,18 @@ public class ImportController extends BaseController {
     private GoodsService goodsService;
     @Autowired
     private FinancialExpenditureService financialExpenditureService;
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
 
     @ApiOperation(value = "导入商品")
     @PostMapping(value = "goods")
     @PreAuthorize("@pcs.hasPermissions('import/goods')")
     public HttpResponseResult<List<Goods>> importGoods(@RequestParam("file") MultipartFile file) throws Exception {
-        return succeed(goodsService.importGoods(file));
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            return failed("用户信息获取失败");
+        }
+        return succeed(goodsService.importGoods(file, sysUser.getId()));
     }
 
     @ApiOperation(value = "导入财务支出")

+ 3 - 2
mec-web/src/main/resources/columnMapper.ini

@@ -11,8 +11,9 @@
 商品图片(插入一张图片) = image
 商品明细 = desc
 商品采购价2(元) = agreeCostPrice
-库存数量 = stockCount
-税务库存 = taxStockCount
+商品数量 = stockCount
+税务数量 = taxStockCount
+备查货号 = supplyChannel
 
 [财务支出导入模板]
 财务流程编号 = financialProcessNo

二进制
mec-web/src/main/resources/excelTemplate/商品导入模板.xls