Summary of WeChat H5 Project of a Bank’s Party History Knowledge Contest

Summary of the Party History Knowledge Contest Project

One, the method of Java program running in the background of the server

Windows server

1. Create a new run.txt file

2. Input:

@echo off

start javaw -jar xx.jar

exit

3. Save as run.bat

4. Double-click to run

5. How to delete programs running in the background

tasklist view process

taskkill /pid process number

taskkill -f /pid process number forcibly kill

Linux server

$ java -jar test.jar

Background process

$ nohup java -jar test.jar &

View the information of a jar

ps aux|grep xxx.jar

Closing the specified jar is actually exiting the process

kill -9 进程号

Two, git use

git init

git clone http地址

Steps to upload code using git

1. cd to the process folder, git add .(note that it is the git add point)

2、git commit -m"标题"

3、git push

Third, the back-end solves cross-domain problems

//@CrossOrigin(origins = "http://xxx.x.xx.xxx")可指定ip跨域
@CrossOrigin(origins = "*")//全局跨域

Four, the mapper.xml file is placed in the xml folder under resource

Insert picture description here

Configuration in the properties configuration file

mybatis-plus.mapper-locations=classpath:/xml/*.xml

5. The interface documentation must be written well! ! !

Six, MySQL trigger

Very useful when synchronizing data from multiple tables

-- 创建触发器
DELIMITER $
DROP TRIGGER IF EXISTS ExerInfo_Insert_Trigger $
CREATE TRIGGER ExerInfo_Insert_Trigger
AFTER INSERT ON `execinfo`
FOR EACH ROW
BEGIN
 DECLARE branchIDs INT;
 DECLARE commentss VARCHAR(32);
 DECLARE recIDs INT;

 SET  @branchIDs   =new.branchID;
 SET  @commentss   =new.comments;
 SET  @recIDs    =new.recID;  

 IF @commentss='A' THEN
      UPDATE `matchgroup` SET userA = @recIDs  WHERE recID = @branchIDs;
 ELSEIF @commentss='B' THEN
      UPDATE `matchgroup` SET userB = @recIDs  WHERE recID = @branchIDs;
 ELSEIF @commentss='C' THEN
      UPDATE `matchgroup` SET userC = @recIDs  WHERE recID = @branchIDs;
 ELSE 
          UPDATE `matchgroup` SET userA = @recIDs  WHERE recID = 0;
 END IF;

END$

DELIMITER ;

Seven, the joint table query is very fragrant, you must know how to use it

SELECT
            `bguser`.`userName`AS `uname`,
            `partybranch`.`branchName` AS `bname`,
            SUM(`execinfo`.`score`)AS `sumScore`,
            -SUM(TIMESTAMPDIFF(MINUTE,`execinfo`.startTime, `execinfo`.endTime)) AS `OperTime`
        FROM
            `bguser`
                INNER JOIN
            `partybranch`
                INNER JOIN
            `execinfo`
            ON
                    `execinfo`.`branchID`=`partybranch`.`recID`
                    AND
                    `execinfo`.`userID`=`bguser`.`userCode`
                    AND
                    execinfo.operType=0
        GROUP BY
            `uname`,
            `bname`
        ORDER BY
            `sumScore` DESC,`OperTime` DESC
SELECT     `matchgroup`.`GroupName`, SUM(AA.score) + SUM(BB.score) + SUM(CC.score) AS `GroupScore`,
       -SUM(TIMESTAMPDIFF(MINUTE,AA.startTime, AA.endTime) +TIMESTAMPDIFF(MINUTE, BB.startTime,
        BB.endTime) + TIMESTAMPDIFF(MINUTE, CC.startTime, CC.endTime)) AS `OperTime`
FROM         `matchgroup` LEFT OUTER JOIN
             `execinfo` AS AA ON `matchgroup`.userA = AA.recID AND AA.operType = 1
                          LEFT OUTER JOIN
             `execinfo` AS BB ON `matchgroup`.userB = BB.recID AND BB.operType = 1
                          LEFT OUTER JOIN
             `execinfo` AS CC ON `matchgroup`.userC = CC.recID AND CC.operType = 1
GROUP BY `GroupName`
ORDER BY `GroupScore` DESC,`OperTime` DESC
SELECT
    `bguser`.`userCode` AS `ucode`,
    `bguser`.`userName`AS `uname`,
    `partybranch`.`branchName` AS `bname`,
    SUM(`execinfo`.`score`)AS `sumScore`,
    COUNT(`execinfo`.`userID`)AS `count`
FROM
    `bguser`
        INNER JOIN
    `partybranch`
        INNER JOIN
    `execinfo`
    ON
            `execinfo`.`branchID`=`partybranch`.`recID`
            AND
            `execinfo`.`userID`=`bguser`.`userCode`
            and
            execinfo.operType=0
GROUP BY
    `ucode`,
    `uname`,
    `bname`

8. Good servers are really fragrant

Programs and databases can be deployed on different servers to relieve server pressure

So, buy a good server

Nine, interface debugging tools

package com.example.demo.demo.utils;

import java.io.Serializable;

public class Result implements Serializable {
    // 消息状态码
    private Integer code;
    // 消息
    private String msg;
    // 返回数据
    private Object data;

    private Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 响应成功(带返回数据)
     * @param data 返回数据
     * @return Result
     */
    public static Result success(Object data){
        return new Result(200,"响应成功",data);
    }

    public static Result success(String msg,Object data){
        return new Result(200,msg,data);
    }

    /**
     * 响应成功
     * @return Result
     */
    public static Result success(){
        return new Result(200,"响应成功",null);
    }

    /**
     * 响应错误(不带状态码,带消息)
     * @return Result
     */
    public static Result error(String msg){
        return new Result(500,msg,null);
    }

    public static Result error(String msg,Object data){
        return new Result(500,msg,data);
    }
    /**
     * 响应错误(带错误码,消息提醒)
     * @return
     */
    public static Result errorMsg(Integer code,String msg){
        return new Result(code,msg,null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}

10. MBP code generator

package com.example.demo;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableFill;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.ArrayList;

public class HsyCode {
    public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");//获取目录

        gc.setOutputDir(projectPath + "/src/main/java");//设置输出的目录
        gc.setAuthor("hsy");//设置作者
        gc.setOpen(false);//生成完毕后是否打开文件夹
        gc.setFileOverride(false);//是否覆盖之前生成的东西
        gc.setServiceName("%sService");//去Service的I前缀
        gc.setIdType(IdType.ID_WORKER);//设置默认主键类型
        gc.setDateType(DateType.ONLY_DATE);//设置默认时间类型为只显示时间
        // gc.setSwagger2(true); 实体属性 Swagger2 注解

        mpg.setGlobalConfig(gc);//丢进全局配置中

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/bgparty?useSSl=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");
        dsc.setDbType(DbType.MYSQL);
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setModuleName("demo");
        pc.setParent("com.example.demo");
        pc.setEntity("pojo");
        pc.setMapper("mapper");
        pc.setController("controller");
        pc.setService("service");
        mpg.setPackageInfo(pc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setInclude("bguser","execinfo","exercise","matchgroup","partybranch");//设置要映射的表名
        strategy.setNaming(NamingStrategy.underline_to_camel);//设置命名规则
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
        strategy.setEntityLombokModel(true);//自动Lombok
        strategy.setRestControllerStyle(true);//restful style
        strategy.setLogicDeleteFieldName("deleted");//设置逻辑删除字段名字
        strategy.setVersionFieldName("version");//设置乐观锁
        strategy.setControllerMappingHyphenStyle(true); //localhost:8080/hello_id_2

        //自动填充配置
        TableFill gmtCreate = new TableFill("gmt_create", FieldFill.INSERT);
        TableFill gmtModified = new TableFill("gmt_modified", FieldFill.INSERT_UPDATE);
        ArrayList<TableFill> tableFills = new ArrayList<>();
        tableFills.add(gmtModified);
        tableFills.add(gmtCreate);
        strategy.setTableFillList(tableFills);

        mpg.setStrategy(strategy);
        mpg.execute();
    }
}

Eleven, MySQL divisible, take the remainder, rounding, etc.

SELECT
    `bguser`.`userName`AS `uname`,
    `partybranch`.`branchName` AS `bname`,
    SUM(`execinfo`.`score`)AS `sumScore`,
    SUM(TIMESTAMPDIFF(SECOND,`execinfo`.startTime, `execinfo`.endTime))AS `time`,
    SUM(TIMESTAMPDIFF(SECOND,`execinfo`.startTime, `execinfo`.endTime))DIV 60 AS `minutes`,
    SUM(TIMESTAMPDIFF(SECOND,`execinfo`.startTime, `execinfo`.endTime))MOD 60 AS `seconds`
FROM
    `bguser`
        INNER JOIN
    `partybranch`
        INNER JOIN
    `execinfo`
    ON
            `execinfo`.`branchID`=`partybranch`.`recID`
            AND
            `execinfo`.`userID`=`bguser`.`userCode`
            AND
            execinfo.operType=0
GROUP BY
    `uname`,
    `bname`
ORDER BY
    `sumScore` DESC,`time` ASC

1. Divide: div

5 div 2 = 2;

Second, take the remainder: mod

5 mod 2 = 1;

Three, rounding: round

round(1.5) = 2;

Twelve, MySQL view

You don’t need to create vo for multi-join table query, just create the view directly, and then add the view table name in the MBP code generator.

For example
DELIMITER $$

ALTER ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vwuser` AS 
SELECT
  `us`.`userName`   AS `userName`,
  `us`.`userCode`   AS `userCode`,
  `py`.`branchName` AS `branchName`
FROM (`bguser` `us`
   JOIN `partybranch` `py`
     ON ((`us`.`branchID` = `py`.`recID`)))
ORDER BY `py`.`branchName`,`us`.`userCode`$$

DELIMITER ;


DELIMITER $$

ALTER ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vwpersonscoreorder` AS 
SELECT
  `bguser`.`userName`        AS `uname`,
  `partybranch`.`branchName` AS `bname`,
  SUM(`execinfo`.`score`)    AS `sumScore`,
  -(SUM(TIMESTAMPDIFF(SECOND,`execinfo`.`startTime`,`execinfo`.`endTime`))) AS `OperTime`
FROM ((`bguser`
    JOIN `partybranch`)
   JOIN `execinfo`
     ON (((`execinfo`.`branchID` = `partybranch`.`recID`)
          AND (`execinfo`.`userID` = `bguser`.`userCode`)
          AND (`execinfo`.`operType` = 0))))
GROUP BY `uname`,`bname`
ORDER BY `sumScore` DESC,`OperTime` DESC$$

DELIMITER ;


DELIMITER $$

ALTER ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vwgroupscoreorder` AS 
SELECT
  `matchgroup`.`GroupName` AS `GroupName`,
  ((SUM(`aa`.`score`) + SUM(`bb`.`score`)) + SUM(`cc`.`score`)) AS `GroupScore`,
  -(SUM(((TIMESTAMPDIFF(SECOND,`aa`.`startTime`,`aa`.`endTime`) + TIMESTAMPDIFF(SECOND,`bb`.`startTime`,`bb`.`endTime`)) + TIMESTAMPDIFF(SECOND,`cc`.`startTime`,`cc`.`endTime`)))) AS `OperTime`
FROM (((`matchgroup`
     LEFT JOIN `execinfo` `aa`
       ON (((`matchgroup`.`userA` = `aa`.`recID`)
            AND (`aa`.`operType` = 1))))
    LEFT JOIN `execinfo` `bb`
      ON (((`matchgroup`.`userB` = `bb`.`recID`)
           AND (`bb`.`operType` = 1))))
   LEFT JOIN `execinfo` `cc`
     ON (((`matchgroup`.`userC` = `cc`.`recID`)
          AND (`cc`.`operType` = 1))))
GROUP BY `matchgroup`.`GroupName`
ORDER BY `GroupScore` DESC,`OperTime` DESC$$

DELIMITER ;

Write a test class in springboot

@SpringBootTest
class DemoApplicationTests {
    @Autowired
    VwuserService vwuserService;
    @Autowired
    VwpersonscoreorderService vwpersonscoreorderService;
    @Autowired
    VwgroupscoreorderService vwgroupscoreorderService;

    @Test
    void contextLoads() {
//        System.out.println(vwuserService.list(null));
//        System.out.println(vwpersonscoreorderService.list(null));
        System.out.println(vwgroupscoreorderService.list(null));
    }
}