|
@@ -8,27 +8,35 @@ 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.util.ExcelUtil;
|
|
|
+import com.fdkankan.agent.vo.AgentDetailTotalAmount;
|
|
|
+import com.fdkankan.agent.vo.AgentTotalAmountVo;
|
|
|
import com.fdkankan.agent.vo.AgentVo;
|
|
|
+import com.fdkankan.agent.vo.ResponseAgentCamera;
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
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.entity.CameraDetail;
|
|
|
+import com.fdkankan.goods.service.ICameraDetailService;
|
|
|
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.apache.commons.lang3.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 org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.io.File;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -47,6 +55,8 @@ public class AgentServiceImpl extends ServiceImpl<IAgentMapper, Agent> implement
|
|
|
private ICameraService cameraService;
|
|
|
@Autowired
|
|
|
private IVirtualOrderService virtualOrderService;
|
|
|
+ @Autowired
|
|
|
+ private ICameraDetailService cameraDetailService;
|
|
|
|
|
|
@Override
|
|
|
public Agent getAgentById(String agentId) {
|
|
@@ -81,25 +91,18 @@ public class AgentServiceImpl extends ServiceImpl<IAgentMapper, Agent> implement
|
|
|
|
|
|
@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()) {
|
|
|
+ Page<Agent> page = this.page(agentPage, getQueryWrapper(param));
|
|
|
+
|
|
|
+ List<AgentVo> agentVoList =page.getRecords().parallelStream().map(agent -> {
|
|
|
AgentVo agentVo = new AgentVo();
|
|
|
- BeanUtils.copyProperties(record,agentVo);
|
|
|
- agentVoList.add(agentVo);
|
|
|
- }
|
|
|
+ BeanUtils.copyProperties(agent, agentVo);
|
|
|
+ return agentVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
Page<AgentVo> agentVoPage = new Page<>();
|
|
|
agentVoPage.setCurrent(agentPage.getCurrent());
|
|
|
agentPage.setSize(agentPage.getSize());
|
|
@@ -132,10 +135,128 @@ public class AgentServiceImpl extends ServiceImpl<IAgentMapper, Agent> implement
|
|
|
|
|
|
@Override
|
|
|
public String deleteAgent(Long id) {
|
|
|
- this.removeById(id);
|
|
|
- return null;
|
|
|
+ if(!this.removeById(id)){
|
|
|
+ throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
+ }
|
|
|
+ return "删除成功";
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String updateAgentStatus(Long id, int status) {
|
|
|
+ Agent agent = this.getById(id);
|
|
|
+ if(agent == null){
|
|
|
+ throw new BusinessException(ErrorCode.NOT_RECORD);
|
|
|
+ }
|
|
|
+ agent.setState(status);
|
|
|
+ if(!this.saveOrUpdate(agent)){
|
|
|
+ throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
+ }
|
|
|
+ return "更新成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<AgentVo> searchAgentList(RequestAgent param) {
|
|
|
+ Page<AgentVo> pageList = this.getPageList(param);
|
|
|
+ pageList.getRecords().forEach(agentVo -> {
|
|
|
+ Integer count = cameraDetailService.getCountByAgentId(agentVo.getAgentId());
|
|
|
+ agentVo.setRepertory(agentVo.getAgentNum() -count);
|
|
|
+ virtualOrderService.getByStatusAndCameraId(agentVo, param.getStartDate(), param.getEndDate());
|
|
|
+ });
|
|
|
+ return pageList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AgentTotalAmountVo searchAgentListStatistics(RequestAgent param) {
|
|
|
+ if(redisTemplate.hasKey("AgentSearchListTotalAmount")){
|
|
|
+ String jsonObject = redisTemplate.opsForValue().get("AgentSearchListTotalAmount");
|
|
|
+ return JSONObject.parseObject(jsonObject, AgentTotalAmountVo.class);
|
|
|
+ }
|
|
|
+ List<Agent> list = this.list(getQueryWrapper(param));
|
|
|
+ if(list == null || list.size()<=0){
|
|
|
+ throw new BusinessException(ErrorCode.NOT_RECORD);
|
|
|
+ }
|
|
|
+ AgentTotalAmountVo totalAmountVo = new AgentTotalAmountVo();
|
|
|
+ for (Agent agent : list) {
|
|
|
+ Integer countByAgentId = cameraDetailService.getCountByAgentId(agent.getAgentId());
|
|
|
+ AgentVo agentVo = new AgentVo();
|
|
|
+ agentVo.setAgentId(agent.getAgentId());
|
|
|
+ virtualOrderService.getByStatusAndCameraId(agentVo,param.getStartDate(),param.getEndDate());
|
|
|
+
|
|
|
+ totalAmountVo.setTotalRepertory( totalAmountVo.getTotalRepertory() + (agent.getAgentNum() - countByAgentId));
|
|
|
+ totalAmountVo.setTotalAgentNum(totalAmountVo.getTotalAgentNum() + agent.getAgentNum());
|
|
|
+ totalAmountVo.setTotalSubExpend(totalAmountVo.getTotalSubExpend() + agentVo.getSubExpend());
|
|
|
+ totalAmountVo.setTotalSubExtract(totalAmountVo.getTotalSubExtract() + agentVo.getSubExtract());
|
|
|
+ totalAmountVo.setTotalSubRecharge(totalAmountVo.getTotalSubRecharge() + agentVo.getSubRecharge());
|
|
|
+ }
|
|
|
+ redisTemplate.opsForValue().set("AgentSearchListTotalAmount",JSONObject.toJSONString(totalAmountVo),7200 ,TimeUnit.SECONDS);
|
|
|
+ return totalAmountVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ResponseAgentCamera> searchAgentListDetail(RequestAgent param) {
|
|
|
+ return cameraDetailService.getPageByAgentId(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AgentDetailTotalAmount searchAgentListDetailStatistics(RequestAgent param) {
|
|
|
+ if(redisTemplate.hasKey("AgentSearchListDetailTotalAmount")){
|
|
|
+ String jsonObject = redisTemplate.opsForValue().get("AgentSearchListDetailTotalAmount");
|
|
|
+ return JSONObject.parseObject(jsonObject, AgentDetailTotalAmount.class);
|
|
|
+ }
|
|
|
+ AgentDetailTotalAmount totalAmount = new AgentDetailTotalAmount();
|
|
|
+ List<CameraDetail> detailList = cameraDetailService.getListByAgentId(param.getAgentId());
|
|
|
+ for (CameraDetail entity : detailList) {
|
|
|
+ Camera camera = cameraService.getById(entity.getCameraId());
|
|
|
+ if(camera == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ResponseAgentCamera vo = virtualOrderService.getPointsByCameraId(entity.getCameraId(), param.getStartDate(), param.getEndDate());
|
|
|
+ totalAmount.setTotalCharge(totalAmount.getTotalCharge() + vo.getCharge() );
|
|
|
+ totalAmount.setTotalExchangePoint(totalAmount.getTotalExchangePoint() + vo.getExchangePoint());
|
|
|
+ totalAmount.setTotalLessPoint(totalAmount.getTotalLessPoint() + vo.getLessPoint());
|
|
|
+ totalAmount.setTotalExtract(totalAmount.getTotalExtract().add(vo.getExtract()));
|
|
|
+ }
|
|
|
+ redisTemplate.opsForValue().set("AgentSearchListTotalAmount",JSONObject.toJSONString(totalAmount),7200 ,TimeUnit.SECONDS);
|
|
|
+ return totalAmount;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String uploadFile(MultipartFile file) throws Exception{
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ throw new BusinessException(ErrorCode.EMPTY_FILE);
|
|
|
+ }
|
|
|
+ File targetFile = new File(ConstantFilePath.AGENT_PATH);
|
|
|
+ if (!targetFile.exists()) {
|
|
|
+ targetFile.mkdirs();
|
|
|
+ }
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ targetFile = new File(ConstantFilePath.AGENT_PATH + fileName);
|
|
|
+ int count = 1;
|
|
|
+ while (targetFile.exists()) {
|
|
|
+ targetFile = new File(ConstantFilePath.AGENT_PATH + fileName.substring(0, fileName.lastIndexOf(".")) + "(" + count + ")" + fileName.substring(fileName.lastIndexOf(".")));
|
|
|
+ ++count;
|
|
|
+ }
|
|
|
+ file.transferTo(targetFile);
|
|
|
+ return ConstantFilePath.AGENT_PATH + targetFile.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ private QueryWrapper<Agent> getQueryWrapper(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());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(param.getStartDate())){
|
|
|
+ queryWrapper.between("create_time",param.getStartDate()+" 00:00:00",param.getEndDate()+" 23:59:59");
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ return queryWrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void saveOrUpdate(RequestAgent param){
|
|
|
Agent agent = new Agent();
|
|
|
agent.setId(param.getId());
|