IndexController.java 88 KB

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