|
@@ -2,20 +2,32 @@ package com.fdkankan.agent.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.agent.entity.Agent;
|
|
|
import com.fdkankan.agent.mapper.IAgentMapper;
|
|
|
import com.fdkankan.agent.request.RequestAgent;
|
|
|
import com.fdkankan.agent.service.IAgentService;
|
|
|
+import com.fdkankan.agent.vo.AgentVo;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
import com.fdkankan.common.util.PasswordUtils;
|
|
|
import com.fdkankan.common.util.SsoUtil;
|
|
|
+import com.fdkankan.goods.entity.Camera;
|
|
|
+import com.fdkankan.goods.service.ICameraService;
|
|
|
+import com.fdkankan.order.service.IVirtualOrderService;
|
|
|
+import com.fdkankan.agent.util.ExcelUtil;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -23,7 +35,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
* 代理商表 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
- * @author
|
|
|
+ * @author
|
|
|
* @since 2021-12-23
|
|
|
*/
|
|
|
@Service
|
|
@@ -31,20 +43,29 @@ public class AgentServiceImpl extends ServiceImpl<IAgentMapper, Agent> implement
|
|
|
|
|
|
@Resource
|
|
|
private RedisTemplate<String,String> redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ private IVirtualOrderService virtualOrderService;
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject login(RequestAgent param) {
|
|
|
- if(param.getAgentId() == null || param.getAgentPassword() == null){
|
|
|
- throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
- }
|
|
|
-
|
|
|
+ public Agent getAgentById(String agentId) {
|
|
|
QueryWrapper<Agent> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("agent_id",param.getAgentId());
|
|
|
+ queryWrapper.eq("agent_id",agentId);
|
|
|
queryWrapper.eq("rec_status","A");
|
|
|
- Agent agent = this.getOne(queryWrapper);
|
|
|
- if(agent == null){
|
|
|
+ List<Agent> list = this.list(queryWrapper);
|
|
|
+ if(list == null || list.size()<=0){
|
|
|
throw new BusinessException(ErrorCode.USER_NOT_EXIST);
|
|
|
}
|
|
|
+ return list.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject login(RequestAgent param) {
|
|
|
+ if(param.getAgentId() == null || param.getAgentPassword() == null){
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ Agent agent = this.getAgentById(param.getAgentId());
|
|
|
String encryptPwd = PasswordUtils.encrypt(param.getAgentId(), param.getAgentPassword(), PasswordUtils.getStaticSalt());
|
|
|
if (!encryptPwd.equals(agent.getAgentPassword())){
|
|
|
throw new BusinessException(ErrorCode.PASSWORD_ERROR);
|
|
@@ -58,4 +79,79 @@ public class AgentServiceImpl extends ServiceImpl<IAgentMapper, Agent> implement
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Page<AgentVo> getPageList(RequestAgent param) {
|
|
|
+ QueryWrapper<Agent> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("rec_status","A");
|
|
|
+ if(StringUtils.isNotBlank(param.getAgentName())){
|
|
|
+ queryWrapper.like("agent_name",param.getAgentName());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(param.getAgentId())){
|
|
|
+ queryWrapper.like("agent_id",param.getAgentId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<Agent> agentPage = new Page<>();
|
|
|
+ agentPage.setCurrent(param.getPageNum());
|
|
|
+ agentPage.setSize(param.getPageSize());
|
|
|
+ Page<Agent> page = this.page(agentPage, queryWrapper);
|
|
|
+ List<AgentVo> agentVoList = new ArrayList<>();
|
|
|
+ for (Agent record : page.getRecords()) {
|
|
|
+ AgentVo agentVo = new AgentVo();
|
|
|
+ BeanUtils.copyProperties(record,agentVo);
|
|
|
+ agentVoList.add(agentVo);
|
|
|
+ }
|
|
|
+ Page<AgentVo> agentVoPage = new Page<>();
|
|
|
+ agentVoPage.setCurrent(agentPage.getCurrent());
|
|
|
+ agentPage.setSize(agentPage.getSize());
|
|
|
+ agentVoPage.setTotal(agentPage.getTotal());
|
|
|
+ agentVoPage.setRecords(agentVoList);
|
|
|
+ return agentVoPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String saveAgent(RequestAgent param) {
|
|
|
+ saveOrUpdate(param);
|
|
|
+ if (StringUtils.isNotBlank(param.getUploadFilePath())) {
|
|
|
+ List<Map<String, String>> list = ExcelUtil.readExcelForManageAgent(param.getUploadFilePath());
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ for (Map<String, String> map : list) {
|
|
|
+ String childName = map.get("0");
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isEmpty(childName) || !param.getAgentId().equals(map.get("4"))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Camera camera = cameraService.saveByAgent(childName, map.get("2"), param.getAgentId(), map.get("3"));
|
|
|
+ if(camera == null){
|
|
|
+ throw new BusinessException(ErrorCode.NOT_RECORD);
|
|
|
+ }
|
|
|
+ virtualOrderService.saveVirtualOrderByAgent(camera.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "操作成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String deleteAgent(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveOrUpdate(RequestAgent param){
|
|
|
+ Agent agent = new Agent();
|
|
|
+ agent.setId(param.getId());
|
|
|
+ agent.setAgentId(param.getAgentId());
|
|
|
+ agent.setAgentPassword(param.getAgentPassword());
|
|
|
+ agent.setAgentName(param.getAgentName());
|
|
|
+ agent.setAgentArea(param.getAgentArea());
|
|
|
+ agent.setAgentEmail(param.getAgentEmail());
|
|
|
+ agent.setAgentPhone(param.getAgentPhone());
|
|
|
+ agent.setAgentCountry(param.getAgentCountry());
|
|
|
+ agent.setAgentNum(param.getAgentNum());
|
|
|
+ agent.setRecStatus("A");
|
|
|
+ if(!this.saveOrUpdate(agent)){
|
|
|
+ throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|