Explorar o código

人员信息中增加一个是否允许查看本单位数据开关。

zhengqiang %!s(int64=5) %!d(string=hai) anos
pai
achega
f10ea475d4

+ 9 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/PersonInfo.java

@@ -155,4 +155,13 @@ public class PersonInfo {
 
     @ApiModelProperty(value="是否允许查看本单位数据")
     private Boolean allowViewLocal;
+
+    public Boolean getAllowViewLocal() {
+        if(allowViewLocal==null){
+            return false;
+        }
+        else{
+            return allowViewLocal;
+        }
+    }
 }

+ 8 - 6
common/src/main/resources/mapper/base/CompanyInfo.xml

@@ -142,14 +142,16 @@
         from base_company_info a
         left join base_company_info b on a.parent_id = b.id_
         where a.del_flag=0
-        and (
-            a.code_ like #{code}
+        <trim prefix="and (" prefixOverrides="and | or" suffix=")">
+            <if test="code!=null">
+                a.code_ like #{code}
+            </if>
             <if test="personId!=null">
-            or a.id_ in (
-                select c.company_id from base_person_company c where c.person_id = #{personId}
-            )
+                or a.id_ in (
+                    select c.company_id from base_person_company c where c.person_id = #{personId}
+                )
             </if>
-        )
+        </trim>
         order by a.sort_no asc,a.name_ asc
     </select>
     <select id="countByParentId" resultType="long">

+ 2 - 1
web/src/main/java/com/jpsoft/smart/config/RedisConfig.java

