package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.base.tips.SuccessTip;
|
import com.stylefeng.guns.core.exception.GunsException;
|
import com.stylefeng.guns.core.exception.ServiceExceptionEnum;
|
import com.stylefeng.guns.core.util.DateUtil;
|
import com.stylefeng.guns.modular.system.controller.resp.TAgentResp;
|
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
|
import com.stylefeng.guns.modular.system.enums.OrderStateEnum;
|
import com.stylefeng.guns.modular.system.enums.PayStatusEnum;
|
import com.stylefeng.guns.modular.system.enums.UserTypeEnum;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.poi.hdf.extractor.TC;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import com.stylefeng.guns.core.log.LogObjectHolder;
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.OutputStream;
|
import java.math.BigDecimal;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 控制器
|
*
|
* @author fengshuonan
|
* @Date 2023-02-20 09:18:08
|
*/
|
@Controller
|
@RequestMapping("/tAgent")
|
public class TAgentController extends BaseController {
|
|
private String PREFIX = "/system/tAgent/";
|
|
@Autowired
|
private ITAgentService tAgentService;
|
|
@Autowired
|
private ITRegionService tRegionService;
|
|
|
/**
|
* 跳转到首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tAgent.html";
|
}
|
|
/**
|
* 跳转到添加
|
*/
|
@RequestMapping("/tAgent_add")
|
public String tAgentAdd() {
|
return PREFIX + "tAgent_add.html";
|
}
|
|
/**
|
* 跳转到修改
|
*/
|
@RequestMapping("/tAgent_update/{tAgentId}")
|
public String tAgentUpdate(@PathVariable Integer tAgentId, Model model) {
|
TAgent tAgent = tAgentService.selectById(tAgentId);
|
model.addAttribute("item",tAgent);
|
LogObjectHolder.me().set(tAgent);
|
return PREFIX + "tAgent_edit.html";
|
}
|
|
/**
|
* 跳转详情页面
|
*/
|
@RequestMapping("/agentDetail")
|
public String agentDetail(Integer agentId, Model model) {
|
tAgentService.detail(agentId,model);
|
return PREFIX + "tAgentDetail.html";
|
}
|
|
/**
|
* 跳转区域页面
|
*/
|
@RequestMapping("/areaDetail")
|
public String areaDetail(Model model) {
|
List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("province",tRegions);
|
return PREFIX + "tAgentArea.html";
|
}
|
|
/**
|
* 获取列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String principal,String principalPhone,String createTime) {
|
EntityWrapper<TAgent> wrapper = tAgentService.getAgentWrapper(principal,principalPhone,createTime);
|
List<TAgent> tAgents = tAgentService.selectList(wrapper);
|
// 代理商列表数据封装(导出共用)
|
return tAgentService.getAgentResp(tAgents);
|
}
|
|
/**
|
* 获取列表
|
*/
|
@RequestMapping(value = "/list-back")
|
@ResponseBody
|
public Object listBack(String condition) {
|
return tAgentService.selectList(null);
|
}
|
|
/**
|
* 新增
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TAgent tAgent) {
|
|
int count = tAgentService.selectCount(new EntityWrapper<TAgent>().eq("principalPhone", tAgent.getPrincipalPhone()));
|
if(count>0){
|
return new SuccessTip(500,"该代理商已存在!");
|
}
|
|
String[] split = tAgent.getAreaId().split("/");
|
// 查询省市
|
// 黑龙江省/大兴安岭地区
|
// 702/852
|
TRegion province = tRegionService.selectById(split[0]);
|
tAgent.setProvinceName(province.getName());
|
tAgent.setProvinceCode(province.getCode());
|
TRegion city = tRegionService.selectById(split[1]);
|
tAgent.setCityName(city.getName());
|
tAgent.setCityCode(city.getCode());
|
tAgentService.insert(tAgent);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 删除
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer tAgentId) {
|
tAgentService.deleteById(tAgentId);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改用户状态
|
*/
|
@RequestMapping(value = "/update-status")
|
@ResponseBody
|
public Object updateStatus(Integer id,Integer status) {
|
TAgent tAgent = tAgentService.selectById(id);
|
if(1 == status){
|
tAgent.setStatus(2);
|
}
|
if(2 == status){
|
tAgent.setStatus(1);
|
}
|
tAgentService.updateById(tAgent);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TAgent tAgent) {
|
tAgentService.updateById(tAgent);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 详情
|
*/
|
@RequestMapping(value = "/detail/{tAgentId}")
|
@ResponseBody
|
public Object detail(@PathVariable("tAgentId") Integer tAgentId) {
|
return tAgentService.selectById(tAgentId);
|
}
|
|
|
@ApiOperation(value = "省市区查询",notes="省市区查询")
|
@RequestMapping(value = "/area")
|
@ResponseBody
|
public Object area() {
|
return tRegionService.getAreaList();
|
}
|
|
@ApiOperation(value = "省查询",notes="省查询")
|
@RequestMapping(value = "/areaProvince")
|
@ResponseBody
|
public Object areaProvince(Model model) {
|
return tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
}
|
|
@ApiOperation(value = "市区查询",notes="市区查询")
|
@RequestMapping(value = "/areaCity")
|
@ResponseBody
|
public Object areaCity(Integer parentId) {
|
return tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id",parentId));
|
}
|
|
|
@ApiOperation(value = "导出代理商列表",notes="导出代理商列表")
|
@RequestMapping(value = "/export")
|
@ResponseBody
|
public void export(String principal,String principalPhone,String createTime, HttpServletResponse response) {
|
try {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String time1 = format.format(date);
|
String fileName = "Agent"+time1+".xls";
|
String[] title = new String[] {"时间","姓名","联系电话","代理区域","订单数量",
|
"有效订单","已发放优惠券","已使用优惠券","累计优惠券金额","司机充值","司机数","状态"};
|
EntityWrapper<TAgent> wrapper = tAgentService.getAgentWrapper(principal,principalPhone,createTime);
|
// 是否异常
|
List<TAgent> list = tAgentService.selectList(wrapper);
|
|
List<TAgentResp> agentResp = tAgentService.getAgentResp(list);
|
|
String[][] values = new String[agentResp.size()][];
|
for (int i = 0; i < agentResp.size(); i++) {
|
TAgentResp d = agentResp.get(i);
|
values[i] = new String[title.length];
|
values[i][0] = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(d.getCreateTime());
|
values[i][1] = d.getPrincipal();
|
values[i][2] = d.getPrincipalPhone();
|
values[i][3] = d.getProvinceName()+d.getCityName();
|
values[i][4] = String.valueOf(d.getOrderSum());
|
values[i][5] = String.valueOf(d.getValidOrder());
|
values[i][6] = String.valueOf(d.getIssuedCoupon());
|
values[i][7] = String.valueOf(d.getUsedCoupon());
|
values[i][8] = String.valueOf(d.getCouponPriceSum());
|
values[i][9] = String.valueOf(d.getDriverRecharge() == null ? "0":d.getDriverRecharge());
|
values[i][10] = String.valueOf(d.getDriverCount());
|
Integer status1 = d.getStatus();
|
if(1 == status1){
|
values[i][11] = "正常";
|
}else if(2 == status1){
|
values[i][11] = "冻结";
|
}else {
|
values[i][11] = "删除";
|
}
|
}
|
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
|
ExcelUtil.setResponseHeader(response, fileName);
|
OutputStream os = response.getOutputStream();
|
wb.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|