写接口方式

package com.wonlymall.mall.restfulapi.modular.system.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gson.util.Tools;
import com.wonlymall.mall.core.constant.CommonConstant;
import com.wonlymall.mall.modular.shop.model.ShopInfo;
import com.wonlymall.mall.modular.shop.service.IShopInfoService;
import com.wonlymall.mall.modular.user.model.UserBaseInfo;
import com.wonlymall.mall.modular.user.model.UserOuteruserInfo;
import com.wonlymall.mall.modular.user.service.IUserBaseInfoService;
import com.wonlymall.mall.modular.user.service.IUserOuteruserInfoService;
import com.wonlymall.mall.restfulapi.common.consts.HttpConsts;
import com.wonlymall.mall.restfulapi.common.consts.NumberConsts;
import com.wonlymall.mall.restfulapi.common.plugins.alipay.util.AlipayNotify;
import com.wonlymall.mall.restfulapi.common.plugins.h5.ClientCustomSSL;
import com.wonlymall.mall.restfulapi.common.plugins.tenpay.ResponseHandler;
import com.wonlymall.mall.restfulapi.common.plugins.wechat.RequestHandler;
import com.wonlymall.mall.restfulapi.common.plugins.wechat.WXConfig;
import com.wonlymall.mall.restfulapi.common.plugins.wechat.util.XMLUtil;
import com.wonlymall.mall.restfulapi.common.plugins.wechat.wxpay.WXPayUtil;
import com.wonlymall.mall.restfulapi.common.util.HttpUtil;
import com.wonlymall.mall.restfulapi.common.util.PayCommonUtil;
import com.wonlymall.mall.restfulapi.common.util.StringUtils;
import com.wonlymall.mall.restfulapi.modular.base.controller.BaseController;
import com.wonlymall.mall.restfulapi.modular.system.handler.SystemHandlerService;
import com.wonlymall.mall.restfulapi.modular.system.handler.SystemHandlerServiceH5;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

@RestController
@RequestMapping("system")
public class SystemController extends BaseController {

	@Autowired
	private SystemHandlerService systemHandlerService;

	@Autowired
	private SystemHandlerServiceH5 systemHandlerServiceH5;

	@Autowired
	private IUserOuteruserInfoService iUserOuteruserInfoService;

	@Autowired
	private IUserBaseInfoService iUserBaseInfoService;

	@Autowired
	private IShopInfoService iShopInfoService;

	@RequestMapping("v1/alipaynotify")
	public String alipayNotify(HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			// 获取支付宝POST过来反馈信息
			Map<String, String> params = new HashMap<String, String>();
			Map requestParams = request.getParameterMap();
			for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
				String name = (String) iter.next();
				String[] values = (String[]) requestParams.get(name);
				String valueStr = "";
				for (int i = 0; i < values.length; i++) {
					valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
				}
				// 乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
				// valueStr = new String(valueStr.getBytes("ISO-8859-1"),
				// "gbk");
				params.put(name, valueStr);
			}

			// 获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表(以下仅供参考)//
			// 商户订单号
			String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");

			// 支付宝交易号
			String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"), "UTF-8");

			// 交易状态
			String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"), "UTF-8");

			// 获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表(以上仅供参考)//
			logger.info("out_trade_no:" + out_trade_no + "==trade_no:" + trade_no + "==trade_status:" + trade_status);
			int valid = HttpConsts.NO;

			logger.info("alipaynotify:params" + params.toString());
			if (AlipayNotify.verify2(params)) {// 验证成功
				//
				// 请在这里加上商户的业务逻辑程序代码

				// ——请根据您的业务逻辑来编写程序(以下代码仅作参考)——

				if (trade_status.equals("TRADE_FINISHED")) {
					// 判断该笔订单是否在商户网站中已经做过处理
					// 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
					// 如果有做过处理,不执行商户的业务程序
					out.println("success"); // 请不要修改或删除
					valid = HttpConsts.YES;
					logger.info("支付宝数据支付成功:" + "out_trade_no:" + out_trade_no + "==trade_no:" + trade_no
							+ "==trade_status:" + trade_status);

					// 注意:
					// 退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
					// 请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
				} else if (trade_status.equals("TRADE_SUCCESS")) {
					// 判断该笔订单是否在商户网站中已经做过处理
					// 如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
					// 如果有做过处理,不执行商户的业务程序

					out.println("success"); // 请不要修改或删除

					valid = HttpConsts.YES;
					logger.info("支付宝数据支付成功:" + "out_trade_no:" + out_trade_no + "==trade_no:" + trade_no
							+ "==trade_status:" + trade_status);

					// 注意:
					// 付款完成后,支付宝系统发送该交易状态通知
					// 请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
				} else {
					out.println("fail"); // 请不要修改或删除
					valid = HttpConsts.NO;
					logger.info("支付宝数据支付失败!!" + "out_trade_no:" + out_trade_no + "==trade_no:" + trade_no
							+ "==trade_status:" + trade_status);
				}

				// ——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

				// out.println("success"); //请不要修改或删除

				// valid = Consts.YES;
				//
			} else {// 验证失败
				out.println("fail");
				valid = HttpConsts.NO;
				logger.error("支付宝数据验证失败!!" + "out_trade_no:" + out_trade_no + "==trade_no:" + trade_no
						+ "==trade_status:" + trade_status);
			}
			systemHandlerService.payResultHandle(out_trade_no, valid, "", trade_no, 2);
		} catch (Exception ex) {
			System.out.println("notify exception:" + ex.getMessage());
			ex.printStackTrace();
		} finally {

		}
		return null;

	}

	/**
	 * 
	 * @Title: memberQueryBack
	 * @Description: 淘宝会员信息回调
	 * @param: @param
	 *             request
	 * @param: @param
	 *             response
	 * @param: @return
	 * @return: String
	 * @throws @date:
	 *             2019年3月15日 下午6:27:46
	 * @author: linjinjing
	 */
	@RequestMapping("v1/memberqueryback")
	public void memberQueryBack(HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			// 获取淘宝POST过来反馈信息
			String body = IOUtils.toString(request.getInputStream(), "utf-8");
			this.logger.info("memberqueryback--》body*************************:" + body);
			JSONObject jsonObject = (JSONObject) JSON.parse(body);
			if (jsonObject != null) {
				// 卖家昵称
				String sellerName = jsonObject.getString("seller_name");
				// 会员手机号
				String mobile = jsonObject.getString("mobile");
				// 会员昵称
				String taobaoNick = jsonObject.getString("taobao_nick");
				// 针对appkey维度的买家信息加密值,同一个买家,不同appkey,则open_id不同(目前该字段定向开放,只有少部分商家使用)
				String openId = jsonObject.getString("open_id");
				// 针对品牌维度的买家信息加密值,同一个买家,同一个卖家,union_id是相同的(目前该字段定向开放,只有少部分商家使用)
				String unionid = jsonObject.getString("union_id");

				JSONObject newJSONObject = new JSONObject();

				UserOuteruserInfo userOuteruserInfo = this.iUserOuteruserInfoService
						.selectOne(new EntityWrapper<UserOuteruserInfo>().eq("mobile", mobile));
				if (userOuteruserInfo != null) {
					newJSONObject.put("query_code", "SUC");
				} else {
					newJSONObject.put("query_code", "E01");
				}

				JSONObject memberJSONObject = new JSONObject();
				memberJSONObject.put("point", 0);
				memberJSONObject.put("level", 1);
				memberJSONObject.put("mobile", mobile);
				memberJSONObject.put("nick", taobaoNick);
				memberJSONObject.put("extend", "{}");
				newJSONObject.put("member", memberJSONObject);
				out.print(JSON.toJSONString(newJSONObject));
			}
		} catch (Exception ex) {
			System.out.println("memberqueryback exception:" + ex.getMessage());
			ex.printStackTrace();
		} finally {

		}
	}

	/**
	 * 
	 * @Title: memberQueryBack
	 * @Description: 淘宝会员注册回调
	 * @param: @param
	 *             request
	 * @param: @param
	 *             response
	 * @param: @return
	 * @return: String
	 * @throws @date:
	 *             2019年3月15日 下午6:27:46
	 * @author: linjinjing
	 */
	@RequestMapping("v1/memberbind")
	public void memberBind(HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			// 获取淘宝POST过来反馈信息
			String body = IOUtils.toString(request.getInputStream(), "utf-8");
			this.logger.info("memberbind--》body*************************:" + body);
			JSONObject jsonObject = (JSONObject) JSON.parse(body);
			if (jsonObject != null) {
				// 卖家昵称
				String sellerName = jsonObject.getString("seller_name");
				// 会员手机号
				String mobile = jsonObject.getString("mobile");
				// 会员昵称
				String taobaoNick = jsonObject.getString("taobao_nick");
				// 针对appkey维度的买家信息加密值,同一个买家,不同appkey,则open_id不同(目前该字段定向开放,只有少部分商家使用)
				String openId = jsonObject.getString("open_id");
				// 针对品牌维度的买家信息加密值,同一个买家,同一个卖家,union_id是相同的(目前该字段定向开放,只有少部分商家使用)
				String unionid = jsonObject.getString("union_id");
				String extend = jsonObject.getString("extend");
				Integer type = jsonObject.getInteger("type");
				if (type != null && type == 1) {
					if (StringUtils.isNotBlank(extend)) {
						JSONObject extendJsonObject = JSONObject.parseObject(extend);
						this.logger.info("memberbind--》extendJsonObject*************************:" + extendJsonObject);
						String city = extendJsonObject.getString("city");
						Integer sex = extendJsonObject.getInteger("sex");

						String email = extendJsonObject.getString("email");
						String storeId = extendJsonObject.getString("storeId");
						// 入会渠道
						String sourceCode = extendJsonObject.getString("source");
						String salerId = extendJsonObject.getString("salerId");
						String realName = extendJsonObject.getString("name");
						String birthday = extendJsonObject.getString("birthday");
						String birthDate = extendJsonObject.getString("birthDate");
						String babyBirthday = extendJsonObject.getString("babyBirthday");
						String province = extendJsonObject.getString("province");
						String employeeNo = extendJsonObject.getString("employeeNo");
						String employeeId = extendJsonObject.getString("employeeId");
						employeeId = StringUtils.isEmpty(employeeId) ? extendJsonObject.getString("employeeid")
								: employeeId;
						String flightMode = extendJsonObject.getString("flightMode");
						Date flightJoinTime = extendJsonObject.getDate("flightJoinTime");

						UserOuteruserInfo userOuteruserInfo = this.iUserOuteruserInfoService
								.selectOne(new EntityWrapper<UserOuteruserInfo>().eq("mobile", mobile));
						if (userOuteruserInfo != null) {
							userOuteruserInfo.setModified(new Date());
							userOuteruserInfo.setName(taobaoNick);
							userOuteruserInfo.setEmployeeId(employeeId);
							userOuteruserInfo.setSellerName(sellerName);
							userOuteruserInfo.setMobile(mobile);
							userOuteruserInfo.setRegion(city);
							userOuteruserInfo.setSource(0);
							userOuteruserInfo.setSourceCode(sourceCode);
							userOuteruserInfo.setSalerId(salerId);
							userOuteruserInfo.setRealName(realName);
							userOuteruserInfo.setBirthday(birthday);
							userOuteruserInfo.setBirthDate(birthDate);
							userOuteruserInfo.setBabyBirthDay(babyBirthday);
							userOuteruserInfo.setEmployeeNo(employeeNo);
							userOuteruserInfo.setFlightMode(flightMode);
							ShopInfo shopInfo = this.iShopInfoService
									.selectOne(new EntityWrapper<ShopInfo>().eq("is_deleted", HttpConsts.NO)
											.eq("is_enable", HttpConsts.YES).eq("store_id", storeId));
							if (shopInfo != null) {
								userOuteruserInfo.setShopId(shopInfo.getId());
								userOuteruserInfo.setEscOrgId(shopInfo.getEscOrgId());
								userOuteruserInfo.setStatus(HttpConsts.YES);
							}
							if (flightJoinTime != null) {
								userOuteruserInfo.setFlightJoinTime(flightJoinTime);
							}
							userOuteruserInfo.setProvince(province);
							userOuteruserInfo.setEmail(email);
							userOuteruserInfo.setStoreId(storeId);
							if (sex != null) {
								if (sex == 1) {
									userOuteruserInfo.setSex(0 + "");
								} else if (sex == 2) {
									userOuteruserInfo.setSex(1 + "");
								}
							} else {
								userOuteruserInfo.setSex(2 + "");
							}
							this.iUserOuteruserInfoService.updateById(userOuteruserInfo);

						}

						UserBaseInfo userBaseInfo = this.iUserBaseInfoService
								.selectOne(new EntityWrapper<UserBaseInfo>().eq("is_deleted", CommonConstant.NO)
										.eq("is_enable", CommonConstant.YES).eq("mobile", mobile));
						if (userBaseInfo != null) {
							userBaseInfo.setModified(new Date());
							userBaseInfo.setIsTmallUser(1);
							this.iUserBaseInfoService.updateById(userBaseInfo);
						}
					}
				}
				JSONObject newJSONObject = new JSONObject();
				newJSONObject.put("bind_code", "SUC");
				JSONObject memberJSONObject = new JSONObject();
				memberJSONObject.put("point", 0);
				memberJSONObject.put("level", 1);
				memberJSONObject.put("mobile", mobile);
				memberJSONObject.put("nick", taobaoNick);
				memberJSONObject.put("extend", "{}");
				newJSONObject.put("member", memberJSONObject);
				out.print(JSON.toJSONString(newJSONObject));
			}
		} catch (Exception ex) {
			System.out.println("memberbind exception:" + ex.getMessage());
			ex.printStackTrace();
		} finally {

		}
	}

	/**
	 * 
	 * @Title: memberQueryBack
	 * @Description: 淘宝会员注册回调
	 * @param: @param
	 *             request
	 * @param: @param
	 *             response
	 * @param: @return
	 * @return: String
	 * @throws @date:
	 *             2019年3月15日 下午6:27:46
	 * @author: linjinjing
	 */
	@RequestMapping("v1/memberregister")
	public void memberRegister(HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			// 获取淘宝POST过来反馈信息
			String body = IOUtils.toString(request.getInputStream(), "utf-8");
			this.logger.info("memberregister--》body*************************:" + body);
			JSONObject jsonObject = (JSONObject) JSON.parse(body);
			if (jsonObject != null) {
				// 卖家昵称
				String sellerName = jsonObject.getString("seller_name");
				// 会员手机号
				String mobile = jsonObject.getString("mobile");
				// 会员昵称
				String taobaoNick = jsonObject.getString("taobao_nick");
				// 针对appkey维度的买家信息加密值,同一个买家,不同appkey,则open_id不同(目前该字段定向开放,只有少部分商家使用)
				String openId = jsonObject.getString("open_id");
				// 针对品牌维度的买家信息加密值,同一个买家,同一个卖家,union_id是相同的(目前该字段定向开放,只有少部分商家使用)
				String unionid = jsonObject.getString("union_id");
				String extend = jsonObject.getString("extend");

				if (StringUtils.isNotBlank(extend)) {
					JSONObject extendJsonObject = JSONObject.parseObject(extend);
					this.logger.info("memberregister--》extendJsonObject*************************:" + extendJsonObject);
					String city = extendJsonObject.getString("city");
					Integer sex = extendJsonObject.getInteger("sex");

					String email = extendJsonObject.getString("email");
					String storeId = extendJsonObject.getString("storeId");
					// 入会渠道
					String sourceCode = extendJsonObject.getString("source");
					String salerId = extendJsonObject.getString("salerId");
					String realName = extendJsonObject.getString("name");
					String birthday = extendJsonObject.getString("birthday");
					String birthDate = extendJsonObject.getString("birthDate");
					String babyBirthday = extendJsonObject.getString("babyBirthday");
					String province = extendJsonObject.getString("province");
					String employeeNo = extendJsonObject.getString("employeeNo");
					String employeeId = extendJsonObject.getString("employeeId");
					employeeId = StringUtils.isEmpty(employeeId) ? extendJsonObject.getString("employeeid")
							: employeeId;
					String flightMode = extendJsonObject.getString("flightMode");
					Date flightJoinTime = extendJsonObject.getDate("flightJoinTime");

					UserOuteruserInfo userOuteruserInfo = new UserOuteruserInfo();
					userOuteruserInfo.setCreated(new Date());
					userOuteruserInfo.setModified(new Date());
					userOuteruserInfo.setIsDeleted(CommonConstant.NO);
					userOuteruserInfo.setIsEnable(CommonConstant.YES);
					userOuteruserInfo.setMobile(mobile);
					userOuteruserInfo.setRegion(city);
					userOuteruserInfo.setSource(0);
					userOuteruserInfo.setName(taobaoNick);
					ShopInfo shopInfo = this.iShopInfoService.selectOne(new EntityWrapper<ShopInfo>()
							.eq("is_deleted", HttpConsts.NO).eq("is_enable", HttpConsts.YES).eq("store_id", storeId));
					if (shopInfo != null) {
						userOuteruserInfo.setShopId(shopInfo.getId());
						userOuteruserInfo.setEscOrgId(shopInfo.getEscOrgId());
						userOuteruserInfo.setStatus(HttpConsts.YES);
					}
					userOuteruserInfo.setIsFollowup(0);
					userOuteruserInfo.setSellerName(sellerName);
					userOuteruserInfo.setSourceCode(sourceCode);
					userOuteruserInfo.setSalerId(salerId);
					userOuteruserInfo.setRealName(realName);
					userOuteruserInfo.setBirthday(birthday);
					userOuteruserInfo.setBirthDate(birthDate);
					userOuteruserInfo.setBabyBirthDay(babyBirthday);
					userOuteruserInfo.setEmployeeNo(employeeNo);
					userOuteruserInfo.setEmployeeId(employeeId);
					userOuteruserInfo.setFlightMode(flightMode);
					if (flightJoinTime != null) {
						userOuteruserInfo.setFlightJoinTime(flightJoinTime);
					}
					userOuteruserInfo.setProvince(province);
					userOuteruserInfo.setEmail(email);
					userOuteruserInfo.setStoreId(storeId);
					if (sex != null) {
						if (sex == 1) {
							userOuteruserInfo.setSex(0 + "");
						} else if (sex == 2) {
							userOuteruserInfo.setSex(1 + "");
						}
					} else {
						userOuteruserInfo.setSex(2 + "");
					}
					this.iUserOuteruserInfoService.insert(userOuteruserInfo);

					UserBaseInfo userBaseInfo = this.iUserBaseInfoService
							.selectOne(new EntityWrapper<UserBaseInfo>().eq("is_deleted", CommonConstant.NO)
									.eq("is_enable", CommonConstant.YES).eq("mobile", mobile));
					if (userBaseInfo != null) {
						userBaseInfo.setModified(new Date());
						userBaseInfo.setIsTmallUser(1);
						this.iUserBaseInfoService.updateById(userBaseInfo);
					}

				}

				JSONObject newJSONObject = new JSONObject();
				newJSONObject.put("register_code", "SUC");
				JSONObject memberJSONObject = new JSONObject();
				memberJSONObject.put("point", 0);
				memberJSONObject.put("level", 1);
				memberJSONObject.put("mobile", mobile);
				memberJSONObject.put("nick", taobaoNick);
				memberJSONObject.put("extend", "{}");
				newJSONObject.put("member", memberJSONObject);
				out.print(JSON.toJSONString(newJSONObject));
			}
		} catch (Exception ex) {
			System.out.println("memberregister exception:" + ex.getMessage());
			ex.printStackTrace();
		} finally {

		}

	}

	/**
	 * 
	 * @Title: memberQueryBack
	 * @Description: 淘宝会员绑定查询
	 * @param: @param
	 *             request
	 * @param: @param
	 *             response
	 * @param: @return
	 * @return: String
	 * @throws @date:
	 *             2019年3月15日 下午6:27:46
	 * @author: linjinjing
	 */
	@RequestMapping("v1/memberbindquery")
	public void memberBindQuery(HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			// 获取淘宝POST过来反馈信息
			String body = IOUtils.toString(request.getInputStream(), "utf-8");
			this.logger.info("memberbindquery--》body*************************:" + body);
			JSONObject jsonObject = (JSONObject) JSON.parse(body);
			if (jsonObject != null) {
				// 卖家昵称
				String sellerName = jsonObject.getString("seller_name");
				// 会员手机号
				String mobile = jsonObject.getString("mobile");
				// 会员昵称
				String nick = jsonObject.getString("nick");
				// 针对appkey维度的买家信息加密值,同一个买家,不同appkey,则open_id不同(目前该字段定向开放,只有少部分商家使用)
				String openId = jsonObject.getString("open_id");
				// 针对品牌维度的买家信息加密值,同一个买家,同一个卖家,union_id是相同的(目前该字段定向开放,只有少部分商家使用)
				String unionid = jsonObject.getString("union_id");
				String extend = jsonObject.getString("extend");
				if (StringUtils.isNotBlank(extend)) {
					JSONObject extendJsonObject = JSONObject.parseObject(extend);
					this.logger.info("memberbindquery--》extendJsonObject*************************:" + extendJsonObject);
				}
				JSONObject newJSONObject = new JSONObject();
				// 根据手机号去查表 看看能否绑定或者注册
				UserOuteruserInfo userOuteruserInfo = this.iUserOuteruserInfoService
						.selectOne(new EntityWrapper<UserOuteruserInfo>().eq("mobile", mobile));
				if (userOuteruserInfo != null) {
					// 绑定逻辑
					newJSONObject.put("bindable", true);
					newJSONObject.put("bind_code", "SUC");
				} else {
					// 注册逻辑
					newJSONObject.put("bindable", false);
					newJSONObject.put("bind_code", "E04");
				}
				newJSONObject.put("mobile", mobile);
				newJSONObject.put("nick", nick);
				JSONObject memberJSONObject = new JSONObject();
				memberJSONObject.put("point", 0);
				memberJSONObject.put("level", 1);
				memberJSONObject.put("mobile", mobile);
				memberJSONObject.put("nick", nick);
				memberJSONObject.put("extend", "{}");
				newJSONObject.put("member", memberJSONObject);
				out.print(JSON.toJSONString(newJSONObject));

			}

		} catch (Exception ex) {
			System.out.println("memberbindquery exception:" + ex.getMessage());
			ex.printStackTrace();
		} finally {

		}

	}

	@RequestMapping("v1/wechatnotify")
	public String weChatNotify(HttpServletRequest request, HttpServletResponse response) {
		return weChatHandler(request, response, 1);
	}

	@RequestMapping("v1/wechatnotifyback")
	public String weChatNotifyBack(HttpServletRequest request, HttpServletResponse response) {
		return weChatHandler(request, response, 1);
	}

	@RequestMapping("v1/minprogramnotify")
	public String minProgramNotify(HttpServletRequest request, HttpServletResponse response) {
		return weChatHandler(request, response, 3);
	}

	@RequestMapping("v1/minprogramnotifyback")
	public String minProgramNotifyBack(HttpServletRequest request, HttpServletResponse response) {
		return weChatHandler(request, response, 3);
	}

	public String weChatHandler(HttpServletRequest request, HttpServletResponse response, int payType) {
		// 创建支付应答对象
		ResponseHandler resHandler = new ResponseHandler(request, response);
		resHandler.setKey(WXConfig.PARTNERKEY);
		try {
			// post 过来的xml
			// WechatPostBean postData = null;
			Map<String, String> postData = null;
			try {
				ServletInputStream in = request.getInputStream();
				// 转换微信post过来的xml内容
				// XStream xs = new XStream(new DomDriver());
				// xs.alias("xml", WechatPostBean.class);
				// String xmlMsg = Tools.inputStream2String(in);
				// postData = (WechatPostBean) xs.fromXML(xmlMsg);
				postData = WXPayUtil.xmlToMap(Tools.inputStream2String(in));
			} catch (IOException e) {
				e.printStackTrace();
				return "fail";
			}
			// ---------------------------------------------------------
			// 财付通支付通知(后台通知)示例,商户按照此文档进行开发即可
			// ---------------------------------------------------------
			// String json = JSON.toJSONString(postData);
			// Map<String, String> paramsMap = JSON.parseObject(json, Map.class);
			System.out.println("*********wx:paramsMap***************");
			System.out.println(postData.toString());

			int valid = HttpConsts.NO;
			// 判断签名
			if (resHandler.isTenpaySignEx(postData)) {
				String out_trade_no = postData.get("out_trade_no");
				String openid = postData.get("openid");
				String wxorderno = postData.get("transaction_id");

				if (StringUtils.isEmpty(out_trade_no) == true) {
					System.out.println("业务订单号为空。");
					// resHandler.sendToCFT("Fail");
					return "fail";
				}
				if (postData.get("result_code").toUpperCase().equals("SUCCESS") == true) {
					valid = HttpConsts.YES;
				}
				systemHandlerService.payResultHandle(out_trade_no, valid, openid, wxorderno, payType);
				return "success";
			} else {
				System.out.println("通知签名验证失败");
				// resHandler.sendToCFT("Fail");
				return "fail";
			}

		} catch (Exception e) {
			logger.error("STATUC_FAIL:" + e.getMessage());
			return "fail";
		}
	}

	@RequestMapping("v1/wechatnotifyh5")
	public String weChatNotifyH5(HttpServletRequest request, HttpServletResponse response) {
		return weChatHandlerH5(request, response);
	}

	@RequestMapping("v1/wechatnotifybackh5")
	public String weChatNotifyBackH5(HttpServletRequest request, HttpServletResponse response) {
		return weChatHandlerH5(request, response);
	}

	public String weChatHandlerH5(HttpServletRequest request, HttpServletResponse response) {
		// 创建支付应答对象
		ResponseHandler resHandler = new ResponseHandler(request, response);
		resHandler.setKey(WXConfig.PARTNERKEY);
		try {
			// post 过来的xml
			// WechatPostBean postData = null;
			Map<String, String> postData = null;
			try {
				ServletInputStream in = request.getInputStream();
				// 转换微信post过来的xml内容
				// XStream xs = new XStream(new DomDriver());
				// xs.alias("xml", WechatPostBean.class);
				// String xmlMsg = Tools.inputStream2String(in);
				// postData = (WechatPostBean) xs.fromXML(xmlMsg);
				postData = WXPayUtil.xmlToMap(Tools.inputStream2String(in));
			} catch (IOException e) {
				e.printStackTrace();
				return "fail";
			}
			// ---------------------------------------------------------
			// 财付通支付通知(后台通知)示例,商户按照此文档进行开发即可
			// ---------------------------------------------------------
			// String json = JSON.toJSONString(postData);
			// Map<String, String> paramsMap = JSON.parseObject(json, Map.class);
			System.out.println("*********wx:paramsMapH5***************");
			System.out.println(postData.toString());

			int valid = HttpConsts.NO;
			// 判断签名
			if (resHandler.isTenpaySignEx(postData)) {
				String out_trade_no = postData.get("out_trade_no");
				String openid = postData.get("openid");
				String wxorderno = postData.get("transaction_id");

				if (StringUtils.isEmpty(out_trade_no) == true) {
					System.out.println("业务订单号为空。");
					// resHandler.sendToCFT("Fail");
					return "fail";
				}
				if (postData.get("result_code").toUpperCase().equals("SUCCESS") == true) {
					valid = HttpConsts.YES;
				}
				systemHandlerServiceH5.payResultHandle(out_trade_no, valid, openid, wxorderno);
				return "success";
			} else {
				System.out.println("通知签名验证失败");
				// resHandler.sendToCFT("Fail");
				return "fail";
			}

		} catch (Exception e) {
			logger.error("STATUC_FAIL:" + e.getMessage());
			return "fail";
		}
	}

}

package com.awj.mall.restfulapi.modular.user.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.awj.mall.core.constant.CommonConstant;
import com.awj.mall.modular.goods.service.IGoodsLibService;
import com.awj.mall.modular.sys.model.SysUser;
import com.awj.mall.modular.sys.service.ISysSerialNumGenService;
import com.awj.mall.modular.sys.service.ISysUserService;
import com.awj.mall.modular.user.model.UserBaseInfo;
import com.awj.mall.modular.user.model.UserDispatchMakeInfo;
import com.awj.mall.modular.user.model.UserFirstpartyInfo;
import com.awj.mall.modular.user.model.UserServiceWorkOrderBill;
import com.awj.mall.modular.user.model.UserServiceWorkOrderGoods;
import com.awj.mall.modular.user.model.UserServiceWorkOrderInfo;
import com.awj.mall.modular.user.model.UserServiceWorkOrderLog;
import com.awj.mall.modular.user.service.IUserBaseInfoService;
import com.awj.mall.modular.user.service.IUserDevService;
import com.awj.mall.modular.user.service.IUserDispatchLogService;
import com.awj.mall.modular.user.service.IUserDispatchMakeInfoService;
import com.awj.mall.modular.user.service.IUserExceptionMoneyApplyService;
import com.awj.mall.modular.user.service.IUserExceptionMoneyService;
import com.awj.mall.modular.user.service.IUserFirstpartyInfoService;
import com.awj.mall.modular.user.service.IUserInnerInvitationLogService;
import com.awj.mall.modular.user.service.IUserServiceAreaService;
import com.awj.mall.modular.user.service.IUserServiceWorkOrderBillService;
import com.awj.mall.modular.user.service.IUserServiceWorkOrderGoodsService;
import com.awj.mall.modular.user.service.IUserServiceWorkOrderInfoService;
import com.awj.mall.modular.user.service.IUserServiceWorkOrderLogService;
import com.awj.mall.modular.user.service.IUserServiceWorkOrderRelService;
import com.awj.mall.modular.work.model.WorkOrderInvoiceInfo;
import com.awj.mall.modular.work.service.IWorkOrderInvoiceInfoService;
import com.awj.mall.restfulapi.common.consts.CacheConsts;
import com.awj.mall.restfulapi.common.consts.HttpConsts;
import com.awj.mall.restfulapi.common.consts.UserConsts;
import com.awj.mall.restfulapi.common.plugins.lm.model.Bom;
import com.awj.mall.restfulapi.common.plugins.lm.model.BomType;
import com.awj.mall.restfulapi.common.plugins.lm.model.Fault;
import com.awj.mall.restfulapi.common.plugins.lm.model.FaultTree;
import com.awj.mall.restfulapi.common.plugins.lm.model.MethodTree;
import com.awj.mall.restfulapi.common.plugins.lm.utils.LmDataUtil;
import com.awj.mall.restfulapi.common.swagger.annotion.ApiVersion;
import com.awj.mall.restfulapi.common.swagger.consts.ApiVersionConsts;
import com.awj.mall.restfulapi.common.task.AliSmsSendTask;
import com.awj.mall.restfulapi.common.task.InsertWorkOrderLogTask;
import com.awj.mall.restfulapi.common.util.BeanUtil;
import com.awj.mall.restfulapi.common.util.CheckUtil;
import com.awj.mall.restfulapi.common.util.RedisUtil;
import com.awj.mall.restfulapi.common.util.ReflectUtil;
import com.awj.mall.restfulapi.modular.base.bean.RequestApiParam;
import com.awj.mall.restfulapi.modular.base.controller.BaseController;
import com.awj.mall.restfulapi.modular.base.result.ResultCode;
import com.awj.mall.restfulapi.modular.base.result.ResultEntity;
import com.awj.mall.restfulapi.modular.user.consts.SmsConsts;
import com.awj.mall.restfulapi.modular.user.consts.WorkOrderConst;
import com.awj.mall.restfulapi.modular.user.consts.WorkOrderLogConst;
import com.awj.mall.restfulapi.modular.user.dto.AppointTimeAuthCodeDTO;
import com.awj.mall.restfulapi.modular.user.dto.AuthCodeDTO;
import com.awj.mall.restfulapi.modular.user.dto.CancelWorkOrderDTO;
import com.awj.mall.restfulapi.modular.user.dto.GetMethodTreeDTO;
import com.awj.mall.restfulapi.modular.user.dto.GetavailableMaterialsDTO;
import com.awj.mall.restfulapi.modular.user.dto.HxWorkOrderDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmAcceptWorkOrderDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmAssignDoDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmCancelWorkOrderDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmDepartRedepartDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmGetFaultTreeDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmHxWorkOrderDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmMakeUserSignedDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmMobileDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmProviderfeedBackDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmSaveGoodsJsonDTO;
import com.awj.mall.restfulapi.modular.user.dto.LmUserWorkOrderGoodsDTO;
import com.awj.mall.restfulapi.modular.user.dto.MakeUserSignedDTO;
import com.awj.mall.restfulapi.modular.user.dto.UpdateCloseApplyDTO;
import com.awj.mall.restfulapi.modular.user.dto.UserDispatchMakeInfoDTO;
import com.awj.mall.restfulapi.modular.user.dto.UserServiceWorkOrderInfoDTO;
import com.awj.mall.restfulapi.modular.user.enums.LmServiceTypeEnum;
import com.awj.mall.restfulapi.modular.user.exception.LmException;
import com.awj.mall.restfulapi.modular.user.util.UserUtil;
import com.awj.mall.restfulapi.modular.user.util.UserWorkOrderLogUtil;
import com.awj.mall.restfulapi.modular.user.vo.ReverDateVO;
import com.awj.mall.restfulapi.modular.user.vo.UserDispatchMakeInfoVO;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.google.common.collect.Lists;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jodd.util.StringUtil;

