|
@@ -0,0 +1,148 @@
|
|
|
+/**
|
|
|
+ * @author 50560
|
|
|
+ * @create 2022-09-15 14:48
|
|
|
+ */
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.gyee.backconfig.BackConfigMain;
|
|
|
+import com.gyee.backconfig.mapper.auto.XrpProjectplanMapper;
|
|
|
+import com.gyee.backconfig.model.auto.XrpProjectplan;
|
|
|
+import com.gyee.common.model.StringUtils;
|
|
|
+import net.minidev.json.writer.UpdaterMapper;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ *@BelongsProject: workpathnew
|
|
|
+ *@BelongsPackage: PACKAGE_NAME
|
|
|
+ *@Author: xiruipeng
|
|
|
+ *@CreateTime: 2022-09-15 14:48
|
|
|
+ *@Description: TODO
|
|
|
+ *@Version: 1.0
|
|
|
+ */
|
|
|
+@SpringBootTest(classes = {BackConfigMain.class})
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+public class MyBatisPlusWrapperTest {
|
|
|
+ @Autowired
|
|
|
+ private XrpProjectplanMapper xrpProjectplanMapper;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testWrapper(){
|
|
|
+ //==> Preparing: SELECT ID,PROJECTID,GENERATINGCAPACITY,OUTAGEHOURS,YEAR,MONTH,WINDPOWER,isdeleted FROM XRP_PROJECTPLAN WHERE isdeleted=1
|
|
|
+ // AND (year LIKE ? AND outagehours BETWEEN ? AND ? AND windpower IS NOT NULL)
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<XrpProjectplan>();
|
|
|
+ queryWrapper.like("year","9")
|
|
|
+ // .between("outagehours",2.43,2.50)
|
|
|
+ .isNotNull("windpower");
|
|
|
+ List<XrpProjectplan> list = xrpProjectplanMapper.selectList(queryWrapper);
|
|
|
+ list.forEach(System.out::println);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testOrder(){
|
|
|
+ //查询信息,按照generatingcapacity降序,相同按照id升序
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.orderByDesc("generatingcapacity").orderByAsc("id");
|
|
|
+ List<XrpProjectplan> list = xrpProjectplanMapper.selectList(queryWrapper);
|
|
|
+ list.forEach(System.out::println);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDelete(){
|
|
|
+ //删除id
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
+ //queryWrapper.isNotNull("month");
|
|
|
+ queryWrapper.eq("month","");
|
|
|
+ int delete = xrpProjectplanMapper.delete(queryWrapper);
|
|
|
+ System.out.println("result"+ delete);
|
|
|
+ }
|
|
|
+
|
|
|
+ //update biao set zd="" where month='' and id or year
|
|
|
+ @Test
|
|
|
+ public void testUpdate2(){
|
|
|
+
|
|
|
+ //将month为”“并且id>jj或者year like 49
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("month","")
|
|
|
+ .gt("id",1570251305913802753L)
|
|
|
+ .or()
|
|
|
+ .like("year","49");
|
|
|
+ XrpProjectplan xrpProjectplan=new XrpProjectplan();
|
|
|
+ xrpProjectplan.setProjectid("5");
|
|
|
+ xrpProjectplan.setGeneratingcapacity("100.4");
|
|
|
+
|
|
|
+ //设置内容和条件
|
|
|
+ int result = xrpProjectplanMapper.update(xrpProjectplan, queryWrapper);
|
|
|
+ System.out.println("result:"+result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdatePer(){
|
|
|
+
|
|
|
+ //将month为”“并且(id>jj或者year like 49)
|
|
|
+ //lambda中的条件优先执行
|
|
|
+ //==> Preparing: UPDATE XRP_PROJECTPLAN SET PROJECTID=?, GENERATINGCAPACITY=?
|
|
|
+ // WHERE isdeleted=1 AND (month = ? AND (id > ? OR year LIKE ?))
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("month","")
|
|
|
+ .and(
|
|
|
+ i->i.gt("id",1570251305913802753L)
|
|
|
+ .or()
|
|
|
+ .like("year","49")
|
|
|
+ );
|
|
|
+
|
|
|
+ XrpProjectplan xrpProjectplan=new XrpProjectplan();
|
|
|
+ xrpProjectplan.setProjectid("90");
|
|
|
+ xrpProjectplan.setGeneratingcapacity("111.4");
|
|
|
+
|
|
|
+ //设置内容和条件
|
|
|
+ int result = xrpProjectplanMapper.update(xrpProjectplan, queryWrapper);
|
|
|
+ System.out.println("result:"+result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testPro(){
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
+ queryWrapper.select("ID","PROJECTID","YEAR");
|
|
|
+ //组装属性字段
|
|
|
+ List<Map<String, Object>> maps = xrpProjectplanMapper.selectMaps(queryWrapper);
|
|
|
+ maps.forEach(System.out::println);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdate(){
|
|
|
+ UpdateWrapper<XrpProjectplan> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("month","")
|
|
|
+ .gt("id",1570251305913802753L)
|
|
|
+ .or()
|
|
|
+ .like("year","49");
|
|
|
+ updateWrapper.set("month","33").set("YEAR","50");
|
|
|
+ int result = xrpProjectplanMapper.update(null, updateWrapper);
|
|
|
+ System.out.println("result:"+result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //组装条件
|
|
|
+ @Test
|
|
|
+ public void test(){
|
|
|
+ String year="";
|
|
|
+ Long idBegin=1570251304856838145L;
|
|
|
+ Long idEnd=1570284357834518534L;
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
+ //加入某个字符串不为null 不为空字符串,不为空白符
|
|
|
+ if(StringUtils.isNotEmpty(year)){
|
|
|
+ queryWrapper.like("year",year);
|
|
|
+ }
|
|
|
+
|
|
|
+ //if(idBegin)
|
|
|
+
|
|
|
+ }
|
|
|
+}
|