@ -1,10 +1,12 @@
package com.dreamchaser.depository_manage.service.impl ;
import com.alibaba.fastjson.JSONObject ;
import com.dreamchaser.depository_manage.entity.* ;
import com.dreamchaser.depository_manage.exception.MyException ;
import com.dreamchaser.depository_manage.mapper.* ;
import com.dreamchaser.depository_manage.pojo.GroupInfoP ;
import com.dreamchaser.depository_manage.pojo.MaterialAndPlaceForView ;
import com.dreamchaser.depository_manage.pojo.ResultForGroupReturn ;
import com.dreamchaser.depository_manage.pojo.RoleAndDepository ;
import com.dreamchaser.depository_manage.service.DepositoryRecordService ;
import com.dreamchaser.depository_manage.service.GroupService ;
@ -57,6 +59,9 @@ public class GroupServiceImpl implements GroupService {
@Autowired
RoleMapper roleMapper ;
@Autowired
QyWxOperationService qyWxOperationService ;
/ * *
* 用于查找所有组合
*
@ -704,7 +709,7 @@ public class GroupServiceImpl implements GroupService {
* /
@Transactional ( rollbackFor = Exception . class )
@Override
public Integer insertApplicationInRecord ( Map < String , Object > map , UserByPort userToken ) {
public Integer insertApplicationInRecord ( Map < String , Object > map , UserByPort userToken , String userAgent ) {
// 获取当前提交数
@ -713,6 +718,14 @@ public class GroupServiceImpl implements GroupService {
// 用于存储申请数
Integer result = 0 ;
// 定义列表用于储存入库单id
List < Integer > recordIds = new ArrayList < > ( ) ;
// 定义列表用于存储入库仓库id
List < Integer > depositoryIds = new ArrayList < > ( ) ;
// 定义列表用于存储展示的入库单id
List < Integer > showRecordIds = new ArrayList < > ( ) ;
// 循环参数列表
for ( String temp : params ) {
@ -722,10 +735,87 @@ public class GroupServiceImpl implements GroupService {
paramForMethod . put ( "placeId" , map . get ( "placeId" + temp ) ) ;
paramForMethod . put ( "depositoryId" , map . get ( "depositoryId" + temp ) ) ;
paramForMethod . put ( "applyRemark" , map . get ( "applyRemark" + temp ) ) ;
result + = insertOrUpdateInventoryForGroupInfo ( paramForMethod , userToken , true ) ;
ResultForGroupReturn resultForGroupReturn = insertOrUpdateInventoryForGroupInfo ( paramForMethod , userToken ) ;
// 添加当前入库数目
result + = resultForGroupReturn . getResult ( ) ;
// 获取需要审批的入库订单
recordIds . addAll ( resultForGroupReturn . getRecordIds ( ) ) ;
// 获取需要审批的入库订单的仓库
depositoryIds . addAll ( resultForGroupReturn . getDepositoryIds ( ) ) ;
// 获取用于展示的入库订单
showRecordIds . addAll ( resultForGroupReturn . getShowRecordIds ( ) ) ;
}
result + = insertOrUpdateInventoryForGroupInfo ( map , userToken , false ) ;
ResultForGroupReturn resultForGroupReturn = insertOrUpdateInventoryForGroupInfo ( map , userToken ) ;
// 添加当前入库数目
result + = resultForGroupReturn . getResult ( ) ;
// 获取需要审批的入库订单
recordIds . addAll ( resultForGroupReturn . getRecordIds ( ) ) ;
// 获取需要审批的入库订单的仓库
depositoryIds . addAll ( resultForGroupReturn . getDepositoryIds ( ) ) ;
// 获取用于展示的入库订单
showRecordIds . addAll ( resultForGroupReturn . getShowRecordIds ( ) ) ;
// 开启一个线程用于发送审批
new Thread ( new Runnable ( ) {
@Override
public void run ( ) {
Map < Integer , List < Integer > > depositoryIdToRecordId = new HashMap < > ( ) ;
for ( int i = 0 ; i < recordIds . size ( ) ; i + + ) {
Integer recordId = recordIds . get ( i ) ;
if ( recordId ! = null ) {
// 如果当前id不是空 获取对应的入库仓库id
Integer depositoryId = depositoryIds . get ( i ) ;
// 将对应仓库与订单id添加映射关系
List < Integer > integers = depositoryIdToRecordId . get ( depositoryId ) ;
if ( integers ! = null ) {
// 如果有对应关系
integers . add ( recordId ) ;
} else {
// 如果没有
integers = new ArrayList < > ( ) ;
integers . add ( recordId ) ;
depositoryIdToRecordId . put ( depositoryId , integers ) ;
}
}
}
// 获取遍历器
Iterator < Integer > iterator = depositoryIdToRecordId . keySet ( ) . iterator ( ) ;
if ( iterator . hasNext ( ) ) {
// 获取当前仓库
Integer next = iterator . next ( ) ;
// 获取入库到当前仓库的订单id
List < Integer > integerList = depositoryIdToRecordId . get ( next ) ;
// 获取当前仓库的管理员
List < RoleAndDepository > depositoryIdForIn = roleMapper . findRoleAndDepositoryByDepositoryIdForIn ( next ) ;
// 用于存储当前仓库的管理员企业微信userId
StringBuilder sb = new StringBuilder ( ) ;
for ( RoleAndDepository depository : depositoryIdForIn
) {
// 获取管理员数据
UserByPort userByPort = LinkInterfaceUtil . FindUserById ( depository . getUserId ( ) , userToken ) ;
String workwechat = userByPort . getWorkwechat ( ) ;
if ( workwechat = = null | | "" . equals ( workwechat ) ) {
workwechat = userByPort . getWechat ( ) ;
}
sb . append ( workwechat ) . append ( "," ) ;
}
JSONObject jsonObject = qyWxOperationService . sendApprovalTemplateIn ( userAgent , userToken , integerList , sb . toString ( ) ) ;
String sp_no = jsonObject . getString ( "sp_no" ) ;
Map < String , Object > QyWxApprovalMap = new HashMap < > ( ) ;
QyWxApprovalMap . put ( "sp_no" , sp_no ) ;
QyWxApprovalMap . put ( "mainId" , integerList . toString ( ) ) ;
QyWxApprovalMap . put ( "mainGidId" , showRecordIds . toString ( ) ) ;
redisTemplate . opsForHash ( ) . putAll ( sp_no , QyWxApprovalMap ) ;
// 设置过期为7天
redisTemplate . expire ( sp_no , 7 , TimeUnit . DAYS ) ;
}
}
} ) . start ( ) ;
return result ;
}
@ -735,10 +825,9 @@ public class GroupServiceImpl implements GroupService {
*
* @param map 入库数据
* @param userToken 入库人员
* @param flag 标志是否需要保存入库单号 ( true时不需要 , false时需要 )
* @return
* /
Integer insertOrUpdateInventoryForGroupInfo ( Map < String , Object > map , UserByPort userToken , boolean flag ) {
ResultForGroupReturn insertOrUpdateInventoryForGroupInfo ( Map < String , Object > map , UserByPort userToken ) {
// 用于存储申请数
Integer result = 0 ;
@ -746,7 +835,8 @@ public class GroupServiceImpl implements GroupService {
List < Integer > recordIds = new ArrayList < > ( ) ;
// 定义列表用于存储入库仓库id
List < Integer > depositoryIds = new ArrayList < > ( ) ;
// 定义列表用于存储展示的入库单id
List < Integer > showRecordIds = new ArrayList < > ( ) ;
// 获取入库的仓库
Integer depositoryId = ObjectFormatUtil . toInteger ( map . get ( "depositoryId" ) ) ;
@ -763,7 +853,6 @@ public class GroupServiceImpl implements GroupService {
// 定义参数用与入库
Map < String , Object > insertForApplicationInRecord = new HashMap < > ( ) ;
insertForApplicationInRecord . put ( "applicantId" , userToken . getId ( ) ) ;
// 获取当前入库的组合数量
@ -791,6 +880,7 @@ public class GroupServiceImpl implements GroupService {
insertForApplicationInRecord . put ( "mid" , groupInfo . getMid ( ) ) ;
insertForApplicationInRecord . put ( "quantity" , String . valueOf ( groupInfo . getQuantity ( ) * quantityForGroup ) ) ;
insertForApplicationInRecord . put ( "code" , groupInfo . getMcode ( ) ) ;
insertForApplicationInRecord . put ( "toGroupId" , gid ) ;
if ( "-1" . equals ( unit ) ) {
// 如果是基础单位
insertForApplicationInRecord . put ( "price" , String . valueOf ( 0 ) ) ;
@ -831,8 +921,15 @@ public class GroupServiceImpl implements GroupService {
insertForApplicationInRecord . put ( "applicant_time" , System . currentTimeMillis ( ) ) ;
// 添加一个组合订单用于展示
depositoryRecordMapper . insertApplicationInRecord ( insertForApplicationInRecord ) ;
showRecordIds . add ( ObjectFormatUtil . toInteger ( insertForApplicationInRecord . get ( "id" ) ) ) ;
insertForApplicationInRecord . remove ( "id" ) ;
return result ;
ResultForGroupReturn resultForGroupReturn = new ResultForGroupReturn ( ) ;
resultForGroupReturn . setRecordIds ( recordIds ) ;
resultForGroupReturn . setDepositoryIds ( depositoryIds ) ;
resultForGroupReturn . setShowRecordIds ( showRecordIds ) ;
resultForGroupReturn . setResult ( result ) ;
return resultForGroupReturn ;
}
/ * *