package com.honghu.cloud.controller;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Maps;
import com.honghu.cloud.bean.Store;
import com.honghu.cloud.code.ResponseCode;
import com.honghu.cloud.dto.AccessoryDto;
import com.honghu.cloud.dto.OrderFormDto;
import com.honghu.cloud.dto.PayoffLogDto;
import com.honghu.cloud.dto.SysConfigDto;
import com.honghu.cloud.dto.UserDto;
import com.honghu.cloud.feign.AccessoryFeignClient;
import com.honghu.cloud.feign.OrderFormFeignClient;
import com.honghu.cloud.feign.PayoffLogFeignClient;
import com.honghu.cloud.feign.SysConfigFeignClient;
import com.honghu.cloud.feign.UserFeignClient;
import com.honghu.cloud.service.impl.StoreServiceImpl;
import com.honghu.cloud.tools.QueryTools;
import com.honghu.cloud.tools.SecurityUserHolder;
import com.honghu.cloud.utils.CommUtil;

import net.sf.json.JSONObject;


@RestController
@CrossOrigin(origins = "*" , maxAge = 3600)
@RequestMapping("/applet/store_payoff")
public class AppletStorePayoffController {

@Autowired
private SysConfigFeignClient sysConfigFeignClient;

@Autowired
private StoreServiceImpl storeService;

@Autowired
private QueryTools queryTools;

@Autowired
private UserFeignClient userFeignClient;

@Autowired
private PayoffLogFeignClient payoffLogFeignClient;

@Autowired
private OrderFormFeignClient orderFormFeignClient;
@Autowired
private AccessoryFeignClient accessoryFeignClient;


/**
* 结算列表页
* @param request
* @param response
* @param currentPage
* @param orderBy
* @param orderType
* @param beginTime
* @param endTime
* @param pl_sn
* @param order_id
* @param status
* @return
*/

@RequestMapping(value = { "/payofflog_list" } , method = RequestMethod.POST)
public Map<String , Object> payofflog_list(HttpServletRequest request,@RequestBody JSONObject json) {

String currentPage = json.optString("currentPage");
String orderBy = json.optString("orderBy");
String orderType = json.optString("orderType");
String beginTime = json.optString("beginTime");
String endTime = json.optString("endTime");
String pl_sn = json.optString("pl_sn");
String order_id = json.optString("order_id");
String status = json.optString("status");

Map<String , Object> map = Maps.newHashMap();
Map<String,Object> maps= this.queryTools.getParams(currentPage,20, orderBy, orderType);
if ((pl_sn != null) && (!pl_sn.equals(""))) {
maps.put("pl_sn", pl_sn);
map.put("pl_sn", pl_sn);
}

if ((order_id != null) && (!order_id.equals(""))) {
maps.put("order_id", order_id);
map.put("order_id", order_id);
}

if ((beginTime != null) && (!beginTime.equals(""))) {
maps.put("add_Time_more_than_equal", CommUtil.formatDate(beginTime));
map.put("beginTime", beginTime);
}

if ((endTime != null) && (!endTime.equals(""))) {
maps.put("add_Time_less_than_equal", CommUtil.formatDate(endTime));
map.put("endTime", endTime);
}

if ((status != null) && (!status.equals(""))) {
if (status.equals("not")) {
maps.put("status", 0);
}
if (status.equals("ok")) {
maps.put("status", 1);
}
if (status.equals("underway")) {
maps.put("status_1", 3);
maps.put("status_2", 4);
}
if (status.equals("already")) {
maps.put("status", 6);
}
} else {
status = "not";
}

/*maps.put("status", Integer.valueOf(st));*/
map.put("status", status);

UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}

maps.put("seller_id", user.getId());
/*IPageList pList = this.payoffLogService.list(maps);
*/
map.putAll(payoffLogFeignClient.list(maps));
Calendar a = Calendar.getInstance();
a.set(5, 1);
a.roll(5, -1);
int maxDate = a.get(5);
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= maxDate; i++) {
list.add(Integer.valueOf(i));
}
SysConfigDto obj = this.sysConfigFeignClient.getSysConfig();
String select = getSelectedDate(obj.getPayoff_count());
String[] str = select.split(",");
String ms = "";
for (int i = 0; i < str.length; i++) {
if (i + 1 == str.length) {
ms = ms + str[i] + "日";
} else {
ms = ms + str[i] + "日、";
}
}
map.put("payoff_mag_default", "今天是"
+ DateFormat.getDateInstance(0).format(new Date())
+ ",本月的结算日期为" + ms + ",请于结算日申请结算。");
return ResponseCode.buildSuccessMap(map);
}

