Browse Source

Merge branch 'dev' of yeshijie/jw2.0 into dev

yeshijie 7 years ago
parent
commit
a073ce5ea7

+ 1 - 1
app/app-iot-server/pom.xml

@ -234,7 +234,7 @@
    </dependencies>
    <build>
        <finalName>app-emergency-server</finalName>
        <finalName>app-iot-server</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>

+ 22 - 8
app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/company/IotCompanyController.java

@ -45,7 +45,7 @@ public class IotCompanyController extends BaseController {
    @PostMapping(value = IotRequestMapping.Company.addCompany)
    @ApiOperation(value = "创建企业", notes = "创建企业")
    public Envelop<IotCompanyVO> addCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
    public Envelop<IotCompanyVO> addCompany(@ApiParam(name = "jsonData", value = "json串", defaultValue = "")
                                            @RequestParam(value = "jsonData", required = true)String jsonData) {
        try {
            return companyService.addCompany(jsonData);
@ -57,7 +57,7 @@ public class IotCompanyController extends BaseController {
    @GetMapping(value = IotRequestMapping.Company.findCompanyById)
    @ApiOperation(value = "根据id查找企业", notes = "根据id查找企业")
    public Envelop<IotCompanyVO> findByCode(@ApiParam(name = "id", value = "id")
    public Envelop<IotCompanyVO> findByCode(@ApiParam(name = "id", value = "企业id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            return companyService.findByCode(id);
@ -69,7 +69,7 @@ public class IotCompanyController extends BaseController {
    @GetMapping(value = IotRequestMapping.Company.findByBusinessLicense)
    @ApiOperation(value = "根据营业执照号查找企业", notes = "根据营业执照号查找企业")
    public Envelop<IotCompanyVO> findByBusinessLicense(@ApiParam(name = "businessLicense", value = "businessLicense")
    public Envelop<IotCompanyVO> findByBusinessLicense(@ApiParam(name = "businessLicense", value = "营业执照号")
                                                       @RequestParam(value = "businessLicense", required = true) String businessLicense) {
        try {
            return companyService.findByBusinessLicense(businessLicense);
@ -81,7 +81,7 @@ public class IotCompanyController extends BaseController {
    @PostMapping(value = IotRequestMapping.Company.delCompany)
    @ApiOperation(value = "删除企业", notes = "删除企业")
    public Envelop<IotCompanyVO> delCompany(@ApiParam(name = "id", value = "id")
    public Envelop<IotCompanyVO> delCompany(@ApiParam(name = "id", value = "企业id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            return companyService.delCompany(id);
@ -93,7 +93,7 @@ public class IotCompanyController extends BaseController {
    @PostMapping(value = IotRequestMapping.Company.updCompany)
    @ApiOperation(value = "修改企业信息", notes = "修改企业信息")
    public Envelop<IotCompanyVO> updCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
    public Envelop<IotCompanyVO> updCompany(@ApiParam(name = "jsonData", value = "json串", defaultValue = "")
                                            @RequestParam(value = "jsonData", required = true)String jsonData) {
        try {
            return companyService.updCompany(jsonData);
@ -128,7 +128,7 @@ public class IotCompanyController extends BaseController {
    @GetMapping(value = IotRequestMapping.Company.findCompanyCertById)
    @ApiOperation(value = "根据id查找企业证书", notes = "根据id查找企业证书")
    public Envelop<IotCompanyCertificateVO> findCompanyCertById(@ApiParam(name = "id", value = "id")
    public Envelop<IotCompanyCertificateVO> findCompanyCertById(@ApiParam(name = "id", value = "企业证书id")
                                                                @RequestParam(value = "id", required = true) String id) {
        try {
            return companyService.findCompanyCertById(id);
@ -140,7 +140,7 @@ public class IotCompanyController extends BaseController {
    @GetMapping(value = IotRequestMapping.Company.findCompanyCertByCompanyId)
    @ApiOperation(value = "根据企业id查找企业证书", notes = "根据企业id查找企业证书")
    public Envelop<IotCompanyCertificateVO> findCompanyCertByCompanyId(@ApiParam(name = "companyId", value = "companyId")
    public Envelop<IotCompanyCertificateVO> findCompanyCertByCompanyId(@ApiParam(name = "companyId", value = "企业id")
                                                                       @RequestParam(value = "companyId", required = true) String companyId) {
        try {
            return companyService.findCompanyCertByCompanyId(companyId);
@ -152,7 +152,7 @@ public class IotCompanyController extends BaseController {
    @PostMapping(value = IotRequestMapping.Company.addCompanyCert)
    @ApiOperation(value = "创建企业证书", notes = "创建企业证书")
    public Envelop<IotCompanyCertificateVO> addCompanyCert(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
    public Envelop<IotCompanyCertificateVO> addCompanyCert(@ApiParam(name = "jsonData", value = "json串", defaultValue = "")
                                                           @RequestParam(value = "jsonData", required = true)String jsonData) {
        try {
            return companyService.addCompanyCert(jsonData);
@ -162,4 +162,18 @@ public class IotCompanyController extends BaseController {
        }
    }
    @PostMapping(value = IotRequestMapping.Company.changePassWord)
    @ApiOperation(value = "修改用户密码", notes = "修改用户密码")
    public Envelop changePassWord(@ApiParam(name = "userId", value = "用户id", defaultValue = "")
                                  @RequestParam(value = "userId", required = true)String userId,
                                  @ApiParam(name = "passWord", value = "密码", defaultValue = "")
                                  @RequestParam(value = "passWord", required = true)String passWord){
        try {
            return companyService.changePassWord(userId,passWord);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 92 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/model/user/UserModel.java

@ -0,0 +1,92 @@
package com.yihu.ehr.iot.model.user;
import java.io.Serializable;
/**
 * ehr用户model
 * @author yeshijie on 2018/2/2.
 */
public class UserModel implements Serializable{
    private String id;
    private String email;
    private String loginCode;
    private String realName;
    private String password;
    private String newPassWord;
    private String telephone;
    private String idCardNo;
    private String role;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getLoginCode() {
        return loginCode;
    }
    public void setLoginCode(String loginCode) {
        this.loginCode = loginCode;
    }
    public String getRealName() {
        return realName;
    }
    public void setRealName(String realName) {
        this.realName = realName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getNewPassWord() {
        return newPassWord;
    }
    public void setNewPassWord(String newPassWord) {
        this.newPassWord = newPassWord;
    }
    public String getTelephone() {
        return telephone;
    }
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    public String getIdCardNo() {
        return idCardNo;
    }
    public void setIdCardNo(String idCardNo) {
        this.idCardNo = idCardNo;
    }
    public String getRole() {
        return role;
    }
    public void setRole(String role) {
        this.role = role;
    }
}

+ 5 - 3
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/common/BaseService.java

@ -2,6 +2,7 @@ package com.yihu.ehr.iot.service.common;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.iot.util.CurrentRequest;
import com.yihu.ehr.iot.util.encode.AES;
import com.yihu.ehr.iot.util.encode.Base64;
import com.yihu.ehr.iot.util.http.HttpHelper;
@ -33,8 +34,8 @@ public class BaseService {
    protected String permissionsInfo;
    @Value("${app.clientId}")
    protected String clientId;
    @Value("${app.baseClientId}")
    protected String baseClientId;
//    @Value("${app.baseClientId}")
//    protected String baseClientId;
    @Value("${service-gateway.profileInnerUrl}")
    protected String profileInnerUrl;
    @Value("${service-gateway.profileOuterUrl}")
@ -49,7 +50,8 @@ public class BaseService {
    protected String oauth2InnerUrl;
    @Value("${app.oauth2OuterUrl}")
    protected String oauth2OuterUrl;
    @Autowired
    private CurrentRequest currentRequest;
    public String readFile(String filePath, String charSet) {

+ 37 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/common/SystemDictService.java

@ -1,6 +1,8 @@
package com.yihu.ehr.iot.service.common;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.model.ObjectResult;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
import com.yihu.jw.restmodel.common.Envelop;
@ -24,6 +26,9 @@ public class SystemDictService extends BaseService{
     * @throws Exception
     */
    public Envelop<IotSystemDictVO> getList(String dictName) throws Exception {
        if("HOSPITAL".equals(dictName)){
            return organizations();
        }
        Map<String, Object> params = new HashMap<>();
        params.put("dictName", dictName);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.System.FindDictByCode, params);
@ -31,4 +36,36 @@ public class SystemDictService extends BaseService{
        return envelop;
    }
    /**
     * 获取组织机构信息
     * @return
     */
    private Envelop<IotSystemDictVO> organizations(){
        String url = "/organizations";
        Envelop<IotSystemDictVO> envelop = new Envelop<IotSystemDictVO>();
        Map<String, Object> params = new HashMap<>();
        params.put("fields","");
        params.put("sorts","");
        params.put("filters", "orgCode?3502");
        params.put("page", 1);
        params.put("size", 100);
        try {
            HttpResponse response = HttpHelper.get(profileInnerUrl + url, params);
            ObjectResult result =  objectMapper.readValue(response.getBody(),ObjectResult.class);
            if(result.isSuccessFlg()){
                envelop = objectMapper.readValue(response.getBody(),Envelop.class);
                envelop.setStatus(200);
            }else {
                envelop.setStatus(-1);
                envelop.setErrorMsg(result.getErrorMsg());
            }
            return envelop;
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setStatus(-1);
            envelop.setErrorMsg(ErrorCode.SystemError.toString());
            return envelop;
        }
    }
}

+ 177 - 2
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/company/CompanyService.java

@ -1,6 +1,10 @@
package com.yihu.ehr.iot.service.company;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.model.ObjectResult;
import com.yihu.ehr.iot.model.Result;
import com.yihu.ehr.iot.model.user.UserModel;
import com.yihu.ehr.iot.service.common.BaseService;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
@ -8,6 +12,7 @@ import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.company.IotCompanyCertificateVO;
import com.yihu.jw.restmodel.iot.company.IotCompanyVO;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.HashMap;
@ -19,6 +24,8 @@ import java.util.Map;
@Service
public class CompanyService extends BaseService {
    private String roleId = "10268";//物联网默认用户角色
    /**
     * 分页查找企业
     * @param name
@ -49,13 +56,181 @@ public class CompanyService extends BaseService {
     * @throws IOException
     */
    public Envelop<IotCompanyVO> addCompany(String jsonData) throws IOException {
        Envelop<IotCompanyVO> envelop = new Envelop<IotCompanyVO>();
        //新增ehr用户
        IotCompanyVO iotCompany = toModel(jsonData, IotCompanyVO.class);
        envelop = userVerification(iotCompany,envelop);
        if(envelop.getStatus()==-1){
            return envelop;
        }
        //验证账户
        Result login_code = existence("login_code",iotCompany.getAccount());
        if(login_code.isSuccessFlg()){
            envelop.setStatus(-1);
            envelop.setErrorMsg("该账号已存在");
            return envelop;
        }
        //验证身份证
        Result id_card_no = existence("id_card_no",iotCompany.getContactsIdcard());
        if(id_card_no.isSuccessFlg()){
            envelop.setStatus(-1);
            envelop.setErrorMsg("该身份证号已被注册,请确认。");
            return envelop;
        }
        //验证邮件
        Result email = existence("email",iotCompany.getContactsEmail());
        if(email.isSuccessFlg()){
            envelop.setStatus(-1);
            envelop.setErrorMsg("该邮箱已存在");
            return envelop;
        }
        //验证手机号
        Result telephone = existence("telephone",iotCompany.getContactsMobile());
        if(telephone.isSuccessFlg()){
            envelop.setStatus(-1);
            envelop.setErrorMsg("该手机号码已存在");
            return envelop;
        }
        Envelop<UserModel> userModelEnvelop = updateUser(iotCompany);
        if(userModelEnvelop.getStatus()!=200){
            envelop.setStatus(-1);
            envelop.setErrorMsg(userModelEnvelop.getErrorMsg());
            return envelop;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        params.put("jsonData", toJson(iotCompany));
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Company.AddCompany, params);
        Envelop<IotCompanyVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 校验用户信息
     * @param iotCompany
     * @param envelop
     * @return
     */
    private Envelop<IotCompanyVO> userVerification(IotCompanyVO iotCompany,Envelop<IotCompanyVO> envelop){
        if(StringUtils.isEmpty(iotCompany.getAccount())){
            envelop.setStatus(-1);
            envelop.setErrorMsg("账号不能为空");
            return envelop;
        }
        if(StringUtils.isEmpty(iotCompany.getContactsIdcard())){
            envelop.setStatus(-1);
            envelop.setErrorMsg("身份证号不能为空");
            return envelop;
        }
        if(StringUtils.isEmpty(iotCompany.getContactsEmail())){
            envelop.setStatus(-1);
            envelop.setErrorMsg("邮箱不能为空");
            return envelop;
        }
        if(StringUtils.isEmpty(iotCompany.getContactsMobile())){
            envelop.setStatus(-1);
            envelop.setErrorMsg("手机号码账号不能为空");
            return envelop;
        }
        return envelop;
    }
    /**
     * 验证用户信息
     */
    private Result existence(String existenceType, String existenceNm){
        String getUserUrl = "/users/existence";
        Result result = null;
        Map<String, Object> params = new HashMap<>();
        params.put("existenceType",existenceType);
        params.put("existenceNm",existenceNm);
//        params.put("username",null);
//        params.put("password",null);
        try {
            HttpResponse response = HttpHelper.get(profileInnerUrl + getUserUrl, params);
            result = objectMapper.readValue(response.getBody(),Result.class);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result = new Result();
            result.setSuccessFlg(false);
            result.setMessage(ErrorCode.SystemError.toString());
            return result;
        }
    }
    /**
     * 新增用户
     * @param iotCompany
     * @return
     */
    private Envelop<UserModel> updateUser(IotCompanyVO iotCompany){
        String url = "/user/";
        UserModel userModel = new UserModel();
        userModel.setEmail(iotCompany.getContactsEmail());
        userModel.setIdCardNo(iotCompany.getContactsIdcard());
        userModel.setLoginCode(iotCompany.getAccount());
        userModel.setTelephone(iotCompany.getContactsMobile());
        userModel.setRole(roleId);
        Envelop envelop  = new Envelop();
        Map<String, Object> params = new HashMap<>();
        params.put("user_json_data",toJson(userModel));
        try {
            Map<String, Object> head = new HashMap<>();
            head.put("Content-Type","application/json; charset=UTF-8");
            HttpResponse response = HttpHelper.post(profileInnerUrl + url, params,head);
            ObjectResult result = toModel(response.getBody(),ObjectResult.class);
            if(result.isSuccessFlg()){
                UserModel addUserModel = toModel(toJson(result.getObj()),UserModel.class);
                iotCompany.setEhrUserId(addUserModel.getId());
                envelop.setStatus(200);
            }else {
                envelop.setStatus(-1);
                envelop.setErrorMsg(result.getErrorMsg());
            }
            return envelop;
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setStatus(-1);
            envelop.setErrorMsg(ErrorCode.SystemError.toString());
            return envelop;
        }
    }
    /**
     * 修改密码
     * @param userId
     * @param passWord
     * @return
     */
    public Envelop changePassWord(String userId,String passWord){
        Envelop envelop = new Envelop();
        String url = "/users/changePassWord";
        Map<String, Object> params = new HashMap<>();
        params.put("user_id",userId);
        params.put("password",passWord);
        try {
            HttpResponse response = HttpHelper.put(profileInnerUrl + url, params);
            ObjectResult result = toModel(response.getBody(),ObjectResult.class);
            if(result.isSuccessFlg()){
                envelop.setStatus(200);
                envelop.setSuccessMsg("修改成功");
            }else {
                envelop.setStatus(-1);
                envelop.setErrorMsg(result.getErrorMsg());
            }
            return envelop;
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setStatus(-1);
            envelop.setErrorMsg(ErrorCode.SystemError.toString());
            return envelop;
        }
    }
    /**
     * 根据id查找企业
     * @param id

+ 11 - 10
app/app-iot-server/src/main/resources/application.yml

@ -18,11 +18,11 @@ spring:
      max-wait: -1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
      min-idle: 1  # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
  application:
    name: app-emergency-server
    message: EHR Emergency Server
  resources:
    static-locations: classpath:/
    cache-period: 0
    name: app-iot-server
    message: App IOT Server
#  resources:
#    static-locations: classpath:/
#    cache-period: 0
@ -59,10 +59,11 @@ app:
  oauth2InnerUrl: http://172.19.103.73:10260/   # 认证中心,获取token ehr环境
  oauth2OuterUrl: http://27.154.233.186:10260/  # 上饶-授权外网映射
service-gateway:
  iotUrl: http://192.168.131.24:8088/svr-io
#  profileInnerUrl: http://172.19.103.48:10000/api/v1.0/admin/ # 物联网环境
  profileInnerUrl: http://172.19.103.73:10000/api/v1.0/admin   # 网关接口 ehr环境
  iotUrl: http://192.168.131.24:8088/svr-iot/
  profileInnerUrl: http://172.19.103.73:10000/api/v1.0/admin
  profileOuterUrl: http://27.154.233.186:10000/api/v1.0/admin
  portalInnerUrl: http://172.19.103.73:10280/api/v1.0/portal
  portalOuterUrl: http://27.154.233.186:10280/api/v1.0/portal
fast-dfs:
@ -70,7 +71,7 @@ fast-dfs:
  public-server: http://172.19.103.54:80/
logging:
  path: /data/logger
  file: app-emergency-server
  file: app-iot-server
---
spring:
@ -116,7 +117,7 @@ fast-dfs:
  accessUrl: http://11.1.2.9
logging:
  path: /data/logger
  file: app-emergency-server
  file: app-iot-server
#单点登录
#GET http://172.19.103.73:10260/oauth/sso?response_type=token&client_id=uzs5G0HgTp&state=sxy&scope=read&redirect_uri=http://192.168.1.221:8010/ehr/browser/common/login/signin?idCardNo=362321200108017313&user=admin