@@ -26,7 +26,8 @@ import java.lang.reflect.Method;
 @EnableCaching
 public class RedisConfig extends CachingConfigurerSupport {
     public final static String WX_COMMON_ACCESS_TOKEN = "wx_common_accessToken";
-    public static final String JS_API_TICKET = "js_api_ticket";
+    public final static String JS_API_TICKET = "js_api_ticket";
+    public final static String PERSON_SELECT_COMPANY = "psc_";
 
     /**
      * 注入 RedisConnectionFactory,注意maven中要有redis.clients.jedis

+ 7 - 1
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/IndividualLogApiController.java

@@ -1,6 +1,7 @@
 package com.jpsoft.smart.modules.mobile.controller;
 
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.config.RedisConfig;
 import com.jpsoft.smart.config.TemperatureConfig;
 import com.jpsoft.smart.modules.base.entity.*;
 import com.jpsoft.smart.modules.base.service.*;
@@ -14,6 +15,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
@@ -46,6 +48,9 @@ public class IndividualLogApiController {
     @Autowired
     private AlarmConfigService alarmConfigService;
 
+    @Autowired
+    private ValueOperations<String, Object> valueOperations;
+
     @PostMapping("healthyPersonList")
     @ApiOperation(value="健康公示列表")
     @ApiImplicitParams({
@@ -62,7 +67,8 @@ public class IndividualLogApiController {
         try{
             PersonInfo admin = personInfoService.get(Long.valueOf(subject));
 
-            String companyId = admin.getCompanyId();
+            Map<String,Object> companyMap = (Map<String,Object>)valueOperations.get(RedisConfig.PERSON_SELECT_COMPANY + admin.getId());
+            String companyId = companyMap.get("id").toString();
 
             Map<String,Object> searchParams = new HashMap<>();
 

+ 8 - 1
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonDeviceFilterLogController.java

@@ -1,6 +1,7 @@
 package com.jpsoft.smart.modules.mobile.controller;
 
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.config.RedisConfig;
 import com.jpsoft.smart.config.TemperatureConfig;
 import com.jpsoft.smart.modules.base.dto.PersonDeviceFilterLogDTO;
 import com.jpsoft.smart.modules.base.entity.*;
@@ -20,6 +21,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.web.bind.annotation.*;
 
@@ -61,6 +63,9 @@ public class PersonDeviceFilterLogController {
     @Autowired
     private WorkAttendanceService workAttendanceService;
 
+    @Autowired
+    private ValueOperations<String, Object> valueOperations;
+    
     @ApiOperation(value="体温记录(正常、异常)")
     @RequestMapping(value = "detail",method = RequestMethod.POST)
     @ApiImplicitParams({
@@ -189,7 +194,9 @@ public class PersonDeviceFilterLogController {
                 String subject = JwtUtil.decodeToken(jwtSecret,token);
 
                 PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
-                companyId = personInfo.getCompanyId();
+
+                Map<String,Object> companyMap = (Map<String,Object>)valueOperations.get(RedisConfig.PERSON_SELECT_COMPANY + personInfo.getId());
+                companyId = companyMap.get("id").toString();
             }
 
             CompanyInfo companyInfo = companyInfoService.get(companyId);

+ 9 - 2
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonDeviceLogApiController.java

@@ -3,6 +3,7 @@ package com.jpsoft.smart.modules.mobile.controller;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.util.StringUtil;
 import com.google.common.collect.Lists;
+import com.jpsoft.smart.config.RedisConfig;
 import com.jpsoft.smart.config.TemperatureConfig;
 import com.jpsoft.smart.modules.base.dto.PersonDeviceFilterLogDTO;
 import com.jpsoft.smart.modules.base.dto.PersonDeviceLogDTO;
@@ -19,6 +20,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.web.bind.annotation.*;
 
@@ -52,6 +54,9 @@ public class PersonDeviceLogApiController {
     @Autowired
     private TemperatureConfig temperatureConfig;
 
+    @Autowired
+    private ValueOperations<String, Object> valueOperations;
+
     @PostMapping("queryTemperatureRawRecordList")
     @ApiOperation(value="根据实时数据查看企业人员温度数据")
     @ApiImplicitParams({
@@ -223,7 +228,9 @@ public class PersonDeviceLogApiController {
 
             if (StringUtils.isEmpty(companyId)) {
                 PersonInfo admin = personInfoService.get(Long.valueOf(subject));
-                companyId = admin.getCompanyId();
+
+                Map<String,Object> companyMap = (Map<String,Object>)valueOperations.get(RedisConfig.PERSON_SELECT_COMPANY + admin.getId());
+                companyId = companyMap.get("id").toString();
             }
 
             personSearchParam.put("companyId", companyId);
@@ -319,7 +326,7 @@ public class PersonDeviceLogApiController {
             PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
             CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
 
-            String companyCode = "";
+            String companyCode = null;
 
             if (personInfo.getAllowViewLocal()!=null && personInfo.getAllowViewLocal()){
                 companyCode = companyInfo.getCode() + "%";

+ 97 - 1
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonInfoApiController.java

@@ -4,8 +4,13 @@ import com.alibaba.fastjson.JSONObject;
 import com.alipay.api.domain.Person;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.config.OSSConfig;
+import com.jpsoft.smart.config.RedisConfig;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
+import com.jpsoft.smart.modules.base.entity.PersonCompany;
 import com.jpsoft.smart.modules.base.entity.PersonDeviceRelation;
 import com.jpsoft.smart.modules.base.entity.PersonInfo;
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
+import com.jpsoft.smart.modules.base.service.PersonCompanyService;
 import com.jpsoft.smart.modules.base.service.PersonDeviceRelationService;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
@@ -63,6 +68,12 @@ public class PersonInfoApiController {
     @Autowired
     private UserService userService;
 
+    @Autowired
+    private CompanyInfoService companyInfoService;
+
+    @Autowired
+    private PersonCompanyService personCompanyService;
+
     @Autowired
     RabbitTemplate rabbitTemplate;
 
@@ -98,6 +109,60 @@ public class PersonInfoApiController {
         return messageResult;
     }
 
+
+    @PostMapping("switchCompany")
+    @ApiOperation(value="切换管理单位")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="companyId",value = "companyId",required = true,paramType = "form"),
+            @ApiImplicitParam(name="token",value = "令牌",paramType = "form"),
+            @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
+    })
+    public MessageResult<Map> switchCompany(String companyId,String token,@RequestAttribute String subject){
+        MessageResult<Map> messageResult = new MessageResult<>();
+
+        try {
+            PersonInfo personInfo = personInfoService.findById(Long.valueOf(subject));
+
+            if (personInfo==null){
+                throw new Exception("当前用户不存在!");
+            }
+
+            //判断companyId是否存在于当前用户的关联单位中
+            List<PersonCompany> personCompanies = personCompanyService.findByPersonId(personInfo.getId());
+
+            long count = personCompanies.stream().filter((item)->item.getCompanyId().equals(companyId)).count();
+
+            if (count==0) {
+                //当前用户可以管理本单位
+                if (personInfo.getAllowViewLocal() && personInfo.getCompanyId().equals(companyId)) {
+                    count = 1;
+                }
+            }
+
+            if (count==0){
+                throw new Exception("选择单位不在当前用户的管理范围内!");
+            }
+
+            CompanyInfo companyInfo = companyInfoService.get(companyId);
+
+            Map<String,Object> companyMap = new HashMap<>();
+            companyMap.put("id",companyInfo.getId());
+            companyMap.put("name",companyInfo.getName());
+
+            valueOperations.set(RedisConfig.PERSON_SELECT_COMPANY + personInfo.getId(), companyMap,2,TimeUnit.HOURS);
+
+            messageResult.setData(companyMap);
+            messageResult.setResult(true);
+            messageResult.setCode(200);
+        }
+        catch (Exception ex){
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
     @PostMapping("findByOpenId")
     @ApiOperation(value="通过openId查询人员(公开接口)")
     @ApiImplicitParams({
@@ -119,6 +184,34 @@ public class PersonInfoApiController {
             dataMap.put("person",personInfo);
             dataMap.put("token", token);
 
+            CompanyInfo selectedCompany = new CompanyInfo();
+
+            Map<String,Object> companyMap = (Map<String, Object>) valueOperations.get(RedisConfig.PERSON_SELECT_COMPANY + personInfo.getId());
+
+            if (companyMap==null) {
+                //当前用户默认管理单位
+                if (StringUtils.isNotEmpty(personInfo.getPopedom()) && personInfo.getPopedom().indexOf("2") != -1) {
+                    if (personInfo.getAllowViewLocal()) {
+                        CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
+                        selectedCompany = companyInfo;
+                    } else {
+                        List<PersonCompany> personCompanies = personCompanyService.findByPersonId(personInfo.getId());
+
+                        if (personCompanies.size() > 0) {
+                            CompanyInfo companyInfo = companyInfoService.get(personCompanies.get(0).getCompanyId());
+                            selectedCompany = companyInfo;
+                        }
+                    }
+                }
+
+                companyMap.put("id",selectedCompany.getId());
+                companyMap.put("name",selectedCompany.getName());
+
+                valueOperations.set(RedisConfig.PERSON_SELECT_COMPANY + personInfo.getId(), companyMap,2,TimeUnit.HOURS);
+            }
+
+            dataMap.put("company",companyMap);
+
             messageResult.setData(dataMap);
             messageResult.setResult(true);
             messageResult.setCode(200);
@@ -376,6 +469,9 @@ public class PersonInfoApiController {
         try {
             PersonInfo admin = personInfoService.get(Long.valueOf(subject));
 
+            Map<String,Object> companyMap = (Map<String,Object>)valueOperations.get(RedisConfig.PERSON_SELECT_COMPANY + admin.getId());
+            String companyId = companyMap.get("id").toString();
+
             if (StringUtils.isEmpty(admin.getPopedom())
             && admin.getPopedom().indexOf("2")==-1){
                 throw new Exception("当前用户不是管理员!");
@@ -385,7 +481,7 @@ public class PersonInfoApiController {
 
             if(personInfo == null) {
                 personInfo = new PersonInfo();
-                personInfo.setCompanyId(admin.getCompanyId());
+                personInfo.setCompanyId(companyId);
                 personInfo.setName(name);
                 personInfo.setPhone(phone);
                 personInfo.setFaceEnabled(true);