|
@@ -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);
|