private String getSelectedDate(int payoff_count) {
Calendar a = Calendar.getInstance();
a.set(5, 1);
a.roll(5, -1);
int allDate = a.get(5);
String selected = "";
if (payoff_count == 1) {
selected = CommUtil.null2String(Integer.valueOf(allDate));
} else if (payoff_count == 2) {
if (allDate == 31) {
selected = "15,31";
}
if (allDate == 30) {
selected = "15,30";
}
if (allDate == 29) {
selected = "14,29";
}
if (allDate == 28) {
selected = "14,28";
}
} else if (payoff_count == 3) {
if (allDate == 31) {
selected = "10,20,31";
}
if (allDate == 30) {
selected = "10,20,30";
}
if (allDate == 29) {
selected = "10,20,29";
}
if (allDate == 28) {
selected = "10,20,28";
}
} else if (payoff_count == 4) {
if (allDate == 31) {
selected = "7,14,21,31";
}
if (allDate == 30) {
selected = "7,14,21,30";
}
if (allDate == 29) {
selected = "7,14,21,29";
}
if (allDate == 28) {
selected = "7,14,21,28";
}
}
return selected;
}
/**
* 可结算列表页
* @param request
* @param response
* @param currentPage
* @param orderBy
* @param orderType
* @param beginTime
* @param endTime
* @param pl_sn
* @param order_id
* @return
*/
@RequestMapping(value = { "/payofflog_ok_list" } , method = RequestMethod.POST)
public Map<String , Object> payofflog_ok_list(HttpServletRequest request,@RequestBody JSONObject json) {

String currentPage = json.optString("currentPage");
String orderBy = json.optString("orderBy");
String orderType = json.optString("orderType");
String beginTime = json.optString("beginTime");
String endTime = json.optString("endTime");
String pl_sn = json.optString("pl_sn");
String order_id = json.optString("order_id");
Map<String , Object> data = Maps.newHashMap();
Map<String,Object> maps= queryTools.getParams(currentPage, 20,orderBy, orderType);
if ((pl_sn != null) && (!pl_sn.equals(""))) {
maps.put("pl_sn", pl_sn);
data.put("pl_sn", pl_sn);
}
if ((order_id != null) && (!order_id.equals(""))) {
maps.put("order_id", order_id);
data.put("order_id", order_id);
}

if ((beginTime != null) && (!beginTime.equals(""))) {
maps.put("add_Time_more_than_equal", CommUtil.formatDate(beginTime));
data.put("beginTime", beginTime);
}

if ((endTime != null) && (!endTime.equals(""))) {
maps.put("add_Time_less_than_equal", CommUtil.formatDate(endTime));
data.put("endTime", endTime);
}

maps.put("status" , 1); // 可结算状态
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}

maps.put("seller_id", user.getId());
data.putAll(this.payoffLogFeignClient.list(maps));

Calendar a = Calendar.getInstance();
a.set(5, 1);
a.roll(5, -1);
int maxDate = a.get(5);
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= maxDate; i++) {
list.add(Integer.valueOf(i));
}
SysConfigDto obj = this.sysConfigFeignClient.getSysConfig();
String select = getSelectedDate(obj.getPayoff_count());
String[] str = select.split(",");
String ms = "";
for (int i = 0; i < str.length; i++) {
if (i + 1 == str.length) {
ms = ms + str[i] + "日";
} else {
ms = ms + str[i] + "日、";
}
}
data.put("payoff_mag_default", "今天是"
+ DateFormat.getDateInstance(0).format(new Date())
+ ",本月的结算日期为" + ms + ",请于结算日申请结算。");
return ResponseCode.buildSuccessMap(data);
}

