|
@@ -0,0 +1,268 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.client.UserServiceClient;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.dto.VersionDetailDTO;
|
|
|
+import com.diagbot.dto.VersionWrapperDTO;
|
|
|
+import com.diagbot.entity.VersionDetail;
|
|
|
+import com.diagbot.entity.VersionInfo;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.enums.StatusEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.service.impl.VersionDetailServiceImpl;
|
|
|
+import com.diagbot.service.impl.VersionInfoServiceImpl;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.VersionDetailVO;
|
|
|
+import com.diagbot.vo.VersionInfoAllVO;
|
|
|
+import com.diagbot.vo.VersionInfoIdVO;
|
|
|
+import com.diagbot.vo.VersionInfoVO;
|
|
|
+import com.diagbot.vo.VersionWrapperNameVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wangfeng
|
|
|
+ * @Description:
|
|
|
+ * @date 2020-08-06 9:35
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class VersionInfoFacade extends VersionInfoServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ VersionDetailFacade versionDetailFacade;
|
|
|
+ @Autowired
|
|
|
+ VersionDetailServiceImpl versionDetailServiceImpl;
|
|
|
+ @Autowired
|
|
|
+ UserServiceClient userServiceClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询版本信息
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<VersionWrapperDTO> getVersionInfoAll(VersionWrapperNameVO versionWrapperNameVO) {
|
|
|
+
|
|
|
+ IPage<VersionWrapperDTO> queryUserInformation = getVersionInfoAPage(versionWrapperNameVO);
|
|
|
+ List<VersionWrapperDTO> versionInfos = queryUserInformation.getRecords();
|
|
|
+ List<VersionWrapperDTO> versionLists = new ArrayList<VersionWrapperDTO>();
|
|
|
+ // 取出操作人id
|
|
|
+ List<String> modifierid = new ArrayList<>();
|
|
|
+ modifierid = versionInfos.stream().map(ac -> ac.getModifierid()).collect(Collectors.toList());
|
|
|
+ // 根据操作人的id获取操作人信息
|
|
|
+ Map<String, String> userNames = new HashMap<>();
|
|
|
+ if (ListUtil.isNotEmpty(modifierid)) {
|
|
|
+ RespDTO<Map<String, String>> userNamesDTO = userServiceClient.getUserInfoByIds(modifierid);
|
|
|
+ if (userNamesDTO == null || !CommonErrorCode.OK.getCode().equals(userNamesDTO.code)) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "获取所有用户信息失败");
|
|
|
+ }
|
|
|
+ userNames = userNamesDTO.data;
|
|
|
+ }
|
|
|
+ // 当查出的数据不为空时,取到版本id,再去版本明细表中查询详细的信息
|
|
|
+ for (VersionWrapperDTO versionInfo : versionInfos) {
|
|
|
+ VersionWrapperDTO versionList = new VersionWrapperDTO();
|
|
|
+ versionList.setId(versionInfo.getId());
|
|
|
+ versionList.setGmtCreate(versionInfo.getGmtCreate());
|
|
|
+ versionList.setName(versionInfo.getName());
|
|
|
+ versionList.setModifierid(userNames.get(versionInfo.getModifierid()));
|
|
|
+ versionList.setRefreshTime(versionInfo.getRefreshTime());
|
|
|
+ versionList.setStatus(versionInfo.getStatus());
|
|
|
+ versionList.setRemark(versionInfo.getRemark());
|
|
|
+ versionLists.add(versionList);
|
|
|
+ }
|
|
|
+ // 取版本id查明细
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ if (versionInfos != null) {
|
|
|
+ // 当查出的数据不为空时,取到版本id,再去版本明细表中查询详细的信息
|
|
|
+ for (VersionWrapperDTO versionInfo : versionInfos) {
|
|
|
+ ids.add(versionInfo.getId());
|
|
|
+ }
|
|
|
+ // 获取明细信息
|
|
|
+ List<VersionDetailDTO> details = versionDetailFacade.getByIds(ids);
|
|
|
+ Map<Long, List<VersionDetailDTO>> map = new HashMap<>();
|
|
|
+ // 获取所有用户开通的产品信息
|
|
|
+ map = EntityUtil.makeEntityListMap(details, "versionId");
|
|
|
+ if (map.size() > 0) {
|
|
|
+ for (VersionWrapperDTO versionList : versionLists) {
|
|
|
+ List<VersionDetailDTO> userAndProdutUDTO = map.get(versionList.getId());
|
|
|
+ if (ListUtil.isNotEmpty(userAndProdutUDTO)) {
|
|
|
+ versionList.setDetail(userAndProdutUDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return queryUserInformation.setRecords(versionLists);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存版本信息
|
|
|
+ *
|
|
|
+ * @param versionInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean saveVersionInfoAll(VersionInfoVO versionInfoVO) {
|
|
|
+ // 1.判断摸个产品该版本号是否存在名字相同的数据
|
|
|
+ QueryWrapper<VersionInfo> templateInfoFand = new QueryWrapper<>();
|
|
|
+ templateInfoFand
|
|
|
+ .eq("name", versionInfoVO.getName())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+
|
|
|
+ VersionInfo dataInfo = getOne(templateInfoFand, false);
|
|
|
+ if (dataInfo != null) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "该产品该版本号已存在");
|
|
|
+ }
|
|
|
+ //2.把相同产品类型的版本状态修改为0,
|
|
|
+ UpdateWrapper<VersionInfo> versionInfoUp = new UpdateWrapper<>();
|
|
|
+ versionInfoUp
|
|
|
+ .eq("status", StatusEnum.Enable.getKey())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .set("status", StatusEnum.Disable.getKey())
|
|
|
+ .set("modifier", UserUtils.getCurrentPrincipleID())
|
|
|
+ .set("gmt_modified", DateUtil.now());
|
|
|
+ update(new VersionInfo(), versionInfoUp);
|
|
|
+
|
|
|
+ //3.增加版本数据
|
|
|
+ VersionInfo versionInfo = new VersionInfo();
|
|
|
+ versionInfo.setCreator(UserUtils.getCurrentPrincipleID());
|
|
|
+ versionInfo.setGmtCreate(DateUtil.now());
|
|
|
+ versionInfo.setName(versionInfoVO.getName());
|
|
|
+ versionInfo.setGmtModified(DateUtil.now());
|
|
|
+ versionInfo.setModifier(UserUtils.getCurrentPrincipleID());
|
|
|
+ versionInfo.setStatus(String.valueOf(StatusEnum.Enable.getKey()));
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ try {
|
|
|
+ versionInfo.setRefreshTime(sdf.parse(versionInfoVO.getRefreshTime()));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "时间格式有误");
|
|
|
+ }
|
|
|
+ versionInfo.setStatus(String.valueOf(StatusEnum.Enable.getKey()));
|
|
|
+ versionInfo.setRemark(versionInfoVO.getRemark());
|
|
|
+ // 优先保存版本号,成功后再保存明细信息
|
|
|
+ boolean res = save(versionInfo);
|
|
|
+ if (res) {
|
|
|
+ List<VersionDetail> dataNew = new ArrayList<VersionDetail>();
|
|
|
+ List<VersionDetailVO> datas = versionInfoVO.getVersionDetail();
|
|
|
+ if (datas != null && datas.size() > 0) {
|
|
|
+ for (VersionDetailVO data : datas) {
|
|
|
+ VersionDetail versionDetail = new VersionDetail();
|
|
|
+ versionDetail.setCreator(UserUtils.getCurrentPrincipleID());
|
|
|
+ versionDetail.setGmtCreate(DateUtil.now());
|
|
|
+ versionDetail.setGmtModified(DateUtil.now());
|
|
|
+ versionDetail.setModifier(UserUtils.getCurrentPrincipleID());
|
|
|
+ versionDetail.setDescription(data.getDescription());
|
|
|
+ versionDetail.setOrderNo(data.getOrderNo());
|
|
|
+ versionDetail.setTitle(data.getTitle());
|
|
|
+ versionDetail.setVersionId(versionInfo.getId());
|
|
|
+ versionDetail.setRemark(data.getRemark());
|
|
|
+ versionDetail.setStatus(String.valueOf(StatusEnum.Enable.getKey()));
|
|
|
+ dataNew.add(versionDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ res = versionDetailServiceImpl.saveBatch(dataNew);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新
|
|
|
+ *
|
|
|
+ * @param versionInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean updateVersionInfoAll(VersionInfoAllVO versionInfoVO) {
|
|
|
+ // 1.先判断数据是否存在有效
|
|
|
+ VersionInfo versionInfoRes = checkExist(versionInfoVO.getId());
|
|
|
+ //验证是否停用
|
|
|
+ if (versionInfoRes != null
|
|
|
+ && StringUtil.isNotBlank(versionInfoRes.getStatus())
|
|
|
+ && versionInfoRes.getStatus().equals(String.valueOf(StatusEnum.Disable.getKey()))) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "该产品该版本号已停用");
|
|
|
+ }
|
|
|
+ // 2.判断该版本号是否存在名字相同的数据
|
|
|
+ QueryWrapper<VersionInfo> templateInfoFand = new QueryWrapper<>();
|
|
|
+ templateInfoFand
|
|
|
+ .eq("name", versionInfoVO.getName())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+
|
|
|
+ VersionInfo dataInfo = getOne(templateInfoFand, false);
|
|
|
+ if (dataInfo != null && !dataInfo.getId().equals(versionInfoVO.getId())) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "该产品该版本号已存在");
|
|
|
+ }
|
|
|
+ // 3.修改版本信息
|
|
|
+ VersionInfo versionInfo = new VersionInfo();
|
|
|
+ versionInfo.setId(versionInfoVO.getId());// 模板id
|
|
|
+ versionInfo.setName(versionInfoVO.getName());// 模板名称
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ if (versionInfoVO.getRefreshTime() != null) {
|
|
|
+ try {
|
|
|
+ versionInfo.setRefreshTime(sdf.parse(versionInfoVO.getRefreshTime()));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "时间格式有误");
|
|
|
+ // e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ versionInfo.setStatus(String.valueOf(StatusEnum.Enable.getKey()));
|
|
|
+ versionInfo.setRemark(versionInfoVO.getRemark());
|
|
|
+ versionInfo.setGmtModified(DateUtil.now());// 修改时间
|
|
|
+ versionInfo.setModifier(UserUtils.getCurrentPrincipleID());
|
|
|
+ boolean res = updateById(versionInfo);
|
|
|
+ if (!res) {
|
|
|
+ throw new CommonException(CommonErrorCode.UPDATE_INFO_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ *
|
|
|
+ * @param versionInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean cancelVersionInfoAll(VersionInfoIdVO versionInfoVO) {
|
|
|
+ // 1.先判断数据是否存在有效
|
|
|
+ checkExist(versionInfoVO.getId());
|
|
|
+ UpdateWrapper<VersionInfo> versionInfoNew = new UpdateWrapper<>();
|
|
|
+ versionInfoNew
|
|
|
+ .eq("id", versionInfoVO.getId())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .set("modifier", UserUtils.getCurrentPrincipleID())
|
|
|
+ .set("gmt_modified", DateUtil.now());
|
|
|
+ return update(new VersionInfo(), versionInfoNew);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断数据是否存在有效
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ private VersionInfo checkExist(Long id) {
|
|
|
+ // 1.先判断数据是否存在有效
|
|
|
+ QueryWrapper<VersionInfo> VersionInfoFand = new QueryWrapper<>();
|
|
|
+ VersionInfoFand.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("id", id);
|
|
|
+ VersionInfo versionInfo = getOne(VersionInfoFand, false);
|
|
|
+ if (null == versionInfo) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "该数据不存在");
|
|
|
+ }
|
|
|
+ return versionInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|