|
@@ -2,7 +2,9 @@ package org.jeecg.modules.ctop.controller;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.Product;
|
|
import cn.com.ctop.common.module.entity.Product;
|
|
import cn.com.ctop.common.module.entity.Project;
|
|
import cn.com.ctop.common.module.entity.Project;
|
|
|
|
+import cn.com.ctop.common.module.entity.UserCompany;
|
|
import cn.com.ctop.common.module.mapper.ProjectMapper;
|
|
import cn.com.ctop.common.module.mapper.ProjectMapper;
|
|
|
|
+import cn.com.ctop.common.module.mapper.UserCompanyMapper;
|
|
import cn.com.ctop.common.module.service.IProductService;
|
|
import cn.com.ctop.common.module.service.IProductService;
|
|
import cn.com.ctop.common.module.service.ISysRoleExtService;
|
|
import cn.com.ctop.common.module.service.ISysRoleExtService;
|
|
import cn.com.ctop.common.module.service.IUserAllocationService;
|
|
import cn.com.ctop.common.module.service.IUserAllocationService;
|
|
@@ -28,6 +30,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -54,6 +57,9 @@ public class ProductController {
|
|
private IProductService productService;
|
|
private IProductService productService;
|
|
@Autowired
|
|
@Autowired
|
|
private ISysRoleExtService sysRoleService;
|
|
private ISysRoleExtService sysRoleService;
|
|
|
|
+ @Resource
|
|
|
|
+ private UserCompanyMapper userCompanyMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 分页列表查询
|
|
* 分页列表查询
|
|
*
|
|
*
|
|
@@ -72,10 +78,23 @@ public class ProductController {
|
|
Result<IPage<Product>> result = new Result<>();
|
|
Result<IPage<Product>> result = new Result<>();
|
|
String productName = product.getProductName();
|
|
String productName = product.getProductName();
|
|
product.setProductName(null);
|
|
product.setProductName(null);
|
|
|
|
+ String userId = product.getUserId();
|
|
|
|
+ product.setUserId(null);
|
|
|
|
+
|
|
QueryWrapper<Product> queryWrapper = QueryGenerator.initQueryWrapper(product, req.getParameterMap());
|
|
QueryWrapper<Product> queryWrapper = QueryGenerator.initQueryWrapper(product, req.getParameterMap());
|
|
if (!Check.isNull(productName)) {
|
|
if (!Check.isNull(productName)) {
|
|
queryWrapper.like("product_name", productName);
|
|
queryWrapper.like("product_name", productName);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ String roleCode = sysRoleService.getRoleCodeByUserId(userId);
|
|
|
|
+ if (!"admin".equals(roleCode)) {
|
|
|
|
+ QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ userCompanyQueryWrapper.eq("user_id", userId);
|
|
|
|
+ userCompanyQueryWrapper.orderByDesc("create_time");
|
|
|
|
+ userCompanyQueryWrapper.last("limit 1");
|
|
|
|
+ UserCompany userCompany = userCompanyMapper.selectOne(userCompanyQueryWrapper);
|
|
|
|
+ queryWrapper.eq("company_id", userCompany.getCompanyId());
|
|
|
|
+ }
|
|
Page<Product> page = new Page<>(pageNo, pageSize);
|
|
Page<Product> page = new Page<>(pageNo, pageSize);
|
|
IPage<Product> pageList = productService.page(page, queryWrapper);
|
|
IPage<Product> pageList = productService.page(page, queryWrapper);
|
|
result.setSuccess(true);
|
|
result.setSuccess(true);
|
|
@@ -97,10 +116,10 @@ public class ProductController {
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping(value = "/getUserProductList")
|
|
@GetMapping(value = "/getUserProductList")
|
|
- public Result<IPage<Product>> getUserProductList(String userId,String productName,
|
|
|
|
- @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
|
- @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
|
- HttpServletRequest req) {
|
|
|
|
|
|
+ public Result<IPage<Product>> getUserProductList(String userId, String productName,
|
|
|
|
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
|
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
|
+ HttpServletRequest req) {
|
|
Result<IPage<Product>> result = new Result<>();
|
|
Result<IPage<Product>> result = new Result<>();
|
|
if (Check.isNull(userId)) {
|
|
if (Check.isNull(userId)) {
|
|
result.setSuccess(false);
|
|
result.setSuccess(false);
|
|
@@ -112,7 +131,7 @@ public class ProductController {
|
|
userId = null;
|
|
userId = null;
|
|
}
|
|
}
|
|
Page<Product> page = new Page<>(pageNo, pageSize);
|
|
Page<Product> page = new Page<>(pageNo, pageSize);
|
|
- IPage<Product> pageList = productService.getUserProductList(page,userId,productName);
|
|
|
|
|
|
+ IPage<Product> pageList = productService.getUserProductList(page, userId, productName);
|
|
result.setSuccess(true);
|
|
result.setSuccess(true);
|
|
result.setResult(pageList);
|
|
result.setResult(pageList);
|
|
return result;
|
|
return result;
|
|
@@ -129,6 +148,19 @@ public class ProductController {
|
|
public Result<Product> add(@RequestBody Product product) {
|
|
public Result<Product> add(@RequestBody Product product) {
|
|
Result<Product> result = new Result<>();
|
|
Result<Product> result = new Result<>();
|
|
try {
|
|
try {
|
|
|
|
+
|
|
|
|
+ String userId = product.getUserId();
|
|
|
|
+ if (!Check.isNull(userId)) {
|
|
|
|
+ QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ userCompanyQueryWrapper.eq("user_id", userId);
|
|
|
|
+ userCompanyQueryWrapper.orderByDesc("create_time");
|
|
|
|
+ userCompanyQueryWrapper.last("limit 1");
|
|
|
|
+ UserCompany userCompany = userCompanyMapper.selectOne(userCompanyQueryWrapper);
|
|
|
|
+ if (!Check.isNull(userCompany)) {
|
|
|
|
+ product.setCompanyId(userCompany.getCompanyId());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
productService.save(product);
|
|
productService.save(product);
|
|
result.success("添加成功!");
|
|
result.success("添加成功!");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|