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(); // 子表列表
......@@ -66,6 +68,14 @@ public class Goods extends DataEntity<Goods> {
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;
}
......@@ -89,4 +95,20 @@ public class GoodsInfo extends DataEntity<GoodsInfo> {
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
......@@ -15,4 +15,5 @@ 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}
......@@ -138,4 +142,12 @@
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);
......@@ -71,4 +89,114 @@ public class GoodsService extends CrudService<GoodsMapper, 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";
......@@ -229,5 +242,58 @@ 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,8 +28,11 @@ 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;
......@@ -42,6 +51,7 @@ public class Ledger extends DataEntity<Ledger> {
this.name = name;
}
@NotNull(message="类型不能为空")
@ExcelField(title="类型", fieldType=MaterialType.class, value="type.name", align=2, sort=2)
public MaterialType getType() {
return type;
......@@ -51,6 +61,7 @@ public class Ledger extends DataEntity<Ledger> {
this.type = type;
}
@NotNull(message="型号不能为空")
@ExcelField(title="型号", align=2, sort=3)
public String getModel() {
return model;
......@@ -60,6 +71,7 @@ public class Ledger extends DataEntity<Ledger> {
this.model = model;
}
@NotNull(message="货架不能为空")
@ExcelField(title="货架id集合", align=2, sort=4)
public String getShelvesIds() {
return shelvesIds;
......@@ -69,6 +81,7 @@ public class Ledger extends DataEntity<Ledger> {
this.shelvesIds = shelvesIds;
}
@NotNull(message="数量不能为空")
@ExcelField(title="数量", align=2, sort=5)
public Integer getNum() {
return num;
......@@ -78,6 +91,16 @@ public class Ledger extends DataEntity<Ledger> {
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
......@@ -15,4 +18,5 @@ 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
......@@ -15,4 +15,5 @@ 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}
......@@ -208,4 +212,27 @@
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}
......@@ -160,4 +164,16 @@
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;
......@@ -35,6 +39,60 @@ public class LedgerService extends CrudService<LedgerMapper, 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) {
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;
......
......@@ -174,6 +174,9 @@ public class LedgerController extends BaseController {
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();
......@@ -55,4 +56,11 @@ public class QrCode extends DataEntity<QrCode> {
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}
......@@ -126,4 +130,70 @@
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.common.utils.text.EscapeUtil;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import javax.imageio.*;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageOutputStream;
import java.awt.*;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.AttributedString;
import java.text.SimpleDateFormat;
import java.util.Iterator;
public class DrawQrcodeUtil {
/**
* 1英寸是2.54里面
*/
private static final double INCH_2_CM = 2.54d;
public static final int M86_53 = 1;
public static final int M110_90 = 2;
public static final int M220_140 = 3;
public static final int M250_160 = 4;
public static final int A86_53 = 5;
public static final int A110_90 = 6;
public static final int A220_140 =7;
public static final int A250_160 = 8;
public static final int C86_53 =9;
public static final int C110_90 =10;
public static final int C220_140 = 11;
public static final int C250_160 = 12;
@Test
public void test() throws IOException {
int dpi = 300;
QrCode qrCode = new QrCode();
File backGroundImg = new File("H:\\qrcodeBG\\86-53.png");
File qrcodeFile = new File("H:\\qrcodeBG\\qrcode-viewfile.png");
Office office = new Office();
office.setId("123");
office.setName("测试数据公司一");
/*asset.setBelongUnit(office);
asset.setName("测试资产名称一");
asset.setModelNum("NPL-C370-9965-432");
asset.setNum("0000-2016-12051-001");*/
BufferedImage bufferedImage = createAssetImageNew(qrcodeFile,qrCode);
System.out.println("height"+bufferedImage.getHeight());
System.out.println("Tileheight"+bufferedImage.getTileHeight());
System.out.println("getWidth"+bufferedImage.getWidth());
System.out.println("TileWidth"+bufferedImage.getTileWidth());
for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName("png"); iw.hasNext();){
ImageWriter writer = iw.next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
continue;
}
//ByteArrayOutputStream output = new ByteArrayOutputStream();
FileOutputStream output = new FileOutputStream(new File("H:\\qrcode-86-53.png"));
ImageOutputStream stream = null;
try {
setDPI(metadata, dpi);
stream = ImageIO.createImageOutputStream(output);
writer.setOutput(stream);
writer.write(metadata, new IIOImage(bufferedImage, null, metadata), writeParam);
} finally {
try {
stream.close();
} catch (IOException e) {
}
}
//return output.toByteArray();
}
//ImageIO.write(bufferedImage, "PNG", new File("H:\\qrcode-86-53.png"));
}
public void writeImage(BufferedImage bufferedImage,String path) throws FileNotFoundException {
int dpi = 300;
for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName("png"); iw.hasNext();){
ImageWriter writer = iw.next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {
continue;
}
//ByteArrayOutputStream output = new ByteArrayOutputStream();
FileOutputStream output = new FileOutputStream(new File(path));
ImageOutputStream stream = null;
try {
setDPI(metadata, dpi);
stream = ImageIO.createImageOutputStream(output);
writer.setOutput(stream);
writer.write(metadata, new IIOImage(bufferedImage, null, metadata), writeParam);
} catch (IIOInvalidTreeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
stream.close();
output.flush();
output.close();
} catch (IOException e) {
}
}
}
}
private void setDPI(IIOMetadata metadata, int dpi) throws IIOInvalidTreeException {
// for PMG, it's dots per millimeter
double dotsPerMilli = 1.0 * dpi / 10 / INCH_2_CM;
IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
horiz.setAttribute("value", Double.toString(dotsPerMilli));
IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
vert.setAttribute("value", Double.toString(dotsPerMilli));
IIOMetadataNode dim = new IIOMetadataNode("Dimension");
dim.appendChild(horiz);
dim.appendChild(vert);
IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
root.appendChild(dim);
metadata.mergeTree("javax_imageio_1.0", root);
}
private static class QRcodeSize{
private int initfontSize;
private int initContentX;
private int initContentY;
private int initContentYIncrement;
private int qrcodeX;
private int qrcodeY;
private int qrcodeWidth;
private int qrcodeHeight;
private Color color;
public QRcodeSize(int initfontSize, int initContentX, int initContentY, int initContentYIncrement, int qrcodeX, int qrcodeY, int qrcodeWidth, int qrcodeHeight,Color color) {
this.initfontSize = initfontSize;
this.initContentX = initContentX;
this.initContentY = initContentY;
this.initContentYIncrement = initContentYIncrement;
this.qrcodeX = qrcodeX;
this.qrcodeY = qrcodeY;
this.qrcodeWidth = qrcodeWidth;
this.qrcodeHeight = qrcodeHeight;
this.color = color;
}
public int getInitfontSize() {
return initfontSize;
}
public void setInitfontSize(int initfontSize) {
this.initfontSize = initfontSize;
}
public int getInitContentX() {
return initContentX;
}
public void setInitContentX(int initContentX) {
this.initContentX = initContentX;
}
public int getInitContentY() {
return initContentY;
}
public void setInitContentY(int initContentY) {
this.initContentY = initContentY;
}
public int getInitContentYIncrement() {
return initContentYIncrement;
}
public void setInitContentYIncrement(int initContentYIncrement) {
this.initContentYIncrement = initContentYIncrement;
}
public int getQrcodeX() {
return qrcodeX;
}
public void setQrcodeX(int qrcodeX) {
this.qrcodeX = qrcodeX;
}
public int getQrcodeY() {
return qrcodeY;
}
public void setQrcodeY(int qrcodeY) {
this.qrcodeY = qrcodeY;
}
public int getQrcodeWidth() {
return qrcodeWidth;
}
public void setQrcodeWidth(int qrcodeWidth) {
this.qrcodeWidth = qrcodeWidth;
}
public int getQrcodeHeight() {
return qrcodeHeight;
}
public void setQrcodeHeight(int qrcodeHeight) {
this.qrcodeHeight = qrcodeHeight;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
}
public static BufferedImage createAssetImageNew(File qrcodeFile,QrCode qrCode) throws IOException {
GoodsInfo goodsInfo = qrCode.getGoodsInfo();
QRcodeSize qRcodeSize = null;
qRcodeSize = new QRcodeSize(8,50,330,78,50,50,300,300,new Color(34,25,21));
BufferedImage bgImage = new BufferedImage(400, 600, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2 = bgImage.createGraphics();
BufferedImage qrcodeImage = ImageIO.read(qrcodeFile);
RenderingHints rh=new RenderingHints(RenderingHints. KEY_ANTIALIASING,
RenderingHints. VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_STROKE_CONTROL
, RenderingHints.VALUE_STROKE_PURE);
rh.put(RenderingHints.KEY_ALPHA_INTERPOLATION
, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2.setRenderingHints(rh);
Font font = new Font("黑体",Font.BOLD,3 * qRcodeSize.getInitfontSize());
g2.setFont(font); //设置字体:字体、字号、大小
g2.setColor(qRcodeSize.color);//设置背景颜色
// g2.setBackground(c);
int contentX = qRcodeSize.getInitContentX();
int contentY = qRcodeSize.getInitContentY() + 70;
//写二维码
g2.drawImage(qrcodeImage,qRcodeSize.getQrcodeX(),qRcodeSize.getQrcodeY(),qRcodeSize.getQrcodeWidth(),qRcodeSize.getQrcodeHeight(),null,null);
//写入货品名称
String contentTitle1 = "货品名称:";
int contentTitle1Width = g2.getFontMetrics().stringWidth(contentTitle1);
g2.drawString(contentTitle1,contentX,contentY);
String name = formatContent(goodsInfo.getName(),10);
AttributedString as = new AttributedString(name);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, name.length());
g2.drawString(as.getIterator(),contentX+contentTitle1Width,contentY);
//写入货品类型
String contentTitle2 = "货品类型:";
int contentTitle2Width = g2.getFontMetrics().stringWidth(contentTitle2);
g2.drawString(contentTitle2,contentX,contentY+50);
String typeName = formatContent(goodsInfo.getType().getName(),10);
as = new AttributedString(typeName);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, typeName.length());
g2.drawString(as.getIterator(),contentX+contentTitle2Width,contentY+50);
//写入物资编码
String contentTitle4 = "物资编码:";
int contentTitle4Width = g2.getFontMetrics().stringWidth(contentTitle4);
g2.drawString(contentTitle4,contentX,contentY+100);
String code = formatContent(qrCode.getCode(),10);
as = new AttributedString(code);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, code.length());
g2.drawString(as.getIterator(),contentX+contentTitle4Width,contentY+100);
return bgImage;
}
/**
* 生成二维码包装图片
* @param bgImg 背景图片
* @param logo 头部logo
* @param qrCode 资产二维码
* @param qc
* */
public static BufferedImage createAssetImage(File bgImg, InputStream logo, InputStream qrCode,InputStream luqiaoLogo, QrCode qc, int coefficint) throws IOException {
GoodsInfo goodsInfo = qc.getGoodsInfo();
// 220 宽:2598---- 高:1654 2.56
// 110 宽:1299 高 827 1.28
//default 宽:1016 高 626
double cfwidth,cfheight;
Color c;
switch (coefficint){
case 2:
cfwidth = 1.28;
cfheight = 1.32;
c = new Color(38,60,146);
break;
case 3:
cfwidth = 2.56;
cfheight = 2.64;
c = new Color(38,60,146);
break;
default:
cfwidth = 1;
cfheight = 1;
c = Color.WHITE;
break;
}
BufferedImage bgImage = ImageIO.read(bgImg);
BufferedImage logoImage = ImageIO.read(logo);
BufferedImage qrcodeImage = ImageIO.read(qrCode);
BufferedImage luqiaoLogoImage = ImageIO.read(luqiaoLogo);
//得到它的绘制环境(这张图片的笔)
Graphics2D g2 = (Graphics2D) bgImage.getGraphics();
RenderingHints rh=new RenderingHints(RenderingHints. KEY_ANTIALIASING,
RenderingHints. VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_STROKE_CONTROL
, RenderingHints.VALUE_STROKE_PURE);
rh.put(RenderingHints.KEY_ALPHA_INTERPOLATION
, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2.setRenderingHints(rh);
Font font = new Font("黑体",Font.BOLD,(int)(64 * cfwidth));
g2.setFont(font); //设置字体:字体、字号、大小
g2.setColor(c);//设置背景颜色
String name = goodsInfo.getName();
String typeName = goodsInfo.getType().getName();
String model = goodsInfo.getModel();
String code = qc.getCode();
/*String assetNum = "JZLQ02-2018-2315-001";
String assetName = "压路机";
String zerenren = "李四";
String chuciqiyongriqi = "2018-06-25";*/
int contentX = (int)Math.round(60*cfwidth);
int contentY = (int)Math.round(260*cfheight);
Font contentFont = new Font("黑体",Font.BOLD,(int)Math.round(28*cfwidth));
g2.setFont(contentFont); //设置字体:字体、字号、大小
g2.setColor(c);//设置字体颜色
//写入货品名称
String contentTitle1 = "货品名称:";
int contentTitle1Width = g2.getFontMetrics().stringWidth(contentTitle1);
g2.drawString(contentTitle1,contentX,contentY);
name = formatContent(name,21);
AttributedString as = new AttributedString(name);
as.addAttribute(TextAttribute.FONT, contentFont);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, name.length());
g2.drawString(as.getIterator(),contentX+contentTitle1Width,contentY);
//写入货品类型
String contentTitle2 = "货品类型:";
int contentTitle2Width = g2.getFontMetrics().stringWidth(contentTitle2);
g2.drawString(contentTitle2,contentX,contentY+(int)(100*cfheight));
typeName = formatContent(typeName,21);
as = new AttributedString(typeName);
as.addAttribute(TextAttribute.FONT, contentFont);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, typeName.length());
g2.drawString(as.getIterator(),contentX+contentTitle2Width,contentY+(int)Math.round(100*cfheight));
//写入规格型号
String contentTitle3 = "规格型号:";
int contentTitle3Width = g2.getFontMetrics().stringWidth(contentTitle3);
g2.drawString(contentTitle3,contentX,contentY+(int)Math.round(200*cfheight));
model = formatContent(model,21);
as = new AttributedString(model);
as.addAttribute(TextAttribute.FONT, contentFont);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, model.length());
g2.drawString(as.getIterator(),contentX+contentTitle3Width,contentY+(int)Math.round(200*cfheight));
//写入物资编码
String contentTitle4 = "物资编码:";
int contentTitle4Width = g2.getFontMetrics().stringWidth(contentTitle4);
g2.drawString(contentTitle4,contentX,contentY+(int)Math.round(200*cfheight));
model = formatContent(model,21);
as = new AttributedString(model);
as.addAttribute(TextAttribute.FONT, contentFont);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, model.length());
g2.drawString(as.getIterator(),contentX+contentTitle4Width,contentY+(int)Math.round(200*cfheight));
//写二维码
g2.drawImage(qrcodeImage,(int)Math.round(640*cfwidth),(int)Math.round(250*cfheight),(int)Math.round(300*cfwidth),(int)Math.round(300*cfheight),null,null);
//写入二维码中的logo
g2.drawImage(luqiaoLogoImage,(int)Math.round(760*cfwidth),(int)Math.round(370*cfheight),(int)Math.round(60*cfwidth),(int)Math.round(60*cfheight),null,null);
return bgImage;
}
/**
* 字符长度若不足指定长度,在字符串后添加空格
* @param str
* @param length 指定长度
*/
public static String formatContent(String str,int length){
try {
int trueSize = getChineseLength(str,"utf-8");
if(trueSize<length){
int count = length - trueSize;
for(int i = 0;i<count;i++){
str = str+" ";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
/**
* 获中英文混合状态下字符串的实际长度。例如 "你好1" 实际长度为5
* @param str
* @param endcoding 字符串的字符编码
*/
public static int getChineseLength(String str, String endcoding) throws Exception {
int len = 0; //定义返回的字符串长度
int j = 0;
//按照指定编码得到byte[]
byte[] b_name = str.getBytes(endcoding);
do {
short tmpst = (short) (b_name[j] & 0xF0);
if (tmpst >= 0xB0) {
if (tmpst < 0xC0) {
j += 2;
len += 2;
} else if ((tmpst == 0xC0) || (tmpst == 0xD0)) {
j += 2;
len += 2;
} else if (tmpst == 0xE0) {
j += 3;
len += 2;
} else {
short tmpst0 = (short) (((short) b_name[j]) & 0x0F);
if (tmpst0 == 0) {
j += 4;
len += 2;
} else if (tmpst0 < 12) {
j += 5;
len += 2;
} else {
j += 6;
len += 2;
}
}
} else {
j += 1;
len += 1;
}
} while (j <= b_name.length - 1);
return len;
}
/**
* 设置字符的间距
* @param str 要写入的字符串
* @param x 字符串写入的位置
* @param y 字符串写入的位置
* @param rate 设置字符串间距倍数,例如1.2
* @param g 画布类对象
*
* */
public static void MyDrawString(String str,int x,int y,double rate,Graphics g){
String tempStr=new String();
int orgStringWight=g.getFontMetrics().stringWidth(str);
int orgStringLength=str.length();
int tempx=x;
int tempy=y;
while(str.length()>0) {
tempStr=str.substring(0, 1);
str=str.substring(1, str.length());
g.drawString(tempStr, tempx, tempy);
tempx=(int)(tempx+(double)orgStringWight/(double)orgStringLength*rate);
}
}
}
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;
}
......@@ -90,4 +96,27 @@ public class StorageInfo extends DataEntity<StorageInfo> {
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
......@@ -15,4 +18,9 @@ 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}
......@@ -183,4 +189,31 @@
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)
......@@ -71,4 +213,29 @@ public class StorageService extends CrudService<StorageMapper, 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";
......@@ -172,6 +186,22 @@ public class StorageController extends BaseController {
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数据
......@@ -229,5 +259,30 @@ 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