1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020 |
- package com.szwl.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.szwl.constant.ResponseCodesEnum;
- import com.szwl.model.bean.*;
- import com.szwl.model.bo.JsonUtils;
- import com.szwl.model.bo.R;
- import com.szwl.model.bo.ResponseModel;
- import com.szwl.model.entity.*;
- import com.szwl.model.utils.AdminUtils;
- import com.szwl.model.utils.HttpClientSslUtils;
- import com.szwl.model.utils.PushUtils;
- import com.szwl.service.*;
- import com.szwl.service.es.EsTEquipmentService;
- import com.szwl.util.IDGenerator;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.io.IOUtils;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.amqp.core.AmqpAdmin;
- import org.springframework.amqp.core.Binding;
- import org.springframework.amqp.core.Queue;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- @Api(value = "/indexController", tags = {"设备信息上传接口"})
- @RestController
- @RequestMapping("/api/app_equipment/index")
- public class IndexController {
- @Autowired
- TAdminService adminService;
- @Autowired
- TEquipmentService equipmentService;
- @Autowired
- TEquipmentApplyService equipmentApplyService;
- @Autowired
- TProductService productService;
- @Autowired
- TProportionService proportionService;
- @Autowired
- TEquipmentDescService equipmentDescService;
- @Autowired
- EsTEquipmentService esTEquipmentService;
- @Autowired
- TParametersService parametersService;
- @Autowired
- TPriceService priceService;
- @Autowired
- TPromoCodeService promoCodeService;
- @Autowired
- TDiyFlowerService diyFlowerService;
- @Autowired
- private AmqpAdmin amqpAdmin;
- @ApiOperation(value = "心跳")
- @RequestMapping(value = "/heart.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String heart(@RequestBody EquipmentVo equipmentVo) {
- String clientId = equipmentVo.getClientId();
- Date lastUpdateTime = equipmentVo.getLastUpdateTime();
- Double longitude = equipmentVo.getLongitude();
- Double latitude = equipmentVo.getLatitude();
- String cabinetHd = equipmentVo.getCabinetHd();
- String cabinetTm = equipmentVo.getCabinetTm();
- String furnaceSp = equipmentVo.getFurnaceSp();
- String furnaceTm = equipmentVo.getFurnaceTm();
- String gtClientId = equipmentVo.getGtClientId();
- String volume = equipmentVo.getVolume();
- Integer eqeStatus = equipmentVo.getEqeStatus();
- Boolean is_sleep = equipmentVo.getIs_sleep();
- String netWorkingMode = equipmentVo.getNetWorkingMode();
- String numberOne = equipmentVo.getNumberOne();
- String candyGeneratorTm = equipmentVo.getCandyGeneratorTm();
- String outsideTm = equipmentVo.getOutsideTm();
- String outsideHd = equipmentVo.getOutsideHd();
- //有记录,则进行修改
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment _new = equipmentService.getOne(query);
- if (_new != null) {
- _new.setNetWorkingMode(netWorkingMode);
- if(StringUtils.isNotEmpty(cabinetTm)){
- _new.setCabinetTm(cabinetTm);
- }
- if(StringUtils.isNotEmpty(cabinetHd)){
- _new.setCabinetHd(cabinetHd);
- }
- if(StringUtils.isNotEmpty(furnaceSp)){
- _new.setFurnaceSp(furnaceSp);
- }
- if(StringUtils.isNotEmpty(furnaceTm)){
- _new.setFurnaceTm(furnaceTm);
- }
- _new.setLastUpdateTime(lastUpdateTime);
- // _new.setLongitude(longitude);
- if(eqeStatus!=null){
- _new.setEqeStatus(eqeStatus);
- }
- if(is_sleep!=null){
- _new.setIsSleep(is_sleep);
- }
- if(!StringUtils.isEmpty(furnaceTm)){
- int fur = Integer.parseInt(furnaceTm);
- if(_new.getEqeStatus()==0&&fur>150){
- _new.setEqeStatus(1);
- }
- if(_new.getEqeStatus()==null&&fur>150){
- _new.setEqeStatus(1);
- }
- }
- if(!StringUtils.isEmpty(volume)){
- _new.setVolume(volume);
- }
- // _new.setLatitude(latitude);
- _new.setGtClientId(gtClientId);
- _new.setModifyDate(new Date());
- equipmentService.updateById(_new);
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(_new.getId());
- if(StringUtils.isNotEmpty(equipmentVo.getBlueSugar())){
- equipmentDesc.setBlueSugar(equipmentVo.getBlueSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getRedSugar())){
- equipmentDesc.setRedSugar(equipmentVo.getRedSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getYellowSugar())){
- equipmentDesc.setYellowSugar(equipmentVo.getYellowSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getWhiteSugar())){
- equipmentDesc.setWhiteSugar(equipmentVo.getWhiteSugar());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getWater())){
- equipmentDesc.setWater(equipmentVo.getWater());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getWasteWater())){
- equipmentDesc.setWasteWater(equipmentVo.getWasteWater());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getStick())){
- equipmentDesc.setStick(equipmentVo.getStick());
- }
- if(equipmentVo.getCupQuantity() != null){
- equipmentDesc.setCupQuantity(equipmentVo.getCupQuantity());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getStirTm())){
- equipmentDesc.setStirTm(equipmentVo.getStirTm());
- }
- if(StringUtils.isNotEmpty(equipmentVo.getCornGeneratorTm())){
- equipmentDesc.setCornGeneratorTm(equipmentVo.getCornGeneratorTm());
- }
- if(StringUtils.isNotEmpty(numberOne)){
- equipmentDesc.setNumberOne(numberOne);
- }
- if(StringUtils.isNotEmpty(candyGeneratorTm)){
- equipmentDesc.setCandyGeneratorTm(candyGeneratorTm);
- }
- if(StringUtils.isNotEmpty(outsideHd)){
- equipmentDesc.setOutsideHd(outsideHd);
- }
- if(StringUtils.isNotEmpty(outsideTm)){
- equipmentDesc.setOutsideTm(outsideTm);
- }
- equipmentDescService.updateById(equipmentDesc);
- return "心跳成功";
- }
- return "心跳失败";
- }
- /**
- * 设备申请
- *
- * @param clientId 个推
- * @param managerId 管理系统id
- * @return
- */
- @ApiOperation(value = "设备申请")
- @RequestMapping(value = "/initNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String initNew(String clientId, String managerId, String gtClientId, String equimentType) {
- String machineType = "0";
- String status = "0";
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.like(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- if (list.size() > 0) {
- TEquipment equipment = list.get(0);
- if(equipment.getAdminId()!=31){
- if(!equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()).equals("xxx")){
- String managerId1 = equipment.getManagerId();
- if(!managerId.equals(managerId1)){
- return "该设备未脱离";
- }else {
- return "该设备已经初始化";
- }
- }
- }else {
- status = "1";
- }
- }
- if (StringUtils.isEmpty(gtClientId)) {
- return "设备不能为空";
- }
- LambdaQueryWrapper<TEquipmentApply> query1 = Wrappers.lambdaQuery();
- query1.eq(TEquipmentApply::getClientId,clientId);
- query1.eq(TEquipmentApply::getStatusType,"1");
- query1.eq(TEquipmentApply::getManagerId,managerId);
- String dateStr = "2022-12-28 00:00:00";
- //获得SimpleDateFormat类,我们转换为yyyy-MM-dd的时间格式
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- //使用SimpleDateFormat的parse()方法生成Date
- Date date = sf.parse(dateStr);
- query1.gt(TEquipmentApply::getCreateDate,date);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- List<TEquipmentApply> list1 = equipmentApplyService.list(query1);
- if(list1.size()>0){
- return "重复申请";
- }
- TEquipmentApply equipmentApply = new TEquipmentApply();
- equipmentApply.setStatusType(1);
- equipmentApply.setClientId(clientId);
- equipmentApply.setManagerId(managerId);
- equipmentApply.setGtClientId(gtClientId);
- Long adminId = AdminUtils.decrypt(false, managerId);
- TAdmin admin = adminService.getById(adminId);
- if (admin == null) {
- return "找不到商家";
- }
- //所属商家
- String username = admin.getUsername();
- equipmentApply.setAdminId(adminId);
- equipmentApply.setAdminUserName(username);
- equipmentApply.setEquimentType(equimentType);
- if(equimentType.equals("POP320")) {
- machineType = "1";
- }
- equipmentApply.setMachineType(machineType);
- equipmentApply.setCreateDate(new Date());
- equipmentApply.setModifyDate(new Date());
- equipmentApplyService.save(equipmentApply);
- if(status.equals("1")||String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
- Long id = equipmentApply.getId();
- agree(id);
- return "设备申请成功";
- }
- if(admin.getApplyStartTime()!=null&&admin.getApplyEndTime()!=null){
- Date applyStartTime = admin.getApplyStartTime();
- Date applyEndTime = admin.getApplyEndTime();
- Date now = new Date();
- if(now.getTime()>applyStartTime.getTime()&&now.getTime()<applyEndTime.getTime()){
- Long id = equipmentApply.getId();
- agree(id);
- return "设备申请成功";
- }
- }
- return "设备申请中,请耐心等待";
- }
- private void agree(Long id) {
- String status = "agreed";
- if (null != id) {
- TEquipmentApply equipmentApply = equipmentApplyService.getById(id);
- Integer statusType = equipmentApply.getStatusType();
- if(statusType>1){
- equipmentApply = null;
- }
- if (equipmentApply != null) {
- if (!StringUtils.isEmpty(status)) {
- if (status.equals("agreed")) {
- String clientId = equipmentApply.getClientId();
- //判断是否设备初始化
- Long adminId = equipmentApply.getAdminId();
- String adminLevel = equipmentApply.getAdminLevel();
- String adminUserName = equipmentApply.getAdminUserName();
- String gtClientId = equipmentApply.getGtClientId();
- String equimentType = equipmentApply.getEquimentType();
- String machineType = equipmentApply.getMachineType();
- TAdmin admin = adminService.getById(adminId);
- String companyType = admin.getCompanyType(); // 公司平台
- String old = "";
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.like(TEquipment::getClientId,clientId+"xxx");
- List<TEquipment> list = equipmentService.list(query);
- LambdaQueryWrapper<TEquipment> query0 = Wrappers.lambdaQuery();
- query0.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list2 = equipmentService.list(query0);
- equipmentApply.setStatusType(3);
- if (list.size() > 0||list2.size()>0) {
- //表示设备第二次申请了:主要为了区分脱离以及初始化
- old = "1";
- //重新修改设备名称
- TEquipment equipment = new TEquipment();
- if(list2.size()>0){
- equipment = list2.get(0);
- }else {
- equipment = list.get(0);
- }
- equipment.setClientId(clientId);
- equipment.setGtClientId(gtClientId);
- equipment.setAdminId(adminId);
- equipment.setAdminLevel(adminLevel);
- equipment.setAdminUserName(adminUserName);
- equipment.setMachineType(machineType);
- equipment.setCompanyType(companyType);
- if(equipmentApply.getEquimentType().equals("MG320-1")){
- if(!equipmentApply.getEquimentType().equals(equipment.getEquimentType())&&equipment.getEquimentType().equals("MG320")){
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> productList = productService.list(queryProduct);
- if(productList.size()==18){
- //从18种变成30种花型
- saveProductMG12(equipment.getId());
- }
- }
- equipment.setEquimentType("MG320");
- }
- if(equipmentApply.getEquimentType().equals("MG330")){
- equipment.setEquimentType("MG330");
- }
- if(equipmentApply.getEquimentType().equals("POP320")) {
- equipment.setEquimentType(equipmentApply.getEquimentType());
- }
- equipmentService.updateById(equipment);
- LambdaQueryWrapper<TProportion> queryProportion = Wrappers.lambdaQuery();
- queryProportion.eq(TProportion::getEquipmentId,equipment.getId());
- List<TProportion> list1 = proportionService.list(queryProportion);
- if(list1.size()>0){
- for(TProportion proportion:list1){
- proportionService.removeById(proportion.getId());
- }
- }
- try {
- esTEquipmentService.updateDataById(equipment);
- }catch (Exception e) {
- e.printStackTrace();
- }
- if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- } else {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- }
- if(equipment.getEquimentType().equals("280")){
- equipmentService.sentMessage(clientId,PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- }
- }else{
- TEquipment equipment = new TEquipment();
- equipment.setId(IDGenerator.commonID());
- equipment.setCreateDate(new Date());
- equipment.setModifyDate(new Date());
- equipment.setClientId(clientId);
- equipment.setManagerId(equipmentApply.getManagerId());
- equipment.setAdminId(adminId);
- equipment.setAdminLevel(adminLevel);
- equipment.setGtClientId(gtClientId);
- equipment.setAdminUserName(adminUserName);
- equipment.setIsUsing(true);
- equipment.setIsNetWork(true);
- equipment.setGuestPwd("123456");
- equipment.setAdminPwd("123456");
- equipment.setChannel("1");
- equipment.setProductTotal(0);
- equipment.setCompanyType(companyType);
- //设置默认规则
- equipment.setTimeRuleId(Long.valueOf(1));
- if(equimentType.equals("MG320-1")){
- equipment.setEquimentType("MG320");
- }else {
- equipment.setEquimentType(equimentType);
- }
- if(!StringUtils.isEmpty(equimentType)&&equimentType.equals("MG280")){
- Long monthBegin = getMonthBegin(new Date());
- long time = System.currentTimeMillis();
- if(time<monthBegin){
- equipment.setEndDate(new Date(monthBegin));
- }else{
- Date date = nextMonthDate();
- equipment.setEndDate(date);
- }
- equipmentService.sentMessage(clientId,PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
- }
- equipmentService.save(equipment);
- if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- } else {
- equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
- PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
- }
- LambdaQueryWrapper<TEquipment> query3 = Wrappers.lambdaQuery();
- query3.eq(TEquipment::getClientId,clientId);
- TEquipment tEquipment = equipmentService.getOne(query3);
- try {
- if(tEquipment != null) {
- esTEquipmentService.insertData(tEquipment);
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- TEquipmentDesc equipmentDesc = new TEquipmentDesc();
- equipmentDesc.setEquipmentId(tEquipment.getId());
- equipmentDescService.save(equipmentDesc);
- }
- //获取设备的id
- LambdaQueryWrapper<TEquipment> query1 = Wrappers.lambdaQuery();
- query1.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query1);
- Long equipmentId = equipment.getId();
- if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
- if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG280")){
- saveProductMG280(equipmentId);
- } else if (equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG320-1")){
- saveProductMG1(equipmentId);
- } else{
- saveProduct(equipmentId);
- }
- } else {
- if(equimentType.equals("POP320")) {
- saveProductPOP320(equipmentId);
- }
- }
- if(String.valueOf(adminId).equals("3")||String.valueOf(adminId).equals("31")||String.valueOf(adminId).equals("506")||String.valueOf(adminId).equals("1090")){
- //自动设置分销
- setProportion(adminId,equipmentId,clientId);
- }
- } else if (status.equals("rejected")) {
- equipmentApply.setStatusType(2);
- equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("statusType", "rejected").toString());
- }
- equipmentApplyService.updateById(equipmentApply);
- }
- }
- }
- }
- private void setProportion(Long adminId,Long equipmentId,String clientId) {
- //先找到原账户的分销
- LambdaQueryWrapper<TProportion> query3 = Wrappers.lambdaQuery();
- query3.eq(TProportion::getAdminId,adminId);
- List<TProportion> list3 = proportionService.list(query3);
- if(list3.size()>0){
- TProportion adminProportion = list3.get(0);
- if(StringUtils.isEmpty(adminProportion.getClientId())){
- TProportion equipmentProportion = new TProportion();
- equipmentProportion.setCreateDate(new Date());
- equipmentProportion.setModifyDate(new Date());
- equipmentProportion.setAdminId(adminId);
- equipmentProportion.setClientId(clientId);
- equipmentProportion.setEquipmentId(equipmentId);
- equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
- Integer type = adminProportion.getType();
- if(type!=null){
- switch (type) {
- case 1:
- equipmentProportion.setProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(0);
- break;
- case 2:
- equipmentProportion.setProportion(adminProportion.getMerchantProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyId(adminProportion.getAgencyId());
- TAdmin byId = adminService.getById(adminProportion.getAgencyId());
- equipmentProportion.setAgencyName(byId.getUsername());
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(1);
- break;
- case 3:
- equipmentProportion.setProportion(adminProportion.getPersonageProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyId(adminProportion.getAgencyId());
- TAdmin byId1 = adminService.getById(adminProportion.getAgencyId());
- equipmentProportion.setAgencyName(byId1.getUsername());
- equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
- equipmentProportion.setMerchantId(adminProportion.getMerchantId());
- TAdmin byId2 = adminService.getById(adminProportion.getMerchantId());
- equipmentProportion.setMerchantName(byId2.getUsername());
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(2);
- break;
- }
- boolean save = proportionService.save(equipmentProportion);
- }
- }
- }
- }
- /**
- * 添加棉花糖产品
- * @param id
- */
- private void saveProduct(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
- "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG280(Long id) {
- String[] str = { "水中芙蓉-A05", "水中芙蓉mini-A31", "烈焰红唇-A06", "烈焰红唇mini-A32", "夏日爱恋-A11", "夏日爱恋mini-A33", "冰美人-A12", "冰美人mini-A34", "彩色精灵-A17", "彩色精灵mini-A35"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG1(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
- "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
- "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24","坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28",
- "花样年华-A29","心花怒放-A30"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG12(Long id) {
- String[] str = { "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24"
- ,"坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28","花样年华-A29","心花怒放-A30"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setEquipmentId(id);
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG22(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
- "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG26(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
- "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28",
- "夏日倾城-A20", "雪花飞舞-A26", "豆蔻年华-A23", "花样年华-A29"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- private void saveProductMG42(Long id) {
- String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
- "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
- "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24","坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28",
- "花样年华-A29","心花怒放-A30","花好月圆-A37","出水芙蓉-A38","微光染晕-A39","夏日莓莓-A40","芳楚纷飞-A41","晨夕光晕-A42","坠入爱河-A43","天马行空-A44",
- "灼灼其华-A45","一帘幽梦-A46","七月初夏-A47","四月微风-A48"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- /**
- * 添加爆米花产品
- * @param id
- */
- private void saveProductPOP320(Long id) {
- String[] str = {"活力爆米花(正常糖)-B01", "活力爆米花(无糖)-B02", "活力爆米花(巧克力)-B03", "活力爆米花(焦糖)-B04", "活力爆米花(水蜜桃)-B05", "活力爆米花(蓝莓)-B06"};
- for (int i = 0; i < str.length; i++) {
- TProduct product = new TProduct();
- product.setCreateDate(new Date());
- product.setModifyDate(new Date());
- product.setEquipmentId(id);
- String[] split = str[i].split("-");
- product.setProductName(split[0]);
- product.setNo(split[1]);
- product.setRmbPrice(BigDecimal.ZERO);
- product.setCodePrice(BigDecimal.ZERO);
- productService.save(product);
- }
- }
- /**
- * 获取指定日期所在月份开始的时间戳
- * @param date 指定日期
- * @return
- */
- public static Long getMonthBegin(Date date) {
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- //设置为10号,当前日期既为本月10号
- c.set(Calendar.DAY_OF_MONTH, 10);
- //将小时至0
- c.set(Calendar.HOUR_OF_DAY, 0);
- //将分钟至0
- c.set(Calendar.MINUTE, 0);
- //将秒至0
- c.set(Calendar.SECOND,0);
- //将毫秒至0
- c.set(Calendar.MILLISECOND, 0);
- // 获取本月第一天的时间戳
- return c.getTimeInMillis();
- }
- public static Date nextMonthDate() {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.DAY_OF_MONTH,10);
- //将小时至0
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- //将分钟至0
- calendar.set(Calendar.MINUTE, 0);
- //将秒至0
- calendar.set(Calendar.SECOND,0);
- //将毫秒至0
- calendar.set(Calendar.MILLISECOND, 0);
- calendar.add(Calendar.MONTH,1);
- return calendar.getTime();
- }
- /**
- *改花型
- * @param
- * @return
- */
- @RequestMapping(value = "/updateFlowers.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateFlowers(String clientId,String number){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if(equipment!=null){
- Long id = equipment.getId();
- //修改花型记录数目
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(id);
- if(equipmentDesc!=null){
- equipmentDesc.setFlowers(number);
- equipmentDescService.updateById(equipmentDesc);
- }else {
- TEquipmentDesc equipmentDesc1 = new TEquipmentDesc();
- equipmentDesc1.setEquipmentId(id);
- equipmentDesc1.setFlowers(number);
- equipmentDescService.save(equipmentDesc1);
- }
- //删除旧花型
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> productList = productService.list(queryProduct);
- for(TProduct product : productList){
- productService.removeById(product.getId());
- }
- //创建花型
- if(number.equals("18")){
- saveProduct(id);
- }
- if(number.equals("22")){
- saveProductMG22(id);
- }
- if(number.equals("26")){
- saveProductMG26(id);
- }
- if(number.equals("30")){
- saveProductMG1(id);
- }
- if(number.equals("42")) {
- saveProductMG42(id);
- }
- return "success";
- }else {
- return "error";
- }
- }
- /**
- * 设备类型 开机时上传
- *
- * @param clientId 个推
- * @return
- */
- @RequestMapping(value = "/equimentType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String equimentType(String clientId, String equimentType){
- if(!StringUtils.isEmpty(equimentType)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- equipment.setEquimentType(equimentType);
- equipmentService.updateById(equipment);
- }
- return "success";
- }
- /**
- * 设备地址 开机时上传
- * @param clientId 个推
- * @return
- */
- @RequestMapping(value = "/equimentArea.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String equimentArea(String clientId, String longitude, String latitude, String fullName){
- if(!StringUtils.isEmpty(longitude)&&!StringUtils.isEmpty(latitude)&&!StringUtils.isEmpty(fullName)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- equipment.setLatitude(Double.valueOf(latitude));
- equipment.setLongitude(Double.valueOf(longitude));
- equipment.setFullName(fullName+"-");
- equipmentService.updateById(equipment);
- return "success";
- }
- return "error";
- }
- /**
- * 商品调价
- */
- @RequestMapping(value = "/updateProduct.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateProduct(@RequestBody List<ProductVo> productVos) {
- Double f=0.00;
- int num=0;
- int n=0;
- HashSet<Double> price = new HashSet<Double>();
- HashSet<Double> minprice = new HashSet<Double>();
- for (ProductVo product : productVos) {
- String clientId = product.getClientId();
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- Long id = equipment.getId();
- if(StringUtils.isNotEmpty(product.getShowType())){
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- queryProduct.eq(TProduct::getProductName,product.getProductName());
- List<TProduct> productList = productService.list(queryProduct);
- TProduct tProduct = productList.get(0);
- tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
- tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
- tProduct.setShowType(product.getShowType());
- tProduct.setSellStatus(product.getSellStatus());
- productService.updateById(tProduct);
- }else {
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- queryProduct.eq(TProduct::getProductName,product.getProductName());
- List<TProduct> productList = productService.list(queryProduct);
- TProduct tProduct = productList.get(0);
- tProduct.setRmbPrice(BigDecimal.valueOf(product.getRmbPrice()));
- tProduct.setCodePrice(BigDecimal.valueOf(product.getCodePrice()));
- tProduct.setSellStatus(product.getSellStatus());
- productService.updateById(tProduct);
- }
- }
- return "调价成功";
- }
- public Double tran(Double d){
- return new BigDecimal(d).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
- }
- public Double tran2(Double d){
- return new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
- }
- /**
- * 密码修改
- *
- * @param clientId 设备个推Id
- * @param pwdType 密码类型 1d代表修adminPwd,0代表guestPwd
- * @return
- * @Param pwd 密码内容
- */
- @RequestMapping(value = "/updatePwd.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updatePwd(String clientId, String pwdType, String pwd) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment != null) {
- if (!StringUtils.isEmpty(pwdType)) {
- switch (pwdType) {
- case "1":
- equipment.setAdminPwd(pwd);
- break;
- case "0":
- equipment.setGuestPwd(pwd);
- break;
- }
- equipmentService.updateById(equipment);
- return "更新密码成功";
- }
- }
- return "更新密码失败";
- }
- /**
- * 设备获取密码
- */
- @GetMapping(value = "/getPwd", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getPwd(String clientId) {
- if(StringUtils.isEmpty(clientId)){
- return null;
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- Map<String,String> map = new HashMap<>();
- map.put("adminPwd",equipment.getAdminPwd());
- map.put("guestPwd",equipment.getGuestPwd());
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("code", 0);
- jsonObject.put("data", JSONObject.toJSON(map).toString());
- jsonObject.put("errmsg", "");
- return jsonObject.toJSONString();
- }
- /**
- * 修改支付方式
- *
- * @param clientId
- * @param payType: 无需支付
- * 线上支付
- * 线下支付
- * 线上/线下
- * @return
- */
- @RequestMapping(value = "/updatePayType.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updatePayType(String clientId, String payType) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "修改支付方式失败";
- }
- equipment.setPayType(0);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 日志上传
- */
- @RequestMapping(value = "/sendLog.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String uploadFile(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception{
- String fileFullPath = "/home/hboxs/log/" + fileName+".txt";
- // String fileFullPath = "/root/uploadfile/apache-tomcat-8.5.42/" + fileName;
- InputStream input = null;
- FileOutputStream fos = null;
- try {
- input = request.getInputStream();
- File file = new File("/home/hboxs/log/");
- if(!file.exists()){
- file.mkdirs();
- }
- fos = new FileOutputStream(fileFullPath);
- int size = 0;
- byte[] buffer = new byte[1024];
- while ((size = input.read(buffer,0,1024)) != -1) {
- fos.write(buffer, 0, size);
- }
- //响应信息 json字符串格式
- Map<String,Object> responseMap = new HashMap<String,Object>();
- responseMap.put("flag", true);
- //生成响应的json字符串
- String jsonResponse = JSONObject.toJSONString(responseMap);
- sendResponse(jsonResponse,response);
- } catch (IOException e) {
- //响应信息 json字符串格式
- Map<String,Object> responseMap = new HashMap<String,Object>();
- responseMap.put("flag", false);
- responseMap.put("errorMsg", e.getMessage());
- String jsonResponse = JSONObject.toJSONString(responseMap);
- sendResponse(jsonResponse,response);
- } finally{
- if(input != null){
- input.close();
- }
- if(fos != null){
- fos.close();
- }
- }
- return null;
- }
- /**
- * 返回响应
- *
- * @throws Exception
- */
- private void sendResponse(String responseString,HttpServletResponse response) throws Exception {
- response.setContentType("application/json;charset=UTF-8");
- PrintWriter pw = null;
- try {
- pw = response.getWriter();
- pw.write(responseString);
- pw.flush();
- } finally {
- IOUtils.closeQuietly(pw);
- }
- }
- /**
- * 脱离系统
- *
- * @param clientId
- * @return
- */
- @RequestMapping(value = "/separate.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String separate(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipmentService.sentMessage(clientId,PushUtils.buildJson("tuoji", "0").toString());
- if("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()))){
- return "脱离成功";
- }
- equipment.setClientId(equipment.getClientId() + "xxx");
- equipmentService.updateById(equipment);
- return "脱离成功";
- }
- /**
- * 脱离系统
- *
- * @param clientId
- * @return
- */
- @RequestMapping(value = "/updateClientId", method = RequestMethod.POST)
- @ResponseBody
- public String updateClientId(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- if("xxx".equals(equipment.getClientId().substring(equipment.getClientId().length()-3,equipment.getClientId().length()))){
- return "脱离成功";
- }
- equipment.setClientId(equipment.getClientId() + "xxx");
- equipment.setManagerId(null);
- equipmentService.updateById(equipment);
- return "脱离成功";
- }
- /**
- * 修改设备联系人名称以及电话
- */
- @RequestMapping(value = "/updateContractPN.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateContractPN(String clientId, String contactName, String contactPhone) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setContactName(contactName);
- equipment.setContactPhone(contactPhone);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 设备上传公司电话
- */
- @RequestMapping(value = "/sentCompanyPhone.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String sentCompanyPhone(String clientId, String companyPhone) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setCompanyPhone(companyPhone);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 获取二维码图片
- */
- @RequestMapping(value = "/getQrCodeImgUrl.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getQrCodeImgUrl(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "404";
- }
- return "400";
- }
- /**
- * 上传4G卡号
- */
- @RequestMapping(value = "/sentSimNo.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String sentSimNo(String clientId, String simNo) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setSimNo(simNo);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 上传机器的apk版本
- */
- @RequestMapping(value = "/sendApkVersion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String sendApkVersion(String clientId, String apkVersion) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setApkVersion(apkVersion);
- equipmentService.updateById(equipment);
- return "success";
- }
- /**
- * 上传机器的做糖状态
- */
- @RequestMapping(value = "/equipmentStatus.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String equipmentStatus(String clientId, String status) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- //机器状态;0:空闲,1:在做糖;
- equipmentDesc.setStatus(status);
- equipmentDescService.updateById(equipmentDesc);
- return "success";
- }
- /**
- * 修改设备状态
- *
- * @param clientId
- * @param eqeStatus 设备状态1开 0关
- * @return
- */
- @RequestMapping(value = "/updateEqeStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateEqeStatus(String clientId, Integer eqeStatus) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- if(eqeStatus!=null){
- equipment.setEqeStatus(eqeStatus);
- equipment.setModifyDate(new Date());
- equipmentService.updateById(equipment);
- }
- return "修改成功";
- }
- /**
- * 新修改设备状态
- *
- * @param clientId
- * @param eqeStatus 设备状态1开 0关
- * @return
- */
- @RequestMapping(value = "/updateEqeStatusNew.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateEqeStatusNew(String clientId, Integer eqeStatus,String netTime) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- if(eqeStatus!=null){
- equipment.setNetwork(netTime);
- equipment.setEqeStatus(eqeStatus);
- equipmentService.updateById(equipment);
- }
- return "修改成功";
- }
- /**
- * 修改设备锁定状态
- *
- * @param clientId
- * @param block
- * @return
- */
- @RequestMapping(value = "/updateBlock.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateBlock(String clientId, Boolean block) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- equipment.setIsBlocked(block);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 修改设备睡眠状态
- *
- * @param clientId
- * @param is_sleep
- * @return
- */
- @RequestMapping(value = "/updateSleep.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateSleep(String clientId, Boolean is_sleep) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- if(is_sleep!=null){
- equipment.setIsSleep(is_sleep);
- equipmentService.updateById(equipment);
- }
- return "修改成功";
- }
- /**
- * 修改设备生产棉花糖个数
- *
- * @param clientId
- * @param productTotal
- * @return
- */
- @RequestMapping(value = "/updateProductTotal.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateProductTotal(String clientId, Integer productTotal) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "该设备不存在";
- }
- Integer total = equipment.getProductTotal();
- if (total == null) {
- total = 0;
- }
- equipment.setProductTotal(total + productTotal);
- equipmentService.updateById(equipment);
- return "修改成功";
- }
- /**
- * 修改设备共同参数/进阶参数
- *
- * @param
- * @return
- */
- // @PostMapping(value = "/updateParam/{code}/{clientId}", produces = "application/json;charset=UTF-8")
- // @ResponseBody
- // public JsonMessage updateParam(@PathVariable Integer code, @PathVariable String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
- // Equipment equipment = equipmentService.findByClientId(clientId);
- // if (equipment == null) {
- // return JsonMessage.error("设备不存在");
- // }
- // String param = JSONArray.toJSONString(commonParamVos);
- // if (code == 0) {
- // equipment.setCommonParameters(param);
- // } else {
- // equipment.setAdvancedParameters(param);
- // }
- // equipmentService.update(equipment);
- // return JsonMessage.success("修改成功");
- // }
- /**
- * 修改设备共同参数/进阶参数
- * code 0:通用参数;1:进阶参数;2:调试页参数;3:湿度参数
- * @param
- * @return
- */
- @RequestMapping(value = "/updateParamNew", method = RequestMethod.POST)
- @ResponseBody
- public String updateParamNew(Integer code, String clientId, @RequestBody List<CommonParamVo> commonParamVos) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "设备不存在";
- }
- if(commonParamVos.size()<=0){
- return "参数为空";
- }
- LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
- queryParameters.eq(TParameters::getClientId,clientId);
- queryParameters.eq(TParameters::getStatus,code);
- queryParameters.eq(TParameters::getEquipmentId,equipment.getId());
- List<TParameters> list = parametersService.list(queryParameters);
- if(list.size()>0){
- for(TParameters parameters:list){
- //删除旧的参数
- parametersService.removeById(parameters.getId());
- }
- }
- Date date = new Date();
- for(CommonParamVo commonParamVo:commonParamVos){
- TParameters parameters = new TParameters();
- parameters.setVal(commonParamVo.getVal());
- parameters.setName(commonParamVo.getName());
- parameters.setStatus(String.valueOf(code));
- parameters.setClientId(clientId);
- parameters.setEquipmentId(equipment.getId());
- parameters.setCreateDate(date);
- parameters.setModifyDate(date);
- parametersService.save(parameters);
- }
- return "修改成功";
- }
- /**
- * 修改单个设备共同参数/进阶参数
- * code 0:通用参数;1:进阶参数;2:调试页参数;3:湿度参数
- * @param
- * @return
- */
- @PostMapping(value = "/updateAloneParam.htm", produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateAloneParam(String code, String clientId,String name,String val) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if (equipment == null) {
- return "设备不存在";
- }
- LambdaQueryWrapper<TParameters> queryParameters = Wrappers.lambdaQuery();
- queryParameters.eq(TParameters::getClientId,clientId);
- queryParameters.eq(TParameters::getStatus,code);
- queryParameters.eq(TParameters::getName,name);
- queryParameters.eq(TParameters::getEquipmentId,equipment.getId());
- List<TParameters> list1 = parametersService.list(queryParameters);
- if(list1.size()>0){
- TParameters parameters = list1.get(0);
- parameters.setVal(val);
- parameters.setModifyDate(new Date());
- parametersService.updateById(parameters);
- }
- return "修改成功";
- }
- /**
- * 获取机器列表
- */
- @RequestMapping(value = "/getEquipmentList.htm", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
- @ResponseBody
- public String getByAdminAndProduct(String adminId,String name) {
- JSONObject jsonObject = new JSONObject();
- if(StringUtils.isEmpty(adminId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "adminId为空");
- return jsonObject.toJSONString();
- }
- if(StringUtils.isEmpty(name)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "name为空");
- return jsonObject.toJSONString();
- }
- TAdmin admin = adminService.getById(adminId);
- if(!admin.getUsername().equals(name)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "name与adminId不匹配");
- return jsonObject.toJSONString();
- }
- List<EquipmentDTO> list = new ArrayList<>();
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getAdminId,Long.valueOf(adminId));
- List<TEquipment> equipmentList = equipmentService.list(query);
- for(TEquipment equipment:equipmentList){
- EquipmentDTO equipmentDTO = new EquipmentDTO();
- equipmentDTO.setClientId(equipment.getClientId());
- equipmentDTO.setSn(equipment.getSn());
- equipmentDTO.setName(equipment.getName());
- equipmentDTO.setLatitude(equipment.getLatitude());
- equipmentDTO.setLongitude(equipment.getLongitude());
- equipmentDTO.setFullName(equipment.getFullName());
- equipmentDTO.setEqeStatus(equipment.getEqeStatus());
- list.add(equipmentDTO);
- }
- jsonObject.put("code", 0);
- jsonObject.put("rows", JsonUtils.toJson(list));
- jsonObject.put("errmsg", "");
- jsonObject.put("total", list.size());
- return jsonObject.toJSONString();
- }
- /**
- * 获取商品信息
- */
- @RequestMapping(value = "/getProductions.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getProductions(String adminId,String clientId) {
- JSONObject jsonObject = new JSONObject();
- if(StringUtils.isEmpty(adminId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "adminId为空");
- return jsonObject.toJSONString();
- }
- if(StringUtils.isEmpty(clientId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "clientId为空");
- return jsonObject.toJSONString();
- }
- TAdmin admin = adminService.getById(Long.valueOf(adminId));
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if(!equipment.getAdminId().toString().equals(admin.getId().toString())){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "clientId与adminId不匹配");
- return jsonObject.toJSONString();
- }
- List<String> list = new ArrayList<>();
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> products = productService.list(queryProduct);
- for (TProduct product:products){
- list.add(product.getProductName());
- }
- jsonObject.put("code", 0);
- jsonObject.put("productions", JsonUtils.toJson(list));
- jsonObject.put("errmsg", "");
- jsonObject.put("total", list.size());
- return jsonObject.toJSONString();
- }
- /**
- * 根据设备编号获取商品信息
- */
- @RequestMapping(value = "/getproducts", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String getproducts(String clientId) {
- JSONObject jsonObject = new JSONObject();
- if(StringUtils.isEmpty(clientId)){
- jsonObject.put("code", 1);
- jsonObject.put("errmsg", "clientId为空");
- return jsonObject.toJSONString();
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
- queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
- List<TProduct> products = productService.list(queryProduct);
- for (TProduct product:products){
- product.setCreateDate(null);
- product.setModifyDate(null);
- }
- JSONObject jsonObject1 = new JSONObject();
- jsonObject1.put("code", 0);
- jsonObject1.put("data", JSONObject.toJSON(products).toString());
- jsonObject1.put("errmsg", "");
- return JSONObject.toJSON(products).toString();
- }
- /**
- *是否启用物料监控功能
- * 0:不启用,1:启用
- * @param clientId 个推
- * @return
- */
- @RequestMapping(value = "/updateMaterialStatus.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateMaterialUse(String clientId, String isMaterialUse){
- if(!StringUtils.isEmpty(clientId)&&!StringUtils.isEmpty(isMaterialUse)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setIsMaterialUse(isMaterialUse);
- equipmentDescService.updateById(equipmentDesc);
- // 改变参数表里的状态
- LambdaQueryWrapper<TParameters> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(TParameters::getClientId,clientId);
- queryWrapper.eq(TParameters::getName,"M502");
- TParameters parameters = parametersService.getOne(queryWrapper);
- parameters.setVal(isMaterialUse);
- parametersService.updateById(parameters);
- return "success";
- }
- return "error";
- }
- //修改优惠码状态
- @RequestMapping(value = "/updateCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String CardPay(String code, String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
- query1.eq(TPromoCode::getAdminId,equipment.getAdminId());
- query1.eq(TPromoCode::getCode,code);
- List<TPromoCode> list1 = promoCodeService.list(query1);
- TPromoCode promoCode = list1.get(0);
- promoCode.setIsUse("1");
- promoCode.setUseBy(equipment.getName());
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = sdf.format(new Date());
- promoCode.setUseDate(time);
- promoCodeService.updateById(promoCode);
- return "success";
- }
- //验证优惠码
- @RequestMapping(value = "/selectCode.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String selectCode(String code, String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- //验证优惠码
- LambdaQueryWrapper<TPromoCode> query1 = Wrappers.lambdaQuery();
- query1.eq(TPromoCode::getCode,code);
- List<TPromoCode> codeList = promoCodeService.list(query1);
- TPromoCode promoCode = new TPromoCode();
- if (codeList.size() == 0) {
- //不存在
- return "1";
- }
- for (TPromoCode cod : codeList) {
- if(!cod.getAdminId().equals("1")){
- String adminId = cod.getAdminId();
- String adminId1 = String.valueOf(equipment.getAdminId());
- if (adminId.equals(adminId1)) {
- promoCode = cod;
- }
- }else{
- promoCode = cod;
- }
- }
- if(promoCode.getAdminId()==null){
- //不是本机
- return "3";
- }
- Date lastUseDate = null;
- if (promoCode != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- promoCodeService.updateById(promoCode);
- //过期
- return "4";
- }
- if (promoCode.getId() == null) {
- //不存在
- return "1";
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return "2";
- }
- if(!promoCode.getAdminId().equals("1")){
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return "3";
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return "0";
- }
- if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- //0折
- return "0";
- }
- return "success";
- }
- //修改机器的分销
- @RequestMapping(value = "/updateProportion.htm", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String updateProportion(String clientId) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- if(equipment!=null&&equipment.getId()!=null){
- TAdmin admin = adminService.getById(equipment.getAdminId());
- String name = admin.getName();
- //查询机器是否已经有设置分销
- LambdaQueryWrapper<TProportion> query1 = Wrappers.lambdaQuery();
- query1.eq(TProportion::getClientId,equipment.getClientId());
- query1.eq(TProportion::getEquipmentId,equipment.getId());
- List<TProportion> list1 = proportionService.list(query1);
- if(list1.size()>0){
- //已有
- }else {
- //没有,需要创建
- //1,判断是否新机器
- // Date createDate = equipment.getCreateDate();
- // long time = createDate.getTime();
- // DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- // String day= "2022-09-21 23:59:59";
- // try {
- // Date parse = simpleDateFormat.parse(day);
- // if(time>parse.getTime()){
- // return "新机器,不能已此方式生成分销!";
- // }
- // } catch (ParseException e) {
- // e.printStackTrace();
- // }
- //先找到原账户的分销
- LambdaQueryWrapper<TProportion> query2 = Wrappers.lambdaQuery();
- query2.eq(TProportion::getAdminId,admin.getId());
- List<TProportion> list2 = proportionService.list(query2);
- if(list2.size()>0){
- TProportion adminProportion = list2.get(0);
- if(StringUtils.isEmpty(adminProportion.getClientId())){
- TProportion equipmentProportion = new TProportion();
- equipmentProportion.setCreateDate(new Date());
- equipmentProportion.setModifyDate(new Date());
- equipmentProportion.setAdminId(admin.getId());
- equipmentProportion.setClientId(equipment.getClientId());
- equipmentProportion.setEquipmentId(equipment.getId());
- equipmentProportion.setAdminProportion(adminProportion.getAdminProportion());
- Integer type = adminProportion.getType();
- switch (type) {
- case 1:
- equipmentProportion.setProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyProportion(new BigDecimal("0.00"));
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(0);
- break;
- case 2:
- equipmentProportion.setProportion(adminProportion.getMerchantProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyId(admin.getAgencyId());
- TAdmin byId = adminService.getById(admin.getAgencyId());
- equipmentProportion.setAgencyName(byId.getUsername());
- equipmentProportion.setMerchantProportion(new BigDecimal("0.00"));
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(1);
- break;
- case 3:
- equipmentProportion.setProportion(adminProportion.getPersonageProportion());
- equipmentProportion.setAgencyProportion(adminProportion.getAgencyProportion());
- equipmentProportion.setAgencyId(admin.getAgencyId());
- TAdmin byId1 = adminService.getById(admin.getAgencyId());
- equipmentProportion.setAgencyName(byId1.getUsername());
- equipmentProportion.setMerchantProportion(adminProportion.getMerchantProportion());
- equipmentProportion.setMerchantId(admin.getMerchantId());
- TAdmin byId2 = adminService.getById(admin.getMerchantId());
- equipmentProportion.setMerchantName(byId2.getUsername());
- equipmentProportion.setPersonageProportion(new BigDecimal("0.00"));
- equipmentProportion.setType(2);
- break;
- }
- boolean save = proportionService.save(equipmentProportion);
- }
- }else {
- return "原账户没有设置分销!";
- }
- }
- }
- return "success";
- }
- /**
- *
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/getManagerId.htm")
- @ResponseBody
- public String getManagerId(String clientId){
- if(!StringUtils.isEmpty(clientId)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- if (list.size()>0) {
- TEquipment equipment = list.get(0);
- Long adminId = equipment.getAdminId();
- if(adminId!=null){
- String managerId = AdminUtils.encrypt(false, adminId);
- if(StringUtils.isEmpty(equipment.getManagerId())||!equipment.getManagerId().equals(managerId)){
- equipment.setManagerId(managerId);
- equipmentService.save(equipment);
- }
- return managerId;
- }
- }
- return "error";
- }
- return "error";
- }
- /**
- * 修改优惠券开关状态
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/updateCouponStatus.htm")
- @ResponseBody
- public String updateCouponStatus(String clientId,String couponStatus){
- if(!StringUtils.isEmpty(clientId)&&StringUtils.isNotEmpty(couponStatus)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setCouponStatus(couponStatus);
- equipmentDescService.updateById(equipmentDesc);
- TAdmin admin = adminService.getById(equipment.getAdminId());
- //同步数据到鲸准
- if(admin.getId().toString().equals("372")||admin.getRelationAdminId().equals("372")||admin.getId().toString().equals("639")||admin.getId().toString().equals("238")) {
- sendCouponStatus(clientId,equipment.getFullName(),equipment.getEqeStatus(),couponStatus);
- }
- return "success";
- }
- return "error";
- }
- private void sendCouponStatus(String clientId, String fullName, Integer eqeStatus, String couponStatus) {
- String url = "http://47.106.13.109:3000/api/listenDeviceStatusChange";
- Map<String,String> map = new HashMap<>();
- map.put("clientId",clientId);
- map.put("address",fullName);
- map.put("status", String.valueOf(eqeStatus));
- if(StringUtils.isEmpty(couponStatus)){
- map.put("wxStatus","1");
- }else {
- map.put("wxStatus",couponStatus);
- }
- String data = JSON.toJSONString(map);
- try {
- String s = HttpClientSslUtils.doPost(url, data);
- System.out.println("发送鲸准:"+s);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- *
- *
- * @param clientId
- * @return
- */
- @GetMapping(value = "/getYouHuiPrice.htm")
- @ResponseBody
- public String getYouHuiPrice(String clientId){
- LambdaQueryWrapper<TPrice> query = Wrappers.lambdaQuery();
- query.eq(TPrice::getName,"优惠券");
- List<TPrice> list = priceService.list(query);
- if(list.size()>0){
- TPrice tPrice = list.get(0);
- Double price = tPrice.getPrice();
- return new BigDecimal(price).setScale(0, RoundingMode.HALF_DOWN).toString();
- }else {
- return "5";
- }
- }
- /**
- * 修改商品名称
- *
- * @param clientId 设备个推Id
- * @param
- * @return
- * @Param
- */
- @RequestMapping(value = "/updateProductName.htm", method = RequestMethod.POST)
- @ResponseBody
- public String updateProductName(String clientId, Long productId,String oldProductName, String newProductName) {
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- List<TEquipment> list = equipmentService.list(query);
- if(list.size()>0){
- TEquipment equipment = list.get(0);
- if (equipment != null&&equipment.getId()!=null) {
- TProduct product = productService.getById(productId);
- product.setName(oldProductName);
- product.setProductName(newProductName);
- productService.updateById(product);
- return "修改成功success!";
- }
- }
- return "更新失败error";
- }
- /**
- * 上传机器状态之门的状态:
- * type(类型,0:外门,1:内门),
- * status(状态:0:关闭,1:开启)
- * @param clientId
- * @return status(状态:0:关闭,1:开启)
- */
- @GetMapping("/updateEquipmentStatus")
- public ResponseModel<?> updateEquipmentStatus(String clientId, String type, String status){
- if(StringUtils.isEmpty(clientId)||StringUtils.isEmpty(type)||StringUtils.isEmpty(status)){
- return R.fail(ResponseCodesEnum.A0001,"adminId为空");
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOnly(query);
- if(equipment!=null&&equipment.getId()!=null){
- if(type.equals("0")){
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setOutDoor(status);
- equipmentDescService.updateById(equipmentDesc);
- return R.ok();
- }else if(type.equals("1")){
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setInDoor(status);
- equipmentDescService.updateById(equipmentDesc);
- return R.ok();
- }
- }
- return R.fail(ResponseCodesEnum.A0002);
- }
- /**
- * 上传花型显示状态
- * @param clientId 设备编号
- * @param tProductBean 包含花型编号和状态
- * @return
- */
- @RequestMapping(value = "/updateShowGoods", method = RequestMethod.POST)
- @ResponseBody
- public String updateShowGoods(@RequestParam String clientId, @RequestBody List<TProductBean> tProductBean) {
- if(StringUtils.isEmpty(clientId)||tProductBean == null) {
- return "参数为空";
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOnly(query);
- if (equipment==null) {
- return "找不到设备信息";
- }
- Long equipmentId = equipment.getId();
- ArrayList<TProduct> tProducts = new ArrayList<>();
- for (TProductBean productBean : tProductBean) {
- String no = productBean.getNo();
- String showType = productBean.getShowType();
- LambdaQueryWrapper<TProduct> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(TProduct::getEquipmentId,equipmentId);
- wrapper.eq(TProduct::getNo,no);
- TProduct product = productService.getOnly(wrapper);
- product.setShowType(showType);
- tProducts.add(product);
- }
- boolean res = productService.updateBatchById(tProducts);
- if (!res) {
- return "error";
- }
- return "success";
- }
- /**
- * 上传DIY花型功能开关状态
- * @param clientId:设备编号
- * @param DIYFlowerStatus:开关状态, 0: 关闭, 1: 开启
- * @return
- */
- @GetMapping(value = "/updateDIYFlowerStatus")
- @ResponseBody
- public String updateDIYFlowerStatus(String clientId, String DIYFlowerStatus){
- if(StringUtils.isNotEmpty(clientId)&&StringUtils.isNotEmpty(DIYFlowerStatus)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
- equipmentDesc.setDiyFlowerStatus(DIYFlowerStatus);
- equipmentDescService.updateById(equipmentDesc);
- // 如果为开启状态
- if (DIYFlowerStatus.equals("1")) {
- LambdaQueryWrapper<TDiyFlower> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(TDiyFlower::getEquipmentId, equipment.getId());
- List<TDiyFlower> list = diyFlowerService.list(queryWrapper);
- // 如何为空就添加新的花型形状和颜色
- if (list.size() == 0) {
- saveDIYProduct(equipment.getId());
- }
- }
- return "success";
- }
- return "error";
- }
- /**
- * 添加DIY花型产品
- * @param id
- */
- private void saveDIYProduct(Long id) {
- String[] str = {"圆五花-S01", "圆心-S02", "心-S03", "圆蝴蝶-S04", "圆四叶草-S05", "圆六花瓣-S06", "圆三叶草-A07", "圆三花瓣-S08", "蘑菇-S09",
- "白糖-T01", "红糖-T02", "黄糖-T03", "蓝糖-T04"};
- for (int i = 0; i < str.length; i++) {
- TDiyFlower diyFlower = new TDiyFlower();
- diyFlower.setCreateDate(new Date());
- diyFlower.setModifyDate(new Date());
- diyFlower.setEquipmentId(id);
- String[] split = str[i].split("-");
- diyFlower.setName(split[0]);
- diyFlower.setNo(split[1]);
- diyFlower.setShowType("1");
- diyFlowerService.save(diyFlower);
- }
- }
- /**
- * 上传DIY花型形状/糖显示状态
- * @param clientId 设备编号
- * @param tProductBean 包含形状/糖的编号和状态
- * @return
- */
- @RequestMapping(value = "/updateDIYFlowerShow", method = RequestMethod.POST)
- @ResponseBody
- public String updateDIYFlowerShow(@RequestParam String clientId, @RequestBody List<TProductBean> tProductBean) {
- if(StringUtils.isEmpty(clientId)||tProductBean == null) {
- return "参数为空";
- }
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOnly(query);
- if (equipment==null) {
- return "找不到设备信息";
- }
- Long equipmentId = equipment.getId();
- ArrayList<TDiyFlower> diyFlowers = new ArrayList<>();
- for (TProductBean productBean : tProductBean) {
- String no = productBean.getNo();
- String showType = productBean.getShowType();
- LambdaQueryWrapper<TDiyFlower> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(TDiyFlower::getEquipmentId,equipmentId);
- wrapper.eq(TDiyFlower::getNo,no);
- TDiyFlower diyFlower = diyFlowerService.getOne(wrapper);
- diyFlower.setShowType(showType);
- diyFlowers.add(diyFlower);
- }
- boolean res = diyFlowerService.updateBatchById(diyFlowers);
- if (!res) {
- return "error";
- }
- return "success";
- }
- /**
- * 花型数目 开机时上传
- *
- * @param clientId 个推
- * @return
- */
- @RequestMapping(value = "/flowerNumber", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
- @ResponseBody
- public String flowerNumber(String clientId, String flowerNumber){
- if(!StringUtils.isEmpty(flowerNumber)){
- LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
- query.eq(TEquipment::getClientId,clientId);
- TEquipment equipment = equipmentService.getOne(query);
- equipment.setFlowers(flowerNumber);
- equipmentService.updateById(equipment);
- return "success";
- }
- return "fail";
- }
- }
|