|
|
|
@ -1,19 +1,37 @@ |
|
|
|
|
package com.dxhy.order.baseservice.module.commodity.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.dxhy.order.baseservice.config.UserCenterConfig; |
|
|
|
|
import com.dxhy.order.baseservice.module.base.service.BaseService; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.dao.CommodityCodeModifyLogDao; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.CommodityCodeEntity; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.CommodityCodeModifyLog; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.GroupCommodity; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.dto.QueryModifyLogDTO; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.dto.UserInfoDTO; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.service.CommodityCodeModifyLogService; |
|
|
|
|
import com.dxhy.order.constant.ConfigureConstant; |
|
|
|
|
import com.dxhy.order.model.PageUtils; |
|
|
|
|
import com.dxhy.order.model.R; |
|
|
|
|
import com.dxhy.order.utils.HttpUtils; |
|
|
|
|
import com.dxhy.order.utils.JsonUtils; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
import lombok.SneakyThrows; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* (CommodityCodeModifyLog)表服务实现类 |
|
|
|
@ -21,14 +39,21 @@ import java.util.List; |
|
|
|
|
* @author 巩权林 |
|
|
|
|
* @since 2023-03-20 15:31:37 |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
@Service("commodityCodeModifyLogService") |
|
|
|
|
public class CommodityCodeModifyLogServiceImpl implements CommodityCodeModifyLogService { |
|
|
|
|
|
|
|
|
|
private static final String LOGGER_MSG = "(物料修改记录表)"; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private CommodityCodeModifyLogDao commodityCodeModifyLogDao; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private BaseService baseService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private UserCenterConfig userCenterConfig; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 比较两个集团物料编码的区别并且保存历史记录 |
|
|
|
|
* |
|
|
|
@ -37,7 +62,7 @@ public class CommodityCodeModifyLogServiceImpl implements CommodityCodeModifyLog |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int saveCommodityCodeDifferenceBetween2(CommodityCodeEntity originOne, CommodityCodeEntity newOne, String modifyUserId) { |
|
|
|
|
public int saveCommodityCodeDifferenceBetween2(CommodityCodeEntity originOne, CommodityCodeEntity newOne, Long modifyUserId) { |
|
|
|
|
if (StringUtils.isBlank(originOne.getId())) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -58,7 +83,7 @@ public class CommodityCodeModifyLogServiceImpl implements CommodityCodeModifyLog |
|
|
|
|
modifyLog.setOriginValue(originValue.toString()); |
|
|
|
|
modifyLog.setOriginValue(originValue.toString()); |
|
|
|
|
modifyLog.setModifyTime(new Date()); |
|
|
|
|
modifyLog.setModifyUserId(modifyUserId); |
|
|
|
|
modifyLog.setModifyUserId(Long.toString(modifyUserId)); |
|
|
|
|
modifyLogs.add(modifyLog); |
|
|
|
|
} |
|
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
@ -67,9 +92,60 @@ public class CommodityCodeModifyLogServiceImpl implements CommodityCodeModifyLog |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 批量插入保存
|
|
|
|
|
return commodityCodeModifyLogDao.batchInsert(modifyLogs); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@SneakyThrows |
|
|
|
|
public PageUtils queryPage(QueryModifyLogDTO dto) { |
|
|
|
|
int pageSize = dto.getPageSize(); |
|
|
|
|
int currPage = dto.getCurrPage(); |
|
|
|
|
PageHelper.startPage(currPage, pageSize); |
|
|
|
|
CommodityCodeModifyLog query = new CommodityCodeModifyLog(); |
|
|
|
|
query.setCommodityCodeId(dto.getCommodityId()); |
|
|
|
|
List<CommodityCodeModifyLog> commodityCodeModifyLogs = commodityCodeModifyLogDao.queryAll(query); |
|
|
|
|
List<String> modifyUserId = commodityCodeModifyLogs.stream().map(CommodityCodeModifyLog::getModifyUserId).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isNotEmpty(modifyUserId)) { |
|
|
|
|
modifyUserId = modifyUserId.stream().distinct().collect(Collectors.toList()); |
|
|
|
|
String requestBody = JsonUtils.getInstance().toJsonString(modifyUserId); |
|
|
|
|
// 如果修改记录的用户id不为空,则进行匹配
|
|
|
|
|
log.info("{},查询用户的接口,url:{},入参:{}", LOGGER_MSG, userCenterConfig.queryUserByIds(), requestBody); |
|
|
|
|
Map<String, String> headMap = new HashMap<>(2); |
|
|
|
|
headMap.put("Content-Type", ConfigureConstant.STRING_APPLICATION_JSON); |
|
|
|
|
HttpServletRequest req = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
|
|
|
|
String requestToken = req.getHeader(ConfigureConstant.DXHY_SSO_SESSION_ID); |
|
|
|
|
headMap.put("Cookie", "dxhy_sso_sessionid=" + requestToken); |
|
|
|
|
String url = userCenterConfig.queryUserByIds(); |
|
|
|
|
String result = HttpUtils.doPostWithHeader(url, requestBody, headMap); |
|
|
|
|
log.info("{},查询用户的接口,返回报文:{}", LOGGER_MSG, result); |
|
|
|
|
if (StringUtils.isEmpty(result)) { |
|
|
|
|
throw new RuntimeException("查询用户信息失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
// 循环插入用户
|
|
|
|
|
JSONObject queryResult = JSONObject.parseObject(result); |
|
|
|
|
if (!StringUtils.equals(queryResult.getString("code"), "0000")) { |
|
|
|
|
log.error("{},查询用户的接口,返回报文:{},查询用户失败", LOGGER_MSG, result); |
|
|
|
|
throw new RuntimeException("查询用户信息失败"); |
|
|
|
|
} |
|
|
|
|
JSONArray userInfoJsonArray = queryResult.getJSONArray("data"); |
|
|
|
|
if (CollectionUtils.isEmpty(userInfoJsonArray)) { |
|
|
|
|
log.error("{},查询用户的接口,返回报文:{},查询用户为空", LOGGER_MSG, result); |
|
|
|
|
throw new RuntimeException("查询用户信息为空"); |
|
|
|
|
} |
|
|
|
|
List<UserInfoDTO> userInfoList = userInfoJsonArray.toJavaList(UserInfoDTO.class); |
|
|
|
|
|
|
|
|
|
// 循环匹配用户
|
|
|
|
|
commodityCodeModifyLogs.forEach(i -> { |
|
|
|
|
UserInfoDTO userInfoDTO = userInfoList.stream() |
|
|
|
|
.filter(j -> StringUtils.equals(Long.toString(j.getUserid()), i.getModifyUserId())) |
|
|
|
|
.findFirst().orElse(null); |
|
|
|
|
i.setModifyUserName(userInfoDTO.getName()); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PageInfo<CommodityCodeModifyLog> pageInfo = new PageInfo<>(commodityCodeModifyLogs); |
|
|
|
|
return new PageUtils(pageInfo.getList(), (int) pageInfo.getTotal(), pageInfo.getPageSize(), pageInfo.getPageNum()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|