|
@@ -3,19 +3,35 @@ package com.ym.mec.collectfee.service.impl;
|
|
|
import com.thoughtworks.xstream.XStream;
|
|
|
import com.ym.mec.collectfee.common.dao.BaseDAO;
|
|
|
import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
|
|
|
-import com.ym.mec.collectfee.dao.ApplyInfoDao;
|
|
|
-import com.ym.mec.collectfee.entity.ApplyInfo;
|
|
|
-import com.ym.mec.collectfee.entity.RequestParamBean;
|
|
|
+import com.ym.mec.collectfee.dao.*;
|
|
|
+import com.ym.mec.collectfee.entity.*;
|
|
|
import com.ym.mec.collectfee.service.ApplyInfoService;
|
|
|
+import com.ym.mec.collectfee.utils.HttpUtil;
|
|
|
+import com.ym.mec.collectfee.utils.XStreamUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.io.Writer;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Base64;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> implements ApplyInfoService {
|
|
|
|
|
|
@Autowired
|
|
|
private ApplyInfoDao applyInfoDao;
|
|
|
+ @Autowired
|
|
|
+ private OrderDao orderDao;
|
|
|
+ @Autowired
|
|
|
+ private CourseGroupInfoDao courseGroupInfoDao;
|
|
|
+ @Autowired
|
|
|
+ private BranchDao branchDao;
|
|
|
+ @Autowired
|
|
|
+ private SeminaryDao seminaryDao;
|
|
|
|
|
|
@Value("${common.properties.mec-publicKey}")
|
|
|
private String publicKey;
|
|
@@ -34,14 +50,146 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void userRegister(Integer userId) {
|
|
|
- ApplyInfo applyInfo = applyInfoDao.get(userId);
|
|
|
- if(applyInfo != null && applyInfo.getStatus() == 1){
|
|
|
- RequestParamBean requestParamBean = new RequestParamBean();
|
|
|
- XStream xs = new XStream();
|
|
|
- xs.autodetectAnnotations(true);
|
|
|
- String xml = xs.toXML(applyInfo);
|
|
|
- return;
|
|
|
+ public Object userRegister(String phone) {
|
|
|
+ try {
|
|
|
+ ApplyInfo applyInfo = applyInfoDao.findUserByPhone(phone,null);
|
|
|
+ if(applyInfo != null && applyInfo.getStatus() == 1 && applyInfo.getPushStatus() != 1){
|
|
|
+ //组装请求
|
|
|
+ applyInfo.setRealName(applyInfo.getName());
|
|
|
+ applyInfo.setgClass(applyInfo.getGrade() + applyInfo.getgClass());
|
|
|
+ applyInfo.setMobile(applyInfo.getPatriarchPhone());
|
|
|
+ XStream xs = new XStream();
|
|
|
+ xs.autodetectAnnotations(true);
|
|
|
+ xs.ignoreUnknownElements();
|
|
|
+ String body = xs.toXML(applyInfo);
|
|
|
+ body = body.substring(body.indexOf("<user>")+6,body.indexOf("</user>"));
|
|
|
+ body = getBody(body,12301);
|
|
|
+ Date date = new Date();
|
|
|
+ try {
|
|
|
+ applyInfo.setUpdateTime(date);
|
|
|
+ ResponseUserInfo userInfo = parseRegisterInfo(body);
|
|
|
+ applyInfo.setUserId(userInfo.getUserId());
|
|
|
+ applyInfo.setPushStatus(1);
|
|
|
+ RequestMecApplyClass applyClass = getApplyClass(applyInfo);
|
|
|
+ body = xs.toXML(applyClass);
|
|
|
+ body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
|
|
|
+ //推送mec注册接口
|
|
|
+ body = getBody(body,125218);
|
|
|
+ }catch (Exception e){
|
|
|
+ applyInfo.setPushStatus(2);
|
|
|
+ }
|
|
|
+ applyInfoDao.update(applyInfo);
|
|
|
+
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestMecApplyClass getApplyClass(ApplyInfo applyInfo) {
|
|
|
+ Order order = orderDao.findOrderByStatus(applyInfo.getId(), 0);
|
|
|
+ if(order != null){
|
|
|
+ //封装请求参数
|
|
|
+ RequestMecApplyClass applyClass = new RequestMecApplyClass();
|
|
|
+ //<studentId>学员编号</studentId>
|
|
|
+ applyClass.setStudentId(applyInfo.getUserId());
|
|
|
+ //<classId>课程班(乐团)编号</classId>
|
|
|
+ applyClass.setClassId(applyInfo.getClassId());
|
|
|
+ //<subName>学员专业名称</subName>
|
|
|
+ CourseGroupInfo groupInfo = courseGroupInfoDao.get(applyInfo.getSubId());
|
|
|
+ applyClass.setSubName(groupInfo.getSubName());
|
|
|
+ //<remark>备注</remark>
|
|
|
+ applyClass.setRemark(order.getRemark());
|
|
|
+ List<Course> courses = new ArrayList<>();
|
|
|
+ Course course = new Course();
|
|
|
+ //<courseId>课程组编号</courseId>
|
|
|
+ course.setCourseId(groupInfo.getId());
|
|
|
+ courses.add(course);
|
|
|
+ applyClass.setCourses(courses);
|
|
|
+ //<amount>缴费总金额</amount>
|
|
|
+ applyClass.setAmount(order.getAmount());
|
|
|
+ //<tuiFee>学费金额</tuiFee>
|
|
|
+ applyClass.setTuiFee(order.getTuiFee());
|
|
|
+ //<goodsFee>乐器费用</goodsFee>
|
|
|
+ applyClass.setGoodsFee(order.getGoodsFee());
|
|
|
+ //<sdName>杂费名称</sdName>
|
|
|
+ List<Sundry> sundries = new ArrayList<>();
|
|
|
+ Sundry sundry = new Sundry();
|
|
|
+ sundry.setSdFee(order.getSdFee());
|
|
|
+ String sdName = order.getSdName();
|
|
|
+ if(StringUtils.isEmpty(sdName)){
|
|
|
+ sdName = order.getRemark();
|
|
|
+ }
|
|
|
+ //<sdFee>杂费金额</sdFee>
|
|
|
+ sundry.setSdName(sdName);
|
|
|
+ sundries.add(sundry);
|
|
|
+ applyClass.setSundries(sundries);
|
|
|
+ return applyClass;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Branch> getBranches() {
|
|
|
+ try {
|
|
|
+ List<Branch> branchList = branchDao.findAll(null);
|
|
|
+ if(branchList == null || branchList.size() < 1){
|
|
|
+ String body = "<province>0</province>";
|
|
|
+ body = getBody(body,121002);
|
|
|
+ body = "<body><branches>" + new String(Base64.getDecoder().decode(body)) + "</branches></body>";
|
|
|
+ ResponseBranchesBean branches = XStreamUtil.xmlToObject("body", ResponseBranchesBean.class, body);
|
|
|
+ branchDao.batchInsert(branches.getBranches());
|
|
|
+ return branches.getBranches();
|
|
|
+ }
|
|
|
+ return branchList;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getBody(String body,Integer cmd) throws Exception{
|
|
|
+ body = Base64.getEncoder().encodeToString(body.getBytes());
|
|
|
+ RequestParamBean requestParamBean = new RequestParamBean();
|
|
|
+ requestParamBean.setBody(body);
|
|
|
+ requestParamBean.setHead(XStreamUtil.getOrdersHead(body,cmd,publicKey));
|
|
|
+ Writer writer = new StringWriter();
|
|
|
+ writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
|
|
+ XStream xs = new XStream();
|
|
|
+ xs.toXML(requestParamBean,writer);
|
|
|
+ body = HttpUtil.postXmlData(writer.toString(), url);
|
|
|
+ return body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveSeminary() {
|
|
|
+ try {
|
|
|
+ List<Branch> branchList = branchDao.findAll(null);
|
|
|
+ for (Branch branch:branchList) {
|
|
|
+ Seminary seminary = seminaryDao.findByBranchId(branch.getBranchId());
|
|
|
+ if(seminary != null){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String body = "<branchId>" + branch.getBranchId() + "</branchId>";
|
|
|
+ body = getBody(body,121107);
|
|
|
+ body = "<body><schools>" + new String(Base64.getDecoder().decode(body)) + "</schools></body>";
|
|
|
+ ResponseSeminariesBean seminaries = XStreamUtil.xmlToObject("body", ResponseSeminariesBean.class, body);
|
|
|
+ if(seminaries.getSchools() == null || seminaries.getSchools().size() < 1){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ seminaryDao.batchInsert(seminaries.getSchools());
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseUserInfo parseRegisterInfo(String body){
|
|
|
+ body = "<body>" + new String(Base64.getDecoder().decode(body)) + "</body>";
|
|
|
+ ResponseUserInfo userInfo = XStreamUtil.xmlToObject("body", ResponseUserInfo.class, body);
|
|
|
+ return userInfo;
|
|
|
}
|
|
|
}
|