package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.util.DateUtil;
|
import com.stylefeng.guns.core.util.ExcelUtil;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import net.sf.json.JSONObject;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.OutputStream;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
@Controller
|
@RequestMapping("/tTaxiCard")
|
public class TTaxiCardController extends BaseController {
|
|
private String PREFIX = "/system/tTaxiCard/";
|
|
@Autowired
|
private ITTaxiCardService taxiCardService;
|
|
@Autowired
|
private ISysCouponRecordService couponRecordService;
|
|
@Autowired
|
private ITCompanyCityService companyCityService;
|
|
@Autowired
|
private ITRegionService regionService;
|
|
@Autowired
|
private ITCompanyService companyService;
|
|
@Autowired
|
private IUserService userService;
|
|
@Autowired
|
private ITTaxiCardPaymentService taxiCardPaymentService;
|
|
@RequestMapping("")
|
public String index(){
|
return PREFIX + "tTaxiCard.html";
|
}
|
|
@RequestMapping("/audit")
|
public String audit(){
|
return PREFIX + "tTaxiCardAudit.html";
|
}
|
|
@RequestMapping("/tTaxiCardPayment/{cardId}")
|
public String tTaxiCardPayment(@PathVariable Integer cardId, Model model){
|
model.addAttribute("cardId",cardId);
|
return PREFIX + "tTaxiCardPayment.html";
|
}
|
|
@RequestMapping("/tTaxiCardPayment_detail/{paymentId}")
|
public String tTaxiCardPaymentDetail(@PathVariable Integer paymentId, Model model){
|
Map<String,Object> map = taxiCardService.searchRecordDetail(paymentId);
|
JSONObject json = JSONObject.fromObject(map.get("content"));
|
if (json.containsKey("businessTypes")){
|
List<Integer> list = JSONArray.parseArray(json.getString("businessTypes"),Integer.class);
|
StringBuilder str = new StringBuilder();
|
for (Integer integer : list) {
|
if (integer == 1){
|
str.append("快车,");
|
}else if (integer == 2){
|
str.append("出租车,");
|
}else if (integer == 3){
|
str.append("跨城出行,");
|
}else if (integer == 4){
|
str.append("同城小件物流,");
|
}else if (integer == 5){
|
str.append("跨城小件物流,");
|
}
|
}
|
map.put("businessTypes",str.substring(0,str.length()-1));
|
}
|
|
/// 使用期至
|
String validDateTo = DateUtil.plusDay(Integer.parseInt(map.get("validDate").toString()),map.get("createTime").toString());
|
String momentDate = DateUtil.getTime();
|
|
if (DateUtil.compareTime(validDateTo, momentDate)){
|
map.put("validDateTo",validDateTo);
|
}else {
|
map.put("validDateTo",validDateTo + " (<span style='color:red'>已过期</span>)");
|
}
|
|
/// 使用时间段
|
if (json.containsKey("timeQuantum")){
|
List<String> list = JSONArray.parseArray(json.getString("timeQuantum"),String.class);
|
StringBuilder stringBuilder = new StringBuilder();
|
for (String s : list) {
|
stringBuilder.append(s);
|
stringBuilder.append(" , ");
|
}
|
map.put("timeQuantum",stringBuilder.substring(0,stringBuilder.length()-3));
|
}
|
|
/// 使用地区
|
String[] arr = map.get("companyCityId").toString().split(";");
|
StringBuilder cityName = new StringBuilder();
|
for (String s : arr) {
|
TCompanyCity companyCity = companyCityService.selectById(s);
|
String name = regionService.selectOne(new EntityWrapper<TRegion>().eq("code",companyCity.getCityCode())).getName();
|
cityName.append(name).append(",");
|
}
|
map.put("cityName",cityName.substring(0,cityName.length()-1));
|
|
Integer taxiCardId = taxiCardPaymentService.selectById(paymentId).getTaxiCardId();
|
TTaxiCard tTaxiCard = taxiCardService.selectById(taxiCardId);
|
if (tTaxiCard.getType() == 6){ /// 优惠包
|
JSONObject jsonn = JSONObject.fromObject(tTaxiCard.getContent());
|
String coupons = json.getString("coupons");
|
List<String> list = JSON.parseArray(coupons,String.class);
|
|
int couponsNum = 0;
|
for (String s : list) {
|
List<Integer> list1 = JSON.parseArray(s,Integer.class);
|
couponsNum += list1.get(0);
|
}
|
map.put("note","送" + couponsNum + "张寄件优惠券");
|
}else if (tTaxiCard.getType() == 5){ /// 物流打折卡
|
JSONObject jsonn = JSONObject.fromObject(tTaxiCard.getContent());
|
String discount = json.getString("discount");
|
map.put("note","每次寄件打" + discount + "折");
|
}else if (tTaxiCard.getType() == 4){ /// 打折天数卡
|
JSONObject jsonn = JSONObject.fromObject(tTaxiCard.getContent());
|
String discount = json.getString("discount");
|
map.put("note","享" + tTaxiCard.getValidDate() + "天打" + discount + "折");
|
}else if (tTaxiCard.getType() == 3){ /// 次数卡
|
JSONObject jsonn = JSONObject.fromObject(tTaxiCard.getContent());
|
String discountAmount = json.getString("discountAmount");
|
map.put("note","每次打车最高抵扣" + discountAmount + "元");
|
}else if (tTaxiCard.getType() == 2){ /// 优惠卡
|
JSONObject jsonn = JSONObject.fromObject(tTaxiCard.getContent());
|
String fullReduction = json.getString("fullReduction");
|
List<String> list = JSON.parseArray(fullReduction,String.class);
|
|
List<Double> doubles = new ArrayList<>();
|
for (String s : list) {
|
List<Double> list1 = JSON.parseArray(s,Double.class);
|
doubles.add(list1.get(1));
|
}
|
Collections.sort(doubles);
|
map.put("note","最高优惠" + doubles.get(doubles.size()-1) + "元");
|
}else if (tTaxiCard.getType() == 1){ /// 次数卡
|
JSONObject jsonn = JSONObject.fromObject(tTaxiCard.getContent());
|
String time = json.getString("time");
|
String discount = json.getString("discount");
|
map.put("note","享" + time + "次打折打" + discount + "折");
|
}
|
model.addAttribute("item",map);
|
return PREFIX + "tTaxiCardPayment_detail.html";
|
}
|
|
@RequestMapping("/tTaxiCard_add")
|
public String tTaxiCardAdd(Model model){
|
model.addAttribute("roleType",ShiroKit.getUser().getRoleType());
|
return PREFIX + "tTaxiCard_add.html";
|
}
|
|
/// 跳转选择优惠券
|
@RequestMapping("/openCheckCoupons/{num}")
|
public String openCheckCoupons(@PathVariable Integer num, Model model){
|
model.addAttribute("jumpType",2);
|
model.addAttribute("num",num);
|
return "/system/sysCouponRecord/sysCouponRecord.html";
|
}
|
|
@RequestMapping("/tTaxiCard_edit/{id}")
|
public String tTaxiCardEdit(@PathVariable Integer id, Model model){
|
TTaxiCard tTaxiCard = taxiCardService.selectById(id);
|
model.addAttribute("viewIdentity","myself"); /// 查看角色--自己
|
|
model.addAttribute("item",tTaxiCard);
|
model.addAttribute("roleType",ShiroKit.getUser().getRoleType());
|
return PREFIX + "tTaxiCard_edit.html";
|
}
|
|
@RequestMapping("/tTaxiCardBranch_edit/{id}")
|
public String tTaxiCardBranch_edit(@PathVariable Integer id, Model model){
|
TTaxiCard tTaxiCard = taxiCardService.selectById(id);
|
model.addAttribute("viewIdentity","you"); /// 查看角色--对方
|
model.addAttribute("item",tTaxiCard);
|
model.addAttribute("roleType",userService.selectById(tTaxiCard.getCreateUserId()).getRoleType());
|
return PREFIX + "tTaxiCardAudit_detail.html";
|
}
|
|
@RequestMapping("/tTaxiCardList")
|
@ResponseBody
|
public Object ttaxiCardList(String startTime, String endTime, Integer type, String nameStr){
|
Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
|
Wrapper wrapper = new EntityWrapper<TTaxiCard>().eq("auditStatus",2)
|
.eq("companyId",ShiroKit.getUser().getObjectId()).orderBy("id",false);
|
|
if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)){
|
wrapper.between("createTime",startTime + " 00:00:00",endTime + " 23:59:59");
|
}
|
|
if (ToolUtil.isNotEmpty(type)){
|
wrapper.eq("type",type);
|
}
|
|
if (ToolUtil.isNotEmpty(nameStr)){
|
wrapper.like("name",nameStr);
|
}
|
|
List<Map<String,Object>> list = taxiCardService.selectMapsPage(page,wrapper).getRecords();
|
List<Map<String,Object>> listx = new ArrayList<>();
|
|
for (Map<String, Object> map : list) {
|
|
JSONObject json = JSONObject.fromObject(map.get("content"));
|
|
if (json.containsKey("businessTypes")){
|
String businessTypes = json.getString("businessTypes");
|
List<String> list1 = JSON.parseArray(businessTypes,String.class);
|
StringBuilder businessType = new StringBuilder();
|
for (String s : list1) {
|
switch (s) {
|
case "1":
|
businessType.append("快车,");
|
break;
|
case "2":
|
businessType.append("出租车,");
|
break;
|
case "3":
|
businessType.append("跨城出行,");
|
break;
|
case "4":
|
businessType.append("同城小件物流,");
|
break;
|
case "5":
|
businessType.append("跨城小件物流,");
|
break;
|
}
|
}
|
|
if (ToolUtil.isNotEmpty(businessType)){
|
map.put("businessTypes",businessType.substring(0,businessType.length()-1));
|
}
|
}
|
|
if (ToolUtil.isNotEmpty(map.get("companyCityId"))){
|
String[] arr = map.get("companyCityId").toString().split(";");
|
StringBuilder cityName = new StringBuilder();
|
for (String s : arr) {
|
TCompanyCity companyCity = companyCityService.selectById(s);
|
if (ToolUtil.isNotEmpty(companyCity)){
|
String name = regionService.selectOne(new EntityWrapper<TRegion>().eq("code",companyCity.getCityCode())).getName();
|
cityName.append(name).append(",");
|
}
|
}
|
|
if (cityName.length()>1){
|
map.put("cityName",cityName.substring(0,cityName.length()-1));
|
listx.add(map);
|
}
|
}else {
|
map.put("cityName","全国");
|
listx.add(map);
|
}
|
}
|
page.setRecords(listx);
|
return super.packForBT(page);
|
}
|
|
|
@RequestMapping("/tTaxiCardAuditList")
|
@ResponseBody
|
public Object tTaxiCardAuditList(String startTime, String endTime, Integer type, String nameStr){
|
Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
|
Wrapper wrapper = new EntityWrapper<TTaxiCard>().ne("companyId",ShiroKit.getUser().getObjectId()).orderBy("id",false);
|
|
if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)){
|
wrapper.between("createTime",startTime + " 00:00:00",endTime + " 23:59:59");
|
}
|
|
if (ToolUtil.isNotEmpty(type)){
|
wrapper.eq("type",type);
|
}
|
|
if (ToolUtil.isNotEmpty(nameStr)){
|
wrapper.like("name",nameStr);
|
}
|
|
List<Map<String,Object>> list = taxiCardService.selectMapsPage(page,wrapper).getRecords();
|
List<Map<String,Object>> listx = new ArrayList<>();
|
|
for (Map<String, Object> map : list) {
|
map.put("companyName",companyService.selectById(map.get("companyId").toString()).getName());
|
|
JSONObject json = JSONObject.fromObject(map.get("content"));
|
|
if (json.containsKey("businessTypes")){
|
String businessTypes = json.getString("businessTypes");
|
List<String> list1 = JSON.parseArray(businessTypes,String.class);
|
StringBuilder businessType = new StringBuilder();
|
for (String s : list1) {
|
switch (s) {
|
case "1":
|
businessType.append("快车,");
|
break;
|
case "2":
|
businessType.append("出租车,");
|
break;
|
case "3":
|
businessType.append("跨城出行,");
|
break;
|
case "4":
|
businessType.append("同城小件物流,");
|
break;
|
case "5":
|
businessType.append("跨城小件物流,");
|
break;
|
}
|
}
|
|
if (ToolUtil.isNotEmpty(businessType)){
|
map.put("businessTypes",businessType.substring(0,businessType.length()-1));
|
}
|
}
|
|
String[] arr = map.get("companyCityId").toString().split(";");
|
StringBuilder cityName = new StringBuilder();
|
for (String s : arr) {
|
TCompanyCity companyCity = companyCityService.selectById(s);
|
if (ToolUtil.isNotEmpty(companyCity)){
|
String name = regionService.selectOne(new EntityWrapper<TRegion>().eq("code",companyCity.getCityCode())).getName();
|
cityName.append(name).append(",");
|
}
|
}
|
|
if (cityName.length()>1){
|
map.put("cityName",cityName.substring(0,cityName.length()-1));
|
listx.add(map);
|
}
|
}
|
page.setRecords(listx);
|
return super.packForBT(page);
|
}
|
|
|
/// 查询打车卡购买记录列表
|
@RequestMapping("/tTaxiCardPaymentList")
|
@ResponseBody
|
public Object tTaxiCardPaymentList(Integer takeCardId, String startTime, String endTime, String name){
|
Page<Map<String,Object>> page = new PageFactory<Map<String,Object>>().defaultPage();
|
page.setRecords(taxiCardService.tTaxiCardPaymentList(takeCardId,page,startTime,endTime,name));
|
return super.packForBT(page);
|
}
|
|
/// 初始化适用城市选择器
|
@RequestMapping("/initSuitCity")
|
@ResponseBody
|
public Object initSuitCity(){
|
List<TCompanyCity> list = companyCityService.selectList(new EntityWrapper<TCompanyCity>().eq("companyId",ShiroKit.getUser().getObjectId()));
|
List<String> stringList = new ArrayList<>();
|
for (TCompanyCity tCompanyCity : list) {
|
String area = "";
|
area += tCompanyCity.getId() + ";";
|
if (ToolUtil.isNotEmpty(tCompanyCity.getProvinceCode())){
|
area += regionService.selectOne(new EntityWrapper<TRegion>().eq("code",tCompanyCity.getProvinceCode())).getName();
|
}
|
if (ToolUtil.isNotEmpty(tCompanyCity.getCityCode())){
|
area += regionService.selectOne(new EntityWrapper<TRegion>().eq("code",tCompanyCity.getCityCode())).getName();
|
}
|
if (ToolUtil.isNotEmpty(tCompanyCity.getAreaCode())){
|
area += regionService.selectOne(new EntityWrapper<TRegion>().eq("code",tCompanyCity.getAreaCode())).getName();
|
}
|
|
stringList.add(area);
|
}
|
return stringList;
|
}
|
|
|
/// 初始化平台--查看分公司适用城市选择器
|
@RequestMapping("/initSuitCityBranch")
|
@ResponseBody
|
public Object initSuitCityBranch(Integer id){
|
List<TCompanyCity> list = companyCityService.selectList(new EntityWrapper<TCompanyCity>().eq("companyId",taxiCardService.selectById(id).getCompanyId()));
|
List<String> stringList = new ArrayList<>();
|
for (TCompanyCity tCompanyCity : list) {
|
String area = "";
|
area += tCompanyCity.getId() + ";";
|
if (ToolUtil.isNotEmpty(tCompanyCity.getProvinceCode())){
|
area += regionService.selectOne(new EntityWrapper<TRegion>().eq("code",tCompanyCity.getProvinceCode())).getName();
|
}
|
if (ToolUtil.isNotEmpty(tCompanyCity.getCityCode())){
|
area += regionService.selectOne(new EntityWrapper<TRegion>().eq("code",tCompanyCity.getCityCode())).getName();
|
}
|
if (ToolUtil.isNotEmpty(tCompanyCity.getAreaCode())){
|
area += regionService.selectOne(new EntityWrapper<TRegion>().eq("code",tCompanyCity.getAreaCode())).getName();
|
}
|
|
stringList.add(area);
|
}
|
return stringList;
|
}
|
|
|
@RequestMapping("/add")
|
@ResponseBody
|
public Object add(TTaxiCard taxiCard){
|
Integer companyId = ShiroKit.getUser().getObjectId();
|
Integer createUserId = ShiroKit.getUser().getId();
|
taxiCard.setCompanyId(companyId);
|
taxiCard.setCreateUserId(createUserId);
|
taxiCard.setState(2);
|
if (ShiroKit.getUser().getRoleType() == 1){
|
taxiCard.setAuditStatus(2);
|
}else {
|
taxiCard.setAuditStatus(1);
|
}
|
taxiCard.setCreateTime(DateUtil.parseTime(DateUtil.getTime()));
|
|
String note = taxiCard.getNote();
|
note = note.replaceAll("& lt;", "<").replaceAll("& gt;", ">");
|
|
note = note.replaceAll("\\(", "& #40;").replaceAll("\\)", "& #41;");
|
taxiCard.setNote(note);
|
|
System.out.println(taxiCard);
|
taxiCardService.insert(taxiCard);
|
return SUCCESS_TIP;
|
}
|
|
|
@RequestMapping("/searchPayment")
|
@ResponseBody
|
public Object searchPayment(Integer id){
|
TTaxiCardPayment tTaxiCardPayment = taxiCardPaymentService.selectOne(new EntityWrapper<TTaxiCardPayment>().eq("taxiCardId",id));
|
if (ToolUtil.isNotEmpty(tTaxiCardPayment)){
|
return "该打车卡已经产生交易记录,不允许再编辑";
|
}
|
return SUCCESS_TIP;
|
}
|
|
|
@RequestMapping("/edit")
|
@ResponseBody
|
public Object edit(TTaxiCard taxiCard){
|
String note = taxiCard.getNote();
|
note = note.replaceAll("& lt;", "<").replaceAll("& gt;", ">");
|
|
note = note.replaceAll("\\(", "& #40;").replaceAll("\\)", "& #41;");
|
taxiCard.setNote(note);
|
|
System.out.println(taxiCard);
|
taxiCardService.updateById(taxiCard);
|
return SUCCESS_TIP;
|
}
|
|
|
@RequestMapping("/delete")
|
@ResponseBody
|
public Object delete(Integer id){
|
TTaxiCardPayment tTaxiCardPayment = taxiCardPaymentService.selectOne(new EntityWrapper<TTaxiCardPayment>().eq("taxiCardId",id));
|
if (ToolUtil.isNotEmpty(tTaxiCardPayment)){
|
return "该打车卡已经被用户购买,不允许删除";
|
}
|
taxiCardService.deleteById(id);
|
return SUCCESS_TIP;
|
}
|
|
|
@RequestMapping("/updateState")
|
@ResponseBody
|
public Object updateState(Integer id, Integer state){
|
TTaxiCard tTaxiCard = taxiCardService.selectById(id);
|
tTaxiCard.setState(state);
|
taxiCardService.updateById(tTaxiCard);
|
return SUCCESS_TIP;
|
}
|
|
|
@RequestMapping("/auditSubmit")
|
@ResponseBody
|
public Object auditSubmit(TTaxiCard taxiCard){
|
taxiCardService.updateById(taxiCard);
|
return SUCCESS_TIP;
|
}
|
|
|
/// 查询优惠券
|
@RequestMapping("/searchCoupons")
|
@ResponseBody
|
public Object searchCoupons(){
|
Integer companyId = ShiroKit.getUser().getObjectId();
|
return couponRecordService.selectList(new EntityWrapper<SysCouponRecord>().eq("companyId",companyId));
|
}
|
|
/// 查询优惠券名称
|
@RequestMapping("/searchCouponsById")
|
@ResponseBody
|
public Object searchCouponsById(Integer id){
|
return couponRecordService.selectById(id);
|
}
|
|
|
/// 查询content对应的json
|
@RequestMapping("/searchContent")
|
@ResponseBody
|
public Object searchContent(Integer id){
|
return taxiCardService.selectById(id).getContent();
|
}
|
|
|
/// 导出某张打车卡的所有购买记录
|
@RequestMapping(value = "/exportAllRecord")
|
@ResponseBody
|
public Object exportAllRecord(HttpServletResponse response,@RequestParam Integer takeCardId,@RequestParam String startTime,
|
@RequestParam String endTime,@RequestParam String name) {
|
try {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String time = format.format(date);
|
String fileName = "打车卡购买记录"+time+".xls";
|
String[] title = new String[] {"购买时间","用户名称","用户手机号","打车卡名称","金额"};
|
List<Map<String,Object>> mapList = taxiCardService.tTaxiCardPaymentLists(takeCardId,startTime,endTime,name);
|
|
String[][] values = new String[mapList.size()][];
|
for (int i = 0; i < mapList.size(); i++) {
|
Map<String,Object> d=mapList.get(i);
|
values[i] = new String[title.length];
|
values[i][0]=d.get("createTime").toString();
|
values[i][1]=d.get("nickName").toString();
|
values[i][2]=d.get("phone").toString();
|
values[i][3]=d.get("cardName").toString();
|
values[i][4]=d.get("payMoney").toString();
|
}
|
String fileNameTitle="打车卡购买记录";
|
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(fileNameTitle+time, title, values, null);
|
this.setResponseHeader(response, fileName);
|
OutputStream os = response.getOutputStream();
|
wb.write(os);
|
os.flush();
|
os.close();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
/*return ApiUtil.putFailObj("导出失败");*/
|
}
|
return SUCCESS_TIP;
|
}
|
|
|
/**
|
* 设置文件响应头
|
* @param response
|
* @param fileName
|
*/
|
private void setResponseHeader(HttpServletResponse response, String fileName) {
|
try {
|
response.setContentType("application/octet-stream;charset=UTF-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
|
response.addHeader("Pargam", "no-cache");
|
response.addHeader("Cache-Control", "no-cache");
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
}
|
}
|
}
|