|
|
|
@ -1,13 +1,21 @@ |
|
|
|
package com.dreamchaser.depository_manage.service.impl; |
|
|
|
|
|
|
|
import com.dreamchaser.depository_manage.entity.Group; |
|
|
|
import com.dreamchaser.depository_manage.entity.GroupInfo; |
|
|
|
import com.dreamchaser.depository_manage.entity.*; |
|
|
|
import com.dreamchaser.depository_manage.exception.MyException; |
|
|
|
import com.dreamchaser.depository_manage.mapper.DepositoryMapper; |
|
|
|
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; |
|
|
|
import com.dreamchaser.depository_manage.mapper.GroupMapper; |
|
|
|
import com.dreamchaser.depository_manage.mapper.MaterialMapper; |
|
|
|
import com.dreamchaser.depository_manage.pojo.GroupInfoP; |
|
|
|
import com.dreamchaser.depository_manage.service.GroupService; |
|
|
|
import com.dreamchaser.depository_manage.utils.DateUtil; |
|
|
|
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
|
|
|
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|
|
|
import com.dreamchaser.depository_manage.utils.WordUtil; |
|
|
|
import org.redisson.api.RLock; |
|
|
|
import org.redisson.api.RedissonClient; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
@ -23,6 +31,19 @@ public class GroupServiceImpl implements GroupService { |
|
|
|
@Autowired |
|
|
|
MaterialMapper materialMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
DepositoryRecordMapper depositoryRecordMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedissonClient redissonClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisTemplate<String, String> redisTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
DepositoryMapper depositoryMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于查找所有套餐 |
|
|
|
* @return |
|
|
|
@ -437,6 +458,112 @@ public class GroupServiceImpl implements GroupService { |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 插入一条出库记录 |
|
|
|
* @param map 具体数据 |
|
|
|
* @param userToken 出库申请人 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Integer insertApplicationOutRecord(Map<String, Object> map, UserByPort userToken) { |
|
|
|
// 用于存储出库数据
|
|
|
|
Map<String,Object> paramForOut = new HashMap<>(); |
|
|
|
paramForOut.put("departmenthead",map.get("departmenthead")); |
|
|
|
paramForOut.put("applicantId",userToken.getId()); |
|
|
|
// 获取当前要出库的套餐数量
|
|
|
|
Integer quantityForGroup = ObjectFormatUtil.toInteger(map.get("quantity")); |
|
|
|
// 获取要出库的套餐
|
|
|
|
Integer gid = ObjectFormatUtil.toInteger(map.get("gid")); |
|
|
|
// 获取要出库套餐的具体信息
|
|
|
|
List<GroupInfo> groupInfoByGid = groupMapper.findGroupInfoByGid(gid); |
|
|
|
// 用于统计出库物料总数
|
|
|
|
Integer quantityForTotal = 0; |
|
|
|
// 用于统计出库物料金额总数
|
|
|
|
double priceForTotal = 0; |
|
|
|
|
|
|
|
for (GroupInfo groupInfo : groupInfoByGid) { |
|
|
|
// 获取具体信息
|
|
|
|
// 获取当前物料库存信息
|
|
|
|
Map<String, Object> paramForMid = new HashMap<>(); |
|
|
|
paramForMid.put("mid", groupInfo.getMid()); |
|
|
|
List<Inventory> inventory = materialMapper.findInventory(paramForMid); |
|
|
|
quantityForTotal += quantityForGroup * groupInfo.getQuantity(); |
|
|
|
priceForTotal += inventory.get(0).getPrice() * 100 * quantityForGroup; |
|
|
|
} |
|
|
|
paramForOut.put("quantity",quantityForTotal); |
|
|
|
paramForOut.put("price",priceForTotal); |
|
|
|
paramForOut.put("applicantTime",System.currentTimeMillis()); |
|
|
|
paramForOut.put("istransfer", 2); |
|
|
|
paramForOut.put("state", "待部门负责人审核"); |
|
|
|
paramForOut.put("applyRemark", map.get("applyRemark")); |
|
|
|
Administration company = LinkInterfaceUtil.getCompany(userToken.getMaindeparment(), userToken); |
|
|
|
// 构造出库订单编码
|
|
|
|
String code = createOutCode( "outOrderNumber", company.getName()); |
|
|
|
paramForOut.put("code", code); |
|
|
|
paramForOut.put("pass", 3); |
|
|
|
Integer integer = depositoryRecordMapper.insertApplicationOutRecord(paramForOut); |
|
|
|
Object parentId = paramForOut.get("id"); |
|
|
|
|
|
|
|
// 用于存储申请数
|
|
|
|
Integer result = 0; |
|
|
|
|
|
|
|
// 获取当前部门仓库
|
|
|
|
List<Depository> depositoryByAdminorg = depositoryMapper.findDepositoryByAdminorg(userToken.getMaindeparment().toString()); |
|
|
|
for (GroupInfo groupInfo : groupInfoByGid) { |
|
|
|
// 用于存储出库数据
|
|
|
|
Map<String,Object> paramForOutMin = new HashMap<>(); |
|
|
|
paramForOutMin.put("parentId", parentId); |
|
|
|
// 套餐中的具体信息
|
|
|
|
// 实际要出库的物料库存数量
|
|
|
|
Integer quantity = groupInfo.getQuantity() * quantityForGroup; |
|
|
|
// 实际出库的仓库编号
|
|
|
|
int did = -1; |
|
|
|
// 实际出库的库存编号
|
|
|
|
int mid = -1; |
|
|
|
// 用于查询各仓库中对应物料的库存
|
|
|
|
Map<String, Object> paramForInventory = new HashMap<>(); |
|
|
|
paramForInventory.put("mid", groupInfo.getMid()); |
|
|
|
// 查询各仓库中是否有符合对应数量的库存
|
|
|
|
for (Depository depository : depositoryByAdminorg) { |
|
|
|
paramForInventory.put("did", depository.getId()); |
|
|
|
// 获取对应库存
|
|
|
|
Inventory inventoryByMidAndDid = materialMapper.findInventoryByMidAndDid(paramForInventory); |
|
|
|
if (inventoryByMidAndDid.getQuantity() > quantity) { |
|
|
|
// 如果当前库存充足
|
|
|
|
did = depository.getId(); |
|
|
|
mid = inventoryByMidAndDid.getId(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (did != -1) { |
|
|
|
// 如果有正确的仓库
|
|
|
|
paramForOutMin.put("depositoryId", did); |
|
|
|
paramForOutMin.put("mid",mid); |
|
|
|
paramForOutMin.put("trueOut", 0); |
|
|
|
paramForOutMin.put("quantity", quantity); |
|
|
|
paramForOutMin.put("code", map.get("code")); |
|
|
|
paramForOutMin.put("placeId", 0); |
|
|
|
result += depositoryRecordMapper.insertApplicationOutRecordMin(paramForOutMin); |
|
|
|
}else{ |
|
|
|
throw new MyException(groupInfo.getMname() + ",库存不足"); |
|
|
|
} |
|
|
|
} |
|
|
|
map.put("id",parentId); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据套餐编号获取套餐具体信息 |
|
|
|
* @param gid 待查讯套餐编号 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<GroupInfo> findGroupInfoByGid(Integer gid) { |
|
|
|
return groupMapper.findGroupInfoByGid(gid); |
|
|
|
} |
|
|
|
|
|
|
|
// 用于执行线程任务
|
|
|
|
class Task implements Callable<Object> { |
|
|
|
|
|
|
|
@ -563,4 +690,30 @@ public class GroupServiceImpl implements GroupService { |
|
|
|
String code = "g-"+String.format("%05d", num + 1); |
|
|
|
return code; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 生成出库单号 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String createOutCode( String key, String mainDeparmentName) { |
|
|
|
RLock lock = redissonClient.getLock(key); |
|
|
|
// 入库单号(公司简称+仓库简称+年月日+数字(位数设置>=9))
|
|
|
|
String code = "GK"; |
|
|
|
String nowTime = DateUtil.getNowTime(); |
|
|
|
lock.lock(5, TimeUnit.SECONDS); |
|
|
|
String orderNumber = redisTemplate.opsForValue().get(key); |
|
|
|
if (orderNumber == null) { |
|
|
|
redisTemplate.opsForValue().set(key, "1", DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); |
|
|
|
orderNumber = "1"; |
|
|
|
} |
|
|
|
int newNumber = ObjectFormatUtil.toInteger(orderNumber) + 1; |
|
|
|
redisTemplate.boundValueOps(key).set(String.valueOf(newNumber), DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); |
|
|
|
lock.unlock(); |
|
|
|
orderNumber = String.format("%09d", ObjectFormatUtil.toInteger(orderNumber)); |
|
|
|
mainDeparmentName = WordUtil.getPinYinHeadChar(mainDeparmentName);code = code + mainDeparmentName + nowTime + orderNumber; |
|
|
|
|
|
|
|
return code; |
|
|
|
} |
|
|
|
} |
|
|
|
|