/**
* 账单详情
* @param request
* @param response
* @param id
* @param currentPage
* @param op
* @return
*/
@RequestMapping( value = { "/payofflog_info" } , method = RequestMethod.POST)
public Map<String , Object> payofflog_info(HttpServletRequest request,@RequestBody JSONObject json) {
String id = json.optString("id");
String currentPage = json.optString("currentPage");
String op = json.optString("op");
if ((id != null) && (!id.equals(""))) {
PayoffLogDto payofflog = this.payoffLogFeignClient.selectByPrimaryKey(Long
.valueOf(Long.parseLong(id)));
if (null!=payofflog&&null!=payofflog.getVoucher_photo_id()) {
AccessoryDto accessoryDto = accessoryFeignClient.selectByPrimaryKey(payofflog.getVoucher_photo_id());
payofflog.setVoucher_photo(accessoryDto);
}
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
Map<String , Object> data = Maps.newHashMap();
if (user.getId().equals(payofflog.getSeller_id())) {
data.put("OrderFormDto", queryOrderInfo(payofflog.getOrder_id(),user.getId()));
data.put("obj", payofflog);
data.put("currentPage", currentPage);
data.put("op", op);
return ResponseCode.buildSuccessMap(data);
} else {
return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
}
} else {
return ResponseCode.buildReturnMap(ResponseCode.PARAM_ERROR, null);
}
}
public OrderFormDto queryOrderInfo(String order_id,Long user_id) {
OrderFormDto of = new OrderFormDto();
if ((order_id != null) && (!order_id.equals(""))) {
UserDto user = this.userFeignClient.selectByPrimaryKey(CommUtil.null2Long(user_id));

Map<String, Object> params = Maps.newHashMap();
params.put("order_id", order_id);
params.put("store_id", user.getStore_id());
params.put("orderBy", "addTime");
params.put("orderType", "asc");
params.put("currentPage", 0);
params.put("pageSize", 1);
List<OrderFormDto> ofs = this.orderFormFeignClient.queryPageList(params);

if (null != ofs && ofs.size() > 0) {
of = ofs.get(0);
}
}
return of;
}
/**
* 账单结算
* @param request
* @param response
* @param mulitId
* @param currentPage
* @return
*/
@RequestMapping(value = { "/payofflog_edit" } , method = RequestMethod.POST)
public Map<String , Object> payofflog_edit(HttpServletRequest request,@RequestBody JSONObject json) {
String mulitId = json.optString("mulitId");
for (String id : mulitId.split(",")) {

if ((id != null) && (!id.equals(""))) {
PayoffLogDto obj = this.payoffLogFeignClient.selectByPrimaryKey(CommUtil.null2Long(id));
if (obj != null) {
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
if ((user.getId().toString().equals(obj.getSeller_id().toString()))&& (obj.getStatus() == 1 || obj.getStatus() == 0)) {
OrderFormDto of = this.orderFormFeignClient.selectByPrimaryKey(CommUtil.null2Long(obj.getO_id()));
if (of != null) {
boolean goods = false;//商品购买
boolean group = false;//团购也就是生活类订单
//of.getOrder_status() == 50 为买家评价完
//of.getOrder_status() == 65 为订单不可评价
if ((of.getOrder_status() == 40) || (of.getOrder_status() == 50) || (of.getOrder_status() == 65)) {
goods = true;
}
//of.getOrder_cat() == 2 为生活类订单
//of.getOrder_status() == 20为为已付款待发货
if ((of.getOrder_cat() == 2) && (of.getOrder_status() == 20)) {
group = true;
}
if ((goods) || (group)) {
obj.setStatus(3);
obj.setApply_time(new Date());
this.payoffLogFeignClient.updateById(obj);
return ResponseCode.buildSuccessMap(null);
}
}else{
return ResponseCode.buildReturnMap(ResponseCode.ORDER_NOT_EXISTS_ERROR, null);
}
}
}
}
}
return ResponseCode.buildReturnMap(ResponseCode.FAILURE, null);
//return ResponseCode.buildSuccessMap(null);
}

