Commit f9ac3214 by 胡懿

货品,二维码,入库,台账逻辑开发

parent fc10533a
......@@ -15,6 +15,21 @@ public class StaticNumSeq {
* */
public final static String GZBA = "GZBA";
/**
* 批次号
*/
public final static String PC = "PC";
/**
* 二维码物资编码
*/
public final static String WZBM = "WZBM";
/**
* 入库单
*/
public final static String RKD = "RKD";
public static List<String> seqList(){
List<String> seqList = new ArrayList<>();
Class<StaticNumSeq> clz = StaticNumSeq.class;
......
......@@ -3,6 +3,7 @@
*/
package com.jeeplus.modules.warehouse.goods.entity;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import javax.validation.constraints.NotNull;
......@@ -24,6 +25,7 @@ public class Goods extends DataEntity<Goods> {
private String batchNum; // 批次号
private Date time; // 时间
private User operator; // 操作人
private BigDecimal sum; // 总价
private Date beginTime; // 开始 时间
private Date endTime; // 结束 时间
private List<GoodsInfo> goodsInfoList = Lists.newArrayList(); // 子表列表
......@@ -65,7 +67,15 @@ public class Goods extends DataEntity<Goods> {
public void setOperator(User operator) {
this.operator = operator;
}
@ExcelField(title="总价", align=2, sort=5)
public BigDecimal getSum() {
return sum;
}
public void setSum(BigDecimal sum) {
this.sum = sum;
}
public Date getBeginTime() {
return beginTime;
}
......@@ -89,4 +99,5 @@ public class Goods extends DataEntity<Goods> {
public void setGoodsInfoList(List<GoodsInfo> goodsInfoList) {
this.goodsInfoList = goodsInfoList;
}
}
\ No newline at end of file
......@@ -8,6 +8,10 @@ import com.jeeplus.modules.warehouse.goods.entity.Goods;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import java.math.BigDecimal;
import java.util.List;
/**
* 货品明细Entity
......@@ -21,8 +25,11 @@ public class GoodsInfo extends DataEntity<GoodsInfo> {
private MaterialType type; // 类型
private String model; // 型号
private Integer num; // 数量
private String state; // 入库状态
private Goods goods; // 主表ID 父类
private String qrInterval; // 物资编码区间
private BigDecimal amount; // 单价
private List<QrCode> qrCodeList; // 二维码集合(xml中无关联查询)
public GoodsInfo() {
super();
......@@ -72,15 +79,14 @@ public class GoodsInfo extends DataEntity<GoodsInfo> {
this.num = num;
}
@ExcelField(title="入库状态", dictType="wh_stockroom_state", align=2, sort=6)
public String getState() {
return state;
@ExcelField(title="单价", align=2, sort=5)
public BigDecimal getAmount() {
return amount;
}
public void setState(String state) {
this.state = state;
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Goods getGoods() {
return goods;
}
......@@ -88,5 +94,21 @@ public class GoodsInfo extends DataEntity<GoodsInfo> {
public void setGoods(Goods goods) {
this.goods = goods;
}
public String getQrInterval() {
return qrInterval;
}
public void setQrInterval(String qrInterval) {
this.qrInterval = qrInterval;
}
public List<QrCode> getQrCodeList() {
return qrCodeList;
}
public void setQrCodeList(List<QrCode> qrCodeList) {
this.qrCodeList = qrCodeList;
}
}
\ No newline at end of file
......@@ -14,5 +14,6 @@ import com.jeeplus.modules.warehouse.goods.entity.Goods;
*/
@MyBatisMapper
public interface GoodsMapper extends BaseMapper<Goods> {
public Goods findByPc(Goods goods);
}
\ No newline at end of file
......@@ -9,7 +9,8 @@
a.model AS "model",
a.num AS "num",
a.remarks AS "remarks",
a.state AS "state",
a.amount as "amount",
a.qr_interval AS "qrInterval",
a.goods_id AS "goods.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
......@@ -57,12 +58,10 @@
<if test="dbName == 'mssql'">'%'+#{model}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{model},'%')</if>
</if>
<if test="state != null and state != ''">
AND a.state = #{state}
</if>
<if test="goods != null and goods.id != null and goods.id != ''">
AND a.goods_id = #{goods.id}
</if>
AND a.num > 0
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
......@@ -101,7 +100,8 @@
model,
num,
remarks,
state,
amount,
qr_interval,
goods_id,
create_by,
create_date,
......@@ -115,7 +115,8 @@
#{model},
#{num},
#{remarks},
#{state},
#{amount},
#{qrInterval},
#{goods.id},
#{createBy.id},
#{createDate},
......@@ -132,7 +133,8 @@
model = #{model},
num = #{num},
remarks = #{remarks},
state = #{state},
amount = #{amount},
qr_interval = #{qrInterval},
goods_id = #{goods.id},
update_by = #{updateBy.id},
update_date = #{updateDate}
......
......@@ -7,6 +7,7 @@
a.batch_num AS "batchNum",
a.time AS "time",
a.remarks AS "remarks",
a.sum as "sum",
a.operator AS "operator.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
......@@ -87,6 +88,7 @@
batch_num,
time,
remarks,
sum,
operator,
create_by,
create_date,
......@@ -98,6 +100,7 @@
#{batchNum},
#{time},
#{remarks},
#{sum},
#{operator.id},
#{createBy.id},
#{createDate},
......@@ -112,6 +115,7 @@
batch_num = #{batchNum},
time = #{time},
remarks = #{remarks},
sum = #{sum},
operator = #{operator.id},
update_by = #{updateBy.id},
update_date = #{updateDate}
......@@ -137,5 +141,13 @@
<select id="findUniqueByProperty" resultType="Goods" statementType="STATEMENT">
select * FROM t_wh_goods where ${propertyName} = '${value}'
</select>
<!-- 根据批次号查询货品信息 -->
<select id="findByPc" resultType="Goods" >
SELECT
<include refid="goodsColumns"/>
FROM t_wh_goods a
<include refid="goodsJoins"/>
WHERE a.batch_num = #{batchNum}
</select>
</mapper>
\ No newline at end of file
......@@ -3,8 +3,24 @@
*/
package com.jeeplus.modules.warehouse.goods.service;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.utils.io.FileUtil;
import com.jeeplus.modules.warehouse.code.util.CodeUtil;
import com.jeeplus.modules.warehouse.code.util.StaticNumSeq;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.qrcode.mapper.QrCodeMapper;
import com.jeeplus.modules.warehouse.qrcode.util.BuildQcUtil;
import com.jeeplus.modules.warehouse.qrcode.util.DrawQrcodeUtil;
import com.jeeplus.modules.warehouse.qrcode.util.TwoDimensionCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -28,6 +44,8 @@ public class GoodsService extends CrudService<GoodsMapper, Goods> {
@Autowired
private GoodsInfoMapper goodsInfoMapper;
@Autowired
private QrCodeMapper qrCodeMapper;
public Goods get(String id) {
Goods goods = super.get(id);
......@@ -70,5 +88,115 @@ public class GoodsService extends CrudService<GoodsMapper, Goods> {
super.delete(goods);
goodsInfoMapper.delete(new GoodsInfo(goods));
}
/**
* 生成二维码
*/
@Transactional(readOnly = false)
public GoodsInfo printQr(String infoId) {
String qrImgPath = Global.getUserfilesBaseDir() + "image";
File file = new File(qrImgPath);
if (!file .exists() && !file .isDirectory()) {
System.out.println("//不存在");
file .mkdirs();
}
GoodsInfo goodsInfo = goodsInfoMapper.get(infoId);
QrCode temQr = new QrCode();
GoodsInfo temGi = new GoodsInfo();
temGi.setId(infoId);
temQr.setGoodsInfo(temGi);
List<QrCode> qrCodeList = qrCodeMapper.findByGoodsInfoId(temQr);
if (null != qrCodeList && qrCodeList.size() > 0) { // 二维码已经生成过
goodsInfo.setQrCodeList(qrCodeList);
return goodsInfo;
} else {
qrCodeList = new ArrayList<>();
int num = goodsInfo.getNum();
String beginNumSeq = "";
String endNumSeq = "";
for (int i = 0; i < num; i++) {
String numSeq = CodeUtil.code("WZBM", StaticNumSeq.WZBM);
if (0 == i) {
beginNumSeq = numSeq;
}
if ((num - 1) == i) {
endNumSeq = numSeq;
}
QrCode qrCode = new QrCode();
qrCode.setCode(numSeq);
qrCode.setGoodsInfo(goodsInfo);
qrCode.setState("0");
qrCode.setGoodsInfo(goodsInfo);
qrCode.preInsert();
try {
BuildQcUtil.buildQr(qrCode, qrImgPath + "/" + numSeq + ".png", qrImgPath + "/" + numSeq + "_" + i + ".png"); // 生成图片
} catch (IOException e) {
e.printStackTrace();
}
qrCode.setUrl("image/" + numSeq + "_" + i + ".png");
qrCodeMapper.insert(qrCode);
qrCodeList.add(qrCode);
}
String qrInterval = "";
if (beginNumSeq.equals(endNumSeq)) {
qrInterval = beginNumSeq;
} else {
qrInterval = beginNumSeq + "_" + endNumSeq.substring(13,17);
}
goodsInfo.setQrInterval(qrInterval); // 设置编码区间
goodsInfo.preUpdate();
goodsInfoMapper.update(goodsInfo);
goodsInfo.setQrCodeList(qrCodeList);
return goodsInfo;
}
}
/**
* 清除二维码
* @param infoId
*/
@Transactional(readOnly = false)
public void cleanQr(String infoId) {
GoodsInfo goodsInfo = goodsInfoMapper.get(infoId);
QrCode temQr = new QrCode();
GoodsInfo temGi = new GoodsInfo();
temGi.setId(infoId);
temQr.setGoodsInfo(temGi);
List<QrCode> qrCodeList = qrCodeMapper.findByGoodsInfoId(temQr);
if (null != qrCodeList && qrCodeList.size() > 0) {
for (QrCode qrCode : qrCodeList) {
if (StringUtils.isNotBlank(qrCode.getUrl())) {
try {
FileUtil.deleteFile(new File(Global.getUserfilesBaseDir() + qrCode.getUrl()));
} catch (IOException e) {
e.printStackTrace();
}
}
}
qrCodeMapper.deleteByGoodInfoId(infoId); // 删除二维码
goodsInfo.setQrInterval("");
goodsInfo.preUpdate();
goodsInfoMapper.update(goodsInfo);
}
}
/**
* 通过goods信息查询goodsInfo信息(批次号)
* @param goods
* @return
*/
@Transactional(readOnly = false)
public Goods findGoodsInfoByGoods(Goods goods) {
goods = mapper.findByPc(goods);
GoodsInfo temGI = new GoodsInfo();
temGI.setGoods(goods);
List<GoodsInfo> goodsInfoList = goodsInfoMapper.findList(temGI);
goods = mapper.findByPc(goods);
goods.setGoodsInfoList(goodsInfoList);
return goods;
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@
*/
package com.jeeplus.modules.warehouse.goods.web;
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -10,6 +12,13 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import com.jeeplus.common.utils.io.FileUtil;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.warehouse.code.util.CodeUtil;
import com.jeeplus.modules.warehouse.code.util.StaticNumSeq;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -86,6 +95,10 @@ public class GoodsController extends BaseController {
@RequiresPermissions(value={"warehouse:goods:goods:view","warehouse:goods:goods:add","warehouse:goods:goods:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, Goods goods, Model model) {
String batchNum = CodeUtil.code("PC", StaticNumSeq.PC);
goods.setBatchNum(batchNum);
goods.setTime(new Date());
goods.setOperator(UserUtils.getUser());
model.addAttribute("goods", goods);
model.addAttribute("mode", mode);
return "modules/warehouse/goods/goodsForm";
......@@ -228,6 +241,59 @@ public class GoodsController extends BaseController {
}
return j;
}
/**
* 打印二维码
*/
@ResponseBody
@RequestMapping(value = "printQr")
public AjaxJson printQr(String goodsInfoId) throws Exception{
AjaxJson j = new AjaxJson();
//新增或编辑表单保存
GoodsInfo goodsInfo = goodsService.printQr(goodsInfoId);//保存
j.put("goodsInfo", goodsInfo);
j.setSuccess(true);
j.setMsg("保存货品模块成功");
return j;
}
/**
* 清除二维码
* @param goodsInfoId
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping(value = "cleanQr")
public AjaxJson cleanQr(String goodsInfoId) throws Exception{
AjaxJson j = new AjaxJson();
//新增或编辑表单保存
goodsService.cleanQr(goodsInfoId);//保存
j.setSuccess(true);
j.setMsg("保存货品模块成功");
return j;
}
/**
* 根据批次号查询货品明细信息
* @param goods
* @return
*/
@ResponseBody
@RequestMapping(value = "getGoodsInfoByGoods")
public AjaxJson getGoodsInfoByGoods(Goods goods) {
AjaxJson j = new AjaxJson();
if (StringUtils.isNotBlank(goods.getBatchNum())) {
Goods resultGoods = goodsService.findGoodsInfoByGoods(goods);
j.put("goods", resultGoods);
j.setSuccess(true);
j.setMsg("查询成功");
} else {
j.setSuccess(false);
j.setMsg("查询条件不能为空");
}
return j;
}
}
\ No newline at end of file
package com.jeeplus.modules.warehouse.ledger.dto;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.ledger.entity.Ledger;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.shelves.entity.Shelves;
import java.math.BigDecimal;
public class CountLedgerInfo {
private static final long serialVersionUID = 1L;
private String name; // 物资名称
private MaterialType type; // 类型
private String model; // 型号
private String batchNum; // 批次号
private Ledger ledger; // 主表外键 父类
private GoodsInfo goodsInfo; // 货品明细
private QrCode qr; // 二维码id
private Shelves shelves; // 货架id
private String code; // 物资编码
private BigDecimal sum; // 单价
private int num; // 数量
private String shelvesNames; // 多个货架信息,前端展示使用
private String warehouseNames; // 多个仓库信息,前端展示使用
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MaterialType getType() {
return type;
}
public void setType(MaterialType type) {
this.type = type;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getBatchNum() {
return batchNum;
}
public void setBatchNum(String batchNum) {
this.batchNum = batchNum;
}
public Ledger getLedger() {
return ledger;
}
public void setLedger(Ledger ledger) {
this.ledger = ledger;
}
public GoodsInfo getGoodsInfo() {
return goodsInfo;
}
public void setGoodsInfo(GoodsInfo goodsInfo) {
this.goodsInfo = goodsInfo;
}
public QrCode getQr() {
return qr;
}
public void setQr(QrCode qr) {
this.qr = qr;
}
public Shelves getShelves() {
return shelves;
}
public void setShelves(Shelves shelves) {
this.shelves = shelves;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public BigDecimal getSum() {
return sum;
}
public void setSum(BigDecimal sum) {
this.sum = sum;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getShelvesNames() {
return shelvesNames;
}
public void setShelvesNames(String shelvesNames) {
this.shelvesNames = shelvesNames;
}
public String getWarehouseNames() {
return warehouseNames;
}
public void setWarehouseNames(String warehouseNames) {
this.warehouseNames = warehouseNames;
}
}
......@@ -3,13 +3,18 @@
*/
package com.jeeplus.modules.warehouse.ledger.entity;
import com.jeeplus.modules.warehouse.ledger.dto.CountLedgerInfo;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
import java.math.BigDecimal;
import java.util.List;
import com.google.common.collect.Lists;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import javax.validation.constraints.NotNull;
/**
* 台账信息Entity
* @author huyi
......@@ -23,7 +28,10 @@ public class Ledger extends DataEntity<Ledger> {
private String model; // 型号
private String shelvesIds; // 货架id集合
private Integer num; // 数量
private BigDecimal sum; // 总价格
private List<LedgerInfo> ledgerInfoList = Lists.newArrayList(); // 子表列表
private List<CountLedgerInfo> countLedgerInfoList; // 前端展示使用的统计明细信息
public Ledger() {
super();
......@@ -33,6 +41,7 @@ public class Ledger extends DataEntity<Ledger> {
super(id);
}
@NotNull(message="物资名称不能为空")
@ExcelField(title="物资名称", align=2, sort=1)
public String getName() {
return name;
......@@ -41,7 +50,8 @@ public class Ledger extends DataEntity<Ledger> {
public void setName(String name) {
this.name = name;
}
@NotNull(message="类型不能为空")
@ExcelField(title="类型", fieldType=MaterialType.class, value="type.name", align=2, sort=2)
public MaterialType getType() {
return type;
......@@ -50,7 +60,8 @@ public class Ledger extends DataEntity<Ledger> {
public void setType(MaterialType type) {
this.type = type;
}
@NotNull(message="型号不能为空")
@ExcelField(title="型号", align=2, sort=3)
public String getModel() {
return model;
......@@ -59,7 +70,8 @@ public class Ledger extends DataEntity<Ledger> {
public void setModel(String model) {
this.model = model;
}
@NotNull(message="货架不能为空")
@ExcelField(title="货架id集合", align=2, sort=4)
public String getShelvesIds() {
return shelvesIds;
......@@ -68,7 +80,8 @@ public class Ledger extends DataEntity<Ledger> {
public void setShelvesIds(String shelvesIds) {
this.shelvesIds = shelvesIds;
}
@NotNull(message="数量不能为空")
@ExcelField(title="数量", align=2, sort=5)
public Integer getNum() {
return num;
......@@ -77,7 +90,17 @@ public class Ledger extends DataEntity<Ledger> {
public void setNum(Integer num) {
this.num = num;
}
@NotNull(message="单价不能为空")
@ExcelField(title="单价", align=2, sort=6)
public BigDecimal getSum() {
return sum;
}
public void setSum(BigDecimal sum) {
this.sum = sum;
}
public List<LedgerInfo> getLedgerInfoList() {
return ledgerInfoList;
}
......@@ -85,4 +108,12 @@ public class Ledger extends DataEntity<Ledger> {
public void setLedgerInfoList(List<LedgerInfo> ledgerInfoList) {
this.ledgerInfoList = ledgerInfoList;
}
public List<CountLedgerInfo> getCountLedgerInfoList() {
return countLedgerInfoList;
}
public void setCountLedgerInfoList(List<CountLedgerInfo> countLedgerInfoList) {
this.countLedgerInfoList = countLedgerInfoList;
}
}
\ No newline at end of file
......@@ -5,8 +5,11 @@ package com.jeeplus.modules.warehouse.ledger.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.warehouse.ledger.dto.CountLedgerInfo;
import com.jeeplus.modules.warehouse.ledger.entity.LedgerInfo;
import java.util.List;
/**
* 台账明细MAPPER接口
* @author huyi
......@@ -14,5 +17,6 @@ import com.jeeplus.modules.warehouse.ledger.entity.LedgerInfo;
*/
@MyBatisMapper
public interface LedgerInfoMapper extends BaseMapper<LedgerInfo> {
public List<CountLedgerInfo> findCliList(LedgerInfo ledgerInfo);
}
\ No newline at end of file
......@@ -14,5 +14,6 @@ import com.jeeplus.modules.warehouse.ledger.entity.Ledger;
*/
@MyBatisMapper
public interface LedgerMapper extends BaseMapper<Ledger> {
public Ledger findByTypeAndModel(Ledger ledger);
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
a.qr_id AS "qr.id",
a.shelves_id AS "shelves.id",
a.code AS "code",
a.amount AS "amount",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
......@@ -131,6 +132,7 @@
qr_id,
shelves_id,
code,
amount,
create_by,
create_date,
update_by,
......@@ -148,6 +150,7 @@
#{qr.id},
#{shelves.id},
#{code},
#{amount},
#{createBy.id},
#{createDate},
#{updateBy.id},
......@@ -168,6 +171,7 @@
qr_id = #{qr.id},
shelves_id = #{shelves.id},
code = #{code},
amount = #{amount},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
......@@ -207,5 +211,28 @@
<select id="findUniqueByProperty" resultType="LedgerInfo" statementType="STATEMENT">
select * FROM t_wh_ledger_info where ${propertyName} = '${value}'
</select>
<select id="findCliList" resultType="com.jeeplus.modules.warehouse.ledger.dto.CountLedgerInfo" >
SELECT
a.ledger_id AS "ledger.id",
count(a.id) AS "num",
a.type_id AS "type.id",
a.model AS "model",
a.batch_num AS "batchNum",
a.shelves_id AS "shelves.id",
sum(a.amount) AS "sum",
type.name AS "type.name",
s.name AS "shelves.name",
w.id AS "shelves.warehouse.id",
w.name AS "shelves.warehouse.name"
FROM t_wh_ledger_info a
LEFT JOIN t_wh_material_type type on type.id = a.type_id
LEFT JOIN t_wh_shelves s on s.id = a.shelves_id
LEFT JOIN t_wh_warehouse w on w.id = s.warehouse_id
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND a.ledger_id = #{ledger.id}
</where>
GROUP BY a.ledger_id,a.batch_num,a.shelves_id
</select>
</mapper>
\ No newline at end of file
......@@ -9,6 +9,7 @@
a.model AS "model",
a.shelvesids AS "shelvesIds",
a.num AS "num",
a.sum AS "sum",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
......@@ -105,6 +106,7 @@
model,
shelvesids,
num,
sum,
create_by,
create_date,
update_by,
......@@ -118,6 +120,7 @@
#{model},
#{shelvesIds},
#{num},
#{sum},
#{createBy.id},
#{createDate},
#{updateBy.id},
......@@ -134,6 +137,7 @@
model = #{model},
shelvesids = #{shelvesIds},
num = #{num},
sum = #{sum},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
......@@ -159,5 +163,17 @@
<select id="findUniqueByProperty" resultType="Ledger" statementType="STATEMENT">
select * FROM t_wh_ledger where ${propertyName} = '${value}'
</select>
<select id="findByTypeAndModel" resultType="Ledger" >
SELECT
<include refid="ledgerColumns"/>
FROM t_wh_ledger a
<include refid="ledgerJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND a.type_id = #{type.id}
AND a.model = #{model}
AND a.name = #{name}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -3,8 +3,12 @@
*/
package com.jeeplus.modules.warehouse.ledger.service;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
import com.jeeplus.modules.warehouse.ledger.dto.CountLedgerInfo;
import com.jeeplus.modules.warehouse.shelves.utils.ShelvesUtil;
import com.jeeplus.modules.warehouse.storage.dto.CountStorageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -34,6 +38,60 @@ public class LedgerService extends CrudService<LedgerMapper, Ledger> {
ledger.setLedgerInfoList(ledgerInfoMapper.findList(new LedgerInfo(ledger)));
return ledger;
}
public Ledger countLedger(String id) {
Ledger ledger = super.get(id);
List<CountLedgerInfo> countLedgerInfoList = ledgerInfoMapper.findCliList(new LedgerInfo(ledger));
Map<String, List<CountLedgerInfo>> map = new HashMap<>();
for (CountLedgerInfo countLedgerInfo : countLedgerInfoList) {
String batchNum = countLedgerInfo.getBatchNum();
List<CountLedgerInfo> list = map.get(batchNum);
if (null == list) {
list = new ArrayList<>();
list.add(countLedgerInfo);
map.put(countLedgerInfo.getBatchNum(), list);
} else {
list.add(countLedgerInfo);
}
}
List<CountLedgerInfo> cliList = new ArrayList<>();
for (Map.Entry<String, List<CountLedgerInfo>> entry : map.entrySet()) {
List<CountLedgerInfo> list = entry.getValue();
CountLedgerInfo cli = new CountLedgerInfo();
Set<String> wNameSet = new HashSet<>();
String shelvesNames = "";
int num = 0;
BigDecimal sum = new BigDecimal(0);
for (int i = 0; i < list.size(); i ++) {
CountLedgerInfo c = list.get(0);
if (i == 0) {
cli.setBatchNum(c.getBatchNum());
cli.setModel(c.getModel());
cli.setName(c.getName());
cli.setType(c.getType());
}
if (i != list.size() - 1) {
shelvesNames = shelvesNames + c.getShelves().getName() + ",";
} else {
shelvesNames = shelvesNames + c.getShelves().getName();
}
wNameSet.add(c.getShelves().getWarehouse().getName());
num += c.getNum();
sum = sum.add(c.getSum());
}
String wNames = ShelvesUtil.mergerWarehouseName(wNameSet);
cli.setShelvesNames(shelvesNames);
cli.setWarehouseNames(wNames);
cli.setNum(num);
cli.setSum(sum);
cliList.add(cli);
}
ledger.setCountLedgerInfoList(cliList);
return ledger;
}
public List<Ledger> findList(Ledger ledger) {
return super.findList(ledger);
......@@ -45,7 +103,42 @@ public class LedgerService extends CrudService<LedgerMapper, Ledger> {
@Transactional(readOnly = false)
public void save(Ledger ledger) {
super.save(ledger);
Ledger oldLeger = mapper.findByTypeAndModel(ledger);
// 判断是否存在同名称、同类型、同型号的台账,如果不存在,做新增操作,如果存在,则做修改操作
if (null == oldLeger || StringUtils.isBlank(oldLeger.getId())) {
super.save(ledger);
} else {
String shelvesIds = ledger.getShelvesIds();
int num = ledger.getNum();
BigDecimal sum = ledger.getSum();
Set<String> set = new HashSet<>();
String [] sIdArr = shelvesIds.split(",");
String [] oldSIdArr = oldLeger.getShelvesIds().split(",");
for (String sId : sIdArr) {
set.add(sId);
}
for (String oSId : oldSIdArr) {
set.add(oSId);
}
List<String> list = new ArrayList<>();
for (String sid : set) {
list.add(sid);
}
String newSIds = "";
for (int i = 0; i < list.size(); i ++) {
if (i != list.size() - 1) {
newSIds = newSIds + list.get(i) +",";
} else {
newSIds = newSIds + list.get(i);
}
}
oldLeger.setShelvesIds(newSIds);
oldLeger.setNum(oldLeger.getNum() + num);
oldLeger.setSum(oldLeger.getSum().add(sum));
oldLeger.preUpdate();
mapper.update(oldLeger);
}
for (LedgerInfo ledgerInfo : ledger.getLedgerInfoList()){
if (ledgerInfo.getId() == null){
continue;
......
......@@ -173,7 +173,10 @@ public class LedgerController extends BaseController {
public Ledger detail(String id) {
return ledgerService.get(id);
}
public Ledger countLedger(String id) {
return ledgerService.countLedger(id);
}
/**
* 导入Excel数据
......
......@@ -19,6 +19,7 @@ public class QrCode extends DataEntity<QrCode> {
private GoodsInfo goodsInfo; // 货品明细外键
private String code; // 物资编码
private String url; // 二维码存储路径
private String state; // 物资状态码 (0:未入库,1:已入库未入账,2:已入账未下账,3:下账)
public QrCode() {
super();
......@@ -54,5 +55,12 @@ public class QrCode extends DataEntity<QrCode> {
public void setUrl(String url) {
this.url = url;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}
\ No newline at end of file
......@@ -6,6 +6,9 @@ package com.jeeplus.modules.warehouse.qrcode.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 二维码MAPPER接口
......@@ -14,5 +17,24 @@ import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
*/
@MyBatisMapper
public interface QrCodeMapper extends BaseMapper<QrCode> {
/**
* 根据货品明细id删除二维码数据
* @param infoId
* @return
*/
public int deleteByGoodInfoId(String infoId);
/**
* 根据货品明细id查询二维码集合
* @param qrCode
* @return
*/
public List<QrCode> findByGoodsInfoId(QrCode qrCode);
/**
* 根据货品批次号,货品明细类型,货品明细型号,查询二维码信息
* @param qrCode
* @return
*/
public List<QrCode> findByPcTypeModel(QrCode qrCode);
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
a.id AS "id",
a.goods_info_id AS "goodsInfo.id",
a.code AS "code",
a.state AS "state",
a.url AS "url",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
......@@ -75,6 +76,7 @@
goods_info_id,
code,
url,
state,
create_by,
create_date,
update_by,
......@@ -86,6 +88,7 @@
#{goodsInfo.id},
#{code},
#{url},
#{state},
#{createBy.id},
#{createDate},
#{updateBy.id},
......@@ -100,6 +103,7 @@
goods_info_id = #{goodsInfo.id},
code = #{code},
url = #{url},
state = #{state},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
......@@ -125,5 +129,71 @@
<select id="findUniqueByProperty" resultType="QrCode" statementType="STATEMENT">
select * FROM t_wh_qr where ${propertyName} = '${value}'
</select>
<!--根据货品明细删除-->
<update id="deleteByGoodInfoId">
DELETE FROM t_wh_qr
WHERE goods_info_id = #{infoId}
</update>
<select id="findByGoodsInfoId" resultType="QrCode">
SELECT
<include refid="qrCodeColumns"/>
FROM t_wh_qr a
<include refid="qrCodeJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
<if test="goodsInfo.id != null and goodsInfo.id != ''">
AND a.goods_info_id = #{goodsInfo.id}
</if>
</where>
</select>
<select id="findByPcTypeModel" resultType="QrCode" >
SELECT
a.id AS "id",
a.goods_info_id AS "goodsInfo.id",
a.code AS "code",
a.url AS "url",
a.state AS "state",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
type.id AS "goodsInfo.type.id",
type.code AS "goodsInfo.type.code",
type.name AS "goodsInfo.type.name",
gi.id AS "goodsInfo.id",
gi.NAME AS "goodsInfo.name",
gi.model AS "goodsInfo.model",
gi.amount AS "goodsInfo.amount",
gi.goods_id AS "goodsInfo.goods.id"
FROM t_wh_qr a
LEFT JOIN t_wh_goods_info gi ON a.goods_info_id = gi.id
LEFT JOIN t_wh_material_type type ON type.id = gi.type_id
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
<if test="goodsInfo.goods.batchNum != null and goodsInfo.goods.batchNum != ''">
AND g.batch_num = #{goodsInfo.goods.batchNum}
</if>
<if test="goodsInfo.type.id != null and goodsInfo.type.id != ''">
AND gi.type_id = #{goodsInfo.type.id}
</if>
<if test="goodsInfo.model != null and goodsInfo.model != ''">
AND gi.type_id = #{goodsInfo.model}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.code ASC
</otherwise>
</choose>
</select>
</mapper>
\ No newline at end of file
package com.jeeplus.modules.warehouse.qrcode.util;
import com.alibaba.fastjson.JSON;
import com.jeeplus.common.utils.io.FileUtil;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class BuildQcUtil {
/**
*
* @param qrCode 二维码对象,里面必须包含完整的goodsInfos对象
* @param qrImgPath 二维码路径
* @param imgPath 最后生成的图片路径
* @throws IOException
*/
public static void buildQr(QrCode qrCode, String qrImgPath, String imgPath) throws IOException {
GoodsInfo goodsInfo = qrCode.getGoodsInfo();
Map<String, String> map = new HashMap<>();
map.put("code", qrCode.getId());
map.put("infoId", goodsInfo.getId());
TwoDimensionCode.encoderQRCode(JSON.toJSONString(map), qrImgPath, "png", 6);
File file = new File(qrImgPath);
try {
BufferedImage image = DrawQrcodeUtil.createAssetImageNew(file, qrCode);
DrawQrcodeUtil drawQrcodeUtil = new DrawQrcodeUtil();
drawQrcodeUtil.writeImage(image, imgPath);
} catch (IOException e) {
e.printStackTrace();
}
FileUtil.deleteFile(file);
}
}
package com.jeeplus.modules.warehouse.qrcode.util;
import com.jeeplus.modules.tools.utils.TwoDimensionCodeImage;
import com.swetake.util.Qrcode;
import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* author: dove19900520
* network:http://dove19900520.iteye.com/blog/2176374
*/
public class TwoDimensionCode {
/**
* 生成二维码(QRCode)图片
*
* @param content
* 存储内容
* @param imgPath
* 图片路径
*/
public static void encoderQRCode(String content, String imgPath) {
encoderQRCode(content, imgPath, "png", 2);
}
/**
* 生成二维码(QRCode)图片
*
* @param content
* 存储内容
* @param output
* 输出流
*/
public static void encoderQRCode(String content, OutputStream output) {
encoderQRCode(content, output, "png", 2);
}
/**
* 生成二维码(QRCode)图片
*
* @param content
* 存储内容
* @param imgPath
* 图片路径
* @param imgType
* 图片类型
*/
public static void encoderQRCode(String content, String imgPath, String imgType) {
encoderQRCode(content, imgPath, imgType, 2);
}
/**
* 生成二维码(QRCode)图片
*
* @param content
* 存储内容
* @param output
* 输出流
* @param imgType
* 图片类型
*/
public static void encoderQRCode(String content, OutputStream output,
String imgType) {
encoderQRCode(content, output, imgType, 2);
}
/**
* 生成二维码(QRCode)图片
*
* @param content
* 存储内容
* @param imgPath
* 图片路径
* @param imgType
* 图片类型
* @param size
* 二维码尺寸
*/
public static void encoderQRCode(String content, String imgPath, String imgType,
int size) {
try {
BufferedImage bufImg = qRCodeCommon(content, imgType, size);
File imgFile = new File(imgPath);
// 生成二维码QRCode图片
ImageIO.write(bufImg, imgType, imgFile);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 生成二维码(QRCode)图片
*
* @param content
* 存储内容
* @param output
* 输出流
* @param imgType
* 图片类型
* @param size
* 二维码尺寸
*/
public static void encoderQRCode(String content, OutputStream output,
String imgType, int size) {
try {
BufferedImage bufImg = qRCodeCommon(content, imgType, size);
// 生成二维码QRCode图片
ImageIO.write(bufImg, imgType, output);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 生成二维码(QRCode)图片的公共方法
*
* @param content
* 存储内容
* @param imgType
* 图片类型
* @param size
* 二维码尺寸
* @return
*/
private static BufferedImage qRCodeCommon(String content, String imgType, int size) {
BufferedImage bufImg = null;
// size = 10;
try {
Qrcode qrcodeHandler = new Qrcode();
// 设置二维码排错率,可选L(7%)、M(15%)、Q(25%)、H(30%),排错率越高可存储的信息越少,但对二维码清晰度的要求越小
qrcodeHandler.setQrcodeErrorCorrect('M');
qrcodeHandler.setQrcodeEncodeMode('B');
// 设置设置二维码尺寸,取值范围1-40,值越大尺寸越大,可存储的信息越大
qrcodeHandler.setQrcodeVersion(size);
// 获得内容的字节数组,设置编码格式
byte[] contentBytes = content.getBytes("utf-8");
// 图片尺寸
//int imgSize = 67 + 12 * (size - 1);
int imgSize = 127;
bufImg = new BufferedImage(imgSize, imgSize,
BufferedImage.TYPE_INT_RGB);
Graphics2D gs = bufImg.createGraphics();
// 设置背景颜色
gs.setBackground(Color.WHITE);
gs.clearRect(0, 0, imgSize, imgSize);
// 设定图像颜色> BLACK
gs.setColor(Color.BLACK);
// 设置偏移量,不设置可能导致解析出错
int pixoff = 2;
// 输出内容> 二维码
if (contentBytes.length > 0 && contentBytes.length < 800) {
boolean[][] codeOut = qrcodeHandler.calQrcode(contentBytes);
for (int i = 0; i < codeOut.length; i++) {
for (int j = 0; j < codeOut.length; j++) {
if (codeOut[j][i]) {
gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3, 3);
}
}
}
} else {
throw new Exception("QRCode content bytes length = "
+ contentBytes.length + " not in [0, 800].");
}
gs.dispose();
bufImg.flush();
} catch (Exception e) {
e.printStackTrace();
}
return bufImg;
}
/**
* 解析二维码(QRCode)
*
* @param imgPath
* 图片路径
* @return
*/
public static String decoderQRCode(String imgPath) throws Exception{
// QRCode 二维码图片的文件
File imageFile = new File(imgPath);
BufferedImage bufImg = null;
String content = null;
try {
bufImg = ImageIO.read(imageFile);
QRCodeDecoder decoder = new QRCodeDecoder();
content = new String(decoder.decode(new TwoDimensionCodeImage(
bufImg)), "utf-8");
} catch (IOException e) {
//e.printStackTrace();
} catch (DecodingFailedException dfe) {
//dfe.printStackTrace();
}
return content;
}
/**
* 解析二维码(QRCode)
*
* @param input
* 输入流
* @return
*/
public static String decoderQRCode(InputStream input) {
BufferedImage bufImg = null;
String content = null;
try {
bufImg = ImageIO.read(input);
QRCodeDecoder decoder = new QRCodeDecoder();
content = new String(decoder.decode(new TwoDimensionCodeImage(
bufImg)), "utf-8");
} catch (IOException e) {
e.printStackTrace();
} catch (DecodingFailedException dfe) {
dfe.printStackTrace();
}
return content;
}
public static void main(String[] args) {
String imgPath = "F:/asset.png";
/*String encoderContent = "Hello 大大、小小,welcome to QRCode!"
+ "\nMyblog [ http://sjsky.iteye.com ]"
+ "\nEMail [ sjsky007@gmail.com ]";*/
String encoderContent = "http://www.baidu.com";
com.jeeplus.modules.tools.utils.TwoDimensionCode handler = new com.jeeplus.modules.tools.utils.TwoDimensionCode();
handler.encoderQRCode(encoderContent, imgPath, "png");
// try {
// OutputStream output = new FileOutputStream(imgPath);
// handler.encoderQRCode(content, output);
// } catch (Exception e) {
// e.printStackTrace();
// }
}
}
package com.jeeplus.modules.warehouse.shelves.utils;
import com.jeeplus.modules.warehouse.shelves.entity.Shelves;
import com.jeeplus.modules.warehouse.warehouse.entity.Warehouse;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class ShelvesUtil {
public static String mergeShevlesName(Set<Shelves> set) {
return "";
}
/**
* 整合仓库名称,返回(a,b,c)
* @param warehousesNames
* @return
*/
public static String mergerWarehouseName(Set<String> warehousesNames) {
List<String> wList = new ArrayList<>();
for (String wName : warehousesNames) {
wList.add(wName);
}
StringBuffer sb = new StringBuffer();
for (int i =0; i < wList.size(); i ++) {
if (0 != wList.size()) {
sb.append(wList.get(0));
sb.append(",");
} else {
sb.append(wList.get(0));
}
}
return sb.toString();
}
}
package com.jeeplus.modules.warehouse.storage.dto;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.shelves.entity.Shelves;
import com.jeeplus.modules.warehouse.storage.entity.Storage;
import com.jeeplus.modules.warehouse.storage.entity.StorageInfo;
import com.jeeplus.modules.warehouse.warehouse.entity.Warehouse;
import java.math.BigDecimal;
import java.util.List;
public class CountStorageInfo extends DataEntity<StorageInfo> {
private static final long serialVersionUID = 1L;
private Storage storage; // 主表id 父类
private String name; // 名称
private MaterialType type; // 类型
private String model; // 型号
private GoodsInfo goodsInfo; // 货品明细id
private Shelves shelves; // 货架id
private Warehouse warehouse; // 仓库外键
private BigDecimal sum; // 单价
private int num; // 数量
private String shelvesNames; // 多个货架信息,前端展示使用
private String warehouseNames; // 多个仓库信息,前端展示使用
public CountStorageInfo() {
super();
}
public CountStorageInfo(Storage storage){
this.storage = storage;
}
public Storage getStorage() {
return storage;
}
public void setStorage(Storage storage) {
this.storage = storage;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MaterialType getType() {
return type;
}
public void setType(MaterialType type) {
this.type = type;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public GoodsInfo getGoodsInfo() {
return goodsInfo;
}
public void setGoodsInfo(GoodsInfo goodsInfo) {
this.goodsInfo = goodsInfo;
}
public Shelves getShelves() {
return shelves;
}
public void setShelves(Shelves shelves) {
this.shelves = shelves;
}
public Warehouse getWarehouse() {
return warehouse;
}
public void setWarehouse(Warehouse warehouse) {
this.warehouse = warehouse;
}
public BigDecimal getSum() {
return sum;
}
public void setSum(BigDecimal sum) {
this.sum = sum;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getShelvesNames() {
return shelvesNames;
}
public void setShelvesNames(String shelvesNames) {
this.shelvesNames = shelvesNames;
}
public String getWarehouseNames() {
return warehouseNames;
}
public void setWarehouseNames(String warehouseNames) {
this.warehouseNames = warehouseNames;
}
}
......@@ -4,6 +4,8 @@
package com.jeeplus.modules.warehouse.storage.entity;
import com.jeeplus.modules.sys.entity.User;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.List;
......@@ -11,6 +13,8 @@ import com.google.common.collect.Lists;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.storage.dto.CountStorageInfo;
/**
* 入库信息Entity
......@@ -26,8 +30,12 @@ public class Storage extends DataEntity<Storage> {
private String batchNum; // 批次号
private Date beginTime; // 开始 时间
private Date endTime; // 结束 时间
private BigDecimal sum; // 总价
private List<StorageInfo> storageInfoList = Lists.newArrayList(); // 子表列表
private List<CountStorageInfo> countStorageInfoList; // 前端使用的入库明细统计信息
public Storage() {
super();
}
......@@ -96,4 +104,20 @@ public class Storage extends DataEntity<Storage> {
public void setStorageInfoList(List<StorageInfo> storageInfoList) {
this.storageInfoList = storageInfoList;
}
public BigDecimal getSum() {
return sum;
}
public void setSum(BigDecimal sum) {
this.sum = sum;
}
public List<CountStorageInfo> getCountStorageInfoList() {
return countStorageInfoList;
}
public void setCountStorageInfoList(List<CountStorageInfo> countStorageInfoList) {
this.countStorageInfoList = countStorageInfoList;
}
}
\ No newline at end of file
......@@ -5,10 +5,14 @@ package com.jeeplus.modules.warehouse.storage.entity;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.shelves.entity.Shelves;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.modules.warehouse.warehouse.entity.Warehouse;
import java.math.BigDecimal;
/**
* 入库明细Entity
......@@ -24,7 +28,10 @@ public class StorageInfo extends DataEntity<StorageInfo> {
private String model; // 型号
private GoodsInfo goodsInfo; // 货品明细id
private Shelves shelves; // 货架id
private Warehouse warehouse; // 仓库外键
private BigDecimal amount; // 单价
private QrCode qrCode; // 前端保存入库单时使用的临时二维码对象
public StorageInfo() {
super();
}
......@@ -81,7 +88,6 @@ public class StorageInfo extends DataEntity<StorageInfo> {
this.goodsInfo = goodsInfo;
}
@ExcelField(title="货架id", fieldType=Shelves.class, value="shelves.name", align=2, sort=6)
public Shelves getShelves() {
return shelves;
}
......@@ -89,5 +95,28 @@ public class StorageInfo extends DataEntity<StorageInfo> {
public void setShelves(Shelves shelves) {
this.shelves = shelves;
}
public QrCode getQrCode() {
return qrCode;
}
public void setQrCode(QrCode qrCode) {
this.qrCode = qrCode;
}
public Warehouse getWarehouse() {
return warehouse;
}
public void setWarehouse(Warehouse warehouse) {
this.warehouse = warehouse;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
}
\ No newline at end of file
......@@ -5,8 +5,11 @@ package com.jeeplus.modules.warehouse.storage.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.warehouse.storage.dto.CountStorageInfo;
import com.jeeplus.modules.warehouse.storage.entity.StorageInfo;
import java.util.List;
/**
* 入库明细MAPPER接口
* @author huyi
......@@ -14,5 +17,10 @@ import com.jeeplus.modules.warehouse.storage.entity.StorageInfo;
*/
@MyBatisMapper
public interface StorageInfoMapper extends BaseMapper<StorageInfo> {
/**
* 入库明细统计
* @return
*/
List<CountStorageInfo> findCsiList(StorageInfo storageInfo);
}
\ No newline at end of file
......@@ -10,29 +10,27 @@
a.model AS "model",
a.goods_info_id AS "goodsInfo.id",
a.shelves_id AS "shelves.id",
a.warehouse_id AS "warehouse.id",
a.qr_id AS "qrCode.id",
a.remarks AS "remarks",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.del_flag AS "delFlag",
b.name AS "storage.name",
a.amount AS "amount",
type.name AS "type.name",
type.code AS "type.code",
shelves.name AS "shelves.name"
warehouse.name AS "warehouse.name"
</sql>
<sql id="storageInfoJoins">
LEFT JOIN t_wh_storage b ON b.id = a.storage_id
LEFT JOIN t_wh_material_type type ON type.id = a.type_id
LEFT JOIN t_wh_shelves shelves ON shelves.id = a.shelves_id
LEFT JOIN t_wh_warehouse warehouse ON warehouse.id = a.warehouse_id
</sql>
......@@ -64,15 +62,15 @@
<if test="type != null and type.id != null and type.id != ''">
AND a.type_id = #{type.id}
</if>
<if test="shelves != null and shelves.id != null and shelves.id != ''">
AND a.shelves_id = #{shelves.id}
</if>
<if test="model != null and model != ''">
AND a.model LIKE
<if test="dbName == 'oracle'">'%'||#{model}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{model}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{model},'%')</if>
</if>
<if test="shelves != null and shelves.id != null and shelves.id != ''">
AND a.shelves_id = #{shelves.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
......@@ -112,6 +110,9 @@
model,
goods_info_id,
shelves_id,
warehouse_id,
qr_id,
amount,
remarks,
create_by,
create_date,
......@@ -126,6 +127,9 @@
#{model},
#{goodsInfo.id},
#{shelves.id},
#{warehouse.id},
#{qrCode.id},
#{amount},
#{remarks},
#{createBy.id},
#{createDate},
......@@ -143,6 +147,8 @@
model = #{model},
goods_info_id = #{goodsInfo.id},
shelves_id = #{shelves.id},
warehouse_id = #{warehouse.id},
amount = #{amount},
remarks = #{remarks},
update_by = #{updateBy.id},
update_date = #{updateDate}
......@@ -182,5 +188,32 @@
<select id="findUniqueByProperty" resultType="StorageInfo" statementType="STATEMENT">
select * FROM t_wh_storage_info where ${propertyName} = '${value}'
</select>
<select id="findCsiList" resultType="com.jeeplus.modules.warehouse.storage.dto.CountStorageInfo" >
SELECT
a.name AS "name",
a.type_id AS "type.id",
type.name AS "type.name",
a.model AS "model",
sum(a.amount) AS "sum",
a.goods_info_id AS "goodsInfo.id",
a.shelves_id AS "shelves.id",
s.name AS "shelves.name",
w.id AS "warehouse.id",
w.name AS "warehouse.name",
COUNT( a.id ) AS "num"
FROM
t_wh_storage_info a
LEFT JOIN t_wh_material_type type on a.type_id = type.id
LEFT JOIN t_wh_shelves s on s.id = a.shelves_id
LEFT JOIN t_wh_warehouse w on w.id = s.warehouse_id
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
<if test="storage != null and storage.id != null and storage.id != ''">
AND a.storage_id = #{storage.id}
</if>
</where>
GROUP BY a.goods_info_id,a.shelves_id
</select>
</mapper>
\ No newline at end of file
......@@ -9,6 +9,7 @@
a.time AS "time",
a.batch_num AS "batchNum",
a.remarks AS "remarks",
sum AS "sum",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
......@@ -96,6 +97,7 @@
operator,
time,
batch_num,
sum,
remarks,
create_by,
create_date,
......@@ -108,6 +110,7 @@
#{operator.id},
#{time},
#{batchNum},
#{sum},
#{remarks},
#{createBy.id},
#{createDate},
......@@ -123,6 +126,7 @@
operator = #{operator.id},
time = #{time},
batch_num = #{batchNum},
sum = #{sum},
remarks = #{remarks},
update_by = #{updateBy.id},
update_date = #{updateDate}
......
......@@ -3,8 +3,20 @@
*/
package com.jeeplus.modules.warehouse.storage.service;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
import com.jeeplus.modules.warehouse.goods.entity.Goods;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.goods.mapper.GoodsInfoMapper;
import com.jeeplus.modules.warehouse.goods.mapper.GoodsMapper;
import com.jeeplus.modules.warehouse.ledger.dto.CountLedgerInfo;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.qrcode.mapper.QrCodeMapper;
import com.jeeplus.modules.warehouse.shelves.entity.Shelves;
import com.jeeplus.modules.warehouse.shelves.mapper.ShelvesMapper;
import com.jeeplus.modules.warehouse.shelves.utils.ShelvesUtil;
import com.jeeplus.modules.warehouse.storage.dto.CountStorageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -28,13 +40,89 @@ public class StorageService extends CrudService<StorageMapper, Storage> {
@Autowired
private StorageInfoMapper storageInfoMapper;
@Autowired
private GoodsInfoMapper goodsInfoMapper;
@Autowired
private QrCodeMapper qrCodeMapper;
@Autowired
private ShelvesMapper shelvesMapper;
@Autowired
private GoodsMapper goodsMapper;
public Storage get(String id) {
Storage storage = super.get(id);
storage.setStorageInfoList(storageInfoMapper.findList(new StorageInfo(storage)));
List<StorageInfo> storageInfoList = storageInfoMapper.findList(new StorageInfo(storage));
storage.setStorageInfoList(storageInfoList);
return storage;
}
public Storage countStorage(String id) {
Storage storage = super.get(id);
List<CountStorageInfo> countStorageInfoList = storageInfoMapper.findCsiList(new StorageInfo(storage));
Map<String, List<CountStorageInfo>> map = new HashMap<>();
for (CountStorageInfo countStorageInfo : countStorageInfoList) {
String goodsInfoId = countStorageInfo.getGoodsInfo().getId();
List<CountStorageInfo> list = map.get(goodsInfoId);
if (null == list) {
list = new ArrayList<>();
list.add(countStorageInfo);
map.put(countStorageInfo.getGoodsInfo().getId(), list);
} else {
list.add(countStorageInfo);
}
}
List<CountStorageInfo> csiList = new ArrayList<>();
for (Map.Entry<String, List<CountStorageInfo>> entry : map.entrySet()) {
List<CountStorageInfo> list = entry.getValue();
CountStorageInfo csi = new CountStorageInfo();
Set<String> wNameSet = new HashSet<>();
String shelvesNames = "";
int num = 0;
BigDecimal sum = new BigDecimal(0);
for (int i = 0; i < list.size(); i ++) {
CountStorageInfo c = list.get(0);
if (i == 0) {
csi.setGoodsInfo(c.getGoodsInfo());
csi.setModel(c.getModel());
csi.setName(c.getName());
csi.setType(c.getType());
}
if (i != list.size() - 1) {
shelvesNames = shelvesNames + c.getShelves().getName() + ",";
} else {
shelvesNames = shelvesNames + c.getShelves().getName();
}
wNameSet.add(c.getWarehouse().getName());
num += c.getNum();
sum = sum.add(c.getSum());
}
String wNames = ShelvesUtil.mergerWarehouseName(wNameSet);
csi.setShelvesNames(shelvesNames);
csi.setWarehouseNames(wNames);
csi.setNum(num);
csi.setSum(sum);
csiList.add(csi);
}
storage.setCountStorageInfoList(csiList);
return storage;
}
/**
* 根据统计信息查询入库明细
* @param countStorageInfo
* @return
*/
public List<StorageInfo> findInfoBycountStorage(CountStorageInfo countStorageInfo) {
StorageInfo storageInfo = new StorageInfo();
storageInfo.setShelves(countStorageInfo.getShelves());
storageInfo.setGoodsInfo(countStorageInfo.getGoodsInfo());
storageInfo.setPage(countStorageInfo.getPage());
return storageInfoMapper.findList(storageInfo);
}
public List<Storage> findList(Storage storage) {
return super.findList(storage);
}
......@@ -46,23 +134,77 @@ public class StorageService extends CrudService<StorageMapper, Storage> {
@Transactional(readOnly = false)
public void save(Storage storage) {
super.save(storage);
Map<String, Integer> map = new HashMap<>();
BigDecimal money = new BigDecimal(0.00);
for (StorageInfo storageInfo : storage.getStorageInfoList()){
if (storageInfo.getId() == null){
continue;
}
GoodsInfo goodsInfo = storageInfo.getGoodsInfo();
if (StorageInfo.DEL_FLAG_NORMAL.equals(storageInfo.getDelFlag())){
if (StringUtils.isBlank(storageInfo.getId())){
storageInfo.setStorage(storage);
storageInfo.preInsert();
storageInfoMapper.insert(storageInfo);
// 计算需要变更的总价格
money = money.subtract(goodsInfo.getAmount());
// 计算货品明细中的需要变更的数量
Integer count = map.get(goodsInfo.getId());
if (null == count) {
count = -1;
} else {
count --;
}
map.put(goodsInfo.getId(), count);
// 更改二维码状态为已入库
QrCode qrCode = qrCodeMapper.get(storageInfo.getQrCode().getId());
qrCode.setState("1");
qrCode.preUpdate();
qrCodeMapper.update(qrCode);
}else{
storageInfo.preUpdate();
storageInfoMapper.update(storageInfo);
}
}else{
storageInfoMapper.delete(storageInfo);
money = money.add(goodsInfo.getAmount());
// 计算货品明细中的需要变更的数量
Integer count = map.get(goodsInfo.getId());
if (null == count) {
count = 1;
} else {
count ++;
}
map.put(goodsInfo.getId(), count);
// 更改二维码状态为未入库
QrCode qrCode = qrCodeMapper.get(storageInfo.getQrCode().getId());
qrCode.setState("0");
qrCode.preUpdate();
qrCodeMapper.update(qrCode);
}
}
// 更新货品明细中的数量
Set<Map.Entry<String, Integer>> countSet = map.entrySet();
for (Map.Entry<String, Integer> entry : countSet) {
String goodsInfoId = entry.getKey();
int count = entry.getValue();
GoodsInfo goodsInfo = goodsInfoMapper.get(goodsInfoId);
goodsInfo.setNum(goodsInfo.getNum() + count);
goodsInfo.preUpdate();
goodsInfoMapper.update(goodsInfo);
}
// 更新货品表总价
Goods temGoods = new Goods();
temGoods.setBatchNum(storage.getBatchNum());
Goods goods = goodsMapper.findByPc(temGoods);
goods.setSum(goods.getSum().add(money));
goods.preUpdate();
goodsMapper.update(goods);
}
@Transactional(readOnly = false)
......@@ -70,5 +212,30 @@ public class StorageService extends CrudService<StorageMapper, Storage> {
super.delete(storage);
storageInfoMapper.delete(new StorageInfo(storage));
}
/**
* 根据批次号,货品类型,货品型号查询二维码
* @param goodsInfo
* @return
*/
@Transactional(readOnly = false)
public List<StorageInfo> findByPcTypeModel(GoodsInfo goodsInfo) {
QrCode temQr = new QrCode();
temQr.setGoodsInfo(goodsInfo);
List<QrCode> qrCodeList = qrCodeMapper.findByPcTypeModel(temQr);
List<StorageInfo> storageInfoList = new ArrayList<>();
for (QrCode qrCode : qrCodeList) {
GoodsInfo gi = qrCode.getGoodsInfo();
StorageInfo storageInfo = new StorageInfo();
storageInfo.setName(gi.getName());
storageInfo.setType(gi.getType());
storageInfo.setModel(gi.getModel());
storageInfo.setGoodsInfo(gi);
storageInfo.setAmount(gi.getAmount());
storageInfo.setQrCode(qrCode);
storageInfoList.add(storageInfo);
}
return storageInfoList;
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
*/
package com.jeeplus.modules.warehouse.storage.web;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -10,6 +11,15 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.warehouse.code.util.CodeUtil;
import com.jeeplus.modules.warehouse.code.util.StaticNumSeq;
import com.jeeplus.modules.warehouse.goods.entity.Goods;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.storage.dto.CountStorageInfo;
import com.jeeplus.modules.warehouse.storage.entity.StorageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -86,6 +96,10 @@ public class StorageController extends BaseController {
@RequiresPermissions(value={"warehouse:storage:storage:view","warehouse:storage:storage:add","warehouse:storage:storage:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, Storage storage, Model model) {
String code = CodeUtil.code("RKD", StaticNumSeq.RKD);
storage.setCode(code);
storage.setTime(new Date());
storage.setOperator(UserUtils.getUser());
model.addAttribute("storage", storage);
model.addAttribute("mode", mode);
return "modules/warehouse/storage/storageForm";
......@@ -171,7 +185,23 @@ public class StorageController extends BaseController {
public Storage detail(String id) {
return storageService.get(id);
}
@ResponseBody
@RequestMapping(value = "countStorage")
public Storage countStorage(String id) {
return storageService.countStorage(id);
}
@ResponseBody
@RequestMapping(value = "findInfoBycountStorage")
public AjaxJson findInfoBycountStorage(CountStorageInfo countStorageInfo) {
AjaxJson j = new AjaxJson();
List<StorageInfo> storageInfoList = storageService.findInfoBycountStorage(countStorageInfo);
j.put("storageInfoList", storageInfoList);
j.setSuccess(true);
j.setMsg("查询成功");
return j;
}
/**
* 导入Excel数据
......@@ -228,6 +258,31 @@ public class StorageController extends BaseController {
}
return j;
}
/**
* 查询需要入库的货品信息
* @param goodsInfo
* @return
*/
@ResponseBody
@RequestMapping(value = "findByPcTypeModel")
public AjaxJson findByPcTypeModel(GoodsInfo goodsInfo) {
Goods goods = new Goods();
goods.setBatchNum("PC-2023-02-0003");
goodsInfo.setType(new MaterialType("3c56529c82bd49c38ebd27d5264af130"));
goodsInfo.setGoods(goods);
AjaxJson j = new AjaxJson();
if (null != goodsInfo && null != goodsInfo.getGoods() && null != goodsInfo.getType() && StringUtils.isNotBlank(goodsInfo.getGoods().getBatchNum()) && StringUtils.isNotBlank(goodsInfo.getType().getId())) {
List<StorageInfo> storageInfoList = storageService.findByPcTypeModel(goodsInfo);
j.put("storageInfoList", storageInfoList);
j.setSuccess(true);
j.setMsg("查询成功");
} else {
j.setSuccess(false);
j.setMsg("查询条件不能为空");
}
return j;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment