package com.iamberry.rst.controllers.cm; import com.iamberry.redis.RedisUtils; import com.iamberry.rst.core.address.City; import com.iamberry.rst.core.address.District; import com.iamberry.rst.core.address.Province; import com.iamberry.rst.core.cm.*; import com.iamberry.rst.core.fm.*; import com.iamberry.rst.core.order.Product; import com.iamberry.rst.core.order.ProductColor; import com.iamberry.rst.core.order.ProductType; import com.iamberry.rst.core.page.PagedResult; import com.iamberry.rst.core.sys.Admin; import com.iamberry.rst.core.tools.KuaiDi100; import com.iamberry.rst.core.tools.LogisticsInfo; import com.iamberry.rst.faces.address.AddressService; import com.iamberry.rst.faces.cm.*; import com.iamberry.rst.faces.fm.ComplaintDetectInfoService; import com.iamberry.rst.faces.fm.ComplaintSignclosedInfoService; import com.iamberry.rst.faces.fm.ComplaintSmallClassInfoService; import com.iamberry.rst.faces.order.EfastOrderService; import com.iamberry.rst.faces.order.LogisticsInfoService; import com.iamberry.rst.faces.order.OrderDepartService; import com.iamberry.rst.faces.product.ProductService; import com.iamberry.rst.faces.sms.SmsService; import com.iamberry.rst.faces.sys.SysService; import com.iamberry.rst.util.GenerateKeyUtil; import com.iamberry.rst.util.SmsConfig; import com.iamberry.rst.utils.*; import com.iamberry.wechat.tools.NameUtils; import com.iamberry.wechat.tools.ResponseJson; import com.iamberry.wechat.tools.ResultInfo; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.StringUtils; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.commons.CommonsMultipartFile; import org.springframework.web.servlet.ModelAndView; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.text.MessageFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.*; /** * Created by wxm */ @Controller @RequestMapping("/admin/customer") public class AdminCustomerController { private Logger logger = LoggerFactory.getLogger(AdminCustomerController.class); @Autowired private CompanyInfoService companyInfoService; @Autowired private StoreInfoService storeInfoService; @Autowired private SalesOrderService salesOrderService; @Autowired private CustomerService customerService; @Autowired private ProductService productService; @Autowired private SysService sysService; @Autowired private ComplaintTypeInfoService complaintTypeInfoService; @Autowired private VisitService visitService; @Autowired private QuestionDescribeService questionDescribeService; @Autowired private ComplaintQuestionInfoService complaintQuestionInfoService; @Autowired private SmsService smsService; @Autowired private ComplaintSignclosedInfoService complaintSignclosedInfoService; @Autowired private ComplaintSmallClassInfoService complaintSmallClassInfoService; @Autowired private AddressService addressService; @Autowired private PostageService postageService; @Autowired private EfastOrderService efastOrderService; @Autowired private RelationOrderService relationOrderService; @Autowired private GenerateKeyUtil generateKeyUtil ; @Autowired private CmRelationService cmRelationService ; @Autowired private ProcMethodService procMethodService ; @Autowired private LogisticsInfoService logisticsInfoService; @Autowired private ComplaintDetectInfoService complaintDetectInfoService; @Autowired private OrderDepartService orderDepartService; /** * 获取客诉列表 * * @param request * @return */ @RequiresPermissions("customer:list:customer") @RequestMapping("/_customer_list") public ModelAndView getCustomer(HttpServletRequest request, CustomerInfo customer, @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize, @RequestParam(value = "pageNO", defaultValue = "1", required = false) Integer pageNO, @RequestParam(value = "totalNum", defaultValue = "0", required = false) Integer totalNum) { ModelAndView mv = new ModelAndView("cm/customer/custome_list"); // PagedResult pagedResult = ptsBomService.listCustomer(pageNO, pageSize, ptsBom, totalNum == 0); // if (totalNum != 0) { // pagedResult.setTotal(totalNum); // } // //获取产品集合,用于页面选择产品 // List list = produceService.getProduceList(); // mv.addObject("produceList", list); // StitchAttrUtil.getSa().setModelAndView(customer, mv, "/admin/bom/_bom_list", pagedResult); return mv; } /** * 跳转到添加客诉页面 * * @return */ @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/to_add_customer") public ModelAndView toAddCustomer(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cm/customer/add_customer"); //获取产品集合,用于页面选择产品 // List produceList = produceService.getProduceList(); // mv.addObject("produceList", produceList); return mv; } /** * 跳转到修改客诉页面 * * @return */ @RequiresPermissions("customer:update:customer") @RequestMapping(value = "/to_update_customer") public ModelAndView toUpdateCustomer(HttpServletRequest request, Integer customerId) { ModelAndView mv = new ModelAndView("cm/customer/update_customer"); ProductType productType = new ProductType(); //查询产品类型集合 List typeList = productService.listProductType(productType); //查询客诉类型集合 List complaintTypeList = complaintTypeInfoService.listComplaintTypeInfo(new ComplaintTypeInfo()); //查询跟进客服集合 Admin admin = new Admin(); admin.setAdminDept(3); admin.setAdminStatus(1); List adminList = sysService.listSelectAdmin(admin); //获取登录人id Integer loginAdminId = AdminUtils.getLoginAdminId(); //查询客诉基本信息 CustomerInfo customerInfo = customerService.getCustomerInfo(customerId); /*查询处理方式*/ CmRelation cmRelation = cmRelationService.getCmRelationByCustomerId(customerInfo.getCustomerId()); /*获取寄出寄入产品*/ cmRelationService.getSendAndBackProduct(cmRelation); /*处理方式*/ ProcMethod procMethod = procMethodService.getProcMethodById(cmRelation.getProcMethodId()); if (customerInfo.getTypeId() == 1 || (procMethod.getProcMethodIsSend()==2 && procMethod.getProcMethodIsBack() == 2)) { customerInfo.setIsNeedSelectOrder(2); //不需要订单 } else { customerInfo.setIsNeedSelectOrder(1); } //setIsNeedSelectOrder if (customerInfo.getIsNeedSelectOrder() == 1 ) { RelationOrder relationOrder = new RelationOrder(); relationOrder.setRelationId(cmRelation.getRelationId()); List relationOrderList = relationOrderService.getRelationOrderList(relationOrder); String[] salesIds = new String[relationOrderList.size()]; for (int k = 0; k < relationOrderList.size(); k++) { salesIds[k] = String.valueOf(relationOrderList.get(k).getSalesId()); } if(salesIds!=null && salesIds.length > 0){ SalesOrder so = new SalesOrder(); so.setSalesIds(salesIds); List orderList = salesOrderService.listSalesOrder(so); for (SalesOrder sor : orderList) { SalesOrderItem salesOrderItem = new SalesOrderItem(); salesOrderItem.setItemOrderId(sor.getSalesId()); List salesOrderItemList = salesOrderService.listSalesOrderItem(salesOrderItem); sor.setSalesOrderItemList(salesOrderItemList); } mv.addObject("salesOrderList", orderList); } } else { mv.addObject("salesOrderList", null); } if ("2".equals(customerInfo.getCustomerIsVisit())) { //1:不需要回访 2:需要回访 Visit visit = new Visit(); visit.setCustomerId(customerInfo.getCustomerId()); visit = visitService.getVisit(visit); mv.addObject("visit", visit); } //查询关联问题 ComplaintQuestionInfo complaintQuestionInfo = complaintQuestionInfoService.getQuestionById(customerInfo.getQuestionId()); //查询问题小类 ComplaintSmallClassInfo complaintSmallClassInfo = new ComplaintSmallClassInfo(); complaintSmallClassInfo.setComplaintId(complaintQuestionInfo.getComplaintId()); List complaintSmallClassInfoList = complaintSmallClassInfoService.listComplaintSmallClassInfo(complaintSmallClassInfo); //查询问题大类 ProductType pType = productService.getProductType(customerInfo.getCustomerId()); ComplaintTypeInfo complaintTypeInfo = new ComplaintTypeInfo(); complaintTypeInfo.setComplaintType(pType.getComplaintType()); List complaintTypeInfoList = complaintTypeInfoService.listComplaintTypeInfo(complaintTypeInfo); mv.addObject("cmRelation", cmRelation); mv.addObject("procMethod", procMethod); mv.addObject("customerInfo", customerInfo); mv.addObject("typeList", typeList); mv.addObject("complaintTypeList", complaintTypeList); mv.addObject("complaintTypeList", complaintTypeList); mv.addObject("adminList", adminList); mv.addObject("loginAdminId", loginAdminId); mv.addObject("complaintQuestionInfo", complaintQuestionInfo); mv.addObject("complaintSmallClassInfoList", complaintSmallClassInfoList); mv.addObject("complaintTypeInfoList", complaintTypeInfoList); return mv; } /** * 查询问题描述 * * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/select_question_describe") public ResponseJson selectQuestionDescribe(HttpServletRequest request, Integer customerId) throws Exception { if (customerId == null || customerId == 0) { return new ResponseJson(500, "未获取到问题描述", 500); } //查询问题描述表 QuestionDescribe questionDescribe = new QuestionDescribe(); questionDescribe.setCustomerId(customerId); questionDescribe = questionDescribeService.listQuestionDescribe(questionDescribe).get(0); ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("questionDescribe", questionDescribe); return rj; } /** * 搜索订单列表弹出框 * * @return */ @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/select_order") public ModelAndView selectOrder(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cm/customer/order_list"); //获取销售公司 List companyInfoList = companyInfoService.listCompanyInfo(new CompanyInfo()); mv.addObject("companyInfoList", companyInfoList); return mv; } /** * 添加订单列表弹出框 * * @return */ @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/add_order") public ModelAndView addOder(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cm/customer/order_add"); return mv; } /** * 添加订单 * * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/add_order_info") public ResponseJson addOrderInfo(HttpServletRequest request, SalesOrder salesOrder, String itemJson) throws Exception { List list = new ArrayList<>(); JSONArray jsonArray = JSONArray.fromObject(itemJson); list = (List) JSONArray.toCollection(jsonArray, SalesOrderItem.class); Integer salesAmount = 0; for (int i = 0; i < list.size(); i++) { SalesOrderItem salesOrderItem = list.get(i); if (salesOrderItem.getItemIsSource() == 1) { //产品来源 1:产品颜色表,2:配件表 Product product = productService.getProductById(salesOrderItem.getItemColorId()); ProductColor productColor = productService.getProduceColor(salesOrderItem.getItemColorId()); salesOrderItem.setItemProductType(product.getProductType()); salesOrderItem.setItemProductName(product.getProductName()); salesOrderItem.setItemProductPic(productColor.getColorPicture()); salesOrderItem.setItemProductColor(productColor.getColorName()); salesOrderItem.setItemColorBar(productColor.getColorBar()); salesOrderItem.setItemProductPrice(productColor.getColorPrice()); salesOrderItem.setItemProductDiscount(productColor.getColorDiscount()); salesOrderItem.setItemIsSource(1); salesAmount += productColor.getColorDiscount(); } } salesOrder.setSalesOpenId("0"); salesOrder.setSalesAmount(salesAmount); salesOrder.setSalesPayMoney(salesAmount); salesOrder.setSalesOrderStatus(1); salesOrder.setSalesCreateTime(new Date()); //salesOrder.setSalesPayTime(new Date()); salesOrder.setSalesLastMoney(salesAmount); salesOrder.setSalesWaitMoney(0); salesOrder.setSalesPayMoney(salesAmount); salesOrder.setSalesSalesTime(new Date()); salesOrder.setSalesDiscountMoney(salesAmount); salesOrder.setSalesPledgeMoney(0); salesOrder.setSalesRemainDeposit(0); salesOrder.setSalesType(1); salesOrder.setSalesStatus(1);//确认状态:0(未确认)1(确认)2(挂起)3(作废) salesOrder.setSalesPayStatus(2); //已付款 salesOrder.setSalesProcessStatus(0); //单据状态:0(正常单)1(问题单) salesOrder.setSalesIsSend(0); //0:否 1:是 是否通知配货 salesOrder.setSalesIsLocked(0); //是否锁定 0:否 1:是 salesOrder.setSalesIsSeparate(0); //是否缺货 0:否 1:是 salesOrder.setSalesShippingFee(0); //邮费 salesOrder.setSalesDeliver(2); // 已出库 Integer adminId = AdminUtils.getLoginAdminId(); String orderCode = GenerateKeyUtil.createOrderCode(adminId); salesOrder.setSalesDealCode(orderCode); salesOrder.setSalesOrderId(orderCode); salesOrder.setSalesBatchId(generateKeyUtil.getSalesBatchIdKS()); //salesOrder = salesOrderService.addOrderAndIteminfo(salesOrder,list); salesOrder.setSalesOrderItemList(list); try { Integer flag = customerService.addOrder(salesOrder); } catch (RuntimeException e) { return new ResponseJson(500, "添加订单失败--" + e.getMessage(), 500); } Integer orderId = salesOrder.getSalesId(); ResponseJson rj = new ResponseJson(200, "添加订单成功", 200); rj.addResponseKeyValue("orderId", orderId); return rj; } /** * 查询销售公司 * * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/select_company") public ResponseJson getCompany(HttpServletRequest request) throws Exception { //获取销售公司 List companyInfoList = companyInfoService.listCompanyInfo(new CompanyInfo()); ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("companyInfoList", companyInfoList); return rj; } /** * 获取店铺集合 * * @param request * @param storeInfo * @param isMyStore 为1则需要判断是否是自己包含的店铺, 为其他则查询所有店铺 * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/select_storeInfo") public ResponseJson listStoreInfo(HttpServletRequest request, StoreInfo storeInfo, @RequestParam(value = "isMyStore", defaultValue = "2", required = false) Integer isMyStore) { if(isMyStore == 1){ //判断用户只能查看自己所能查询的公司的订单 Integer[] storeIds = orderDepartService.getDepartStoreIds(AdminUtils.getLoginAdminId()); storeInfo.setStoreIds(storeIds); } storeInfo.setStoreStatus(1); List storeInfoList = storeInfoService.listStore(storeInfo); ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("storeInfoList", storeInfoList); return rj; } /** * 获取订单集合 * * @param request * @param salesOrder * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping(value = "/select_salesOrder") public ResponseJson listOrder(HttpServletRequest request, SalesOrder salesOrder, String ids, @RequestParam(value = "pageSize", defaultValue = "20", required = false) Integer pageSize, @RequestParam(value = "pageNO", defaultValue = "1", required = false) Integer pageNO, @RequestParam(value = "totalNum", defaultValue = "0", required = false) Integer totalNum) { if (ids != null && ids.indexOf("_") > -1) { String[] salesIds = ids.split("_"); salesOrder.setSalesIds(salesIds); } //分页获取订单信息 PagedResult pagedResult = salesOrderService.listSalesOrderPage(pageNO, pageSize, salesOrder, totalNum == 0); List salesOrderList = pagedResult.getDataList(); for (SalesOrder so:salesOrderList) { if(so.getSalesOrderStatus() != 0){ ProcMethod procMethod = procMethodService.getProcMethodById(so.getSalesOrderStatus()); so.setSalesOrderStatusProcTypeName(procMethod.getProcTypeName()); } } if (salesOrderList == null || salesOrderList.size() < 1) { return new ResponseJson(500, "查询失败", 500); } else { ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("salesOrderList", salesOrderList); return rj; } } /** * 分页查询客诉列表信息 * * @param request * @param customerInfo * @param pageSize * @param pageNO * @param totalNum * @return * @throws Exception */ @RequiresPermissions("customer:select:customer") @RequestMapping("/select_customer_list") public ModelAndView selectCustomerList(HttpServletRequest request, CustomerInfo customerInfo, @RequestParam(value = "isFirst", defaultValue = "2", required = false) Integer isFirst, @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize, @RequestParam(value = "pageNO", defaultValue = "1", required = false) Integer pageNO, @RequestParam(value = "totalNum", defaultValue = "0", required = false) Integer totalNum) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/custome_list"); /*if (customerInfo.getAdminId() == null && isFirst == 1) { //获取登录员工id Integer adminId = AdminUtils.getLoginAdminId(); customerInfo.setAdminId(adminId); }*/ //获取登录人id Integer loginAdminId = AdminUtils.getLoginAdminId(); if(customerInfo != null){ if(customerInfo.getAfterState() != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar date = Calendar.getInstance(); date.setTime(new Date()); switch (customerInfo.getAfterState()) { case 1: //今日签收 customerInfo.setAfterTime(sdf.format(date.getTime())); break; case 2: //昨日签收 date.set(Calendar.DATE, date.get(Calendar.DATE) - 1); customerInfo.setAfterTime(sdf.format(date.getTime())); break; case 3: //前日签收 date.set(Calendar.DATE, date.get(Calendar.DATE) - 2); customerInfo.setAfterTime(sdf.format(date.getTime())); break; } String isOneself = request.getParameter("isOneself"); if(isOneself != null){ if(isOneself.equals("2")){ customerInfo.setAdminId(loginAdminId); } } } } PagedResult pagedResult = customerService.listCustomer(pageNO, pageSize, customerInfo, totalNum == 0); if (totalNum != 0) { pagedResult.setTotal(totalNum); } //查询寄出状态 if(pagedResult.getDataList().size() > 0){ for(CustomerInfo info : pagedResult.getDataList()){ if(info.getSalesOrderList().size() > 0){ info.setSendStatus(info.getSalesOrderList().get(0).getSalesStatus()); } } } ProductType productType = new ProductType(); //查询产品类型集合 List typeList = productService.listProductType(productType); //查询客诉类型集合 List complaintTypeList = complaintTypeInfoService.listComplaintTypeInfo(new ComplaintTypeInfo()); //查询客诉类型集合 List complaintSmallClassInfoList = complaintSmallClassInfoService.listComplaintSmallClassInfo(new ComplaintSmallClassInfo()); //查询处理类型 List procTypeList = customerService.listProcType(); //店铺(销售渠道) List listStoreInfo = storeInfoService.listStore(new StoreInfo()); //客诉问题 ComplaintQuestionInfo complaintQuestionInfo = new ComplaintQuestionInfo(); List listComplaintQuestionInfo = complaintQuestionInfoService.listQuestionAll(complaintQuestionInfo); //查询问题集合 第 30 条bug // List questionDescribeList = questionDescribeService.listQuestionDescribe(new QuestionDescribe()); //查询跟进客服集合 Admin admin = new Admin(); admin.setAdminDept(3); admin.setAdminStatus(1); List adminList = sysService.listSelectAdmin(admin); mv.addObject("listComplaintQuestionInfo",listComplaintQuestionInfo); mv.addObject("complaintSmallClassInfoList", complaintSmallClassInfoList); mv.addObject("loginAdminId", loginAdminId); mv.addObject("typeList", typeList); mv.addObject("complaintTypeList", complaintTypeList); mv.addObject("adminList", adminList); mv.addObject("procTypeList", procTypeList); mv.addObject("listStoreInfo", listStoreInfo); customerInfo.setVisit(null); customerInfo.setCustomerCommon(null); customerInfo.setComplaintDetectList(null); StitchAttrUtil sa = StitchAttrUtil.getSa(); sa.addDatePro("yyyy-MM-dd", "startTime", "endTime"); sa.setModelAndView(customerInfo, mv, "/admin/customer/select_customer_list", pagedResult); return mv; } /** * 进入客诉基本信息页面 * * @param request * @return * @throws Exception */ @RequiresPermissions("customer:select:customer") @RequestMapping("/_customer_info") public ModelAndView toCustomerInfo(HttpServletRequest request) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/custome_detail"); String customerId = request.getParameter("customerId"); CmRelation cmRelation = new CmRelation(); cmRelation.setCustomerId(Integer.valueOf(customerId)); cmRelation = customerService.getCmRelationInfo(cmRelation); ProcMethod procMethod = customerService.getProcMethod(cmRelation.getProcMethodId()); ListlogisticsInfoList = logisticsInfoService.getLogisticsInfoList(new LogisticsInfo()); List listPostageInfo = customerService.listPostageInfo(cmRelation.getRelationId()); List listSendbackInfo = customerService.listSendbackInfo(cmRelation.getRelationId()); //查询寄回产品 ClosedProdcue record = new ClosedProdcue(); record.setRelationId(cmRelation.getRelationId()); List listClosedProdcue = customerService.listclosedProdcue(record); SalesOrder salesOrder = new SalesOrder(); salesOrder.setSalesCustomerId(cmRelation.getCustomerId()); List salesOrderList = salesOrderService.salesOrderListAndItem(salesOrder); mv.addObject("listClosedProdcue",listClosedProdcue); mv.addObject("listSendbackInfo",listSendbackInfo); mv.addObject("logisticsInfoList",logisticsInfoList); mv.addObject("listPostageInfo", listPostageInfo); mv.addObject("procMethod", procMethod); mv.addObject("customerId", customerId); mv.addObject("salesOrderList", salesOrderList); return mv; } /** * 查询客诉基本信息 * * @param request * @return * @throws Exception */ @ResponseBody @RequiresPermissions("customer:select:customer") @RequestMapping("/get_customer_info") public ResponseJson getCustomerInfo(HttpServletRequest request) throws Exception { String customerId = request.getParameter("customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "该客诉信息不存在!", 500); } CustomerInfo customerInfo = new CustomerInfo(); customerInfo.setCustomerId(Integer.parseInt(customerId)); Map map = customerService.getCustomerInfo(customerInfo); ResponseJson rj = new ResponseJson(200, "修改成功!", 200); //查询处理方式信息 CmRelation cmRelation = new CmRelation(); cmRelation.setCustomerId(customerInfo.getCustomerId()); cmRelation = customerService.getCmRelationInfo(cmRelation); ProcMethod procMethod = customerService.getProcMethod(cmRelation.getProcMethodId()); CustomerInfo ci = (CustomerInfo) map.get("customer"); if(ci != null){ if(ci.getCustomerProvinceId() != null && !"".equals(ci.getCustomerProvinceId())){ Province province = new Province(); province.setProvinceId(Integer.valueOf(ci.getCustomerProvinceId())); List provinceList = addressService.listProvince(province); ci.setCustomerProvinceName(provinceList.get(0).getProvince()); }else{ ci.setCustomerProvinceName(""); } if(ci.getCustomerCityId() != null && !"".equals(ci.getCustomerCityId())){ City city = new City(); city.setCityId(Integer.valueOf(ci.getCustomerCityId())); List cityList = addressService.listCity(city); ci.setCustomerCityName(cityList.get(0).getCity()); }else{ ci.setCustomerCityName(""); } if(ci.getCustomerDistrictId() != null && !"".equals(ci.getCustomerDistrictId())){ District district = new District(); district.setDistrictId(Integer.valueOf(ci.getCustomerDistrictId())); List districtList = addressService.listDistrict(district); ci.setCustomerDistrictName(districtList.get(0).getDistrict()); }else{ ci.setCustomerDistrictName(""); } } //已完成维修、原机退货,并且发货状态为待下单的维修记录,则需要查询当前客诉对应的维修机器 List listDetet = complaintDetectInfoService.listDetectByCustomerId(Integer.valueOf(customerId)); rj.addResponseKeyValue("listDetet", listDetet); rj.addResponseKeyValue("cmRelation", cmRelation); rj.addResponseKeyValue("procMethod", procMethod); rj.addResponseKeyValue("customerCommon", map.get("customerCommon")); rj.addResponseKeyValue("customer", map.get("customer")); rj.addResponseKeyValue("orderList", map.get("orderList")); rj.addResponseKeyValue("colorIds", map.get("colorIds")); return rj; } /** * 查询客诉基本信息 * * @param request * @return * @throws Exception */ @ResponseBody @RequiresPermissions("customer:select:customer") @RequestMapping("/get_customer") public ResponseJson getCustomer(HttpServletRequest request) throws Exception { String customerId = request.getParameter("customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "该客诉信息不存在!", 500); } SalesOrder salesOrder = new SalesOrder(); salesOrder.setSalesCustomerId(Integer.valueOf(customerId)); List salesOrderList = salesOrderService.salesOrderListAndItem(salesOrder); ResponseJson rj = ResponseJson.getSUCCESS(); rj.addResponseKeyValue("salesOrderList", salesOrderList); return rj; } /** * 进入添加回访页面 * * @param request * @return * @throws Exception */ @RequiresPermissions("customer:select:customer") @RequestMapping("/_add_visit") public ModelAndView toAddVisit(HttpServletRequest request) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/add_visit"); String customerId = request.getParameter("customerId"); //查询跟进客服集合 Admin admin = new Admin(); admin.setAdminDept(3); admin.setAdminStatus(1); List adminList = sysService.listSelectAdmin(admin); //获取登录人id Integer loginAdminId = AdminUtils.getLoginAdminId(); mv.addObject("loginAdminId", loginAdminId); mv.addObject("customerId", customerId); mv.addObject("adminList", adminList); return mv; } /** * 添加回访信息 * * @param request * @param visit * @return */ @ResponseBody @RequiresPermissions("customer:add:visit") @RequestMapping("/add_visit_info") public ResponseJson addVisitInfo(HttpServletRequest request, Visit visit) throws Exception { String visitAdminId = request.getParameter("visitAdminId"); if (!StringUtils.isNotEmpty(visitAdminId)) { return new ResponseJson(500, "请选择回访人!", 500); } Integer loginAdminId = AdminUtils.getLoginAdminId(); visit.setAdminId(loginAdminId); visit.setDesignatedAdminId(Integer.parseInt(visitAdminId)); visit.setVisitStatus(1); visit.setVisitCreateTime(new Date()); int num = visitService.addVisitInfo(visit, visit.getCustomerId()); if (num > 0) { return new ResponseJson(200, "修改成功!", 200); } else { return new ResponseJson(500, "修改失败!", 500); } } /** * 修改客诉状态为已解决 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:update:customerIsSolve") @RequestMapping("/update_customerIsSolve") public ResponseJson updateCustomerIsSolve(HttpServletRequest request) throws Exception { String customerId = request.getParameter("customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "该客诉信息不存在!", 500); } //根据id获取客诉信息 CustomerInfo customer = customerService.getCustomerInfo(Integer.parseInt(customerId)); if (customer == null) { return new ResponseJson(500, "该客诉信息不存在!", 500); } if (customer.getCustomerIsSolve().intValue() != 2) { return new ResponseJson(500, "该客诉信息不能修改为已解决状态!", 500); } CustomerInfo customerInfo = new CustomerInfo(); customerInfo.setCustomerId(Integer.parseInt(customerId)); customerInfo.setCustomerIsSolve(1); //修改客诉信息 int num = customerService.updateCustomerInfo(customerInfo); if (num > 0) { return new ResponseJson(200, "修改成功!", 200); } else { return new ResponseJson(500, "修改失败!", 500); } } /** * 查询客服 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping("/select_sys_admin") public ResponseJson selectSysAdmin(HttpServletRequest request) throws Exception { ResponseJson rj = new ResponseJson(200, "修改成功!", 200); Integer adminId = AdminUtils.getLoginAdminId(); Admin admin = new Admin(); admin.setAdminDept(3); admin.setAdminStatus(1); List adminList = sysService.listSelectAdmin(admin); if (adminList.size() > 0) { rj.addResponseKeyValue("adminList", adminList); rj.addResponseKeyValue("adminId", adminId); return rj; } else { return new ResponseJson(500, "查询失败!", 500); } } /** * 查询产品类型 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping("/select_produce_type") public ResponseJson selectProduceType(HttpServletRequest request) throws Exception { ResponseJson rj = new ResponseJson(200, "修改成功!", 200); ProductType productType = new ProductType(); productType.setTypeStatus(1); List productTypeList = productService.listProductType(productType); if (productTypeList != null && productTypeList.size() > 0) { rj.addResponseKeyValue("productTypeList", productTypeList); return rj; } else { return new ResponseJson(500, "查询失败!", 500); } } /** * 查询产品 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping("/select_produce") public ResponseJson selectProduce(HttpServletRequest request) { ResponseJson rj = new ResponseJson(200, "查询成功!", 200); Product product = new Product(); List productList = productService.listProduce(product); for (Product pro : productList) { ProductColor productColor = new ProductColor(); productColor.setColorProductId(pro.getProductId()); List productColorList = productService.listProduceColor(productColor); pro.setColorList(productColorList); } if (productList != null && productList.size() > 0) { rj.addResponseKeyValue("productList", productList); return rj; } else { return new ResponseJson(500, "查询失败!", 500); } } /** * 添加客诉 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping("/save_customer") public ResponseJson addCustomer(HttpServletRequest request, CustomerInfo customerInfo, SalesOrder salesOrder, CmRelation cmRelation, String sendProdcuesJson,String closedProdcuesJson) throws Exception { ResponseJson rjx = this.isValiData(customerInfo); if (rjx.getResultCode() == 500) { return rjx; } if(customerInfo.getCustomerTel() != null && !"".equals(customerInfo.getCustomerTel())){ customerInfo.setCustomerTel(customerInfo.getCustomerTel().trim()); } if(cmRelation.getRelationBackTel() != null && !"".equals(cmRelation.getRelationBackTel())){ cmRelation.setRelationBackTel(cmRelation.getRelationBackTel().trim()); } if(cmRelation.getRelationSendTel() != null && !"".equals(cmRelation.getRelationSendTel())){ cmRelation.setRelationSendTel(cmRelation.getRelationSendTel().trim()); } Integer customerIsSolve = customerInfo.getCustomerIsSolve(); //处理类型 String phone = customerInfo.getCustomerTel(); //手机号码 Integer typeCompany = customerInfo.getTypeCompany(); // 所属商城 1:美国watero; 2:上朵电动牙刷 3:优尼雅净水机 Integer flag = 0; if (customerInfo.getIsNeedSelectOrder() == 1) { ////1:需要有订单 2:不需要有订单 JSONArray jsonArray; List sendProdcueList; List closedProdcueList; jsonArray = JSONArray.fromObject(sendProdcuesJson); sendProdcueList = (List) JSONArray.toCollection(jsonArray, SendProdcue.class); jsonArray = JSONArray.fromObject(closedProdcuesJson); closedProdcueList = (List) JSONArray.toCollection(jsonArray, ClosedProdcue.class); cmRelation.setSendProdcues(sendProdcueList); cmRelation.setClosedProdcues(closedProdcueList); } customerInfo.setCmRelation(cmRelation); String orderId = ""; if (customerInfo.getCustomerIsSolve() == 3 || customerInfo.getCustomerIsSolve() == 4 || customerInfo.getCustomerIsSolve() == 5) { Integer adminId = AdminUtils.getLoginAdminId(); orderId = OrderNoUtil.createOrderCode(adminId); } customerInfo.setTransactionNumber(orderId); Integer customerId = customerInfo.getCustomerId(); logger.info("-----------------添加客诉开始----------------------"); try { flag = customerService.saveCustomerInfo(customerInfo, salesOrder); } catch (RuntimeException e) { e.printStackTrace(); return new ResponseJson(500, e.getMessage(), 500); } catch (Exception e) { e.printStackTrace(); return new ResponseJson(500, "添加失败", 500); } customerId = customerInfo.getCustomerId(); logger.info("-----------------添加客诉结束----------------------"); if (flag < 1) { return new ResponseJson(500, "添加客诉失败!", 500); } String msg = ""; //处理结果: 1:已解决 2:未解决 3:换新 4:维修 5:补发 6:退货 7:无理由退货 if (customerIsSolve == 3 || customerIsSolve == 4 || customerIsSolve == 5 || customerIsSolve == 6 || customerIsSolve == 7) { String solveMsg = ""; switch (customerIsSolve) { case 3: solveMsg = "为您更换新机"; break; case 4: solveMsg = "为您维修机器"; break; case 5: solveMsg = "为您补发产品"; break; case 6: solveMsg = "为您办理退货"; break; case 7: solveMsg = "为您办理退货"; break; } String addCustomerSuccessMsg = ""; String typeMsg = ""; switch (typeCompany) { case 1: addCustomerSuccessMsg = SmsConfig.ADD_CUSTOMER_SUCCESS_WATERO; typeMsg = "美国WaterO售后"; break; case 2: addCustomerSuccessMsg = SmsConfig.ADD_CUSTOMER_SUCCESS_SHANGDUO; typeMsg = "上朵售后"; break; case 3: addCustomerSuccessMsg = SmsConfig.ADD_CUSTOMER_SUCCESS_YULIA; typeMsg = "YULIA售后"; break; case 4: addCustomerSuccessMsg = SmsConfig.ADD_CUSTOMER_SUCCESS_AIBERLE; typeMsg = "爱贝源售后"; break; } // Object [] msg = new Object[]{solveMsg,typeMsg}; // String text = MessageFormat.format(addCustomerSuccessMsg, msg); // logger.info("添加客诉成功后,给 "+ phone +" 手机用户发送短信:" + text ); // String result = smsService.sendOtherCMS(phone, text); // // if (!"SUCCESS".equals(result)) { // return new ResponseJson(505, "添加客诉发送短信失败,失败原因:" + result + "
客诉信息发送失败并不影响客诉添加。客诉编号为:"+ customerId, 505); // } msg = ",请前往Efast进行换货/退货操作。"; } return new ResponseJson(200, "录入客诉成功!客诉编号:" + customerId + msg, 200); } /** * 修改客诉 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:update:customer") @RequestMapping("/update_customer") public ResponseJson updateCustomer(HttpServletRequest request, CustomerInfo customerInfo, SalesOrder salesOrder, CmRelation cmRelation, String sendProdcuesJson, String closedProdcuesJson) throws Exception { ResponseJson rjx = this.isValiData(customerInfo); if (rjx.getResultCode() == 500) { return rjx; } Integer flag = 0; if(customerInfo.getCustomerTel() != null && !"".equals(customerInfo.getCustomerTel())){ customerInfo.setCustomerTel(customerInfo.getCustomerTel().trim()); } if(cmRelation.getRelationBackTel() != null && !"".equals(cmRelation.getRelationBackTel())){ cmRelation.setRelationBackTel(cmRelation.getRelationBackTel().trim()); } if(cmRelation.getRelationSendTel() != null && !"".equals(cmRelation.getRelationSendTel())){ cmRelation.setRelationSendTel(cmRelation.getRelationSendTel().trim()); } Integer customerIsSolve = customerInfo.getCustomerIsSolve(); //处理类型 String phone = customerInfo.getCustomerTel(); //手机号码 Integer typeCompany = customerInfo.getTypeCompany(); // 所属商城 1:美国watero; 2:上朵电动牙刷 3:优尼雅净水机 if (customerInfo.getIsNeedSelectOrder() == 1) { JSONArray jsonArray; List sendProdcueList; List closedProdcueList; jsonArray = JSONArray.fromObject(sendProdcuesJson); sendProdcueList = (List) JSONArray.toCollection(jsonArray, SendProdcue.class); jsonArray = JSONArray.fromObject(closedProdcuesJson); closedProdcueList = (List) JSONArray.toCollection(jsonArray, ClosedProdcue.class); cmRelation.setSendProdcues(sendProdcueList); cmRelation.setClosedProdcues(closedProdcueList); } String orderId = ""; if (customerInfo.getCustomerIsSolve() == 3 || customerInfo.getCustomerIsSolve() == 4 || customerInfo.getCustomerIsSolve() == 5) { Integer adminId = AdminUtils.getLoginAdminId(); orderId = OrderNoUtil.createOrderCode(adminId); } customerInfo.setTransactionNumber(orderId); customerInfo.setCmRelation(cmRelation); Integer customerId = customerInfo.getCustomerId(); logger.info("-----------------修改客诉开始----------------------"); try { flag = customerService.updateCustomerInfo(customerInfo, salesOrder); } catch (RuntimeException e) { e.printStackTrace(); return new ResponseJson(500, e.getMessage(), 500); } catch (Exception e) { e.printStackTrace(); return new ResponseJson(500, "修改失败", 500); } customerId = customerInfo.getCustomerId(); logger.info("-----------------修改客诉结束----------------------"); if (flag < 1) { return new ResponseJson(500, "修改客诉失败!", 500); } return new ResponseJson(200, "修改客诉成功!客诉编号为:" + customerId, 200); } /** * 验证方法 * * @param customerInfo * @return */ public ResponseJson isValiData(CustomerInfo customerInfo) { ResponseJson rj = new ResponseJson(); if (customerInfo.getAdminId() == null) { return new ResponseJson(500, "未填写客诉id", 500); } return rj; } /** * 发送短信 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:add:customer") @RequestMapping("/send_phone_sms") public ResponseJson sendPhoneSms(HttpServletRequest request, String type, String phone, Integer typeCompany, ComplaintQuestionInfo complaintQuestionInfo) throws Exception { String url = NameUtils.getConfig("website"); Integer flag = 1; if (typeCompany == null || typeCompany == 0) { return new ResponseJson(500, "未获取到产品类型!", 500); } String con = ""; if (type != null && !"".equals(type)) { if ("p".equals(type)) { //problem" 问题处理; mailAddress:邮寄地址; if (complaintQuestionInfo.getQuestionId() == null || "".equals(complaintQuestionInfo.getQuestionId())) { complaintQuestionInfo.setQuestionState(1); complaintQuestionInfo.setQuestionIsQcDetect(0); complaintQuestionInfo = complaintQuestionInfoService.insertBackInfo(complaintQuestionInfo); } else { complaintQuestionInfo.setSmallClassId(null); //不能修改小类类型 flag = complaintQuestionInfoService.updateQuestionById(complaintQuestionInfo); if (flag < 1) { return new ResponseJson(500, "问题修改失败!", 500); } } url += "/" + complaintQuestionInfo.getQuestionId() + "/" + typeCompany; switch (typeCompany) { case 1: con = SmsConfig.SEND_PRODUCT_SEND_WATERO; break; case 2: con = SmsConfig.SEND_PRODUCT_SEND_SHANGDUO; break; case 3: con = SmsConfig.SEND_PRODUCT_SEND_YULIA; break; case 4: con = SmsConfig.SEND_PRODUCT_SEND_AIBERLE; break; } } else if ("m".equals(type)) { if (complaintQuestionInfo.getQuestionId() == null) { return new ResponseJson(500, "未获取到邮寄信息!", 500); } complaintQuestionInfo.setQuestionName(null); complaintQuestionInfo.setSmallClassId(null); url += "/5/0"; switch (typeCompany) { case 1: con = SmsConfig.SEND_PRODUCT_SMS_WATERO; break; case 2: con = SmsConfig.SEND_PRODUCT_SMS_SHANGDUO; break; case 3: con = SmsConfig.SEND_PRODUCT_SMS_YULIA; break; case 4: con = SmsConfig.SEND_PRODUCT_SMS_AIBERLE; break; } } } String userPhone = encodePhoneNumber(phone); String text = MessageFormat.format(con, url); logger.info("给 " + phone + " 手机用户发送短信:" + text); String result = smsService.sendOtherCMS(phone, text); if ("SUCCESS".equals(result)) { return new ResponseJson(200, "发送短信成功!", 200); } else { return new ResponseJson(500, "发送短信失败,失败原因:" + result, 500); } } String encodePhoneNumber(String number) { int encnum = Integer.parseInt(number.substring(2)); int prefix = (number.charAt(1) - '2') / 2; // '3'=>0, '5'=>1, '[67]'=>2, '8'=>3 encnum |= (prefix <<= 30); final byte[] raw = new byte[4]; raw[0] = (byte) (encnum >>> 24); raw[1] = (byte) (encnum >>> 16); raw[2] = (byte) (encnum >>> 8); raw[3] = (byte) encnum; return Base64.encodeBase64URLSafeString(raw); } /** * 进入回访完成页面 * * @param request * @return * @throws Exception */ @RequiresPermissions("customer:update:visit") @RequestMapping("/_update_visit_info") public ModelAndView toUpdateVisitFinish(HttpServletRequest request) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/visit_finish"); String customerId = request.getParameter("customerId"); mv.addObject("customerId", customerId); return mv; } /** * 添加回访完成内容 * * @param request * @param visit * @return */ @ResponseBody @RequiresPermissions("customer:update:visit") @RequestMapping("/update_visit_finish") public ResponseJson updateVisitFinish(HttpServletRequest request, Visit visit) throws Exception { String customerId = request.getParameter("finish_customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "该客诉信息不存在!", 500); } visit.setCustomerId(Integer.parseInt(customerId)); visit.setVisitStatus(2); //修改回访信息内容 int num = visitService.updateVisit(visit); if (num > 0) { return new ResponseJson(200, "添加成功!", 200); } else { return new ResponseJson(500, "添加失败!", 500); } } /** * 进入回访信息详情 * * @param request * @return * @throws Exception */ @RequiresPermissions("customer:get:visit") @RequestMapping("/_visit_info") public ModelAndView toVisitInfo(HttpServletRequest request) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/visit_detail"); String customerId = request.getParameter("customerId"); // 1:未回访,2:已回访 String num = request.getParameter("num"); if (!StringUtils.isNotEmpty(num)) { num = "2"; } mv.addObject("customerId", customerId); mv.addObject("num", num); return mv; } /** * 获取回访信息详情 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:get:visit") @RequestMapping("/get_visit_info") public ResponseJson getVisitInfo(HttpServletRequest request) throws Exception { String customerId = request.getParameter("customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "该客诉信息不存在!", 500); } Visit visit = new Visit(); visit.setCustomerId(Integer.parseInt(customerId)); //查询回访信息集合 List visitList = visitService.listVisit(visit); if (visitList == null || visitList.size() == 0) { return new ResponseJson(500, "该客诉没有回访信息!", 500); } visit = visitList.get(0); ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("visit", visit); return rj; } /** * 进入问题描述页面 * * @param request * @return * @throws Exception */ @RequiresPermissions("customer:get:describe") @RequestMapping("/_question_describe") public ModelAndView toQuestionDescribe(HttpServletRequest request) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/describe_detail"); String customerId = request.getParameter("customerId"); mv.addObject("customerId", customerId); return mv; } /** * 获取问题描述信息 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:get:describe") @RequestMapping("/get_describe_info") public ResponseJson getDescribeInfo(HttpServletRequest request) throws Exception { String customerId = request.getParameter("customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "该客诉信息不存在!", 500); } QuestionDescribe describe = new QuestionDescribe(); describe.setCustomerId(Integer.parseInt(customerId)); //查询问题集合 List questionList = questionDescribeService.listQuestionDescribe(describe); if (questionList == null || questionList.size() == 0) { return new ResponseJson(500, "该客诉信息没有问题描述!", 500); } describe = questionList.get(0); CustomerInfo customerInfo = customerService.getCustomerInfo(Integer.parseInt(customerId)); ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("describe", describe); rj.addResponseKeyValue("customerInfo", customerInfo); return rj; } /** * 进入修改售后处理信息页面 * * @param request * @return * @throws Exception */ @RequiresPermissions("customer:update:renewed") @RequestMapping("/_update_relation") public ModelAndView toUpdateRenewed(HttpServletRequest request) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/update_relation"); String customerId = request.getParameter("customerId"); String type = request.getParameter("type"); if(type != null && !type.equals("")){ mv.addObject("type",type); }else{ mv.addObject("type",0); } CmRelation cmRelation = new CmRelation(); cmRelation.setCustomerId(Integer.valueOf(customerId)); cmRelation = customerService.getCmRelationInfo(cmRelation); ProcMethod procMethod = customerService.getProcMethod(cmRelation.getProcMethodId()); ListlogisticsInfoList = logisticsInfoService.getLogisticsInfoList(new LogisticsInfo()); List listPostageInfo = customerService.listPostageInfo(cmRelation.getRelationId()); List listSendbackInfo = customerService.listSendbackInfo(cmRelation.getRelationId()); List listInformationInfo = customerService.listInformationInfo(cmRelation.getRelationId()); ComplaintDetectInfo detectInfo = new ComplaintDetectInfo(); detectInfo.setCustomerId(Integer.valueOf(customerId)); List detectList = complaintDetectInfoService.listComplaintDetect(detectInfo); ComplaintSignclosedInfo complaintSignclosedInfo = new ComplaintSignclosedInfo(); complaintSignclosedInfo.setSignclosedCustomerId(Integer.valueOf(customerId)); List signclosedList = complaintSignclosedInfoService.listSignclosed(complaintSignclosedInfo); //查询寄回产品 ClosedProdcue record = new ClosedProdcue(); record.setRelationId(cmRelation.getRelationId()); List listClosedProdcue = customerService.listclosedProdcue(record); //查询售前客服 Admin admin = new Admin(); admin.setAdminDept(22);//售前部id List adminlist = sysService.listSelectAdmin(admin); mv.addObject("listInformationInfo",listInformationInfo); mv.addObject("listClosedProdcue",listClosedProdcue); mv.addObject("listSendbackInfo",listSendbackInfo); mv.addObject("logisticsInfoList",logisticsInfoList); mv.addObject("listPostageInfo", listPostageInfo); mv.addObject("procMethod", procMethod); mv.addObject("customerId", customerId); mv.addObject("detectList", detectList); mv.addObject("signclosedList", signclosedList); mv.addObject("adminlist", adminlist); return mv; } /** * 获取售后详情 * * @param request * @return */ @ResponseBody @RequiresPermissions("customer:get:renewed") @RequestMapping("/get_cmRelation_info") public ResponseJson getRenewedInfo(HttpServletRequest request) throws Exception { String customerId = request.getParameter("customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "该客诉信息不存在!", 500); } CmRelation cmRelation = new CmRelation(); cmRelation.setCustomerId(Integer.parseInt(customerId)); //获取换新详情和检测信息 cmRelation = customerService.getCmRelationInfo(cmRelation); if (cmRelation == null) { return new ResponseJson(500, "该客诉没有售后信息!", 500); } else { //查询寄出状态 SalesOrder salesOrder = new SalesOrder(); salesOrder.setSalesCustomerId(Integer.valueOf(customerId)); List salesOrderList = salesOrderService.salesOrderListAndItem(salesOrder); if(salesOrderList.size() > 0){ cmRelation.setRelationSendStatus(salesOrderList.get(0).getSalesStatus()); }else{ cmRelation.setRelationSendStatus(0); } ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("cmRelation", cmRelation); return rj; } } /** * 修改处理信息 * * @param request * @param cmRelation * @return * @throws Exception */ @ResponseBody @RequiresPermissions("customer:update:renewed") @RequestMapping("/update_cmRelation_info") public ResponseJson updateRenewedInfo(HttpServletRequest request, CmRelation cmRelation) throws Exception { String mergeAddress = request.getParameter("merge_address"); if (!StringUtils.isNotEmpty(cmRelation.getRelationId().toString())) { return new ResponseJson(500, "该售后信息不能修改!", 500); } if (StringUtils.isNotEmpty(mergeAddress)) { cmRelation.setRelationSendMergeAddress(mergeAddress); } if (cmRelation.getRelationBackStatus() != null) { if (cmRelation.getRelationBackStatus() != 1) { ComplaintSignclosedInfo cs = new ComplaintSignclosedInfo(); cs.setSignclosedCustomerId(cmRelation.getCustomerId()); cs.setSignclosedLogistics(cmRelation.getRelationBackLogisticsCompany()); cs.setSignclosedLogisticsNumber(cmRelation.getRelationBackLogisticsNo()); complaintSignclosedInfoService.updateSignclosedByCustomerId(cs); } } //修改售后信息 int num = customerService.updateCmRelation(cmRelation); if (num > 0) { return new ResponseJson(200, "修改成功!", 200); } else { return new ResponseJson(500, "修改失败!", 500); } } /** * 查询未解决客诉数量 */ @ResponseBody @RequestMapping(value = "/selectNumberBacklog") public ResultMsg selectTodo(HttpServletRequest request) { ResultMsg msg = new ResultMsg(); CustomerInfo customerInfo = new CustomerInfo(); //获取登录员工id Admin admin = AdminUtils.getLoginAdmin(); // customerInfo.setAdminId(admin.getAdminId()); // customerInfo.setCustomerIsSolve(2); //未解决客诉数量 // Integer notSolvedCustomer = customerService.selectNotSolvedCustomer(customerInfo); //需要向工厂确认所有已签收的产品数量 // CustomerCommon customerCommon = new CustomerCommon(); // customerCommon.setAdminId(admin.getAdminId()); // customerCommon.setRelationBackStatus(4); // Integer amountReceivedCustomer = customerCommonService.listCustomerCommonByStatus(customerCommon); //需要填写Efast订单号的客诉数量 // customerCommon.setRelationBackStatus(3); // Integer noEntryCustomer = customerCommonService.listCustomerCommonByStatus(customerCommon); //客诉录入后,三天后未寄回的客诉数量 // customerCommon.setRelationBackStatus(1); // customerCommon.setRelationCreateTime(new Date()); // Integer notSendCustomer = customerCommonService.listCustomerCommonByStatus(customerCommon); SalesOrder salesOrder = new SalesOrder(); salesOrder.setSalesStatus(0); //未确认 Integer toBeConfirmedOrder = salesOrderService.listSalesOrderNum(salesOrder); salesOrder = new SalesOrder(); salesOrder.setSalesShippingStatus(0); //未发货 Integer toBeAnnounced = salesOrderService.listSalesOrderNum(salesOrder); salesOrder.setSalesShippingStatus(11); //已通知配货 Integer toBeDelivered = salesOrderService.listSalesOrderNum(salesOrder); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY,00); calendar.set(Calendar.MINUTE,00); calendar.set(Calendar.SECOND,01); salesOrder = new SalesOrder(); salesOrder.setStartDate(calendar.getTime()); //startDate Calendar ca = Calendar.getInstance(); ca.set(Calendar.HOUR_OF_DAY,23); ca.set(Calendar.MINUTE,59); ca.set(Calendar.SECOND,59); salesOrder.setEndDate(ca.getTime()); Integer allToDayOrder = salesOrderService.listSalesOrderNum(salesOrder); Map numberMap = new HashMap<>(); numberMap.put("toBeConfirmedOrder", toBeConfirmedOrder); numberMap.put("toBeAnnounced", toBeAnnounced); numberMap.put("toBeDelivered", toBeDelivered); numberMap.put("allToDayOrder", allToDayOrder); // numberMap.put("notSolvedCustomer", notSolvedCustomer); // numberMap.put("amountReceivedCustomer", amountReceivedCustomer); // numberMap.put("noEntryCustomer", noEntryCustomer); // numberMap.put("notSendCustomer", notSendCustomer); numberMap.put("adminDept", admin.getAdminDept()); SalesOrder salesOrderNum = salesOrderService.getStatusNum(); numberMap.put("salesOrderNum", salesOrderNum); msg.setResultCode(ResultInfo.SUCCESSCODE); msg.setStatus(true); msg.setData(numberMap); return msg; } // /** // * 根据微信昵称/姓名/电话查询客诉 // * // * @param request // * @return // */ // @ResponseBody // @RequiresPermissions("customer:list:customer") // @RequestMapping("/get_custoner_info") // public ResponseJson getCustonerInfo(HttpServletRequest request, CustomerCommon customerCommon) throws Exception { // if (customerCommon == null) { // return new ResponseJson(500, "参数错误!", 500); // } // List customerCommonList = customerCommonService.listCustomerCommon(customerCommon); // if (customerCommonList.size() < 1) { // return new ResponseJson(500, "不存在相关客诉信息!", 500); // } else { // ResponseJson rj = new ResponseJson(200, "查询成功", 200); // rj.addResponseKeyValue("customer", customerCommonList.get(0)); // return rj; // } // } /** * 申请邮费 * * @return */ @ResponseBody @RequiresPermissions("customer:applyPostage:customer") @RequestMapping(value = "/apply_postage") public ResponseJson applyPostage(HttpServletRequest request, Integer customerId) throws Exception { CustomerInfo customerInfo = customerService.getCustomerInfo(customerId); if (customerInfo == null) { return new ResponseJson(500, "未获取到客诉", 500); } CmRelation cmRelation = cmRelationService.getCmRelationByCustomerId(customerId); if (cmRelation.getRelationBackStatus() == 1) { //1:未寄回 2:已寄回 3:已收货 4:已签收待确认 return new ResponseJson(500, "请修改寄回状态,并填写寄回信息", 500); } if (cmRelation.getRelationBackStatus() == 2) { //1:未寄回 2:已寄回 3:已收货 4:已签收待确认 return new ResponseJson(500, "产品正在寄回中!", 500); } if (cmRelation.getRelationIsTransfer() == 0) { //relationIsTransfer 是否需要转账邮费 0:不需要 10:需要转账 return new ResponseJson(500, "请修改邮费转账状态,并填写邮费信息", 500); } if (cmRelation.getRelationBackPostage() == null || cmRelation.getRelationBackPostage() == 0 //relationBackPostage || cmRelation.getRelationAlipay() == null || cmRelation.getRelationAlipayName() == null) { return new ResponseJson(500, "请填写邮费信息", 500); } if (customerInfo.getCompanyId() == null || customerInfo.getCompanyId() == 0) { return new ResponseJson(500, "未正确选择销售公司", 500); } Postage age = new Postage(); age.setCustomerId(customerInfo.getCustomerId()); //客诉id List postageList = postageService.listPostage(age); if (postageList != null && postageList.size() > 0) { return new ResponseJson(500, "该条客诉已在申请邮费中了", 500); } ResponseJson rj = new ResponseJson(200, "可以申请邮费", 200); rj.addResponseKeyValue("customerCommon", cmRelation); rj.addResponseKeyValue("customerInfo", customerInfo); return rj; } /** * 申请邮费 * * @return */ @ResponseBody @RequiresPermissions("customer:applyPostage:customer") @RequestMapping(value = "/add_postage") public ResponseJson addPostage(HttpServletRequest request, Integer customerId, String postageLogisticsImg) throws Exception { CustomerInfo customerInfo = customerService.getCustomerInfo(customerId); if (customerInfo == null) { return new ResponseJson(500, "未获取到客诉", 500); } CmRelation cmRelation = cmRelationService.getCmRelationByCustomerId(customerId); if (cmRelation.getRelationBackStatus() == 1) { //1:未寄回 2:已寄回 3:已收货 4:已签收待确认 return new ResponseJson(500, "请修改寄回状态,并填写寄回信息", 500); } if (cmRelation.getRelationBackStatus() == 2) { //1:未寄回 2:已寄回 3:已收货 4:已签收待确认 return new ResponseJson(500, "产品正在寄回中!", 500); } if (cmRelation.getRelationIsTransfer() == 0) { //relationIsTransfer 是否需要转账邮费 0:不需要 10:需要转账 return new ResponseJson(500, "请修改邮费转账状态,并填写邮费信息", 500); } if (cmRelation.getRelationBackPostage() == null || cmRelation.getRelationBackPostage() == 0 //relationBackPostage || cmRelation.getRelationAlipay() == null || cmRelation.getRelationAlipayName() == null) { return new ResponseJson(500, "请填写邮费信息", 500); } if (customerInfo.getCompanyId() == null || customerInfo.getCompanyId() == 0) { return new ResponseJson(500, "未正确选择销售公司", 500); } Postage age = new Postage(); age.setCustomerId(customerInfo.getCustomerId()); //客诉id List postageList = postageService.listPostage(age); if (postageList != null && postageList.size() > 0) { return new ResponseJson(500, "该条客诉已在申请邮费中了", 500); } /*String orderId = ""; for (SalesOrder salesOrder : cmRelation.getSalesOrderList()) { if ("".equals(orderId)) { orderId = salesOrder.getSalesOrderId(); } else { orderId += "," + salesOrder.getSalesOrderId(); } }*/ Integer flag = 0; Postage postage = new Postage(); postage.setCompanyId(customerInfo.getCompanyId()); //销售公司 postage.setAdminId(customerInfo.getAdminId()); //客服 postage.setCustomerId(customerInfo.getCustomerId()); //客诉id postage.setPostageCustomerStatus(2); //------考虑手动点, 直接变为申请中 postage.setPostageManagerStatus(1); //------考虑手动点, 直接变为申请中 postage.setPostageOrderSource(customerInfo.getStoreId()); //店铺id // postage.setPostageTreatmentMethod(cmRelation.getProcMethodId()); //处理方式 // postage.setSalesOrderId(orderId); //efast订单号 postage.setPostageClientName(cmRelation.getRelationBackName()); postage.setPostageClientTel(cmRelation.getRelationBackTel()); postage.setPostageClientAddress(cmRelation.getRelationSendAddress()); postage.setPostageLogisticsCompany(cmRelation.getRelationBackLogisticsCompany()); postage.setPostageLogisticsNo(cmRelation.getRelationBackLogisticsNo()); postage.setPostageAmount(cmRelation.getRelationBackPostage()); //寄回邮费 postage.setPostageAlipay(cmRelation.getRelationAlipay()); //支付宝账户 postage.setPostageAlipayName(cmRelation.getRelationAlipayName()); //支付宝账号名称 postage.setPostageLogisticsImg(postageLogisticsImg); flag = postageService.savePostage(postage); if (flag < 1) { return new ResponseJson(500, "申请失败", 500); } ResponseJson rj = new ResponseJson(200, "申请成功,请前往邮费转账列表查看", 200); return rj; } /** * 根据客诉id查询产品类型 * * @param request * @return * @throws Exception */ @ResponseBody @RequestMapping("/getProductType") public ResponseJson getProductType(HttpServletRequest request) throws Exception { String customerId = request.getParameter("customerId"); if (!StringUtils.isNotEmpty(customerId)) { return new ResponseJson(500, "查询产品类型失败!", 500); } //查询客诉产品类型 ProductType productType = productService.getProductType(Integer.valueOf(customerId)); if (productType == null) { return new ResponseJson(500, "未找到产品类型!", 500); } else { ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("productType", productType); return rj; } } /** * 根据客户信息查询旧的客诉信息 * * @param request * @return * @throws Exception */ @ResponseBody @RequestMapping("/selectOnCustomer") public ResponseJson listOnCustomer(HttpServletRequest request, CustomerInfo customerInfo) throws Exception { if (customerInfo == null) { return new ResponseJson(500, "查询客诉失败!", 500); } List onCustomerList = customerService.listOnCustomer(customerInfo); if (onCustomerList.size() == 0) { return new ResponseJson(500, "未找到客诉!", 500); } else { ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("onCustomerList", onCustomerList); return rj; } } /** * 根据efast订单号查询efast订单物流信息 * * @param request * @return * @throws Exception */ @ResponseBody @RequestMapping("/getefastOrder") public ResponseJson getEfastOrderInfo(HttpServletRequest request, String efastOrderId) throws Exception { if (efastOrderId == null) { return new ResponseJson(500, "查询失败!", 500); } JSONObject orderInfo = efastOrderService.getOrderFormEfastByOrderId(efastOrderId); if (orderInfo == null) { return new ResponseJson(500, "查询失败!", 500); } else if (!orderInfo.has("orders")) { return new ResponseJson(500, "查询失败!", 500); } else { ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("orderInfo", orderInfo.toString()); return rj; } } /** * 进入下载客诉页面 * * @param request * @param res * @param * @throws Exception */ @ResponseBody @RequestMapping("/to_download_customer_excel") public ModelAndView toDownloadCustomerExcel(HttpServletRequest request, HttpServletResponse res, CustomerInfo customerInfo) throws Exception { ModelAndView mv = new ModelAndView("cm/customer/download_customer"); Admin admin = AdminUtils.getLoginAdmin(); //获取销售公司 List companyInfoList = companyInfoService.listCompanyInfo(new CompanyInfo()); //查询店铺 StoreInfo storeInfo = new StoreInfo(); storeInfo.setCompanyId(companyInfoList.get(0).getCompanyId()); List storeList = storeInfoService.listStore(storeInfo); //查询处理类型 List procTypeList = customerService.listProcType(); //查询登录人下载客诉记录 DownloadProgressInfo downloadProgressInfo = new DownloadProgressInfo(); downloadProgressInfo.setDownloadAdminId(admin.getAdminId()); List listDownloadProgressInfo = customerService.listDownloadProgressInfo(downloadProgressInfo); mv.addObject("listDownloadProgressInfo",listDownloadProgressInfo); mv.addObject("companyInfoList",companyInfoList); mv.addObject("storeList",storeList); mv.addObject("procTypeList",procTypeList); return mv; } /** * 查询下载客诉信息 (2018-05-29) * * @param request * @param res * @param * @throws Exception */ @ResponseBody @RequestMapping("/list_download_customer_excel") public ResponseJson listdownloadEfastOrderExcel(HttpServletRequest request, HttpServletResponse res) throws Exception { Admin admin = AdminUtils.getLoginAdmin(); //查询登录人下载客诉记录 DownloadProgressInfo downloadProgressInfo = new DownloadProgressInfo(); /*downloadProgressInfo.setDownloadStatus(1);*/ downloadProgressInfo.setDownloadAdminId(admin.getAdminId()); List listDownloadProgressInfo = customerService.listDownloadProgressInfo(downloadProgressInfo); ResponseJson rj = new ResponseJson(200, "查询成功", 200); rj.addResponseKeyValue("listDownloadProgressInfo", listDownloadProgressInfo); return rj; } /** * 下载客诉信息 (2018-05-29) * * @param request * @param res * @param * @throws Exception */ @ResponseBody @RequestMapping("/download_customer_excel") public ResponseJson downloadEfastOrderExcel(HttpServletRequest request, HttpServletResponse res, CustomerInfo customerInfo) throws Exception { String path = request.getSession().getServletContext().getRealPath("/"); new Thread(new Mythread(path,customerInfo)).start(); return new ResponseJson(200, "查询成功", 200); } class Mythread extends Thread{ private String path; private CustomerInfo customerInfo; public Mythread(String path,CustomerInfo customerInfo) { this.path=path; this.customerInfo=customerInfo; } @Override public void run(){ Admin admin = AdminUtils.getLoginAdmin(); //添加一条下载记录 DownloadProgressInfo downloadProgressInfo = new DownloadProgressInfo(); downloadProgressInfo.setDownloadAdminId(admin.getAdminId()); downloadProgressInfo.setDownloadProgress("00.00"); downloadProgressInfo.setDownloadStatus(1); customerService.addDownloadProgressInfo(downloadProgressInfo); //循环一次的时间(毫秒) long cycleOne = 0; long cycleOnes = 0; int s = 0; List customerList = customerService.listStatisticalCustomer(customerInfo); String[] cells = { "日期", "姓名", "联系电话", "类别", "来源入口", "问题类别", "小类名称", "客诉问题", "处理过程", "购买日期", "处理方式","处理结果", "销售公司", "销售渠道", "产品型号", "产品颜色","产品类型", "产品数量", "寄回快递", "寄回单号", "签收日期", "状态", "寄出快递", "寄出单号", "开箱损", "二次客诉", "跟进客服", "工厂报价", "客户报价", "邮费信息" }; List customerStatisticalInfoList = new ArrayList<>(); SimpleDateFormat sdf4=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (CustomerStatisticalInfo customerInfo : customerList) { long startTime=System.currentTimeMillis(); //获取开始时间 s++; //新建一个容器 CustomerStatisticalInfo customer = new CustomerStatisticalInfo(); //将数据copy到新容器 BeanUtils.copyProperties(customerInfo, customer); CustomerCommon customerCommon = new CustomerCommon(); customerCommon.setCustomerId(customerInfo.getCustomerId()); customerCommon.setRelationId(customerInfo.getRelationId()); List listCustomerCommon = customerService.listCustomerCommons(customerCommon); if(listCustomerCommon.size() > 0) { for (CustomerCommon common : listCustomerCommon) { if (common.getSalesOrderList().size() > 0) { for (SalesOrder salesOrder : common.getSalesOrderList()) { if (salesOrder.getSalesOrderItemList().size() > 0) { for (SalesOrderItem salesOrderItem : salesOrder.getSalesOrderItemList()) { if(common.getSignclosedInfos().size() > 0){ for(ComplaintSignclosedInfo signclosedInfo : common.getSignclosedInfos()){ for (SignclosedProductInfo signclosedProductInfo : signclosedInfo.getSignclosedProductInfoList()) { //将数据copy到新容器 CustomerStatisticalInfo customers = new CustomerStatisticalInfo(); BeanUtils.copyProperties(customer, customers); customers.setRelationBackLogisticsCompany(signclosedInfo.getSignclosedLogistics()); customers.setRelationBackLogisticsNo(signclosedInfo.getSignclosedLogisticsNumber()); customers.setRelationBackStatus(String.valueOf(signclosedInfo.getSignclosedIsReceiving())); if(signclosedInfo.getSignclosedDate() == null){ customers.setRelationBackReceiptDate(null); }else{ customers.setRelationBackReceiptDate(sdf4.format(signclosedInfo.getSignclosedDate())); } customers.setSignclosedProductInfo(signclosedProductInfo.getProductName()+"("+signclosedProductInfo.getColorName()+")"+"*"+signclosedProductInfo.getProductNum()); customers.setItemProductColor(signclosedProductInfo.getColorName()); customers.setRelationSendLogisticsCompany(salesOrder.getSalesPostNum()); customers.setRelationSendLogisticsNo(salesOrder.getSalesPostFirm()); customers.setSalesPayTime(salesOrder.getSalesPayTime()); customers.setItemProductName(salesOrderItem.getItemProductName()); customers.setItemNum(String.valueOf(salesOrderItem.getItemNum())); if(salesOrderItem.getTypeName() != null || !salesOrderItem.getTypeName().equals("")){ customers.setTypeName(String.valueOf(salesOrderItem.getTypeName())); } customers.setRelationFactoryCosts(customerInfo.getRelationFactoryCosts()); customers.setRelationCustomerCosts(customerInfo.getRelationCustomerCosts()); customers.setSignclosedProductInfos(common.getSignclosedProductInfos()); String postageString = ""; //查询邮费信息 List listPostageInfo = customerService.listPostageInfo(customers.getRelationId()); if(listPostageInfo.size() > 0){ for(PostageInfo postageInfo : listPostageInfo){ String state = ""; if(postageInfo.getPostageStatus() == 1){ state = "未申请"; } if(postageInfo.getPostageStatus() == 2){ state = "已申请(待转账)"; } if(postageInfo.getPostageStatus() == 3){ state = "已转账"; } postageString = postageString+"状态:"+state+" ,金额:"+postageInfo.getPostageAmount()/100+" ,支付宝账号:"+postageInfo.getPostageAlipay()+";"; } } customers.setPostageString(postageString); customerStatisticalInfoList.add(customers); } } } } } else { customerStatisticalInfoList.add(customer); } } } else { customerStatisticalInfoList.add(customer); } } }else{ customerStatisticalInfoList.add(customer); } long endTime=System.currentTimeMillis(); //获取结束时间 NumberFormat numberFormat = NumberFormat.getInstance(); float percentage = (float) s / (float) customerList.size() * 100; String result = numberFormat.format(percentage); if(s == 1){ cycleOne = endTime - startTime; SimpleDateFormat sdf3=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); cycleOnes = cycleOne * customerList.size(); //修改预计下载完成时间 downloadProgressInfo.setDownloadDate(sdf3.format(new Date().getTime()+cycleOnes)); downloadProgressInfo.setDownloadProgress(result); customerService.updateDownloadProgressInfo(downloadProgressInfo); }else{ numberFormat.setMaximumFractionDigits(2); downloadProgressInfo.setDownloadProgress(result); customerService.updateDownloadProgressInfo(downloadProgressInfo); } } //导出订单Excel并下载 try { customerExcel(cells,customerStatisticalInfoList,downloadProgressInfo,path); } catch (Exception e) { e.printStackTrace(); } } } /** * 导出订单Excel并下载 * @param cells * @throws Exception */ public void customerExcel(String[] cells,List customerList, DownloadProgressInfo downloadProgressInfo,String path) throws Exception { //创建一个workbook,对应一个Excel文件 HSSFWorkbook wb = new HSSFWorkbook(); //在workbook中添加一个sheet,对应Excel中的一个sheet HSSFSheet sheet = wb.createSheet("导出订单"); //在sheet中添加表头第0行,老版本poi对excel行数列数有限制short HSSFRow row = sheet.createRow((int) 0); //创建单元格,设置值表头,设置表头居中 HSSFCellStyle style = wb.createCellStyle(); //居中格式 style.setAlignment(HSSFCellStyle.ALIGN_CENTER); //设置表头 if (cells == null || cells.length == 0) { return; } //循环设置表头 HSSFCell cell = null; for (int i = 0;i < cells.length;i++) { String name = cells[i]; cell = row.createCell(i); cell.setCellValue(name); cell.setCellStyle(style); } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); for (int i = 0; i < customerList.size(); i++) { row = sheet.createRow((int) i + 1); CustomerStatisticalInfo customerStatisticalInfo = customerList.get(i); String createTime = ""; if(customerStatisticalInfo.getCreateTime() != null){ createTime = format.format(customerStatisticalInfo.getCreateTime()); } String salesPayTime = ""; if(customerStatisticalInfo.getSalesPayTime() != null ){ salesPayTime = format.format(customerStatisticalInfo.getSalesPayTime()); } String backLogisticsCompany = ""; if(customerStatisticalInfo.getRelationBackLogisticsCompany() != null){ backLogisticsCompany = KuaiDi100.replace(customerStatisticalInfo.getRelationBackLogisticsCompany()); } String backStatus = "未知"; if(customerStatisticalInfo.getRelationBackStatus() != null){ if(customerStatisticalInfo.getRelationBackStatus().equals("1")){ backStatus = "未寄回"; } if(customerStatisticalInfo.getRelationBackStatus().equals("2")){ backStatus = "已寄回"; } if(customerStatisticalInfo.getRelationBackStatus().equals("3")){ backStatus = "已收货"; } } String sendLogisticsCompany = ""; if(customerStatisticalInfo.getRelationSendLogisticsCompany() != null){ sendLogisticsCompany = KuaiDi100.replace(customerStatisticalInfo.getRelationSendLogisticsCompany()); } // 创建单元格,设置值 row.createCell(0).setCellValue(createTime); row.createCell(1).setCellValue(customerStatisticalInfo.getCustomerName() == null ? null : customerStatisticalInfo.getCustomerName()); row.createCell(2).setCellValue(customerStatisticalInfo.getCustomerTel() == null ? null : customerStatisticalInfo.getCustomerTel()); row.createCell(3).setCellValue(customerStatisticalInfo.getCounselType() == null ? null : customerStatisticalInfo.getCounselType()); row.createCell(4).setCellValue(customerStatisticalInfo.getSourceType() == null ? null : customerStatisticalInfo.getSourceType()); row.createCell(5).setCellValue(customerStatisticalInfo.getComplaintClassName() == null ? null : customerStatisticalInfo.getComplaintClassName()); row.createCell(6).setCellValue(customerStatisticalInfo.getSmallClassName() == null ? null : customerStatisticalInfo.getSmallClassName()); row.createCell(7).setCellValue(customerStatisticalInfo.getDescribeTitle() == null ? null : customerStatisticalInfo.getDescribeTitle()); row.createCell(8).setCellValue(customerStatisticalInfo.getDescribeHandleDesc() == null ? null : customerStatisticalInfo.getDescribeHandleDesc()); row.createCell(9).setCellValue(salesPayTime); row.createCell(10).setCellValue(customerStatisticalInfo.getProcMethodName() == null ? null : customerStatisticalInfo.getProcMethodName()); row.createCell(11).setCellValue(customerStatisticalInfo.getCustomerIsSolve() == null ? null : customerStatisticalInfo.getCustomerIsSolve()); row.createCell(12).setCellValue(customerStatisticalInfo.getCompanyName() == null ? null : customerStatisticalInfo.getCompanyName()); row.createCell(13).setCellValue(customerStatisticalInfo.getStoreName() == null ? null : customerStatisticalInfo.getStoreName()); /*StringBuffer sb = new StringBuffer(""); if(customerStatisticalInfo.getSignclosedProductInfos().size() > 0){ for(SignclosedProductInfo sign : customerStatisticalInfo.getSignclosedProductInfos()){ sb.append(sign.getProductName()+"("+sign.getColorName()+")"+"*"+sign.getProductNum()+";"); } }*/ if(customerStatisticalInfo.getSignclosedProductInfo() == null){ row.createCell(14).setCellValue(""); }else{ row.createCell(14).setCellValue(customerStatisticalInfo.getSignclosedProductInfo().toString()); } row.createCell(15).setCellValue(customerStatisticalInfo.getItemProductColor() == null ? null : customerStatisticalInfo.getItemProductColor()); row.createCell(16).setCellValue(customerStatisticalInfo.getTypeName() == null ? null : customerStatisticalInfo.getTypeName()); row.createCell(17).setCellValue(customerStatisticalInfo.getItemNum() == null ? null : customerStatisticalInfo.getItemNum()); row.createCell(18).setCellValue(backLogisticsCompany); row.createCell(19).setCellValue(customerStatisticalInfo.getRelationBackLogisticsNo() == null ? null : customerStatisticalInfo.getRelationBackLogisticsNo()); row.createCell(20).setCellValue(customerStatisticalInfo.getRelationBackReceiptDate() == null ? null : customerStatisticalInfo.getRelationBackReceiptDate()); row.createCell(21).setCellValue(backStatus); row.createCell(22).setCellValue(sendLogisticsCompany); row.createCell(23).setCellValue(customerStatisticalInfo.getRelationSendLogisticsNo() == null ? null : customerStatisticalInfo.getRelationSendLogisticsNo()); row.createCell(24).setCellValue(customerStatisticalInfo.getCustomerOutDamaged() == null ? null : customerStatisticalInfo.getCustomerOutDamaged()); row.createCell(25).setCellValue(customerStatisticalInfo.getCustomerSecondaryCustomer() == null ? null : customerStatisticalInfo.getCustomerSecondaryCustomer()); row.createCell(26).setCellValue(customerStatisticalInfo.getAdminName() == null ? null : customerStatisticalInfo.getAdminName()); if(customerStatisticalInfo.getRelationFactoryCosts() == null){ row.createCell(27).setCellValue(""); }else{ row.createCell(27).setCellValue(customerStatisticalInfo.getRelationFactoryCosts()); } if(customerStatisticalInfo.getRelationCustomerCosts() == null){ row.createCell(28).setCellValue(""); }else{ row.createCell(28).setCellValue(customerStatisticalInfo.getRelationCustomerCosts()); } row.createCell(29).setCellValue(customerStatisticalInfo.getPostageString()); } //下载导出订单Excel downloadCustomerExcel(wb,downloadProgressInfo,path,"客诉报表"); } /** * 下载导出客诉到本地 * @param wb * @throws Exception */ public void downloadCustomerExcel(HSSFWorkbook wb,DownloadProgressInfo downloadProgressInfo,String path,String name) throws Exception{ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String fileName = format.format(new Date()) + name; try { FileOutputStream fout = new FileOutputStream(path+"/common/customerExcel/"+fileName+downloadProgressInfo.getDownloadId()+".xls"); wb.write(fout); fout.close(); } catch (Exception e) { e.printStackTrace(); } downloadProgressInfo.setDownloadStatus(2); downloadProgressInfo.setDownloadUrl("\\common\\customerExcel\\"+fileName+downloadProgressInfo.getDownloadId()+".xls"); customerService.updateDownloadProgressInfo(downloadProgressInfo); } /** * 下载导出客诉到Excel * @param res * @param wb * @throws Exception */ public void downloadCustomerExcel(HttpServletResponse res, HSSFWorkbook wb) throws Exception{ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String fileName = format.format(new Date()) + "客诉报表"; ByteArrayOutputStream os = new ByteArrayOutputStream(); wb.write(os); byte[] content = os.toByteArray(); InputStream is = new ByteArrayInputStream(content); // 设置response参数,可以打开下载页面 res.reset(); res.setContentType("application/vnd.ms-excel;charset=utf-8"); res.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1")); ServletOutputStream out = res.getOutputStream(); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(is); bos = new BufferedOutputStream(out); byte[] buff = new byte[2048]; int bytesRead; // Simple read/write loop. while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { if (bis != null) bis.close(); if (bos != null) bos.close(); } } /** * 跳转到添加客诉页面 * * @return */ @RequiresPermissions("customer:statistical:customer") @RequestMapping(value = "/to_return_statistics") public ModelAndView toReturnStatistics(HttpServletRequest request) { ModelAndView mv = new ModelAndView("cm/report/return_statistics"); //获取产品集合,用于页面选择产品 ProductColor productColor = new ProductColor(); List productColorList = productService.listproductAndColor(productColor); mv.addObject("productColorList", productColorList); //查询店铺 StoreInfo storeInfo = new StoreInfo(); List storeList = storeInfoService.listStore(storeInfo); mv.addObject("storeList", storeList); return mv; } /** * 退换货统计 * @param request * @param salesOrder * @return */ @ResponseBody @RequestMapping("/return_statistics") public ResponseJson returnStatistics(HttpServletRequest request,SalesOrder salesOrder){ if(salesOrder.getStartDate() == null){ Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(now); c.set(Calendar.DAY_OF_YEAR, 1); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); salesOrder.setStartDate(c.getTime()); c.add(Calendar.YEAR, 1); c.set(Calendar.DAY_OF_YEAR, -1); c.set(Calendar.HOUR, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); salesOrder.setEndDate(c.getTime()); } if(salesOrder.getItemColorBar() != null && !salesOrder.getItemColorBar().equals("")){ List listColorBar = Arrays.asList(salesOrder.getItemColorBar().split(",")); salesOrder.setListColorBar(listColorBar); } /*销售总数*/ List listTotalSales = customerService.salesTotalSales(salesOrder); /*总换货*/ List listTotalExchange = customerService.salesTotalExchange(salesOrder); /*总退货*/ List listTotalReturn = customerService.salesTotalReturn(salesOrder); /*二次换货*/ List listSecondaryChangeNew = customerService.salesSecondaryChangeNew(salesOrder); /*二次换新退货*/ List listReturnForSecond = customerService.salesReturnForSecond(salesOrder); /*封装数据*/ List listReturnStatisticsInfo = new ArrayList<>(); boolean isThereAre = false; for (int i = 1;i<=12;i++){ ReturnStatisticsInfo returnStatisticsInfo = new ReturnStatisticsInfo(); for(int j = 0;j< listTotalSales.size(); j++){ if(i == listTotalSales.get(j).getMonths()){ returnStatisticsInfo.setMonths(i); returnStatisticsInfo.setTotalSales(listTotalSales.get(j).getNum()); isThereAre = true; } } if(!isThereAre){ returnStatisticsInfo.setMonths(i); returnStatisticsInfo.setTotalSales(0); } isThereAre = false; listReturnStatisticsInfo.add(returnStatisticsInfo); } for(int i = 0;i pagedResult = customerService.listCustomer(pageNO, pageSize, customer, totalNum == 0); if (totalNum != 0) { pagedResult.setTotal(totalNum); } // // //查询产品类型集合 // List typeList = productService.listProductType(new ProductType()); // //查询客诉类型集合 // List complaintTypeList = complaintTypeInfoService.listComplaintTypeInfo(new ComplaintTypeInfo()); // //查询客诉类型集合 // List complaintSmallClassInfoList = complaintSmallClassInfoService.listComplaintSmallClassInfo(new ComplaintSmallClassInfo()); //查询跟进客服集合 Admin admin = new Admin(); admin.setAdminDept(3); admin.setAdminStatus(1); List adminList = sysService.listSelectAdmin(admin); ResponseJson rj = ResponseJson.getSUCCESS(); // rj.addResponseKeyValue("typeList",typeList); // rj.addResponseKeyValue("complaintTypeList",complaintTypeList); // rj.addResponseKeyValue("complaintSmallClassInfoList",complaintSmallClassInfoList); rj.addResponseKeyValue("adminList",adminList); rj.addResponseKeyValue("customerList",pagedResult.getDataList()); return rj; } /** * 获取邮费信息 * @param request * @param postageId * @return */ @ResponseBody @RequestMapping("/get_PostageInfo") public ResponseJson getPostageInfo(HttpServletRequest request,Integer postageId){ ResponseJson rj = new ResponseJson(200, "查询成功", 200); if(postageId == null){ return new ResponseJson(500, "查询失败!", 500); } PostageInfo postageInfo = customerService.getPostageInfo(postageId); rj.addResponseKeyValue("postageInfo",postageInfo); return rj; } /** * 添加邮费信息 * @param request * @param postageInfo * @return */ @ResponseBody @RequestMapping("/add_PostageInfo") public ResponseJson addPostageInfo(HttpServletRequest request,PostageInfo postageInfo){ ResponseJson rj = new ResponseJson(200, "添加成功", 200); if(postageInfo == null){ return new ResponseJson(500, "添加失败,请检查参数!", 500); } postageInfo.setAdminId(AdminUtils.getLoginAdminId()); Integer msg = customerService.addPostageInfo(postageInfo); if(msg < 1){ return new ResponseJson(500, "添加失败", 500); } rj.addResponseKeyValue("postageInfo",postageInfo); return rj; } /** * 修改邮费信息 * @param request * @param postageInfo * @return */ @ResponseBody @RequestMapping("/update_PostageInfo") public ResponseJson updatePostageInfo(HttpServletRequest request,PostageInfo postageInfo){ ResponseJson rj = new ResponseJson(200, "修改成功", 200); if(postageInfo == null){ return new ResponseJson(500, "修改失败,请检查参数!", 500); } Integer msg = customerService.updatePostageInfo(postageInfo); if(msg < 1){ return new ResponseJson(500, "修改失败", 500); } rj.addResponseKeyValue("postageInfo",postageInfo); return rj; } /** * 删除邮费信息 * @param request * @param postageId * @return */ @ResponseBody @RequestMapping("/delete_PostageInfo") public ResponseJson deletePostageInfo(HttpServletRequest request,Integer postageId){ ResponseJson rj = new ResponseJson(200, "删除成功", 200); if(postageId == null){ return new ResponseJson(500, "删除失败,请检查参数!", 500); } Integer msg = customerService.deletePostageInfo(postageId); if(msg < 1){ return new ResponseJson(500, "删除失败", 500); } return rj; } /** * 获取寄回信息 * @param request * @param sendbackId * @return */ @ResponseBody @RequestMapping("/get_SendbackInfo") public ResponseJson getSendbackInfo(HttpServletRequest request,Integer sendbackId){ ResponseJson rj = new ResponseJson(200, "查询成功", 200); if(sendbackId == null){ return new ResponseJson(500, "查询失败!", 500); } SendbackInfo sendbackInfo = customerService.getSendbackInfo(sendbackId); rj.addResponseKeyValue("sendbackInfo",sendbackInfo); return rj; } /** * 添加寄回信息 * @param request * @param sendbackInfo * @return */ @ResponseBody @RequestMapping("/add_SendbackInfo") public ResponseJson addSendbackInfo(HttpServletRequest request,SendbackInfo sendbackInfo){ ResponseJson rj = new ResponseJson(200, "添加成功", 200); if(sendbackInfo == null){ return new ResponseJson(500, "添加失败,请检查参数!", 500); } /*signTime*/ SendbackInfo info = customerService.addSendbackInfo(sendbackInfo); if(info == null){ return new ResponseJson(500, "添加失败", 500); } SendbackInfo info1 = customerService.getSendbackInfo(sendbackInfo.getSendbackId()); rj.addResponseKeyValue("sendbackInfo",info1); return rj; } /** * 修改寄回信息 * @param request * @param sendbackInfo * @return */ @ResponseBody @RequestMapping("/update_SendbackInfo") public ResponseJson updateSendbackInfo(HttpServletRequest request,SendbackInfo sendbackInfo){ ResponseJson rj = new ResponseJson(200, "修改成功", 200); if(sendbackInfo == null){ return new ResponseJson(500, "修改失败,请检查参数!", 500); } SendbackInfo info = customerService.updateSendbackInfo(sendbackInfo); if(info == null){ return new ResponseJson(500, "修改失败", 500); } SendbackInfo info1 = customerService.getSendbackInfo(sendbackInfo.getSendbackId()); rj.addResponseKeyValue("sendbackInfo",info1); return rj; } /** * 修改寄回状态为已签收 * @param request * @param sendbackInfo * @return */ @ResponseBody @RequestMapping("/update_SendbackStatus") public ResponseJson updateSendbackStatus(HttpServletRequest request,SendbackInfo sendbackInfo){ ResponseJson rj = new ResponseJson(200, "修改成功", 200); if(sendbackInfo == null){ return new ResponseJson(500, "修改失败,请检查参数!", 500); } if(customerService.updateSendbackStatus(sendbackInfo) < 1){ return new ResponseJson(500, "修改失败", 500); } SendbackInfo info1 = customerService.getSendbackInfo(sendbackInfo.getSendbackId()); rj.addResponseKeyValue("sendbackInfo",info1); return rj; } /** * 删除单个寄回信息 * @param request * @param sendbackId * @return */ @ResponseBody @RequestMapping("/delete_SendbackInfo") public ResponseJson deleteSendbackInfo(HttpServletRequest request,Integer sendbackId){ ResponseJson rj = new ResponseJson(200, "删除成功", 200); if(sendbackId == null){ return new ResponseJson(500, "删除失败,请检查参数!", 500); } Integer msg = customerService.deleteSendbackInfo(sendbackId); if(msg > 0){ complaintSignclosedInfoService.delSignclosedBySendbackId(sendbackId); }else{ return new ResponseJson(500, "删除失败", 500); } return rj; } /** * 同步邮费信息 * @param request * @param * @return */ /*@ResponseBody @RequestMapping("/synchronize_PostageInfo")*/ public ResponseJson synchronizePostageInfo(HttpServletRequest request){ String msg = customerService.synchronizePostageInfo(); return new ResponseJson(200, msg, 200); } /** * 同步寄回信息 * @param request * @param * @return */ /*@ResponseBody @RequestMapping("/synchronizeSendbackInfo")*/ public ResponseJson synchronizeSendbackInfo(HttpServletRequest request){ String msg = customerService.synchronizeSendbackInfo(); return new ResponseJson(200, msg, 200); } /** * 添加收费 * @param request * @param informationInfo * @return */ @ResponseBody @RequestMapping("/add_informationInfo") public ResponseJson addInformationInfo(HttpServletRequest request,InformationInfo informationInfo){ ResponseJson rj = new ResponseJson(200, "添加成功", 200); if(informationInfo == null){ return new ResponseJson(500, "添加失败,请检查参数!", 500); } /*signTime*/ Integer msg = customerService.addInformationInfo(informationInfo); if(msg < 1){ return new ResponseJson(500, "添加失败", 500); } InformationInfo info = customerService.getInformationInfo(informationInfo.getFeeId()); rj.addResponseKeyValue("informationInfo",info); return rj; } /** * 上传交易图片 * @RequestParam("file") 将name=file控件得到的文件封装成CommonsMultipartFile 对象 */ @ResponseBody @RequestMapping("/fee_fileUpload") public ResponseJson fileUpload(HttpServletRequest request, @RequestParam(value = "file",required = false) CommonsMultipartFile file) throws IOException { ResponseJson responseJson = new ResponseJson(); if(file == null || file.getOriginalFilename() == null || "".equals(file.getOriginalFilename())){ responseJson.setReturnCode(500); return responseJson; } System.out.println("fileName:"+file.getOriginalFilename()); String realPath = request.getSession().getServletContext().getRealPath("/"); String oldName = file.getOriginalFilename(); //名称 String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().toString().lastIndexOf(".")); String name = System.currentTimeMillis()+suffix; String path = UploadFileUtils.cmFeePayPictureUploadFile(realPath,name,file); String url = request.getScheme()+"://"+ request.getServerName(); responseJson.setReturnCode(200); responseJson.addResponseKeyValue("allImgUrl",url + "/" + path); responseJson.addResponseKeyValue("imgUrl",path); responseJson.addResponseKeyValue("oldName",oldName); responseJson.addResponseKeyValue("name",name); return responseJson; } /** * 修改收费 * @param request * @param informationInfo * @return */ @ResponseBody @RequestMapping("/update_informationInfo") public ResponseJson updateInformationInfo(HttpServletRequest request,InformationInfo informationInfo){ ResponseJson rj = new ResponseJson(200, "修改成功", 200); if(informationInfo == null){ return new ResponseJson(500, "修改失败,请检查参数!", 500); } /*signTime*/ Integer msg = customerService.updateInformationInfo(informationInfo); if(msg < 1){ return new ResponseJson(500, "修改失败", 500); } InformationInfo info = customerService.getInformationInfo(informationInfo.getFeeId()); rj.addResponseKeyValue("informationInfo",info); return rj; } /** * 删除单个收费信息 * @param request * @param feeId * @return */ @ResponseBody @RequestMapping("/delete_informationInfo") public ResponseJson deleteInformationInfo(HttpServletRequest request,Integer feeId){ ResponseJson rj = new ResponseJson(200, "删除成功", 200); if(feeId == null){ return new ResponseJson(500, "删除失败,请检查参数!", 500); } Integer msg = customerService.delInformationInfo(feeId); if(msg < 1){ return new ResponseJson(500, "删除失败", 500); } return rj; } /** * 查询单个收费信息 * @param request * @param feeId * @return */ @ResponseBody @RequestMapping("/get_informationInfo") public ResponseJson getInformationInfo(HttpServletRequest request,Integer feeId){ ResponseJson rj = new ResponseJson(200, "查询成功", 200); if(feeId == null){ return new ResponseJson(500, "查询失败,请检查参数!", 500); } InformationInfo informationInfo = customerService.getInformationInfo(feeId); if(informationInfo == null){ return new ResponseJson(500, "查询失败", 500); } rj.addResponseKeyValue("informationInfo",informationInfo); return rj; } /** * 查询签收/检测数量 * @param request * @param isOneself 1全部 2只看自己 * @return */ @ResponseBody @RequestMapping("/get_afterSalesNum") public ResponseJson getAfterSalesNum(HttpServletRequest request,Integer isOneself){ ResponseJson rj = new ResponseJson(200, "查询成功", 200); ComplaintAfterSalesNum complaintAfterSalesNum = new ComplaintAfterSalesNum(); //获取登录人id Integer loginAdminId = AdminUtils.getLoginAdminId(); if(isOneself == null){ //查询缓存数据 String redisIsOneself = RedisUtils.get("CUSTOMER"+loginAdminId); if(redisIsOneself == null){ RedisUtils.put("CUSTOMER"+loginAdminId,1);//新增缓存为查询全部 isOneself = 1; }else{ isOneself = Integer.valueOf(redisIsOneself); } }else if(isOneself == 1){ RedisUtils.put("CUSTOMER"+loginAdminId,1);//更新缓存 }else if(isOneself == 2){ RedisUtils.put("CUSTOMER"+loginAdminId,2);//更新缓存 } ComplaintDetectInfo detect = new ComplaintDetectInfo(); ComplaintSignclosedInfo signclosed = new ComplaintSignclosedInfo(); if (isOneself == 2) { detect.setAdminId(loginAdminId); signclosed.setAdminId(loginAdminId); } /*查询维修数据 state*/ ComplaintAfterSalesNum afterSalesNum = complaintDetectInfoService.getCustomerDetectNum(detect); if(afterSalesNum == null){ complaintAfterSalesNum.setBeDetected(0); complaintAfterSalesNum.setBeConfirmed(0); complaintAfterSalesNum.setCompleteProcessing(0); complaintAfterSalesNum.setPlaceOrderNum(0); complaintAfterSalesNum.setDetectplaceOrderNum(0); complaintAfterSalesNum.setMaintenanceCutTimeNum(0); complaintAfterSalesNum.setCompleteCutTimeNum(0); }else{ complaintAfterSalesNum.setBeDetected(afterSalesNum.getBeDetected()); complaintAfterSalesNum.setBeConfirmed(afterSalesNum.getBeConfirmed()); complaintAfterSalesNum.setCompleteProcessing(afterSalesNum.getCompleteProcessing()); complaintAfterSalesNum.setPlaceOrderNum(afterSalesNum.getPlaceOrderNum()); complaintAfterSalesNum.setDetectplaceOrderNum(afterSalesNum.getDetectplaceOrderNum()); complaintAfterSalesNum.setMaintenanceCutTimeNum(afterSalesNum.getMaintenanceCutTimeNum()); complaintAfterSalesNum.setCompleteCutTimeNum(afterSalesNum.getCompleteCutTimeNum()); } /*查询维修数据 end*/ /*查询签收数据 state*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar date = Calendar.getInstance(); date.setTime(new Date()); //今日签收 signclosed.setDate(sdf.format(date.getTime())); Integer s1 = complaintSignclosedInfoService.getSignclosedDay(signclosed); complaintAfterSalesNum.setTodaysignNum(complaintSignclosedInfoService.getSignclosedDay(signclosed)); //昨日签收 date.set(Calendar.DATE, date.get(Calendar.DATE) - 1); signclosed.setDate(sdf.format(date.getTime())); complaintAfterSalesNum.setYesterdaysignNum(complaintSignclosedInfoService.getSignclosedDay(signclosed)); //前日签收 date.set(Calendar.DATE, date.get(Calendar.DATE) - 1); signclosed.setDate(sdf.format(date.getTime())); complaintAfterSalesNum.setBeforedaysignNum(complaintSignclosedInfoService.getSignclosedDay(signclosed)); //待联系 signclosed.setIsBinding(1); signclosed.setDate(null); complaintAfterSalesNum.setContactNum(complaintSignclosedInfoService.getSignclosedDay(signclosed)); //待换货发出数量 ComplaintSignclosedInfo signcloseds = new ComplaintSignclosedInfo(); if (isOneself == 2) { signcloseds.setAdminId(loginAdminId); } complaintAfterSalesNum.setCompleteSent(complaintSignclosedInfoService.getCompleteSent(signcloseds)); /*查询签收数据 end*/ //待打印邮费申请 complaintAfterSalesNum.setPostagePrintedNum(postageService.getPostagePrintedNum()); rj.addResponseKeyValue("complaintAfterSalesNum",complaintAfterSalesNum); rj.addResponseKeyValue("isOneself",isOneself); return rj; } /** * 下载客诉统计信息 (2018-05-29) * * @param request * @param res * @param * @throws Exception */ @ResponseBody @RequestMapping("/download_customer_statistics") public ResponseJson downloadStatisticsExcel(HttpServletRequest request, HttpServletResponse res, CustomerInfo customerInfo) throws Exception { String path = request.getSession().getServletContext().getRealPath("/"); new Thread(new Mythread2(path,customerInfo)).start(); return new ResponseJson(200, "查询成功", 200); } class Mythread2 extends Thread{ private String path; private CustomerInfo customerInfo; public Mythread2(String path,CustomerInfo customerInfo) { this.path=path; this.customerInfo=customerInfo; } @Override public void run(){ Admin admin = AdminUtils.getLoginAdmin(); //添加一条下载记录 DownloadProgressInfo downloadProgressInfo = new DownloadProgressInfo(); downloadProgressInfo.setDownloadAdminId(admin.getAdminId()); downloadProgressInfo.setDownloadProgress("00.00"); downloadProgressInfo.setDownloadStatus(1); customerService.addDownloadProgressInfo(downloadProgressInfo); //循环一次的时间(毫秒) long cycleOne = 0; long cycleOnes = 0; int s = 0; List customerList = new ArrayList<>(); //计算统计月份 List listmonth = ExcelUtil.month(customerInfo.getStartTime(),customerInfo.getEndTime()); if(listmonth.size() > 0){ for(String month : listmonth){ List list = customerService.selectCustomerStatistics(month); customerList.addAll(list); } } String[] cells = { "月份", "产品型号", "处理结果", "数量1", "处理方法", "数量2", "购买月份", "数量3", "客诉问题", "数量4", "数量5" }; long startTime=System.currentTimeMillis(); //获取开始时间 s++; long endTime=System.currentTimeMillis(); //获取结束时间 NumberFormat numberFormat = NumberFormat.getInstance(); float percentage = (float) s / (float) customerList.size() * 100; String result = numberFormat.format(percentage); if(s == 1){ cycleOne = endTime - startTime; SimpleDateFormat sdf3=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); cycleOnes = cycleOne * customerList.size(); //修改预计下载完成时间 downloadProgressInfo.setDownloadDate(sdf3.format(new Date().getTime()+cycleOnes)); downloadProgressInfo.setDownloadProgress(result); customerService.updateDownloadProgressInfo(downloadProgressInfo); } //导出订单Excel并下载 try { customerExcel2(cells,customerList,downloadProgressInfo,path); } catch (Exception e) { e.printStackTrace(); } } } /** * 导出订单Excel并下载 * @param cells * @throws Exception */ public void customerExcel2(String[] cells,List customerList, DownloadProgressInfo downloadProgressInfo,String path) throws Exception { //创建一个workbook,对应一个Excel文件 HSSFWorkbook wb = new HSSFWorkbook(); //在workbook中添加一个sheet,对应Excel中的一个sheet HSSFSheet sheet = wb.createSheet("导出客诉统计"); //在sheet中添加表头第0行,老版本poi对excel行数列数有限制short HSSFRow row = sheet.createRow((int) 0); //创建单元格,设置值表头,设置表头居中 HSSFCellStyle style = wb.createCellStyle(); //居中格式 style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中 //设置表头 if (cells == null || cells.length == 0) { return; } //循环设置表头 HSSFCell cell = null; for (int i = 0; i < cells.length; i++) { String name = cells[i]; cell = row.createCell(i); cell.setCellValue(name); cell.setCellStyle(style); } if (customerList.size() > 0) { int s1 = 0; for (int i = 0; i < customerList.size() - 1; i++) { if (i >= s1) { for (int j = 0; j < customerList.size() - 1; j++) { if (j >= s1) { if (customerList.get(i).getProcessingResults().equals(customerList.get(j + 1).getProcessingResults()) && customerList.get(i).getProductModel().equals(customerList.get(j + 1).getProductModel())) { customerList.get(i).setNumberOne(customerList.get(i).getNumberOne() + customerList.get(j + 1).getNumberOne()); customerList.get(j + 1).setNumberOne(0); s1 = j + 1; } else { s1 = j + 1; break; } } } } } } if (customerList.size() > 0) { int s2 = 0; for (int i = 0; i < customerList.size() - 1; i++) { if (i >= s2) { for (int j = 0; j < customerList.size() - 1; j++) { if (j >= s2) { if (customerList.get(i).getProcessingResults().equals(customerList.get(j + 1).getProcessingResults()) && customerList.get(i).getProductModel().equals(customerList.get(j + 1).getProductModel()) && customerList.get(i).getProcessingMethod().equals(customerList.get(j + 1).getProcessingMethod())) { customerList.get(i).setNumberTwo(customerList.get(i).getNumberTwo() + customerList.get(j + 1).getNumberTwo()); customerList.get(j + 1).setNumberTwo(0); s2 = j + 1; } else { s2 = j + 1; break; } } } } } } if (customerList.size() > 0) { int s2 = 0; for (int i = 0; i < customerList.size() - 1; i++) { if (i >= s2) { for (int j = 0; j < customerList.size() - 1; j++) { if (j >= s2) { if (customerList.get(i).getProcessingResults().equals(customerList.get(j + 1).getProcessingResults()) && customerList.get(i).getProductModel().equals(customerList.get(j + 1).getProductModel()) && customerList.get(i).getProcessingMethod().equals(customerList.get(j + 1).getProcessingMethod()) && customerList.get(i).getBuyMonth() != null && customerList.get(j + 1).getBuyMonth() != null && customerList.get(i).getBuyMonth().equals(customerList.get(j + 1).getBuyMonth())) { customerList.get(i).setNumberThree(customerList.get(i).getNumberThree() + customerList.get(j + 1).getNumberThree()); customerList.get(j + 1).setNumberThree(0); customerList.get(j + 1).setBuyMonth(""); s2 = j + 1; } else { s2 = j + 1; break; } } } } } } if (customerList.size() > 0) { int s2 = 0; for (int i = 0; i < customerList.size() - 1; i++) { if (i >= s2) { for (int j = 0; j < customerList.size() - 1; j++) { if (j >= s2) { if (customerList.get(i).getProcessingResults().equals(customerList.get(j + 1).getProcessingResults()) && customerList.get(i).getProductModel().equals(customerList.get(j + 1).getProductModel()) && customerList.get(i).getProcessingMethod().equals(customerList.get(j + 1).getProcessingMethod())) { customerList.get(j + 1).setProcessingMethod(""); s2 = j + 1; } else { s2 = j + 1; break; } } } } } } if (customerList.size() > 0) { int s2 = 0; for (int i = 0; i < customerList.size() - 1; i++) { if (i >= s2) { for (int j = 0; j < customerList.size() - 1; j++) { if (j >= s2) { if (customerList.get(i).getProcessingResults().equals(customerList.get(j + 1).getProcessingResults()) && customerList.get(i).getProductModel().equals(customerList.get(j + 1).getProductModel())) { customerList.get(j + 1).setProcessingResults(""); s2 = j + 1; } else { s2 = j + 1; break; } } } } } } if (customerList.size() > 0) { int s2 = 0; for (int i = 0; i < customerList.size() - 1; i++) { if (i >= s2) { for (int j = 0; j < customerList.size() - 1; j++) { if (j >= s2) { if (customerList.get(i).getProductModel().equals(customerList.get(j + 1).getProductModel())) { customerList.get(j + 1).setProductModel(""); s2 = j + 1; } else { s2 = j + 1; break; } } } } } } if (customerList.size() > 0) { int s2 = 0; for (int i = 0; i < customerList.size() - 1; i++) { if (i >= s2) { for (int j = 0; j < customerList.size() - 1; j++) { if (j >= s2) { if (customerList.get(i).getMonth().equals(customerList.get(j + 1).getMonth())) { customerList.get(j + 1).setMonth(""); s2 = j + 1; } else { s2 = j + 1; break; } } } } } } for (int i = 0; i < customerList.size(); i++) { row = sheet.createRow((int) i + 1); CustomerStatistics customerStatisticalInfo = customerList.get(i); // 创建单元格,设置值 row.createCell(0).setCellValue(customerStatisticalInfo.getMonth() == null ? "" : customerStatisticalInfo.getMonth()); if(customerStatisticalInfo.getProductModel() == null){ row.createCell(1).setCellValue(""); }else{ row.createCell(1).setCellValue( customerStatisticalInfo.getProductModel()); } if(customerStatisticalInfo.getProcessingResults() == null){ row.createCell(2).setCellValue(""); }else{ row.createCell(2).setCellValue( customerStatisticalInfo.getProcessingResults()); } if(customerStatisticalInfo.getNumberOne() == null || customerStatisticalInfo.getNumberOne() == 0){ row.createCell(3).setCellValue(""); }else{ row.createCell(3).setCellValue( customerStatisticalInfo.getNumberOne()); } if(customerStatisticalInfo.getProcessingMethod() == null){ row.createCell(4).setCellValue(""); }else{ row.createCell(4).setCellValue( customerStatisticalInfo.getProcessingMethod()); } if(customerStatisticalInfo.getNumberTwo() == null || customerStatisticalInfo.getNumberTwo() == 0){ row.createCell(5).setCellValue(""); }else{ row.createCell(5).setCellValue( customerStatisticalInfo.getNumberTwo()); } if(customerStatisticalInfo.getBuyMonth() == null){ row.createCell(6).setCellValue(""); }else{ row.createCell(6).setCellValue( customerStatisticalInfo.getBuyMonth()); } if(customerStatisticalInfo.getNumberThree() == null || customerStatisticalInfo.getNumberThree() == 0){ row.createCell(7).setCellValue(""); }else{ row.createCell(7).setCellValue( customerStatisticalInfo.getNumberThree()); } if(customerStatisticalInfo.getAftersaleProblem() == null){ row.createCell(8).setCellValue(""); }else{ row.createCell(8).setCellValue( customerStatisticalInfo.getAftersaleProblem()); } if(customerStatisticalInfo.getNumberFour() == null || customerStatisticalInfo.getNumberFour() == 0){ row.createCell(9).setCellValue(""); }else{ row.createCell(9).setCellValue( customerStatisticalInfo.getNumberFour()); } if(customerStatisticalInfo.getNumberFive() == null || customerStatisticalInfo.getNumberFive() == 0){ row.createCell(10).setCellValue(""); }else{ row.createCell(10).setCellValue( customerStatisticalInfo.getNumberFive()); } cell = row.getCell(0); cell.setCellStyle(style); cell = row.getCell(1); cell.setCellStyle(style); cell = row.getCell(2); cell.setCellStyle(style); cell = row.getCell(3); cell.setCellStyle(style); cell = row.getCell(4); cell.setCellStyle(style); cell = row.getCell(5); cell.setCellStyle(style); cell = row.getCell(6); cell.setCellStyle(style); cell = row.getCell(7); cell.setCellStyle(style); cell = row.getCell(8); cell.setCellStyle(style); cell = row.getCell(9); cell.setCellStyle(style); cell = row.getCell(10); cell.setCellStyle(style); } HashMap> cellMaps = new HashMap<>(); HashMap cellMap = new HashMap<>(); int c1 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c1){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c1){ if(sheet.getRow(j+1).getCell(0).toString().equals("") || sheet.getRow(j+1).getCell(0) == null){ cellMap.put(i,j+1); c1 = j+1; }else{ c1 = j+1; break; } } } } } cellMaps.put(0,cellMap); HashMap cellMap2 = new HashMap<>(); int c2 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c2){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c2){ if(sheet.getRow(j+1).getCell(1).toString().equals("") || sheet.getRow(j+1).getCell(1) == null){ cellMap2.put(i,j+1); c2 = j+1; }else{ c2 = j+1; break; } } } } } cellMaps.put(1,cellMap2); HashMap cellMap3 = new HashMap<>(); int c3 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c3){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c3){ if(sheet.getRow(j+1).getCell(2).toString().equals("") || sheet.getRow(j+1).getCell(2) == null){ cellMap3.put(i,j+1); c3 = j+1; }else{ c3 = j+1; break; } } } } } cellMaps.put(2,cellMap3); HashMap cellMap4 = new HashMap<>(); int c4 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c4){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c4){ if(sheet.getRow(j+1).getCell(3).toString().equals("") || sheet.getRow(j+1).getCell(3) == null){ cellMap4.put(i,j+1); c4 = j+1; }else{ c4 = j+1; break; } } } } } cellMaps.put(3,cellMap4); HashMap cellMap5 = new HashMap<>(); int c5 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c5){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c5){ if(sheet.getRow(j+1).getCell(4).toString().equals("") || sheet.getRow(j+1).getCell(4) == null){ cellMap5.put(i,j+1); c5 = j+1; }else{ c5 = j+1; break; } } } } } cellMaps.put(4,cellMap5); HashMap cellMap6 = new HashMap<>(); int c6 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c6){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c6){ if(sheet.getRow(j+1).getCell(5).toString().equals("") || sheet.getRow(j+1).getCell(5) == null){ cellMap6.put(i,j+1); c6 = j+1; }else{ c6 = j+1; break; } } } } } cellMaps.put(5,cellMap6); HashMap cellMap7 = new HashMap<>(); int c7 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c7){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c7){ if((sheet.getRow(j+1).getCell(6).toString().equals("") || sheet.getRow(j+1).getCell(6) == null) && (sheet.getRow(j+1).getCell(5).toString().equals("") || sheet.getRow(j+1).getCell(5) == null)){ cellMap7.put(i,j+1); c7 = j+1; }else{ c7 = j+1; break; } } } } } cellMaps.put(6,cellMap7); HashMap cellMap8 = new HashMap<>(); int c8 = 0; //合并单元格 for(int i=0;i < sheet.getPhysicalNumberOfRows() -1;i++){ if(i >= c7){ for(int j=0;j < sheet.getPhysicalNumberOfRows() -1;j++){ if(j >= c8){ if((sheet.getRow(j+1).getCell(7).toString().equals("") || sheet.getRow(j+1).getCell(7) == null) && (sheet.getRow(j+1).getCell(6).toString().equals("") || sheet.getRow(j+1).getCell(6) == null) && (sheet.getRow(j+1).getCell(5).toString().equals("") || sheet.getRow(j+1).getCell(5) == null)){ cellMap8.put(i,j+1); c8 = j+1; }else{ c8 = j+1; break; } } } } } cellMaps.put(7,cellMap8); for(Map.Entry> entry : cellMaps.entrySet()) { HashMap map = entry.getValue(); for(Integer key : map.keySet()) { CellRangeAddress region = new CellRangeAddress(key, map.get(key), entry.getKey(), entry.getKey()); sheet.addMergedRegion(region); } } NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); downloadProgressInfo.setDownloadProgress("100"); customerService.updateDownloadProgressInfo(downloadProgressInfo); //下载导出订单Excel downloadCustomerExcel(wb, downloadProgressInfo,path,"统计报表"); } /** * 客诉标识列表 * @param request * @param customerId * @return */ @RequestMapping("/to_tag_list") public ModelAndView listTag(HttpServletRequest request,Integer customerId){ ModelAndView mv = new ModelAndView("cm/customer/tag_list"); if(customerId != null){ TagInfo tag = new TagInfo(); tag.setTagCustomerId(customerId); List listTag = customerService.listTag(tag); mv.addObject("listTag",listTag); } return mv; } /** * 进入添加客诉标识 * @param request * @param customerId * @return */ @RequestMapping("/to_add_Tag") public ModelAndView toAddTag(HttpServletRequest request,Integer customerId){ ModelAndView mv = new ModelAndView("cm/customer/add_tag"); TagInfo tag = new TagInfo(); tag.setTagCustomerId(customerId); List listTag = customerService.listTag(tag); mv.addObject("listTag",listTag); mv.addObject("customerId",customerId); return mv; } /** * 添加客诉标识 * @param request * @param tagInfo * @return */ @ResponseBody @RequestMapping("/add_Tag") public ResponseJson addTag(HttpServletRequest request,TagInfo tagInfo){ if(tagInfo == null || tagInfo.getTagCustomerId() == null){ return new ResponseJson(500, "查询失败,请检查参数!", 500); } //获取登录人id Integer loginAdminId = AdminUtils.getLoginAdminId(); tagInfo.setTagAdminId(loginAdminId); if(customerService.addTag(tagInfo) > 0){ return new ResponseJson(200, "添加成功", 200); }else{ return new ResponseJson(500, "查询失败,请检查参数!", 500); } } }