guoyujia 1 tydzień temu
rodzic
commit
d76baab614
18 zmienionych plików z 43 dodań i 22 usunięć
  1. 10 2
      src/main/java/cn/ezhizao/framework/web/controller/BaseController.java
  2. 1 1
      src/main/java/cn/ezhizao/project/business/equipment/controller/BizEquipmentCategoryController.java
  3. 1 0
      src/main/java/cn/ezhizao/project/business/equipment/controller/BizEquipmentDetailController.java
  4. 3 2
      src/main/java/cn/ezhizao/project/business/inspectionChamber/controller/BizInspectionChamberController.java
  5. 1 0
      src/main/java/cn/ezhizao/project/business/inspectionChamber/domain/BizInspectionChamber.java
  6. 1 0
      src/main/java/cn/ezhizao/project/business/product/controller/BizProductController.java
  7. 1 5
      src/main/java/cn/ezhizao/project/business/supplier/controller/BizSupplierController.java
  8. 1 0
      src/main/java/cn/ezhizao/project/business/technologicalProcess/controller/BizTechnologicalProcessController.java
  9. 1 1
      src/main/java/cn/ezhizao/project/business/technologicalProcessDetailDrawing/controller/BizTechnologicalProcessDetailDrawingController.java
  10. 4 0
      src/main/java/cn/ezhizao/project/business/technologicalProcessDetailDrawing/service/impl/BizTechnologicalProcessDetailDrawingServiceImpl.java
  11. 3 0
      src/main/java/cn/ezhizao/project/business/workshop/controller/BizWorkshopController.java
  12. 5 4
      src/main/java/cn/ezhizao/project/system/controller/SysDeptController.java
  13. 2 2
      src/main/java/cn/ezhizao/project/system/mapper/SysDeptMapper.java
  14. 2 2
      src/main/java/cn/ezhizao/project/system/service/impl/SysDeptServiceImpl.java
  15. 3 1
      src/main/resources/mybatis/business/equipment/BizEquipmentDetailMapper.xml
  16. 1 0
      src/main/resources/mybatis/business/inspectionChamber/BizInspectionChamberMapper.xml
  17. 1 0
      src/main/resources/mybatis/business/workshop/BizWorkshopMapper.xml
  18. 2 2
      src/main/resources/mybatis/system/SysDeptMapper.xml

+ 10 - 2
src/main/java/cn/ezhizao/framework/web/controller/BaseController.java

@@ -23,10 +23,13 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.WebDataBinder;
 import org.springframework.web.bind.annotation.InitBinder;
 
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.beans.PropertyEditorSupport;
 import java.lang.reflect.Field;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