/**
* 批量统计
* @param request
* @param response
* @param mulitId
* @throws ClassNotFoundException
*/
@RequestMapping(value = { "/payofflog_ajax" } , method = RequestMethod.POST)
public Map<String , Object> payofflog_ajax(HttpServletRequest request,@RequestBody JSONObject json)
throws ClassNotFoundException {
String mulitId = json.optString("mulitId");
if (mulitId == null) {
mulitId = "";
}
String[] ids = mulitId.split(",");
double order_total_price = 0.0D;
double commission_amount = 0.0D;
double total_amount = 0.0D;
boolean error = true;

for (String id : ids) {
if (!id.equals("")) {
PayoffLogDto obj = this.payoffLogFeignClient.selectByPrimaryKey(Long.parseLong(id));
if (obj != null) {
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder.getCurrentUser(request).getId());
if(user == null){
return ResponseCode.buildReturnMap(ResponseCode.TOKEN_EXPIRE, null);
}
if (user.getParent_id()!=null) {
user = this.userFeignClient.selectByPrimaryKey(user.getParent_id());
}
Store store = this.storeService.selectByPrimaryKey(CommUtil.null2Long(user
.getStore_id()));
if(store == null){
return ResponseCode.buildReturnMap(ResponseCode.NOTSTORE, null);
}
if (user.getId().equals(obj.getSeller_id())) {
total_amount = CommUtil.add(Double.valueOf(total_amount), obj.getTotal_amount());
commission_amount = CommUtil.add(Double.valueOf(commission_amount), obj.getCommission_amount());
order_total_price = CommUtil.add(Double.valueOf(order_total_price), obj.getOrder_total_price());
} else {
error = false;
break;
}
} else {
error = false;
break;
}
}
}
Map<String, Object> map = Maps.newHashMap();
map.put("order_total_price", Double.valueOf(order_total_price));
map.put("commission_amount", Double.valueOf(commission_amount));
map.put("total_amount", Double.valueOf(total_amount));
map.put("error", Boolean.valueOf(error));
return map;
}
/**
* 账单数据导出
* @param request
* @param response
* @param beginTime
* @param endTime
* @param pl_sn
* @param order_id
* @param status
*/
/*@RequestMapping(value = { "/payofflog_excel" } ,method = RequestMethod.POST)
public void payofflog_excel(HttpServletRequest request,HttpServletResponse response ,@RequestBody JSONObject json) {
String beginTime = json.optString("beginTime");
String endTime = json.optString("endTime");
String pl_sn = json.optString("pl_sn");
String order_id = json.optString("order_id");
String status = json.optString("status");
UserDto user = this.userFeignClient.selectByPrimaryKey(SecurityUserHolder
.getCurrentUser(request).getId());
user = user.getParent() == null ? user : user.getParent();

Map<String,Object> maps= queryTools.getParams(null,100000, "addTime", "desc");
maps.put("seller_id", user.getId());

String status2 = "0";
if ((status != null) && (!status.equals(""))) {
status2 = CommUtil.null2String(status);
}

if ((pl_sn != null) && (!pl_sn.equals(""))) {
maps.put("pl_sn", pl_sn);
}

if ((order_id != null) && (!order_id.equals(""))) {
maps.put("order_id", order_id);
}

if ((beginTime != null) && (!beginTime.equals(""))) {
maps.put("add_Time_more_than_equal", CommUtil.formatDate(beginTime));
}

if ((endTime != null) && (!endTime.equals(""))) {
maps.put("add_Time_less_than_equal", CommUtil.formatDate(endTime));
}

int st = 0;
if ((status != null) && (!status.equals(""))) {
if (status.equals("not")) {
st = 0;
}
if (status.equals("underway")) {
st = 3;
}
if (status.equals("already")) {
st = 6;
}
} else {
status = "not";
}
maps.put("status", st);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.add(2, 0);
c.set(5, 1);
String first = format.format(c.getTime());
Calendar ca = Calendar.getInstance();
ca.set(5, ca.getActualMaximum(5));
String last = format.format(ca.getTime());

Map<String, Object> list = this.payoffLogFeignClient.list(maps);

if (list.get("result") != null) {
List<PayoffLogDto> datas = (List<PayoffLogDto>) list.get("result");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("结算账单");
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
List<HSSFClientAnchor> anchor = new ArrayList<>();
for (int i = 0; i < datas.size(); i++) {
anchor.add(new HSSFClientAnchor(0, 0, 1000, 255, (short) 1,
2 + i, (short) 1, 2 + i));
}
sheet.setColumnWidth(0, 6000);
sheet.setColumnWidth(1, 4000);
sheet.setColumnWidth(2, 4000);
sheet.setColumnWidth(3, 6000);
sheet.setColumnWidth(4, 6000);
sheet.setColumnWidth(5, 6000);
sheet.setColumnWidth(6, 6000);
sheet.setColumnWidth(7, 6000);
sheet.setColumnWidth(8, 6000);
sheet.setColumnWidth(9, 6000);
sheet.setColumnWidth(10, 6000);
sheet.setColumnWidth(11, 8000);
HSSFFont font = wb.createFont();
font.setFontName("Verdana");
font.setBoldweight((short) 100);
font.setFontHeight((short) 300);
font.setColor((short) 12);
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment((short) 2);
style.setVerticalAlignment((short) 1);
style.setFillForegroundColor((short) 41);
style.setFillPattern((short) 1);
style.setBottomBorderColor((short) 10);
style.setBorderBottom((short) 1);
style.setBorderLeft((short) 1);
style.setBorderRight((short) 1);
style.setBorderTop((short) 1);
style.setFont(font);
HSSFRow row = sheet.createRow(0);
row.setHeight((short) 500);
HSSFCell cell = row.createCell(0);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 11));
cell.setCellStyle(style);
String title = "结算账单";
String time = CommUtil.null2String(CommUtil.formatDate(beginTime)
+ " - " + CommUtil.formatDate(endTime));
cell.setCellValue(this.sysConfigFeignClient.getSysConfig().getTitle()
+ title + "(" + time + ")");
HSSFCellStyle style1 = wb.createCellStyle();
style1.setDataFormat(HSSFDataFormat.getBuiltinFormat("yyyy-mm-dd"));
style1.setWrapText(true);
style1.setAlignment((short) 2);
HSSFCellStyle style2 = wb.createCellStyle();
style2.setAlignment((short) 2);
row = sheet.createRow(1);
cell = row.createCell(0);
cell.setCellStyle(style2);
cell.setCellValue("账单流水号");
cell = row.createCell(1);
cell.setCellStyle(style2);
cell.setCellValue("商家名称");
cell = row.createCell(2);
cell.setCellStyle(style2);
cell.setCellValue("账单说明");
cell = row.createCell(3);
cell.setCellStyle(style2);
cell.setCellValue("账单入账时间");
cell = row.createCell(4);
cell.setCellStyle(style2);
cell.setCellValue("申请结算时间");
cell = row.createCell(5);
cell.setCellStyle(style2);
cell.setCellValue("完成结算时间");
cell = row.createCell(6);
cell.setCellStyle(style2);
cell.setCellValue("账单总金额(元)");
cell = row.createCell(7);
cell.setCellStyle(style2);
cell.setCellValue("账单总佣金(元)");
cell = row.createCell(8);
cell.setCellStyle(style2);
cell.setCellValue("账单应结算(元)");
cell = row.createCell(9);
cell.setCellStyle(style2);
cell.setCellValue("操作财务");
cell = row.createCell(10);
cell.setCellStyle(style2);
cell.setCellValue("操作管理员");
cell = row.createCell(11);
cell.setCellStyle(style2);
cell.setCellValue("结算备注");
double all_order_price = 0.0D;
double all_commission_amount = 0.0D;
double all_total_amount = 0.0D;
for (int j = 2; j <= datas.size() + 1; j++) {
row = sheet.createRow(j);
int i = 0;
cell = row.createCell(i);
cell.setCellStyle(style2);
cell.setCellValue(((PayoffLogDto) datas.get(j - 2)).getPl_sn());
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(((PayoffLogDto) datas.get(j - 2)).getSeller()
.getUserName());
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(((PayoffLogDto) datas.get(j - 2)).getPl_info());
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.formatLongDate(((PayoffLogDto) datas
.get(j - 2)).getAddTime()));
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.formatLongDate(((PayoffLogDto) datas
.get(j - 2)).getApply_time()));
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.formatLongDate(((PayoffLogDto) datas
.get(j - 2)).getComplete_time()));
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.null2String(((PayoffLogDto) datas
.get(j - 2)).getOrder_total_price()));
all_order_price = CommUtil.add(Double.valueOf(all_order_price),
((PayoffLogDto) datas.get(j - 2)).getOrder_total_price());
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.null2String(((PayoffLogDto) datas
.get(j - 2)).getCommission_amount()));
all_commission_amount = CommUtil.add(
Double.valueOf(all_commission_amount),
((PayoffLogDto) datas.get(j - 2)).getCommission_amount());
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.null2String(((PayoffLogDto) datas
.get(j - 2)).getTotal_amount()));
all_total_amount = CommUtil.add(
Double.valueOf(all_total_amount),
((PayoffLogDto) datas.get(j - 2)).getTotal_amount());
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.null2String(((PayoffLogDto) datas
.get(j - 2)).getFinance_userName()));
cell = row.createCell(++i);
cell.setCellStyle(style2);
if (((PayoffLogDto) datas.get(j - 2)).getAdmin() != null) {
cell.setCellValue(CommUtil.null2String(((PayoffLogDto) datas
.get(j - 2)).getAdmin().getUserName()));
}
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(CommUtil.null2String(((PayoffLogDto) datas
.get(j - 2)).getPayoff_remark()));
}
int m = datas.size() + 2;
row = sheet.createRow(m);
int i = 0;
cell = row.createCell(i);
cell.setCellStyle(style2);
cell.setCellValue("总计");
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue("本次总销售金额:");
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(all_order_price);
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue("本次总销售佣金:");
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(all_commission_amount);
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue("本次总结算金额:");
cell = row.createCell(++i);
cell.setCellStyle(style2);
cell.setCellValue(all_total_amount);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String excel_name = sdf.format(new Date());
try {
String path = request.getSession().getServletContext()
.getRealPath("")
+ File.separator + "excel";
response.setContentType("application/x-download");
response.addHeader("Content-Disposition",
"attachment;filename=" + excel_name + ".xls");
OutputStream os = response.getOutputStream();
wb.write(os);
os.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
}*/

}