更新入库接口
This commit is contained in:
parent
d31c67d128
commit
6dda4a908e
1
.gitignore
vendored
1
.gitignore
vendored
@ -34,5 +34,6 @@ build/
|
||||
logs
|
||||
api-docs
|
||||
InventoryProMax.db
|
||||
InventoryProMax.db-journal
|
||||
keypair.key
|
||||
src/main/resources/static
|
||||
|
@ -42,6 +42,6 @@
|
||||
  需要Maven3、JDK11+
|
||||
|
||||
```
|
||||
mvn compile
|
||||
mvn clear
|
||||
mvn package
|
||||
```
|
||||
|
@ -6,11 +6,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.sqlite.SQLiteConfig;
|
||||
import org.sqlite.SQLiteDataSource;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* 数据库配置
|
||||
@ -51,6 +56,19 @@ public class DatabaseConfiguration {
|
||||
config.enforceForeignKeys(true);
|
||||
SQLiteDataSource sqLiteDataSource = new SQLiteDataSource(config);
|
||||
sqLiteDataSource.setUrl(dbProperties.getUrl());
|
||||
try (Connection connection = sqLiteDataSource.getConnection()) {
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("SELECT * FROM t_users");
|
||||
if (!resultSet.next()) {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO t_users(username,password,role) VALUES (?,?,?)");
|
||||
preparedStatement.setString(1, "admin");
|
||||
preparedStatement.setString(2, new BCryptPasswordEncoder().encode("root"));
|
||||
preparedStatement.setString(3, UserRoles.ROOT);
|
||||
preparedStatement.executeUpdate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("", e);
|
||||
}
|
||||
LOGGER.info("SQLite数据库配置完毕");
|
||||
return sqLiteDataSource;
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package icu.mmmc.InventoryProMax.controller;
|
||||
|
||||
import icu.mmmc.InventoryProMax.mapper.entity.RestockEntity;
|
||||
import icu.mmmc.InventoryProMax.service.RestockService;
|
||||
import icu.mmmc.InventoryProMax.vo.ResultStatus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 库存接口
|
||||
*
|
||||
* @author shouchen
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/api/store")
|
||||
public class RestockController {
|
||||
private RestockService restockService;
|
||||
|
||||
/**
|
||||
* 创建入库清单
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/create")
|
||||
@PreAuthorize("hasAnyRole(@userRoles.roleInvAdmin)")
|
||||
public ResultStatus createRestock(@RequestBody RestockEntity restockEntity) {
|
||||
try {
|
||||
restockService.createRestock(restockEntity);
|
||||
} catch (Exception e) {
|
||||
return new ResultStatus(false, "创建失败");
|
||||
}
|
||||
return new ResultStatus(true, "创建成功");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public RestockController setStoreService(RestockService restockService) {
|
||||
this.restockService = restockService;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -24,6 +24,11 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* JWT安全认证过滤器
|
||||
*
|
||||
* @author shouchen
|
||||
*/
|
||||
@Component
|
||||
public class JwtTokenAuthenticationFilter extends GenericFilterBean {
|
||||
private UserDetailsService userDetailsService;
|
||||
@ -59,6 +64,7 @@ public class JwtTokenAuthenticationFilter extends GenericFilterBean {
|
||||
response.sendRedirect("/");
|
||||
return;
|
||||
}
|
||||
// 检索Token
|
||||
for (Cookie cookie : cookies) {
|
||||
if (HttpHeaders.AUTHORIZATION.equalsIgnoreCase(cookie.getName())) {
|
||||
token = cookie.getValue();
|
||||
|
@ -0,0 +1,30 @@
|
||||
package icu.mmmc.InventoryProMax.mapper;
|
||||
|
||||
import icu.mmmc.InventoryProMax.mapper.entity.RestockEntity;
|
||||
import icu.mmmc.InventoryProMax.mapper.entity.RestockItemEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 库存Mapper
|
||||
*
|
||||
* @author shouchen
|
||||
*/
|
||||
@Mapper
|
||||
public interface RestockMapper {
|
||||
/**
|
||||
* 插入入库清单
|
||||
*
|
||||
* @param restockEntity 清单实体
|
||||
* @return 更新的条数
|
||||
*/
|
||||
int insertRestockEntity(@Param("restockEntity") RestockEntity restockEntity);
|
||||
|
||||
/**
|
||||
* 插入入库条目
|
||||
*
|
||||
* @param item 物品实体
|
||||
* @return 更新的条数
|
||||
*/
|
||||
int insertRestockItem(@Param("item") RestockItemEntity item);
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package icu.mmmc.InventoryProMax.mapper.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 入库记录实体
|
||||
*
|
||||
* @author shouchen
|
||||
*/
|
||||
public class RestockEntity {
|
||||
private Integer id;
|
||||
private String receiver;
|
||||
private String sender;
|
||||
private String senderPhone;
|
||||
private double amount;
|
||||
private String remarks;
|
||||
private String createTime;
|
||||
private List<RestockItemEntity> items;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RestockEntity setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public RestockEntity setReceiver(String receiver) {
|
||||
this.receiver = receiver;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public RestockEntity setSender(String sender) {
|
||||
this.sender = sender;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSenderPhone() {
|
||||
return senderPhone;
|
||||
}
|
||||
|
||||
public RestockEntity setSenderPhone(String senderPhone) {
|
||||
this.senderPhone = senderPhone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public RestockEntity setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRemarks() {
|
||||
return remarks;
|
||||
}
|
||||
|
||||
public RestockEntity setRemarks(String remarks) {
|
||||
this.remarks = remarks;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public RestockEntity setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<RestockItemEntity> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public RestockEntity setItems(List<RestockItemEntity> items) {
|
||||
this.items = items;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package icu.mmmc.InventoryProMax.mapper.entity;
|
||||
|
||||
/**
|
||||
* 入库物品实体
|
||||
*
|
||||
* @author shouchen
|
||||
*/
|
||||
public class RestockItemEntity {
|
||||
private Integer id;
|
||||
private Integer resId;
|
||||
private Integer proId;
|
||||
private Integer invId;
|
||||
private String title;
|
||||
private String model;
|
||||
private String unit;
|
||||
private int count;
|
||||
private double cost;
|
||||
private double amount;
|
||||
private String remarks;
|
||||
private String createTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RestockItemEntity setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getResId() {
|
||||
return resId;
|
||||
}
|
||||
|
||||
public RestockItemEntity setResId(Integer resId) {
|
||||
this.resId = resId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getProId() {
|
||||
return proId;
|
||||
}
|
||||
|
||||
public RestockItemEntity setProId(Integer proId) {
|
||||
this.proId = proId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getInvId() {
|
||||
return invId;
|
||||
}
|
||||
|
||||
public RestockItemEntity setInvId(Integer invId) {
|
||||
this.invId = invId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public RestockItemEntity setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public RestockItemEntity setModel(String model) {
|
||||
this.model = model;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public RestockItemEntity setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public RestockItemEntity setCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public RestockItemEntity setCost(double cost) {
|
||||
this.cost = cost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public RestockItemEntity setAmount(double amount) {
|
||||
this.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRemarks() {
|
||||
return remarks;
|
||||
}
|
||||
|
||||
public RestockItemEntity setRemarks(String remarks) {
|
||||
this.remarks = remarks;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public RestockItemEntity setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package icu.mmmc.InventoryProMax.service;
|
||||
|
||||
import icu.mmmc.InventoryProMax.dto.UserInfo;
|
||||
import icu.mmmc.InventoryProMax.mapper.RestockMapper;
|
||||
import icu.mmmc.InventoryProMax.mapper.entity.RestockEntity;
|
||||
import icu.mmmc.InventoryProMax.mapper.entity.RestockItemEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 库存业务
|
||||
*
|
||||
* @author shouchen
|
||||
*/
|
||||
@Service
|
||||
public class RestockService {
|
||||
private RestockMapper restockMapper;
|
||||
private UserCenterService userCenterService;
|
||||
|
||||
/**
|
||||
* 创建入库清单
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createRestock(RestockEntity restockEntity) throws Exception {
|
||||
UserInfo userInfo = userCenterService.getUserInfoByUsername((String) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
|
||||
restockEntity.setReceiver(userInfo.getNickname());
|
||||
if (restockMapper.insertRestockEntity(restockEntity) < 1) {
|
||||
throw new Exception("");
|
||||
}
|
||||
for (RestockItemEntity item : restockEntity.getItems()) {
|
||||
item.setResId(restockEntity.getId());
|
||||
if (restockMapper.insertRestockItem(item) < 1) {
|
||||
throw new Exception("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public RestockService setRestockMapper(RestockMapper restockMapper) {
|
||||
this.restockMapper = restockMapper;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public RestockService setUserCenterService(UserCenterService userCenterService) {
|
||||
this.userCenterService = userCenterService;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -67,7 +67,8 @@
|
||||
</sql>
|
||||
|
||||
<!-- 插入一个订单 -->
|
||||
<insert id="insertOrder" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
<insert id="insertOrder" useGeneratedKeys="true" keyColumn="id" keyProperty="id"
|
||||
parameterType="icu.mmmc.InventoryProMax.mapper.entity.OrderEntity">
|
||||
INSERT INTO t_orders
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="order.seller != null">seller,</if>
|
||||
@ -102,7 +103,7 @@
|
||||
</insert>
|
||||
|
||||
<!-- 插入一个条目 -->
|
||||
<insert id="insertItem">
|
||||
<insert id="insertItem" parameterType="icu.mmmc.InventoryProMax.mapper.entity.OrderItemEntity">
|
||||
INSERT INTO t_order_items
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
ord_id,
|
||||
|
116
src/main/resources/mappers/RestockMapper.xml
Normal file
116
src/main/resources/mappers/RestockMapper.xml
Normal file
@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="icu.mmmc.InventoryProMax.mapper.RestockMapper">
|
||||
<resultMap id="restockEntity" type="icu.mmmc.InventoryProMax.mapper.entity.RestockEntity">
|
||||
<result column="id" property="id"/>
|
||||
<result column="receiver" property="receiver"/>
|
||||
<result column="sender" property="sender"/>
|
||||
<result column="sender_phone" property="senderPhone"/>
|
||||
<result column="amount" property="amount"/>
|
||||
<result column="remarks" property="remarks"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
</resultMap>
|
||||
<resultMap id="restockItem" type="icu.mmmc.InventoryProMax.mapper.entity.RestockItemEntity">
|
||||
<result column="id" property="id"/>
|
||||
<result column="res_id" property="resId"/>
|
||||
<result column="pro_id" property="proId"/>
|
||||
<result column="inv_id" property="invId"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="model" property="model"/>
|
||||
<result column="unit" property="unit"/>
|
||||
<result column="count" property="count"/>
|
||||
<result column="cost" property="cost"/>
|
||||
<result column="amount" property="amount"/>
|
||||
<result column="remarks" property="remarks"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 插入入库清单 -->
|
||||
<insert id="insertRestockEntity" parameterType="icu.mmmc.InventoryProMax.mapper.entity.RestockEntity"
|
||||
useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO t_restocks
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="restockEntity.receiver != null">
|
||||
receiver,
|
||||
</if>
|
||||
<if test="restockEntity.sender != null">
|
||||
sender,
|
||||
</if>
|
||||
<if test="restockEntity.senderPhone != null">
|
||||
sender_phone,
|
||||
</if>
|
||||
<if test="restockEntity.amount != null">
|
||||
amount,
|
||||
</if>
|
||||
<if test="restockEntity.remarks != null">
|
||||
remarks,
|
||||
</if>
|
||||
<if test="restockEntity.createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="VALUES(" suffix=")" suffixOverrides=",">
|
||||
<if test="restockEntity.receiver != null">
|
||||
#{restockEntity.receiver},
|
||||
</if>
|
||||
<if test="restockEntity.sender != null">
|
||||
#{restockEntity.sender},
|
||||
</if>
|
||||
<if test="restockEntity.senderPhone != null">
|
||||
#{restockEntity.senderPhone},
|
||||
</if>
|
||||
<if test="restockEntity.amount != null">
|
||||
#{restockEntity.amount},
|
||||
</if>
|
||||
<if test="restockEntity.remarks != null">
|
||||
#{restockEntity.remarks},
|
||||
</if>
|
||||
<if test="restockEntity.createTime != null">
|
||||
#{restockEntity.createTime},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 插入入库条目 -->
|
||||
<insert id="insertRestockItem" parameterType="icu.mmmc.InventoryProMax.mapper.entity.RestockItemEntity">
|
||||
INSERT INTO t_restock_items
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
res_id,
|
||||
pro_id,
|
||||
inv_id,
|
||||
title,
|
||||
model,
|
||||
<if test="item.unit != null">
|
||||
unit,
|
||||
</if>
|
||||
count,
|
||||
cost,
|
||||
amount,
|
||||
<if test="item.remarks != null">
|
||||
remarks,
|
||||
</if>
|
||||
<if test="item.createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="VALUES(" suffix=")" suffixOverrides=",">
|
||||
#{item.resId},
|
||||
#{item.proId},
|
||||
#{item.invId},
|
||||
#{item.title},
|
||||
#{item.model},
|
||||
<if test="item.unit != null">
|
||||
#{item.unit},
|
||||
</if>
|
||||
#{item.count},
|
||||
#{item.cost},
|
||||
#{item.amount},
|
||||
<if test="item.remarks != null">
|
||||
#{item.remarks},
|
||||
</if>
|
||||
<if test="item.createTime != null">
|
||||
#{item.createTime},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user