@@ -36,7 +39,8 @@ import java.util.stream.Collectors;
  */
 public class BaseController {
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
-
+    @Resource
+    private HttpServletRequest request;
 
     /**
      * 将前台传递过来的日期格式的字符串,自动转化为Date类型
@@ -225,12 +229,16 @@ public class BaseController {
      */
     protected <T> void setTenantId(T t) throws NoSuchFieldException, IllegalAccessException {
         SysUser user = SecurityUtils.getLoginUser().getUser();
+        Long tenantId = request.getHeader("tenantId") != null && !Objects.equals(request.getHeader("tenantId"), "0") ? Long.parseLong(request.getHeader("tenantId")) : null;
         if (!user.isAdmin()) {
             Field field = t.getClass().getDeclaredField("tenantId");
             field.setAccessible(true);
-            field.set(t, user.getTenantId());
+            field.set(t, tenantId);
         }
     }
+    protected Long getTenantId() {
+        return request.getHeader("tenantId") != null && !Objects.equals(request.getHeader("tenantId"), "0") ? Long.parseLong(request.getHeader("tenantId")) : null;
+    }
 
     protected <T> boolean saveOrUpdateBatch(IService<T> service, List<T> newList, List<T> oldList) {
         // 批量保存/跟新 新数据 避免使用 saveOrUpdate() 方法 数据量超过50条就很卡了

+ 1 - 1
src/main/java/cn/ezhizao/project/business/equipment/controller/BizEquipmentCategoryController.java

@@ -67,7 +67,7 @@ public class BizEquipmentCategoryController extends BaseController {
     @PostMapping("/listCategories")
     @Log(title = "设备类别查询", businessType = BusinessType.SELECT)
     public AjaxResult listCategories(BizEquipmentCategory bizEquipmentCategory) throws NoSuchFieldException, IllegalAccessException {
-
+        setTenantId(bizEquipmentCategory);
         List<BizEquipmentCategory> list = bizEquipmentDetailService.getCategoryList(bizEquipmentCategory);
         return success(list);
     }

+ 1 - 0
src/main/java/cn/ezhizao/project/business/equipment/controller/BizEquipmentDetailController.java

@@ -105,6 +105,7 @@ public class BizEquipmentDetailController extends BaseController {
     public TableDataInfo detailList( BizEquipmentDetail data) throws NoSuchFieldException, IllegalAccessException, JsonProcessingException {
 //        final String tenantId = request.getHeader("tenantId");
 //        data.setTenantId(Long.valueOf(tenantId));
+        setTenantId(data);
         startPage();
         List<BizEquipmentDetail> list = bizEquipmentDetailService.getDetailsList(data);
 //        for (BizEquipmentDetail item:list

+ 3 - 2
src/main/java/cn/ezhizao/project/business/inspectionChamber/controller/BizInspectionChamberController.java

@@ -53,7 +53,7 @@ public class BizInspectionChamberController extends BaseController
     @GetMapping("/list")
     public TableDataInfo list(BizInspectionChamber bizInspectionChamber) throws NoSuchFieldException, IllegalAccessException
     {
-//        setTenantId(bizInspectionChamber);
+        setTenantId(bizInspectionChamber);
         startPage();
         List<BizInspectionChamber> list = bizInspectionChamberService.getList(bizInspectionChamber);
         List<BizWorkshopChamber> chambers = bizWorkshopChamberService.query().in("chamber_id", list.isEmpty() ? Collections.singletonList(0L) : list.stream().map(BizInspectionChamber::getId).collect(Collectors.toList())).list();
@@ -99,8 +99,9 @@ public class BizInspectionChamberController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody BizInspectionChamber bizInspectionChamber) throws NoSuchFieldException, IllegalAccessException
     {
+        setTenantId(bizInspectionChamber);
         // 判断仪器室名称不能重复
-        if (bizInspectionChamberService.query().eq("chamber_name", bizInspectionChamber.getChamberName()).count() > 0) {
+        if (bizInspectionChamberService.query().eq("tenant_id", bizInspectionChamber.getTenantId()).eq("chamber_name", bizInspectionChamber.getChamberName()).count() > 0) {
             return error("仪器室名称不可重复");
         }
 //        setTenantId(bizInspectionChamber);

+ 1 - 0
src/main/java/cn/ezhizao/project/business/inspectionChamber/domain/BizInspectionChamber.java

@@ -20,6 +20,7 @@ import java.util.List;
 public class BizInspectionChamber extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
+    private Long tenantId;
 
     /** 检查室名称 */
     @Excel(name = "检查室名称")

+ 1 - 0
src/main/java/cn/ezhizao/project/business/product/controller/BizProductController.java

@@ -43,6 +43,7 @@ public class BizProductController extends BaseController {
     public TableDataInfo list(BizProduct bizProduct) throws NoSuchFieldException, IllegalAccessException {
 //        final String tenantId = request.getHeader("tenantId");
 //        bizProduct.setTenantId(Long.valueOf(tenantId));
+        setTenantId(bizProduct);
         startPage();
         List<BizProduct> list = bizProductService.getList(bizProduct);
         return getDataTable(list);

+ 1 - 5
src/main/java/cn/ezhizao/project/business/supplier/controller/BizSupplierController.java

@@ -60,12 +60,8 @@ public class BizSupplierController extends BaseController {
     @Log(title = "外协商单位查询", businessType = BusinessType.SELECT)
     @GetMapping("/list")
     public TableDataInfo list(BizSupplier data) throws NoSuchFieldException, IllegalAccessException, JsonProcessingException {
-
-        String config = configService.selectConfigByKey("switch_data_source");
         String tenantId = request.getHeader("tenantId");
-        if ("true".equals(config) && tenantId != null && !"0".equals(tenantId)) {
             data.setTenantId(Long.parseLong(tenantId));
-        }
         startPage();
         List<BizSupplier> list = iBizSupplierService.getList(data);
         return getDataTable(list);
@@ -74,7 +70,7 @@ public class BizSupplierController extends BaseController {
     @Log(title = "外协工段选择外协商单位", businessType = BusinessType.SELECT)
     @GetMapping("/listByDept")
     public TableDataInfo listByDept(SysDept dept) throws NoSuchFieldException, IllegalAccessException, JsonProcessingException {
-
+        setTenantId(dept);
         startPage();
         List<BizSupplier> list = iBizSupplierService.getListByDept(dept);
         return getDataTable(list);

+ 1 - 0
src/main/java/cn/ezhizao/project/business/technologicalProcess/controller/BizTechnologicalProcessController.java

@@ -95,6 +95,7 @@ public class BizTechnologicalProcessController extends BaseController {
         Long productId = Long.parseLong(data.get("productId").toString());
         List<BizTechnologicalProcess> list = bizTechnologicalProcessService.query()
                 .eq("product_id", productId)
+                .eq("is_history",0)
                 .list();
         return success(list);
     }

+ 1 - 1
src/main/java/cn/ezhizao/project/business/technologicalProcessDetailDrawing/controller/BizTechnologicalProcessDetailDrawingController.java

@@ -327,7 +327,7 @@ public class BizTechnologicalProcessDetailDrawingController extends BaseControll
 
     public AjaxResult save(@RequestBody List<BizTechnologicalProcessDetailDrawing> bizTechnologicalProcessDetailDrawing) throws NoSuchFieldException, IllegalAccessException, COSVisitorException, DocumentException, IOException {
 
-
+        setTenantId(bizTechnologicalProcessDetailDrawing);
         int i = bizTechnologicalProcessDetailDrawingService.saveData(bizTechnologicalProcessDetailDrawing, SecurityUtils.getLoginUser().getUser().getUserName(), SecurityUtils.getLoginUser().getUser().getNickName());
         if (i == 3) {
             return error("请先上传个人章");

+ 4 - 0
src/main/java/cn/ezhizao/project/business/technologicalProcessDetailDrawing/service/impl/BizTechnologicalProcessDetailDrawingServiceImpl.java

@@ -164,6 +164,7 @@ public class BizTechnologicalProcessDetailDrawingServiceImpl extends ServiceImpl
                 drawingUser.setProcessCode(item.getProcessCode());
                 drawingUser.setDrawingName(item.getDrawingName());
                 drawingUser.setType(0);
+                drawingUser.setTenantId(item.getTenantId());
                 drawingUser.setUserId(user.getUserId());
                 drawingUser.setNickName(user.getNickName());
                 drawingUser.setProductId(item.getProductId());
@@ -188,6 +189,7 @@ public class BizTechnologicalProcessDetailDrawingServiceImpl extends ServiceImpl
                         drawingUser.setDrawingId(item.getId());
                         drawingUser.setProcessCode(item.getProcessCode());
                         drawingUser.setDrawingName(item.getDrawingName());
+                        drawingUser.setTenantId(item.getTenantId());
                         drawingUser.setType(1);
                         drawingUser.setUserId(user.getUserId());
                         drawingUser.setNickName(user.getNickName());
@@ -261,6 +263,7 @@ public class BizTechnologicalProcessDetailDrawingServiceImpl extends ServiceImpl
             drawingUser.setDrawingId(byId.getId());
             drawingUser.setProcessCode(byId.getProcessCode());
             drawingUser.setDrawingName(byId.getDrawingName());
+            drawingUser.setTenantId(item.getTenantId());
             drawingUser.setType(4);
             drawingUser.setUserId(user.getUserId());
             drawingUser.setNickName(user.getNickName());
@@ -329,6 +332,7 @@ public class BizTechnologicalProcessDetailDrawingServiceImpl extends ServiceImpl
         drawingUser.setDrawingId(item.getId());
         drawingUser.setProcessCode(item.getProcessCode());
         drawingUser.setDrawingName(item.getDrawingName());
+        drawingUser.setTenantId(item.getTenantId());
         drawingUser.setType(2);
         drawingUser.setUserId(user.getUserId());
         drawingUser.setNickName(user.getNickName());

+ 3 - 0
src/main/java/cn/ezhizao/project/business/workshop/controller/BizWorkshopController.java

@@ -50,6 +50,7 @@ public class BizWorkshopController extends BaseController
     @GetMapping("/list")
     public TableDataInfo list(BizWorkshop bizWorkshop) throws NoSuchFieldException, IllegalAccessException
     {
+        setTenantId(bizWorkshop);
 //        startPage();
         List<BizWorkshop> list = bizWorkshopService.getList(bizWorkshop);
         return getDataTable(list);
@@ -88,9 +89,11 @@ public class BizWorkshopController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody BizWorkshop bizWorkshop) throws NoSuchFieldException, IllegalAccessException
     {
+        setTenantId(bizWorkshop);
         QueryWrapper<BizWorkshop> queryWrapper = new QueryWrapper();
         queryWrapper.eq("name",bizWorkshop.getName());
         queryWrapper.eq("deleted",0);
+        queryWrapper.eq("tenant_id",bizWorkshop.getTenantId());
         if(bizWorkshopService.list(queryWrapper).size()>0){
             return error("车间名称已存在");
         }

+ 5 - 4
src/main/java/cn/ezhizao/project/system/controller/SysDeptController.java

@@ -81,7 +81,8 @@ public class SysDeptController extends BaseController
      */
     @Log(title = "部门管理获取部门名称和id", businessType = BusinessType.SELECT)
     @GetMapping("/getDeptList")
-    public AjaxResult getDeptList(SysDept dept) {
+    public AjaxResult getDeptList(SysDept dept) throws NoSuchFieldException, IllegalAccessException {
+        setTenantId(dept);
 //        String tenantId = request.getHeader("tenantId");
 //        dept.setTenantId(Long.valueOf(tenantId));
         List<SysDept> departments = deptService.getDeptList(dept);
@@ -157,10 +158,10 @@ public class SysDeptController extends BaseController
     @PostMapping(value = "save")
     @Transactional
     public AjaxResult save(@Validated @RequestBody SysDept dept) throws NoSuchFieldException, IllegalAccessException {
-        if(dept.getTenantId() ==null) {
+
         String tenantId = request.getHeader("tenantId");
-        dept.setTenantId(Long.valueOf(tenantId));
-        }
+        dept.setTenantId(Long.parseLong(tenantId) == 0?1L:Long.valueOf(tenantId));
+
         Long deptId = dept.getDeptId();
         // 判断没有id的进行新增操作
         if(deptId == null){

+ 2 - 2
src/main/java/cn/ezhizao/project/system/mapper/SysDeptMapper.java

@@ -108,7 +108,7 @@ public interface SysDeptMapper {
      * @param parentId 父部门ID
      * @return 结果
      */
-    public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);
+    public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId,@Param("tenantId") Long tenantId);
 
   /**
      * 校验部门编码是否唯一
@@ -117,7 +117,7 @@ public interface SysDeptMapper {
      * @param parentId 父部门ID
      * @return 结果
      */
-    public SysDept checkDeptCodeUnique(@Param("deptCode") String deptCode, @Param("parentId") Long parentId);
+    public SysDept checkDeptCodeUnique(@Param("deptCode") String deptCode, @Param("parentId") Long parentId,@Param("tenantId") Long tenantId);
 
 
     /**

+ 2 - 2
src/main/java/cn/ezhizao/project/system/service/impl/SysDeptServiceImpl.java

@@ -217,7 +217,7 @@ public class SysDeptServiceImpl implements ISysDeptService
     public String checkDeptNameUnique(SysDept dept)
     {
         Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
-        SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
+        SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId(),dept.getTenantId());
         if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
         {
             return UserConstants.NOT_UNIQUE;
@@ -235,7 +235,7 @@ public class SysDeptServiceImpl implements ISysDeptService
     public String checkDeptCodeUnique(SysDept dept)
     {
         Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
-        SysDept info = deptMapper.checkDeptCodeUnique(dept.getDeptCode(), dept.getParentId());
+        SysDept info = deptMapper.checkDeptCodeUnique(dept.getDeptCode(), dept.getParentId(),dept.getTenantId());
         if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
         {
             return UserConstants.NOT_UNIQUE;

+ 3 - 1
src/main/resources/mybatis/business/equipment/BizEquipmentDetailMapper.xml

@@ -67,8 +67,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="getCategoryList" resultType="cn.ezhizao.project.business.equipment.domain.BizEquipmentCategory">
         SELECT id AS Value,name AS Label
         FROM biz_equipment_category
-        WHERE
+        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
             deleted = 0
+            <if test="tenantId != null  and tenantId != 0"> AND tenant_id = #{tenantId}</if>
+        </trim>
     </select>
     <delete id="physicalDelete">
         DELETE FROM biz_equipment_detail

+ 1 - 0
src/main/resources/mybatis/business/inspectionChamber/BizInspectionChamberMapper.xml

@@ -15,6 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             deleted = 0
             <if test="chamberName != null  and chamberName != ''"> AND chamber_name like concat('%', #{chamberName}, '%')</if>
             <if test="chamberCode != null  and chamberCode != ''"> AND chamber_code = #{chamberCode}</if>
+            <if test="tenantId != null  and tenantId != 0"> AND tenant_id = #{tenantId}</if>
         </trim>
     </select>
 

+ 1 - 0
src/main/resources/mybatis/business/workshop/BizWorkshopMapper.xml

@@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
             deleted = 0
             <if test="name != null  and name != ''"> AND name like concat('%', #{name}, '%')</if>
+            <if test="tenantId != null  and tenantId != 0"> AND tenant_id = #{tenantId}</if>
         </trim>
     </select>
 

+ 2 - 2
src/main/resources/mybatis/system/SysDeptMapper.xml

@@ -170,11 +170,11 @@
 
 	<select id="checkDeptNameUnique" resultMap="SysDeptResult">
 		<include refid="selectDeptVo"/>
-		where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0'  limit 1
+		where dept_name=#{deptName} and parent_id = #{parentId} and tenant_id = #{tenantId} and del_flag = '0'  limit 1
 	</select>
 	<select id="checkDeptCodeUnique" resultMap="SysDeptResult">
 		<include refid="selectDeptVo"/>
-		where dept_code=#{deptCode} and parent_id = #{parentId} and del_flag = '0' limit 1
+		where dept_code=#{deptCode} and parent_id = #{parentId} and tenant_id = #{tenantId} and del_flag = '0' limit 1
 	</select>
 
 	<select id="getRootParentId" parameterType="Long">