@RestController
@RequestMapping(value = "api/user/lmUserworkorder")
@Api(value = "LmUserWorkOrderController", tags = { "绿米工单管理接口" })
public class LmUserWorkOrderController extends BaseController {

	@Resource(name = "userBaseInfoServiceImpl")
	private IUserBaseInfoService iUserBaseInfoService;

	@Resource
	private IUserServiceAreaService iUserServiceAreaService;

	@Resource
	private ISysSerialNumGenService iSysSerialNumGenService;

	@Resource
	private AliSmsSendTask aliSmsSendTask;

	@Resource
	private IUserServiceWorkOrderInfoService iUserServiceWorkOrderInfoService;

	@Resource
	private IUserServiceWorkOrderGoodsService iUserServiceWorkOrderGoodsService;

	@Resource
	private IUserDispatchMakeInfoService iUserDispatchMakeInfoService;

	@Resource
	private InsertWorkOrderLogTask insertWorkOrderLogTask;

	@Resource
	private IUserDispatchLogService iUserDispatchLogService;

	@Autowired
	private IUserDevService userDevService;

	@Autowired
	private IUserFirstpartyInfoService iUserFirstpartyInfoService;

	@Autowired
	private IGoodsLibService iGoodsLibService;

	@Autowired
	private IUserServiceWorkOrderRelService iUserServiceWorkOrderRelService;

	@Autowired
	private IUserInnerInvitationLogService iUserInnerInvitationLogService;

	@Autowired
	private IWorkOrderInvoiceInfoService iworkOrderInvoiceInfoService;

	@Autowired
	private ISysUserService iSysUserService;

	@Autowired
	private IUserExceptionMoneyService iUserExceptionMoneyService;

	@Autowired
	private IUserExceptionMoneyApplyService iUserExceptionMoneyApplyService;

	@Autowired
	private IUserServiceWorkOrderBillService iUserServiceWorkOrderBillService;

	@Autowired
	private IUserServiceWorkOrderLogService iUserServiceWorkOrderLogService;

	private static Log log = LogFactory.getLog(UserServiceController.class);

	/**
	 * 获取故障分类
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/getfaulttree", method = RequestMethod.POST)
	@ApiOperation(value = "获取故障分类||二期一阶段", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<List<FaultTree>> getFaultTree(@RequestBody RequestApiParam<LmGetFaultTreeDTO> requestApiParam) {
		LmGetFaultTreeDTO dto = requestApiParam.getT();
		JSONObject jsonObject = LmDataUtil.getFaultTree(dto.getGoodsId(),
				LmServiceTypeEnum.getName(dto.getServiceType()));
		if (jsonObject == null) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		if (jsonObject.getInteger("code") != 0) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("faultTree");
		if (jsonArray == null || jsonArray.isEmpty()) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		List<FaultTree> faultTreeList = Lists.newLinkedList();
		FaultTree faultTree = null;
		Fault fault = null;
		for (int i = 0; i < jsonArray.size(); i++) {
			JSONObject faultTreeObject = jsonArray.getJSONObject(i);
			faultTree = new FaultTree();
			faultTree.setFaultTypeId(faultTreeObject.getInteger("faultTypeId"));
			faultTree.setFaultTypeName(faultTreeObject.getString("faultName"));
			JSONArray faultArray = faultTreeObject.getJSONArray("faultList");
			List<Fault> faultList = Lists.newLinkedList();
			if (faultArray == null || faultArray.isEmpty()) {
				faultTree.setFaultList(Lists.newArrayList());
			} else {
				for (int j = 0; j < faultArray.size(); j++) {
					fault = new Fault();
					JSONObject faultObject = faultArray.getJSONObject(i);
					fault.setFaultCode(faultObject.getString("faultCode"));
					fault.setFaultName(faultObject.getString("faultName"));
					faultList.add(fault);
				}
				faultTree.setFaultList(faultList);
			}
			faultTreeList.add(faultTree);
		}
		return success(faultTreeList);
	}

	/**
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/getmethodtree", method = RequestMethod.POST)
	@ApiOperation(value = "获取处理方法||二期一阶段", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<List<MethodTree>> getMethodTree(
			@RequestBody RequestApiParam<GetMethodTreeDTO> requestApiParam) {
		GetMethodTreeDTO dto = requestApiParam.getT();
		JSONObject jsonObject = LmDataUtil.getMethodTree(dto.getGoodsId(),
				LmServiceTypeEnum.getName(dto.getServiceType()));
		if (jsonObject == null) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		if (jsonObject.getInteger("code") != 0) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("methodTree");
		if (jsonArray == null || jsonArray.isEmpty()) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		List<MethodTree> methodTreeList = Lists.newLinkedList();
		MethodTree methodTree = null;
		for (int i = 0; i < jsonArray.size(); i++) {
			JSONObject methodTreeObject = jsonArray.getJSONObject(i);
			methodTree = new MethodTree();
			methodTree.setCoexist(methodTreeObject.getInteger("coexist"));
			methodTree.setMethodCode(methodTreeObject.getString("methodCode"));
			methodTree.setMethodName(methodTreeObject.getString("methodName"));
			methodTree.setUseMaterial(methodTreeObject.getInteger("useMaterial"));
			methodTreeList.add(methodTree);
		}
		return success(methodTreeList);
	}

	/**
	 * 获取用料
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/getavailablematerials", method = RequestMethod.POST)
	@ApiOperation(value = "获取用料||二期一阶段", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<List<BomType>> getAvailableMaterials(
			@RequestBody RequestApiParam<GetavailableMaterialsDTO> requestApiParam) {
		GetavailableMaterialsDTO dto = requestApiParam.getT();
		String faultIds = dto.getFaultIds();
		List<String> faultIdList = null;
		try {
			faultIdList = JSON.parseArray(faultIds, String.class);
		} catch (Exception e) {
			return error(ResultCode.PARAM_DECODE_ERROR);
		}
		if (faultIdList == null || faultIdList.isEmpty()) {
			return error(ResultCode.PARAM_CHECK_ERROR);
		}
		String methodIds = dto.getMethodIds();
		List<String> methodIdList = null;
		try {
			methodIdList = JSON.parseArray(methodIds, String.class);
		} catch (Exception e) {
			return error(ResultCode.PARAM_DECODE_ERROR);
		}
		if (methodIdList == null || methodIdList.isEmpty()) {
			return error(ResultCode.PARAM_CHECK_ERROR);
		}
		JSONObject jsonObject = LmDataUtil.getAvailableMaterials(dto.getGoodsId(),
				LmServiceTypeEnum.getName(dto.getServiceType()), faultIdList, methodIdList);
		if (jsonObject == null) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		if (jsonObject.getInteger("code") != 0) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("materials");
		if (jsonArray == null || jsonArray.isEmpty()) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		List<BomType> bomTypeList = Lists.newLinkedList();
		BomType bomType = null;
		Bom bom = null;
		for (int i = 0; i < jsonArray.size(); i++) {
			JSONObject bomTypeObject = jsonArray.getJSONObject(i);
			bomType = new BomType();
			bomType.setBomTypeId(bomTypeObject.getInteger("bomTypeId"));
			bomType.setBomTypeName(bomTypeObject.getString("bomTypeName"));
			bomType.setRequireState(bomTypeObject.getInteger("requireState"));
			bomType.setMultiState(bomTypeObject.getInteger("multiState"));
			JSONArray bomArray = bomTypeObject.getJSONArray("bomList");
			List<Bom> bomList = Lists.newLinkedList();
			if (bomArray == null || bomArray.isEmpty()) {
				bomType.setBomList(Lists.newArrayList());
			} else {
				for (int j = 0; j < bomArray.size(); j++) {
					bom = new Bom();
					JSONObject bomObject = bomArray.getJSONObject(i);
					bom.setBomCode(bomObject.getString("bomCode"));
					bom.setBomName(bomObject.getString("bomName"));
					bom.setSnState(bomObject.getInteger("snState"));
					bomList.add(bom);
				}
				bomType.setBomList(bomList);
			}
			bomTypeList.add(bomType);
		}
		return success(bomTypeList);
	}

	/**
	 * 发送核销码
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/authcode", method = RequestMethod.POST)
	@ApiOperation(value = "发送核销码||二期一阶段", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> authCode(@RequestBody RequestApiParam<AuthCodeDTO> requestApiParam) {
		AuthCodeDTO dto = requestApiParam.getT();
		JSONObject jsonObject = LmDataUtil.authCode(dto.getLmWorkOrderNo());
		if (jsonObject == null) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		if (jsonObject.getInteger("code") != 0) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		return success();
	}

	/**
	 * 发送改约码
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/appointtimeauthcode", method = RequestMethod.POST)
	@ApiOperation(value = "发送改约码||二期一阶段", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> appointTimeAuthCode(@RequestBody RequestApiParam<AppointTimeAuthCodeDTO> requestApiParam) {
		AppointTimeAuthCodeDTO dto = requestApiParam.getT();
		String appointTime = dto.getReservationDate() + " " + UserUtil.getReservationTime(dto.getReservationTime());
		JSONObject jsonObject = LmDataUtil.appointTimeAuthCode(dto.getLmWorkOrderNo(), appointTime);
		if (jsonObject == null) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		if (jsonObject.getInteger("code") != 0) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		return success();
	}

	/**
	 * 发送取消码
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/updatecloseapply", method = RequestMethod.POST)
	@ApiOperation(value = "发送取消码||二期一阶段", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> update_closeApply(@RequestBody RequestApiParam<UpdateCloseApplyDTO> requestApiParam) {
		this.assertUidNotNull(requestApiParam);
		UpdateCloseApplyDTO dto = requestApiParam.getT();
		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		JSONObject jsonObject = LmDataUtil.update_closeApply(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				userBaseInfo.getName(), userBaseInfo.getMobile(),
				LmServiceTypeEnum.getName(userServiceWorkOrderInfo.getLmWorkOrderType()), dto.getCancelReasonId(),
				dto.getRemark());
		if (jsonObject == null) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		if (jsonObject.getInteger("code") != 0) {
			return error(ResultCode.LM_MSG_GET_FAIL);
		}
		return success();
	}

	/**
	 * 派单给安装师傅
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmassigndo", method = RequestMethod.POST)
	@ApiOperation(value = "派单给安装师傅||二期", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> makeUserOrderTaking(@RequestBody RequestApiParam<LmAssignDoDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmAssignDoDTO dto = requestApiParam.getT();
		// 原子性操作
		if (RedisUtil.get(CacheConsts.CACHE_SERVICE_APPLY_REPEAT_COMMIT + requestApiParam.getUid()) != null) {
			return error(ResultCode.SYS_COMMIT_SECONE);
		} else {
			RedisUtil.set(CacheConsts.CACHE_SERVICE_APPLY_REPEAT_COMMIT + requestApiParam.getUid(),
					requestApiParam.getUid() + "", CacheConsts.CACHE_SERVICE_APPLY_REPEAT_COMMIT_EXPIRE_TIME);
		}
		UserBaseInfo makeUserBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				dto.getMakeUserId());

		if (makeUserBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserBaseInfo serviceUserBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (serviceUserBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(userServiceWorkOrderInfo.getLmIsClose())) {
			return error(ResultCode.LM_WORK_ORDER_CANCEL);
		}
		JSONObject jsonObject = LmDataUtil.receiveMessage("CANCEL", userServiceWorkOrderInfo.getLmWorkOrderNo(), "Y");
		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
			JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("messageList");
			if (jsonArray != null && !jsonArray.isEmpty()) {
				JSONObject contentObject = jsonArray.getJSONObject(0).getJSONObject("content");
				userServiceWorkOrderInfo.setLmCustomerCancelDate(UserUtil.setMiToDate(contentObject.getLong("opTime")));
				userServiceWorkOrderInfo.setLmCustomerCancelReason(
						UserUtil.getLmCustomerCancelReasonByCode(contentObject.getIntValue("cancelReasonId")));
				userServiceWorkOrderInfo.setLmCustomerCancelRemark(contentObject.getString("remark"));
				userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
				this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);
				return error(ResultCode.LM_WORK_ORDER_CANCEL);
			}
		}
		Date date = new Date();
		// String buyerPhone = userServiceWorkOrderInfo.getBuyerPhone();
		if (!WorkOrderConst.WORK_ORDER_STATUS_8.equals(userServiceWorkOrderInfo.getWorkOrderStatus())) {
			return error(ResultCode.USER_WORKORDER_ISAPPLICATION);
		}
		if (UserConsts.PLATFORM_SERVICE.equals(makeUserBaseInfo.getIdentity())
				|| UserConsts.THIRD_SERVICE.equals(makeUserBaseInfo.getIdentity())) {
			// 如果服务商的话 指派之后状态直接改为已接单
			userServiceWorkOrderInfo.setWorkOrderStatus(10);
		} else {
			userServiceWorkOrderInfo.setWorkOrderStatus(9);
		}
		userServiceWorkOrderInfo.setServiceUserName(serviceUserBaseInfo.getName());
		userServiceWorkOrderInfo.setServiceUserMobile(serviceUserBaseInfo.getMobile());
		userServiceWorkOrderInfo.setServiceUserId(serviceUserBaseInfo.getId());
		userServiceWorkOrderInfo.setMakeUserName(makeUserBaseInfo.getName());
		userServiceWorkOrderInfo.setMakeUserMobile(makeUserBaseInfo.getMobile());
		userServiceWorkOrderInfo.setMakeUserId(makeUserBaseInfo.getId());
		userServiceWorkOrderInfo.setApplyDate(date);
		userServiceWorkOrderInfo.setModified(date);
		userServiceWorkOrderInfo.setModifier(requestApiParam.getUid());
		userServiceWorkOrderInfo.setReservationDate(dto.getReservationDate());
		userServiceWorkOrderInfo.setReservationTime(dto.getReservationTime());
		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		// 插入安装师傅安装信息记录表
		UserDispatchMakeInfo userDispatchMakeInfo = new UserDispatchMakeInfo();
		BeanUtil.copyProperties(dto, userDispatchMakeInfo);
		try {
			this.setCreateInfo(userDispatchMakeInfo, UserDispatchMakeInfo.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		userDispatchMakeInfo.setReservationDate(dto.getReservationDate());
		userDispatchMakeInfo.setReservationTime(dto.getReservationTime());
		userDispatchMakeInfo.setReverDate(dto.getReverDate() + "");
		userDispatchMakeInfo.setStatus(0);
		userDispatchMakeInfo.setUserId(requestApiParam.getUid());
		userDispatchMakeInfo.setCreator(requestApiParam.getUid());
		userDispatchMakeInfo.setModifier(requestApiParam.getUid());
		this.iUserDispatchMakeInfoService.insert(userDispatchMakeInfo);

		// 插入日志
		UserWorkOrderLogUtil.insertWorkOrderLog_1(dto.getWorkOrderId(), requestApiParam.getUid(), dto.getMakeUserId(),
				dto.getRemark(), null, null);

		JSONObject result = LmDataUtil.update_assignDO(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				makeUserBaseInfo.getName(), makeUserBaseInfo.getMobile(),
				LmServiceTypeEnum.getName(userServiceWorkOrderInfo.getLmWorkOrderType()), dto.getRemark());
		if (result == null) {
			throw new LmException("同步绿米工单状态失败!");
		}
		if (result != null && result.getInteger("code") != 0) {
			throw new LmException("同步绿米工单状态失败!");
		}

		/**
		 * 新工单指派给师傅短信消息(安装师傅) ${name}师傅,服务商${servicename}有一笔新的工单指派给您,请登陆安万家APP查看。
		 * SMS_163851018
		 */
		try {
			this.aliSmsSendTask.sendSms(CommonConstant.SMS_CODE_4, makeUserBaseInfo.getMobile(), SmsConsts.TYPE_1,
					new String[] { makeUserBaseInfo.getName(), serviceUserBaseInfo.getName() });
		} catch (Exception e) {
			log.error("发送短信或者推送失败--> 新工单指派给师傅短信消息", e);
		}

		return success();
	}

	/**
	 * 安装师傅取消接单接口
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmcancelorreverworkorder", method = RequestMethod.POST)
	@ApiOperation(value = "安装师傅取消接单", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> lmCancelOrReverWorkOrder(
			@RequestBody RequestApiParam<LmCancelWorkOrderDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmCancelWorkOrderDTO dto = requestApiParam.getT();

		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(userServiceWorkOrderInfo.getLmIsClose())) {
			return error(ResultCode.LM_WORK_ORDER_CANCEL);
		}
		JSONObject jsonObject = LmDataUtil.receiveMessage("CANCEL", userServiceWorkOrderInfo.getLmWorkOrderNo(), "Y");
		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
			JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("messageList");
			if (jsonArray != null && !jsonArray.isEmpty()) {
				JSONObject contentObject = jsonArray.getJSONObject(0).getJSONObject("content");
				userServiceWorkOrderInfo.setLmCustomerCancelDate(UserUtil.setMiToDate(contentObject.getLong("opTime")));
				userServiceWorkOrderInfo.setLmCustomerCancelReason(
						UserUtil.getLmCustomerCancelReasonByCode(contentObject.getIntValue("cancelReasonId")));
				userServiceWorkOrderInfo.setLmCustomerCancelRemark(contentObject.getString("remark"));
				userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
				this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);
				return error(ResultCode.LM_WORK_ORDER_CANCEL);
			}
		}
		UserDispatchMakeInfo userDispatchMakeInfo = this.iUserDispatchMakeInfoService
				.getOkUserDispatchMakeInfo(dto.getDispatcherId());
		if (userDispatchMakeInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		userDispatchMakeInfo.setModified(new Date());
		userDispatchMakeInfo.setModifier(requestApiParam.getUid());
		userDispatchMakeInfo.setStatus(2);
		userServiceWorkOrderInfo.setModified(new Date());
		userServiceWorkOrderInfo.setModifier(requestApiParam.getUid());
		userServiceWorkOrderInfo.setLmMasterCancelDate(new Date());
		userServiceWorkOrderInfo.setLmMasterCancelReason(dto.getCancelReason());
		userServiceWorkOrderInfo.setLmMasterCancelRemark(dto.getRemark());
		userServiceWorkOrderInfo.setIsDelayed(HttpConsts.NO);
		userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
		userServiceWorkOrderInfo.setWorkOrderStatus(8);
		userServiceWorkOrderInfo.setIsSignDelayed(HttpConsts.NO);
		if (UserConsts.OTHER_SERVICE.equals(userBaseInfo.getIdentity())
				&& HttpConsts.YES.equals(userBaseInfo.getMasterType())) {
			userServiceWorkOrderInfo.setIsBack(WorkOrderConst.IS_BACK_5);
		}
		/**
		 * 插入服务工单操作日志
		 */
		UserWorkOrderLogUtil.insertWorkOrderLog_3_back(dto.getWorkOrderId(), userDispatchMakeInfo.getUserId(),
				userDispatchMakeInfo.getMakeUserId());

		this.iUserDispatchMakeInfoService.updateById(userDispatchMakeInfo);

		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		JSONObject result = LmDataUtil.update_cancel(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				userBaseInfo.getName(), userBaseInfo.getMobile(),
				LmServiceTypeEnum.getName(userServiceWorkOrderInfo.getLmWorkOrderType()), dto.getCancelReasonId(),
				dto.getCancelReason(), dto.getCloseVerifyCode());
		if (result == null) {
			throw new LmException("同步绿米工单状态失败!");
		}
		if (result != null && result.getInteger("code") != 0) {
			throw new LmException("同步绿米工单状态失败!");
		}
		return success();
	}

	/**
	 * 改约
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmdepartredepart", method = RequestMethod.POST)
	@ApiOperation(value = "改约", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> lmDepartRedepart(@RequestBody RequestApiParam<LmDepartRedepartDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmDepartRedepartDTO dto = requestApiParam.getT();
		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(userServiceWorkOrderInfo.getLmIsClose())) {
			return error(ResultCode.LM_WORK_ORDER_CANCEL);
		}
		JSONObject jsonObject = LmDataUtil.receiveMessage("CANCEL", userServiceWorkOrderInfo.getLmWorkOrderNo(), "Y");
		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
			JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("messageList");
			if (jsonArray != null && !jsonArray.isEmpty()) {
				JSONObject contentObject = jsonArray.getJSONObject(0).getJSONObject("content");
				userServiceWorkOrderInfo.setLmCustomerCancelDate(UserUtil.setMiToDate(contentObject.getLong("opTime")));
				userServiceWorkOrderInfo.setLmCustomerCancelReason(
						UserUtil.getLmCustomerCancelReasonByCode(contentObject.getIntValue("cancelReasonId")));
				userServiceWorkOrderInfo.setLmCustomerCancelRemark(contentObject.getString("remark"));
				userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
				this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);
				return error(ResultCode.LM_WORK_ORDER_CANCEL);
			}
		}
		UserDispatchMakeInfo userDispatchMakeInfo = this.iUserDispatchMakeInfoService
				.getOkUserDispatchMakeInfo(dto.getDispatcherId());
		if (userDispatchMakeInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		userServiceWorkOrderInfo.setLmModifyAppointmentReason(dto.getChangeAppointmentReason());
		userServiceWorkOrderInfo.setLmModifyAppointmentRemark(dto.getRemark());
		userServiceWorkOrderInfo.setReservationDate(dto.getReservationDate());
		userServiceWorkOrderInfo.setReservationTime(dto.getReservationTime());
		userServiceWorkOrderInfo.setModified(new Date());
		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		userDispatchMakeInfo.setReservationDate(dto.getReservationDate());
		userDispatchMakeInfo.setReservationTime(dto.getReservationTime());
		userDispatchMakeInfo.setModified(new Date());
		this.iUserDispatchMakeInfoService.updateById(userDispatchMakeInfo);

		JSONObject result = LmDataUtil.update_departRedepart(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				userBaseInfo.getName(), userBaseInfo.getMobile(),
				LmServiceTypeEnum.getName(userServiceWorkOrderInfo.getLmWorkOrderType()),
				dto.getReservationDate() + " " + UserUtil.getReservationTime(dto.getReservationTime()), dto.getRemark(),
				dto.getChangeAppointmentReasonId(), dto.getUpdateTimeVerifyCode());
		if (result == null) {
			throw new LmException("同步绿米工单状态失败!");
		}
		if (result != null && result.getInteger("code") != 0) {
			throw new LmException("同步绿米工单状态失败!");
		}
		return success();
	}

	/**
	 * 预约失败接口
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/providerfeedback", method = RequestMethod.POST)
	@ApiOperation(value = "预约失败接口", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> providerFeedback(@RequestBody RequestApiParam<LmProviderfeedBackDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmProviderfeedBackDTO dto = requestApiParam.getT();
		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(userServiceWorkOrderInfo.getLmIsClose())) {
			return error(ResultCode.LM_WORK_ORDER_CANCEL);
		}
		JSONObject jsonObject = LmDataUtil.receiveMessage("CANCEL", userServiceWorkOrderInfo.getLmWorkOrderNo(), "Y");
		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
			JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("messageList");
			if (jsonArray != null && !jsonArray.isEmpty()) {
				JSONObject contentObject = jsonArray.getJSONObject(0).getJSONObject("content");
				userServiceWorkOrderInfo.setLmCustomerCancelDate(UserUtil.setMiToDate(contentObject.getLong("opTime")));
				userServiceWorkOrderInfo.setLmCustomerCancelReason(
						UserUtil.getLmCustomerCancelReasonByCode(contentObject.getIntValue("cancelReasonId")));
				userServiceWorkOrderInfo.setLmCustomerCancelRemark(contentObject.getString("remark"));
				userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
				this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);
				return error(ResultCode.LM_WORK_ORDER_CANCEL);
			}
		}

		userServiceWorkOrderInfo.setLmAppointmentFailReason(dto.getFeedbackReason());
		userServiceWorkOrderInfo.setModified(new Date());
		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		UserServiceWorkOrderLog userServiceWorkOrderLog = new UserServiceWorkOrderLog();
		try {
			this.setCreateInfo(userServiceWorkOrderLog, UserServiceWorkOrderLog.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		userServiceWorkOrderLog.setWorkOrderId(userServiceWorkOrderInfo.getId());
		userServiceWorkOrderLog.setStatus(WorkOrderLogConst.STATUS_4);
		userServiceWorkOrderLog.setDetail(
				UserUtil.getIdentityNameByIdentityCode(userBaseInfo.getIdentity(), userBaseInfo.getMasterType())
						+ userBaseInfo.getName() + "预约失败,失败原因:" + dto.getFeedbackReason());
		this.iUserServiceWorkOrderLogService.insert(userServiceWorkOrderLog);

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		JSONObject result = LmDataUtil.providerFeedback(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				sdf.format(userServiceWorkOrderInfo.getLmWorkerFirstCallTime()),
				sdf.format(userServiceWorkOrderInfo.getLmWorkerLastCallTime()),
				userServiceWorkOrderInfo.getLmWorkerCallNum(), dto.getFeedbackReasonId());
		if (result == null) {
			throw new LmException("同步绿米工单状态失败!");
		}
		if (result != null && result.getInteger("code") != 0) {
			throw new LmException("同步绿米工单状态失败!");
		}
		return success();
	}

	/**
	 * 拨打电话接口
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmmobile", method = RequestMethod.POST)
	@ApiOperation(value = "拨打电话接口", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> lmMobile(@RequestBody RequestApiParam<LmMobileDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmMobileDTO dto = requestApiParam.getT();
		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (userServiceWorkOrderInfo.getLmWorkerFirstCallTime() == null) {
			userServiceWorkOrderInfo.setLmWorkerFirstCallTime(new Date());
		}
		Integer lmWorkerCallNum = null;
		userServiceWorkOrderInfo.setLmWorkerLastCallTime(new Date());
		if (userServiceWorkOrderInfo.getLmWorkerCallNum() == null) {
			lmWorkerCallNum = 0;
		} else {
			lmWorkerCallNum = userServiceWorkOrderInfo.getLmWorkerCallNum();
		}
		lmWorkerCallNum++;
		userServiceWorkOrderInfo.setLmWorkerCallNum(lmWorkerCallNum);
		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		UserServiceWorkOrderLog userServiceWorkOrderLog = new UserServiceWorkOrderLog();
		try {
			this.setCreateInfo(userServiceWorkOrderLog, UserServiceWorkOrderLog.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		userServiceWorkOrderLog.setWorkOrderId(userServiceWorkOrderInfo.getId());
		userServiceWorkOrderLog.setStatus(WorkOrderLogConst.STATUS_14);
		userServiceWorkOrderLog.setDetail(
				UserUtil.getIdentityNameByIdentityCode(userBaseInfo.getIdentity(), userBaseInfo.getMasterType())
						+ userBaseInfo.getName() + "与客户电话沟通1次");
		this.iUserServiceWorkOrderLogService.insert(userServiceWorkOrderLog);

		return success();
	}

	/**
	 * 安装师傅接单接口
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmacceptworkorder", method = RequestMethod.POST)
	@ApiOperation(value = "安装师傅立即接单接口", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> lmAcceptWorkOrder(@RequestBody RequestApiParam<LmAcceptWorkOrderDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmAcceptWorkOrderDTO dto = requestApiParam.getT();

		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(userServiceWorkOrderInfo.getLmIsClose())) {
			return error(ResultCode.LM_WORK_ORDER_CANCEL);
		}
		JSONObject jsonObject = LmDataUtil.receiveMessage("CANCEL", userServiceWorkOrderInfo.getLmWorkOrderNo(), "Y");
		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
			JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("messageList");
			if (jsonArray != null && !jsonArray.isEmpty()) {
				JSONObject contentObject = jsonArray.getJSONObject(0).getJSONObject("content");
				userServiceWorkOrderInfo.setLmCustomerCancelDate(UserUtil.setMiToDate(contentObject.getLong("opTime")));
				userServiceWorkOrderInfo.setLmCustomerCancelReason(
						UserUtil.getLmCustomerCancelReasonByCode(contentObject.getIntValue("cancelReasonId")));
				userServiceWorkOrderInfo.setLmCustomerCancelRemark(contentObject.getString("remark"));
				userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
				this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);
				return error(ResultCode.LM_WORK_ORDER_CANCEL);
			}
		}
		UserDispatchMakeInfo userDispatchMakeInfo = this.iUserDispatchMakeInfoService
				.getOkUserDispatchMakeInfo(dto.getDispatcherId());
		if (userDispatchMakeInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		userDispatchMakeInfo.setModified(new Date());
		userDispatchMakeInfo.setModifier(requestApiParam.getUid());
		userDispatchMakeInfo.setReservationDate(dto.getReservationDate());
		userDispatchMakeInfo.setReservationTime(dto.getReservationTime());
		userServiceWorkOrderInfo.setModified(new Date());
		userServiceWorkOrderInfo.setModifier(requestApiParam.getUid());
		userServiceWorkOrderInfo.setIsDelayed(HttpConsts.NO);
		userDispatchMakeInfo.setAcceptanceTime(new Date());
		userServiceWorkOrderInfo.setWorkOrderStatus(10);
		userServiceWorkOrderInfo.setAcceptDate(new Date());
		userServiceWorkOrderInfo.setReservationDate(dto.getReservationDate());
		userServiceWorkOrderInfo.setReservationTime(dto.getReservationTime());
		/**
		 * 插入服务工单操作日志
		 */
		UserWorkOrderLogUtil.insertWorkOrderLog_3(dto.getWorkOrderId(), userDispatchMakeInfo.getUserId(),
				userDispatchMakeInfo.getMakeUserId());

		this.iUserDispatchMakeInfoService.updateById(userDispatchMakeInfo);

		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		JSONObject result = LmDataUtil.update_acceptDo(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				userBaseInfo.getName(), userBaseInfo.getMobile(),
				LmServiceTypeEnum.getName(userServiceWorkOrderInfo.getLmWorkOrderType()),
				dto.getReservationDate() + " " + UserUtil.getReservationTime(dto.getReservationTime()),
				dto.getRemark());
		if (result == null) {
			throw new LmException("同步绿米工单状态失败!");
		}
		if (result != null && result.getInteger("code") != 0) {
			throw new LmException("同步绿米工单状态失败!");
		}
		return success();
	}

	/**
	 * 安装师傅签到接口
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/makeusersigned", method = RequestMethod.POST)
	@ApiOperation(value = "安装师傅签到接口||二期", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> makeUserSigned(@RequestBody RequestApiParam<LmMakeUserSignedDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		LmMakeUserSignedDTO dto = requestApiParam.getT();
		UserDispatchMakeInfo userDispatchMakeInfo = this.iUserDispatchMakeInfoService
				.getOkUserDispatchMakeInfo(dto.getDispatcherId());
		if (userDispatchMakeInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		List<UserServiceWorkOrderGoods> userServiceWorkOrderGoodsList = this.iUserServiceWorkOrderGoodsService
				.selectList(new EntityWrapper<UserServiceWorkOrderGoods>().eq("is_deleted", HttpConsts.NO)
						.eq("is_enable", HttpConsts.YES).eq("work_order_id", dto.getWorkOrderId()));
		if (userServiceWorkOrderGoodsList == null || userServiceWorkOrderGoodsList.isEmpty()) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(userServiceWorkOrderInfo.getLmIsClose())) {
			return error(ResultCode.LM_WORK_ORDER_CANCEL);
		}
		JSONObject jsonObject = LmDataUtil.receiveMessage("CANCEL", userServiceWorkOrderInfo.getLmWorkOrderNo(), "Y");
		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
			JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("messageList");
			if (jsonArray != null && !jsonArray.isEmpty()) {
				JSONObject contentObject = jsonArray.getJSONObject(0).getJSONObject("content");
				userServiceWorkOrderInfo.setLmCustomerCancelDate(UserUtil.setMiToDate(contentObject.getLong("opTime")));
				userServiceWorkOrderInfo.setLmCustomerCancelReason(
						UserUtil.getLmCustomerCancelReasonByCode(contentObject.getIntValue("cancelReasonId")));
				userServiceWorkOrderInfo.setLmCustomerCancelRemark(contentObject.getString("remark"));
				userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
				this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);
				return error(ResultCode.LM_WORK_ORDER_CANCEL);
			}
		}

		JSONArray jsonArray = new JSONArray();
		for (UserServiceWorkOrderGoods userServiceWorkOrderGoods : userServiceWorkOrderGoodsList) {
			if (StringUtils.isEmpty(userServiceWorkOrderGoods.getLmEachSignJson())) {
				continue;
			}
			JSONObject goodsJsonObject = JSON.parseObject(userServiceWorkOrderGoods.getLmEachSignJson());
			jsonArray.add(goodsJsonObject);
		}
		userServiceWorkOrderInfo.setModified(new Date());
		userServiceWorkOrderInfo.setModifier(requestApiParam.getUid());
		userServiceWorkOrderInfo.setWorkOrderStatus(101);
		userServiceWorkOrderInfo.setIsDelayed(HttpConsts.NO);
		userServiceWorkOrderInfo.setIsSignDelayed(HttpConsts.NO);
		userServiceWorkOrderInfo.setSignDate(new Date());
		userServiceWorkOrderInfo.setLmSignJson(JSON.toJSONString(jsonArray));
		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		userDispatchMakeInfo.setModified(new Date());
		userDispatchMakeInfo.setModifier(requestApiParam.getUid());
		userDispatchMakeInfo.setSignImageSrc(dto.getSignImageSrc());
		userDispatchMakeInfo.setLocation(dto.getLocation());
		userDispatchMakeInfo.setSignTime(new Date());
		this.iUserDispatchMakeInfoService.updateById(userDispatchMakeInfo);

		/**
		 * 插入服务工单操作日志
		 */
		UserWorkOrderLogUtil.insertWorkOrderLog_4(dto.getWorkOrderId(), userDispatchMakeInfo.getUserId(),
				userDispatchMakeInfo.getMakeUserId(), dto.getLocation(), new String[] { dto.getSignImageSrc() });

		JSONObject result = LmDataUtil.update_visitDo(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				userBaseInfo.getName(), userBaseInfo.getMobile(),
				LmServiceTypeEnum.getName(userServiceWorkOrderInfo.getLmWorkOrderType()), jsonArray, "");
		if (result == null) {
			throw new LmException("同步绿米工单状态失败!");
		}
		if (result != null && result.getInteger("code") != 0) {
			throw new LmException("同步绿米工单状态失败!");
		}

		return success();
	}

	/**
	 * 查询绿米服务工单详情
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmworkorderdetail", method = RequestMethod.POST)
	@ApiOperation(value = "查询绿米服务工单详情", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<UserDispatchMakeInfoVO> lmWorkOrderDetail(
			@RequestBody RequestApiParam<LmUserWorkOrderGoodsDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmUserWorkOrderGoodsDTO dto = requestApiParam.getT();

		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}

		UserDispatchMakeInfoVO userDispatchMakeInfoVO = new UserDispatchMakeInfoVO();
		BeanUtil.copyProperties(userServiceWorkOrderInfo, userDispatchMakeInfoVO);

		List<UserServiceWorkOrderGoods> userServiceWorkOrderGoods = this.iUserServiceWorkOrderGoodsService
				.selectList(new EntityWrapper<UserServiceWorkOrderGoods>().eq("is_deleted", HttpConsts.NO)
						.eq("is_enable", HttpConsts.YES).eq("work_order_id", dto.getWorkOrderId()));

		userDispatchMakeInfoVO.setUserServiceWorkOrderGoods(
				userServiceWorkOrderGoods == null ? Lists.newArrayList() : userServiceWorkOrderGoods);

		if (dto.getDispatcherId() != null) {
			UserDispatchMakeInfo userDispatchMakeInfo = this.iUserDispatchMakeInfoService
					.getOkUserDispatchMakeInfo(dto.getDispatcherId());
			if (userDispatchMakeInfo == null) {
				return error(ResultCode.SYS_DATA_ERROR);
			}
			userDispatchMakeInfoVO.setReservationDate(userDispatchMakeInfo.getReservationDate());
			userDispatchMakeInfoVO.setReservationTime(userDispatchMakeInfo.getReservationTime());
			userDispatchMakeInfoVO.setDispatcherRemark(userDispatchMakeInfo.getRemark());
			userDispatchMakeInfoVO.setServiceUserId(userDispatchMakeInfo.getUserId());
			userDispatchMakeInfoVO.setDispatcherId(dto.getDispatcherId());
			userDispatchMakeInfoVO.setMakeUserId(userDispatchMakeInfo.getMakeUserId());
			if (userDispatchMakeInfo.getStatus() == 1) {
				userDispatchMakeInfoVO.setHxDate(userDispatchMakeInfo.getModified());
			}

			UserBaseInfo serviceUserBaseInfo = this.iUserBaseInfoService
					.getServiceUserBaseInfoByUserId(userDispatchMakeInfo.getUserId());
			if (serviceUserBaseInfo != null) {
				userDispatchMakeInfoVO.setServiceUserMobile(serviceUserBaseInfo.getMobile());
			}
			ReverDateVO reverDateVO = new ReverDateVO();
			Long min = UserUtil.getAcceptMins(userDispatchMakeInfo.getCreated(),
					Integer.valueOf(userDispatchMakeInfo.getReverDate()));
			if (min != null) {
				if (min < 0) {
					reverDateVO.setIsOutTime(1);
				} else {
					reverDateVO.setIsOutTime(0);
				}
				min = Math.abs(min);
				reverDateVO.setHour(min / 60);
				reverDateVO.setMin(min % 60);
			}
			userDispatchMakeInfoVO.setReverDateVO(reverDateVO);

		}

		return success(userDispatchMakeInfoVO);
	}

	/**
	 * 保存签到和核销时的json数据
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmsavegoodsjson", method = RequestMethod.POST)
	@ApiOperation(value = "保存签到和核销时的json数据", notes = "一期一阶段")
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> lmSaveGoodsJson(@RequestBody RequestApiParam<LmSaveGoodsJsonDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmSaveGoodsJsonDTO dto = requestApiParam.getT();
		UserServiceWorkOrderGoods userServiceWorkOrderGoods = this.iUserServiceWorkOrderGoodsService
				.selectById(dto.getGoodsId());
		if (userServiceWorkOrderGoods == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(dto.getType())) {
			userServiceWorkOrderGoods.setLmEachSignJson(dto.getGoodsJson());
			userServiceWorkOrderGoods.setLmOldDoorLockSn(dto.getSn());
		} else {
			userServiceWorkOrderGoods.setLmEachHxJson(dto.getGoodsJson());
		}
		userServiceWorkOrderGoods.setModified(new Date());
		userServiceWorkOrderGoods.setModifier(requestApiParam.getUid());
		this.iUserServiceWorkOrderGoodsService.updateById(userServiceWorkOrderGoods);
		return success();
	}

	/**
	 * 安装师傅核销接口
	 * 
	 * @param requestApiParam
	 * @return
	 */
	@RequestMapping(value = "v1/lmhxWorkOrder", method = RequestMethod.POST)
	@ApiOperation(value = "安装师傅核销接口||二期", notes = "一期一阶段")
	@Transactional
	@ApiVersion(group = { ApiVersionConsts.V_2_2_4 })
	public ResultEntity<?> lmHxworkorder(@RequestBody RequestApiParam<LmHxWorkOrderDTO> requestApiParam) {
		assertUidNotNull(requestApiParam);
		LmHxWorkOrderDTO dto = requestApiParam.getT();
		Date date = new Date();
		// 原子性操作
		if (RedisUtil.get(CacheConsts.CACHE_SERVICE_HX_REPEAT_COMMIT + requestApiParam.getUid()) != null) {
			return error(ResultCode.SYS_COMMIT_SECONE);
		} else {
			RedisUtil.set(CacheConsts.CACHE_SERVICE_HX_REPEAT_COMMIT + requestApiParam.getUid(),
					requestApiParam.getUid() + "", CacheConsts.CACHE_SERVICE_HX_REPEAT_COMMIT_EXPIRE_TIME);
		}
		UserBaseInfo userBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				requestApiParam.getUid());
		if (userBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		if (UserConsts.SHOP_SERVICE.equals(userBaseInfo.getIdentity())
				|| UserConsts.COMMON_SERVICE.equals(userBaseInfo.getIdentity())) {
			return error(ResultCode.USER_NOT_ALLOWED);
		}
		UserServiceWorkOrderInfo userServiceWorkOrderInfo = this.iUserServiceWorkOrderInfoService
				.selectById(dto.getWorkOrderId());
		if (userServiceWorkOrderInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		if (HttpConsts.NO.equals(userServiceWorkOrderInfo.getLmIsClose())) {
			return error(ResultCode.LM_WORK_ORDER_CANCEL);
		}
		JSONObject jsonObject = LmDataUtil.receiveMessage("CANCEL", userServiceWorkOrderInfo.getLmWorkOrderNo(), "Y");
		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
			JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("messageList");
			if (jsonArray != null && !jsonArray.isEmpty()) {
				JSONObject contentObject = jsonArray.getJSONObject(0).getJSONObject("content");
				userServiceWorkOrderInfo.setLmCustomerCancelDate(UserUtil.setMiToDate(contentObject.getLong("opTime")));
				userServiceWorkOrderInfo.setLmCustomerCancelReason(
						UserUtil.getLmCustomerCancelReasonByCode(contentObject.getIntValue("cancelReasonId")));
				userServiceWorkOrderInfo.setLmCustomerCancelRemark(contentObject.getString("remark"));
				userServiceWorkOrderInfo.setLmIsClose(HttpConsts.NO);
				this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);
				return error(ResultCode.LM_WORK_ORDER_CANCEL);
			}
		}
		UserDispatchMakeInfo userDispatchMakeInfo = this.iUserDispatchMakeInfoService
				.getOkUserDispatchMakeInfo(dto.getDispatcherId());
		if (userDispatchMakeInfo == null) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		List<UserServiceWorkOrderGoods> userServiceWorkOrderGoodsList = this.iUserServiceWorkOrderGoodsService
				.selectList(new EntityWrapper<UserServiceWorkOrderGoods>().eq("is_deleted", HttpConsts.NO)
						.eq("is_enable", HttpConsts.YES).eq("work_order_id", dto.getWorkOrderId()));
		if (userServiceWorkOrderGoodsList == null || userServiceWorkOrderGoodsList.isEmpty()) {
			return error(ResultCode.SYS_DATA_ERROR);
		}
		JSONArray materialsArray = new JSONArray();
		for (UserServiceWorkOrderGoods userServiceWorkOrderGoods : userServiceWorkOrderGoodsList) {
			if (StringUtils.isEmpty(userServiceWorkOrderGoods.getLmEachSignJson())) {
				continue;
			}
			JSONObject goodsJsonObject = JSON.parseObject(userServiceWorkOrderGoods.getLmEachHxJson());
			materialsArray.add(goodsJsonObject);
		}
		String otherFileImageSrc = dto.getOtherFileImageSrc();
		JSONArray otherFileImageSrcArray = null;
		try {
			otherFileImageSrcArray = JSON.parseArray(otherFileImageSrc);
			if (otherFileImageSrcArray == null || otherFileImageSrcArray.isEmpty()) {
				return error(ResultCode.PARAM_CHECK_ERROR);
			}
			if (otherFileImageSrcArray.size() < 3) {
				return error(ResultCode.LM_WORK_ORDER_HX_PIC);
			}
		} catch (Exception e) {
			return error(ResultCode.PARAM_DECODE_ERROR);
		}
		UserBaseInfo makeUserBaseInfo = this.iUserBaseInfoService.selectByUserId(HttpConsts.NO, HttpConsts.YES,
				userDispatchMakeInfo.getMakeUserId());
		if (makeUserBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}

		UserBaseInfo serviceUserBaseInfo = new UserBaseInfo();
		if (UserConsts.PLATFORM_SERVICE.equals(userBaseInfo.getIdentity())
				|| UserConsts.THIRD_SERVICE.equals(userBaseInfo.getIdentity())) {
			serviceUserBaseInfo = this.iUserBaseInfoService
					.getServiceUserBaseInfoByUserId(userDispatchMakeInfo.getUserId());
		} else if (UserConsts.OTHER_SERVICE.equals(userBaseInfo.getIdentity())) {
			if (userBaseInfo.getMasterType() == null || HttpConsts.NO.equals(userBaseInfo.getMasterType())) {
				serviceUserBaseInfo = this.iUserBaseInfoService
						.getServiceUserBaseInfoByUserId(userDispatchMakeInfo.getUserId());
			} else {
				BeanUtil.copyProperties(userBaseInfo, serviceUserBaseInfo);
			}
		}

		if (serviceUserBaseInfo == null) {
			return error(ResultCode.USER_NOT_EXIST);
		}
		userServiceWorkOrderInfo.setModified(new Date());
		userServiceWorkOrderInfo.setModifier(requestApiParam.getUid());
		userServiceWorkOrderInfo.setWorkOrderStatus(102);
		userServiceWorkOrderInfo.setHxDate(new Date());
		userServiceWorkOrderInfo.setLmHxJson(JSON.toJSONString(materialsArray));
		this.iUserServiceWorkOrderInfoService.updateById(userServiceWorkOrderInfo);

		userDispatchMakeInfo.setStatus(1);
		userDispatchMakeInfo.setModified(new Date());
		userDispatchMakeInfo.setModifier(requestApiParam.getUid());
		userDispatchMakeInfo.setOtherFileImageSrc(dto.getOtherFileImageSrc());
		userDispatchMakeInfo.setVerificationTime(new Date());
		this.iUserDispatchMakeInfoService.updateById(userDispatchMakeInfo);

		// 计算未结算服务佣金
		BigDecimal serviceProviderMoney = BigDecimal.ZERO;
		if (UserConsts.PLATFORM_SERVICE.equals(serviceUserBaseInfo.getIdentity())
				|| UserConsts.THIRD_SERVICE.equals(serviceUserBaseInfo.getIdentity())) {
			serviceProviderMoney = userServiceWorkOrderInfo.getServiceOrderPrice();
		} else if (UserConsts.OTHER_SERVICE.equals(serviceUserBaseInfo.getIdentity())) {
			serviceProviderMoney = userServiceWorkOrderInfo.getMasterOrderPrice();
		}
		serviceUserBaseInfo.setUnliquidatedWithdrawcashMoney(
				this.add(serviceProviderMoney, serviceUserBaseInfo.getUnliquidatedWithdrawcashMoney(), 2));
		serviceUserBaseInfo.setModified(new Date());
		// serviceUserBaseInfo.setRunningWithdrawcashMoney(
		// this.subtract(serviceUserBaseInfo.getRunningWithdrawcashMoney(),
		// serviceProviderMoney, 2));
		serviceUserBaseInfo.setModifier(requestApiParam.getUid());
		this.iUserBaseInfoService.updateById(serviceUserBaseInfo);

		// 插入订单账单信息表
		UserServiceWorkOrderBill userServiceWorkOrderBill = new UserServiceWorkOrderBill();
		try {
			ReflectUtil.setCreateInfo(userServiceWorkOrderBill, userServiceWorkOrderBill.getClass());
		} catch (Exception e) {
			e.printStackTrace();
		}
		userServiceWorkOrderBill.setUserPrice(serviceProviderMoney);
		userServiceWorkOrderBill.setType(HttpConsts.NO);
		userServiceWorkOrderBill.setWorkOrderId(userServiceWorkOrderInfo.getId());
		userServiceWorkOrderBill.setBuyerName(userServiceWorkOrderInfo.getBuyerName());
		userServiceWorkOrderBill.setBuyerPhone(userServiceWorkOrderInfo.getBuyerPhone());
		userServiceWorkOrderBill.setBuyerDetailAddress(userServiceWorkOrderInfo.getBuyerDetailAddress());
		userServiceWorkOrderBill.setRemark(userServiceWorkOrderInfo.getRemark());
		userServiceWorkOrderBill.setWorkOrderNo(userServiceWorkOrderInfo.getWorkOrderNo());
		userServiceWorkOrderBill.setHxDate(new Date());
		userServiceWorkOrderBill.setUserId(serviceUserBaseInfo.getId());
		userServiceWorkOrderBill.setMakeUserMobile(makeUserBaseInfo.getMobile());
		userServiceWorkOrderBill.setMakeUserName(makeUserBaseInfo.getName());
		this.iUserServiceWorkOrderBillService.insert(userServiceWorkOrderBill);

		/**
		 * 插入服务工单操作日志
		 */
		UserWorkOrderLogUtil.insertWorkOrderLog_5(dto.getWorkOrderId(), userDispatchMakeInfo.getUserId(),
				userDispatchMakeInfo.getMakeUserId(), new String[] { dto.getOtherFileImageSrc() });

		/**
		 * 插入财务信息
		 */
		WorkOrderInvoiceInfo workOrderInvoiceInfo = new WorkOrderInvoiceInfo();
		try {
			this.setCreateInfo(workOrderInvoiceInfo, WorkOrderInvoiceInfo.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		workOrderInvoiceInfo.setWorkOrderComDate(date);
		workOrderInvoiceInfo.setWorkOrderCreated(userServiceWorkOrderInfo.getCreated());
		if (WorkOrderConst.SOURCE_1.equals(userServiceWorkOrderInfo.getSource())) {
			SysUser workOrderCreateSysUser = this.iSysUserService.selectById(userServiceWorkOrderInfo.getCreator());
			if (workOrderCreateSysUser != null) {
				workOrderInvoiceInfo.setWorkOrderCreater(workOrderCreateSysUser.getAccount());
			}
		} else {
			UserBaseInfo workOrderCreateUserBaseInfo = this.iUserBaseInfoService
					.selectById(userServiceWorkOrderInfo.getCreator());
			if (workOrderCreateUserBaseInfo != null) {
				workOrderInvoiceInfo.setWorkOrderCreater(StringUtils.isEmpty(workOrderCreateUserBaseInfo.getName())
						? workOrderCreateUserBaseInfo.getNickname()
						: workOrderCreateUserBaseInfo.getName());
			}
		}
		workOrderInvoiceInfo.setShopId(userServiceWorkOrderInfo.getShopId());
		workOrderInvoiceInfo.setSource(4);
		workOrderInvoiceInfo.setWorkOrderNo(userServiceWorkOrderInfo.getWorkOrderNo());
		workOrderInvoiceInfo.setWorkOrderId(userServiceWorkOrderInfo.getId());
		workOrderInvoiceInfo.setStatus(HttpConsts.NO);
		workOrderInvoiceInfo.setWorkOrderStatus(HttpConsts.YES);
		UserFirstpartyInfo userFirstpartyInfo = this.iUserFirstpartyInfoService
				.selectById(userServiceWorkOrderInfo.getShopId());
		if (userFirstpartyInfo != null) {
			workOrderInvoiceInfo.setShopName(userFirstpartyInfo.getShopName());
			workOrderInvoiceInfo.setShopSn(userFirstpartyInfo.getShopSn());
		}
		workOrderInvoiceInfo.setBuyerName(userServiceWorkOrderInfo.getBuyerName());
		workOrderInvoiceInfo.setBuyerPhone(userServiceWorkOrderInfo.getBuyerPhone());
		workOrderInvoiceInfo.setBuyerDetailAddress(userServiceWorkOrderInfo.getBuyerDetailAddress());

		UserServiceWorkOrderGoods userServiceWorkOrderGoods = userServiceWorkOrderGoodsList.get(0);
		workOrderInvoiceInfo.setGoodsName(userServiceWorkOrderGoods.getGoodsName());
		try {
			JSONArray jsonArray = JSON.parseArray(userServiceWorkOrderGoods.getGoodsAttribute());
			if (jsonArray != null && !jsonArray.isEmpty()) {
				if (jsonArray.size() == 4) {
					workOrderInvoiceInfo.setGoodsModelType(jsonArray.getString(1));
					workOrderInvoiceInfo.setBrandName(jsonArray.getString(0));
				} else {
					workOrderInvoiceInfo.setGoodsModelType("");
					workOrderInvoiceInfo.setBrandName("");
				}
			} else {
				workOrderInvoiceInfo.setGoodsModelType("");
				workOrderInvoiceInfo.setBrandName("");
			}
		} catch (Exception e) {
			workOrderInvoiceInfo.setGoodsModelType("");
			workOrderInvoiceInfo.setBrandName("");
		}
		workOrderInvoiceInfo.setNum(WorkOrderConst.DEFAULT_DISPATCHER_NUM);
		workOrderInvoiceInfo.setWorkOrderPrice(userServiceWorkOrderInfo.getTotalOrderPrice());
		workOrderInvoiceInfo.setUserSn(serviceUserBaseInfo.getUserSn());
		workOrderInvoiceInfo.setUserMobile(serviceUserBaseInfo.getMobile());
		workOrderInvoiceInfo.setUserType(UserUtil.getIdentityNameByIdentityCode(serviceUserBaseInfo.getIdentity(),
				serviceUserBaseInfo.getMasterType()));
		workOrderInvoiceInfo.setUserName(serviceUserBaseInfo.getName());
		Integer serviceType = serviceUserBaseInfo.getServiceType();
		if (UserConsts.PLATFORM_SERVICE.equals(serviceUserBaseInfo.getIdentity())) {
			workOrderInvoiceInfo.setUserPrice(userServiceWorkOrderInfo.getServiceOrderPrice());
			workOrderInvoiceInfo.setUserTotalPrice(userServiceWorkOrderInfo.getServiceOrderPrice());
			if (serviceType == null) {
				serviceType = HttpConsts.NO;
			}
		} else {
			workOrderInvoiceInfo.setUserPrice(userServiceWorkOrderInfo.getMasterOrderPrice());
			workOrderInvoiceInfo.setUserTotalPrice(userServiceWorkOrderInfo.getMasterOrderPrice());
			if (serviceType == null) {
				serviceType = HttpConsts.YES;
			}
		}
		workOrderInvoiceInfo.setSettleType(serviceType);
		this.iworkOrderInvoiceInfoService.insert(workOrderInvoiceInfo);

		JSONObject result = LmDataUtil.update_processDo(userServiceWorkOrderInfo.getLmWorkOrderNo(),
				makeUserBaseInfo.getName(), makeUserBaseInfo.getMobile(),
				LmServiceTypeEnum.getName(userServiceWorkOrderInfo.getLmWorkOrderType()), 1, dto.getAuthCode(),
				"ServiceEnd", materialsArray, otherFileImageSrcArray, "");
		if (result == null) {
			throw new LmException("同步绿米工单状态失败!");
		}
		if (result != null && result.getInteger("code") != 0) {
			throw new LmException("同步绿米工单状态失败!");
		}

		return success();
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值