|
@@ -0,0 +1,212 @@
|
|
|
|
+
|
|
|
|
+ * @author 50560
|
|
|
|
+ * @create 2022-09-15 14:48
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
+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 com.sun.org.apache.bcel.internal.generic.IFNE;
|
|
|
|
+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(){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<XrpProjectplan>();
|
|
|
|
+ queryWrapper.like("year","9")
|
|
|
|
+
|
|
|
|
+ .isNotNull("windpower");
|
|
|
|
+ List<XrpProjectplan> list = xrpProjectplanMapper.selectList(queryWrapper);
|
|
|
|
+ list.forEach(System.out::println);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testOrder(){
|
|
|
|
+
|
|
|
|
+ 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(){
|
|
|
|
+
|
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
|
+
|
|
|
|
+ queryWrapper.eq("GENERATINGCAPACITY","100.4");
|
|
|
|
+ int delete = xrpProjectplanMapper.delete(queryWrapper);
|
|
|
|
+ System.out.println("result"+ delete);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testUpdate2(){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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(){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ UpdateWrapper<XrpProjectplan> queryWrapper = new UpdateWrapper<>();
|
|
|
|
+ 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 testUpdatePerLambda(){
|
|
|
|
+ LambdaUpdateWrapper<XrpProjectplan> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
+ updateWrapper.like(XrpProjectplan::getYear,"")
|
|
|
|
+ .gt(XrpProjectplan::getMonth,"5")
|
|
|
|
+ .and(
|
|
|
|
+ i->i.gt(XrpProjectplan::getId,1570251306048020482L)
|
|
|
|
+ .or()
|
|
|
|
+ .like(XrpProjectplan::getYear,"49")
|
|
|
|
+ );
|
|
|
|
+ updateWrapper
|
|
|
|
+ .set(XrpProjectplan::getProjectid,"120").set(XrpProjectplan::getGeneratingcapacity,111.7);
|
|
|
|
+ int result = xrpProjectplanMapper.update(null, updateWrapper);
|
|
|
|
+ System.out.println("result:"+result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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 testPro(){
|
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
|
+ queryWrapper.select("ID","PROJECTID","YEAR","generatingcapacity");
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> maps = xrpProjectplanMapper.selectMaps(queryWrapper);
|
|
|
|
+ maps.forEach(System.out::println);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void test(){
|
|
|
|
+ String year="5";
|
|
|
|
+ Long idBegin=1570251304856838145L;
|
|
|
|
+ Long idEnd=1570284357834518534L;
|
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotEmpty(year)){
|
|
|
|
+ queryWrapper.like("year",year);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (idBegin == null) {
|
|
|
|
+ queryWrapper.ge("id",idBegin);
|
|
|
|
+ }
|
|
|
|
+ if (idEnd == null) {
|
|
|
|
+ queryWrapper.le("id",idEnd);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<XrpProjectplan> list = xrpProjectplanMapper.selectList(queryWrapper);
|
|
|
|
+ list.forEach(System.out::println);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testCondition(){
|
|
|
|
+ String year="5";
|
|
|
|
+ Long idBegin=1570251304856838145L;
|
|
|
|
+ Long idEnd=1570284357834518534L;
|
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
|
+ queryWrapper.like(StringUtils.isNotEmpty(year),"year",year)
|
|
|
|
+ .ge(idBegin!=null,"id",idBegin)
|
|
|
|
+ .le(idEnd!=null,"id",idEnd);
|
|
|
|
+ List<XrpProjectplan> xrpProjectplanList = xrpProjectplanMapper.selectList(queryWrapper);
|
|
|
|
+ xrpProjectplanList.forEach(System.out::println);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void TestLambda(){
|
|
|
|
+ String year="5";
|
|
|
|
+ Long idBegin=1570251304856838145L;
|
|
|
|
+ Long idEnd=1570284357834518534L;
|
|
|
|
+ LambdaQueryWrapper<XrpProjectplan> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ lambdaQueryWrapper.like(StringUtils.isNotBlank(year),XrpProjectplan::getYear,year)
|
|
|
|
+ .ge(idBegin!=null,XrpProjectplan::getId,idBegin)
|
|
|
|
+ .le(idEnd!=null,XrpProjectplan::getId,idEnd);
|
|
|
|
+ List<XrpProjectplan> list = xrpProjectplanMapper.selectList(lambdaQueryWrapper);
|
|
|
|
+ list.forEach(System.out::println);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|