|
@@ -7,6 +7,7 @@ import cn.cslg.pas.common.model.request.GroupRequest;
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
import cn.cslg.pas.common.utils.LoginUtils;
|
|
import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
|
+import cn.cslg.pas.common.utils.StringUtils;
|
|
import cn.cslg.pas.common.vo.business.PersonVO;
|
|
import cn.cslg.pas.common.vo.business.PersonVO;
|
|
import cn.cslg.pas.common.vo.business.ProductVO;
|
|
import cn.cslg.pas.common.vo.business.ProductVO;
|
|
import cn.cslg.pas.domain.business.*;
|
|
import cn.cslg.pas.domain.business.*;
|
|
@@ -17,6 +18,7 @@ import cn.cslg.pas.mapper.ProductMapper;
|
|
import cn.cslg.pas.service.common.FileManagerService;
|
|
import cn.cslg.pas.service.common.FileManagerService;
|
|
import cn.cslg.pas.service.permissions.PermissionService;
|
|
import cn.cslg.pas.service.permissions.PermissionService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -26,6 +28,7 @@ import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -35,6 +38,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 产品的Service层
|
|
* 产品的Service层
|
|
|
|
+ *
|
|
* @Author xiexiang
|
|
* @Author xiexiang
|
|
* @Date 2023/10/26
|
|
* @Date 2023/10/26
|
|
*/
|
|
*/
|
|
@@ -69,8 +73,29 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
- List<String> sqls = formatQueryService.reSqls(queryRequest,"product");
|
|
|
|
- sqls= this.loadSearchSql(sqls);
|
|
|
|
|
|
+ List<String> sqls = formatQueryService.reSqls(queryRequest, "product");
|
|
|
|
+ sqls = this.loadSearchSql(sqls);
|
|
|
|
+ //根据sql查询产品信息
|
|
|
|
+ List<ProductVO> productVOS = productMapper.getProduct(sqls.get(0), sqls.get(1), sqls.get(2));
|
|
|
|
+ //查询总数
|
|
|
|
+ Long total = productMapper.getProductCount(sqls.get(0));
|
|
|
|
+ //装载产品信息
|
|
|
|
+ this.loadProduct(productVOS);
|
|
|
|
+ //装载返回信息
|
|
|
|
+ Records records = new Records();
|
|
|
|
+ records.setCurrent(queryRequest.getCurrent());
|
|
|
|
+ records.setSize(queryRequest.getSize());
|
|
|
|
+ records.setData(productVOS);
|
|
|
|
+ records.setTotal(total);
|
|
|
|
+ return records;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Object selectProduct(QueryRequest queryRequest) throws Exception {
|
|
|
|
+ List<String> sqls = formatQueryService.reSqls(queryRequest, "product");
|
|
|
|
+ sqls = this.loadSearchSql(sqls);
|
|
|
|
+ sqls = this.loadProductIdsSql(sqls, queryRequest.getProductIds());
|
|
|
|
+
|
|
//根据sql查询产品信息
|
|
//根据sql查询产品信息
|
|
List<ProductVO> productVOS = productMapper.getProduct(sqls.get(0), sqls.get(1), sqls.get(2));
|
|
List<ProductVO> productVOS = productMapper.getProduct(sqls.get(0), sqls.get(1), sqls.get(2));
|
|
//查询总数
|
|
//查询总数
|
|
@@ -88,6 +113,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
/**
|
|
* 新增产品
|
|
* 新增产品
|
|
|
|
+ *
|
|
* @param object
|
|
* @param object
|
|
* @param files
|
|
* @param files
|
|
* @return
|
|
* @return
|
|
@@ -140,10 +166,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
}
|
|
}
|
|
//判断可见类型:
|
|
//判断可见类型:
|
|
Integer showType = productDTO.getShowType();
|
|
Integer showType = productDTO.getShowType();
|
|
- if(showType != 0 && showType != 1){
|
|
|
|
|
|
+ if (showType != 0 && showType != 1) {
|
|
List<String> showPersonIds = productDTO.getShowPersonIds();
|
|
List<String> showPersonIds = productDTO.getShowPersonIds();
|
|
//0所有人可见,1本人可见
|
|
//0所有人可见,1本人可见
|
|
- if(showPersonIds != null && showPersonIds.size() != 0){
|
|
|
|
|
|
+ if (showPersonIds != null && showPersonIds.size() != 0) {
|
|
for (String showPersonId : showPersonIds) {
|
|
for (String showPersonId : showPersonIds) {
|
|
AssoProductPerson assoProductPerson = new AssoProductPerson();
|
|
AssoProductPerson assoProductPerson = new AssoProductPerson();
|
|
assoProductPerson.setProductId(product.getId());
|
|
assoProductPerson.setProductId(product.getId());
|
|
@@ -161,11 +187,11 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(assoProductPeople != null && assoProductPeople.size() != 0){
|
|
|
|
|
|
+ if (assoProductPeople != null && assoProductPeople.size() != 0) {
|
|
assoProductPersonService.saveBatch(assoProductPeople);
|
|
assoProductPersonService.saveBatch(assoProductPeople);
|
|
}
|
|
}
|
|
//判断文件是否为空
|
|
//判断文件是否为空
|
|
- if(files != null && files.size() != 0) {
|
|
|
|
|
|
+ if (files != null && files.size() != 0) {
|
|
try {
|
|
try {
|
|
//调用上传文件接口
|
|
//调用上传文件接口
|
|
List<String> guids = fileManagerService.uploadFileGetGuid(files);
|
|
List<String> guids = fileManagerService.uploadFileGetGuid(files);
|
|
@@ -190,6 +216,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
/**
|
|
* 删除产品
|
|
* 删除产品
|
|
|
|
+ *
|
|
* @param ids
|
|
* @param ids
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -218,6 +245,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
/**
|
|
* 更新产品
|
|
* 更新产品
|
|
|
|
+ *
|
|
* @param object
|
|
* @param object
|
|
* @param files
|
|
* @param files
|
|
* @return
|
|
* @return
|
|
@@ -226,7 +254,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
//object to updateProductDTO
|
|
//object to updateProductDTO
|
|
UpdateProductDTO updateProductDTO = (UpdateProductDTO) object;
|
|
UpdateProductDTO updateProductDTO = (UpdateProductDTO) object;
|
|
- if(updateProductDTO == null || updateProductDTO.getId() == null){
|
|
|
|
|
|
+ if (updateProductDTO == null || updateProductDTO.getId() == null) {
|
|
throw new XiaoShiException("参数错误");
|
|
throw new XiaoShiException("参数错误");
|
|
}
|
|
}
|
|
//获取登陆人信息 用于设置创建人
|
|
//获取登陆人信息 用于设置创建人
|
|
@@ -244,7 +272,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper.eq(Product::getName, name);
|
|
queryWrapper.eq(Product::getName, name);
|
|
List<Product> products = this.list(queryWrapper);
|
|
List<Product> products = this.list(queryWrapper);
|
|
- if(!updateProductDTO.getName().equals(product.getName()) && products.size() != 0){
|
|
|
|
|
|
+ if (!updateProductDTO.getName().equals(product.getName()) && products.size() != 0) {
|
|
throw new XiaoShiException("名称重复");
|
|
throw new XiaoShiException("名称重复");
|
|
}
|
|
}
|
|
BeanUtils.copyProperties(updateProductDTO, product);
|
|
BeanUtils.copyProperties(updateProductDTO, product);
|
|
@@ -279,10 +307,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
}
|
|
}
|
|
//判断可见类型:
|
|
//判断可见类型:
|
|
Integer showType = updateProductDTO.getShowType();
|
|
Integer showType = updateProductDTO.getShowType();
|
|
- if(showType != 0 && showType != 1){
|
|
|
|
|
|
+ if (showType != 0 && showType != 1) {
|
|
List<String> showPersonIds = updateProductDTO.getShowPersonIds();
|
|
List<String> showPersonIds = updateProductDTO.getShowPersonIds();
|
|
//0所有人可见,1本人可见
|
|
//0所有人可见,1本人可见
|
|
- if(showPersonIds != null && showPersonIds.size() != 0){
|
|
|
|
|
|
+ if (showPersonIds != null && showPersonIds.size() != 0) {
|
|
for (String showPersonId : showPersonIds) {
|
|
for (String showPersonId : showPersonIds) {
|
|
AssoProductPerson assoProductPerson = new AssoProductPerson();
|
|
AssoProductPerson assoProductPerson = new AssoProductPerson();
|
|
assoProductPerson.setProductId(product.getId());
|
|
assoProductPerson.setProductId(product.getId());
|
|
@@ -300,7 +328,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(assoProductPeople != null && assoProductPeople.size() != 0){
|
|
|
|
|
|
+ if (assoProductPeople != null && assoProductPeople.size() != 0) {
|
|
assoProductPersonService.saveBatch(assoProductPeople);
|
|
assoProductPersonService.saveBatch(assoProductPeople);
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -313,20 +341,20 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
List<String> fileGuIds = assoFiles.stream().map(AssoProductFile::getFileGuid).collect(Collectors.toList());
|
|
List<String> fileGuIds = assoFiles.stream().map(AssoProductFile::getFileGuid).collect(Collectors.toList());
|
|
//获取更新后的附件ids
|
|
//获取更新后的附件ids
|
|
List<String> updateFileGuIds = new ArrayList<>();
|
|
List<String> updateFileGuIds = new ArrayList<>();
|
|
- if(updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0){
|
|
|
|
|
|
+ if (updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0) {
|
|
updateFileGuIds = updateProductDTO.getGuids();
|
|
updateFileGuIds = updateProductDTO.getGuids();
|
|
fileGuIds.retainAll(updateFileGuIds);
|
|
fileGuIds.retainAll(updateFileGuIds);
|
|
}
|
|
}
|
|
//做差获得被删除的文件id
|
|
//做差获得被删除的文件id
|
|
- if(fileGuIds.size() != 0){
|
|
|
|
|
|
+ if (fileGuIds.size() != 0) {
|
|
//根据文件id删除产品与文件关联表记录
|
|
//根据文件id删除产品与文件关联表记录
|
|
LambdaQueryWrapper<AssoProductFile> deleteWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<AssoProductFile> deleteWrapper = new LambdaQueryWrapper<>();
|
|
deleteWrapper.in(AssoProductFile::getFileGuid, fileGuIds);
|
|
deleteWrapper.in(AssoProductFile::getFileGuid, fileGuIds);
|
|
assoProductFileService.remove(deleteWrapper);
|
|
assoProductFileService.remove(deleteWrapper);
|
|
//远程删除服务器上的文件
|
|
//远程删除服务器上的文件
|
|
- try{
|
|
|
|
|
|
+ try {
|
|
fileManagerService.deleteFileFromFMS(fileGuIds);
|
|
fileManagerService.deleteFileFromFMS(fileGuIds);
|
|
- } catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -353,7 +381,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public GroupVO getGroup(GroupRequest groupRequest,String tableName) throws Exception {
|
|
|
|
|
|
+ public GroupVO getGroup(GroupRequest groupRequest, String tableName) throws Exception {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -369,6 +397,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
/**
|
|
/**
|
|
* 装载productVO
|
|
* 装载productVO
|
|
|
|
+ *
|
|
* @param productVOS
|
|
* @param productVOS
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
@@ -377,7 +406,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
List<Integer> ids = new ArrayList<>();
|
|
List<Integer> ids = new ArrayList<>();
|
|
productVOS.forEach(
|
|
productVOS.forEach(
|
|
item -> {
|
|
item -> {
|
|
- if(item.getCreateId() != null){
|
|
|
|
|
|
+ if (item.getCreateId() != null) {
|
|
createIds.add(item.getCreateId());
|
|
createIds.add(item.getCreateId());
|
|
}
|
|
}
|
|
if (item.getId() != null) {
|
|
if (item.getId() != null) {
|
|
@@ -409,8 +438,8 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
if (guids.size() != 0) {
|
|
if (guids.size() != 0) {
|
|
String res = fileManagerService.getSystemFileFromFMS(guids);
|
|
String res = fileManagerService.getSystemFileFromFMS(guids);
|
|
systemFiles = JSONObject.parseArray(res, SystemFile.class);
|
|
systemFiles = JSONObject.parseArray(res, SystemFile.class);
|
|
- if(systemFiles==null){
|
|
|
|
- systemFiles=new ArrayList<>();
|
|
|
|
|
|
+ if (systemFiles == null) {
|
|
|
|
+ systemFiles = new ArrayList<>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -418,7 +447,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
for (ProductVO productVO : productVOS) {
|
|
for (ProductVO productVO : productVOS) {
|
|
//装载人员信息
|
|
//装载人员信息
|
|
Personnel personnel = personnels.stream().filter(item -> item.getId().toString().equals(productVO.getCreateId())).findFirst().orElse(null);
|
|
Personnel personnel = personnels.stream().filter(item -> item.getId().toString().equals(productVO.getCreateId())).findFirst().orElse(null);
|
|
- if(personnel != null){
|
|
|
|
|
|
+ if (personnel != null) {
|
|
productVO.setCreateName(personnel.getPersonnelName());
|
|
productVO.setCreateName(personnel.getPersonnelName());
|
|
} else {
|
|
} else {
|
|
throw new XiaoShiException("未获取到当前登陆人信息");
|
|
throw new XiaoShiException("未获取到当前登陆人信息");
|
|
@@ -497,23 +526,39 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
|
|
|
|
|
|
//装载查询语句
|
|
//装载查询语句
|
|
//装载查询语句
|
|
//装载查询语句
|
|
- private List<String> loadSearchSql(List<String> sqls){
|
|
|
|
- PersonnelVO personnelVO =cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
|
- String id =personnelVO.getId();
|
|
|
|
- Integer tenantId =personnelVO.getTenantId();
|
|
|
|
- String rootSql ="product.create_id="+id+" or(product.show_type =0 and product.tenant_id ="+tenantId+") or ( product.id in (select product_id from asso_product_person where" +
|
|
|
|
- " person_id="+id+" and role=0)) or (product.show_type=2 and product.id in (select product_id from asso_product_person where" +
|
|
|
|
- " person_id="+id+" and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
|
|
|
|
- " person_id="+id+" and role=2))";
|
|
|
|
- if(sqls.get(0)!=null&&!sqls.get(0).equals(""))
|
|
|
|
- {
|
|
|
|
- sqls.set(0,"("+rootSql+") and"+"("+sqls.get(0)+")");
|
|
|
|
|
|
+ private List<String> loadSearchSql(List<String> sqls) {
|
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
|
+ String id = personnelVO.getId();
|
|
|
|
+ Integer tenantId = personnelVO.getTenantId();
|
|
|
|
+ String rootSql = "product.create_id=" + id + " or(product.show_type =0 and product.tenant_id =" + tenantId + ") or ( product.id in (select product_id from asso_product_person where" +
|
|
|
|
+ " person_id=" + id + " and role=0)) or (product.show_type=2 and product.id in (select product_id from asso_product_person where" +
|
|
|
|
+ " person_id=" + id + " and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
|
|
|
|
+ " person_id=" + id + " and role=2))";
|
|
|
|
+ if (sqls.get(0) != null && !sqls.get(0).equals("")) {
|
|
|
|
+ sqls.set(0, "(" + rootSql + ")" + " and " + "(" + sqls.get(0) + ")");
|
|
|
|
|
|
|
|
+ } else {
|
|
|
|
+ sqls.set(0, rootSql);
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- sqls.set(0,rootSql);
|
|
|
|
|
|
+
|
|
|
|
+ return sqls;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //装载查询产品语句
|
|
|
|
+ private List<String> loadProductIdsSql(List<String> sqls, List<Integer> ids) {
|
|
|
|
+ String rootSql = "";
|
|
|
|
+ if (CollectionUtils.isEmpty(ids)) {
|
|
|
|
+ rootSql = "product.id in " + "(" + 0 + ")";
|
|
|
|
+ } else {
|
|
|
|
+ rootSql = "product.id in " + "(" + String.join(",", ids.stream().map(Object::toString).collect(Collectors.toList())) + ")";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (sqls.get(0) != null && !sqls.get(0).equals("")) {
|
|
|
|
+ sqls.set(0, "(" + rootSql + ")" + " and " + "(" + sqls.get(0) + ")");
|
|
|
|
+ } else {
|
|
|
|
+ sqls.set(0, rootSql);
|
|
|
|
+ }
|
|
return sqls;
|
|
return sqls;
|
|
|
|
|
|
}
|
|
}
|