Commit 84f40054 authored by 周亚武's avatar 周亚武

小程序接口更新

parent 3318e751
package com.mortals.xhx.busiz.applets.req;
import com.mortals.xhx.busiz.BaseReq;
import lombok.Data;
/**
* 企业详情
*
* @author: zxfei
* @date: 2023/10/7 16:53
*/
@Data
public class CompanyReq extends BaseReq {
/**
* 企业id
*/
private long companyId;
}
package com.mortals.xhx.busiz.applets.req;
import com.mortals.xhx.busiz.BaseReq;
import lombok.Data;
/**
* 登录请求
*
* @author: zxfei
* @date: 2023/10/7 16:53
*/
@Data
public class LoginReq extends BaseReq {
/**
* 微信openId
*/
private String openId;
}
package com.mortals.xhx.busiz.applets.web; package com.mortals.xhx.busiz.applets.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.xhx.busiz.applets.req.NewsReq; import com.mortals.framework.exception.AppException;
import com.mortals.xhx.module.company.model.CompanyLabelsQuery; import com.mortals.framework.model.Context;
import com.mortals.xhx.busiz.applets.req.CompanyReq;
import com.mortals.xhx.module.company.model.CompanyPatentEntity;
import com.mortals.xhx.module.company.model.CompanyPatentQuery;
import com.mortals.xhx.module.company.model.CompanyQuery; import com.mortals.xhx.module.company.model.CompanyQuery;
import com.mortals.xhx.module.company.service.CompanyLabelsService; import com.mortals.xhx.module.company.service.CompanyPatentService;
import com.mortals.xhx.module.company.service.CompanyService; import com.mortals.xhx.module.company.service.CompanyService;
import com.mortals.xhx.module.labels.model.LabelsQuery; import com.mortals.xhx.module.labels.model.LabelsQuery;
import com.mortals.xhx.module.labels.service.LabelsService; import com.mortals.xhx.module.labels.service.LabelsService;
import com.mortals.xhx.module.news.model.NewsCategoryQuery; import com.mortals.xhx.module.product.model.ProductQuery;
import com.mortals.xhx.module.product.service.ProductService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
...@@ -25,11 +35,15 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -25,11 +35,15 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@Slf4j @Slf4j
@RequestMapping("/api/v1/company") @RequestMapping("/api/v1/company")
public class CompanyApiController extends AbstractBaseController<NewsReq>{ public class CompanyApiController extends AbstractBaseController<CompanyReq>{
@Autowired @Autowired
private CompanyService companyService; private CompanyService companyService;
@Autowired @Autowired
private LabelsService labelsService; private LabelsService labelsService;
@Autowired
private CompanyPatentService companyPatentService;
@Autowired
private ProductService productService;
/** /**
* 公司标注列表 * 公司标注列表
...@@ -63,4 +77,38 @@ public class CompanyApiController extends AbstractBaseController<NewsReq>{ ...@@ -63,4 +77,38 @@ public class CompanyApiController extends AbstractBaseController<NewsReq>{
return rest; return rest;
} }
/**
* 公司知识产权数量列表及推荐产品列表
*/
@PostMapping(value = "companyInfo")
public Rest<Object> companyInfo(@RequestBody CompanyReq companyReq){
String busiDesc = "公司详情";
log.info("【{}】【请求体】--> {}", busiDesc, JSONObject.toJSONString(companyReq));
Rest<Object> rest = Rest.ok(busiDesc + " 【成功】");
Context context = this.getContext();
Map<String, Object> model = new HashMap<>();
try {
if (ObjectUtils.isEmpty(companyReq.getCompanyId())) {
throw new AppException("详细查询id不能为空!");
}
CompanyPatentQuery companyPatentQuery = new CompanyPatentQuery();
companyPatentQuery.setCompanyId(companyReq.getCompanyId());
ProductQuery productQuery = new ProductQuery();
productQuery.setCompanyId(String.valueOf(companyReq.getCompanyId()));
JSONObject data = new JSONObject();
data.put("patentList",companyPatentService.find(companyPatentQuery));
data.put("productList",productService.find(productQuery));
rest.setData(data);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error(busiDesc, e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
} }
package com.mortals.xhx.busiz.applets.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.IAuthTokenService;
import com.mortals.xhx.base.login.web.LoginForm;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.busiz.applets.req.LoginReq;
import com.mortals.xhx.busiz.applets.req.StaffReq;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.module.company.model.CompanyQuery;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.model.StaffRecordEntity;
import com.mortals.xhx.module.staff.service.StaffRecordService;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_TOKEN_EXPIRED_CONTENT;
/**
* @author ZYW
* @date 2023-10-30 9:39
*/
@RestController
@Slf4j
@RequestMapping("/api/v1/login")
public class LoginApiController extends AbstractBaseController<LoginReq>{
@Autowired
private UserService userService;
@Autowired
private StaffService staffService;
@Autowired
private IAuthTokenService authTokenService;
@RequestMapping("login")
public Rest<Object> login(@RequestBody LoginReq loginReq) throws Exception {
String busiDesc = "小程序登录";
Rest<Object> rest = Rest.ok();
try {
JSONObject data = new JSONObject();
String token = authTokenService.getToken(request);
data.put("token", token);
UserQuery userQuery = new UserQuery();
userQuery.setOpenId(loginReq.getOpenId());
UserEntity userEntity = userService.selectOne(userQuery);
//如果没查到用户,则第一次登录,根据openid创建用户
if(ObjectUtils.isEmpty(userEntity)){
UserEntity entity = new UserEntity();
entity.setUserType(1); //普通用户
entity.setLastLoginTime(new Date());
entity.setOpenId(loginReq.getOpenId());
entity.setRealName("游客");
userService.save(entity);
log.info( busiDesc, "第一次登陆,保存用户信息成功");
rest.setMsg("未查询到用户信息");
}else {
StaffQuery staffQuery = new StaffQuery();
if(ObjectUtils.isEmpty(userEntity.getStaffId())){
rest.setMsg("后台未绑定员工信息");
}else {
staffQuery.setId(userEntity.getStaffId());
StaffEntity staffEntity = staffService.selectOne(staffQuery);
data.put("userInfo",staffEntity);
if(ObjectUtils.isEmpty(userEntity)){
rest.setMsg("未查询到员工信息");
}
}
}
rest.setData(data);
}catch (Exception e) {
log.error(busiDesc, e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment