IndexController.java 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  1. package com.szwl.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6. import com.szwl.constant.ResponseCodesEnum;
  7. import com.szwl.model.bean.*;
  8. import com.szwl.model.bo.JsonMessage;
  9. import com.szwl.model.bo.JsonUtils;
  10. import com.szwl.model.bo.R;
  11. import com.szwl.model.bo.ResponseModel;
  12. import com.szwl.model.entity.*;
  13. import com.szwl.model.utils.AdminUtils;
  14. import com.szwl.model.utils.HttpClientSslUtils;
  15. import com.szwl.model.utils.PushUtils;
  16. import com.szwl.service.*;
  17. import com.szwl.service.es.EsTEquipmentService;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import org.apache.commons.io.IOUtils;
  21. import org.apache.commons.lang.StringUtils;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.web.bind.annotation.*;
  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import java.io.*;
  27. import java.math.BigDecimal;
  28. import java.math.RoundingMode;
  29. import java.text.DateFormat;
  30. import java.text.ParseException;
  31. import java.text.SimpleDateFormat;
  32. import java.util.*;
  33. //@Api(value = "/api/app_equipment/index", tags = {"设备信息上传接口"})
  34. @Api(value = "/indexController", tags = {"设备信息上传接口"})
  35. @RestController
  36. @RequestMapping("/api/app_equipment/index")
  37. public class IndexController { ;
  38. @Autowired
  39. TAdminService adminService;
  40. @Autowired
  41. TEquipmentService equipmentService;
  42. @Autowired
  43. TEquipmentApplyService equipmentApplyService;
  44. @Autowired
  45. TProductService productService;
  46. @Autowired
  47. TProportionService proportionService;
  48. @Autowired
  49. TEquipmentDescService equipmentDescService;
  50. @Autowired
  51. EsTEquipmentService esTEquipmentService;
  52. @Autowired
  53. TParametersService parametersService;
  54. @Autowired
  55. TPriceService priceService;
  56. @Autowired
  57. TPromoCodeService promoCodeService;
  58. @ApiOperation(value = "心跳")
  59. // @PostMapping("/heart.htm")
  60. @RequestMapping(value = "/heart.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  61. @ResponseBody
  62. public String heart(@RequestBody EquipmentVo equipmentVo) {
  63. String clientId = equipmentVo.getClientId();
  64. Date lastUpdateTime = equipmentVo.getLastUpdateTime();
  65. Double longitude = equipmentVo.getLongitude();
  66. Double latitude = equipmentVo.getLatitude();
  67. String cabinetHd = equipmentVo.getCabinetHd();
  68. String cabinetTm = equipmentVo.getCabinetTm();
  69. String furnaceSp = equipmentVo.getFurnaceSp();
  70. String furnaceTm = equipmentVo.getFurnaceTm();
  71. String gtClientId = equipmentVo.getGtClientId();
  72. String volume = equipmentVo.getVolume();
  73. Integer eqeStatus = equipmentVo.getEqeStatus();
  74. Boolean is_sleep = equipmentVo.getIs_sleep();
  75. String netWorkingMode = equipmentVo.getNetWorkingMode();
  76. //有记录,则进行修改
  77. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  78. query.eq(TEquipment::getClientId,clientId);
  79. List<TEquipment> list = equipmentService.list(query);
  80. TEquipment _new = list.get(0);
  81. // Equipment _new = equipmentService.findByClientId(clientId);
  82. if (_new != null) {
  83. _new.setNetWorkingMode(netWorkingMode);
  84. if(StringUtils.isNotEmpty(cabinetTm)){
  85. _new.setCabinetTm(cabinetTm);
  86. }
  87. if(StringUtils.isNotEmpty(cabinetHd)){
  88. _new.setCabinetHd(cabinetHd);
  89. }
  90. if(StringUtils.isNotEmpty(furnaceSp)){
  91. _new.setFurnaceSp(furnaceSp);
  92. }
  93. if(StringUtils.isNotEmpty(furnaceTm)){
  94. _new.setFurnaceTm(furnaceTm);
  95. }
  96. _new.setLastUpdateTime(lastUpdateTime);
  97. // _new.setLongitude(longitude);
  98. if(eqeStatus!=null){
  99. _new.setEqeStatus(eqeStatus);
  100. }
  101. if(is_sleep!=null){
  102. _new.setIsSleep(is_sleep);
  103. }
  104. if(!StringUtils.isEmpty(furnaceTm)){
  105. int fur = Integer.parseInt(furnaceTm);
  106. if(_new.getEqeStatus()==0&&fur>150){
  107. _new.setEqeStatus(1);
  108. }
  109. if(_new.getEqeStatus()==null&&fur>150){
  110. _new.setEqeStatus(1);
  111. }
  112. }
  113. if(!StringUtils.isEmpty(volume)){
  114. _new.setVolume(volume);
  115. }
  116. // _new.setLatitude(latitude);
  117. _new.setGtClientId(gtClientId);
  118. _new.setModifyDate(new Date());
  119. equipmentService.updateById(_new);
  120. TEquipmentDesc equipmentDesc = equipmentDescService.getById(_new.getId());
  121. if(StringUtils.isNotEmpty(equipmentVo.getBlueSugar())){
  122. equipmentDesc.setBlueSugar(equipmentVo.getBlueSugar());
  123. }
  124. if(StringUtils.isNotEmpty(equipmentVo.getRedSugar())){
  125. equipmentDesc.setRedSugar(equipmentVo.getRedSugar());
  126. }
  127. if(StringUtils.isNotEmpty(equipmentVo.getYellowSugar())){
  128. equipmentDesc.setYellowSugar(equipmentVo.getYellowSugar());
  129. }
  130. if(StringUtils.isNotEmpty(equipmentVo.getWhiteSugar())){
  131. equipmentDesc.setWhiteSugar(equipmentVo.getWhiteSugar());
  132. }
  133. if(StringUtils.isNotEmpty(equipmentVo.getWater())){
  134. equipmentDesc.setWater(equipmentVo.getWater());
  135. }
  136. if(StringUtils.isNotEmpty(equipmentVo.getWasteWater())){
  137. equipmentDesc.setWasteWater(equipmentVo.getWasteWater());
  138. }
  139. if(StringUtils.isNotEmpty(equipmentVo.getStick())){
  140. equipmentDesc.setStick(equipmentVo.getStick());
  141. }
  142. equipmentDescService.updateById(equipmentDesc);
  143. // return JsonMessage.success("心跳成功");
  144. return "心跳成功";
  145. }
  146. // return JsonMessage.error("心跳失败");
  147. return "心跳失败";
  148. }
  149. /**
  150. * 设备申请
  151. *
  152. * @param clientId 个推
  153. * @param managerId 管理系统id
  154. * @return
  155. */
  156. @ApiOperation(value = "设备申请")
  157. @RequestMapping(value = "/initNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  158. @ResponseBody
  159. public String initNew(String clientId, String managerId, String gtClientId, String equimentType) {
  160. String machineType = "0";
  161. String status = "0";
  162. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  163. query.like(TEquipment::getClientId,clientId);
  164. List<TEquipment> list = equipmentService.list(query);
  165. if (list.size() > 0) {
  166. TEquipment equipment = list.get(0);
  167. if(equipment.getAdminId()!=31){
  168. if(!equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()).equals("xxx")){
  169. String managerId1 = equipment.getManagerId();
  170. if(!managerId.equals(managerId1)){
  171. return "该设备未脱离";
  172. }else {
  173. return "该设备已经初始化";
  174. }
  175. }
  176. }else {
  177. status = "1";
  178. }
  179. }
  180. if (StringUtils.isEmpty(gtClientId)) {
  181. return "设备不能为空";
  182. }
  183. LambdaQueryWrapper<TEquipmentApply> query1 = Wrappers.lambdaQuery();
  184. query1.eq(TEquipmentApply::getClientId,clientId);
  185. query1.eq(TEquipmentApply::getStatusType,"1");
  186. query1.eq(TEquipmentApply::getManagerId,managerId);
  187. String dateStr = "2022-12-28 00:00:00";
  188. //获得SimpleDateFormat类,我们转换为yyyy-MM-dd的时间格式
  189. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  190. try {
  191. //使用SimpleDateFormat的parse()方法生成Date
  192. Date date = sf.parse(dateStr);
  193. query1.gt(TEquipmentApply::getCreateDate,date);
  194. } catch (ParseException e) {
  195. e.printStackTrace();
  196. }
  197. List<TEquipmentApply> list1 = equipmentApplyService.list(query1);
  198. if(list1.size()>0){
  199. return "重复申请";
  200. }
  201. TEquipmentApply equipmentApply = new TEquipmentApply();
  202. equipmentApply.setStatusType(1);
  203. equipmentApply.setClientId(clientId);
  204. equipmentApply.setManagerId(managerId);
  205. equipmentApply.setGtClientId(gtClientId);
  206. Long adminId = AdminUtils.decrypt(false, managerId);
  207. TAdmin admin = adminService.getById(adminId);
  208. if (admin == null) {
  209. return "找不到商家";
  210. }
  211. //所属商家
  212. String username = admin.getUsername();
  213. equipmentApply.setAdminId(adminId);
  214. equipmentApply.setAdminUserName(username);
  215. equipmentApply.setEquimentType(equimentType);
  216. equipmentApply.setMachineType(machineType);
  217. equipmentApply.setCreateDate(new Date());
  218. equipmentApply.setModifyDate(new Date());
  219. equipmentApplyService.save(equipmentApply);
  220. if(status.equals("1")||String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
  221. Long id = equipmentApply.getId();
  222. agree(id);
  223. return "设备申请成功";
  224. }
  225. if(admin.getApplyStartTime()!=null&&admin.getApplyEndTime()!=null){
  226. Date applyStartTime = admin.getApplyStartTime();
  227. Date applyEndTime = admin.getApplyEndTime();
  228. Date now = new Date();
  229. if(now.getTime()>applyStartTime.getTime()&&now.getTime()<applyEndTime.getTime()){
  230. Long id = equipmentApply.getId();
  231. agree(id);
  232. return "设备申请成功";
  233. }
  234. }
  235. return "设备申请中,请耐心等待";
  236. }
  237. private void agree(Long id) {
  238. String status = "agreed";
  239. if (null != id) {
  240. TEquipmentApply equipmentApply = equipmentApplyService.getById(id);
  241. Integer statusType = equipmentApply.getStatusType();
  242. if(statusType>1){
  243. equipmentApply = null;
  244. }
  245. if (equipmentApply != null) {
  246. if (!StringUtils.isEmpty(status)) {
  247. if (status.equals("agreed")) {
  248. String clientId = equipmentApply.getClientId();
  249. //判断是否设备初始化
  250. Long adminId = equipmentApply.getAdminId();
  251. String adminLevel = equipmentApply.getAdminLevel();
  252. String adminUserName = equipmentApply.getAdminUserName();
  253. String gtClientId = equipmentApply.getGtClientId();
  254. String equimentType = equipmentApply.getEquimentType();
  255. String machineType = equipmentApply.getMachineType();
  256. String old = "";
  257. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  258. query.like(TEquipment::getClientId,clientId+"xxx");
  259. List<TEquipment> list = equipmentService.list(query);
  260. LambdaQueryWrapper<TEquipment> query0 = Wrappers.lambdaQuery();
  261. query0.eq(TEquipment::getClientId,clientId);
  262. List<TEquipment> list2 = equipmentService.list(query0);
  263. equipmentApply.setStatusType(3);
  264. if (list.size() > 0||list2.size()>0) {
  265. //表示设备第二次申请了:主要为了区分脱离以及初始化
  266. old = "1";
  267. //重新修改设备名称
  268. // TEquipment equipment = list.get(0);
  269. TEquipment equipment = new TEquipment();
  270. if(list2.size()>0){
  271. equipment = list2.get(0);
  272. }else {
  273. equipment = list.get(0);
  274. }
  275. equipment.setClientId(clientId);
  276. equipment.setGtClientId(gtClientId);
  277. equipment.setAdminId(adminId);
  278. equipment.setAdminLevel(adminLevel);
  279. equipment.setAdminUserName(adminUserName);
  280. equipment.setMachineType(machineType);
  281. if(equipmentApply.getEquimentType().equals("MG320-1")){
  282. if(!equipmentApply.getEquimentType().equals(equipment.getEquimentType())&&equipment.getEquimentType().equals("MG320")){
  283. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  284. queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
  285. List<TProduct> productList = productService.list(queryProduct);
  286. if(productList.size()==18){
  287. //从18种变成30种花型
  288. saveProductMG12(equipment.getId());
  289. }
  290. //从18种变成30种花型
  291. // saveProductMG12(equipment.getId());
  292. }
  293. equipment.setEquimentType("MG320");
  294. }
  295. if(equipmentApply.getEquimentType().equals("MG330")){
  296. equipment.setEquimentType("MG330");
  297. }
  298. equipmentService.updateById(equipment);
  299. LambdaQueryWrapper<TProportion> queryProportion = Wrappers.lambdaQuery();
  300. queryProportion.eq(TProportion::getEquipmentId,equipment.getId());
  301. List<TProportion> list1 = proportionService.list(queryProportion);
  302. if(list1.size()>0){
  303. for(TProportion proportion:list1){
  304. proportionService.removeById(proportion.getId());
  305. }
  306. }
  307. // if(String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
  308. // //自动设置分销
  309. // setProportion(adminId,equipment.getId(),clientId);
  310. // }
  311. try {
  312. esTEquipmentService.updateDataById(equipment);
  313. }catch (Exception e) {
  314. e.printStackTrace();
  315. }
  316. equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
  317. PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  318. if(equipment.getEquimentType().equals("280")){
  319. equipmentService.sentMessage(clientId,PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
  320. PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
  321. }
  322. }else{
  323. TEquipment equipment = new TEquipment();
  324. equipment.setCreateDate(new Date());
  325. equipment.setModifyDate(new Date());
  326. equipment.setClientId(clientId);
  327. equipment.setManagerId(equipmentApply.getManagerId());
  328. equipment.setAdminId(adminId);
  329. equipment.setAdminLevel(adminLevel);
  330. equipment.setGtClientId(gtClientId);
  331. equipment.setAdminUserName(adminUserName);
  332. equipment.setIsUsing(true);
  333. equipment.setIsNetWork(true);
  334. equipment.setGuestPwd("123456");
  335. equipment.setAdminPwd("123456");
  336. equipment.setChannel("1");
  337. equipment.setProductTotal(0);
  338. //设置默认规则
  339. equipment.setTimeRuleId(Long.valueOf(1));
  340. if(equimentType.equals("MG320-1")){
  341. equipment.setEquimentType("MG320");
  342. }else {
  343. equipment.setEquimentType(equimentType);
  344. }
  345. if(equipmentApply.getEquimentType().equals("MG330")){
  346. equipment.setEquimentType("MG330");
  347. }
  348. if(!StringUtils.isEmpty(equimentType)&&equimentType.equals("MG280")){
  349. Long monthBegin = getMonthBegin(new Date());
  350. long time = new Date().getTime();
  351. if(time<monthBegin){
  352. equipment.setEndDate(new Date(monthBegin));
  353. }else{
  354. Date date = nextMonthDate();
  355. equipment.setEndDate(date);
  356. }
  357. equipmentService.sentMessage(clientId,PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
  358. PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
  359. }
  360. equipmentService.save(equipment);
  361. equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
  362. PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
  363. // Equipment byClientId = equipmentService.findByClientId(equipment.getClientId());
  364. // String data = com.alibaba.fastjson.JSON.toJSONString(byClientId);
  365. LambdaQueryWrapper<TEquipment> query3 = Wrappers.lambdaQuery();
  366. query3.eq(TEquipment::getClientId,clientId);
  367. List<TEquipment> list1 = equipmentService.list(query3);
  368. try {
  369. if(list1.size()>0){
  370. TEquipment tEquipment = list1.get(0);
  371. esTEquipmentService.insertData(tEquipment);
  372. }
  373. }catch (Exception e) {
  374. e.printStackTrace();
  375. }
  376. TEquipmentDesc equipmentDesc = new TEquipmentDesc();
  377. equipmentDesc.setEquipmentId(list1.get(0).getId());
  378. equipmentDescService.save(equipmentDesc);
  379. }
  380. //获取设备的id
  381. // Long equipmentId = equipmentService.findByClientId(clientId).getId();
  382. LambdaQueryWrapper<TEquipment> query1 = Wrappers.lambdaQuery();
  383. query1.eq(TEquipment::getClientId,clientId);
  384. List<TEquipment> list1 = equipmentService.list(query1);
  385. Long equipmentId = list1.get(0).getId();
  386. // if (!productService.exists(Filter.eq("equipmentId", equipmentId))) {
  387. if (true) {
  388. if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG280")){
  389. saveProductMG280(equipmentId);
  390. }else if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG320-1")){
  391. saveProductMG1(equipmentId);
  392. } else{
  393. saveProduct(equipmentId);
  394. }
  395. }
  396. if(String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
  397. //自动设置分销
  398. setProportion(adminId,equipmentId,clientId);
  399. }
  400. } else if (status.equals("rejected")) {
  401. equipmentApply.setStatusType(2);
  402. equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("statusType", "rejected").toString());
  403. // PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "拒绝", PushUtils.buildJson("statusType", "rejected").toString());
  404. }
  405. equipmentApplyService.updateById(equipmentApply);
  406. }
  407. }
  408. }
  409. }
  410. private void setProportion(Long adminId,Long equipmentId,String clientId) {
  411. //先找到原账户的分销
  412. LambdaQueryWrapper<TProportion> query3 = Wrappers.lambdaQuery();
  413. query3.eq(TProportion::getAdminId,adminId);
  414. List<TProportion> list3 = proportionService.list(query3);
  415. if(list3.size()>0){
  416. TProportion adminProportion = list3.get(0);
  417. if(StringUtils.isEmpty(adminProportion.getClientId())){
  418. TProportion equipmentProportion = new TProportion();
  419. equipmentProportion.setCreateDate(new Date());
  420. equipmentProportion.setModifyDate(new Date());
  421. equipmentProportion.setAdminId(adminId);
  422. equipmentProportion.setClientId(clientId);
  423. equipmentProportion.setEquipmentId(equipmentId);
  424. equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
  425. Integer type = adminProportion.getType();
  426. if(type!=null){
  427. switch (type) {
  428. case 1:
  429. equipmentProportion.setProportion(adminProportion.getAgencyProportion());
  430. equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
  431. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  432. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  433. equipmentProportion.setType(0);
  434. break;
  435. case 2:
  436. equipmentProportion.setProportion(adminProportion.getMerchantProportion());
  437. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  438. // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
  439. // equipmentProportion.setAgencyId(admin.getAgencyId());
  440. // TAdmin byId = adminService.getById(admin.getAgencyId());
  441. // equipmentProportion.setAgencyName(byId.getUsername());
  442. // }
  443. equipmentProportion.setAgencyId(adminProportion.getAgencyId());
  444. TAdmin byId = adminService.getById(adminProportion.getAgencyId());
  445. equipmentProportion.setAgencyName(byId.getUsername());
  446. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  447. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  448. equipmentProportion.setType(1);
  449. break;
  450. case 3:
  451. equipmentProportion.setProportion(adminProportion.getPersonageProportion());
  452. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  453. // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
  454. // equipmentProportion.setAgencyId(admin.getAgencyId());
  455. // TAdmin byId = adminService.getById(admin.getAgencyId());
  456. // equipmentProportion.setAgencyName(byId.getUsername());
  457. // }
  458. equipmentProportion.setAgencyId(adminProportion.getAgencyId());
  459. TAdmin byId1 = adminService.getById(adminProportion.getAgencyId());
  460. equipmentProportion.setAgencyName(byId1.getUsername());
  461. equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
  462. // if(adminProportion.getMerchantProportion().compareTo(new BigDecimal("0.00"))!=0){
  463. // equipmentProportion.setMerchantId(admin.getMerchantId());
  464. // TAdmin byId = adminService.getById(admin.getMerchantId());
  465. // equipmentProportion.setMerchantName(byId.getUsername());
  466. // }
  467. equipmentProportion.setMerchantId(adminProportion.getMerchantId());
  468. TAdmin byId2 = adminService.getById(adminProportion.getMerchantId());
  469. equipmentProportion.setMerchantName(byId2.getUsername());
  470. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  471. equipmentProportion.setType(2);
  472. break;
  473. }
  474. boolean save = proportionService.save(equipmentProportion);
  475. }
  476. }
  477. }
  478. }
  479. /**
  480. * 添加产品
  481. *
  482. * @param id
  483. */
  484. private void saveProduct(Long id) {
  485. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
  486. "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18"};
  487. for (int i = 0; i < str.length; i++) {
  488. TProduct product = new TProduct();
  489. product.setCreateDate(new Date());
  490. product.setModifyDate(new Date());
  491. product.setEquipmentId(id);
  492. String[] split = str[i].split("-");
  493. product.setProductName(split[0]);
  494. product.setNo(split[1]);
  495. product.setRmbPrice(BigDecimal.ZERO);
  496. product.setCodePrice(BigDecimal.ZERO);
  497. productService.save(product);
  498. }
  499. }
  500. private void saveProductMG280(Long id) {
  501. String[] str = { "水中芙蓉-A05", "水中芙蓉mini-A31", "烈焰红唇-A06", "烈焰红唇mini-A32", "夏日爱恋-A11", "夏日爱恋mini-A33", "冰美人-A12", "冰美人mini-A34", "彩色精灵-A17", "彩色精灵mini-A35"};
  502. for (int i = 0; i < str.length; i++) {
  503. TProduct product = new TProduct();
  504. product.setCreateDate(new Date());
  505. product.setModifyDate(new Date());
  506. product.setEquipmentId(id);
  507. String[] split = str[i].split("-");
  508. product.setProductName(split[0]);
  509. product.setNo(split[1]);
  510. product.setRmbPrice(BigDecimal.ZERO);
  511. product.setCodePrice(BigDecimal.ZERO);
  512. productService.save(product);
  513. }
  514. }
  515. private void saveProductMG1(Long id) {
  516. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
  517. "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
  518. "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24","坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28",
  519. "花样年华-A29","心花怒放-A30"};
  520. for (int i = 0; i < str.length; i++) {
  521. TProduct product = new TProduct();
  522. product.setCreateDate(new Date());
  523. product.setModifyDate(new Date());
  524. product.setEquipmentId(id);
  525. String[] split = str[i].split("-");
  526. product.setProductName(split[0]);
  527. product.setNo(split[1]);
  528. product.setRmbPrice(BigDecimal.ZERO);
  529. product.setCodePrice(BigDecimal.ZERO);
  530. productService.save(product);
  531. }
  532. }
  533. private void saveProductMG12(Long id) {
  534. String[] str = { "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24"
  535. ,"坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28","花样年华-A29","心花怒放-A30"};
  536. for (int i = 0; i < str.length; i++) {
  537. TProduct product = new TProduct();
  538. product.setEquipmentId(id);
  539. product.setCreateDate(new Date());
  540. product.setModifyDate(new Date());
  541. String[] split = str[i].split("-");
  542. product.setProductName(split[0]);
  543. product.setNo(split[1]);
  544. product.setRmbPrice(BigDecimal.ZERO);
  545. product.setCodePrice(BigDecimal.ZERO);
  546. productService.save(product);
  547. }
  548. }
  549. private void saveProductMG22(Long id) {
  550. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
  551. "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28"};
  552. for (int i = 0; i < str.length; i++) {
  553. TProduct product = new TProduct();
  554. product.setCreateDate(new Date());
  555. product.setModifyDate(new Date());
  556. product.setEquipmentId(id);
  557. String[] split = str[i].split("-");
  558. product.setProductName(split[0]);
  559. product.setNo(split[1]);
  560. product.setRmbPrice(BigDecimal.ZERO);
  561. product.setCodePrice(BigDecimal.ZERO);
  562. productService.save(product);
  563. }
  564. }
  565. private void saveProductMG26(Long id) {
  566. String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
  567. "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28",
  568. "夏日倾城-A20", "雪花飞舞-A26", "豆蔻年华-A23", "花样年华-A29"};
  569. for (int i = 0; i < str.length; i++) {
  570. TProduct product = new TProduct();
  571. product.setCreateDate(new Date());
  572. product.setModifyDate(new Date());
  573. product.setEquipmentId(id);
  574. String[] split = str[i].split("-");
  575. product.setProductName(split[0]);
  576. product.setNo(split[1]);
  577. product.setRmbPrice(BigDecimal.ZERO);
  578. product.setCodePrice(BigDecimal.ZERO);
  579. productService.save(product);
  580. }
  581. }
  582. /**
  583. * 获取指定日期所在月份开始的时间戳
  584. * @param date 指定日期
  585. * @return
  586. */
  587. public static Long getMonthBegin(Date date) {
  588. Calendar c = Calendar.getInstance();
  589. c.setTime(date);
  590. //设置为10号,当前日期既为本月10号
  591. c.set(Calendar.DAY_OF_MONTH, 10);
  592. //将小时至0
  593. c.set(Calendar.HOUR_OF_DAY, 0);
  594. //将分钟至0
  595. c.set(Calendar.MINUTE, 0);
  596. //将秒至0
  597. c.set(Calendar.SECOND,0);
  598. //将毫秒至0
  599. c.set(Calendar.MILLISECOND, 0);
  600. // 获取本月第一天的时间戳
  601. return c.getTimeInMillis();
  602. }
  603. public static Date nextMonthDate() {
  604. Calendar calendar = Calendar.getInstance();
  605. calendar.set(Calendar.DAY_OF_MONTH,10);
  606. //将小时至0
  607. calendar.set(Calendar.HOUR_OF_DAY, 0);
  608. //将分钟至0
  609. calendar.set(Calendar.MINUTE, 0);
  610. //将秒至0
  611. calendar.set(Calendar.SECOND,0);
  612. //将毫秒至0
  613. calendar.set(Calendar.MILLISECOND, 0);
  614. calendar.add(Calendar.MONTH,1);
  615. return calendar.getTime();
  616. }
  617. /**
  618. *改花型
  619. * @param
  620. * @return
  621. */
  622. @RequestMapping(value = "/updateFlowers.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  623. @ResponseBody
  624. public String updateFlowers(String clientId,String number){
  625. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  626. query.eq(TEquipment::getClientId,clientId);
  627. List<TEquipment> list = equipmentService.list(query);
  628. TEquipment equipment = list.get(0);
  629. if(equipment!=null){
  630. Long id = equipment.getId();
  631. //修改花型记录数目
  632. TEquipmentDesc equipmentDesc = equipmentDescService.getById(id);
  633. if(equipmentDesc!=null){
  634. equipmentDesc.setFlowers(number);
  635. equipmentDescService.updateById(equipmentDesc);
  636. }else {
  637. TEquipmentDesc equipmentDesc1 = new TEquipmentDesc();
  638. equipmentDesc1.setEquipmentId(id);
  639. equipmentDesc1.setFlowers(number);
  640. equipmentDescService.save(equipmentDesc1);
  641. }
  642. //删除旧花型
  643. // List<Filter> filters = new ArrayList<>();
  644. // filters.add(Filter.eq("equipmentId", id));
  645. // List<Product> list = productService.findList(null, filters, null);
  646. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  647. queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
  648. List<TProduct> productList = productService.list(queryProduct);
  649. for(TProduct product : productList){
  650. productService.removeById(product.getId());
  651. }
  652. //创建花型
  653. if(number.equals("18")){
  654. saveProduct(id);
  655. }
  656. if(number.equals("22")){
  657. saveProductMG22(id);
  658. }
  659. if(number.equals("26")){
  660. saveProductMG26(id);
  661. }
  662. if(number.equals("30")){
  663. saveProductMG1(id);
  664. }
  665. // return JsonMessage.success("success");
  666. return "success";
  667. }else {
  668. // return JsonMessage.success("error");
  669. return "error";
  670. }
  671. }
  672. /**
  673. * 设备类型 开机时上传
  674. *
  675. * @param clientId 个推
  676. * @return
  677. */
  678. @RequestMapping(value = "/equimentType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  679. @ResponseBody
  680. public String equimentType(String clientId, String equimentType){
  681. if(!StringUtils.isEmpty(equimentType)){
  682. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  683. query.eq(TEquipment::getClientId,clientId);
  684. List<TEquipment> list = equipmentService.list(query);
  685. TEquipment equipment = list.get(0);
  686. equipment.setEquimentType(equimentType);
  687. equipmentService.updateById(equipment);
  688. }
  689. // return JsonMessage.success("success");
  690. return "success";
  691. }
  692. /**
  693. * 设备地址 开机时上传
  694. * @param clientId 个推
  695. * @return
  696. */
  697. @RequestMapping(value = "/equimentArea.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  698. @ResponseBody
  699. public String equimentArea(String clientId, String longitude, String latitude, String fullName){
  700. if(!StringUtils.isEmpty(longitude)&&!StringUtils.isEmpty(latitude)&&!StringUtils.isEmpty(fullName)){
  701. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  702. query.eq(TEquipment::getClientId,clientId);
  703. List<TEquipment> list = equipmentService.list(query);
  704. TEquipment equipment = list.get(0);
  705. equipment.setLatitude(Double.valueOf(latitude));
  706. equipment.setLongitude(Double.valueOf(longitude));
  707. equipment.setFullName(fullName+"-");
  708. equipmentService.updateById(equipment);
  709. // return JsonMessage.success("success");
  710. return "success";
  711. }
  712. // return JsonMessage.success("error");
  713. return "error";
  714. }
  715. /**
  716. * 商品调价
  717. */
  718. @RequestMapping(value = "/updateProduct.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  719. @ResponseBody
  720. public String updateProduct(@RequestBody List<ProductVo> productVos) {
  721. Double f=0.00;
  722. int num=0;
  723. int n=0;
  724. HashSet<Double> price = new HashSet<Double>();
  725. HashSet<Double> minprice = new HashSet<Double>();
  726. for (ProductVo product : productVos) {
  727. String clientId = product.getClientId();
  728. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  729. query.eq(TEquipment::getClientId,clientId);
  730. List<TEquipment> list = equipmentService.list(query);
  731. TEquipment equipment = list.get(0);
  732. Long id = equipment.getId();
  733. if(StringUtils.isNotEmpty(product.getShowType())){
  734. // productService.updateByClientID2(id, product.getRmbPrice(), product.getCodePrice(), product.getProductName(), product.getSellStatus(),product.getShowType());
  735. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  736. queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
  737. queryProduct.eq(TProduct::getProductName,product.getProductName());
  738. List<TProduct> productList = productService.list(queryProduct);
  739. TProduct tProduct = productList.get(0);
  740. tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
  741. tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
  742. tProduct.setShowType(product.getShowType());
  743. tProduct.setSellStatus(product.getSellStatus());
  744. productService.updateById(tProduct);
  745. }else {
  746. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  747. queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
  748. queryProduct.eq(TProduct::getProductName,product.getProductName());
  749. List<TProduct> productList = productService.list(queryProduct);
  750. TProduct tProduct = productList.get(0);
  751. tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
  752. tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
  753. tProduct.setSellStatus(product.getSellStatus());
  754. productService.updateById(tProduct);
  755. // productService.updateByClientID(id, product.getRmbPrice(), product.getCodePrice(), product.getProductName(), product.getSellStatus());
  756. }
  757. }
  758. // return JsonMessage.success("调价成功");
  759. return "调价成功";
  760. }
  761. public Double tran(Double d){
  762. return new BigDecimal(d).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  763. }
  764. public Double tran2(Double d){
  765. return new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  766. }
  767. /**
  768. * 密码修改
  769. *
  770. * @param clientId 设备个推Id
  771. * @param pwdType 密码类型 1d代表修adminPwd,0代表guestPwd
  772. * @return
  773. * @Param pwd 密码内容
  774. */
  775. @RequestMapping(value = "/updatePwd.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  776. @ResponseBody
  777. public String updatePwd(String clientId, String pwdType, String pwd) {
  778. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  779. query.eq(TEquipment::getClientId,clientId);
  780. List<TEquipment> list = equipmentService.list(query);
  781. TEquipment equipment = list.get(0);
  782. if (equipment != null) {
  783. if (!StringUtils.isEmpty(pwdType)) {
  784. switch (pwdType) {
  785. case "1":
  786. equipment.setAdminPwd(pwd);
  787. break;
  788. case "0":
  789. equipment.setGuestPwd(pwd);
  790. break;
  791. }
  792. equipmentService.updateById(equipment);
  793. // return JsonMessage.success("更新密码成功");
  794. return "更新密码成功";
  795. }
  796. }
  797. // return JsonMessage.error("更新密码失败");
  798. return "更新密码失败";
  799. }
  800. /**
  801. * 设备获取密码
  802. */
  803. @GetMapping(value = "/getPwd", produces = "text/html;charset=utf-8")
  804. @ResponseBody
  805. public String getPwd(String clientId) {
  806. if(StringUtils.isEmpty(clientId)){
  807. return null;
  808. }
  809. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  810. query.eq(TEquipment::getClientId,clientId);
  811. List<TEquipment> list = equipmentService.list(query);
  812. TEquipment equipment = list.get(0);
  813. Map<String,String> map = new HashMap<>();
  814. // map.put("adminUserName",equipment.getAdminUserName());
  815. map.put("adminPwd",equipment.getAdminPwd());
  816. map.put("guestPwd",equipment.getGuestPwd());
  817. JSONObject jsonObject = new JSONObject();
  818. jsonObject.put("code", 0);
  819. jsonObject.put("data", JSONObject.toJSON(map).toString());
  820. jsonObject.put("errmsg", "");
  821. return jsonObject.toJSONString();
  822. }
  823. /**
  824. * 修改支付方式
  825. *
  826. * @param clientId
  827. * @param payType: 无需支付
  828. * 线上支付
  829. * 线下支付
  830. * 线上/线下
  831. * @return
  832. */
  833. @RequestMapping(value = "/updatePayType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  834. @ResponseBody
  835. public String updatePayType(String clientId, String payType) {
  836. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  837. query.eq(TEquipment::getClientId,clientId);
  838. List<TEquipment> list = equipmentService.list(query);
  839. TEquipment equipment = list.get(0);
  840. if (equipment == null) {
  841. // return JsonMessage.error("修改支付方式失败");
  842. return "修改支付方式失败";
  843. }
  844. equipment.setPayType(0);
  845. equipmentService.updateById(equipment);
  846. return "修改成功";
  847. // return JsonMessage.success("修改成功");
  848. }
  849. /**
  850. * 日志上传
  851. */
  852. @RequestMapping(value = "/sendLog.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  853. @ResponseBody
  854. public String uploadFile(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception{
  855. // String fileName = request.getParameter("fileName");
  856. // log.info("filename:"+fileName);
  857. // String fileName ="shafei.xls";
  858. // file1.length();
  859. // String name = request.getParameter("inputName");
  860. String fileFullPath = "/home/hboxs/log/" + fileName+".txt";
  861. // String fileFullPath = "/root/uploadfile/apache-tomcat-8.5.42/" + fileName;
  862. InputStream input = null;
  863. FileOutputStream fos = null;
  864. try {
  865. input = request.getInputStream();
  866. File file = new File("/home/hboxs/log/");
  867. if(!file.exists()){
  868. file.mkdirs();
  869. }
  870. fos = new FileOutputStream(fileFullPath);
  871. int size = 0;
  872. byte[] buffer = new byte[1024];
  873. while ((size = input.read(buffer,0,1024)) != -1) {
  874. fos.write(buffer, 0, size);
  875. }
  876. //响应信息 json字符串格式
  877. Map<String,Object> responseMap = new HashMap<String,Object>();
  878. responseMap.put("flag", true);
  879. //生成响应的json字符串
  880. String jsonResponse = JSONObject.toJSONString(responseMap);
  881. sendResponse(jsonResponse,response);
  882. } catch (IOException e) {
  883. //响应信息 json字符串格式
  884. Map<String,Object> responseMap = new HashMap<String,Object>();
  885. responseMap.put("flag", false);
  886. responseMap.put("errorMsg", e.getMessage());
  887. String jsonResponse = JSONObject.toJSONString(responseMap);
  888. sendResponse(jsonResponse,response);
  889. } finally{
  890. if(input != null){
  891. input.close();
  892. }
  893. if(fos != null){
  894. fos.close();
  895. }
  896. }
  897. return null;
  898. }
  899. /**
  900. * 返回响应
  901. *
  902. * @throws Exception
  903. */
  904. private void sendResponse(String responseString,HttpServletResponse response) throws Exception {
  905. response.setContentType("application/json;charset=UTF-8");
  906. PrintWriter pw = null;
  907. try {
  908. pw = response.getWriter();
  909. pw.write(responseString);
  910. pw.flush();
  911. } finally {
  912. IOUtils.closeQuietly(pw);
  913. }
  914. }
  915. /**
  916. * 脱离系统
  917. *
  918. * @param clientId
  919. * @return
  920. */
  921. @RequestMapping(value = "/separate.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  922. @ResponseBody
  923. public String separate(String clientId) {
  924. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  925. query.eq(TEquipment::getClientId,clientId);
  926. List<TEquipment> list = equipmentService.list(query);
  927. TEquipment equipment = list.get(0);
  928. if (equipment == null) {
  929. // return "该设备不存在";
  930. return "该设备不存在";
  931. }
  932. equipmentService.sentMessage(clientId,PushUtils.buildJson("tuoji", "0").toString());
  933. // PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("tuoji", "0").toString());
  934. if("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()))){
  935. // return JsonMessage.success("脱离成功");
  936. return "脱离成功";
  937. }
  938. equipment.setClientId(equipment.getClientId() + "xxx");
  939. equipmentService.updateById(equipment);
  940. // return JsonMessage.success("脱离成功");
  941. return "脱离成功";
  942. }
  943. /**
  944. * 脱离系统
  945. *
  946. * @param clientId
  947. * @return
  948. */
  949. @RequestMapping(value = "/updateClientId", method = RequestMethod.POST)
  950. @ResponseBody
  951. public String updateClientId(String clientId) {
  952. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  953. query.eq(TEquipment::getClientId,clientId);
  954. List<TEquipment> list = equipmentService.list(query);
  955. TEquipment equipment = list.get(0);
  956. if (equipment == null) {
  957. return "该设备不存在";
  958. }
  959. // equipmentService.sentMessage(clientId,PushUtils.buildJson("tuoji", "0").toString());
  960. // PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("tuoji", "0").toString());
  961. if("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()))){
  962. return "脱离成功";
  963. }
  964. equipment.setClientId(equipment.getClientId() + "xxx");
  965. equipment.setManagerId(null);
  966. equipmentService.updateById(equipment);
  967. return "脱离成功";
  968. }
  969. /**
  970. * 修改设备联系人名称以及电话
  971. */
  972. @RequestMapping(value = "/updateContractPN.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  973. @ResponseBody
  974. public String updateContractPN(String clientId, String contactName, String contactPhone) {
  975. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  976. query.eq(TEquipment::getClientId,clientId);
  977. List<TEquipment> list = equipmentService.list(query);
  978. TEquipment equipment = list.get(0);
  979. if (equipment == null) {
  980. // return JsonMessage.error("该设备不存在");
  981. return "该设备不存在";
  982. }
  983. equipment.setContactName(contactName);
  984. equipment.setContactPhone(contactPhone);
  985. equipmentService.updateById(equipment);
  986. // return JsonMessage.success("修改成功");
  987. return "修改成功";
  988. }
  989. /**
  990. * 设备上传公司电话
  991. */
  992. @RequestMapping(value = "/sentCompanyPhone.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  993. @ResponseBody
  994. public String sentCompanyPhone(String clientId, String companyPhone) {
  995. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  996. query.eq(TEquipment::getClientId,clientId);
  997. List<TEquipment> list = equipmentService.list(query);
  998. TEquipment equipment = list.get(0);
  999. if (equipment == null) {
  1000. // return JsonMessage.error("该设备不存在");
  1001. return "该设备不存在";
  1002. }
  1003. equipment.setCompanyPhone(companyPhone);
  1004. equipmentService.updateById(equipment);
  1005. // return JsonMessage.success("修改成功");
  1006. return "修改成功";
  1007. }
  1008. /**
  1009. * 获取二维码图片
  1010. */
  1011. @RequestMapping(value = "/getQrCodeImgUrl.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1012. @ResponseBody
  1013. public String getQrCodeImgUrl(String clientId) {
  1014. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1015. query.eq(TEquipment::getClientId,clientId);
  1016. List<TEquipment> list = equipmentService.list(query);
  1017. TEquipment equipment = list.get(0);
  1018. if (equipment == null) {
  1019. return "404";
  1020. }
  1021. return "400";
  1022. }
  1023. /**
  1024. * 上传4G卡号
  1025. */
  1026. @RequestMapping(value = "/sentSimNo.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1027. @ResponseBody
  1028. public String sentSimNo(String clientId, String simNo) {
  1029. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1030. query.eq(TEquipment::getClientId,clientId);
  1031. List<TEquipment> list = equipmentService.list(query);
  1032. TEquipment equipment = list.get(0);
  1033. if (equipment == null) {
  1034. // return JsonMessage.error("该设备不存在");
  1035. return "该设备不存在";
  1036. }
  1037. equipment.setSimNo(simNo);
  1038. equipmentService.updateById(equipment);
  1039. // return JsonMessage.success("修改成功");
  1040. return "修改成功";
  1041. }
  1042. /**
  1043. * 上传机器的apk版本
  1044. */
  1045. @RequestMapping(value = "/sendApkVersion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1046. @ResponseBody
  1047. public String sendApkVersion(String clientId, String apkVersion) {
  1048. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1049. query.eq(TEquipment::getClientId,clientId);
  1050. List<TEquipment> list = equipmentService.list(query);
  1051. TEquipment equipment = list.get(0);
  1052. if (equipment == null) {
  1053. return "该设备不存在";
  1054. }
  1055. equipment.setApkVersion(apkVersion);
  1056. equipmentService.updateById(equipment);
  1057. return "success";
  1058. }
  1059. /**
  1060. * 上传机器的做糖状态
  1061. */
  1062. @RequestMapping(value = "/equipmentStatus.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1063. @ResponseBody
  1064. public String equipmentStatus(String clientId, String status) {
  1065. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1066. query.eq(TEquipment::getClientId,clientId);
  1067. List<TEquipment> list = equipmentService.list(query);
  1068. TEquipment equipment = list.get(0);
  1069. if (equipment == null) {
  1070. return "该设备不存在";
  1071. }
  1072. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1073. //机器状态;0:空闲,1:在做糖;
  1074. equipmentDesc.setStatus(status);
  1075. equipmentDescService.updateById(equipmentDesc);
  1076. return "success";
  1077. }
  1078. /**
  1079. * 修改设备状态
  1080. *
  1081. * @param clientId
  1082. * @param eqeStatus 设备状态1开 0关
  1083. * @return
  1084. */
  1085. @RequestMapping(value = "/updateEqeStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1086. @ResponseBody
  1087. public String updateEqeStatus(String clientId, Integer eqeStatus) {
  1088. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1089. query.eq(TEquipment::getClientId,clientId);
  1090. List<TEquipment> list = equipmentService.list(query);
  1091. TEquipment equipment = list.get(0);
  1092. if (equipment == null) {
  1093. return "该设备不存在";
  1094. }
  1095. if(eqeStatus!=null){
  1096. equipment.setEqeStatus(eqeStatus);
  1097. equipment.setModifyDate(new Date());
  1098. equipmentService.updateById(equipment);
  1099. }
  1100. return "修改成功";
  1101. }
  1102. /**
  1103. * 新修改设备状态
  1104. *
  1105. * @param clientId
  1106. * @param eqeStatus 设备状态1开 0关
  1107. * @return
  1108. */
  1109. @RequestMapping(value = "/updateEqeStatusNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1110. @ResponseBody
  1111. public String updateEqeStatusNew(String clientId, Integer eqeStatus,String netTime) {
  1112. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1113. query.eq(TEquipment::getClientId,clientId);
  1114. List<TEquipment> list = equipmentService.list(query);
  1115. TEquipment equipment = list.get(0);
  1116. if (equipment == null) {
  1117. // return JsonMessage.error("该设备不存在");
  1118. return "该设备不存在";
  1119. }
  1120. if(eqeStatus!=null){
  1121. equipment.setNetwork(netTime);
  1122. equipment.setEqeStatus(eqeStatus);
  1123. equipmentService.updateById(equipment);
  1124. }
  1125. // return JsonMessage.success("修改成功");
  1126. return "修改成功";
  1127. }
  1128. /**
  1129. * 修改设备锁定状态
  1130. *
  1131. * @param clientId
  1132. * @param block
  1133. * @return
  1134. */
  1135. @RequestMapping(value = "/updateBlock.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1136. @ResponseBody
  1137. public String updateBlock(String clientId, Boolean block) {
  1138. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1139. query.eq(TEquipment::getClientId,clientId);
  1140. List<TEquipment> list = equipmentService.list(query);
  1141. TEquipment equipment = list.get(0);
  1142. if (equipment == null) {
  1143. // return JsonMessage.error("该设备不存在");
  1144. return "该设备不存在";
  1145. }
  1146. equipment.setIsBlocked(block);
  1147. equipmentService.updateById(equipment);
  1148. return "修改成功";
  1149. }
  1150. /**
  1151. * 修改设备睡眠状态
  1152. *
  1153. * @param clientId
  1154. * @param is_sleep
  1155. * @return
  1156. */
  1157. @RequestMapping(value = "/updateSleep.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1158. @ResponseBody
  1159. public String updateSleep(String clientId, Boolean is_sleep) {
  1160. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1161. query.eq(TEquipment::getClientId,clientId);
  1162. List<TEquipment> list = equipmentService.list(query);
  1163. TEquipment equipment = list.get(0);
  1164. if (equipment == null) {
  1165. return "该设备不存在";
  1166. }
  1167. if(is_sleep!=null){
  1168. equipment.setIsSleep(is_sleep);
  1169. equipmentService.updateById(equipment);
  1170. }
  1171. return "修改成功";
  1172. }
  1173. /**
  1174. * 修改设备生产棉花糖个数
  1175. *
  1176. * @param clientId
  1177. * @param productTotal
  1178. * @return
  1179. */
  1180. @RequestMapping(value = "/updateProductTotal.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1181. @ResponseBody
  1182. public String updateProductTotal(String clientId, Integer productTotal) {
  1183. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1184. query.eq(TEquipment::getClientId,clientId);
  1185. List<TEquipment> list = equipmentService.list(query);
  1186. TEquipment equipment = list.get(0);
  1187. if (equipment == null) {
  1188. return "该设备不存在";
  1189. }
  1190. Integer total = equipment.getProductTotal();
  1191. if (total == null) {
  1192. total = 0;
  1193. }
  1194. equipment.setProductTotal(total + productTotal);
  1195. equipmentService.updateById(equipment);
  1196. return "修改成功";
  1197. }
  1198. /**
  1199. * 修改设备共同参数/进阶参数
  1200. *
  1201. * @param
  1202. * @return
  1203. */
  1204. // @PostMapping(value = "/updateParam/{code}/{clientId}", produces = "application/json;charset=UTF-8")
  1205. // @ResponseBody
  1206. // public JsonMessage updateParam(@PathVariable Integer code, @PathVariable String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
  1207. // Equipment equipment = equipmentService.findByClientId(clientId);
  1208. // if (equipment == null) {
  1209. // return JsonMessage.error("设备不存在");
  1210. // }
  1211. // String param = JSONArray.toJSONString(commonParamVos);
  1212. // if (code == 0) {
  1213. // equipment.setCommonParameters(param);
  1214. // } else {
  1215. // equipment.setAdvancedParameters(param);
  1216. // }
  1217. // equipmentService.update(equipment);
  1218. // return JsonMessage.success("修改成功");
  1219. // }
  1220. /**
  1221. * 修改设备共同参数/进阶参数
  1222. * code 0:通用参数;1:进阶参数;2:调试页参数
  1223. * @param
  1224. * @return
  1225. */
  1226. @RequestMapping(value = "/updateParamNew", method = RequestMethod.POST)
  1227. // @PostMapping(value = "/updateParamNew", produces = "text/html;charset=utf-8")
  1228. @ResponseBody
  1229. public String updateParamNew(Integer code, String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
  1230. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1231. query.eq(TEquipment::getClientId,clientId);
  1232. List<TEquipment> list = equipmentService.list(query);
  1233. TEquipment equipment = list.get(0);
  1234. if (equipment == null) {
  1235. return "设备不存在";
  1236. }
  1237. if(commonParamVos.size()<=0){
  1238. return "参数为空";
  1239. }
  1240. LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
  1241. queryParameters.eq(TParameters::getClientId,clientId);
  1242. queryParameters.eq(TParameters::getStatus,code);
  1243. queryParameters.eq(TParameters::getEquipmentId,equipment.getId());
  1244. List<TParameters> list1 = parametersService.list(queryParameters);
  1245. if(list1.size()>0){
  1246. for(TParameters parameters:list1){
  1247. //删除旧的参数
  1248. parametersService.removeById(parameters.getId());
  1249. }
  1250. }
  1251. Date date = new Date();
  1252. for(CommonParamVo commonParamVo:commonParamVos){
  1253. TParameters parameters = new TParameters();
  1254. parameters.setVal(commonParamVo.getVal());
  1255. parameters.setName(commonParamVo.getName());
  1256. parameters.setStatus(String.valueOf(code));
  1257. parameters.setClientId(clientId);
  1258. parameters.setEquipmentId(equipment.getId());
  1259. parameters.setCreateDate(date);
  1260. parameters.setModifyDate(date);
  1261. parametersService.save(parameters);
  1262. }
  1263. return "修改成功";
  1264. }
  1265. /**
  1266. * 修改单个设备共同参数/进阶参数
  1267. * code 0:通用参数;1:进阶参数;2:调试页参数
  1268. * @param
  1269. * @return
  1270. */
  1271. @PostMapping(value = "/updateAloneParam.htm", produces = "text/html;charset=utf-8")
  1272. @ResponseBody
  1273. public String updateAloneParam(String code, String clientId,String name,String val) {
  1274. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1275. query.eq(TEquipment::getClientId,clientId);
  1276. List<TEquipment> list = equipmentService.list(query);
  1277. TEquipment equipment = list.get(0);
  1278. if (equipment == null) {
  1279. // return JsonMessage.error("设备不存在");
  1280. return "设备不存在";
  1281. }
  1282. // ArrayList<Filter> filters = new ArrayList<>();
  1283. // filters.add(Filter.eq("status", code));
  1284. // filters.add(Filter.eq("clientId", clientId));
  1285. // filters.add(Filter.eq("equipmentId", equipment.getId()));
  1286. // filters.add(Filter.eq("name", name));
  1287. // List<Parameters> list = parametersService.findList(null, filters, null);
  1288. LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
  1289. queryParameters.eq(TParameters::getClientId,clientId);
  1290. queryParameters.eq(TParameters::getStatus,code);
  1291. queryParameters.eq(TParameters::getName,name);
  1292. queryParameters.eq(TParameters::getEquipmentId,equipment.getId());
  1293. List<TParameters> list1 = parametersService.list(queryParameters);
  1294. if(list1.size()>0){
  1295. TParameters parameters = list1.get(0);
  1296. parameters.setVal(val);
  1297. parameters.setModifyDate(new Date());
  1298. parametersService.updateById(parameters);
  1299. }
  1300. return "修改成功";
  1301. }
  1302. /**
  1303. * 获取机器列表
  1304. */
  1305. @RequestMapping(value = "/getEquipmentList.htm", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
  1306. @ResponseBody
  1307. public String getByAdminAndProduct(String adminId,String name) {
  1308. JSONObject jsonObject = new JSONObject();
  1309. if(StringUtils.isEmpty(adminId)){
  1310. jsonObject.put("code", 1);
  1311. jsonObject.put("errmsg", "adminId为空");
  1312. return jsonObject.toJSONString();
  1313. }
  1314. if(StringUtils.isEmpty(name)){
  1315. jsonObject.put("code", 1);
  1316. jsonObject.put("errmsg", "name为空");
  1317. return jsonObject.toJSONString();
  1318. }
  1319. // Admin admin = adminService.find(Long.valueOf(adminId));
  1320. TAdmin admin = adminService.getById(adminId);
  1321. if(!admin.getUsername().equals(name)){
  1322. jsonObject.put("code", 1);
  1323. jsonObject.put("errmsg", "name与adminId不匹配");
  1324. return jsonObject.toJSONString();
  1325. }
  1326. List<EquipmentDTO> list = new ArrayList<>();
  1327. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1328. query.eq(TEquipment::getAdminId,Long.valueOf(adminId));
  1329. List<TEquipment> equipmentList = equipmentService.list(query);
  1330. // List<TEquipment> equipmentList = equipmentService.findByAdminId(Long.valueOf(adminId));
  1331. for(TEquipment equipment:equipmentList){
  1332. EquipmentDTO equipmentDTO = new EquipmentDTO();
  1333. equipmentDTO.setClientId(equipment.getClientId());
  1334. equipmentDTO.setSn(equipment.getSn());
  1335. equipmentDTO.setName(equipment.getName());
  1336. equipmentDTO.setLatitude(equipment.getLatitude());
  1337. equipmentDTO.setLongitude(equipment.getLongitude());
  1338. equipmentDTO.setFullName(equipment.getFullName());
  1339. equipmentDTO.setEqeStatus(equipment.getEqeStatus());
  1340. list.add(equipmentDTO);
  1341. }
  1342. jsonObject.put("code", 0);
  1343. jsonObject.put("rows", JsonUtils.toJson(list));
  1344. jsonObject.put("errmsg", "");
  1345. jsonObject.put("total", list.size());
  1346. return jsonObject.toJSONString();
  1347. }
  1348. /**
  1349. * 获取商品信息
  1350. */
  1351. @RequestMapping(value = "/getProductions.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1352. @ResponseBody
  1353. public String getProductions(String adminId,String clientId) {
  1354. JSONObject jsonObject = new JSONObject();
  1355. if(StringUtils.isEmpty(adminId)){
  1356. jsonObject.put("code", 1);
  1357. jsonObject.put("errmsg", "adminId为空");
  1358. return jsonObject.toJSONString();
  1359. }
  1360. if(StringUtils.isEmpty(clientId)){
  1361. jsonObject.put("code", 1);
  1362. jsonObject.put("errmsg", "clientId为空");
  1363. return jsonObject.toJSONString();
  1364. }
  1365. // KafkaProperties.Admin admin = adminService.find(Long.valueOf(adminId));
  1366. TAdmin admin = adminService.getById(Long.valueOf(adminId));
  1367. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1368. query.eq(TEquipment::getClientId,clientId);
  1369. List<TEquipment> list1 = equipmentService.list(query);
  1370. TEquipment equipment = list1.get(0);
  1371. // Equipment equipment = equipmentService.findByClientId(clientId);
  1372. if(!equipment.getAdminId().toString().equals(admin.getId().toString())){
  1373. jsonObject.put("code", 1);
  1374. jsonObject.put("errmsg", "clientId与adminId不匹配");
  1375. return jsonObject.toJSONString();
  1376. }
  1377. // ArrayList<Filter> filters = new ArrayList<>();
  1378. // filters.add(Filter.eq("equipmentId", equipment.getId()));
  1379. // List<Product> products = productService.findList(null, filters, null);
  1380. List<String> list = new ArrayList<>();
  1381. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  1382. queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
  1383. List<TProduct> products = productService.list(queryProduct);
  1384. // TProduct tProduct = products.get(0);
  1385. for (TProduct product:products){
  1386. list.add(product.getProductName());
  1387. }
  1388. jsonObject.put("code", 0);
  1389. jsonObject.put("productions", JsonUtils.toJson(list));
  1390. jsonObject.put("errmsg", "");
  1391. jsonObject.put("total", list.size());
  1392. return jsonObject.toJSONString();
  1393. }
  1394. /**
  1395. * 根据设备编号获取商品信息
  1396. */
  1397. @RequestMapping(value = "/getproducts", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1398. @ResponseBody
  1399. public String getproducts(String clientId) {
  1400. JSONObject jsonObject = new JSONObject();
  1401. if(StringUtils.isEmpty(clientId)){
  1402. jsonObject.put("code", 1);
  1403. jsonObject.put("errmsg", "clientId为空");
  1404. return jsonObject.toJSONString();
  1405. }
  1406. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1407. query.eq(TEquipment::getClientId,clientId);
  1408. List<TEquipment> list1 = equipmentService.list(query);
  1409. TEquipment equipment = list1.get(0);
  1410. LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
  1411. queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
  1412. List<TProduct> products = productService.list(queryProduct);
  1413. // TProduct tProduct = products.get(0);
  1414. for (TProduct product:products){
  1415. product.setCreateDate(null);
  1416. product.setModifyDate(null);
  1417. }
  1418. // jsonObject.put("code", 0);
  1419. // jsonObject.put("productions", JsonUtils.toJson(list));
  1420. // jsonObject.put("errmsg", "");
  1421. // jsonObject.put("total", list.size());
  1422. // return jsonObject.toJSONString();
  1423. JSONObject jsonObject1 = new JSONObject();
  1424. jsonObject1.put("code", 0);
  1425. jsonObject1.put("data", JSONObject.toJSON(products).toString());
  1426. jsonObject1.put("errmsg", "");
  1427. // return jsonObject1.toString();
  1428. return JSONObject.toJSON(products).toString();
  1429. }
  1430. // @ApiOperation(value = "分页查询")
  1431. // @GetMapping("/testPage")
  1432. // public ResponseModel<IPage<?>> testPage(TAdminParam param) {
  1433. // LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
  1434. // query.eq(TAdmin::getIsEnabled,true);
  1435. // if(StrUtil.isNotBlank(param.getName())){
  1436. // query.like(TAdmin::getName,param.getName());
  1437. // }
  1438. // query.orderByDesc(TAdmin::getApplyStartTime);
  1439. // Page<TAdmin> page = new Page<>(param.getCurrent(), param.getSize(), true);
  1440. // IPage<TAdmin> iPage = tAdminService.page(page, query);
  1441. // return R.ok(iPage);
  1442. // }
  1443. //
  1444. // @ApiOperation(value = "列表查询")
  1445. // @GetMapping("/testList")
  1446. // public ResponseModel<List<?>> testList(TAdminParam param) {
  1447. // LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
  1448. // query.eq(TAdmin::getIsEnabled,true);
  1449. // if(StrUtil.isNotBlank(param.getName())){
  1450. // query.like(TAdmin::getName,param.getName());
  1451. // }
  1452. // query.orderByDesc(TAdmin::getApplyStartTime);
  1453. // List<TAdmin> list = tAdminService.list(query);
  1454. // return R.ok(list);
  1455. // }
  1456. // @ApiOperation(value = "返回失败")
  1457. // @GetMapping("/testError")
  1458. // public ResponseModel<List<?>> testError(boolean success) {
  1459. // if(success){
  1460. // return R.ok();
  1461. // }else{
  1462. // return R.fail(ResponseCodesEnum.B0001,"你的错误信息");
  1463. // }
  1464. // }
  1465. /**
  1466. *是否启用物料监控功能
  1467. * 0:不启用,1:启用
  1468. * @param clientId 个推
  1469. * @return
  1470. */
  1471. @RequestMapping(value = "/updateMaterialStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
  1472. @ResponseBody
  1473. public String updateMaterialUse(String clientId, String isMaterialUse){
  1474. if(!StringUtils.isEmpty(clientId)&&!StringUtils.isEmpty(isMaterialUse)){
  1475. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1476. query.eq(TEquipment::getClientId,clientId);
  1477. List<TEquipment> list1 = equipmentService.list(query);
  1478. TEquipment equipment = list1.get(0);
  1479. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1480. equipmentDesc.setIsMaterialUse(isMaterialUse);
  1481. equipmentDescService.updateById(equipmentDesc);
  1482. // return JsonMessage.success("success");
  1483. return "success";
  1484. }
  1485. // return JsonMessage.error("error");
  1486. return "error";
  1487. }
  1488. //修改优惠码状态
  1489. @RequestMapping(value = "/updateCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1490. @ResponseBody
  1491. public String CardPay(String code, String clientId) {
  1492. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1493. query.eq(TEquipment::getClientId,clientId);
  1494. List<TEquipment> list = equipmentService.list(query);
  1495. TEquipment equipment = list.get(0);
  1496. // List<Filter> filters = new ArrayList<>();
  1497. // if(code.length()<7){
  1498. // filters.add(Filter.in("adminId", equipment.getAdminId()));
  1499. // }
  1500. // filters.add(Filter.in("code", code));
  1501. // List<PromoCode> list = promoCodeService.findList(null, filters, null);
  1502. // PromoCode promoCode = list.get(0);
  1503. LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
  1504. query1.eq(TPromoCode::getAdminId,equipment.getAdminId());
  1505. query1.eq(TPromoCode::getCode,code);
  1506. List<TPromoCode> list1 = promoCodeService.list(query1);
  1507. TPromoCode promoCode = list1.get(0);
  1508. promoCode.setIsUse("1");
  1509. promoCode.setUseBy(equipment.getName());
  1510. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1511. String time = sdf.format(new Date());
  1512. promoCode.setUseDate(time);
  1513. promoCodeService.updateById(promoCode);
  1514. // return JsonMessage.success("success");
  1515. return "success";
  1516. }
  1517. //验证优惠码
  1518. @RequestMapping(value = "/selectCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1519. @ResponseBody
  1520. public String selectCode(String code, String clientId) {
  1521. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1522. query.eq(TEquipment::getClientId,clientId);
  1523. List<TEquipment> list = equipmentService.list(query);
  1524. TEquipment equipment = list.get(0);
  1525. //验证优惠码
  1526. LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
  1527. query1.eq(TPromoCode::getCode,code);
  1528. List<TPromoCode> codeList = promoCodeService.list(query1);
  1529. TPromoCode promoCode = new TPromoCode();
  1530. if (codeList.size() == 0) {
  1531. //不存在
  1532. // return JsonMessage.success("1");
  1533. return "1";
  1534. }
  1535. for (TPromoCode cod : codeList) {
  1536. if(!cod.getAdminId().equals("1")){
  1537. String adminId = cod.getAdminId();
  1538. String adminId1 = String.valueOf(equipment.getAdminId());
  1539. if (adminId.equals(adminId1)) {
  1540. promoCode = cod;
  1541. }
  1542. }else{
  1543. promoCode = cod;
  1544. }
  1545. }
  1546. if(promoCode.getAdminId()==null){
  1547. //不是本机
  1548. // return JsonMessage.success("3");
  1549. return "3";
  1550. }
  1551. Date lastUseDate = null;
  1552. if (promoCode != null) {
  1553. lastUseDate = promoCode.getLastUseDate();
  1554. }
  1555. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  1556. promoCode.setIsUse("2");
  1557. promoCodeService.updateById(promoCode);
  1558. //过期
  1559. // return JsonMessage.success("4");
  1560. return "4";
  1561. }
  1562. if (promoCode.getId() == null) {
  1563. //不存在
  1564. // return JsonMessage.success("1");
  1565. return "1";
  1566. }
  1567. if (promoCode.getIsUse().equals("1")) {
  1568. //被使用
  1569. // return JsonMessage.success("2");
  1570. return "2";
  1571. }
  1572. if(!promoCode.getAdminId().equals("1")){
  1573. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  1574. } else {
  1575. //不是本机
  1576. // return JsonMessage.success("3");
  1577. return "3";
  1578. }
  1579. }
  1580. if (promoCode.getDiscount() == null) {
  1581. //旧优惠码
  1582. // return JsonMessage.success("0");
  1583. return "0";
  1584. }
  1585. if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  1586. //0折
  1587. // return JsonMessage.success("0");
  1588. return "0";
  1589. }
  1590. // return JsonMessage.success("success");
  1591. return "success";
  1592. }
  1593. //修改机器的分销
  1594. @RequestMapping(value = "/updateProportion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
  1595. @ResponseBody
  1596. public String updateProportion(String clientId) {
  1597. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1598. query.eq(TEquipment::getClientId,clientId);
  1599. List<TEquipment> list = equipmentService.list(query);
  1600. TEquipment equipment = list.get(0);
  1601. if(equipment!=null&&equipment.getId()!=null){
  1602. TAdmin admin = adminService.getById(equipment.getAdminId());
  1603. String name = admin.getName();
  1604. //查询机器是否已经有设置分销
  1605. LambdaQueryWrapper<TProportion> query1 = Wrappers.lambdaQuery();
  1606. query1.eq(TProportion::getClientId,equipment.getClientId());
  1607. query1.eq(TProportion::getEquipmentId,equipment.getId());
  1608. List<TProportion> list1 = proportionService.list(query1);
  1609. if(list1.size()>0){
  1610. //已有
  1611. }else {
  1612. //没有,需要创建
  1613. //1,判断是否新机器
  1614. // Date createDate = equipment.getCreateDate();
  1615. // long time = createDate.getTime();
  1616. // DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1617. // String day= "2022-09-21 23:59:59";
  1618. // try {
  1619. // Date parse = simpleDateFormat.parse(day);
  1620. // if(time>parse.getTime()){
  1621. // return "新机器,不能已此方式生成分销!";
  1622. // }
  1623. // } catch (ParseException e) {
  1624. // e.printStackTrace();
  1625. // }
  1626. //先找到原账户的分销
  1627. LambdaQueryWrapper<TProportion> query2 = Wrappers.lambdaQuery();
  1628. query2.eq(TProportion::getAdminId,admin.getId());
  1629. List<TProportion> list2 = proportionService.list(query2);
  1630. if(list2.size()>0){
  1631. TProportion adminProportion = list2.get(0);
  1632. if(StringUtils.isEmpty(adminProportion.getClientId())){
  1633. TProportion equipmentProportion = new TProportion();
  1634. equipmentProportion.setCreateDate(new Date());
  1635. equipmentProportion.setModifyDate(new Date());
  1636. equipmentProportion.setAdminId(admin.getId());
  1637. equipmentProportion.setClientId(equipment.getClientId());
  1638. equipmentProportion.setEquipmentId(equipment.getId());
  1639. equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
  1640. Integer type = adminProportion.getType();
  1641. switch (type) {
  1642. case 1:
  1643. equipmentProportion.setProportion(adminProportion.getAgencyProportion());
  1644. equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
  1645. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  1646. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  1647. equipmentProportion.setType(0);
  1648. break;
  1649. case 2:
  1650. equipmentProportion.setProportion(adminProportion.getMerchantProportion());
  1651. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  1652. // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
  1653. // equipmentProportion.setAgencyId(admin.getAgencyId());
  1654. // TAdmin byId = adminService.getById(admin.getAgencyId());
  1655. // equipmentProportion.setAgencyName(byId.getUsername());
  1656. // }
  1657. equipmentProportion.setAgencyId(admin.getAgencyId());
  1658. TAdmin byId = adminService.getById(admin.getAgencyId());
  1659. equipmentProportion.setAgencyName(byId.getUsername());
  1660. equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
  1661. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  1662. equipmentProportion.setType(1);
  1663. break;
  1664. case 3:
  1665. equipmentProportion.setProportion(adminProportion.getPersonageProportion());
  1666. equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
  1667. // if(adminProportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))!=0){
  1668. // equipmentProportion.setAgencyId(admin.getAgencyId());
  1669. // TAdmin byId = adminService.getById(admin.getAgencyId());
  1670. // equipmentProportion.setAgencyName(byId.getUsername());
  1671. // }
  1672. equipmentProportion.setAgencyId(admin.getAgencyId());
  1673. TAdmin byId1 = adminService.getById(admin.getAgencyId());
  1674. equipmentProportion.setAgencyName(byId1.getUsername());
  1675. equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
  1676. // if(adminProportion.getMerchantProportion().compareTo(new BigDecimal("0.00"))!=0){
  1677. // equipmentProportion.setMerchantId(admin.getMerchantId());
  1678. // TAdmin byId = adminService.getById(admin.getMerchantId());
  1679. // equipmentProportion.setMerchantName(byId.getUsername());
  1680. // }
  1681. equipmentProportion.setMerchantId(admin.getMerchantId());
  1682. TAdmin byId2 = adminService.getById(admin.getMerchantId());
  1683. equipmentProportion.setMerchantName(byId2.getUsername());
  1684. equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
  1685. equipmentProportion.setType(2);
  1686. break;
  1687. }
  1688. boolean save = proportionService.save(equipmentProportion);
  1689. }
  1690. }else {
  1691. return "原账户没有设置分销!";
  1692. }
  1693. }
  1694. }
  1695. return "success";
  1696. }
  1697. /**
  1698. *
  1699. *
  1700. * @param clientId
  1701. * @return
  1702. */
  1703. @GetMapping(value = "/getManagerId.htm")
  1704. @ResponseBody
  1705. public String getManagerId(String clientId){
  1706. if(!StringUtils.isEmpty(clientId)){
  1707. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1708. query.eq(TEquipment::getClientId,clientId);
  1709. List<TEquipment> list = equipmentService.list(query);
  1710. if (list.size()>0) {
  1711. TEquipment equipment = list.get(0);
  1712. Long adminId = equipment.getAdminId();
  1713. if(adminId!=null){
  1714. String managerId = AdminUtils.encrypt(false, adminId);
  1715. if(StringUtils.isEmpty(equipment.getManagerId())||!equipment.getManagerId().equals(managerId)){
  1716. equipment.setManagerId(managerId);
  1717. equipmentService.save(equipment);
  1718. }
  1719. return managerId;
  1720. }
  1721. }
  1722. return "error";
  1723. }
  1724. return "error";
  1725. }
  1726. /**
  1727. *修改优惠券开关状态
  1728. *
  1729. * @param clientId
  1730. * @return
  1731. */
  1732. @GetMapping(value = "/updateCouponStatus.htm")
  1733. @ResponseBody
  1734. public String updateCouponStatus(String clientId,String couponStatus){
  1735. if(!StringUtils.isEmpty(clientId)&&StringUtils.isNotEmpty(couponStatus)){
  1736. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1737. query.eq(TEquipment::getClientId,clientId);
  1738. List<TEquipment> list = equipmentService.list(query);
  1739. TEquipment equipment = list.get(0);
  1740. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1741. equipmentDesc.setCouponStatus(couponStatus);
  1742. equipmentDescService.updateById(equipmentDesc);
  1743. TAdmin admin = adminService.getById(equipment.getAdminId());
  1744. //同步数据到鲸准
  1745. if(admin.getId().toString().equals("372")||admin.getRelationAdminId().equals("372")||admin.getId().toString().equals("639")||admin.getId().toString().equals("238")) {
  1746. sendCouponStatus(clientId,equipment.getFullName(),equipment.getEqeStatus(),couponStatus);
  1747. }
  1748. return "success";
  1749. }
  1750. return "error";
  1751. }
  1752. private void sendCouponStatus(String clientId, String fullName, Integer eqeStatus, String couponStatus) {
  1753. String url = "http://47.106.13.109:3000/api/listenDeviceStatusChange";
  1754. Map<String,String> map = new HashMap<>();
  1755. map.put("clientId",clientId);
  1756. map.put("address",fullName);
  1757. map.put("status", String.valueOf(eqeStatus));
  1758. if(StringUtils.isEmpty(couponStatus)){
  1759. map.put("wxStatus","1");
  1760. }else {
  1761. map.put("wxStatus",couponStatus);
  1762. }
  1763. String data = JSON.toJSONString(map);
  1764. try {
  1765. String s = HttpClientSslUtils.doPost(url, data);
  1766. System.out.println("发送鲸准:"+s);
  1767. } catch (Exception e) {
  1768. e.printStackTrace();
  1769. }
  1770. }
  1771. /**
  1772. *
  1773. *
  1774. * @param clientId
  1775. * @return
  1776. */
  1777. @GetMapping(value = "/getYouHuiPrice.htm")
  1778. @ResponseBody
  1779. public String getYouHuiPrice(String clientId){
  1780. LambdaQueryWrapper<TPrice> query = Wrappers.lambdaQuery();
  1781. query.eq(TPrice::getName,"优惠券");
  1782. List<TPrice> list = priceService.list(query);
  1783. if(list.size()>0){
  1784. TPrice tPrice = list.get(0);
  1785. Double price = tPrice.getPrice();
  1786. return new BigDecimal(price).setScale(0, RoundingMode.HALF_DOWN).toString();
  1787. }else {
  1788. return "5";
  1789. }
  1790. }
  1791. /**
  1792. * 修改商品名称
  1793. *
  1794. * @param clientId 设备个推Id
  1795. * @param
  1796. * @return
  1797. * @Param
  1798. */
  1799. @RequestMapping(value = "/updateProductName.htm", method = RequestMethod.POST)
  1800. @ResponseBody
  1801. public String updateProductName(String clientId, Long productId,String oldProductName, String newProductName) {
  1802. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1803. query.eq(TEquipment::getClientId,clientId);
  1804. List<TEquipment> list = equipmentService.list(query);
  1805. if(list.size()>0){
  1806. TEquipment equipment = list.get(0);
  1807. if (equipment != null&&equipment.getId()!=null) {
  1808. TProduct product = productService.getById(productId);
  1809. product.setName(oldProductName);
  1810. product.setProductName(newProductName);
  1811. productService.updateById(product);
  1812. return "修改成功success!";
  1813. }
  1814. }
  1815. return "更新失败error";
  1816. }
  1817. /**
  1818. * 上传机器状态之门的状态:
  1819. * type(类型,0:外门,1:内门),
  1820. * status(状态:0:关闭,1:开启)
  1821. * @param clientId
  1822. * @return status(状态:0:关闭,1:开启)
  1823. */
  1824. @GetMapping("/updateEquipmentStatus")
  1825. public ResponseModel<?> updateEquipmentStatus(String clientId, String type, String status){
  1826. if(StringUtils.isEmpty(clientId)||StringUtils.isEmpty(type)||StringUtils.isEmpty(status)){
  1827. return R.fail(ResponseCodesEnum.A0001,"adminId为空");
  1828. }
  1829. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1830. query.eq(TEquipment::getClientId,clientId);
  1831. TEquipment equipment = equipmentService.getOnly(query);
  1832. if(equipment!=null&&equipment.getId()!=null){
  1833. if(type.equals("0")){
  1834. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1835. equipmentDesc.setOutDoor(status);
  1836. equipmentDescService.updateById(equipmentDesc);
  1837. return R.ok();
  1838. }else if(type.equals("1")){
  1839. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
  1840. equipmentDesc.setInDoor(status);
  1841. equipmentDescService.updateById(equipmentDesc);
  1842. return R.ok();
  1843. }
  1844. }
  1845. return R.fail(ResponseCodesEnum.A0002);
  1846. }
  1847. /**
  1848. * 上传花型显示状态
  1849. * @param clientId 设备编号
  1850. * @param tProductBean 包含花型编号和状态
  1851. * @return
  1852. */
  1853. @RequestMapping(value = "/updateShowGoods", method = RequestMethod.POST)
  1854. @ResponseBody
  1855. public String updateShowGoods(@RequestParam String clientId, @RequestBody List<TProductBean> tProductBean) {
  1856. if(StringUtils.isEmpty(clientId)||tProductBean == null) {
  1857. return "参数为空";
  1858. }
  1859. LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
  1860. query.eq(TEquipment::getClientId,clientId);
  1861. TEquipment equipment = equipmentService.getOnly(query);
  1862. if (equipment==null) {
  1863. return "找不到设备信息";
  1864. }
  1865. Long equipmentId = equipment.getId();
  1866. ArrayList<TProduct> tProducts = new ArrayList<>();
  1867. for (TProductBean productBean : tProductBean) {
  1868. String no = productBean.getNo();
  1869. String showType = productBean.getShowType();
  1870. LambdaQueryWrapper<TProduct> wrapper = new LambdaQueryWrapper<>();
  1871. wrapper.eq(TProduct::getEquipmentId,equipmentId);
  1872. wrapper.eq(TProduct::getNo,no);
  1873. TProduct product = productService.getOnly(wrapper);
  1874. product.setShowType(showType);
  1875. tProducts.add(product);
  1876. }
  1877. boolean res = productService.updateBatchById(tProducts);
  1878. if (!res) {
  1879. return "error";
  1880. }
  1881. return "success";
  1882. }
  1883. }