进销存项目实战
一、 首页默认:
1、当前库存查询(部分功能模块复用)
系统登录成功后,进入系统首页,默认展示当前库存信息,如下示例:
分析
查询所有的商品 对应的是goods表 返回类型应该是List集合里边全是Goods 可是为什么返回类型是Map<String,Object>
好家伙不仔细看返回的数据有哪些
商品编码 商品名称 类别 型号 库存数量 销售总数 上次进价 成本均价 销售价 库存总值 单位 生产厂商
那么那些表有这些字段属性呢?
离谱啊 **这三个属性找不到 ??? 成本均价() 库存总值 **
t_goods
商品编码goods_code
商品名称goods_name
型号goods_model
库存数量inventory_quantity
上次进价last_purchasing_price
销售价selling_price
生产厂商goods_producer
类别goods_type_name(t_goods_type)
销售总数(WC居然是用销售表销售数量减去退货表退的数量)
成本均价()
库存总值
干干干 为什么需求 和接口文档 需要的数据有差别? 以接口文档为主
{
"total": 26,
"rows": [
{
"goodsId": 1,
"goodsCode": "0001",
"goodsName": "陶华碧老干妈香辣脆油辣椒",
"inventoryQuantity": 167,
"lastPurchasingPrice": 8.5,
"minNum": 1000,
"goodsModel": "红色装",
"goodsProducer": "贵州省贵阳南明老干妈风味食品有限公司",
"purchasingPrice": 7.95,
"remarks": "好卖",
"sellingPrice": 8.5,
"state": 2,
"goodsUnit": "瓶",
"goodsTypeId": 10,
"goodsTypeName": "地方特产",
"saleTotal": 15
},………………..
]
}
这段SQL语句有问题 group by a.goods_code //分组去重存在问题 去充不了啊
<select id="listInventory" resultType="com.atguigu.jxc.entity.Goods">
select a.goods_id goodsId,
a.goods_code goodsCode,
a.goods_name goodsName,
a.inventory_quantity inventoryQuantity,
a.last_purchasing_price lastPurchasingPrice,
a.min_num minNum,
a.goods_model goodsModel,
a.goods_producer goodsProducer,
a.purchasing_price purchasingPrice,
a.remarks,
a.selling_price sellingPrice,
a.state,
a.goods_unit goodsUnit,
a.goods_type_id goodsTypeId,
b.goods_type_name goodsTypeName,
(c.goods_num - d.goods_num) saleTotal
from t_goods a
inner join t_goods_type b on a.goods_type_id = b.goods_type_id
left join t_sale_list_goods c on a.goods_id = c.goods_id
left join t_customer_return_list_goods d on a.goods_id = d.goods_id
<where>
<if test="codeOrName != null and codeOrName != ''">
and (a.goods_code = #{codeOrName} or a.goods_name like "%"#{codeOrName}"%")
</if>
<if test="goodsTypeId != null and goodsTypeId != ''">
and (a.goods_type_id = #{goodsTypeId})
</if>
</where>
group by a.goods_code
order by a.goods_code
limit #{page} ,#{rows}
</select>
粘一下莫名其妙的错误代码 居然是sql语句的问题?????
select a.goods_id goodsId,
a.goods_code goodsCode,
a.goods_name goodsName,
a.inventory_quantity inventoryQuantity,
a.last_purchasing_price lastPurchasingPrice,
a.min_num minNum,
a.goods_model goodsModel,
a.goods_producer goodsProducer,
a.purchasing_price purchasingPrice,
a.remarks,
a.selling_price sellingPrice,
a.state,
a.goods_unit goodsUnit,
a.goods_type_id goodsTypeId,
b.goods_type_name goodsTypeName,
(c.goods_num-d.goods_num) saleTotal
FROM t_goods a
inner join t_goods_type b on a.goods_type_id = b.goods_type_id
left join t_sale_list_goods c on a.goods_id = c.goods_id
left join t_customer_return_list_goods d on a.goods_id = d.goods_id
<where>
<if test="codeOrName != null and ordeOrName != ''">
and (a.goods_name = "%"#{codeOrName}"%" or a.goods_code = #{ordeOrName})
</if>
<if test="goodsTypeId != null and goodsTypeId != ''">
and (a.goods_type_id = #{goodsTypeId})
</if>
</where>
limit #{page},#{rows}
order by a.goods_code
找一找原因 好家伙 原来是因为 limit 写在了order by 前面
<select id="SelectAllGoods" resultType="com.atguigu.jxc.entity.Goods">
select a.goods_id goodsId,
a.goods_code goodsCode,
a.goods_name goodsName,
a.inventory_quantity inventoryQuantity,
a.last_purchasing_price lastPurchasingPrice,
a.min_num minNum,
a.goods_model goodsModel,
a.goods_producer goodsProducer,
a.purchasing_price purchasingPrice,
a.remarks,
a.selling_price sellingPrice,
a.state,
a.goods_unit goodsUnit,
a.goods_type_id goodsTypeId,
b.goods_type_name goodsTypeName,
(c.goods_num - d.goods_num) saleTotal
from t_goods a
inner join t_goods_type b on a.goods_type_id = b.goods_type_id
left join t_sale_list_goods c on a.goods_id = c.goods_id
left join t_customer_return_list_goods d on a.goods_id = d.goods_id
<where>
<if test="codeOrName != null and codeOrName != ''">
and (a.goods_code = #{codeOrName} or a.goods_name like "%"#{codeOrName}"%")
</if>
<if test="goodsTypeId != null and goodsTypeId != ''">
and (a.goods_type_id = #{goodsTypeId})
</if>
</where>
order by a.goods_code
limit #{page} ,#{rows}
</select>
解决了
现在测试如果返回类型不直接写实体类 而是写resultMap,而且resultMap返回的是实体类 会出问题吗?
<resultMap id="GoodsDaoMap" type="com.atguigu.jxc.entity.Goods" autoMapping="true">
</resultMap>
没问题
现在测试控制器写上@PathVariable注解会不会出现问题
出现了问题参数传不了
public Map<String,Object> getAllGoods(@PathVariable Integer page, @PathVariable Integer rows, @PathVariable String codeOrName,
@PathVariable Integer goodsTypeId)
这次呢?在注解里加上参数
public Map<String,Object> getAllGoods(@PathVariable("page") Integer page, @PathVariable("rows") Integer rows,
@PathVariable("codeOrName") String codeOrName,
@PathVariable("goodsTypeId") Integer goodsTypeId)
还是不行
查一查 @PathVariable注解的应用
@PathVariable 映射 URL 绑定的占位符 通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过
@PathVariable(“xxx”) 绑定到操作方法的入参中。
一般与@RequestMapping(method = RequestMethod.GET)一起使用
@RequestMapping("/getUserById/{name}")
public User getUser(@PathVariable("name") String name){
return userService.selectUser(name);
}
1、若方法参数名称和需要绑定的url中变量名称一致时,可以简写:
@RequestMapping("/getUser/{name}")
public User getUser(@PathVariable String name){
return userService.selectUser(name);
}
2、若方法参数名称和需要绑定的url中变量名称不一致时,写成:
@RequestMapping("/getUserById/{name}")
public User getUser(@PathVariable("name") String userName){
return userService.selectUser(userName);
}
|